X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d3b9f782ef3949f583e8ac53795d36787f044fc3..eb087029329fab4b9d4d956b525eba752ee8d5e3:/src/osx/cocoa/toolbar.mm diff --git a/src/osx/cocoa/toolbar.mm b/src/osx/cocoa/toolbar.mm index 50ff8949a4..0add59ad00 100644 --- a/src/osx/cocoa/toolbar.mm +++ b/src/osx/cocoa/toolbar.mm @@ -136,7 +136,7 @@ public: { // separator size curSize = GetToolBar()->GetToolSize(); - if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL ) + if ( GetToolBar()->GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) ) curSize.y /= 4; else curSize.x /= 4; @@ -153,9 +153,9 @@ public: bool DoEnable( bool enable ); void UpdateImages(); - + void UpdateToggleImage( bool toggle ); - + void UpdateLabel() { #if wxOSX_USE_NATIVE_TOOLBAR @@ -167,7 +167,7 @@ public: wxCFStringRef l(labelStr, GetToolBarFontEncoding()); [m_toolbarItem setLabel:l.AsNSString()]; - + wxCFStringRef sh( GetShortHelp(), GetToolBarFontEncoding() ); [m_toolbarItem setToolTip:sh.AsNSString()]; } @@ -187,7 +187,7 @@ public: tbar->OnLeftClick( GetId(), IsToggled() ); } - + #if wxOSX_USE_NATIVE_TOOLBAR void SetToolbarItemRef( NSToolbarItem* ref ) { @@ -269,12 +269,12 @@ private: @end -@interface wxNSToolbarDelegate : NSObject +@interface wxNSToolbarDelegate : NSObject wxOSX_10_6_AND_LATER() { } - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag; - + - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar; - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar; @@ -315,6 +315,7 @@ private: - (void) clickedAction: (id) sender { + wxUnusedVar(sender); if ( impl ) { impl->Action(); @@ -337,21 +338,25 @@ private: - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar { + wxUnusedVar(toolbar); return nil; } - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar { + wxUnusedVar(toolbar); return nil; } - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar { + wxUnusedVar(toolbar); return nil; } - (NSToolbarItem*) toolbar:(NSToolbar*) toolbar itemForItemIdentifier:(NSString*) itemIdentifier willBeInsertedIntoToolbar:(BOOL) flag { + wxUnusedVar(toolbar); #ifdef __LP64__ wxToolBarTool* tool = (wxToolBarTool*) [itemIdentifier longLongValue]; #else @@ -393,6 +398,7 @@ private: - (void) clickedAction: (id) sender { + wxUnusedVar(sender); if ( impl ) { impl->Action(); @@ -473,7 +479,7 @@ void wxToolBarTool::SetPosition( const wxPoint& position ) frame.origin.y = mac_y; [m_controlHandle setFrame:frame]; } - } + } } void wxToolBarTool::UpdateImages() @@ -493,7 +499,7 @@ void wxToolBarTool::UpdateImages() dc.DrawRectangle( 0, 0, w, h ); dc.DrawBitmap( m_bmpNormal, 0, 0, true ); dc.SelectObject( wxNullBitmap ); - + [(NSButton*) m_controlHandle setAlternateImage:m_alternateBitmap.GetNSImage()]; } UpdateToggleImage( CanBeToggled() && IsToggled() ); @@ -592,19 +598,19 @@ bool wxToolBar::Create( if (parent->IsKindOf(CLASSINFO(wxFrame)) && wxSystemOptions::GetOptionInt(wxT("mac.toolbar.no-native")) != 1) { static wxNSToolbarDelegate* controller = nil; - + if ( controller == nil ) controller = [[wxNSToolbarDelegate alloc] init]; wxString identifier = wxString::Format( wxT("%p"), this ); wxCFStringRef cfidentifier(identifier); NSToolbar* tb = [[NSToolbar alloc] initWithIdentifier:cfidentifier.AsNSString()]; - + m_macToolbar = tb ; - + if (m_macToolbar != NULL) { [tb setDelegate:controller]; - + NSToolbarDisplayMode mode = NSToolbarDisplayModeDefault; NSToolbarSizeMode displaySize = NSToolbarSizeModeSmall; @@ -625,18 +631,10 @@ bool wxToolBar::Create( } wxToolBar::~wxToolBar() -{ -#if wxOSX_USE_NATIVE_TOOLBAR - if (m_macToolbar != NULL) - { - // if this is the installed toolbar, then deinstall it - if (m_macUsesNativeToolbar) - MacInstallNativeToolbar( false ); - - [(NSToolbar*)m_macToolbar release]; - m_macToolbar = NULL; - } -#endif +{ + [(NSToolbar*)m_macToolbar setDelegate:nil]; + [(NSToolbar*)m_macToolbar release]; + m_macToolbar = NULL; } bool wxToolBar::Show( bool show ) @@ -698,8 +696,8 @@ void wxToolBar::DoGetSize( int *width, int *height ) const { WXWindow tlw = MacGetTopLevelWindowRef(); float toolbarHeight = 0.0; - NSRect windowFrame; - + NSRect windowFrame = NSMakeRect(0, 0, 0, 0); + if(m_macToolbar && [(NSToolbar*)m_macToolbar isVisible]) { windowFrame = [NSWindow contentRectForFrameRect:[tlw frame] @@ -707,11 +705,11 @@ void wxToolBar::DoGetSize( int *width, int *height ) const toolbarHeight = NSHeight(windowFrame) - NSHeight([[tlw contentView] frame]); } - + if ( width != NULL ) - *width = windowFrame.size.width; + *width = (int)windowFrame.size.width; if ( height != NULL ) - *height = toolbarHeight; + *height = (int)toolbarHeight; } else wxToolBarBase::DoGetSize( width, height ); @@ -783,7 +781,7 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative) if (usesNative && (m_macToolbar == NULL)) return bResult; - if (usesNative && ((GetWindowStyleFlag() & wxTB_VERTICAL) != 0)) + if (usesNative && ((GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT|wxTB_BOTTOM)) != 0)) return bResult; WXWindow tlw = MacGetTopLevelWindowRef(); @@ -803,7 +801,7 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative) bResult = true; [tlw setToolbar:(NSToolbar*) m_macToolbar]; [(NSToolbar*) m_macToolbar setVisible:YES]; - + m_peer->Move(0,0,0,0 ); SetSize( wxSIZE_AUTO_WIDTH, 0 ); m_peer->SetVisibility( false ); @@ -817,7 +815,7 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative) { bResult = true; [(NSToolbar*) m_macToolbar setVisible:NO]; - [tlw setToolbar:nil]; + MacUninstallNativeToolbar(); m_peer->SetVisibility( true ); } } @@ -828,11 +826,21 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative) // wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") ); return bResult; } + +void wxToolBar::MacUninstallNativeToolbar() +{ + if (!m_macToolbar) + return; + + WXWindow tlw = MacGetTopLevelWindowRef(); + if (tlw) + [tlw setToolbar:nil]; +} #endif bool wxToolBar::Realize() { - if (m_tools.GetCount() == 0) + if ( !wxToolBarBase::Realize() ) return false; int maxWidth = 0; @@ -901,7 +909,7 @@ bool wxToolBar::Realize() if ( y + cursize.y > maxHeight ) maxHeight = y + cursize.y; - if ( GetWindowStyleFlag() & wxTB_VERTICAL ) + if ( GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) ) { int x1 = x + ( maxToolWidth - cursize.x ) / 2; tool->SetPosition( wxPoint(x1, y) ); @@ -913,7 +921,7 @@ bool wxToolBar::Realize() } // update the item positioning state - if ( GetWindowStyleFlag() & wxTB_VERTICAL ) + if ( GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) ) y += cursize.y + kwxMacToolSpacing; else x += cursize.x + kwxMacToolSpacing; @@ -953,10 +961,21 @@ bool wxToolBar::Realize() } } } - wxString identifier = wxString::Format( wxT("%ld"), (long) tool ); - wxCFStringRef cfidentifier(identifier); - [refTB insertItemWithItemIdentifier:cfidentifier.AsNSString() atIndex:currentPosition]; + wxCFStringRef cfidentifier; + const NSString *nsItemId; + if (tool->GetStyle() == wxTOOL_STYLE_SEPARATOR) + { + nsItemId = tool->IsStretchable() ? NSToolbarFlexibleSpaceItemIdentifier + : NSToolbarSeparatorItemIdentifier; + } + else + { + cfidentifier = wxCFStringRef(wxString::Format("%ld", (long)tool)); + nsItemId = cfidentifier.AsNSString(); + } + + [refTB insertItemWithItemIdentifier:nsItemId atIndex:currentPosition]; tool->SetIndex( currentPosition ); } @@ -1006,14 +1025,14 @@ bool wxToolBar::Realize() node = node->GetNext(); } - if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) + if ( GetWindowStyleFlag() & (wxTB_TOP|wxTB_BOTTOM) ) { // if not set yet, only one row if ( m_maxRows <= 0 ) SetRows( 1 ); m_minWidth = maxWidth; - maxWidth = tw; + // maxHeight = th; maxHeight += m_yMargin + kwxMacToolBarTopMargin; m_minHeight = m_maxHeight = maxHeight; } @@ -1024,7 +1043,7 @@ bool wxToolBar::Realize() SetRows( GetToolsCount() ); m_minHeight = maxHeight; - maxHeight = th; + // maxWidth = tw; maxWidth += m_xMargin + kwxMacToolBarLeftMargin; m_minWidth = m_maxWidth = maxWidth; } @@ -1035,7 +1054,7 @@ bool wxToolBar::Realize() bool wantNativeToolbar, ownToolbarInstalled; // attempt to install the native toolbar - wantNativeToolbar = ((GetWindowStyleFlag() & wxTB_VERTICAL) == 0); + wantNativeToolbar = ((GetWindowStyleFlag() & (wxTB_LEFT|wxTB_BOTTOM|wxTB_RIGHT)) == 0); MacInstallNativeToolbar( wantNativeToolbar ); (void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled ); if (!ownToolbarInstalled) @@ -1198,7 +1217,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) wxASSERT( tool->GetControlHandle() == NULL ); toolSize.x /= 4; toolSize.y /= 4; - if ( GetWindowStyleFlag() & wxTB_VERTICAL ) + if ( GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) ) toolrect.size.height = toolSize.y; else toolrect.size.width = toolSize.x; @@ -1207,7 +1226,10 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) #if wxOSX_USE_NATIVE_TOOLBAR if (m_macToolbar != NULL) { - NSToolbarItem* item = [[NSToolbarItem alloc] initWithItemIdentifier:NSToolbarSeparatorItemIdentifier]; + const NSString * const + nsItemId = tool->IsStretchable() ? NSToolbarFlexibleSpaceItemIdentifier + : NSToolbarSeparatorItemIdentifier; + NSToolbarItem* item = [[NSToolbarItem alloc] initWithItemIdentifier:nsItemId]; tool->SetToolbarItemRef( item ); } #endif // wxOSX_USE_NATIVE_TOOLBAR @@ -1229,9 +1251,9 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) [v setBordered:NO]; [v setButtonType: ( tool->CanBeToggled() ? NSOnOffButton : NSMomentaryPushInButton )]; [v setImplementation:tool]; - + controlHandle = v; - + #if wxOSX_USE_NATIVE_TOOLBAR if (m_macToolbar != NULL) { @@ -1264,7 +1286,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) if (m_macToolbar != NULL) { WXWidget view = (WXWidget) tool->GetControl()->GetHandle() ; - wxCHECK_MSG( view, false, _T("control must be non-NULL") ); + wxCHECK_MSG( view, false, wxT("control must be non-NULL") ); wxString identifier = wxString::Format(wxT("%ld"), (long) tool); wxCFStringRef cfidentifier( identifier, wxFont::GetDefaultEncoding() ); @@ -1345,7 +1367,7 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase) wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData(); wxPoint pt = tool2->GetPosition(); - if ( GetWindowStyleFlag() & wxTB_VERTICAL ) + if ( GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) ) pt.y -= sz.y; else pt.x -= sz.x;