Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SplitButton.h
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
22 #ifndef __SPLIT_BUTTON_H__
23 #define __SPLIT_BUTTON_H__
24 
25 #include <wx/wx.h>
26 #include <wx/menu.h>
27 #include <wx/xrc/xmlres.h>
28 
29 class SplitButton : public wxPanel
30 {
31 public:
33  SplitButton():wxPanel() {};
34  SplitButton(wxWindow* parent,
35  wxWindowID id = wxID_ANY,
36  const wxString& label = wxEmptyString,
37  const wxPoint& pos = wxDefaultPosition,
38  const wxSize& size = wxDefaultSize,
39  const wxString& name = wxT("splitbutton")
40  )
41  {
42  Create(parent, id, label, pos, size, name);
43  };
45  bool Create(wxWindow* parent,
46  wxWindowID id = wxID_ANY,
47  const wxString& label = wxEmptyString,
48  const wxPoint& pos = wxDefaultPosition,
49  const wxSize& size = wxDefaultSize,
50  const wxString& name = wxT("splitbutton")
51  );
52  ~SplitButton();
54  wxMenu* GetSplitButtonMenu();
56  bool Enable(bool enable = true) override;
58  wxBitmap GetBitmap() const;
60  void SetBitmap(const wxBitmap& bitmap);
62  wxMenu* LoadMenu(const wxString& name);
64  void SetLabel(const wxString& label);
66  wxString GetLabel() const;
67 
68 protected:
70  void OnKillFocus(wxFocusEvent& event);
71  void OnMouseLeave(wxMouseEvent& event);
72  void OnMouseEnter(wxMouseEvent& event);
74  void OnLeftButtonUp(wxMouseEvent& event);
75  void OnLeftButtonDown(wxMouseEvent& event);
77  void OnPaint(wxPaintEvent& WXUNUSED(event));
79  bool HasBitmap() const;
81  void UpdateMinSize();
82 
83 private:
84  int m_stateButton = 0;
85  int m_stateMenu = 0;
86  bool m_IsEnabled = true;
87  const int m_arrowButtonWidth = 20;
88  wxString m_label;
89  wxMenu* m_dropDownMenu = nullptr;
90  wxBitmap m_bitmap;
91 };
92 
94 class SplitButtonXmlHandler : public wxXmlResourceHandler
95 {
96  DECLARE_DYNAMIC_CLASS(SplitButtonXmlHandler)
97 
98 public:
100  virtual wxObject* DoCreateResource();
101  virtual bool CanHandle(wxXmlNode* node);
102 };
103 
104 #endif /*__SPLIT_BUTTON_H__*/
wxString GetLabel() const
return the label of the button
virtual wxObject * DoCreateResource()
void OnLeftButtonUp(wxMouseEvent &event)
handle left mouse button on button and drop down button
Definition: SplitButton.cpp:96
int m_stateButton
Definition: SplitButton.h:84
void OnPaint(wxPaintEvent &WXUNUSED(event))
paint handler to draw to the button
xrc handler for split button
Definition: SplitButton.h:94
wxBitmap m_bitmap
Definition: SplitButton.h:90
void OnMouseEnter(wxMouseEvent &event)
Definition: SplitButton.cpp:87
wxMenu * GetSplitButtonMenu()
returns a pointer to the drop down menu
Definition: SplitButton.cpp:64
bool HasBitmap() const
return true if buttons has a bitmap assigned
void OnMouseLeave(wxMouseEvent &event)
Definition: SplitButton.cpp:78
SplitButton(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &label=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, const wxString &name=wxT("splitbutton"))
Definition: SplitButton.h:34
bool m_IsEnabled
Definition: SplitButton.h:86
wxMenu * LoadMenu(const wxString &name)
loads the drop down menu from the XRC ressource
virtual bool CanHandle(wxXmlNode *node)
void OnKillFocus(wxFocusEvent &event)
some event handler to mimic default mouse over behaviour
Definition: SplitButton.cpp:69
int m_stateMenu
Definition: SplitButton.h:85
void SetBitmap(const wxBitmap &bitmap)
sets bitmap and direction
const int m_arrowButtonWidth
Definition: SplitButton.h:87
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &label=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, const wxString &name=wxT("splitbutton"))
for two-step creation
Definition: SplitButton.cpp:34
bool Enable(bool enable=true) override
enable or disable the control
wxMenu * m_dropDownMenu
Definition: SplitButton.h:89
SplitButton()
constructor
Definition: SplitButton.h:33
void OnLeftButtonDown(wxMouseEvent &event)
void SetLabel(const wxString &label)
set the label string
wxBitmap GetBitmap() const
returns the currently active bitmap
wxString m_label
Definition: SplitButton.h:88
void UpdateMinSize()
update the internal size calculation