]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/menuitem.cpp
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenuItem implementation
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
13 // headers & declarations
14 // ============================================================================
17 #pragma implementation "menuitem.h"
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
25 #include "wx/bitmap.h"
26 #include "wx/settings.h"
28 #include "wx/window.h"
31 #include "wx/string.h"
34 #include "wx/menuitem.h"
41 #include "wx/os2/private.h"
43 // ---------------------------------------------------------------------------
45 // ---------------------------------------------------------------------------
48 #define GetHMenuOf(menu) ((HMENU)menu->GetHMenu())
50 // conditional compilation
52 #define OWNER_DRAWN_ONLY( code ) if ( IsOwnerDrawn() ) code
53 #else // !wxUSE_OWNER_DRAWN
54 #define OWNER_DRAWN_ONLY( code )
55 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
57 // ============================================================================
59 // ============================================================================
61 // ----------------------------------------------------------------------------
62 // dynamic classes implementation
63 // ----------------------------------------------------------------------------
66 IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem
, wxMenuItemBase
, wxOwnerDrawn
)
67 #else //!USE_OWNER_DRAWN
68 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxMenuItemBase
)
69 #endif //USE_OWNER_DRAWN
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
78 wxMenuItem::wxMenuItem(
81 , const wxString
& rText
82 , const wxString
& rStrHelp
92 wxASSERT_MSG(pParentMenu
!= NULL
, wxT("a menu item should have a parent"));
97 // Set default menu colors
99 #define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c))
101 SetTextColour(SYS_COLOR(MENUTEXT
));
102 SetBackgroundColour(SYS_COLOR(MENU
));
105 // We don't want normal items be owner-drawn
110 #endif // wxUSE_OWNER_DRAWN
112 m_parentMenu
= pParentMenu
;
113 m_subMenu
= pSubMenu
;
118 m_isCheckable
= bCheckable
;
120 } // end of wxMenuItem::wxMenuItem
122 wxMenuItem::~wxMenuItem()
124 } // end of wxMenuItem::~wxMenuItem
131 // Return the id for calling Win32 API functions
133 int wxMenuItem::GetRealId() const
135 return m_subMenu
? (int)m_subMenu
->GetHMenu() : GetId();
136 } // end of wxMenuItem::GetRealId
141 bool wxMenuItem::IsChecked() const
143 USHORT uFlag
= SHORT1FROMMR(::WinSendMsg( GetHMenuOf(m_parentMenu
)
145 ,MPFROM2SHORT(GetId(), TRUE
)
146 ,MPFROMSHORT(MIA_CHECKED
)
149 return (uFlag
& MIA_CHECKED
);
150 } // end of wxMenuItem::IsChecked
152 wxString
wxMenuItemBase::GetLabelFromText(
153 const wxString
& rText
156 return wxStripMenuCodes(rText
);
164 wxAcceleratorEntry
*wxMenuItem::GetAccel() const
166 return wxGetAccelFromString(GetText());
169 #endif // wxUSE_ACCEL
174 void wxMenuItem::Enable(
180 if (m_isEnabled
== bEnable
)
183 bOk
= (bool)::WinSendMsg( GetHMenuOf(m_parentMenu
)
185 ,MPFROM2SHORT(GetRealId(), TRUE
)
186 ,MPFROM2SHORT(MIA_DISABLED
, MIA_DISABLED
)
189 bOk
= (bool)::WinSendMsg( GetHMenuOf(m_parentMenu
)
191 ,MPFROM2SHORT(GetRealId(), TRUE
)
192 ,MPFROM2SHORT(MIA_DISABLED
, FALSE
)
196 wxLogLastError("EnableMenuItem");
198 wxMenuItemBase::Enable(bEnable
);
199 } // end of wxMenuItem::Enable
201 void wxMenuItem::Check(
207 wxCHECK_RET( m_isCheckable
, wxT("only checkable items may be checked") );
208 if (m_isChecked
== bCheck
)
211 bOk
= (bool)::WinSendMsg( GetHMenuOf(m_parentMenu
)
213 ,MPFROM2SHORT(GetRealId(), TRUE
)
214 ,MPFROM2SHORT(MIA_CHECKED
, MIA_CHECKED
)
217 bOk
= (bool)::WinSendMsg( GetHMenuOf(m_parentMenu
)
219 ,MPFROM2SHORT(GetRealId(), TRUE
)
220 ,MPFROM2SHORT(MIA_CHECKED
, FALSE
)
224 wxLogLastError("EnableMenuItem");
226 wxMenuItemBase::Check(bCheck
);
227 } // end of wxMenuItem::Check
229 void wxMenuItem::SetText(
230 const wxString
& rText
234 // Don't do anything if label didn't change
239 wxMenuItemBase::SetText(rText
);
240 OWNER_DRAWN_ONLY(wxOwnerDrawn::SetName(rText
));
242 HWND hMenu
= GetHMenuOf(m_parentMenu
);
244 wxCHECK_RET(hMenu
, wxT("menuitem without menu"));
247 m_parentMenu
->UpdateAccel(this);
248 #endif // wxUSE_ACCEL
250 USHORT uId
= GetRealId();
254 if (!::WinSendMsg( hMenu
256 ,MPFROM2SHORT(uId
, TRUE
)
260 wxLogLastError("GetMenuState");
264 uFlagsOld
= vItem
.afStyle
;
267 uFlagsOld
|= MIS_SUBMENU
;
272 #if wxUSE_OWNER_DRAWN
275 uFlagsOld
|= MIS_OWNERDRAW
;
281 uFlagsOld
|= MIS_TEXT
;
282 pData
= (BYTE
*)rText
.c_str();
288 if (!::WinSendMsg( hMenu
290 ,MPFROM2SHORT(uId
, TRUE
)
294 wxLogLastError(wxT("ModifyMenu"));
300 if (::WinSendMsg( hMenu
306 wxLogLastError(wxT("ModifyMenu"));
309 } // end of wxMenuItem::SetText
311 void wxMenuItem::SetCheckable(
315 wxMenuItemBase::SetCheckable(bCheckable
);
316 OWNER_DRAWN_ONLY(wxOwnerDrawn::SetCheckable(bCheckable
));
317 } // end of wxMenuItem::SetCheckable
319 // ----------------------------------------------------------------------------
321 // ----------------------------------------------------------------------------
323 wxMenuItem
* wxMenuItemBase::New(
326 , const wxString
& rName
327 , const wxString
& rHelp
332 return new wxMenuItem( pParentMenu
339 } // end of wxMenuItemBase::New