Add support for stretchable spaces to wxToolBar.

Stretchable spaces consume all extra toolbar space not allocated to the fixed
size items. They can in particular be used to right-align (some) toolbar tools.

Add and document the new API, change the sample to show it and implement it
for MSW, GTK and OS X/Cocoa.

Also refactor MSW background erasing/repainting code to avoid duplicated calls
to DrawThemeBackground(), call it from a new helper MSWEraseRect() function.

Note that we may want to add support for "invisible" separators, IOW
non-stretchable spaces. This could be easily done for MSW after the changes in
this commit and is supported natively by GTK+ and Cocoa so implementing this
would be trivial if there is any interest.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62850 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-12-10 03:04:19 +00:00
parent 0b83552acf
commit cc26010927
9 changed files with 374 additions and 185 deletions

View File

@@ -101,11 +101,6 @@ public:
m_control = control;
}
m_toolStyle = wxTOOL_STYLE_CONTROL;
m_dropdownMenu = 0;
}
virtual ~wxToolBarToolBase();
// accessors
@@ -123,10 +118,12 @@ public:
wxToolBarBase *GetToolBar() const { return m_tbar; }
// style
// style/kind
bool IsStretchable() const { return m_stretchable; }
bool IsButton() const { return m_toolStyle == wxTOOL_STYLE_BUTTON; }
bool IsControl() const { return m_toolStyle == wxTOOL_STYLE_CONTROL; }
bool IsSeparator() const { return m_toolStyle == wxTOOL_STYLE_SEPARATOR; }
bool IsStretchableSpace() const { return IsSeparator() && IsStretchable(); }
int GetStyle() const { return m_toolStyle; }
wxItemKind GetKind() const
{
@@ -135,6 +132,13 @@ public:
return m_kind;
}
void MakeStretchable()
{
wxASSERT_MSG( IsSeparator(), "only separators can be stretchable" );
m_stretchable = true;
}
// state
bool IsEnabled() const { return m_enabled; }
bool IsToggled() const { return m_toggled; }
@@ -214,6 +218,7 @@ protected:
m_clientData = NULL;
m_stretchable = false;
m_toggled = false;
m_enabled = true;
@@ -223,7 +228,7 @@ protected:
wxToolBarBase *m_tbar; // the toolbar to which we belong (may be NULL)
// tool parameters
int m_toolStyle; // see enum wxToolBarToolStyle
wxToolBarToolStyle m_toolStyle;
wxWindowIDRef m_id; // the tool id, wxID_SEPARATOR for separator
wxItemKind m_kind; // for normal buttons may be wxITEM_NORMAL/CHECK/RADIO
@@ -234,6 +239,9 @@ protected:
wxControl *m_control;
};
// true if this tool is stretchable: currently is only value for separators
bool m_stretchable;
// tool state
bool m_toggled;
bool m_enabled;
@@ -362,6 +370,12 @@ public:
virtual wxToolBarToolBase *AddSeparator();
virtual wxToolBarToolBase *InsertSeparator(size_t pos);
// add a stretchable space to the toolbar: this is similar to a separator
// except that it's always blank and that all the extra space the toolbar
// has is [equally] distributed among the stretchable spaces in it
virtual wxToolBarToolBase *AddStretchableSpace();
virtual wxToolBarToolBase *InsertStretchableSpace(size_t pos);
// remove the tool from the toolbar: the caller is responsible for actually
// deleting the pointer
virtual wxToolBarToolBase *RemoveTool(int toolid);
@@ -606,6 +620,17 @@ protected:
virtual wxToolBarToolBase *CreateTool(wxControl *control,
const wxString& label) = 0;
// this one is not virtual but just a simple helper/wrapper around
// CreateTool() for separators
wxToolBarToolBase *CreateSeparator()
{
return CreateTool(wxID_SEPARATOR,
wxEmptyString,
wxNullBitmap, wxNullBitmap,
wxITEM_SEPARATOR, NULL,
wxEmptyString, wxEmptyString);
}
// helper functions
// ----------------