00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #ifndef _WX_TOOLBARCUST_H_
00013 #define _WX_TOOLBARCUST_H_
00014
00015 #include "wx/toolbar.h"
00016 #include "wx/confbase.h"
00017
00022 class wxToolBarCustomisationInfoItem: public wxObject
00023 {
00024 public:
00025 wxToolBarCustomisationInfoItem();
00026 wxToolBarCustomisationInfoItem(const wxToolBarCustomisationInfoItem& item);
00027 ~wxToolBarCustomisationInfoItem();
00028
00029 void Copy(const wxToolBarCustomisationInfoItem& item);
00030
00031
00032 bool IsButton() const { return m_toolStyle == wxTOOL_STYLE_BUTTON; }
00033 bool IsControl() const { return m_toolStyle == wxTOOL_STYLE_CONTROL; }
00034 bool IsSeparator() const { return m_toolStyle == wxTOOL_STYLE_SEPARATOR; }
00035 int GetStyle() const { return m_toolStyle; }
00036 int GetId() const { return m_id; }
00037 wxItemKind GetKind() const
00038 {
00039 wxASSERT_MSG( IsButton(), _T("only makes sense for buttons") );
00040
00041 return m_kind;
00042 }
00043
00044
00045 wxToolBarCustomisationInfoItem& Enable(bool enable) { m_enabled = enable; return *this; }
00046 bool IsEnabled() const { return m_enabled; }
00047
00048 bool CanBeToggled() const
00049 { return m_kind == wxITEM_CHECK || m_kind == wxITEM_RADIO; }
00050
00051
00052 const wxBitmap& GetNormalBitmap() const { return m_bmpNormal; }
00053 const wxBitmap& GetDisabledBitmap() const { return m_bmpDisabled; }
00054
00055 wxToolBarCustomisationInfoItem& SetLabel(const wxString& label) { m_label = label; return *this; }
00056 const wxString& GetLabel() const { return m_label; }
00057
00058 wxToolBarCustomisationInfoItem& SetName(const wxString& name) { m_name = name; return *this; }
00059 const wxString& GetName() const { return m_name; }
00060
00061 const wxString& GetShortHelp() const { return m_shortHelpString; }
00062 const wxString& GetLongHelp() const { return m_longHelpString; }
00063
00064 wxToolBarCustomisationInfoItem& SetShortHelp(const wxString& help) { m_shortHelpString = help; return *this; }
00065 wxToolBarCustomisationInfoItem& SetLongHelp(const wxString& help) { m_longHelpString = help; return *this; }
00066
00067 wxToolBarCustomisationInfoItem& SetNormalBitmap(const wxBitmap& bmp) { m_bmpNormal = bmp; return *this; }
00068 wxToolBarCustomisationInfoItem& SetDisabledBitmap(const wxBitmap& bmp) { m_bmpDisabled = bmp; return *this; }
00069
00070
00071 int m_toolStyle;
00072 int m_id;
00073 wxItemKind m_kind;
00074
00075
00076 bool m_enabled;
00077
00078
00079 wxBitmap m_bmpNormal;
00080 wxBitmap m_bmpDisabled;
00081
00082
00083 wxString m_label;
00084
00085
00086 wxString m_name;
00087
00088
00089 wxString m_shortHelpString;
00090 wxString m_longHelpString;
00091 };
00092
00097 class wxToolBarCustomisationInfo: public wxObject
00098 {
00099 public:
00100 wxToolBarCustomisationInfo(const wxString& toolbarName = wxEmptyString);
00101 wxToolBarCustomisationInfo(const wxToolBarCustomisationInfo& info);
00102 ~wxToolBarCustomisationInfo();
00103
00105 void Init();
00106
00108 void Clear();
00109
00111 void Copy(const wxToolBarCustomisationInfo& info);
00112
00114 wxToolBarCustomisationInfoItem& AddTool(int toolid, const wxString& name,
00115 const wxString& label,
00116 const wxBitmap& bitmap,
00117 const wxBitmap& bmpDisabled,
00118 wxItemKind kind = wxITEM_NORMAL,
00119 const wxString& shortHelp = wxEmptyString,
00120 const wxString& longHelp = wxEmptyString,
00121 int style = wxTOOL_STYLE_BUTTON);
00122
00124 wxToolBarCustomisationInfoItem& AddButton(int toolid, const wxString& name,
00125 const wxString& label,
00126 const wxBitmap& bitmap,
00127 const wxString& shortHelp = wxEmptyString,
00128 const wxString& longHelp = wxEmptyString);
00129
00131 wxToolBarCustomisationInfoItem& AddCheckButton(int toolid, const wxString& name,
00132 const wxString& label,
00133 const wxBitmap& bitmap,
00134 const wxString& shortHelp = wxEmptyString,
00135 const wxString& longHelp = wxEmptyString);
00136
00138 wxToolBarCustomisationInfoItem& AddRadioButton(int toolid, const wxString& name,
00139 const wxString& label,
00140 const wxBitmap& bitmap,
00141 const wxString& shortHelp = wxEmptyString,
00142 const wxString& longHelp = wxEmptyString);
00143
00145 wxToolBarCustomisationInfoItem& AddControl(int toolid, const wxString& name,
00146 const wxString& shortHelp = wxEmptyString,
00147 const wxString& longHelp = wxEmptyString);
00148
00150 wxToolBarCustomisationInfoItem& AddSeparator();
00151
00153 bool Save(const wxString& path, wxConfigBase& config);
00154
00156 bool Load(const wxString& path, wxConfigBase& config);
00157
00159
00161 bool Reset(wxToolBarBase* toolBar);
00162
00164 bool GetNextItem();
00165
00168 bool CreateTool();
00169
00172 bool CreateTool(wxControl* control);
00173
00175 const wxToolBarCustomisationInfoItem& GetCurrentItem() const;
00176 wxToolBarCustomisationInfoItem& GetCurrentItem() ;
00177
00179 bool IsControl() const;
00180
00182 bool IsSeparator() const;
00183
00185 bool IsButton() const;
00186
00188 bool IsEnabled() const;
00189
00191
00193 bool IsToolBarEnabled() const { return m_toolbarEnabled; }
00194 void SetToolBarEnabled(bool enabled) { m_toolbarEnabled = enabled; }
00195
00197 bool GetCanHaveLabels() const { return m_canHaveLabels; }
00198 void SetCanHaveLabels(bool labels) { m_canHaveLabels = labels; }
00199
00201 bool GetUseLabels() const { return m_useLabels; }
00202 void SetUseLabels(bool useLabels) { m_useLabels = useLabels; }
00203
00205 int GetTotalItemCount() const;
00206
00208 int GetEnabledItemCount() const;
00209
00211 const wxToolBarCustomisationInfoItem& GetItem(int n) const;
00212 wxToolBarCustomisationInfoItem& GetItem(int n) ;
00213
00215 wxToolBarCustomisationInfoItem* Find(const wxString& name) const;
00216
00218 wxToolBarCustomisationInfoItem* Find(int id) const;
00219
00221 void SetName(const wxString& name) { m_name = name; }
00222 const wxString& GetName() const { return m_name; }
00223
00225
00227 wxString GetKey(const wxString& prefix, const wxString& key) const;
00228
00229 protected:
00230 wxString m_name;
00231 wxList m_toolbarItems;
00232 int m_currentTool;
00233 bool m_needsSeparator;
00234 int m_createdCount;
00235 bool m_toolbarEnabled;
00236 bool m_canHaveLabels;
00237 bool m_useLabels;
00238 wxToolBarBase* m_currentToolBar;
00239 };
00240
00245 class wxToolBarCustomisationManager: public wxObject
00246 {
00247 public:
00248 wxToolBarCustomisationManager();
00249 ~wxToolBarCustomisationManager();
00250
00252 void Init();
00253
00255 void Clear();
00256
00258 void Add(wxToolBarCustomisationInfo* info);
00259
00261 wxToolBarCustomisationInfo* Find(const wxString& name) const;
00262
00264 int FindIndex(const wxString& name) const;
00265
00267 wxToolBarCustomisationInfo* GetNth(int n) const;
00268
00270 int GetCount() const { return m_infos.GetCount(); }
00271
00273 bool Save(const wxString& path, wxConfigBase& config);
00274
00276 bool Load(const wxString& path, wxConfigBase& config);
00277
00278 protected:
00279
00280 wxList m_infos;
00281 };
00282
00287 #define wxID_CUSTOMIZE_TOOLBAR wxID_HIGHEST + 1
00288
00289 class wxCustomisableToolBar: public wxToolBar
00290 {
00291 DECLARE_CLASS(wxCustomisableToolBar)
00292 DECLARE_EVENT_TABLE()
00293 public:
00294
00295 wxCustomisableToolBar()
00296 {
00297 Init();
00298 }
00299
00300 wxCustomisableToolBar(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize,
00301 long style = wxTB_FLAT|wxTB_HORIZONTAL|wxTB_NODIVIDER|wxTB_NOALIGN);
00302
00303 ~wxCustomisableToolBar();
00304
00305 bool Create(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize,
00306 long style = wxTB_FLAT|wxTB_HORIZONTAL|wxTB_NODIVIDER|wxTB_NOALIGN);
00307
00308 void Init();
00309 static void CleanUpMenu();
00310
00311 void SetCustomisationName(const wxString& name) { m_customisationName = name; }
00312 const wxString& GetCustomisationName() const { return m_customisationName; }
00313
00314 void SetExpandToFitParent(bool expand) { m_expandToFitParent = expand; }
00315 bool GetExpandToFitParent() const { return m_expandToFitParent; }
00316
00317 void OnRightDown(wxMouseEvent& event);
00318 void OnCustomise(wxCommandEvent& event);
00319
00320 virtual void DoSetSize(int x, int y,
00321 int width, int height,
00322 int sizeFlags = wxSIZE_AUTO);
00323
00324
00325 virtual void OnInternalIdle();
00326
00327 wxString m_customisationName;
00328 static wxMenu* sm_menu;
00329 static long sm_commandId;
00330 bool m_expandToFitParent;
00331 };
00332
00333 #endif
00334