X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2bed17c862db626a40bfb981cb8d2bfed17b2737..c937bcac0fb8a8df7c0cbfc8c478a2874fec3eb9:/src/osx/carbon/toolbar.cpp diff --git a/src/osx/carbon/toolbar.cpp b/src/osx/carbon/toolbar.cpp index f1ff79cd4c..9f969bea5c 100644 --- a/src/osx/carbon/toolbar.cpp +++ b/src/osx/carbon/toolbar.cpp @@ -145,7 +145,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; @@ -167,14 +167,14 @@ public: { if ( wxToolBarToolBase::Toggle( toggle ) == false ) return false; - + UpdateToggleImage(toggle); return true; } - + void UpdateHelpStrings() { -#if wxOSX_USE_NATIVE_TOOLBAR +#if wxOSX_USE_NATIVE_TOOLBAR if ( m_toolbarItemRef ) { wxFontEncoding enc = GetToolBarFontEncoding(); @@ -186,16 +186,16 @@ public: } #endif } - + virtual bool SetShortHelp(const wxString& help) { if ( wxToolBarToolBase::SetShortHelp( help ) == false ) return false; - - UpdateHelpStrings(); + + UpdateHelpStrings(); return true; } - + virtual bool SetLongHelp(const wxString& help) { if ( wxToolBarToolBase::SetLongHelp( help ) == false ) @@ -205,12 +205,12 @@ public: return true; } - virtual void SetNormalBitmap(const wxBitmap& bmp) + virtual void SetNormalBitmap(const wxBitmap& bmp) { wxToolBarToolBase::SetNormalBitmap(bmp); UpdateToggleImage(CanBeToggled() && IsToggled()); } - + virtual void SetLabel(const wxString& label) { wxToolBarToolBase::SetLabel(label); @@ -429,7 +429,7 @@ bool wxToolBarTool::Enable( bool enable ) { if ( wxToolBarToolBase::Enable( enable ) == false ) return false; - + if ( IsControl() ) { GetControl()->Enable( enable ); @@ -501,16 +501,20 @@ void wxToolBarTool::UpdateToggleImage( bool toggle ) { if ( toggle ) { - int w = m_bmpNormal.GetWidth(); - int h = m_bmpNormal.GetHeight(); + int w = m_bmpNormal.GetWidth() + 6; + int h = m_bmpNormal.GetHeight() + 6; wxBitmap bmp( w, h ); wxMemoryDC dc; dc.SelectObject( bmp ); - dc.SetPen( wxPen(*wxBLACK) ); - dc.SetBrush( wxBrush( *wxLIGHT_GREY )); - dc.DrawRectangle( 0, 0, w, h ); - dc.DrawBitmap( m_bmpNormal, 0, 0, true ); + wxColour mid_grey_75 = wxColour(128, 128, 128, 196); + wxColour light_grey_75 = wxColour(196, 196, 196, 196); + dc.GradientFillLinear( wxRect(1, 1, w - 1, h-1), + light_grey_75, mid_grey_75, wxNORTH); + wxColour black_50 = wxColour(0, 0, 0, 127); + dc.SetPen( wxPen(black_50) ); + dc.DrawRoundedRectangle( 0, 0, w, h, 1.5 ); + dc.DrawBitmap( m_bmpNormal, 3, 3, true ); dc.SelectObject( wxNullBitmap ); ControlButtonContentInfo info; wxMacCreateBitmapButton( &info, bmp ); @@ -1081,7 +1085,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; WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef()); @@ -1104,8 +1108,16 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative) bResult = true; SetWindowToolbar( tlw, (HIToolbarRef) m_macToolbar ); + + // ShowHideWindowToolbar will make the wxFrame grow + // which we don't want in this case + wxSize sz = GetParent()->GetSize(); ShowHideWindowToolbar( tlw, true, false ); + // Restore the orginal size + GetParent()->SetSize( sz ); + ChangeWindowAttributes( tlw, kWindowToolbarButtonAttribute, 0 ); + SetAutomaticControlDragTrackingEnabledForWindow( tlw, true ); m_peer->Move(0,0,0,0 ); @@ -1139,9 +1151,11 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative) bool wxToolBar::Realize() { - if (m_tools.GetCount() == 0) + if ( !wxToolBarBase::Realize() ) return false; + wxSize tlw_sz = GetParent()->GetSize(); + int maxWidth = 0; int maxHeight = 0; @@ -1208,7 +1222,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) ); @@ -1220,7 +1234,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; @@ -1349,14 +1363,16 @@ bool wxToolBar::Realize() node = node->GetNext(); } - if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) + if (m_macUsesNativeToolbar) + GetParent()->SetSize( tlw_sz ); + + 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 += m_yMargin + kwxMacToolBarTopMargin; m_minHeight = m_maxHeight = maxHeight; } @@ -1367,7 +1383,6 @@ bool wxToolBar::Realize() SetRows( GetToolsCount() ); m_minHeight = maxHeight; - maxHeight = th; maxWidth += m_xMargin + kwxMacToolBarLeftMargin; m_minWidth = m_maxWidth = maxWidth; } @@ -1378,7 +1393,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) @@ -1447,7 +1462,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.")); @@ -1461,7 +1476,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.")); @@ -1489,7 +1504,7 @@ wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const node = node->GetNext(); } - return (wxToolBarToolBase*)NULL; + return NULL; } wxString wxToolBar::MacGetToolTipString( wxPoint &pt ) @@ -1506,14 +1521,14 @@ void wxToolBar::DoEnableTool(wxToolBarToolBase *WXUNUSED(t), bool WXUNUSED(enabl // everything already done in the tool's implementation } -void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle) +void wxToolBar::DoToggleTool(wxToolBarToolBase *WXUNUSED(t), bool WXUNUSED(toggle)) { // everything already done in the tool's implementation } 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; @@ -1540,7 +1555,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.bottom = toolSize.y; else toolrect.right = toolSize.x; @@ -1638,7 +1653,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) #if wxOSX_USE_NATIVE_TOOLBAR if (m_macToolbar != NULL) { - wxCHECK_MSG( tool->GetControl(), false, _T("control must be non-NULL") ); + wxCHECK_MSG( tool->GetControl(), false, wxT("control must be non-NULL") ); HIToolbarItemRef item; HIViewRef viewRef = (HIViewRef) tool->GetControl()->GetHandle() ; CFDataRef data = CFDataCreate( kCFAllocatorDefault , (UInt8*) &viewRef , sizeof(viewRef) ) ; @@ -1697,7 +1712,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() ) { @@ -1737,7 +1752,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;