X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5bf565977f9ec437b29ac6fd8ab77fce365f55f2..ab52bac815bed0189bb0ba3b52a15e093c354533:/src/osx/cocoa/toolbar.mm diff --git a/src/osx/cocoa/toolbar.mm b/src/osx/cocoa/toolbar.mm index 1b8b4866fe..70b6de32d0 100644 --- a/src/osx/cocoa/toolbar.mm +++ b/src/osx/cocoa/toolbar.mm @@ -39,10 +39,6 @@ END_EVENT_TABLE() #pragma mark - #pragma mark Tool Implementation -#if wxOSX_USE_COCOA -#define wxOSX_USE_NATIVE_TOOLBAR 1 -#endif - // ---------------------------------------------------------------------------- // private classes // ---------------------------------------------------------------------------- @@ -140,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; @@ -162,6 +158,7 @@ public: void UpdateLabel() { +#if wxOSX_USE_NATIVE_TOOLBAR if ( m_toolbarItem ) { // strip mnemonics from the label for compatibility with the usual @@ -174,6 +171,7 @@ public: wxCFStringRef sh( GetShortHelp(), GetToolBarFontEncoding() ); [m_toolbarItem setToolTip:sh.AsNSString()]; } +#endif } void Action() @@ -256,6 +254,8 @@ private: #endif }; +#if wxOSX_USE_NATIVE_TOOLBAR + @interface wxNSToolbarItem : NSToolbarItem { wxToolBarTool* impl; @@ -284,6 +284,8 @@ private: @end +#endif + @interface wxNSToolBarButton : NSButton { @@ -298,6 +300,8 @@ private: @end +#if wxOSX_USE_NATIVE_TOOLBAR + @implementation wxNSToolbarItem - (id)initWithItemIdentifier: (NSString*) identifier @@ -311,6 +315,7 @@ private: - (void) clickedAction: (id) sender { + wxUnusedVar(sender); if ( impl ) { impl->Action(); @@ -333,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 @@ -374,6 +383,8 @@ private: @end +#endif + @implementation wxNSToolBarButton - (id)initWithFrame:(NSRect)frame @@ -387,6 +398,7 @@ private: - (void) clickedAction: (id) sender { + wxUnusedVar(sender); if ( impl ) { impl->Action(); @@ -627,6 +639,7 @@ wxToolBar::~wxToolBar() if (m_macUsesNativeToolbar) MacInstallNativeToolbar( false ); + [(NSToolbar*)m_macToolbar setDelegate:nil]; [(NSToolbar*)m_macToolbar release]; m_macToolbar = NULL; } @@ -692,7 +705,7 @@ 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]) { @@ -703,9 +716,9 @@ void wxToolBar::DoGetSize( int *width, int *height ) const } 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 ); @@ -777,7 +790,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(); @@ -826,7 +839,7 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative) bool wxToolBar::Realize() { - if (m_tools.GetCount() == 0) + if ( !wxToolBarBase::Realize() ) return false; int maxWidth = 0; @@ -895,7 +908,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) ); @@ -907,7 +920,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; @@ -1000,14 +1013,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; } @@ -1018,7 +1031,7 @@ bool wxToolBar::Realize() SetRows( GetToolsCount() ); m_minHeight = maxHeight; - maxHeight = th; + // maxWidth = tw; maxWidth += m_xMargin + kwxMacToolBarLeftMargin; m_minWidth = m_maxWidth = maxWidth; } @@ -1029,7 +1042,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) @@ -1098,7 +1111,7 @@ void wxToolBar::MacSuperChangedPosition() void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) { - wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id)); + wxToolBarTool* tool = static_cast(FindById(id)); if ( tool ) { wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools.")); @@ -1112,7 +1125,7 @@ void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap ) { - wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id)); + wxToolBarTool* tool = static_cast(FindById(id)); if ( tool ) { wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools.")); @@ -1140,7 +1153,7 @@ wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const node = node->GetNext(); } - return (wxToolBarToolBase*)NULL; + return NULL; } wxString wxToolBar::MacGetToolTipString( wxPoint &pt ) @@ -1167,7 +1180,7 @@ void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle) bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) { - wxToolBarTool *tool = wx_static_cast( wxToolBarTool*, toolBase ); + wxToolBarTool *tool = static_cast< wxToolBarTool*>(toolBase ); if (tool == NULL) return false; @@ -1192,7 +1205,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; @@ -1258,7 +1271,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() ); @@ -1299,7 +1312,7 @@ void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(tog bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase) { - wxToolBarTool* tool = wx_static_cast( wxToolBarTool*, toolbase ); + wxToolBarTool* tool = static_cast< wxToolBarTool*>(toolbase ); wxToolBarToolsList::compatibility_iterator node; for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) { @@ -1339,7 +1352,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;