X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/aae0472bf3086707216125e4caa8650caeeeaf97..a20a357d928b6da93bc8b92193471f51a71127ba:/src/motif/toolbar.cpp diff --git a/src/motif/toolbar.cpp b/src/motif/toolbar.cpp index 0841393811..75f4c0fbed 100644 --- a/src/motif/toolbar.cpp +++ b/src/motif/toolbar.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: motif/toolbar.cpp +// Name: src/motif/toolbar.cpp // Purpose: wxToolBar // Author: Julian Smart // Modified by: 13.12.99 by VZ during toolbar classes reorganization @@ -17,19 +17,17 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ - #pragma implementation "toolbar.h" -#endif - -#ifdef __VMS -#define XtDisplay XTDISPLAY -#endif +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" -#include "wx/settings.h" -#include "wx/app.h" -#include "wx/timer.h" #include "wx/toolbar.h" -#include "wx/frame.h" + +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/frame.h" + #include "wx/timer.h" + #include "wx/settings.h" +#endif #ifdef __VMS__ #pragma message disable nosimpint @@ -52,9 +50,7 @@ // wxWin macros // ---------------------------------------------------------------------------- -#if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase) -#endif +IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) // ---------------------------------------------------------------------------- // private functions @@ -97,8 +93,8 @@ public: Init(); } - wxToolBarTool(wxToolBar *tbar, wxControl *control) - : wxToolBarToolBase(tbar, control) + wxToolBarTool(wxToolBar *tbar, wxControl *control, const wxString& label) + : wxToolBarToolBase(tbar, control, label) { Init(); } @@ -131,7 +127,7 @@ protected: // globals // ---------------------------------------------------------------------------- -static wxToolBarTimer* wxTheToolBarTimer = (wxToolBarTimer*) NULL; +static wxToolBarTimer* wxTheToolBarTimer = NULL; Widget wxToolBarTimer::help_popup = (Widget) 0; Widget wxToolBarTimer::buttonWidget = (Widget) 0; @@ -159,9 +155,10 @@ wxToolBarToolBase *wxToolBar::CreateTool(int id, } -wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control) +wxToolBarToolBase * +wxToolBar::CreateTool(wxControl *control, const wxString& label) { - return new wxToolBarTool(this, control); + return new wxToolBarTool(this, control, label); } void wxToolBarTool::Init() @@ -202,9 +199,10 @@ bool wxToolBar::Create(wxWindow *parent, { if( !wxControl::CreateControl( parent, id, pos, size, style, wxDefaultValidator, name ) ) - return FALSE; + return false; + PreCreation(); - m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); + FixupStyle(); Widget parentWidget = (Widget) parent->GetClientWidget(); @@ -229,8 +227,6 @@ bool wxToolBar::Create(wxWindow *parent, m_mainWidget = (WXWidget) toolbar; - ChangeFont(FALSE); - wxPoint rPos = pos; wxSize rSize = size; @@ -239,13 +235,11 @@ bool wxToolBar::Create(wxWindow *parent, if( rSize.x == -1 && GetParent() ) rSize.x = GetParent()->GetSize().x; - SetCanAddEventHandler(TRUE); + PostCreation(); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, rPos.x, rPos.y, rSize.x, rSize.y); - ChangeBackgroundColour(); - - return TRUE; + return true; } wxToolBar::~wxToolBar() @@ -259,7 +253,7 @@ bool wxToolBar::Realize() if ( m_tools.GetCount() == 0 ) { // nothing to do - return TRUE; + return true; } bool isVertical = GetWindowStyle() & wxTB_VERTICAL; @@ -276,13 +270,11 @@ bool wxToolBar::Realize() int buttonHeight = 0, buttonWidth = 0; - int currentSpacing = 0; - Widget button; Pixmap pixmap, insensPixmap; wxBitmap bmp, insensBmp; - wxToolBarToolsList::Node *node = m_tools.GetFirst(); + wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); while ( node ) { wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); @@ -361,8 +353,8 @@ bool wxToolBar::Realize() if( !tool->GetButtonWidget() ) { - DoChangeBackgroundColour((WXWidget) button, - m_backgroundColour, TRUE); + wxDoChangeBackgroundColour((WXWidget) button, + m_backgroundColour, true); tool->SetWidget(button); } @@ -382,7 +374,7 @@ bool wxToolBar::Realize() insensBmp = tool->GetDisabledBitmap(); if ( bmp.GetMask() || insensBmp.GetMask() ) { - int backgroundPixel; + WXPixel backgroundPixel; XtVaGetValues(button, XmNbackground, &backgroundPixel, NULL); @@ -405,7 +397,7 @@ bool wxToolBar::Realize() // Create a selected/toggled bitmap. If there isn't a 2nd // bitmap, we need to create it (with a darker, selected // background) - int backgroundPixel; + WXPixel backgroundPixel; if ( tool->CanBeToggled() ) XtVaGetValues(button, XmNselectColor, &backgroundPixel, NULL); @@ -423,7 +415,7 @@ bool wxToolBar::Realize() (Pixmap)tmp.GetDrawable() : tool->GetInsensPixmap(); } - + if (tool->CanBeToggled()) { // Toggle button @@ -470,7 +462,6 @@ bool wxToolBar::Realize() XtAddEventHandler (button, EnterWindowMask | LeaveWindowMask, False, wxToolButtonPopupCallback, (XtPointer) this); - currentSpacing = 0; break; } @@ -481,7 +472,7 @@ bool wxToolBar::Realize() isVertical ? buttonWidth + 2 * marginX : -1, isVertical ? -1 : buttonHeight + 2*marginY ); - return TRUE; + return true; } wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x), @@ -489,17 +480,17 @@ wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x), { wxFAIL_MSG( _T("TODO") ); - return (wxToolBarToolBase *)NULL; + return NULL; } bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) { tool->Attach(this); - return TRUE; + return true; } -bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) +bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) { tool->Detach(); @@ -508,7 +499,7 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) int packing = GetToolPacking(); int offset = 0; - for( wxToolBarToolsList::Node *node = m_tools.GetFirst(); + for( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); node; node = node->GetNext() ) { wxToolBarTool *t = (wxToolBarTool*)node->GetData(); @@ -523,7 +514,7 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) offset = isVertical ? size.y : size.x; offset += packing; break; - } + } case wxTOOL_STYLE_SEPARATOR: offset = isVertical ? 0 : separatorSize; break; @@ -549,14 +540,14 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) { case wxTOOL_STYLE_CONTROL: { - wxPoint pos = t->GetControl()->GetPosition(); + wxPoint location = t->GetControl()->GetPosition(); if( isVertical ) - pos.y -= offset; + location.y -= offset; else - pos.x -= offset; + location.x -= offset; - t->GetControl()->Move( pos ); + t->GetControl()->Move( location ); break; } case wxTOOL_STYLE_SEPARATOR: @@ -570,9 +561,9 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) NULL ); if( isVertical ) - y -= offset; + y = (Dimension)(y - offset); else - x -= offset; + x = (Dimension)(x - offset); XtVaSetValues( t->GetButtonWidget(), XmNx, x, @@ -584,14 +575,18 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) } } - return TRUE; + return true; } void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable) { wxToolBarTool *tool = (wxToolBarTool *)toolBase; - - XtSetSensitive(tool->GetButtonWidget(), (Boolean) enable); + if (tool->GetButtonWidget()){ + XtSetSensitive(tool->GetButtonWidget(), (Boolean) enable); + } else if (wxTOOL_STYLE_CONTROL == tool->GetStyle()){ + // Controls (such as wxChoice) do not have button widgets + tool->GetControl()->Enable(enable); + } } void wxToolBar::DoToggleTool(wxToolBarToolBase *toolBase, bool toggle) @@ -624,12 +619,12 @@ void wxToolBar::DoSetSize(int x, int y, int width, int height, int sizeFlags) } wxToolBarBase::DoSetSize(x, y, width, height, sizeFlags); - + // We must refresh the frame size when the toolbar changes size // otherwise the toolbar can be shown incorrectly if ( old_width != width || old_height != height ) { - // But before we send the size event check it + // But before we send the size event check it // we have a frame that is not being deleted. wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); if ( frame && !frame->IsBeingDeleted() ) @@ -645,7 +640,7 @@ void wxToolBar::DoSetSize(int x, int y, int width, int height, int sizeFlags) wxToolBarToolBase *wxToolBar::FindToolByWidget(WXWidget w) const { - wxToolBarToolsList::Node* node = m_tools.GetFirst(); + wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); while ( node ) { wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); @@ -657,7 +652,7 @@ wxToolBarToolBase *wxToolBar::FindToolByWidget(WXWidget w) const node = node->GetNext(); } - return (wxToolBarToolBase *)NULL; + return NULL; } static void wxToolButtonCallback(Widget w, @@ -717,7 +712,7 @@ static void wxToolButtonPopupCallback(Widget w, wxToolBarTimer::help_popup = (Widget) 0; // One shot - wxTheToolBarTimer->Start(delayMilli, TRUE); + wxTheToolBarTimer->Start(delayMilli, true); } /************************************************************/ @@ -757,7 +752,7 @@ void wxToolBarTimer::Notify() // Move the tooltip more or less above the button int yOffset = 20; // TODO: What should be really? - y -= yOffset; + y = (Position)(y - yOffset); if (y < yOffset) y = 0; /************************************************************/ @@ -789,4 +784,3 @@ void wxToolBarTimer::Notify() /************************************************************/ XtPopup (help_popup, XtGrabNone); } -