toolbar.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/toolbar.h
  3. // Purpose: wxToolBar (Windows 95 toolbar) class
  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_MSW_TBAR95_H_
  11. #define _WX_MSW_TBAR95_H_
  12. #if wxUSE_TOOLBAR
  13. #include "wx/dynarray.h"
  14. #include "wx/imaglist.h"
  15. class WXDLLIMPEXP_CORE wxToolBar : public wxToolBarBase
  16. {
  17. public:
  18. // ctors and dtor
  19. wxToolBar() { Init(); }
  20. wxToolBar(wxWindow *parent,
  21. wxWindowID id,
  22. const wxPoint& pos = wxDefaultPosition,
  23. const wxSize& size = wxDefaultSize,
  24. long style = wxTB_HORIZONTAL,
  25. const wxString& name = wxToolBarNameStr)
  26. {
  27. Init();
  28. Create(parent, id, pos, size, style, name);
  29. }
  30. bool Create(wxWindow *parent,
  31. wxWindowID id,
  32. const wxPoint& pos = wxDefaultPosition,
  33. const wxSize& size = wxDefaultSize,
  34. long style = wxTB_HORIZONTAL,
  35. const wxString& name = wxToolBarNameStr);
  36. virtual ~wxToolBar();
  37. // override/implement base class virtuals
  38. virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y) const;
  39. virtual bool Realize();
  40. virtual void SetToolBitmapSize(const wxSize& size);
  41. virtual wxSize GetToolSize() const;
  42. virtual void SetRows(int nRows);
  43. virtual void SetToolNormalBitmap(int id, const wxBitmap& bitmap);
  44. virtual void SetToolDisabledBitmap(int id, const wxBitmap& bitmap);
  45. // implementation only from now on
  46. // -------------------------------
  47. virtual void SetWindowStyleFlag(long style);
  48. virtual bool MSWCommand(WXUINT param, WXWORD id);
  49. virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
  50. void OnMouseEvent(wxMouseEvent& event);
  51. void OnSysColourChanged(wxSysColourChangedEvent& event);
  52. void OnEraseBackground(wxEraseEvent& event);
  53. void SetFocus() {}
  54. static WXHBITMAP MapBitmap(WXHBITMAP bitmap, int width, int height);
  55. // override WndProc mainly to process WM_SIZE
  56. virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
  57. virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
  58. // returns true if the platform should explicitly apply a theme border
  59. virtual bool CanApplyThemeBorder() const { return false; }
  60. #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
  61. virtual bool MSWEraseBgHook(WXHDC hDC);
  62. virtual WXHBRUSH MSWGetBgBrushForChild(WXHDC hDC, wxWindowMSW *child);
  63. #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
  64. virtual wxToolBarToolBase *CreateTool(int id,
  65. const wxString& label,
  66. const wxBitmap& bmpNormal,
  67. const wxBitmap& bmpDisabled = wxNullBitmap,
  68. wxItemKind kind = wxITEM_NORMAL,
  69. wxObject *clientData = NULL,
  70. const wxString& shortHelp = wxEmptyString,
  71. const wxString& longHelp = wxEmptyString);
  72. virtual wxToolBarToolBase *CreateTool(wxControl *control,
  73. const wxString& label);
  74. protected:
  75. // common part of all ctors
  76. void Init();
  77. // create the native toolbar control
  78. bool MSWCreateToolbar(const wxPoint& pos, const wxSize& size);
  79. // recreate the control completely
  80. void Recreate();
  81. // implement base class pure virtuals
  82. virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool);
  83. virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool);
  84. virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable);
  85. virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle);
  86. virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle);
  87. // return the appropriate size and flags for the toolbar control
  88. virtual wxSize DoGetBestSize() const;
  89. // handlers for various events
  90. bool HandleSize(WXWPARAM wParam, WXLPARAM lParam);
  91. #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
  92. bool HandlePaint(WXWPARAM wParam, WXLPARAM lParam);
  93. #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
  94. void HandleMouseMove(WXWPARAM wParam, WXLPARAM lParam);
  95. // should be called whenever the toolbar size changes
  96. void UpdateSize();
  97. // create m_disabledImgList (but doesn't fill it), set it to NULL if it is
  98. // unneeded
  99. void CreateDisabledImageList();
  100. // get the Windows toolbar style of this control
  101. long GetMSWToolbarStyle() const;
  102. // the big bitmap containing all bitmaps of the toolbar buttons
  103. WXHBITMAP m_hBitmap;
  104. // the image list with disabled images, may be NULL if we use
  105. // system-provided versions of them
  106. wxImageList *m_disabledImgList;
  107. // the total number of toolbar elements
  108. size_t m_nButtons;
  109. // the sum of the sizes of the fixed items (i.e. excluding stretchable
  110. // spaces) in the toolbar direction
  111. int m_totalFixedSize;
  112. // the tool the cursor is in
  113. wxToolBarToolBase *m_pInTool;
  114. private:
  115. // makes sure tool bitmap size is sufficient for all tools
  116. void AdjustToolBitmapSize();
  117. // update the sizes of stretchable spacers to consume all extra space we
  118. // have
  119. void UpdateStretchableSpacersSize();
  120. #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
  121. // do erase the toolbar background, always do it for the entire control as
  122. // the caller sets the clipping region correctly to exclude parts which
  123. // should not be erased
  124. void MSWDoEraseBackground(WXHDC hDC);
  125. // return the brush to use for erasing the toolbar background
  126. WXHBRUSH MSWGetToolbarBgBrush();
  127. #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
  128. DECLARE_EVENT_TABLE()
  129. DECLARE_DYNAMIC_CLASS(wxToolBar)
  130. wxDECLARE_NO_COPY_CLASS(wxToolBar);
  131. };
  132. #endif // wxUSE_TOOLBAR
  133. #endif // _WX_MSW_TBAR95_H_