X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/24998710952312c2cc1a5bfee1b416783e17319a..e2c922f53f6a8f08e8a82817c75981822dbe9ca1:/src/msw/tbar95.cpp diff --git a/src/msw/tbar95.cpp b/src/msw/tbar95.cpp index 836a79ee2f..304a161756 100644 --- a/src/msw/tbar95.cpp +++ b/src/msw/tbar95.cpp @@ -5,8 +5,8 @@ // Modified by: // Created: 04/01/98 // RCS-ID: $Id$ -// Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Copyright: (c) Julian Smart +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -17,7 +17,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "tbar95.h" #endif @@ -49,30 +49,11 @@ #include "wx/msw/private.h" -#ifndef __TWIN32__ +// include "properly" +#include "wx/msw/wrapcctl.h" -#if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__)) - #include -#else - #include "wx/msw/gnuwin32/extra.h" -#endif - -#endif // __TWIN32__ - -#include "wx/msw/dib.h" #include "wx/app.h" // for GetComCtl32Version -#if defined(__MWERKS__) && defined(__WXMSW__) -// including for max definition doesn't seem -// to work using CodeWarrior 6 Windows. So we define it -// here. (Otherwise we get a undefined identifier 'max' -// later on in this file.) (Added by dimitri@shortcut.nl) -# ifndef max -# define max(a,b) (((a) > (b)) ? (a) : (b)) -# endif - -#endif - // ---------------------------------------------------------------------------- // conditional compilation // ---------------------------------------------------------------------------- @@ -126,7 +107,26 @@ // wxWin macros // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase) +IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) + +/* + TOOLBAR PROPERTIES + tool + bitmap + bitmap2 + tooltip + longhelp + radio (bool) + toggle (bool) + separator + style ( wxNO_BORDER | wxTB_HORIZONTAL) + bitmapsize + margins + packing + separation + + dontattachtoframe +*/ BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase) EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent) @@ -181,6 +181,8 @@ public: private: size_t m_nSepCount; + + DECLARE_NO_COPY_CLASS(wxToolBarTool) }; @@ -238,7 +240,7 @@ bool wxToolBar::Create(wxWindow *parent, return FALSE; // MSW-specific initialisation - if ( !MSWCreateToolbar(pos, size, style) ) + if ( !MSWCreateToolbar(pos, size) ) return FALSE; // set up the colors and fonts @@ -248,11 +250,9 @@ bool wxToolBar::Create(wxWindow *parent, return TRUE; } -bool wxToolBar::MSWCreateToolbar(const wxPoint& pos, - const wxSize& size, - long style) +bool wxToolBar::MSWCreateToolbar(const wxPoint& pos, const wxSize& size) { - if ( !MSWCreateControl(TOOLBARCLASSNAME, _T(""), pos, size, style) ) + if ( !MSWCreateControl(TOOLBARCLASSNAME, wxEmptyString, pos, size) ) return FALSE; // toolbar-specific post initialisation @@ -276,7 +276,7 @@ void wxToolBar::Recreate() UnsubclassWin(); - if ( !MSWCreateToolbar(pos, size, GetWindowStyle()) ) + if ( !MSWCreateToolbar(pos, size) ) { // what can we do? wxFAIL_MSG( _T("recreating the toolbar failed") ); @@ -285,7 +285,7 @@ void wxToolBar::Recreate() } // reparent all our children under the new toolbar - for ( wxWindowList::Node *node = m_children.GetFirst(); + for ( wxWindowList::compatibility_iterator node = m_children.GetFirst(); node; node = node->GetNext() ) { @@ -347,7 +347,7 @@ WXDWORD wxToolBar::MSWGetStyle(long style, WXDWORD *exstyle) const // do have tooltips wouldn't work msStyle |= TBSTYLE_TOOLTIPS; - if ( style & wxTB_FLAT ) + if ( style & (wxTB_FLAT | wxTB_HORZ_LAYOUT) ) { // static as it doesn't change during the program lifetime static int s_verComCtl = wxTheApp->GetComCtl32Version(); @@ -360,6 +360,11 @@ WXDWORD wxToolBar::MSWGetStyle(long style, WXDWORD *exstyle) const { msStyle |= TBSTYLE_FLAT | TBSTYLE_TRANSPARENT; } + + if ( s_verComCtl >= 470 && style & wxTB_HORZ_LAYOUT ) + { + msStyle |= TBSTYLE_LIST; + } } if ( style & wxTB_NODIVIDER ) @@ -368,6 +373,9 @@ WXDWORD wxToolBar::MSWGetStyle(long style, WXDWORD *exstyle) const if ( style & wxTB_NOALIGN ) msStyle |= CCS_NOPARENTALIGN; + if ( style & wxTB_VERTICAL ) + msStyle |= CCS_VERT; + return msStyle; } @@ -393,7 +401,7 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) // first determine the position of the first button to delete: it may be // different from pos if we use several separators to cover the space used // by a control - wxToolBarToolsList::Node *node; + wxToolBarToolsList::compatibility_iterator node; for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) { wxToolBarToolBase *tool2 = node->GetData(); @@ -472,9 +480,19 @@ bool wxToolBar::Realize() const bool isVertical = HasFlag(wxTB_VERTICAL); + // delete all old buttons, if any + for ( size_t pos = 0; pos < m_nButtons; pos++ ) + { + if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, 0, 0) ) + { + wxLogDebug(wxT("TB_DELETEBUTTON failed")); + } + } + // First, add the bitmap: we use one bitmap for all toolbar buttons // ---------------------------------------------------------------- + wxToolBarToolsList::compatibility_iterator node; int bitmapId = 0; wxSize sizeBmp; @@ -531,9 +549,7 @@ bool wxToolBar::Realize() // the number of buttons (not separators) int nButtons = 0; - for ( wxToolBarToolsList::Node *node = m_tools.GetFirst(); - node; - node = node->GetNext() ) + for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) { wxToolBarToolBase *tool = node->GetData(); if ( tool->IsButton() ) @@ -613,15 +629,6 @@ bool wxToolBar::Realize() bitmapId = m_nButtons; } - - // Now delete all the buttons - for ( size_t pos = 0; pos < m_nButtons; pos++ ) - { - if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, 0, 0) ) - { - wxLogDebug(wxT("TB_DELETEBUTTON failed")); - } - } } if ( addBitmap ) // no old bitmap or we can't replace it @@ -655,15 +662,18 @@ bool wxToolBar::Realize() bool lastWasRadio = FALSE; int i = 0; - for ( wxToolBarToolsList::Node *node = m_tools.GetFirst(); - node; - node = node->GetNext() ) + for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) { wxToolBarToolBase *tool = node->GetData(); - // don't add separators to the vertical toolbar - looks ugly - if ( isVertical && tool->IsSeparator() ) + // don't add separators to the vertical toolbar with old comctl32.dll + // versions as they didn't handle this properly + if ( isVertical && tool->IsSeparator() && + wxTheApp->GetComCtl32Version() <= 472 ) + { continue; + } + TBBUTTON& button = buttons[i]; @@ -789,7 +799,7 @@ bool wxToolBar::Realize() int left = -1; // TB_SETBUTTONINFO message is only supported by comctl32.dll 4.71+ -#if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 ) +#ifdef TB_SETBUTTONINFO // available in headers, now check whether it is available now // (during run-time) if ( wxTheApp->GetComCtl32Version() >= 471 ) @@ -905,28 +915,30 @@ bool wxToolBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id) if ( !tool ) return FALSE; + bool toggled = false; // just to suppress warnings + if ( tool->CanBeToggled() ) { LRESULT state = ::SendMessage(GetHwnd(), TB_GETSTATE, id, 0); - tool->Toggle((state & TBSTATE_CHECKED) != 0); - } + toggled = (state & TBSTATE_CHECKED) != 0; - bool toggled = tool->IsToggled(); + // ignore the event when a radio button is released, as this doesn't seem to + // happen at all, and is handled otherwise + if ( tool->GetKind() == wxITEM_RADIO && !toggled ) + return TRUE; - // avoid sending the event when a radio button is released, this is not - // interesting - if ( !tool->CanBeToggled() || tool->GetKind() != wxITEM_RADIO || toggled ) + tool->Toggle(toggled); + UnToggleRadioGroup(tool); + } + + // OnLeftClick() can veto the button state change - for buttons which + // may be toggled only, of couse + if ( !OnLeftClick((int)id, toggled) && tool->CanBeToggled() ) { - // OnLeftClick() can veto the button state change - for buttons which - // may be toggled only, of couse - if ( !OnLeftClick((int)id, toggled) && tool->CanBeToggled() ) - { - // revert back - toggled = !toggled; - tool->SetToggle(toggled); + // revert back + tool->Toggle(!toggled); - ::SendMessage(GetHwnd(), TB_CHECKBUTTON, id, MAKELONG(toggled, 0)); - } + ::SendMessage(GetHwnd(), TB_CHECKBUTTON, id, MAKELONG(toggled, 0)); } return TRUE; @@ -999,7 +1011,8 @@ wxSize wxToolBar::GetToolSize() const { // TB_GETBUTTONSIZE is supported from version 4.70 #if defined(_WIN32_IE) && (_WIN32_IE >= 0x300 ) \ - && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) + && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) \ + && !defined (__DIGITALMARS__) if ( wxTheApp->GetComCtl32Version() >= 470 ) { DWORD dw = ::SendMessage(GetHwnd(), TB_GETBUTTONSIZE, 0, 0); @@ -1018,7 +1031,7 @@ static wxToolBarToolBase *GetItemSkippingDummySpacers(const wxToolBarToolsList& tools, size_t index ) { - wxToolBarToolsList::Node* current = tools.GetFirst(); + wxToolBarToolsList::compatibility_iterator current = tools.GetFirst(); for ( ; current != 0; current = current->GetNext() ) { @@ -1170,9 +1183,9 @@ void wxToolBar::OnMouseEvent(wxMouseEvent& event) } } -bool wxToolBar::HandleSize(WXWPARAM wParam, WXLPARAM lParam) +bool wxToolBar::HandleSize(WXWPARAM WXUNUSED(wParam), WXLPARAM lParam) { - // calculate our minor dimenstion ourselves - we're confusing the standard + // calculate our minor dimension ourselves - we're confusing the standard // logic (TB_AUTOSIZE) with our horizontal toolbars and other hacks RECT r; if ( ::SendMessage(GetHwnd(), TB_GETITEMRECT, 0, (LPARAM)&r) ) @@ -1197,12 +1210,8 @@ bool wxToolBar::HandleSize(WXWPARAM wParam, WXLPARAM lParam) h = r.bottom - r.top; if ( m_maxRows ) { - // FIXME: 6 is hardcoded separator line height... - //h += 6; - if (HasFlag(wxTB_NODIVIDER)) - h += 3; - else - h += 6; + // FIXME: hardcoded separator line height... + h += HasFlag(wxTB_NODIVIDER) ? 4 : 6; h *= m_maxRows; } } @@ -1226,7 +1235,7 @@ bool wxToolBar::HandlePaint(WXWPARAM wParam, WXLPARAM lParam) // any here // first of all, do we have any controls at all? - wxToolBarToolsList::Node *node; + wxToolBarToolsList::compatibility_iterator node; for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) { if ( node->GetData()->IsControl() ) @@ -1308,6 +1317,10 @@ bool wxToolBar::HandlePaint(WXWPARAM wParam, WXLPARAM lParam) { // yes, do erase it! dc.DrawRectangle(rectItem); + + // Necessary in case we use a no-paint-on-size + // style in the parent: the controls can disappear + control->Refresh(FALSE); } } } @@ -1316,7 +1329,7 @@ bool wxToolBar::HandlePaint(WXWPARAM wParam, WXLPARAM lParam) return TRUE; } -void wxToolBar::HandleMouseMove(WXWPARAM wParam, WXLPARAM lParam) +void wxToolBar::HandleMouseMove(WXWPARAM WXUNUSED(wParam), WXLPARAM lParam) { wxCoord x = GET_X_LPARAM(lParam), y = GET_Y_LPARAM(lParam);