Qt 4.8
qmainwindowlayout_mac.mm
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <private/qmainwindowlayout_p.h>
43 #include <qtoolbar.h>
44 #include <private/qtoolbarlayout_p.h>
45 #include <private/qt_cocoa_helpers_mac_p.h>
46 #include <private/qtoolbar_p.h>
47 
48 #ifndef QT_MAC_USE_COCOA
49 #include <Carbon/Carbon.h>
50 #else
51 #include <quuid.h>
52 #include <private/qcocoatoolbardelegate_mac_p.h>
53 #import <private/qcocoawindowdelegate_mac_p.h>
54 #endif
55 
57 #ifdef QT_NAMESPACE
58 
59 // namespace up the stuff
60 #define SS(x) #x
61 #define S0(x) SS(x)
62 #define S "com.trolltech.qt-" S0(QT_NAMESPACE) ".qmainwindow.qtoolbarInHIToolbar"
63 #define SToolbar "com.trolltech.qt-" S0(QT_NAMESPACE) ".hitoolbar-qtoolbar"
64 #define SNSToolbar "com.trolltech.qt-" S0(QT_NAMESPACE) ".qtoolbarInNSToolbar"
65 #define MacToolbar "com.trolltech.qt-" S0(QT_NAMESPACE) ".qmainwindow.mactoolbar"
66 
67 #ifndef QT_MAC_USE_COCOA
70 #else
71 static NSString *kQToolBarNSToolbarIdentifier = @SNSToolbar;
72 #endif
74 #undef SS
75 #undef S0
76 #undef S
77 #undef SToolbar
78 #undef SNSToolbar
79 #undef MacToolbar
80 
81 #else
82 #ifndef QT_MAC_USE_COCOA
83 static CFStringRef kQToolBarHIToolbarItemClassID = CFSTR("com.trolltech.qt.qmainwindow.qtoolbarInHIToolbar");
84 static CFStringRef kQToolBarHIToolbarIdentifier = CFSTR("com.trolltech.qt.hitoolbar-qtoolbar");
85 #else
86 static NSString *kQToolBarNSToolbarIdentifier = @"com.trolltech.qt.qmainwindow.qtoolbarInNSToolbar";
87 #endif
88 static CFStringRef kQMainWindowMacToolbarID = CFSTR("com.trolltech.qt.qmainwindow.mactoolbar");
89 #endif // QT_NAMESPACE
90 
91 #ifndef QT_MAC_USE_COCOA
92 
93 static const int kEventParamQToolBar = 'QTBR';
94 static const int kEventParamQMainWindowLayout = 'QMWL';
95 
96 const EventTypeSpec qtoolbarEvents[] =
97 {
98  { kEventClassHIObject, kEventHIObjectConstruct },
99  { kEventClassHIObject, kEventHIObjectDestruct },
100  { kEventClassHIObject, kEventHIObjectInitialize },
101  { kEventClassToolbarItem, kEventToolbarItemCreateCustomView }
102 };
103 
105 {
107  : toolbarItem(item), mainWindowLayout(0)
108  {}
111 };
112 
114  EventRef event, void *data)
115 {
116  OSStatus result = eventNotHandledErr;
117  QToolBarInHIToolbarInfo *object = static_cast<QToolBarInHIToolbarInfo *>(data);
118 
119  switch (GetEventClass(event)) {
120  case kEventClassHIObject:
121  switch (GetEventKind(event)) {
122  case kEventHIObjectConstruct:
123  {
125  GetEventParameter(event, kEventParamHIObjectInstance, typeHIObjectRef,
126  0, sizeof( HIObjectRef ), 0, &toolbarItem);
127 
128  QToolBarInHIToolbarInfo *item = new QToolBarInHIToolbarInfo(toolbarItem);
129  SetEventParameter(event, kEventParamHIObjectInstance, typeVoidPtr,
130  sizeof(void *), &item);
131  result = noErr;
132  }
133  break;
134  case kEventHIObjectInitialize:
135  result = CallNextEventHandler(inCallRef, event);
136  if (result == noErr) {
137  QToolBar *toolbar = 0;
139  GetEventParameter(event, kEventParamQToolBar, typeVoidPtr,
140  0, sizeof(void *), 0, &toolbar);
141  GetEventParameter(event, kEventParamQMainWindowLayout, typeVoidPtr,
142  0, sizeof(void *), 0, &layout);
143  object->mainWindowLayout = layout;
144  object->mainWindowLayout->unifiedToolbarHash.insert(object->toolbarItem, toolbar);
145  HIToolbarItemChangeAttributes(object->toolbarItem,
146  kHIToolbarItemLabelDisabled, 0);
147  }
148  break;
149 
150  case kEventHIObjectDestruct:
151  delete object;
152  result = noErr;
153  break;
154  }
155  break;
156 
157  case kEventClassToolbarItem:
158  switch (GetEventKind(event))
159  {
160  case kEventToolbarItemCreateCustomView:
161  {
163  = object->mainWindowLayout->unifiedToolbarHash.value(object->toolbarItem);
164  if (toolbar) {
165  HIViewRef hiview = HIViewRef(toolbar->winId());
166  SetEventParameter(event, kEventParamControlRef, typeControlRef,
167  sizeof(HIViewRef), &hiview);
168  result = noErr;
169  }
170  }
171  break;
172  }
173  break;
174  }
175  return result;
176 }
177 
179 {
180  static bool registered = false;
181 
182  if (!registered) {
183  HIObjectRegisterSubclass( kQToolBarHIToolbarItemClassID,
184  kHIToolbarItemClassID, 0, QMainWindowLayout::qtoolbarInHIToolbarHandler,
185  GetEventTypeCount(qtoolbarEvents), qtoolbarEvents, 0, 0 );
186  registered = true;
187  }
188 }
189 
190 static void GetToolbarAllowedItems(CFMutableArrayRef array)
191 {
192  CFArrayAppendValue(array, kQToolBarHIToolbarIdentifier);
193 }
194 
197 {
199 
200  EventRef event;
201  HIToolbarItemRef result = 0;
202 
204  UInt32 options = kHIToolbarItemAllowDuplicates;
205 
206  CreateEvent(0, kEventClassHIObject, kEventHIObjectInitialize,
207  GetCurrentEventTime(), 0, &event);
208  SetEventParameter(event, kEventParamToolbarItemIdentifier, typeCFStringRef,
209  sizeof(CFStringRef), &identifier);
210  SetEventParameter(event, kEventParamAttributes, typeUInt32, sizeof(UInt32), &options);
211  SetEventParameter(event, kEventParamQToolBar, typeVoidPtr, sizeof(void *), &toolbar);
212  SetEventParameter(event, kEventParamQMainWindowLayout, typeVoidPtr, sizeof(void *), &layout);
213 
214  HIObjectCreate(kQToolBarHIToolbarItemClassID, event,
215  static_cast<HIObjectRef *>(&result));
216 
217  ReleaseEvent(event);
218  return result;
219 
220 }
221 
223  CFTypeRef data)
224 {
225  HIToolbarItemRef item = 0;
226  if (CFStringCompare(kQToolBarHIToolbarIdentifier, identifier,
227  kCFCompareBackwards) == kCFCompareEqualTo) {
228  if (data && CFGetTypeID(data) == CFArrayGetTypeID()) {
229  CFArrayRef array = static_cast<CFArrayRef>(data);
230  QToolBar *toolbar = static_cast<QToolBar *>(const_cast<void *>(CFArrayGetValueAtIndex(array, 0)));
231  QMainWindowLayout *layout = static_cast<QMainWindowLayout *>(const_cast<void *>(CFArrayGetValueAtIndex(array, 1)));
232  item = createQToolBarInHIToolbarItem(toolbar, layout);
233  }
234  }
235  return item;
236 }
237 
238 static const EventTypeSpec kToolbarEvents[] = {
239 { kEventClassToolbar, kEventToolbarGetDefaultIdentifiers },
240 { kEventClassToolbar, kEventToolbarGetAllowedIdentifiers },
241 { kEventClassToolbar, kEventToolbarCreateItemWithIdentifier },
242 { kEventClassToolbar, kEventToolbarItemAdded },
243 { kEventClassToolbar, kEventToolbarItemRemoved }
244 };
245 
247 {
249  OSStatus result = eventNotHandledErr;
250  CFMutableArrayRef array;
251  CFStringRef identifier;
252  switch (GetEventKind(event)) {
253  case kEventToolbarGetDefaultIdentifiers:
254  case kEventToolbarGetAllowedIdentifiers:
255  GetEventParameter(event, kEventParamMutableArray, typeCFMutableArrayRef, 0,
256  sizeof(CFMutableArrayRef), 0, &array);
257  GetToolbarAllowedItems(array);
258  result = noErr;
259  break;
260  case kEventToolbarCreateItemWithIdentifier: {
261  HIToolbarItemRef item;
262  CFTypeRef data = 0;
263  OSStatus err = GetEventParameter(event, kEventParamToolbarItemIdentifier, typeCFStringRef,
264  0, sizeof(CFStringRef), 0, &identifier);
265  err = GetEventParameter(event, kEventParamToolbarItemConfigData, typeCFTypeRef,
266  0, sizeof(CFTypeRef), 0, &data);
267  item = CreateToolbarItemForIdentifier(identifier, data);
268  if (item) {
269  result = SetEventParameter(event, kEventParamToolbarItem, typeHIToolbarItemRef,
270  sizeof(HIToolbarItemRef), &item );
271  }
272  break;
273  }
274  case kEventToolbarItemAdded: {
275  // Double check that our "view" of the toolbar is similar.
276  HIToolbarItemRef item;
277  CFIndex index;
278  if (GetEventParameter(event, kEventParamToolbarItem, typeHIToolbarItemRef,
279  0, sizeof(HIToolbarItemRef), 0, &item) == noErr
280  && GetEventParameter(event, kEventParamIndex, typeCFIndex, 0,
281  sizeof(CFIndex), 0, &index) == noErr) {
282  CFRetain(item); // We will watch this until it's removed from the list (or bust).
283  mainWindowLayout->toolbarItemsCopy.insert(index, item);
284  QToolBar *toolbar = mainWindowLayout->unifiedToolbarHash.value(item);
285  if (toolbar) {
286  int toolbarIndex = mainWindowLayout->qtoolbarsInUnifiedToolbarList.indexOf(toolbar);
287  if (index != toolbarIndex) {
288  // Dang, we must be out of sync, rebuild it from the "toolbarItemsCopy"
289  mainWindowLayout->qtoolbarsInUnifiedToolbarList.clear();
290  for (int i = 0; i < mainWindowLayout->toolbarItemsCopy.size(); ++i) {
291  // This will either append the correct toolbar or an
292  // null toolbar. This is fine because this list
293  // is really only kept to make sure that things are but in the right order.
294  mainWindowLayout->qtoolbarsInUnifiedToolbarList.append(
295  mainWindowLayout->unifiedToolbarHash.value(mainWindowLayout->
296  toolbarItemsCopy.at(i)));
297  }
298  }
299  }
300  }
301  break;
302  }
303  case kEventToolbarItemRemoved: {
304  HIToolbarItemRef item;
305  if (GetEventParameter(event, kEventParamToolbarItem, typeHIToolbarItemRef,
306  0, sizeof(HIToolbarItemRef), 0, &item) == noErr) {
307  mainWindowLayout->unifiedToolbarHash.remove(item);
308  for (int i = 0; i < mainWindowLayout->toolbarItemsCopy.size(); ++i) {
309  if (mainWindowLayout->toolbarItemsCopy.at(i) == item) {
310  // I know about it, so release it.
311  mainWindowLayout->toolbarItemsCopy.removeAt(i);
312  mainWindowLayout->qtoolbarsInUnifiedToolbarList.removeAt(i);
313  CFRelease(item);
314  break;
315  }
316  }
317  }
318  break;
319  }
320  }
321  return result;
322 }
323 #endif // ! QT_MAC_USE_COCOA
324 
325 #ifndef kWindowUnifiedTitleAndToolbarAttribute
326 #define kWindowUnifiedTitleAndToolbarAttribute (1 << 7)
327 #endif
328 
330 {
331  bool useMacToolbar = layoutState.mainWindow->unifiedTitleAndToolBarOnMac();
332 #ifndef QT_MAC_USE_COCOA
333  if (useMacToolbar) {
334  ChangeWindowAttributes(qt_mac_window_for(layoutState.mainWindow),
336  } else {
337  ChangeWindowAttributes(qt_mac_window_for(layoutState.mainWindow),
339  }
340 #endif
341 
342  layoutState.mainWindow->setUpdatesEnabled(false); // reduces a little bit of flicker, not all though
343 #if defined(QT_MAC_USE_COCOA)
345  NSView *cView = [qt_mac_window_for(layoutState.mainWindow) contentView];
346  if (useMacToolbar) {
347  [cView setPostsFrameChangedNotifications:YES];
348  [[NSNotificationCenter defaultCenter] addObserver: [QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate]
349  selector: @selector(syncContentViewFrame:)
350  name: NSViewFrameDidChangeNotification
351  object: cView];
352  }
353 #endif
354  if (!useMacToolbar) {
355  macWindowToolbarShow(layoutState.mainWindow, false);
356  // Move everything out of the HIToolbar into the main toolbar.
357  while (!qtoolbarsInUnifiedToolbarList.isEmpty()) {
358  // Should shrink the list by one every time.
359  QToolBar *toolbar = qtoolbarsInUnifiedToolbarList.first();
360 #if defined(QT_MAC_USE_COCOA)
361  unifiedSurface->removeToolbar(toolbar);
362 #endif
363  layoutState.mainWindow->addToolBar(Qt::TopToolBarArea, toolbar);
364  }
365  macWindowToolbarSet(qt_mac_window_for(layoutState.mainWindow), 0);
366  } else {
367  QList<QToolBar *> toolbars = layoutState.mainWindow->findChildren<QToolBar *>();
368  for (int i = 0; i < toolbars.size(); ++i) {
369  QToolBar *toolbar = toolbars.at(i);
370  if (toolBarArea(toolbar) == Qt::TopToolBarArea) {
371  // Do this here, because we are in an in-between state.
372  removeWidget(toolbar);
373  layoutState.mainWindow->addToolBar(Qt::TopToolBarArea, toolbar);
374  }
375  }
376  syncUnifiedToolbarVisibility();
377  }
378 #if defined(QT_MAC_USE_COCOA)
379  if (!useMacToolbar) {
380  [cView setPostsFrameChangedNotifications:NO];
381  [[NSNotificationCenter defaultCenter] removeObserver: [QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate]
382  name: NSViewFrameDidChangeNotification
383  object: cView];
384  }
385 #endif
386  layoutState.mainWindow->setUpdatesEnabled(true);
387 }
388 
390 {
391  // This layering could go on to one more level, but I decided to stop here.
392  // The HIToolbar and NSToolbar APIs are fairly similar as you will see.
393  if (toolbar == 0)
394  return;
395 
396 #if defined(QT_MAC_USE_COCOA)
397  // toolbar will now become native (if not already) since we need
398  // an nsview for it inside the corresponding NSToolbarItem.
399  // Setting isInUnifiedToolbar will (among other things) stop alien
400  // siblings from becoming native when this happends since the toolbar
401  // will not overlap with other children of the QMainWindow. NB: Switching
402  // unified toolbar off after this stage is not supported, as this means
403  // that either the menubar must be alien again, or the sibling must
404  // be backed by an nsview to protect from overlapping issues:
405  toolbar->d_func()->isInUnifiedToolbar = true;
406 #endif
407 
408  QToolBarLayout *toolbarLayout = static_cast<QToolBarLayout *>(toolbar->layout());
409  toolbarSaveState.insert(toolbar, ToolBarSaveState(toolbar->isMovable(), toolbar->maximumSize()));
410 
411  if (toolbarLayout->hasExpandFlag() == false)
412  toolbar->setMaximumSize(toolbar->sizeHint());
413 
414  toolbar->setMovable(false);
415  toolbarLayout->setUsePopupMenu(true);
416  // Make the toolbar a child of the mainwindow to avoid creating a window.
417  toolbar->setParent(layoutState.mainWindow);
418 
419  toolbar->winId(); // Now create the OSViewRef.
420  layoutState.mainWindow->createWinId();
421 
422  OSWindowRef window = qt_mac_window_for(layoutState.mainWindow);
423  int beforeIndex = qtoolbarsInUnifiedToolbarList.indexOf(before);
424  if (beforeIndex == -1)
425  beforeIndex = qtoolbarsInUnifiedToolbarList.size();
426 
427  int toolbarIndex = qtoolbarsInUnifiedToolbarList.indexOf(toolbar);
428 
429 #ifndef QT_MAC_USE_COCOA
430  HIToolbarRef macToolbar = NULL;
431  if ((GetWindowToolbar(window, &macToolbar) == noErr) && !macToolbar) {
432  HIToolbarCreate(kQMainWindowMacToolbarID,
433  kHIToolbarItemAllowDuplicates, &macToolbar);
434  InstallEventHandler(HIObjectGetEventTarget(static_cast<HIToolbarRef>(macToolbar)),
436  kToolbarEvents, this, 0);
437  HIToolbarSetDisplaySize(macToolbar, kHIToolbarDisplaySizeNormal);
438  HIToolbarSetDisplayMode(macToolbar, kHIToolbarDisplayModeIconOnly);
439  macWindowToolbarSet(window, macToolbar);
440  if (layoutState.mainWindow->isVisible())
441  macWindowToolbarShow(layoutState.mainWindow, true);
442  CFRelease(macToolbar);
443  }
444 #else
446  NSToolbar *macToolbar = [window toolbar];
447  if (macToolbar == nil) {
448  macToolbar = [[NSToolbar alloc] initWithIdentifier:qt_mac_QStringToNSString(QUuid::createUuid().toString())];
449  [macToolbar setDisplayMode:NSToolbarDisplayModeIconOnly];
450  [macToolbar setSizeMode:NSToolbarSizeModeRegular];
451  [macToolbar setDelegate:[[QT_MANGLE_NAMESPACE(QCocoaToolBarDelegate) alloc] initWithMainWindowLayout:this]];
452  [window setToolbar:macToolbar];
453  [macToolbar release];
454  }
455 #endif
456  if (toolbarIndex != -1) {
457  qtoolbarsInUnifiedToolbarList.removeAt(toolbarIndex);
458 #ifndef QT_MAC_USE_COCOA
459  HIToolbarRemoveItemAtIndex(macToolbar, toolbarIndex);
460 #else
461  [macToolbar removeItemAtIndex:toolbarIndex];
462 #endif
463  }
464  qtoolbarsInUnifiedToolbarList.insert(beforeIndex, toolbar);
465 
466  // Adding to the unified toolbar surface for the raster engine.
467  if (layoutState.mainWindow->windowSurface()) {
468  QPoint offset(0, 0);
469  for (int i = 0; i < beforeIndex; ++i) {
470  offset.setX(offset.x() + qtoolbarsInUnifiedToolbarList.at(i)->size().width());
471  }
472 #ifdef QT_MAC_USE_COCOA
473  unifiedSurface->insertToolbar(toolbar, offset);
474 #endif // QT_MAC_USE_COCOA
475  }
476 
477 #ifndef QT_MAC_USE_COCOA
479  const QObject *stupidArray[] = { toolbar, this };
480  QCFType<CFArrayRef> array = CFArrayCreate(0, reinterpret_cast<const void **>(&stupidArray),
481  2, 0);
482  HIToolbarCreateItemWithIdentifier(macToolbar, kQToolBarHIToolbarIdentifier,
483  array, &outItem);
484  HIToolbarInsertItemAtIndex(macToolbar, outItem, beforeIndex);
485 #else
486  NSString *toolbarID = kQToolBarNSToolbarIdentifier;
487  toolbarID = [toolbarID stringByAppendingFormat:@"%p", toolbar];
488  cocoaItemIDToToolbarHash.insert(qt_mac_NSStringToQString(toolbarID), toolbar);
489  [macToolbar insertItemWithItemIdentifier:toolbarID atIndex:beforeIndex];
490 #endif
491 }
492 
493 #ifdef QT_MAC_USE_COCOA
494 void QMainWindowLayout::updateUnifiedToolbarOffset()
495 {
496  QPoint offset(0, 0);
497 
498  for (int i = 1; i < qtoolbarsInUnifiedToolbarList.length(); ++i) {
499  offset.setX(offset.x() + qtoolbarsInUnifiedToolbarList.at(i - 1)->size().width());
500  qtoolbarsInUnifiedToolbarList.at(i)->d_func()->toolbar_offset = offset;
501  }
502 }
503 #endif // QT_MAC_USE_COCOA
504 
505 
507 {
508  QHash<void *, QToolBar *>::iterator it = unifiedToolbarHash.begin();
509  while (it != unifiedToolbarHash.end()) {
510  if (it.value() == toolbar) {
511  // Rescue our HIView and set it on the mainWindow again.
512  bool saveVisible = !toolbar->isHidden();
513  toolbar->setParent(0);
514  toolbar->setParent(parentWidget());
515  toolbar->setVisible(saveVisible);
516  ToolBarSaveState saveState = toolbarSaveState.value(toolbar);
517  static_cast<QToolBarLayout *>(toolbar->layout())->setUsePopupMenu(false);
518  toolbar->setMovable(saveState.movable);
519  toolbar->setMaximumSize(saveState.maximumSize);
520  toolbarSaveState.remove(toolbar);
521 #ifndef QT_MAC_USE_COCOA
522  HIToolbarItemRef item = static_cast<HIToolbarItemRef>(it.key());
523  HIToolbarRemoveItemAtIndex(HIToolbarItemGetToolbar(item),
524  toolbarItemsCopy.indexOf(item));
525 #else
526  NSToolbarItem *item = static_cast<NSToolbarItem *>(it.key());
527  [[qt_mac_window_for(layoutState.mainWindow->window()) toolbar]
528  removeItemAtIndex:toolbarItemsCopy.indexOf(item)];
529  unifiedToolbarHash.remove(item);
530  qtoolbarsInUnifiedToolbarList.removeAll(toolbar);
531 #endif
532  break;
533  }
534  ++it;
535  }
536 }
537 
539 {
540 #ifdef QT_MAC_USE_COCOA
542 #endif
543  for (int i = 0; i < toolbarItemsCopy.size(); ++i) {
544 #ifdef QT_MAC_USE_COCOA
545  NSToolbarItem *item = static_cast<NSToolbarItem *>(toolbarItemsCopy.at(i));
546  [item setView:0];
547 #endif
548  CFRelease(toolbarItemsCopy.at(i));
549  }
550  toolbarItemsCopy.clear();
551  unifiedToolbarHash.clear();
552 
553 #ifdef QT_MAC_USE_COCOA
554  OSWindowRef window = qt_mac_window_for(layoutState.mainWindow);
555  NSToolbar *macToolbar = [window toolbar];
556  if (macToolbar) {
557  [[macToolbar delegate] release];
558  [macToolbar setDelegate:nil];
559  }
560 #endif
561 }
562 
564 {
565 #ifdef QT_MAC_USE_COCOA
566  QHash<void *, QToolBar *>::const_iterator it = unifiedToolbarHash.constBegin();
567  NSToolbarItem *item = nil;
568  while (it != unifiedToolbarHash.constEnd()) {
569  if (tb == it.value()) {
570  item = static_cast<NSToolbarItem *>(it.key());
571  break;
572  }
573  ++it;
574  }
575  if (item) {
577  QWidgetItem layoutItem(tb);
578  QSize size = layoutItem.maximumSize();
579  NSSize nssize = NSMakeSize(size.width(), size.height());
580  [item setMaxSize:nssize];
581  size = layoutItem.minimumSize();
582  nssize.width = size.width();
583  nssize.height = size.height();
584  [item setMinSize:nssize];
585  }
586 #else
587  Q_UNUSED(tb);
588 #endif
589 }
590 
592 {
593  if (blockVisiblityCheck)
594  return;
595 
596  Q_ASSERT(layoutState.mainWindow->unifiedTitleAndToolBarOnMac());
597  bool show = false;
598  const int ToolBarCount = qtoolbarsInUnifiedToolbarList.count();
599  for (int i = 0; i < ToolBarCount; ++i) {
600  if (qtoolbarsInUnifiedToolbarList.at(i)->isVisible()) {
601  show = true;
602  break;
603  }
604  }
605  macWindowToolbarShow(layoutState.mainWindow, show);
606 }
607 
QSize maximumSize() const
Reimplemented Function
bool isMovable() const
Definition: qtoolbar.cpp:656
const struct __CFString * CFStringRef
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
static CFStringRef kQMainWindowMacToolbarID
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
Definition: qwidget.cpp:10479
EventRef event
#define it(className, varName)
static QUuid createUuid()
On any platform other than Windows, this function returns a new UUID with variant QUuid::DCE and vers...
Definition: quuid.cpp:897
void setMaximumSize(const QSize &)
Definition: qwidget.h:972
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qhash.h:348
void insertIntoMacToolbar(QToolBar *before, QToolBar *after)
#define MacToolbar
void macWindowToolbarSet(void *window, void *toolbarRef)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static HIToolbarItemRef CreateToolbarItemForIdentifier(CFStringRef identifier, CFTypeRef data)
NSToolbar * toolbar
const EventTypeSpec qtoolbarEvents[]
virtual QSize sizeHint() const
OSWindowRef qt_mac_window_for(const QWidget *)
Definition: qwidget_mac.mm:484
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition: qwidget.h:1008
const Key & key() const
Returns the current item&#39;s key.
Definition: qhash.h:419
static CFStringRef kQToolBarHIToolbarItemClassID
NSWindow * window
int width() const
Returns the width.
Definition: qsize.h:126
static QString toString(Register *reg, int type, bool *ok=0)
void removeFromMacToolbar(QToolBar *toolbar)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
WindowRef OSWindowRef
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
struct OpaqueControlRef * HIViewRef
const char * layout
static HIToolbarItemRef createQToolBarInHIToolbarItem(QToolBar *toolbar, QMainWindowLayout *layout)
const T & value() const
Returns the current item&#39;s value.
Definition: qhash.h:420
static const char * data(const QByteArray &arr)
QList< QToolBar * > qtoolbarsInUnifiedToolbarList
void clear()
Removes all items from the list.
Definition: qlist.h:764
const Key & key() const
Returns the current item&#39;s key as a const reference.
Definition: qhash.h:347
static void qtMacHIToolbarRegisterQToolBarInHIToolborItemClass()
signed long OSStatus
The QWidgetItem class is a layout item that represents a widget.
Definition: qlayoutitem.h:122
static const EventTypeSpec kToolbarEvents[]
QToolBarInHIToolbarInfo(HIToolbarItemRef item)
struct OpaqueEventRef * EventRef
virtual void setVisible(bool visible)
Definition: qwidget.cpp:7991
const void * CFTypeRef
static QWidget * parentWidget(const QWidget *w)
HIObjectRef HIToolbarItemRef
QSize minimumSize() const
Reimplemented Function
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
QHash< void *, QToolBar * > unifiedToolbarHash
static void GetToolbarAllowedItems(CFMutableArrayRef array)
#define QT_MANGLE_NAMESPACE(name)
Definition: qglobal.h:106
void setUsePopupMenu(bool set)
static OSStatus qtmacToolbarDelegate(EventHandlerCallRef, EventRef, void *)
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QSize maximumSize() const
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
#define S
struct OpaqueHIObjectRef * HIObjectRef
void macWindowToolbarShow(const QWidget *widget, bool show)
int height() const
Returns the height.
Definition: qsize.h:129
#define kWindowUnifiedTitleAndToolbarAttribute
quint16 index
static const int kEventParamQToolBar
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073
bool hasExpandFlag() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
struct OpaqueEventHandlerCallRef * EventHandlerCallRef
WId winId() const
Returns the window system identifier of the widget.
Definition: qwidget.cpp:2557
QMainWindowLayout * mainWindowLayout
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
#define SNSToolbar
static const int kEventParamQMainWindowLayout
static OSStatus qtoolbarInHIToolbarHandler(EventHandlerCallRef inCallRef, EventRef event, void *data)
void fixSizeInUnifiedToolbar(QToolBar *tb) const
const struct __CFArray * CFArrayRef
void setMovable(bool movable)
Definition: qtoolbar.cpp:646
void setX(int x)
Sets the x coordinate of this point to the given x coordinate.
Definition: qpoint.h:134
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
#define SToolbar
QList< void * > toolbarItemsCopy
static CFStringRef kQToolBarHIToolbarIdentifier
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480