toolbar.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/univ/toolbar.h
  3. // Purpose: wxToolBar declaration
  4. // Author: Robert Roebling
  5. // Modified by:
  6. // Created: 10.09.00
  7. // Copyright: (c) Robert Roebling
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_UNIV_TOOLBAR_H_
  11. #define _WX_UNIV_TOOLBAR_H_
  12. #include "wx/button.h" // for wxStdButtonInputHandler
  13. class WXDLLIMPEXP_FWD_CORE wxToolBarTool;
  14. // ----------------------------------------------------------------------------
  15. // the actions supported by this control
  16. // ----------------------------------------------------------------------------
  17. #define wxACTION_TOOLBAR_TOGGLE wxACTION_BUTTON_TOGGLE
  18. #define wxACTION_TOOLBAR_PRESS wxACTION_BUTTON_PRESS
  19. #define wxACTION_TOOLBAR_RELEASE wxACTION_BUTTON_RELEASE
  20. #define wxACTION_TOOLBAR_CLICK wxACTION_BUTTON_CLICK
  21. #define wxACTION_TOOLBAR_ENTER wxT("enter") // highlight the tool
  22. #define wxACTION_TOOLBAR_LEAVE wxT("leave") // unhighlight the tool
  23. // ----------------------------------------------------------------------------
  24. // wxToolBar
  25. // ----------------------------------------------------------------------------
  26. class WXDLLIMPEXP_CORE wxToolBar : public wxToolBarBase
  27. {
  28. public:
  29. // construction/destruction
  30. wxToolBar() { Init(); }
  31. wxToolBar(wxWindow *parent,
  32. wxWindowID id,
  33. const wxPoint& pos = wxDefaultPosition,
  34. const wxSize& size = wxDefaultSize,
  35. long style = 0,
  36. const wxString& name = wxToolBarNameStr)
  37. {
  38. Init();
  39. Create(parent, id, pos, size, style, name);
  40. }
  41. bool Create( wxWindow *parent,
  42. wxWindowID id,
  43. const wxPoint& pos = wxDefaultPosition,
  44. const wxSize& size = wxDefaultSize,
  45. long style = 0,
  46. const wxString& name = wxToolBarNameStr );
  47. virtual ~wxToolBar();
  48. virtual bool Realize();
  49. virtual void SetWindowStyleFlag( long style );
  50. virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y) const;
  51. virtual void SetToolShortHelp(int id, const wxString& helpString);
  52. virtual void SetMargins(int x, int y);
  53. void SetMargins(const wxSize& size)
  54. { SetMargins((int) size.x, (int) size.y); }
  55. virtual bool PerformAction(const wxControlAction& action,
  56. long numArg = -1,
  57. const wxString& strArg = wxEmptyString);
  58. static wxInputHandler *GetStdInputHandler(wxInputHandler *handlerDef);
  59. virtual wxInputHandler *DoGetStdInputHandler(wxInputHandler *handlerDef)
  60. {
  61. return GetStdInputHandler(handlerDef);
  62. }
  63. protected:
  64. // common part of all ctors
  65. void Init();
  66. // implement base class pure virtuals
  67. virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool);
  68. virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool);
  69. virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable);
  70. virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle);
  71. virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle);
  72. virtual wxToolBarToolBase *CreateTool(int id,
  73. const wxString& label,
  74. const wxBitmap& bmpNormal,
  75. const wxBitmap& bmpDisabled,
  76. wxItemKind kind,
  77. wxObject *clientData,
  78. const wxString& shortHelp,
  79. const wxString& longHelp);
  80. virtual wxToolBarToolBase *CreateTool(wxControl *control,
  81. const wxString& label);
  82. virtual wxSize DoGetBestClientSize() const;
  83. virtual void DoSetSize(int x, int y,
  84. int width, int height,
  85. int sizeFlags = wxSIZE_AUTO);
  86. virtual void DoDraw(wxControlRenderer *renderer);
  87. // get the bounding rect for the given tool
  88. wxRect GetToolRect(wxToolBarToolBase *tool) const;
  89. // redraw the given tool
  90. void RefreshTool(wxToolBarToolBase *tool);
  91. // (re)calculate the tool positions, should only be called if it is
  92. // necessary to do it, i.e. m_needsLayout == true
  93. void DoLayout();
  94. // get the rect limits depending on the orientation: top/bottom for a
  95. // vertical toolbar, left/right for a horizontal one
  96. void GetRectLimits(const wxRect& rect, wxCoord *start, wxCoord *end) const;
  97. private:
  98. // have we calculated the positions of our tools?
  99. bool m_needsLayout;
  100. // the width of a separator
  101. wxCoord m_widthSeparator;
  102. // the total size of all toolbar elements
  103. wxCoord m_maxWidth,
  104. m_maxHeight;
  105. private:
  106. DECLARE_DYNAMIC_CLASS(wxToolBar)
  107. };
  108. #endif // _WX_UNIV_TOOLBAR_H_