X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9f8845289521c7f53e95b6dfd8275daab8b05639..67193066b2d16ca36529216f70d093690d7e1123:/src/mac/classic/toolbar.cpp diff --git a/src/mac/classic/toolbar.cpp b/src/mac/classic/toolbar.cpp index 1b4b9733d0..b1db448182 100644 --- a/src/mac/classic/toolbar.cpp +++ b/src/mac/classic/toolbar.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: toolbar.cpp +// Name: src/mac/classic/toolbar.cpp // Purpose: wxToolBar // Author: Stefan Csomor // Modified by: @@ -9,27 +9,25 @@ // Licence: The wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "toolbar.h" -#endif - -#include "wx/wx.h" +#include "wx/wxprec.h" #if wxUSE_TOOLBAR #include "wx/toolbar.h" + +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + #include "wx/notebook.h" #include "wx/tabctrl.h" -#include "wx/bitmap.h" -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase) - EVT_MOUSE_EVENTS( wxToolBar::OnMouse ) - EVT_PAINT( wxToolBar::OnPaint ) + EVT_MOUSE_EVENTS( wxToolBar::OnMouse ) + EVT_PAINT( wxToolBar::OnPaint ) END_EVENT_TABLE() -#endif #include "wx/mac/uma.h" #include "wx/geometry.h" @@ -49,19 +47,19 @@ public: wxObject *clientData, const wxString& shortHelp, const wxString& longHelp) ; - + wxToolBarTool(wxToolBar *tbar, wxControl *control) : wxToolBarToolBase(tbar, control) { Init() ; } - + ~wxToolBarTool() { if ( m_controlHandle ) DisposeControl( m_controlHandle ) ; } - + ControlHandle GetControlHandle() { return m_controlHandle ; } void SetControlHandle( ControlHandle handle ) { m_controlHandle = handle ; } @@ -88,9 +86,9 @@ public: wxPoint GetPosition() const { return wxPoint(m_x, m_y); - } + } private : - void Init() + void Init() { m_controlHandle = NULL ; } @@ -125,18 +123,18 @@ void wxToolBarTool::SetPosition(const wxPoint& position) { int x , y ; x = y = 0 ; - WindowRef rootwindow = (WindowRef) GetToolBar()->MacGetRootWindow() ; + WindowRef rootwindow = (WindowRef) GetToolBar()->MacGetRootWindow() ; GetToolBar()->MacWindowToRootWindow( &x , &y ) ; int mac_x = x + position.x ; int mac_y = y + position.y ; - - Rect contrlRect ; - GetControlBounds( m_controlHandle , &contrlRect ) ; + + Rect contrlRect ; + GetControlBounds( m_controlHandle , &contrlRect ) ; int former_mac_x = contrlRect.left ; int former_mac_y = contrlRect.top ; wxSize sz = GetToolBar()->GetToolSize() ; - + if ( mac_x != former_mac_x || mac_y != former_mac_y ) { { @@ -162,42 +160,42 @@ const short kwxMacToolBarTopMargin = 2 ; const short kwxMacToolBarLeftMargin = 2 ; wxToolBarTool::wxToolBarTool(wxToolBar *tbar, - int id, - const wxString& label, - const wxBitmap& bmpNormal, - const wxBitmap& bmpDisabled, - wxItemKind kind, - wxObject *clientData, - const wxString& shortHelp, - const wxString& longHelp) + int id, + const wxString& label, + const wxBitmap& bmpNormal, + const wxBitmap& bmpDisabled, + wxItemKind kind, + wxObject *clientData, + const wxString& shortHelp, + const wxString& longHelp) : wxToolBarToolBase(tbar, id, label, bmpNormal, bmpDisabled, kind, clientData, shortHelp, longHelp) { Init(); - + if (id == wxID_SEPARATOR) return; - - WindowRef window = (WindowRef) tbar->MacGetRootWindow() ; - wxSize toolSize = tbar->GetToolSize() ; + + WindowRef window = (WindowRef) tbar->MacGetRootWindow() ; + wxSize toolSize = tbar->GetToolSize() ; Rect toolrect = { 0, 0 , toolSize.y , toolSize.x } ; - + ControlButtonContentInfo info ; wxMacCreateBitmapButton( &info , GetNormalBitmap() ) ; - + SInt16 behaviour = kControlBehaviorOffsetContents ; if ( CanBeToggled() ) behaviour += kControlBehaviorToggles ; - - if ( info.contentType != kControlNoContent ) + + if ( info.contentType != kControlNoContent ) { - m_controlHandle = ::NewControl( window , &toolrect , "\p" , false , 0 , + m_controlHandle = ::NewControl( window , &toolrect , "\p" , false , 0 , behaviour + info.contentType , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ; - + ::SetControlData( m_controlHandle , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; } else { - m_controlHandle = ::NewControl( window , &toolrect , "\p" , false , 0 , + m_controlHandle = ::NewControl( window , &toolrect , "\p" , false , 0 , behaviour , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ; } UMAShowControl( m_controlHandle ) ; @@ -213,7 +211,7 @@ wxToolBarTool::wxToolBarTool(wxToolBar *tbar, { ::SetControl32BitValue( m_controlHandle , 0 ) ; } - + ControlHandle container = (ControlHandle) tbar->MacGetContainerForEmbedding() ; wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; ::EmbedControl( m_controlHandle , container ) ; @@ -248,12 +246,12 @@ void wxToolBar::Init() bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) -{ +{ int x = pos.x; int y = pos.y; int width = size.x; int height = size.y; - + if (width <= 0) width = 100; if (height <= 0) @@ -262,20 +260,20 @@ bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, cons x = 0; if (y < 0) y = 0; - + SetName(name); - + m_windowStyle = style; parent->AddChild(this); - + m_backgroundColour = parent->GetBackgroundColour() ; m_foregroundColour = parent->GetForegroundColour() ; - - if (id == -1) + + if (id == wxID_ANY) m_windowId = NewControlId(); else m_windowId = id; - + { m_width = size.x ; m_height = size.y ; @@ -285,12 +283,12 @@ bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, cons m_x = x ; m_y = y ; } - - return TRUE; + + return true; } wxToolBar::~wxToolBar() -{ +{ // we must refresh the frame size when the toolbar is deleted but the frame // is not - otherwise toolbar leaves a hole in the place it used to occupy } @@ -298,17 +296,17 @@ wxToolBar::~wxToolBar() bool wxToolBar::Realize() { if (m_tools.GetCount() == 0) - return FALSE; + return false; int x = m_xMargin + kwxMacToolBarLeftMargin ; int y = m_yMargin + kwxMacToolBarTopMargin ; int tw, th; GetSize(& tw, & th); - + int maxWidth = 0 ; int maxHeight = 0 ; - + int maxToolWidth = 0; int maxToolHeight = 0; @@ -332,15 +330,15 @@ bool wxToolBar::Realize() { wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); wxSize cursize = tool->GetSize() ; - + // for the moment we just do a single row/column alignement if ( x + cursize.x > maxWidth ) maxWidth = x + cursize.x ; if ( y + cursize.y > maxHeight ) maxHeight = y + cursize.y ; - + tool->SetPosition( wxPoint( x , y ) ) ; - + if ( GetWindowStyleFlag() & wxTB_VERTICAL ) { y += cursize.y ; @@ -352,7 +350,7 @@ bool wxToolBar::Realize() node = node->GetNext(); } - + if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) { if ( m_maxRows == 0 ) @@ -360,7 +358,7 @@ bool wxToolBar::Realize() // if not set yet, only one row SetRows(1); } - maxWidth = tw ; + maxWidth = tw ; maxHeight += m_yMargin + kwxMacToolBarTopMargin; m_maxHeight = maxHeight ; } @@ -375,11 +373,11 @@ bool wxToolBar::Realize() maxWidth += m_xMargin + kwxMacToolBarLeftMargin; m_maxWidth = maxWidth ; } - + SetSize(maxWidth, maxHeight); InvalidateBestSize(); - - return TRUE; + + return true; } void wxToolBar::SetToolBitmapSize(const wxSize& size) @@ -393,15 +391,15 @@ wxSize wxToolBar::GetToolSize() const return wxSize(m_defaultWidth + 4, m_defaultHeight + 4); } -void wxToolBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ) +void wxToolBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ) { wxToolBarToolsList::Node *node; for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) { - wxToolBarTool* tool = (wxToolBarTool*) node->GetData() ; + wxToolBarTool* tool = (wxToolBarTool*) node->GetData() ; if ( tool->IsButton() ) { - if( tool->GetControlHandle() == control ) + if( (WXWidget) tool->GetControlHandle() == control ) { if ( tool->CanBeToggled() ) { @@ -425,7 +423,7 @@ void wxToolBar::SetRows(int nRows) m_maxRows = nRows; } -void wxToolBar::MacSuperChangedPosition() +void wxToolBar::MacSuperChangedPosition() { wxWindow::MacSuperChangedPosition() ; Realize() ; @@ -497,7 +495,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), tool->Attach(this); InvalidateBestSize(); - return TRUE; + return true; } void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle)) @@ -525,7 +523,7 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) tool->Detach(); // and finally reposition all the controls after this one - + for ( /* node -> first after deleted */ ; node; node = node->GetNext() ) { wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData(); @@ -541,24 +539,24 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) } tool2->SetPosition( pt ) ; } - + InvalidateBestSize(); - return TRUE ; + return true ; } void wxToolBar::OnPaint(wxPaintEvent& event) { wxPaintDC dc(this) ; wxMacPortSetter helper(&dc) ; - - Rect toolbarrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) , + + Rect toolbarrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) , dc.YLOG2DEVMAC(m_height) , dc.XLOG2DEVMAC(m_width) } ; UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; { wxToolBarToolsList::Node *node; for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) { - wxToolBarTool* tool = (wxToolBarTool*) node->GetData() ; + wxToolBarTool* tool = (wxToolBarTool*) node->GetData() ; if ( tool->IsButton() ) { UMADrawControl( tool->GetControlHandle() ) ; @@ -567,41 +565,41 @@ void wxToolBar::OnPaint(wxPaintEvent& event) } } -void wxToolBar::OnMouse( wxMouseEvent &event ) +void wxToolBar::OnMouse( wxMouseEvent &event ) { if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) { - + int x = event.m_x ; int y = event.m_y ; - + MacClientToRootWindow( &x , &y ) ; - + ControlHandle control ; Point localwhere ; SInt16 controlpart ; WindowRef window = (WindowRef) MacGetRootWindow() ; - + localwhere.h = x ; localwhere.v = y ; - + short modifiers = 0; - + if ( !event.m_leftDown && !event.m_rightDown ) modifiers |= btnState ; - + if ( event.m_shiftDown ) modifiers |= shiftKey ; - + if ( event.m_controlDown ) modifiers |= controlKey ; - + if ( event.m_altDown ) modifiers |= optionKey ; - + if ( event.m_metaDown ) modifiers |= cmdKey ; - + controlpart = ::FindControl( localwhere , window , &control ) ; { if ( control && ::IsControlActive( control ) ) @@ -611,7 +609,7 @@ void wxToolBar::OnMouse( wxMouseEvent &event ) wxTheApp->s_lastMouseDown = 0 ; if ( control && controlpart != kControlNoPart ) // otherwise we will get the event twice { - MacHandleControlClick( control , controlpart , false /* not down anymore */ ) ; + MacHandleControlClick( (WXWidget) control , controlpart , false /* not down anymore */ ) ; } } } @@ -620,4 +618,3 @@ void wxToolBar::OnMouse( wxMouseEvent &event ) } #endif // wxUSE_TOOLBAR -