X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/062b84dd49ed5d6f494727df9db9d43d20928dda..39bc0347fda3505f7fb43447f21efd84b9e00b3c:/src/common/tbarbase.cpp diff --git a/src/common/tbarbase.cpp b/src/common/tbarbase.cpp index edfff6c1f2..a8ada3fa9b 100644 --- a/src/common/tbarbase.cpp +++ b/src/common/tbarbase.cpp @@ -1,8 +1,8 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: common/tbarbase.cpp +// Name: src/common/tbarbase.cpp // Purpose: wxToolBarBase implementation // Author: Julian Smart -// Modified by: VZ at 11.12.99 (wxScrollableToolBar splitted off) +// Modified by: VZ at 11.12.99 (wxScrollableToolBar split off) // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "tbarbase.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -30,16 +26,17 @@ #if wxUSE_TOOLBAR +#include "wx/toolbar.h" + #ifndef WX_PRECOMP #include "wx/control.h" + #include "wx/frame.h" + #include "wx/settings.h" + #if WXWIN_COMPATIBILITY_2_8 + #include "wx/image.h" + #endif // WXWIN_COMPATIBILITY_2_8 #endif -#include "wx/frame.h" -#include "wx/image.h" -#include "wx/settings.h" - -#include "wx/toolbar.h" - // ---------------------------------------------------------------------------- // wxWidgets macros // ---------------------------------------------------------------------------- @@ -49,7 +46,7 @@ END_EVENT_TABLE() #include "wx/listimpl.cpp" -WX_DEFINE_LIST(wxToolBarToolsList); +WX_DEFINE_LIST(wxToolBarToolsList) // ============================================================================ // implementation @@ -114,30 +111,6 @@ bool wxToolBarToolBase::SetLongHelp(const wxString& help) return true; } -#if WXWIN_COMPATIBILITY_2_2 - -const wxBitmap& wxToolBarToolBase::GetBitmap1() const -{ - return GetNormalBitmap(); -} - -const wxBitmap& wxToolBarToolBase::GetBitmap2() const -{ - return GetDisabledBitmap(); -} - -void wxToolBarToolBase::SetBitmap1(const wxBitmap& bmp) -{ - SetNormalBitmap(bmp); -} - -void wxToolBarToolBase::SetBitmap2(const wxBitmap& bmp) -{ - SetDisabledBitmap(bmp); -} - -#endif // WXWIN_COMPATIBILITY_2_2 - // ---------------------------------------------------------------------------- // wxToolBarBase adding/deleting items // ---------------------------------------------------------------------------- @@ -152,6 +125,15 @@ wxToolBarBase::wxToolBarBase() m_defaultHeight = 15; } +void wxToolBarBase::FixupStyle() +{ + if ( !HasFlag(wxTB_TOP | wxTB_LEFT | wxTB_RIGHT | wxTB_BOTTOM) ) + { + // this is the default + m_windowStyle |= wxTB_TOP; + } +} + wxToolBarToolBase *wxToolBarBase::DoAddTool(int id, const wxString& label, const wxBitmap& bitmap, @@ -215,12 +197,16 @@ wxToolBarBase::InsertTool(size_t pos, wxToolBarToolBase *tool) return tool; } -wxToolBarToolBase *wxToolBarBase::AddControl(wxControl *control) +wxToolBarToolBase * +wxToolBarBase::AddControl(wxControl *control, const wxString& label) { - return InsertControl(GetToolsCount(), control); + return InsertControl(GetToolsCount(), control, label); } -wxToolBarToolBase *wxToolBarBase::InsertControl(size_t pos, wxControl *control) +wxToolBarToolBase * +wxToolBarBase::InsertControl(size_t pos, + wxControl *control, + const wxString& label) { wxCHECK_MSG( control, (wxToolBarToolBase *)NULL, _T("toolbar: can't insert NULL control") ); @@ -231,7 +217,7 @@ wxToolBarToolBase *wxToolBarBase::InsertControl(size_t pos, wxControl *control) wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, _T("invalid position in wxToolBar::InsertControl()") ); - wxToolBarToolBase *tool = CreateTool(control); + wxToolBarToolBase *tool = CreateTool(control, label); if ( !InsertTool(pos, tool) ) { @@ -402,14 +388,14 @@ void wxToolBarBase::UnToggleRadioGroup(wxToolBarToolBase *tool) wxToolBarToolsList::compatibility_iterator nodeNext = node->GetNext(); while ( nodeNext ) { - wxToolBarToolBase *tool = nodeNext->GetData(); + wxToolBarToolBase *toolNext = nodeNext->GetData(); - if ( !tool->IsButton() || tool->GetKind() != wxITEM_RADIO ) + if ( !toolNext->IsButton() || toolNext->GetKind() != wxITEM_RADIO ) break; - if ( tool->Toggle(false) ) + if ( toolNext->Toggle(false) ) { - DoToggleTool(tool, false); + DoToggleTool(toolNext, false); } nodeNext = nodeNext->GetNext(); @@ -418,14 +404,14 @@ void wxToolBarBase::UnToggleRadioGroup(wxToolBarToolBase *tool) wxToolBarToolsList::compatibility_iterator nodePrev = node->GetPrevious(); while ( nodePrev ) { - wxToolBarToolBase *tool = nodePrev->GetData(); + wxToolBarToolBase *toolNext = nodePrev->GetData(); - if ( !tool->IsButton() || tool->GetKind() != wxITEM_RADIO ) + if ( !toolNext->IsButton() || toolNext->GetKind() != wxITEM_RADIO ) break; - if ( tool->Toggle(false) ) + if ( toolNext->Toggle(false) ) { - DoToggleTool(tool, false); + DoToggleTool(toolNext, false); } nodePrev = nodePrev->GetPrevious(); @@ -434,7 +420,10 @@ void wxToolBarBase::UnToggleRadioGroup(wxToolBarToolBase *tool) void wxToolBarBase::ClearTools() { - WX_CLEAR_LIST(wxToolBarToolsList, m_tools); + while ( GetToolsCount() ) + { + DeleteToolByPos(0); + } } bool wxToolBarBase::Realize() @@ -448,7 +437,7 @@ wxToolBarBase::~wxToolBarBase() // notify the frame that it doesn't have a tool bar any longer to avoid // dangling pointers - wxFrameBase *frame = wxDynamicCast(GetParent(), wxFrameBase); + wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); if ( frame && frame->GetToolBar() == this ) { frame->SetToolBar(NULL); @@ -660,6 +649,10 @@ void wxToolBarBase::UpdateWindowUI(long flags) { wxWindowBase::UpdateWindowUI(flags); + // don't waste time updating state of tools in a hidden toolbar + if ( !IsShown() ) + return; + // There is no sense in updating the toolbar UI // if the parent window is about to get destroyed wxWindow *tlw = wxGetTopLevelParent( this ); @@ -691,75 +684,19 @@ void wxToolBarBase::UpdateWindowUI(long flags) } } -// Helper function, used by wxCreateGreyedImage - -static void wxGreyOutImage( const wxImage& src, - wxImage& dest, - const wxColour& darkCol, - const wxColour& lightCol, - const wxColour& bgCol ) -{ - // Second attempt, just making things monochrome - int width = src.GetWidth(); - int height = src.GetHeight(); - - int redCur, greenCur, blueCur; - for ( int x = 0; x < width; x++ ) - { - for ( int y = 1; y < height; y++ ) - { - redCur = src.GetRed(x, y); - greenCur = src.GetGreen(x, y); - blueCur = src.GetBlue(x, y); - - // Change light things to the background colour - if ( redCur >= (lightCol.Red() - 50) && greenCur >= (lightCol.Green() - 50) && blueCur >= (lightCol.Blue() - 50) ) - { - dest.SetRGB(x,y, bgCol.Red(), bgCol.Green(), bgCol.Blue()); - } - else if ( redCur == bgCol.Red() && greenCur == bgCol.Green() && blueCur == bgCol.Blue() ) - { - // Leave the background colour as-is - // dest.SetRGB(x,y, bgCol.Red(), bgCol.Green(), bgCol.Blue()); - } - else // if ( redCur <= darkCol.Red() && greenCur <= darkCol.Green() && blueCur <= darkCol.Blue() ) - { - // Change dark things to really dark - dest.SetRGB(x,y, darkCol.Red(), darkCol.Green(), darkCol.Blue()); - } - } - } -} - -/* - * Make a greyed-out image suitable for disabled buttons. - * This code is adapted from wxNewBitmapButton in FL. - */ +#if WXWIN_COMPATIBILITY_2_8 bool wxCreateGreyedImage(const wxImage& in, wxImage& out) { - out = in.Copy(); +#if wxUSE_IMAGE + out = in.ConvertToGreyscale(); + if ( out.Ok() ) + return true; +#endif // wxUSE_IMAGE - unsigned char r, g, b; - if ( in.HasMask() ) - { - in.GetOrFindMaskColour(&r, &g, &b); - } - else // assuming the pixels along the edges are of the background color - { - r = in.GetRed(0, 0); - g = in.GetGreen(0, 0); - b = in.GetBlue(0, 0); - } - - wxColour bgCol(r, g, b); - - wxColour darkCol = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW) ; - wxColour lightCol = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT) ; - - wxGreyOutImage(in, out, darkCol, lightCol, bgCol); - - return true; + return false; } +#endif // WXWIN_COMPATIBILITY_2_8 + #endif // wxUSE_TOOLBAR