panel.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/ribbon/panel.h
  3. // Purpose: Ribbon-style container for a group of related tools / controls
  4. // Author: Peter Cawley
  5. // Modified by:
  6. // Created: 2009-05-25
  7. // Copyright: (C) Peter Cawley
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_RIBBON_PANEL_H_
  11. #define _WX_RIBBON_PANEL_H_
  12. #include "wx/defs.h"
  13. #if wxUSE_RIBBON
  14. #include "wx/bitmap.h"
  15. #include "wx/ribbon/control.h"
  16. enum wxRibbonPanelOption
  17. {
  18. wxRIBBON_PANEL_NO_AUTO_MINIMISE = 1 << 0,
  19. wxRIBBON_PANEL_EXT_BUTTON = 1 << 3,
  20. wxRIBBON_PANEL_MINIMISE_BUTTON = 1 << 4,
  21. wxRIBBON_PANEL_STRETCH = 1 << 5,
  22. wxRIBBON_PANEL_FLEXIBLE = 1 << 6,
  23. wxRIBBON_PANEL_DEFAULT_STYLE = 0
  24. };
  25. class WXDLLIMPEXP_RIBBON wxRibbonPanel : public wxRibbonControl
  26. {
  27. public:
  28. wxRibbonPanel();
  29. wxRibbonPanel(wxWindow* parent,
  30. wxWindowID id = wxID_ANY,
  31. const wxString& label = wxEmptyString,
  32. const wxBitmap& minimised_icon = wxNullBitmap,
  33. const wxPoint& pos = wxDefaultPosition,
  34. const wxSize& size = wxDefaultSize,
  35. long style = wxRIBBON_PANEL_DEFAULT_STYLE);
  36. virtual ~wxRibbonPanel();
  37. bool Create(wxWindow* parent,
  38. wxWindowID id = wxID_ANY,
  39. const wxString& label = wxEmptyString,
  40. const wxBitmap& icon = wxNullBitmap,
  41. const wxPoint& pos = wxDefaultPosition,
  42. const wxSize& size = wxDefaultSize,
  43. long style = wxRIBBON_PANEL_DEFAULT_STYLE);
  44. wxBitmap& GetMinimisedIcon() {return m_minimised_icon;}
  45. const wxBitmap& GetMinimisedIcon() const {return m_minimised_icon;}
  46. bool IsMinimised() const;
  47. bool IsMinimised(wxSize at_size) const;
  48. bool IsHovered() const;
  49. bool IsExtButtonHovered() const;
  50. bool CanAutoMinimise() const;
  51. bool ShowExpanded();
  52. bool HideExpanded();
  53. void SetArtProvider(wxRibbonArtProvider* art);
  54. virtual bool Realize();
  55. virtual bool Layout();
  56. virtual wxSize GetMinSize() const;
  57. virtual bool IsSizingContinuous() const;
  58. virtual void AddChild(wxWindowBase *child);
  59. virtual void RemoveChild(wxWindowBase *child);
  60. virtual bool HasExtButton() const;
  61. wxRibbonPanel* GetExpandedDummy();
  62. wxRibbonPanel* GetExpandedPanel();
  63. // Finds the best width and height given the parent's width and height
  64. virtual wxSize GetBestSizeForParentSize(const wxSize& parentSize) const;
  65. long GetFlags() { return m_flags; }
  66. void HideIfExpanded();
  67. protected:
  68. virtual wxSize DoGetBestSize() const;
  69. virtual wxSize GetPanelSizerBestSize() const;
  70. wxSize GetPanelSizerMinSize() const;
  71. wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
  72. wxSize GetMinNotMinimisedSize() const;
  73. virtual wxSize DoGetNextSmallerSize(wxOrientation direction,
  74. wxSize relative_to) const;
  75. virtual wxSize DoGetNextLargerSize(wxOrientation direction,
  76. wxSize relative_to) const;
  77. void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO);
  78. void OnSize(wxSizeEvent& evt);
  79. void OnEraseBackground(wxEraseEvent& evt);
  80. void OnPaint(wxPaintEvent& evt);
  81. void OnMouseEnter(wxMouseEvent& evt);
  82. void OnMouseEnterChild(wxMouseEvent& evt);
  83. void OnMouseLeave(wxMouseEvent& evt);
  84. void OnMouseLeaveChild(wxMouseEvent& evt);
  85. void OnMouseClick(wxMouseEvent& evt);
  86. void OnMotion(wxMouseEvent& evt);
  87. void OnKillFocus(wxFocusEvent& evt);
  88. void OnChildKillFocus(wxFocusEvent& evt);
  89. void TestPositionForHover(const wxPoint& pos);
  90. bool ShouldSendEventToDummy(wxEvent& evt);
  91. virtual bool TryAfter(wxEvent& evt);
  92. void CommonInit(const wxString& label, const wxBitmap& icon, long style);
  93. static wxRect GetExpandedPosition(wxRect panel,
  94. wxSize expanded_size,
  95. wxDirection direction);
  96. wxBitmap m_minimised_icon;
  97. wxBitmap m_minimised_icon_resized;
  98. wxSize m_smallest_unminimised_size;
  99. wxSize m_minimised_size;
  100. wxDirection m_preferred_expand_direction;
  101. wxRibbonPanel* m_expanded_dummy;
  102. wxRibbonPanel* m_expanded_panel;
  103. wxWindow* m_child_with_focus;
  104. long m_flags;
  105. bool m_minimised;
  106. bool m_hovered;
  107. bool m_ext_button_hovered;
  108. wxRect m_ext_button_rect;
  109. #ifndef SWIG
  110. DECLARE_CLASS(wxRibbonPanel)
  111. DECLARE_EVENT_TABLE()
  112. #endif
  113. };
  114. class WXDLLIMPEXP_RIBBON wxRibbonPanelEvent : public wxCommandEvent
  115. {
  116. public:
  117. wxRibbonPanelEvent(wxEventType command_type = wxEVT_NULL,
  118. int win_id = 0,
  119. wxRibbonPanel* panel = NULL)
  120. : wxCommandEvent(command_type, win_id)
  121. , m_panel(panel)
  122. {
  123. }
  124. #ifndef SWIG
  125. wxRibbonPanelEvent(const wxRibbonPanelEvent& e) : wxCommandEvent(e)
  126. {
  127. m_panel = e.m_panel;
  128. }
  129. #endif
  130. wxEvent *Clone() const { return new wxRibbonPanelEvent(*this); }
  131. wxRibbonPanel* GetPanel() {return m_panel;}
  132. void SetPanel(wxRibbonPanel* panel) {m_panel = panel;}
  133. protected:
  134. wxRibbonPanel* m_panel;
  135. #ifndef SWIG
  136. private:
  137. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRibbonPanelEvent)
  138. #endif
  139. };
  140. #ifndef SWIG
  141. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON, wxEVT_RIBBONPANEL_EXTBUTTON_ACTIVATED, wxRibbonPanelEvent);
  142. typedef void (wxEvtHandler::*wxRibbonPanelEventFunction)(wxRibbonPanelEvent&);
  143. #define wxRibbonPanelEventHandler(func) \
  144. wxEVENT_HANDLER_CAST(wxRibbonPanelEventFunction, func)
  145. #define EVT_RIBBONPANEL_EXTBUTTON_ACTIVATED(winid, fn) \
  146. wx__DECLARE_EVT1(wxEVT_RIBBONPANEL_EXTBUTTON_ACTIVATED, winid, wxRibbonPanelEventHandler(fn))
  147. #else
  148. // wxpython/swig event work
  149. %constant wxEventType wxEVT_RIBBONPANEL_EXTBUTTON_ACTIVATED;
  150. %pythoncode {
  151. EVT_RIBBONPANEL_EXTBUTTON_ACTIVATED = wx.PyEventBinder( wxEVT_RIBBONPANEL_EXTBUTTON_ACTIVATED, 1 )
  152. }
  153. #endif
  154. // old wxEVT_COMMAND_* constants
  155. #define wxEVT_COMMAND_RIBBONPANEL_EXTBUTTON_ACTIVATED wxEVT_RIBBONPANEL_EXTBUTTON_ACTIVATED
  156. #endif // wxUSE_RIBBON
  157. #endif // _WX_RIBBON_PANEL_H_