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