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
This commit is contained in:
Julian Smart 2006-04-14 12:40:34 +00:00
parent 1a1190b245
commit 77631b1d81
5 changed files with 70 additions and 7 deletions

View File

@ -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;

View File

@ -39,7 +39,7 @@
*/
#ifndef wxMAC_USE_NATIVE_TOOLBAR
#define wxMAC_USE_NATIVE_TOOLBAR 0
#define wxMAC_USE_NATIVE_TOOLBAR 1
#endif
#endif

View File

@ -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
);

View File

@ -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

View File

@ -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