]> git.saurik.com Git - wxWidgets.git/blob - src/os2/menuitem.cpp
*** empty log message ***
[wxWidgets.git] / src / os2 / menuitem.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: menuitem.cpp
3 // Purpose: wxMenuItem implementation
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/10/98
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // headers & declarations
14 // ============================================================================
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifndef WX_PRECOMP
20 #include "wx/font.h"
21 #include "wx/bitmap.h"
22 #include "wx/settings.h"
23 #include "wx/font.h"
24 #include "wx/window.h"
25 #include "wx/accel.h"
26 #include "wx/menu.h"
27 #include "wx/string.h"
28 #endif
29
30 #include "wx/ownerdrw.h"
31 #include "wx/menuitem.h"
32 #include "wx/log.h"
33
34 #include "wx/os2/private.h"
35
36 // ---------------------------------------------------------------------------
37 // convenience macro
38 // ---------------------------------------------------------------------------
39
40 #define GetHMenuOf(menu) ((HMENU)menu->GetHMenu())
41
42 // ============================================================================
43 // implementation
44 // ============================================================================
45
46 // ----------------------------------------------------------------------------
47 // dynamic classes implementation
48 // ----------------------------------------------------------------------------
49
50 #if !defined(USE_SHARED_LIBRARY) || !USE_SHARED_LIBRARY
51 #if wxUSE_OWNER_DRAWN
52 IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem, wxObject, wxOwnerDrawn)
53 #else //!USE_OWNER_DRAWN
54 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
55 #endif //USE_OWNER_DRAWN
56
57 #endif //USE_SHARED_LIBRARY
58
59 // ----------------------------------------------------------------------------
60 // wxMenuItem
61 // ----------------------------------------------------------------------------
62
63 // ctor & dtor
64 // -----------
65
66 wxMenuItem::wxMenuItem(wxMenu *pParentMenu, int id,
67 const wxString& strName, const wxString& strHelp,
68 bool bCheckable,
69 wxMenu *pSubMenu) :
70 #if wxUSE_OWNER_DRAWN
71 wxOwnerDrawn(strName, bCheckable),
72 #else //no owner drawn support
73 m_bCheckable(bCheckable),
74 m_strName(strName),
75 #endif //owner drawn
76 m_strHelp(strHelp)
77 {
78 wxASSERT_MSG( pParentMenu != NULL, wxT("a menu item should have a parent") );
79
80 #if wxUSE_OWNER_DRAWN
81 // set default menu colors
82 #define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c))
83
84 SetTextColour(SYS_COLOR(MENUTEXT));
85 SetBackgroundColour(SYS_COLOR(MENU));
86
87 // we don't want normal items be owner-drawn
88 ResetOwnerDrawn();
89
90 #undef SYS_COLOR
91 #endif
92
93 m_pParentMenu = pParentMenu;
94 m_pSubMenu = pSubMenu;
95 m_bEnabled = TRUE;
96 m_bChecked = FALSE;
97 m_idItem = id;
98 }
99
100 wxMenuItem::~wxMenuItem()
101 {
102 }
103
104 // misc
105 // ----
106
107 // return the id for calling Win32 API functions
108 int wxMenuItem::GetRealId() const
109 {
110 return m_pSubMenu ? (int)m_pSubMenu->GetHMenu() : GetId();
111 }
112
113 // delete the sub menu
114 // -------------------
115 void wxMenuItem::DeleteSubMenu()
116 {
117 delete m_pSubMenu;
118 m_pSubMenu = NULL;
119 }
120
121 // change item state
122 // -----------------
123
124 void wxMenuItem::Enable(bool bDoEnable)
125 {
126 // TODO:
127 /*
128 if ( m_bEnabled != bDoEnable ) {
129 long rc = EnableMenuItem(GetHMenuOf(m_pParentMenu),
130 GetRealId(),
131 MF_BYCOMMAND |
132 (bDoEnable ? MF_ENABLED : MF_GRAYED));
133
134 if ( rc == -1 ) {
135 wxLogLastError("EnableMenuItem");
136 }
137
138 m_bEnabled = bDoEnable;
139 }
140 */
141 }
142
143 void wxMenuItem::Check(bool bDoCheck)
144 {
145 wxCHECK_RET( IsCheckable(), wxT("only checkable items may be checked") );
146
147 // TODO:
148 /*
149 if ( m_bChecked != bDoCheck ) {
150 long rc = CheckMenuItem(GetHMenuOf(m_pParentMenu),
151 GetId(),
152 MF_BYCOMMAND |
153 (bDoCheck ? MF_CHECKED : MF_UNCHECKED));
154
155 if ( rc == -1 ) {
156 wxLogLastError("CheckMenuItem");
157 }
158
159 m_bChecked = bDoCheck;
160 }
161 */
162 }
163
164 void wxMenuItem::SetName(const wxString& strName)
165 {
166 // don't do anything if label didn't change
167 if ( m_strName == strName )
168 return;
169
170 m_strName = strName;
171
172 HMENU hMenu = GetHMenuOf(m_pParentMenu);
173
174 UINT id = GetRealId();
175
176 // TODO:
177 /*
178 UINT flagsOld = ::GetMenuState(hMenu, id, MF_BYCOMMAND);
179 if ( flagsOld == 0xFFFFFFFF )
180 {
181 wxLogLastError("GetMenuState");
182 }
183 else
184 {
185 if ( IsSubMenu() )
186 {
187 // high byte contains the number of items in a submenu for submenus
188 flagsOld &= 0xFF;
189 flagsOld |= MF_POPUP;
190 }
191
192 LPCTSTR data;
193 #if wxUSE_OWNER_DRAWN
194 if ( IsOwnerDrawn() )
195 {
196 flagsOld |= MF_OWNERDRAW;
197 data = (LPCTSTR)this;
198 }
199 else
200 #endif //owner drawn
201 {
202 flagsOld |= MF_STRING;
203 data = strName;
204 }
205
206 if ( ::ModifyMenu(hMenu, id,
207 MF_BYCOMMAND | flagsOld,
208 id, data) == 0xFFFFFFFF )
209 {
210 wxLogLastError(wxT("ModifyMenu"));
211 }
212 }
213 */
214 }
215