From c631abdae995a4ceae512d7853f6424fbfb27e83 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 26 Mar 2002 00:44:57 +0000 Subject: [PATCH] made radio buttons and the toolbat text work for Win32 toolbar git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14788 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 3 +- docs/latex/wx/toolbar.tex | 7 +-- include/wx/msw/tbar95.h | 2 + include/wx/tbarbase.h | 2 +- samples/toolbar/toolbar.cpp | 10 ++-- src/msw/tbar95.cpp | 114 +++++++++++++++++++++++++++++++++++- 6 files changed, 125 insertions(+), 13 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index d6d9d4d5eb..e86d7983f1 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -111,9 +111,10 @@ Unix (Base/GUI): All (GUI): +- implemented radio menu items and radio toolbar buttons +- added possibility to show text in the toolbar buttons - added wxArtProvider class that can be used to customize the look of standard wxWindows dialogs -- implemented radio menu items - significantly improved native font support - wxImage::ComputeHistogram() now uses wxImageHistogram instead of type-unsafe wxHashTable diff --git a/docs/latex/wx/toolbar.tex b/docs/latex/wx/toolbar.tex index c5c7dc3a4f..3961ad5cb9 100644 --- a/docs/latex/wx/toolbar.tex +++ b/docs/latex/wx/toolbar.tex @@ -42,9 +42,6 @@ ignore the values for explicit placement and use their own layout and the meanin of a "separator" is a vertical line under Windows95 vs. simple space under GTK etc. {\bf wxToolBar95:} Note that this toolbar paints tools to reflect user-selected colours. -The toolbar orientation must always be {\bf wxHORIZONTAL}. - -{\bf wxToolBarGtk:} The toolbar orientation is ignored and is always {\bf wxHORIZONTAL}. \wxheading{Window styles} @@ -60,7 +57,9 @@ toolbar).} \twocolitem{\windowstyle{wxTB\_NOICONS}}{Doesn't show the icons in the toolbar buttons, by default they are shown} \end{twocollist} -See also \helpref{window styles overview}{windowstyles}. +See also \helpref{window styles overview}{windowstyles}. Note that the Win32 +native toolbar ignores {\tt wxTB\_NOICONS} style. Also, toggling the +{\tt wxTB\_TEXT} works only if the style was initially on. \wxheading{Event handling} diff --git a/include/wx/msw/tbar95.h b/include/wx/msw/tbar95.h index 45c82b48d2..faee503642 100644 --- a/include/wx/msw/tbar95.h +++ b/include/wx/msw/tbar95.h @@ -60,6 +60,8 @@ public: // implementation only from now on // ------------------------------- + virtual void SetWindowStyleFlag(long style); + virtual bool MSWCommand(WXUINT param, WXWORD id); virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); diff --git a/include/wx/tbarbase.h b/include/wx/tbarbase.h index 1ba060a436..7899208435 100644 --- a/include/wx/tbarbase.h +++ b/include/wx/tbarbase.h @@ -178,7 +178,7 @@ public: void SetNormalBitmap(const wxBitmap& bmp) { m_bmpNormal = bmp; } void SetDisabledBitmap(const wxBitmap& bmp) { m_bmpDisabled = bmp; } - void SetLabel(const wxString& label) { m_label = label; } + virtual void SetLabel(const wxString& label) { m_label = label; } void SetClientData(wxObject *clientData) { diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index 6afda23514..4d5307987b 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -152,7 +152,7 @@ private: const int ID_TOOLBAR = 500; -static const long TOOLBAR_STYLE = wxNO_BORDER | wxTB_FLAT | wxTB_DOCKABLE; +static const long TOOLBAR_STYLE = wxTB_FLAT | wxTB_DOCKABLE | wxTB_TEXT; enum { @@ -227,7 +227,7 @@ bool MyApp::OnInit() // Create the main frame window MyFrame* frame = new MyFrame((wxFrame *) NULL, -1, "wxToolBar Sample", - wxPoint(100, 100), wxSize(450, 300)); + wxPoint(100, 100), wxSize(550, 300)); frame->Show(TRUE); @@ -397,6 +397,8 @@ MyFrame::MyFrame(wxFrame* parent, // Associate the menu bar with the frame SetMenuBar(menuBar); + menuBar->Check(IDM_TOOLBAR_SHOW_BOTH, TRUE); + // Create the toolbar RecreateToolbar(); } @@ -464,8 +466,8 @@ void MyFrame::OnToggleAnotherToolbar(wxCommandEvent& WXUNUSED(event)) style); m_tbar->AddRadioTool(wxID_NEW, _T("First"), wxBITMAP(new)); - m_tbar->AddRadioTool(wxID_NEW, _T("Second"), wxBITMAP(new)); - m_tbar->AddRadioTool(wxID_NEW, _T("Third"), wxBITMAP(new)); + m_tbar->AddRadioTool(wxID_OPEN, _T("Second"), wxBITMAP(open)); + m_tbar->AddRadioTool(wxID_SAVE, _T("Third"), wxBITMAP(save)); m_tbar->AddSeparator(); m_tbar->AddTool(wxID_HELP, _T("Help"), wxBITMAP(help)); diff --git a/src/msw/tbar95.cpp b/src/msw/tbar95.cpp index 0efea2ffc0..721124a0aa 100644 --- a/src/msw/tbar95.cpp +++ b/src/msw/tbar95.cpp @@ -161,6 +161,19 @@ public: m_nSepCount = 1; } + virtual void SetLabel(const wxString& label) + { + if ( label == m_label ) + return; + + wxToolBarToolBase::SetLabel(label); + + // we need to update the label shown in the toolbar because it has a + // pointer to the internal buffer of the old label + // + // TODO: use TB_SETBUTTONINFO + } + // set/get the number of separators which we use to cover the space used by // a control in the toolbar void SetSeparatorsCount(size_t count) { m_nSepCount = count; } @@ -543,7 +556,6 @@ bool wxToolBar::Realize() wxLogDebug(wxT("TB_DELETEBUTTON failed")); } } - } if ( addBitmap ) // no old bitmap or we can't replace it @@ -566,6 +578,7 @@ bool wxToolBar::Realize() // this array will hold the indices of all controls in the toolbar wxArrayInt controlIds; + bool lastWasRadio = FALSE; int i = 0; for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) { @@ -579,6 +592,7 @@ bool wxToolBar::Realize() wxZeroMemory(button); + bool isRadio = FALSE; switch ( tool->GetStyle() ) { case wxTOOL_STYLE_CONTROL: @@ -592,6 +606,12 @@ bool wxToolBar::Realize() case wxTOOL_STYLE_BUTTON: button.iBitmap = bitmapId; + + if ( HasFlag(wxTB_TEXT) && !tool->GetLabel().empty() ) + { + button.iString = (int)tool->GetLabel().c_str(); + } + button.idCommand = tool->GetId(); if ( tool->IsEnabled() ) @@ -599,13 +619,40 @@ bool wxToolBar::Realize() if ( tool->IsToggled() ) button.fsState |= TBSTATE_CHECKED; - button.fsStyle = tool->CanBeToggled() ? TBSTYLE_CHECK - : TBSTYLE_BUTTON; + switch ( tool->GetKind() ) + { + case wxITEM_RADIO: + button.fsStyle = TBSTYLE_CHECKGROUP; + + if ( !lastWasRadio ) + { + // the first item in the radio group is checked by + // default to be consistent with wxGTK and the menu + // radio items + button.fsState |= TBSTATE_CHECKED; + } + + isRadio = TRUE; + break; + + case wxITEM_CHECK: + button.fsStyle = TBSTYLE_CHECK; + break; + + default: + wxFAIL_MSG( _T("unexpected toolbar button kind") ); + // fall through + + case wxITEM_NORMAL: + button.fsStyle = TBSTYLE_BUTTON; + } bitmapId++; break; } + lastWasRadio = isRadio; + i++; } @@ -981,6 +1028,67 @@ void wxToolBar::UpdateSize() } } +// ---------------------------------------------------------------------------- +// toolbar styles +// --------------------------------------------------------------------------- + +void wxToolBar::SetWindowStyleFlag(long style) +{ + // there doesn't seem to be any reasonably simple way to prevent the + // toolbar from showing the icons so for now we don't honour wxTB_NOICONS + if ( (style & wxTB_TEXT) != (GetWindowStyle() & wxTB_TEXT) ) + { + // update the strings of all toolbar buttons + // + // NB: we can only do it using TB_SETBUTTONINFO which is available + // in comctl32.dll >= 4.71 only +#if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 ) + if ( wxTheApp->GetComCtl32Version() >= 471 ) + { + // set the (underlying) separators width to be that of the + // control + TBBUTTONINFO tbbi; + tbbi.cbSize = sizeof(tbbi); + tbbi.dwMask = TBIF_TEXT; + if ( !(style & wxTB_TEXT) ) + { + // don't show the text - remove the labels + tbbi.pszText = NULL; + } + + for ( wxToolBarToolsList::Node *node = m_tools.GetFirst(); + node; + node = node->GetNext() ) + { + wxToolBarToolBase *tool = node->GetData(); + if ( !tool->IsButton() ) + { + continue; + } + + if ( style & wxTB_TEXT ) + { + // cast is harmless + tbbi.pszText = (wxChar *)tool->GetLabel().c_str(); + } + + if ( !SendMessage(GetHwnd(), TB_SETBUTTONINFO, + tool->GetId(), (LPARAM)&tbbi) ) + { + // the id is probably invalid? + wxLogLastError(wxT("TB_SETBUTTONINFO")); + } + } + + UpdateSize(); + Refresh(); + } +#endif // comctl32.dll 4.71 + } + + wxToolBarBase::SetWindowStyleFlag(style); +} + // ---------------------------------------------------------------------------- // tool state // ---------------------------------------------------------------------------- -- 2.47.2