tbarbase.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/tbarbase.h
  3. // Purpose: Base class for toolbar classes
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 01/02/97
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_TBARBASE_H_
  11. #define _WX_TBARBASE_H_
  12. // ----------------------------------------------------------------------------
  13. // headers
  14. // ----------------------------------------------------------------------------
  15. #include "wx/defs.h"
  16. #if wxUSE_TOOLBAR
  17. #include "wx/bitmap.h"
  18. #include "wx/list.h"
  19. #include "wx/control.h"
  20. class WXDLLIMPEXP_FWD_CORE wxToolBarBase;
  21. class WXDLLIMPEXP_FWD_CORE wxToolBarToolBase;
  22. class WXDLLIMPEXP_FWD_CORE wxImage;
  23. // ----------------------------------------------------------------------------
  24. // constants
  25. // ----------------------------------------------------------------------------
  26. extern WXDLLIMPEXP_DATA_CORE(const char) wxToolBarNameStr[];
  27. extern WXDLLIMPEXP_DATA_CORE(const wxSize) wxDefaultSize;
  28. extern WXDLLIMPEXP_DATA_CORE(const wxPoint) wxDefaultPosition;
  29. enum wxToolBarToolStyle
  30. {
  31. wxTOOL_STYLE_BUTTON = 1,
  32. wxTOOL_STYLE_SEPARATOR = 2,
  33. wxTOOL_STYLE_CONTROL
  34. };
  35. // ----------------------------------------------------------------------------
  36. // wxToolBarTool is a toolbar element.
  37. //
  38. // It has a unique id (except for the separators which always have id wxID_ANY), the
  39. // style (telling whether it is a normal button, separator or a control), the
  40. // state (toggled or not, enabled or not) and short and long help strings. The
  41. // default implementations use the short help string for the tooltip text which
  42. // is popped up when the mouse pointer enters the tool and the long help string
  43. // for the applications status bar.
  44. // ----------------------------------------------------------------------------
  45. class WXDLLIMPEXP_CORE wxToolBarToolBase : public wxObject
  46. {
  47. public:
  48. // ctors & dtor
  49. // ------------
  50. // generic ctor for any kind of tool
  51. wxToolBarToolBase(wxToolBarBase *tbar = NULL,
  52. int toolid = wxID_SEPARATOR,
  53. const wxString& label = wxEmptyString,
  54. const wxBitmap& bmpNormal = wxNullBitmap,
  55. const wxBitmap& bmpDisabled = wxNullBitmap,
  56. wxItemKind kind = wxITEM_NORMAL,
  57. wxObject *clientData = NULL,
  58. const wxString& shortHelpString = wxEmptyString,
  59. const wxString& longHelpString = wxEmptyString)
  60. : m_label(label),
  61. m_shortHelpString(shortHelpString),
  62. m_longHelpString(longHelpString)
  63. {
  64. Init
  65. (
  66. tbar,
  67. toolid == wxID_SEPARATOR ? wxTOOL_STYLE_SEPARATOR
  68. : wxTOOL_STYLE_BUTTON,
  69. toolid == wxID_ANY ? wxWindow::NewControlId()
  70. : toolid,
  71. kind
  72. );
  73. m_clientData = clientData;
  74. m_bmpNormal = bmpNormal;
  75. m_bmpDisabled = bmpDisabled;
  76. }
  77. // ctor for controls only
  78. wxToolBarToolBase(wxToolBarBase *tbar,
  79. wxControl *control,
  80. const wxString& label)
  81. : m_label(label)
  82. {
  83. Init(tbar, wxTOOL_STYLE_CONTROL, control->GetId(), wxITEM_MAX);
  84. m_control = control;
  85. }
  86. virtual ~wxToolBarToolBase();
  87. // accessors
  88. // ---------
  89. // general
  90. int GetId() const { return m_id; }
  91. wxControl *GetControl() const
  92. {
  93. wxASSERT_MSG( IsControl(), wxT("this toolbar tool is not a control") );
  94. return m_control;
  95. }
  96. wxToolBarBase *GetToolBar() const { return m_tbar; }
  97. // style/kind
  98. bool IsStretchable() const { return m_stretchable; }
  99. bool IsButton() const { return m_toolStyle == wxTOOL_STYLE_BUTTON; }
  100. bool IsControl() const { return m_toolStyle == wxTOOL_STYLE_CONTROL; }
  101. bool IsSeparator() const { return m_toolStyle == wxTOOL_STYLE_SEPARATOR; }
  102. bool IsStretchableSpace() const { return IsSeparator() && IsStretchable(); }
  103. int GetStyle() const { return m_toolStyle; }
  104. wxItemKind GetKind() const
  105. {
  106. wxASSERT_MSG( IsButton(), wxT("only makes sense for buttons") );
  107. return m_kind;
  108. }
  109. void MakeStretchable()
  110. {
  111. wxASSERT_MSG( IsSeparator(), "only separators can be stretchable" );
  112. m_stretchable = true;
  113. }
  114. // state
  115. bool IsEnabled() const { return m_enabled; }
  116. bool IsToggled() const { return m_toggled; }
  117. bool CanBeToggled() const
  118. { return m_kind == wxITEM_CHECK || m_kind == wxITEM_RADIO; }
  119. // attributes
  120. const wxBitmap& GetNormalBitmap() const { return m_bmpNormal; }
  121. const wxBitmap& GetDisabledBitmap() const { return m_bmpDisabled; }
  122. const wxBitmap& GetBitmap() const
  123. { return IsEnabled() ? GetNormalBitmap() : GetDisabledBitmap(); }
  124. const wxString& GetLabel() const { return m_label; }
  125. const wxString& GetShortHelp() const { return m_shortHelpString; }
  126. const wxString& GetLongHelp() const { return m_longHelpString; }
  127. wxObject *GetClientData() const
  128. {
  129. if ( m_toolStyle == wxTOOL_STYLE_CONTROL )
  130. {
  131. return (wxObject*)m_control->GetClientData();
  132. }
  133. else
  134. {
  135. return m_clientData;
  136. }
  137. }
  138. // modifiers: return true if the state really changed
  139. virtual bool Enable(bool enable);
  140. virtual bool Toggle(bool toggle);
  141. virtual bool SetToggle(bool toggle);
  142. virtual bool SetShortHelp(const wxString& help);
  143. virtual bool SetLongHelp(const wxString& help);
  144. void Toggle() { Toggle(!IsToggled()); }
  145. virtual void SetNormalBitmap(const wxBitmap& bmp) { m_bmpNormal = bmp; }
  146. virtual void SetDisabledBitmap(const wxBitmap& bmp) { m_bmpDisabled = bmp; }
  147. virtual void SetLabel(const wxString& label) { m_label = label; }
  148. void SetClientData(wxObject *clientData)
  149. {
  150. if ( m_toolStyle == wxTOOL_STYLE_CONTROL )
  151. {
  152. m_control->SetClientData(clientData);
  153. }
  154. else
  155. {
  156. m_clientData = clientData;
  157. }
  158. }
  159. // add tool to/remove it from a toolbar
  160. virtual void Detach() { m_tbar = NULL; }
  161. virtual void Attach(wxToolBarBase *tbar) { m_tbar = tbar; }
  162. #if wxUSE_MENUS
  163. // these methods are only for tools of wxITEM_DROPDOWN kind (but even such
  164. // tools can have a NULL associated menu)
  165. virtual void SetDropdownMenu(wxMenu *menu);
  166. wxMenu *GetDropdownMenu() const { return m_dropdownMenu; }
  167. #endif
  168. protected:
  169. // common part of all ctors
  170. void Init(wxToolBarBase *tbar,
  171. wxToolBarToolStyle style,
  172. int toolid,
  173. wxItemKind kind)
  174. {
  175. m_tbar = tbar;
  176. m_toolStyle = style;
  177. m_id = toolid;
  178. m_kind = kind;
  179. m_clientData = NULL;
  180. m_stretchable = false;
  181. m_toggled = false;
  182. m_enabled = true;
  183. #if wxUSE_MENUS
  184. m_dropdownMenu = NULL;
  185. #endif
  186. }
  187. wxToolBarBase *m_tbar; // the toolbar to which we belong (may be NULL)
  188. // tool parameters
  189. wxToolBarToolStyle m_toolStyle;
  190. wxWindowIDRef m_id; // the tool id, wxID_SEPARATOR for separator
  191. wxItemKind m_kind; // for normal buttons may be wxITEM_NORMAL/CHECK/RADIO
  192. // as controls have their own client data, no need to waste memory
  193. union
  194. {
  195. wxObject *m_clientData;
  196. wxControl *m_control;
  197. };
  198. // true if this tool is stretchable: currently is only value for separators
  199. bool m_stretchable;
  200. // tool state
  201. bool m_toggled;
  202. bool m_enabled;
  203. // normal and disabled bitmaps for the tool, both can be invalid
  204. wxBitmap m_bmpNormal;
  205. wxBitmap m_bmpDisabled;
  206. // the button label
  207. wxString m_label;
  208. // short and long help strings
  209. wxString m_shortHelpString;
  210. wxString m_longHelpString;
  211. #if wxUSE_MENUS
  212. wxMenu *m_dropdownMenu;
  213. #endif
  214. DECLARE_DYNAMIC_CLASS_NO_COPY(wxToolBarToolBase)
  215. };
  216. // a list of toolbar tools
  217. WX_DECLARE_EXPORTED_LIST(wxToolBarToolBase, wxToolBarToolsList);
  218. // ----------------------------------------------------------------------------
  219. // the base class for all toolbars
  220. // ----------------------------------------------------------------------------
  221. class WXDLLIMPEXP_CORE wxToolBarBase : public wxControl
  222. {
  223. public:
  224. wxToolBarBase();
  225. virtual ~wxToolBarBase();
  226. // toolbar construction
  227. // --------------------
  228. // the full AddTool() function
  229. //
  230. // If bmpDisabled is wxNullBitmap, a shadowed version of the normal bitmap
  231. // is created and used as the disabled image.
  232. wxToolBarToolBase *AddTool(int toolid,
  233. const wxString& label,
  234. const wxBitmap& bitmap,
  235. const wxBitmap& bmpDisabled,
  236. wxItemKind kind = wxITEM_NORMAL,
  237. const wxString& shortHelp = wxEmptyString,
  238. const wxString& longHelp = wxEmptyString,
  239. wxObject *data = NULL)
  240. {
  241. return DoAddTool(toolid, label, bitmap, bmpDisabled, kind,
  242. shortHelp, longHelp, data);
  243. }
  244. // the most common AddTool() version
  245. wxToolBarToolBase *AddTool(int toolid,
  246. const wxString& label,
  247. const wxBitmap& bitmap,
  248. const wxString& shortHelp = wxEmptyString,
  249. wxItemKind kind = wxITEM_NORMAL)
  250. {
  251. return AddTool(toolid, label, bitmap, wxNullBitmap, kind, shortHelp);
  252. }
  253. // add a check tool, i.e. a tool which can be toggled
  254. wxToolBarToolBase *AddCheckTool(int toolid,
  255. const wxString& label,
  256. const wxBitmap& bitmap,
  257. const wxBitmap& bmpDisabled = wxNullBitmap,
  258. const wxString& shortHelp = wxEmptyString,
  259. const wxString& longHelp = wxEmptyString,
  260. wxObject *data = NULL)
  261. {
  262. return AddTool(toolid, label, bitmap, bmpDisabled, wxITEM_CHECK,
  263. shortHelp, longHelp, data);
  264. }
  265. // add a radio tool, i.e. a tool which can be toggled and releases any
  266. // other toggled radio tools in the same group when it happens
  267. wxToolBarToolBase *AddRadioTool(int toolid,
  268. const wxString& label,
  269. const wxBitmap& bitmap,
  270. const wxBitmap& bmpDisabled = wxNullBitmap,
  271. const wxString& shortHelp = wxEmptyString,
  272. const wxString& longHelp = wxEmptyString,
  273. wxObject *data = NULL)
  274. {
  275. return AddTool(toolid, label, bitmap, bmpDisabled, wxITEM_RADIO,
  276. shortHelp, longHelp, data);
  277. }
  278. // insert the new tool at the given position, if pos == GetToolsCount(), it
  279. // is equivalent to AddTool()
  280. virtual wxToolBarToolBase *InsertTool
  281. (
  282. size_t pos,
  283. int toolid,
  284. const wxString& label,
  285. const wxBitmap& bitmap,
  286. const wxBitmap& bmpDisabled = wxNullBitmap,
  287. wxItemKind kind = wxITEM_NORMAL,
  288. const wxString& shortHelp = wxEmptyString,
  289. const wxString& longHelp = wxEmptyString,
  290. wxObject *clientData = NULL
  291. );
  292. virtual wxToolBarToolBase *AddTool (wxToolBarToolBase *tool);
  293. virtual wxToolBarToolBase *InsertTool (size_t pos, wxToolBarToolBase *tool);
  294. // add an arbitrary control to the toolbar (notice that the control will be
  295. // deleted by the toolbar and that it will also adjust its position/size)
  296. //
  297. // the label is optional and, if specified, will be shown near the control
  298. // NB: the control should have toolbar as its parent
  299. virtual wxToolBarToolBase *
  300. AddControl(wxControl *control, const wxString& label = wxEmptyString);
  301. virtual wxToolBarToolBase *
  302. InsertControl(size_t pos, wxControl *control,
  303. const wxString& label = wxEmptyString);
  304. // get the control with the given id or return NULL
  305. virtual wxControl *FindControl( int toolid );
  306. // add a separator to the toolbar
  307. virtual wxToolBarToolBase *AddSeparator();
  308. virtual wxToolBarToolBase *InsertSeparator(size_t pos);
  309. // add a stretchable space to the toolbar: this is similar to a separator
  310. // except that it's always blank and that all the extra space the toolbar
  311. // has is [equally] distributed among the stretchable spaces in it
  312. virtual wxToolBarToolBase *AddStretchableSpace();
  313. virtual wxToolBarToolBase *InsertStretchableSpace(size_t pos);
  314. // remove the tool from the toolbar: the caller is responsible for actually
  315. // deleting the pointer
  316. virtual wxToolBarToolBase *RemoveTool(int toolid);
  317. // delete tool either by index or by position
  318. virtual bool DeleteToolByPos(size_t pos);
  319. virtual bool DeleteTool(int toolid);
  320. // delete all tools
  321. virtual void ClearTools();
  322. // must be called after all buttons have been created to finish toolbar
  323. // initialisation
  324. //
  325. // derived class versions should call the base one first, before doing
  326. // platform-specific stuff
  327. virtual bool Realize();
  328. // tools state
  329. // -----------
  330. virtual void EnableTool(int toolid, bool enable);
  331. virtual void ToggleTool(int toolid, bool toggle);
  332. // Set this to be togglable (or not)
  333. virtual void SetToggle(int toolid, bool toggle);
  334. // set/get tools client data (not for controls)
  335. virtual wxObject *GetToolClientData(int toolid) const;
  336. virtual void SetToolClientData(int toolid, wxObject *clientData);
  337. // returns tool pos, or wxNOT_FOUND if tool isn't found
  338. virtual int GetToolPos(int id) const;
  339. // return true if the tool is toggled
  340. virtual bool GetToolState(int toolid) const;
  341. virtual bool GetToolEnabled(int toolid) const;
  342. virtual void SetToolShortHelp(int toolid, const wxString& helpString);
  343. virtual wxString GetToolShortHelp(int toolid) const;
  344. virtual void SetToolLongHelp(int toolid, const wxString& helpString);
  345. virtual wxString GetToolLongHelp(int toolid) const;
  346. virtual void SetToolNormalBitmap(int WXUNUSED(id),
  347. const wxBitmap& WXUNUSED(bitmap)) {}
  348. virtual void SetToolDisabledBitmap(int WXUNUSED(id),
  349. const wxBitmap& WXUNUSED(bitmap)) {}
  350. // margins/packing/separation
  351. // --------------------------
  352. virtual void SetMargins(int x, int y);
  353. void SetMargins(const wxSize& size)
  354. { SetMargins((int) size.x, (int) size.y); }
  355. virtual void SetToolPacking(int packing)
  356. { m_toolPacking = packing; }
  357. virtual void SetToolSeparation(int separation)
  358. { m_toolSeparation = separation; }
  359. virtual wxSize GetToolMargins() const { return wxSize(m_xMargin, m_yMargin); }
  360. virtual int GetToolPacking() const { return m_toolPacking; }
  361. virtual int GetToolSeparation() const { return m_toolSeparation; }
  362. // toolbar geometry
  363. // ----------------
  364. // set the number of toolbar rows
  365. virtual void SetRows(int nRows);
  366. // the toolbar can wrap - limit the number of columns or rows it may take
  367. void SetMaxRowsCols(int rows, int cols)
  368. { m_maxRows = rows; m_maxCols = cols; }
  369. int GetMaxRows() const { return m_maxRows; }
  370. int GetMaxCols() const { return m_maxCols; }
  371. // get/set the size of the bitmaps used by the toolbar: should be called
  372. // before adding any tools to the toolbar
  373. virtual void SetToolBitmapSize(const wxSize& size)
  374. { m_defaultWidth = size.x; m_defaultHeight = size.y; }
  375. virtual wxSize GetToolBitmapSize() const
  376. { return wxSize(m_defaultWidth, m_defaultHeight); }
  377. // the button size in some implementations is bigger than the bitmap size:
  378. // get the total button size (by default the same as bitmap size)
  379. virtual wxSize GetToolSize() const
  380. { return GetToolBitmapSize(); }
  381. // returns a (non separator) tool containing the point (x, y) or NULL if
  382. // there is no tool at this point (coordinates are client)
  383. virtual wxToolBarToolBase *FindToolForPosition(wxCoord x,
  384. wxCoord y) const = 0;
  385. // find the tool by id
  386. wxToolBarToolBase *FindById(int toolid) const;
  387. // return true if this is a vertical toolbar, otherwise false
  388. bool IsVertical() const;
  389. // these methods allow to access tools by their index in the toolbar
  390. size_t GetToolsCount() const { return m_tools.GetCount(); }
  391. const wxToolBarToolBase *GetToolByPos(int pos) const { return m_tools[pos]; }
  392. #if WXWIN_COMPATIBILITY_2_8
  393. // the old versions of the various methods kept for compatibility
  394. // don't use in the new code!
  395. // --------------------------------------------------------------
  396. wxDEPRECATED_INLINE(
  397. wxToolBarToolBase *AddTool(int toolid,
  398. const wxBitmap& bitmap,
  399. const wxBitmap& bmpDisabled,
  400. bool toggle = false,
  401. wxObject *clientData = NULL,
  402. const wxString& shortHelpString = wxEmptyString,
  403. const wxString& longHelpString = wxEmptyString)
  404. ,
  405. return AddTool(toolid, wxEmptyString,
  406. bitmap, bmpDisabled,
  407. toggle ? wxITEM_CHECK : wxITEM_NORMAL,
  408. shortHelpString, longHelpString, clientData);
  409. )
  410. wxDEPRECATED_INLINE(
  411. wxToolBarToolBase *AddTool(int toolid,
  412. const wxBitmap& bitmap,
  413. const wxString& shortHelpString = wxEmptyString,
  414. const wxString& longHelpString = wxEmptyString)
  415. ,
  416. return AddTool(toolid, wxEmptyString,
  417. bitmap, wxNullBitmap, wxITEM_NORMAL,
  418. shortHelpString, longHelpString, NULL);
  419. )
  420. wxDEPRECATED_INLINE(
  421. wxToolBarToolBase *AddTool(int toolid,
  422. const wxBitmap& bitmap,
  423. const wxBitmap& bmpDisabled,
  424. bool toggle,
  425. wxCoord xPos,
  426. wxCoord yPos = wxDefaultCoord,
  427. wxObject *clientData = NULL,
  428. const wxString& shortHelp = wxEmptyString,
  429. const wxString& longHelp = wxEmptyString)
  430. ,
  431. return DoAddTool(toolid, wxEmptyString, bitmap, bmpDisabled,
  432. toggle ? wxITEM_CHECK : wxITEM_NORMAL,
  433. shortHelp, longHelp, clientData, xPos, yPos);
  434. )
  435. wxDEPRECATED_INLINE(
  436. wxToolBarToolBase *InsertTool(size_t pos,
  437. int toolid,
  438. const wxBitmap& bitmap,
  439. const wxBitmap& bmpDisabled = wxNullBitmap,
  440. bool toggle = false,
  441. wxObject *clientData = NULL,
  442. const wxString& shortHelp = wxEmptyString,
  443. const wxString& longHelp = wxEmptyString)
  444. ,
  445. return InsertTool(pos, toolid, wxEmptyString, bitmap, bmpDisabled,
  446. toggle ? wxITEM_CHECK : wxITEM_NORMAL,
  447. shortHelp, longHelp, clientData);
  448. )
  449. #endif // WXWIN_COMPATIBILITY_2_8
  450. // event handlers
  451. // --------------
  452. // NB: these functions are deprecated, use EVT_TOOL_XXX() instead!
  453. // Only allow toggle if returns true. Call when left button up.
  454. virtual bool OnLeftClick(int toolid, bool toggleDown);
  455. // Call when right button down.
  456. virtual void OnRightClick(int toolid, long x, long y);
  457. // Called when the mouse cursor enters a tool bitmap.
  458. // Argument is wxID_ANY if mouse is exiting the toolbar.
  459. virtual void OnMouseEnter(int toolid);
  460. // more deprecated functions
  461. // -------------------------
  462. // use GetToolMargins() instead
  463. wxSize GetMargins() const { return GetToolMargins(); }
  464. // Tool factories,
  465. // helper functions to create toolbar tools
  466. // -------------------------
  467. virtual wxToolBarToolBase *CreateTool(int toolid,
  468. const wxString& label,
  469. const wxBitmap& bmpNormal,
  470. const wxBitmap& bmpDisabled = wxNullBitmap,
  471. wxItemKind kind = wxITEM_NORMAL,
  472. wxObject *clientData = NULL,
  473. const wxString& shortHelp = wxEmptyString,
  474. const wxString& longHelp = wxEmptyString) = 0;
  475. virtual wxToolBarToolBase *CreateTool(wxControl *control,
  476. const wxString& label) = 0;
  477. // this one is not virtual but just a simple helper/wrapper around
  478. // CreateTool() for separators
  479. wxToolBarToolBase *CreateSeparator()
  480. {
  481. return CreateTool(wxID_SEPARATOR,
  482. wxEmptyString,
  483. wxNullBitmap, wxNullBitmap,
  484. wxITEM_SEPARATOR, NULL,
  485. wxEmptyString, wxEmptyString);
  486. }
  487. // implementation only from now on
  488. // -------------------------------
  489. // Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
  490. virtual void UpdateWindowUI(long flags = wxUPDATE_UI_NONE) ;
  491. // don't want toolbars to accept the focus
  492. virtual bool AcceptsFocus() const { return false; }
  493. #if wxUSE_MENUS
  494. // Set dropdown menu
  495. bool SetDropdownMenu(int toolid, wxMenu *menu);
  496. #endif
  497. protected:
  498. // choose the default border for this window
  499. virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
  500. // to implement in derived classes
  501. // -------------------------------
  502. // create a new toolbar tool and add it to the toolbar, this is typically
  503. // implemented by just calling InsertTool()
  504. virtual wxToolBarToolBase *DoAddTool
  505. (
  506. int toolid,
  507. const wxString& label,
  508. const wxBitmap& bitmap,
  509. const wxBitmap& bmpDisabled,
  510. wxItemKind kind,
  511. const wxString& shortHelp = wxEmptyString,
  512. const wxString& longHelp = wxEmptyString,
  513. wxObject *clientData = NULL,
  514. wxCoord xPos = wxDefaultCoord,
  515. wxCoord yPos = wxDefaultCoord
  516. );
  517. // the tool is not yet inserted into m_tools list when this function is
  518. // called and will only be added to it if this function succeeds
  519. virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool) = 0;
  520. // the tool is still in m_tools list when this function is called, it will
  521. // only be deleted from it if it succeeds
  522. virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool) = 0;
  523. // called when the tools enabled flag changes
  524. virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable) = 0;
  525. // called when the tool is toggled
  526. virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle) = 0;
  527. // called when the tools "can be toggled" flag changes
  528. virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle) = 0;
  529. // helper functions
  530. // ----------------
  531. // call this from derived class ctor/Create() to ensure that we have either
  532. // wxTB_HORIZONTAL or wxTB_VERTICAL style, there is a lot of existing code
  533. // which randomly checks either one or the other of them and gets confused
  534. // if neither is set (and making one of them 0 is not an option neither as
  535. // then the existing tests would break down)
  536. void FixupStyle();
  537. // un-toggle all buttons in the same radio group
  538. void UnToggleRadioGroup(wxToolBarToolBase *tool);
  539. // make the size of the buttons big enough to fit the largest bitmap size
  540. void AdjustToolBitmapSize();
  541. // calls InsertTool() and deletes the tool if inserting it failed
  542. wxToolBarToolBase *DoInsertNewTool(size_t pos, wxToolBarToolBase *tool)
  543. {
  544. if ( !InsertTool(pos, tool) )
  545. {
  546. delete tool;
  547. return NULL;
  548. }
  549. return tool;
  550. }
  551. // the list of all our tools
  552. wxToolBarToolsList m_tools;
  553. // the offset of the first tool
  554. int m_xMargin;
  555. int m_yMargin;
  556. // the maximum number of toolbar rows/columns
  557. int m_maxRows;
  558. int m_maxCols;
  559. // the tool packing and separation
  560. int m_toolPacking,
  561. m_toolSeparation;
  562. // the size of the toolbar bitmaps
  563. wxCoord m_defaultWidth, m_defaultHeight;
  564. private:
  565. DECLARE_EVENT_TABLE()
  566. wxDECLARE_NO_COPY_CLASS(wxToolBarBase);
  567. };
  568. // deprecated function for creating the image for disabled buttons, use
  569. // wxImage::ConvertToGreyscale() instead
  570. #if WXWIN_COMPATIBILITY_2_8
  571. wxDEPRECATED( bool wxCreateGreyedImage(const wxImage& in, wxImage& out) );
  572. #endif // WXWIN_COMPATIBILITY_2_8
  573. #endif // wxUSE_TOOLBAR
  574. #endif
  575. // _WX_TBARBASE_H_