1 ///////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/univ/menuitem.h
3 // Purpose:     wxMenuItem class for wxUniversal
4 // Author:      Vadim Zeitlin
5 // Modified by:
6 // Created:     05.05.01
7 // Copyright:   (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
8 // Licence:     wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10 
11 #ifndef _WX_UNIV_MENUITEM_H_
12 #define _WX_UNIV_MENUITEM_H_
13 
14 // ----------------------------------------------------------------------------
15 // wxMenuItem implements wxMenuItemBase
16 // ----------------------------------------------------------------------------
17 
18 class WXDLLIMPEXP_CORE wxMenuItem : public wxMenuItemBase
19 {
20 public:
21     // ctor & dtor
22     wxMenuItem(wxMenu *parentMenu = NULL,
23                int id = wxID_SEPARATOR,
24                const wxString& name = wxEmptyString,
25                const wxString& help = wxEmptyString,
26                wxItemKind kind = wxITEM_NORMAL,
27                wxMenu *subMenu = NULL);
28     virtual ~wxMenuItem();
29 
30     // override base class virtuals to update the item appearance on screen
31     virtual void SetItemLabel(const wxString& text) wxOVERRIDE;
32     virtual void SetCheckable(bool checkable) wxOVERRIDE;
33 
34     virtual void Enable(bool enable = true) wxOVERRIDE;
35     virtual void Check(bool check = true) wxOVERRIDE;
36 
37     // we add some extra functions which are also available under MSW from
38     // wxOwnerDrawn class - they will be moved to wxMenuItemBase later
39     // hopefully
40     void SetBitmaps(const wxBitmap& bmpChecked,
41                     const wxBitmap& bmpUnchecked = wxNullBitmap);
SetBitmap(const wxBitmap & bmp)42     void SetBitmap(const wxBitmap& bmp) { SetBitmaps(bmp); }
43     const wxBitmap& GetBitmap(bool checked = true) const
44       { return checked ? m_bmpChecked : m_bmpUnchecked; }
45 
SetDisabledBitmap(const wxBitmap & bmpDisabled)46     void SetDisabledBitmap( const wxBitmap& bmpDisabled )
47       { m_bmpDisabled = bmpDisabled; }
GetDisabledBitmap()48     const wxBitmap& GetDisabledBitmap() const
49       { return m_bmpDisabled; }
50 
51     // mark item as belonging to the given radio group
52     void SetAsRadioGroupStart();
53     void SetRadioGroupStart(int start);
54     void SetRadioGroupEnd(int end);
55     int GetRadioGroupStart();
56     int GetRadioGroupEnd();
57 
58     // wxUniv-specific methods for implementation only starting from here
59 
60     // get the accel index of our label or -1 if none
GetAccelIndex()61     int GetAccelIndex() const { return m_indexAccel; }
62 
63     // get the accel string (displayed to the right of the label)
GetAccelString()64     const wxString& GetAccelString() const { return m_strAccel; }
65 
66     // set/get the y coord and the height of this item: note that it must be
67     // set first and retrieved later, the item doesn't calculate it itself
SetGeometry(wxCoord y,wxCoord height)68     void SetGeometry(wxCoord y, wxCoord height)
69     {
70         m_posY = y;
71         m_height = height;
72     }
73 
GetPosition()74     wxCoord GetPosition() const
75     {
76         wxASSERT_MSG( m_posY != wxDefaultCoord, wxT("must call SetHeight first!") );
77 
78         return m_posY;
79     }
80 
GetHeight()81     wxCoord GetHeight() const
82     {
83         wxASSERT_MSG( m_height != wxDefaultCoord, wxT("must call SetHeight first!") );
84 
85         return m_height;
86     }
87 
88 protected:
89     // notify the menu about the change in this item
90     inline void NotifyMenu();
91 
92     // set the accel index and string from text
93     void UpdateAccelInfo();
94 
95     // the bitmaps (may be invalid, then they're not used)
96     wxBitmap m_bmpChecked,
97              m_bmpUnchecked,
98              m_bmpDisabled;
99 
100     // the positions of the first and last items of the radio group this item
101     // belongs to or -1: start is the radio group start and is valid for all
102     // but first radio group items (m_isRadioGroupStart == false), end is valid
103     // only for the first one
104     union
105     {
106         int start;
107         int end;
108     } m_radioGroup;
109 
110     // does this item start a radio group?
111     bool m_isRadioGroupStart;
112 
113     // the position of the accelerator in our label, -1 if none
114     int m_indexAccel;
115 
116     // the accel string (i.e. "Ctrl-Q" or "Alt-F1")
117     wxString m_strAccel;
118 
119     // the position and height of the displayed item
120     wxCoord m_posY,
121             m_height;
122 
123 private:
124     wxDECLARE_DYNAMIC_CLASS(wxMenuItem);
125 };
126 
127 #endif // _WX_UNIV_MENUITEM_H_
128 
129