42 #include <private/qmainwindowlayout_p.h> 44 #include <private/qtoolbarlayout_p.h> 45 #include <private/qt_cocoa_helpers_mac_p.h> 46 #include <private/qtoolbar_p.h> 48 #ifndef QT_MAC_USE_COCOA 49 #include <Carbon/Carbon.h> 52 #include <private/qcocoatoolbardelegate_mac_p.h> 53 #import <private/qcocoawindowdelegate_mac_p.h> 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" 67 #ifndef QT_MAC_USE_COCOA 71 static NSString *kQToolBarNSToolbarIdentifier = @
SNSToolbar;
82 #ifndef QT_MAC_USE_COCOA 86 static NSString *kQToolBarNSToolbarIdentifier =
@"com.trolltech.qt.qmainwindow.qtoolbarInNSToolbar";
89 #endif // QT_NAMESPACE 91 #ifndef QT_MAC_USE_COCOA 98 { kEventClassHIObject, kEventHIObjectConstruct },
99 { kEventClassHIObject, kEventHIObjectDestruct },
100 { kEventClassHIObject, kEventHIObjectInitialize },
101 { kEventClassToolbarItem, kEventToolbarItemCreateCustomView }
116 OSStatus result = eventNotHandledErr;
119 switch (GetEventClass(event)) {
120 case kEventClassHIObject:
121 switch (GetEventKind(event)) {
122 case kEventHIObjectConstruct:
125 GetEventParameter(event, kEventParamHIObjectInstance, typeHIObjectRef,
129 SetEventParameter(event, kEventParamHIObjectInstance, typeVoidPtr,
130 sizeof(
void *), &item);
134 case kEventHIObjectInitialize:
135 result = CallNextEventHandler(inCallRef, event);
136 if (result == noErr) {
140 0,
sizeof(
void *), 0, &toolbar);
142 0,
sizeof(
void *), 0, &layout);
143 object->mainWindowLayout =
layout;
144 object->mainWindowLayout->unifiedToolbarHash.insert(object->
toolbarItem, toolbar);
146 kHIToolbarItemLabelDisabled, 0);
150 case kEventHIObjectDestruct:
157 case kEventClassToolbarItem:
158 switch (GetEventKind(event))
160 case kEventToolbarItemCreateCustomView:
163 =
object->mainWindowLayout->unifiedToolbarHash.value(object->
toolbarItem);
166 SetEventParameter(event, kEventParamControlRef, typeControlRef,
180 static bool registered =
false;
204 UInt32 options = kHIToolbarItemAllowDuplicates;
206 CreateEvent(0, kEventClassHIObject, kEventHIObjectInitialize,
207 GetCurrentEventTime(), 0, &event);
208 SetEventParameter(event, kEventParamToolbarItemIdentifier, typeCFStringRef,
210 SetEventParameter(event, kEventParamAttributes, typeUInt32,
sizeof(UInt32), &options);
215 static_cast<HIObjectRef *>(&result));
227 kCFCompareBackwards) == kCFCompareEqualTo) {
228 if (data && CFGetTypeID(data) == CFArrayGetTypeID()) {
232 item = createQToolBarInHIToolbarItem(toolbar, layout);
239 { kEventClassToolbar, kEventToolbarGetDefaultIdentifiers },
240 { kEventClassToolbar, kEventToolbarGetAllowedIdentifiers },
241 { kEventClassToolbar, kEventToolbarCreateItemWithIdentifier },
242 { kEventClassToolbar, kEventToolbarItemAdded },
243 { kEventClassToolbar, kEventToolbarItemRemoved }
249 OSStatus result = eventNotHandledErr;
250 CFMutableArrayRef array;
252 switch (GetEventKind(event)) {
253 case kEventToolbarGetDefaultIdentifiers:
254 case kEventToolbarGetAllowedIdentifiers:
255 GetEventParameter(event, kEventParamMutableArray, typeCFMutableArrayRef, 0,
256 sizeof(CFMutableArrayRef), 0, &array);
260 case kEventToolbarCreateItemWithIdentifier: {
263 OSStatus err = GetEventParameter(event, kEventParamToolbarItemIdentifier, typeCFStringRef,
265 err = GetEventParameter(event, kEventParamToolbarItemConfigData, typeCFTypeRef,
267 item = CreateToolbarItemForIdentifier(identifier, data);
269 result = SetEventParameter(event, kEventParamToolbarItem, typeHIToolbarItemRef,
274 case kEventToolbarItemAdded: {
278 if (GetEventParameter(event, kEventParamToolbarItem, typeHIToolbarItemRef,
280 && GetEventParameter(event, kEventParamIndex, typeCFIndex, 0,
281 sizeof(CFIndex), 0, &index) == noErr) {
287 if (index != toolbarIndex) {
296 toolbarItemsCopy.at(i)));
303 case kEventToolbarItemRemoved: {
305 if (GetEventParameter(event, kEventParamToolbarItem, typeHIToolbarItemRef,
323 #endif // ! QT_MAC_USE_COCOA 325 #ifndef kWindowUnifiedTitleAndToolbarAttribute 326 #define kWindowUnifiedTitleAndToolbarAttribute (1 << 7) 331 bool useMacToolbar = layoutState.mainWindow->unifiedTitleAndToolBarOnMac();
332 #ifndef QT_MAC_USE_COCOA 342 layoutState.mainWindow->setUpdatesEnabled(
false);
343 #if defined(QT_MAC_USE_COCOA) 347 [cView setPostsFrameChangedNotifications:YES];
348 [[NSNotificationCenter defaultCenter] addObserver: [
QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate]
349 selector:
@selector(syncContentViewFrame:)
350 name: NSViewFrameDidChangeNotification
354 if (!useMacToolbar) {
357 while (!qtoolbarsInUnifiedToolbarList.isEmpty()) {
360 #if defined(QT_MAC_USE_COCOA) 361 unifiedSurface->removeToolbar(toolbar);
368 for (
int i = 0; i < toolbars.
size(); ++i) {
372 removeWidget(toolbar);
376 syncUnifiedToolbarVisibility();
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
386 layoutState.mainWindow->setUpdatesEnabled(
true);
396 #if defined(QT_MAC_USE_COCOA) 405 toolbar->d_func()->isInUnifiedToolbar =
true;
417 toolbar->
setParent(layoutState.mainWindow);
420 layoutState.mainWindow->createWinId();
423 int beforeIndex = qtoolbarsInUnifiedToolbarList.indexOf(before);
424 if (beforeIndex == -1)
425 beforeIndex = qtoolbarsInUnifiedToolbarList.size();
427 int toolbarIndex = qtoolbarsInUnifiedToolbarList.indexOf(toolbar);
429 #ifndef QT_MAC_USE_COCOA 430 HIToolbarRef macToolbar = NULL;
431 if ((GetWindowToolbar(window, &macToolbar) == noErr) && !macToolbar) {
433 kHIToolbarItemAllowDuplicates, &macToolbar);
434 InstallEventHandler(HIObjectGetEventTarget(static_cast<HIToolbarRef>(macToolbar)),
437 HIToolbarSetDisplaySize(macToolbar, kHIToolbarDisplaySizeNormal);
438 HIToolbarSetDisplayMode(macToolbar, kHIToolbarDisplayModeIconOnly);
440 if (layoutState.mainWindow->isVisible())
442 CFRelease(macToolbar);
446 NSToolbar *macToolbar = [window
toolbar];
447 if (macToolbar == nil) {
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];
456 if (toolbarIndex != -1) {
457 qtoolbarsInUnifiedToolbarList.removeAt(toolbarIndex);
458 #ifndef QT_MAC_USE_COCOA 459 HIToolbarRemoveItemAtIndex(macToolbar, toolbarIndex);
461 [macToolbar removeItemAtIndex:toolbarIndex];
464 qtoolbarsInUnifiedToolbarList.insert(beforeIndex, toolbar);
467 if (layoutState.mainWindow->windowSurface()) {
469 for (
int i = 0; i < beforeIndex; ++i) {
470 offset.
setX(offset.
x() + qtoolbarsInUnifiedToolbarList.at(i)->size().width());
472 #ifdef QT_MAC_USE_COCOA 473 unifiedSurface->insertToolbar(toolbar, offset);
474 #endif // QT_MAC_USE_COCOA 477 #ifndef QT_MAC_USE_COCOA 480 QCFType<CFArrayRef> array = CFArrayCreate(0, reinterpret_cast<const void **>(&stupidArray),
484 HIToolbarInsertItemAtIndex(macToolbar, outItem, beforeIndex);
486 NSString *toolbarID = kQToolBarNSToolbarIdentifier;
487 toolbarID = [toolbarID stringByAppendingFormat:
@"%p",
toolbar];
488 cocoaItemIDToToolbarHash.insert(qt_mac_NSStringToQString(toolbarID), toolbar);
489 [macToolbar insertItemWithItemIdentifier:toolbarID atIndex:beforeIndex];
493 #ifdef QT_MAC_USE_COCOA 494 void QMainWindowLayout::updateUnifiedToolbarOffset()
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;
503 #endif // QT_MAC_USE_COCOA 509 while (it != unifiedToolbarHash.end()) {
512 bool saveVisible = !toolbar->
isHidden();
520 toolbarSaveState.remove(toolbar);
521 #ifndef QT_MAC_USE_COCOA 523 HIToolbarRemoveItemAtIndex(HIToolbarItemGetToolbar(item),
524 toolbarItemsCopy.indexOf(item));
526 NSToolbarItem *item =
static_cast<NSToolbarItem *
>(it.
key());
528 removeItemAtIndex:toolbarItemsCopy.indexOf(item)];
529 unifiedToolbarHash.remove(item);
530 qtoolbarsInUnifiedToolbarList.removeAll(toolbar);
540 #ifdef QT_MAC_USE_COCOA 543 for (
int i = 0; i < toolbarItemsCopy.size(); ++i) {
544 #ifdef QT_MAC_USE_COCOA 545 NSToolbarItem *item =
static_cast<NSToolbarItem *
>(toolbarItemsCopy.at(i));
548 CFRelease(toolbarItemsCopy.at(i));
550 toolbarItemsCopy.clear();
551 unifiedToolbarHash.clear();
553 #ifdef QT_MAC_USE_COCOA 555 NSToolbar *macToolbar = [window
toolbar];
557 [[macToolbar delegate] release];
558 [macToolbar setDelegate:nil];
565 #ifdef QT_MAC_USE_COCOA 567 NSToolbarItem *item = nil;
568 while (it != unifiedToolbarHash.constEnd()) {
569 if (tb == it.
value()) {
570 item =
static_cast<NSToolbarItem *
>(it.
key());
579 NSSize nssize = NSMakeSize(size.
width(), size.
height());
580 [item setMaxSize:nssize];
583 nssize.height = size.
height();
584 [item setMinSize:nssize];
593 if (blockVisiblityCheck)
596 Q_ASSERT(layoutState.mainWindow->unifiedTitleAndToolBarOnMac());
598 const int ToolBarCount = qtoolbarsInUnifiedToolbarList.count();
599 for (
int i = 0; i < ToolBarCount; ++i) {
600 if (qtoolbarsInUnifiedToolbarList.at(i)->isVisible()) {
const struct __CFString * CFStringRef
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
static CFStringRef kQMainWindowMacToolbarID
#define QT_END_NAMESPACE
This macro expands to.
#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...
void syncUnifiedToolbarVisibility()
T & value() const
Returns a modifiable reference to the current item's value.
void insertIntoMacToolbar(QToolBar *before, QToolBar *after)
void macWindowToolbarSet(void *window, void *toolbarRef)
The QObject class is the base class of all Qt objects.
static HIToolbarItemRef CreateToolbarItemForIdentifier(CFStringRef identifier, CFTypeRef data)
const EventTypeSpec qtoolbarEvents[]
OSWindowRef qt_mac_window_for(const QWidget *)
const Key & key() const
Returns the current item's key.
static CFStringRef kQToolBarHIToolbarItemClassID
int width() const
Returns the width.
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.
#define QT_BEGIN_NAMESPACE
This macro expands to.
const T & at(int i) const
Returns the item at index position i in the list.
struct OpaqueControlRef * HIViewRef
static HIToolbarItemRef createQToolBarInHIToolbarItem(QToolBar *toolbar, QMainWindowLayout *layout)
const T & value() const
Returns the current item's value.
static const char * data(const QByteArray &arr)
QList< QToolBar * > qtoolbarsInUnifiedToolbarList
void clear()
Removes all items from the list.
const Key & key() const
Returns the current item's key as a const reference.
static void qtMacHIToolbarRegisterQToolBarInHIToolborItemClass()
static const EventTypeSpec kToolbarEvents[]
struct OpaqueEventRef * EventRef
static QWidget * parentWidget(const QWidget *w)
HIObjectRef HIToolbarItemRef
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...
QHash< void *, QToolBar * > unifiedToolbarHash
static void GetToolbarAllowedItems(CFMutableArrayRef array)
#define QT_MANGLE_NAMESPACE(name)
static OSStatus qtmacToolbarDelegate(EventHandlerCallRef, EventRef, void *)
The QPoint class defines a point in the plane using integer precision.
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
int size() const
Returns the number of items in the list.
void updateHIToolBarStatus()
struct OpaqueHIObjectRef * HIObjectRef
void macWindowToolbarShow(const QWidget *widget, bool show)
int height() const
Returns the height.
#define kWindowUnifiedTitleAndToolbarAttribute
static const int kEventParamQToolBar
The QSize class defines the size of a two-dimensional object using integer point precision.
struct OpaqueEventHandlerCallRef * EventHandlerCallRef
int x() const
Returns the x coordinate of this point.
void cleanUpMacToolbarItems()
static const int kEventParamQMainWindowLayout
static OSStatus qtoolbarInHIToolbarHandler(EventHandlerCallRef inCallRef, EventRef event, void *data)
void fixSizeInUnifiedToolbar(QToolBar *tb) const
const struct __CFArray * CFArrayRef
void setX(int x)
Sets the x coordinate of this point to the given x coordinate.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
QList< void * > toolbarItemsCopy
static CFStringRef kQToolBarHIToolbarIdentifier
The QList class is a template class that provides lists.
void removeAt(int i)
Removes the item at index position i.