]> git.saurik.com Git - wxWidgets.git/commitdiff
made radio buttons and the toolbat text work for Win32 toolbar
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 26 Mar 2002 00:44:57 +0000 (00:44 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 26 Mar 2002 00:44:57 +0000 (00:44 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14788 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
docs/latex/wx/toolbar.tex
include/wx/msw/tbar95.h
include/wx/tbarbase.h
samples/toolbar/toolbar.cpp
src/msw/tbar95.cpp

index d6d9d4d5ebfc67ade37de945c7427f78977bc3e8..e86d7983f191f44d815ef650251226b024fb9cf3 100644 (file)
@@ -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
index c5c7dc3a4f71f24892415d23f9ec65d6f96145de..3961ad5cb9d97b0489dcfb45843eca8e706e176c 100644 (file)
@@ -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}
 
index 45c82b48d2c922a288c1a37370895202a9fcfb1a..faee5036421be4933d09586b25d8a3744fe85cca 100644 (file)
@@ -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);
 
index 1ba060a4364779f0db6626419455181c19f92b9b..7899208435fb0eda43995904d5d8866645bec4c6 100644 (file)
@@ -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)
     {
index 6afda235145ccb31883de4e96b0e997dcce0105f..4d5307987bf09e8b32ba6f4189139ea18a2d5982 100644 (file)
@@ -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));
 
index 0efea2ffc0a2c95a50c1eed216fe81bbf2f78004..721124a0aaa7c7805d587c799832b6fefe815a59 100644 (file)
@@ -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
 // ----------------------------------------------------------------------------