From 77631b1d818c890391b7111a1e499f1317a9ea07 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Fri, 14 Apr 2006 12:40:34 +0000 Subject: [PATCH] Implemented Mac-style button toggling within wxButtonToolBar, and line under toolbar. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38710 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/buttonbar.h | 3 ++ include/wx/mac/carbon/chkconf.h | 2 +- samples/dialogs/dialogs.cpp | 6 +++- src/generic/buttonbar.cpp | 62 +++++++++++++++++++++++++++++++-- src/generic/toolbkg.cpp | 4 +-- 5 files changed, 70 insertions(+), 7 deletions(-) diff --git a/include/wx/generic/buttonbar.h b/include/wx/generic/buttonbar.h index 7d339e6eae..96e83491a9 100644 --- a/include/wx/generic/buttonbar.h +++ b/include/wx/generic/buttonbar.h @@ -90,6 +90,9 @@ protected: // receives button commands void OnCommand(wxCommandEvent& event); + // paints a border + void OnPaint(wxPaintEvent& event); + private: // have we calculated the positions of our tools? bool m_needsLayout; diff --git a/include/wx/mac/carbon/chkconf.h b/include/wx/mac/carbon/chkconf.h index f9c630775e..a7759ef6f3 100644 --- a/include/wx/mac/carbon/chkconf.h +++ b/include/wx/mac/carbon/chkconf.h @@ -39,7 +39,7 @@ */ #ifndef wxMAC_USE_NATIVE_TOOLBAR - #define wxMAC_USE_NATIVE_TOOLBAR 0 + #define wxMAC_USE_NATIVE_TOOLBAR 1 #endif #endif diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index 8a7e4e8b6e..14bfa35549 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -1420,9 +1420,11 @@ SettingsDialog::SettingsDialog(wxWindow* win, int dialogType) int tabImage2 = -1; bool useToolBook = (dialogType == DIALOGS_PROPERTY_SHEET_TOOLBOOK || dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK); + int resizeBorder = wxRESIZE_BORDER; if (useToolBook) { + resizeBorder = 0; tabImage1 = 0; tabImage2 = 1; @@ -1433,6 +1435,8 @@ SettingsDialog::SettingsDialog(wxWindow* win, int dialogType) sheetStyle |= wxPROPSHEET_TOOLBOOK; SetSheetStyle(sheetStyle); + SetSheetInnerBorder(0); + SetSheetOuterBorder(0); // create a dummy image list with a few icons const wxSize imageSize(32, 32); @@ -1453,7 +1457,7 @@ SettingsDialog::SettingsDialog(wxWindow* win, int dialogType) Create(win, wxID_ANY, _("Preferences"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE #ifndef __WXWINCE__ - |wxRESIZE_BORDER + |resizeBorder #endif ); diff --git a/src/generic/buttonbar.cpp b/src/generic/buttonbar.cpp index 47308b3189..c632ec8ca3 100644 --- a/src/generic/buttonbar.cpp +++ b/src/generic/buttonbar.cpp @@ -37,6 +37,8 @@ #include "wx/frame.h" #include "wx/image.h" #include "wx/log.h" +#include "wx/settings.h" +#include "wx/dcclient.h" // ---------------------------------------------------------------------------- // wxButtonToolBarTool: our implementation of wxToolBarToolBase @@ -96,6 +98,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxButtonToolBar, wxControl) BEGIN_EVENT_TABLE(wxButtonToolBar, wxControl) EVT_BUTTON(wxID_ANY, wxButtonToolBar::OnCommand) + EVT_PAINT(wxButtonToolBar::OnPaint) END_EVENT_TABLE() // ---------------------------------------------------------------------------- @@ -111,7 +114,10 @@ void wxButtonToolBar::Init() m_widthSeparator = wxDefaultCoord; m_maxWidth = - m_maxHeight = 0; + m_maxHeight = 0; + + SetMargins(8, 4); + SetToolPacking(5); } bool wxButtonToolBar::Create(wxWindow *parent, @@ -127,6 +133,9 @@ bool wxButtonToolBar::Create(wxWindow *parent, return false; } + // TODO: get the correct colour from the system + wxColour lightBackground(240, 240, 240); + SetBackgroundColour(lightBackground); return true; } @@ -362,7 +371,7 @@ void wxButtonToolBar::DoLayout() if (!tool->GetButton()) { wxBitmapButton* bmpButton = new wxBitmapButton(this, tool->GetId(), tool->GetNormalBitmap(), wxPoint(tool->m_x, tool->m_y), wxDefaultSize, - wxBU_AUTODRAW); + wxBU_AUTODRAW|wxBORDER_NONE); tool->SetButton(bmpButton); } @@ -404,6 +413,10 @@ void wxButtonToolBar::DoLayout() // calculate the total toolbar size m_maxWidth = x + 2*m_xMargin; m_maxHeight = maxHeight + 2*m_yMargin; + + if ((GetWindowStyle() & wxTB_NODIVIDER) == 0) + m_maxHeight += 2; + } wxSize wxButtonToolBar::DoGetBestClientSize() const @@ -421,8 +434,51 @@ void wxButtonToolBar::OnCommand(wxCommandEvent& event) return; } + if (tool->CanBeToggled()) + tool->Toggle(tool->IsToggled()); + // TODO: handle toggle items - OnLeftClick(event.GetId(), false); + OnLeftClick(event.GetId(), false); + + if (tool->GetKind() == wxITEM_RADIO) + UnToggleRadioGroup(tool); + + if (tool->CanBeToggled()) + Refresh(); +} + +// paints a border +void wxButtonToolBar::OnPaint(wxPaintEvent& event) +{ + wxPaintDC dc(this); + + for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); + node; + node = node->GetNext() ) + { + wxButtonToolBarTool *tool = (wxButtonToolBarTool*) node->GetData(); + if (tool->IsToggled()) + { + wxRect rectTool = GetToolRect(tool); + rectTool.y = 0; rectTool.height = GetClientSize().y; + wxBrush brush(wxColour(220, 220, 220)); + wxPen pen(*wxLIGHT_GREY); + dc.SetBrush(brush); + dc.SetPen(pen); + dc.DrawRectangle(rectTool); + } + } + + if ((GetWindowStyle() & wxTB_NODIVIDER) == 0) + { + wxPen pen(*wxLIGHT_GREY); + dc.SetPen(pen); + int x1 = 0; + int y1 = GetClientSize().y-1; + int x2 = GetClientSize().x; + int y2 = y1; + dc.DrawLine(x1, y1, x2, y2); + } } #endif // wxUSE_TOOLBAR && wxUSE_BMPBUTTON diff --git a/src/generic/toolbkg.cpp b/src/generic/toolbkg.cpp index a88ea5fd9c..abc941aef6 100644 --- a/src/generic/toolbkg.cpp +++ b/src/generic/toolbkg.cpp @@ -103,7 +103,7 @@ bool wxToolbook::Create(wxWindow *parent, wxID_TOOLBOOKTOOLBAR, wxDefaultPosition, wxDefaultSize, - orient|wxTB_TEXT|wxTB_FLAT|wxTB_NODIVIDER|wxNO_BORDER + orient|wxTB_TEXT|wxTB_FLAT|wxNO_BORDER ); } else @@ -353,7 +353,7 @@ bool wxToolbook::InsertPage(size_t n, if (bSelect) { - // GetToolBar()->ToggleTool(n, true); + GetToolBar()->ToggleTool(n, true); m_selection = n; } else -- 2.45.2