#include "wx/defs.h"
+#if wxUSE_TOOLBAR
+
#include "wx/bitmap.h"
#include "wx/list.h"
#include "wx/control.h"
class WXDLLEXPORT wxToolBarBase;
class WXDLLEXPORT wxToolBarToolBase;
+class WXDLLEXPORT wxImage;
// ----------------------------------------------------------------------------
// constants
wxToolBarBase *GetToolBar() const { return m_tbar; }
// style
- int IsButton() const { return m_toolStyle == wxTOOL_STYLE_BUTTON; }
- int IsControl() const { return m_toolStyle == wxTOOL_STYLE_CONTROL; }
- int IsSeparator() const { return m_toolStyle == wxTOOL_STYLE_SEPARATOR; }
+ 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; }
int GetStyle() const { return m_toolStyle; }
// state
bool CanBeToggled() const { return m_isToggle; }
// attributes
- const wxBitmap& GetBitmap1() const { return m_bitmap1; }
- const wxBitmap& GetBitmap2() const { return m_bitmap2; }
+ const wxBitmap& GetNormalBitmap() const { return m_bitmap1; }
+ const wxBitmap& GetDisabledBitmap() const { return m_bitmap2; }
const wxBitmap& GetBitmap() const
- { return IsToggled() ? m_bitmap2 : m_bitmap1; }
+ { return IsEnabled() ? GetNormalBitmap() : GetDisabledBitmap(); }
+
+ wxString GetLabel() const { return m_label; }
wxString GetShortHelp() const { return m_shortHelpString; }
wxString GetLongHelp() const { return m_longHelpString; }
wxObject *GetClientData() const
{
- wxASSERT_MSG( m_toolStyle != wxTOOL_STYLE_CONTROL,
- _T("this toolbar tool doesn't have client data") );
-
- return m_clientData;
+ if ( m_toolStyle == wxTOOL_STYLE_CONTROL )
+ {
+ return (wxObject*)m_control->GetClientData();
+ }
+ else
+ {
+ return m_clientData;
+ }
}
// modifiers: return TRUE if the state really changed
void Toggle() { Toggle(!IsToggled()); }
- void SetBitmap1(const wxBitmap& bmp) { m_bitmap1 = bmp; }
- void SetBitmap2(const wxBitmap& bmp) { m_bitmap2 = bmp; }
+ void SetNormalBitmap(const wxBitmap& bmp) { m_bitmap1 = bmp; }
+ void SetDisabledBitmap(const wxBitmap& bmp) { m_bitmap2 = bmp; }
+
+ void SetLabel(const wxString& label) { m_label = label; }
+
+ void SetClientData(wxObject *clientData)
+ {
+ if ( m_toolStyle == wxTOOL_STYLE_CONTROL )
+ {
+ m_control->SetClientData(clientData);
+ }
+ else
+ {
+ m_clientData = clientData;
+ }
+ }
// add tool to/remove it from a toolbar
virtual void Detach() { m_tbar = (wxToolBarBase *)NULL; }
virtual void Attach(wxToolBarBase *tbar) { m_tbar = tbar; }
+ // compatibility only, don't use
+#if WXWIN_COMPATIBILITY_2_2
+ const wxBitmap& GetBitmap1() const { return GetNormalBitmap(); }
+ const wxBitmap& GetBitmap2() const { return GetDisabledBitmap(); }
+
+ void SetBitmap1(const wxBitmap& bmp) { SetNormalBitmap(bmp); }
+ void SetBitmap2(const wxBitmap& bmp) { SetDisabledBitmap(bmp); }
+#endif // WXWIN_COMPATIBILITY_2_2
+
protected:
wxToolBarBase *m_tbar; // the toolbar to which we belong (may be NULL)
bool m_isToggle;
bool m_enabled;
- // normal and toggles bitmaps
+ // normal and disabled bitmaps
wxBitmap m_bitmap1;
wxBitmap m_bitmap2;
+ // the button label
+ wxString m_label;
+
// short and long help strings
wxString m_shortHelpString;
wxString m_longHelpString;
};
// a list of toolbar tools
-WX_DECLARE_LIST(wxToolBarToolBase, wxToolBarToolsList);
+WX_DECLARE_EXPORTED_LIST(wxToolBarToolBase, wxToolBarToolsList);
// ----------------------------------------------------------------------------
// the base class for all toolbars
// toolbar construction
// --------------------
+ // the most commonly used version of AddTool()
+ wxToolBarToolBase *AddTool(int id,
+ const wxBitmap& bitmap,
+ const wxString& shortHelpString = wxEmptyString,
+ const wxString& longHelpString = wxEmptyString)
+ {
+ return AddTool(id, bitmap, wxNullBitmap, FALSE, NULL,
+ shortHelpString, longHelpString);
+ }
+
// If pushedBitmap is NULL, a reversed version of bitmap is created and
// used as the pushed/toggled image. If toggle is TRUE, the button toggles
// between the two states.
wxToolBarToolBase *AddTool(int id,
const wxBitmap& bitmap,
- const wxBitmap& pushedBitmap = wxNullBitmap,
+ const wxBitmap& pushedBitmap,
bool toggle = FALSE,
wxObject *clientData = NULL,
const wxString& shortHelpString = wxEmptyString,
// Set this to be togglable (or not)
virtual void SetToggle(int id, bool toggle);
- virtual wxObject *GetToolClientData(int index) const;
+ // set/get tools client data (not for controls)
+ virtual wxObject *GetToolClientData(int id) const;
+ virtual void SetToolClientData(int id, wxObject *clientData);
// return TRUE if the tool is toggled
virtual bool GetToolState(int id) const;
virtual void SetToolSeparation(int separation)
{ m_toolSeparation = separation; }
- virtual wxSize GetToolMargins() { return wxSize(m_xMargin, m_yMargin); }
+ virtual wxSize GetToolMargins() { return GetMargins(); }
virtual int GetToolPacking() { return m_toolPacking; }
virtual int GetToolSeparation() { return m_toolSeparation; }
+ // for compatibility
+ wxSize GetMargins() const { return wxSize(m_xMargin, m_yMargin); }
+
// toolbar geometry
// ----------------
virtual wxToolBarToolBase *FindToolForPosition(wxCoord x,
wxCoord y) const = 0;
+ // return TRUE if this is a vertical toolbar, otherwise FALSE
+ bool IsVertical() const { return HasFlag(wxTB_VERTICAL); }
+
// event handlers
// --------------
// Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
virtual void DoToolbarUpdates();
+ // don't want toolbars to accept the focus
+ virtual bool AcceptsFocus() const { return FALSE; }
+
protected:
// to implement in derived classes
// -------------------------------
private:
DECLARE_EVENT_TABLE()
+ DECLARE_CLASS(wxToolBarBase)
};
+// Helper function for creating the image for disabled buttons
+bool wxCreateGreyedImage(const wxImage& in, wxImage& out) ;
+
+#endif // wxUSE_TOOLBAR
+
#endif
// _WX_TBARBASE_H_