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) wxOVERRIDE;
66 
67     virtual bool Realize() wxOVERRIDE;
68     virtual bool Layout() wxOVERRIDE;
69     virtual wxSize GetMinSize() const wxOVERRIDE;
70 
71     virtual bool IsSizingContinuous() const wxOVERRIDE;
72 
73     virtual void AddChild(wxWindowBase *child) wxOVERRIDE;
74     virtual void RemoveChild(wxWindowBase *child) wxOVERRIDE;
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 wxOVERRIDE;
83 
GetFlags()84     long GetFlags() { return m_flags; }
85 
86     void HideIfExpanded();
87 
88 protected:
89     virtual wxSize DoGetBestSize() const wxOVERRIDE;
90     virtual wxSize GetPanelSizerBestSize() const;
91     wxSize  GetPanelSizerMinSize() const;
GetDefaultBorder()92     wxBorder GetDefaultBorder() const wxOVERRIDE { return wxBORDER_NONE; }
93     wxSize GetMinNotMinimisedSize() const;
94 
95     virtual wxSize DoGetNextSmallerSize(wxOrientation direction,
96                                       wxSize relative_to) const wxOVERRIDE;
97     virtual wxSize DoGetNextLargerSize(wxOrientation direction,
98                                      wxSize relative_to) const wxOVERRIDE;
99 
100     void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO) wxOVERRIDE;
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) wxOVERRIDE;
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     wxDECLARE_CLASS(wxRibbonPanel);
138     wxDECLARE_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     }
Clone()153     wxEvent *Clone() const wxOVERRIDE { return new wxRibbonPanelEvent(*this); }
154 
GetPanel()155     wxRibbonPanel* GetPanel() {return m_panel;}
SetPanel(wxRibbonPanel * panel)156     void SetPanel(wxRibbonPanel* panel) {m_panel = panel;}
157 
158 protected:
159     wxRibbonPanel* m_panel;
160 
161 #ifndef SWIG
162 private:
163     wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRibbonPanelEvent);
164 #endif
165 };
166 
167 #ifndef SWIG
168 
169 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON, wxEVT_RIBBONPANEL_EXTBUTTON_ACTIVATED, wxRibbonPanelEvent);
170 
171 typedef void (wxEvtHandler::*wxRibbonPanelEventFunction)(wxRibbonPanelEvent&);
172 
173 #define wxRibbonPanelEventHandler(func) \
174     wxEVENT_HANDLER_CAST(wxRibbonPanelEventFunction, func)
175 
176 #define EVT_RIBBONPANEL_EXTBUTTON_ACTIVATED(winid, fn) \
177     wx__DECLARE_EVT1(wxEVT_RIBBONPANEL_EXTBUTTON_ACTIVATED, winid, wxRibbonPanelEventHandler(fn))
178 #else
179 
180 // wxpython/swig event work
181 %constant wxEventType wxEVT_RIBBONPANEL_EXTBUTTON_ACTIVATED;
182 
183 %pythoncode {
184     EVT_RIBBONPANEL_EXTBUTTON_ACTIVATED = wx.PyEventBinder( wxEVT_RIBBONPANEL_EXTBUTTON_ACTIVATED, 1 )
185 }
186 #endif
187 
188 // old wxEVT_COMMAND_* constants
189 #define wxEVT_COMMAND_RIBBONPANEL_EXTBUTTON_ACTIVATED   wxEVT_RIBBONPANEL_EXTBUTTON_ACTIVATED
190 
191 #endif // wxUSE_RIBBON
192 
193 #endif // _WX_RIBBON_PANEL_H_
194