]>
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 // ----------------------------------------------------------------------------
58 // static function for translating menu labels
59 // ----------------------------------------------------------------------------
61 static wxString
TextToLabel(const wxString
& rTitle
)
65 for (pc
= rTitle
.c_str(); *pc
!= wxT('\0'); pc
++ )
69 if (*(pc
+1) == wxT('&'))
79 if ( *pc
== wxT('~') )
81 // tildes must be doubled to prevent them from being
82 // interpreted as accelerator character prefix by PM ???
91 // ============================================================================
93 // ============================================================================
95 // ----------------------------------------------------------------------------
96 // dynamic classes implementation
97 // ----------------------------------------------------------------------------
100 IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem
, wxMenuItemBase
, wxOwnerDrawn
)
101 #else //!USE_OWNER_DRAWN
102 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxMenuItemBase
)
103 #endif //USE_OWNER_DRAWN
105 // ----------------------------------------------------------------------------
107 // ----------------------------------------------------------------------------
112 wxMenuItem::wxMenuItem(
115 , const wxString
& rText
116 , const wxString
& rStrHelp
120 #if wxUSE_OWNER_DRAWN
121 : wxOwnerDrawn( TextToLabel(rText
)
124 #endif // owner drawn
126 wxASSERT_MSG(pParentMenu
!= NULL
, wxT("a menu item should have a parent"));
128 #if wxUSE_OWNER_DRAWN
131 // Set default menu colors
133 #define SYS_COLOR(c) (wxSystemSettings::GetColour(wxSYS_COLOUR_##c))
135 SetTextColour(SYS_COLOR(MENUTEXT
));
136 SetBackgroundColour(SYS_COLOR(MENU
));
139 // We don't want normal items be owner-drawn
144 #endif // wxUSE_OWNER_DRAWN
146 m_parentMenu
= pParentMenu
;
147 m_subMenu
= pSubMenu
;
151 m_text
= TextToLabel(rText
);
152 m_isCheckable
= bCheckable
;
154 memset(&m_vMenuData
, '\0', sizeof(m_vMenuData
));
156 } // end of wxMenuItem::wxMenuItem
158 wxMenuItem::~wxMenuItem()
160 } // end of wxMenuItem::~wxMenuItem
167 // Return the id for calling Win32 API functions
169 int wxMenuItem::GetRealId() const
171 return m_subMenu
? (int)m_subMenu
->GetHMenu() : GetId();
172 } // end of wxMenuItem::GetRealId
177 bool wxMenuItem::IsChecked() const
179 USHORT uFlag
= SHORT1FROMMR(::WinSendMsg( GetHMenuOf(m_parentMenu
)
181 ,MPFROM2SHORT(GetId(), TRUE
)
182 ,MPFROMSHORT(MIA_CHECKED
)
185 return (uFlag
& MIA_CHECKED
);
186 } // end of wxMenuItem::IsChecked
188 wxString
wxMenuItemBase::GetLabelFromText(
189 const wxString
& rText
193 for ( const wxChar
*pc
= rText
.c_str(); *pc
; pc
++ )
195 if ( *pc
== wxT('~') || *pc
== wxT('&') )
197 // '~' is the escape character for GTK+ and '&' is the one for
198 // wxWindows - skip both of them
210 void wxMenuItem::Enable(
216 if (m_isEnabled
== bEnable
)
219 bOk
= (bool)::WinSendMsg( GetHMenuOf(m_parentMenu
)
221 ,MPFROM2SHORT(GetRealId(), TRUE
)
222 ,MPFROM2SHORT(MIA_DISABLED
, FALSE
)
225 bOk
= (bool)::WinSendMsg( GetHMenuOf(m_parentMenu
)
227 ,MPFROM2SHORT(GetRealId(), TRUE
)
228 ,MPFROM2SHORT(MIA_DISABLED
, MIA_DISABLED
)
232 wxLogLastError("EnableMenuItem");
234 wxMenuItemBase::Enable(bEnable
);
235 } // end of wxMenuItem::Enable
237 void wxMenuItem::Check(
243 wxCHECK_RET( m_isCheckable
, wxT("only checkable items may be checked") );
244 if (m_isChecked
== bCheck
)
247 bOk
= (bool)::WinSendMsg( GetHMenuOf(m_parentMenu
)
249 ,MPFROM2SHORT(GetRealId(), TRUE
)
250 ,MPFROM2SHORT(MIA_CHECKED
, MIA_CHECKED
)
253 bOk
= (bool)::WinSendMsg( GetHMenuOf(m_parentMenu
)
255 ,MPFROM2SHORT(GetRealId(), TRUE
)
256 ,MPFROM2SHORT(MIA_CHECKED
, FALSE
)
260 wxLogLastError("CheckMenuItem");
262 wxMenuItemBase::Check(bCheck
);
263 } // end of wxMenuItem::Check
265 void wxMenuItem::SetText(
266 const wxString
& rText
270 // Don't do anything if label didn't change
273 wxString Text
= TextToLabel(rText
);
277 wxMenuItemBase::SetText(Text
);
278 OWNER_DRAWN_ONLY(wxOwnerDrawn::SetName(Text
));
280 HWND hMenu
= GetHMenuOf(m_parentMenu
);
282 wxCHECK_RET(hMenu
, wxT("menuitem without menu"));
285 m_parentMenu
->UpdateAccel(this);
286 #endif // wxUSE_ACCEL
288 USHORT uId
= GetRealId();
292 if (!::WinSendMsg( hMenu
294 ,MPFROM2SHORT(uId
, TRUE
)
298 wxLogLastError("GetMenuState");
302 uFlagsOld
= vItem
.afStyle
;
305 uFlagsOld
|= MIS_SUBMENU
;
310 #if wxUSE_OWNER_DRAWN
313 uFlagsOld
|= MIS_OWNERDRAW
;
319 uFlagsOld
|= MIS_TEXT
;
320 pData
= (BYTE
*)Text
.c_str();
326 if (!::WinSendMsg( hMenu
328 ,MPFROM2SHORT(uId
, TRUE
)
332 wxLogLastError(wxT("ModifyMenu"));
338 if (::WinSendMsg( hMenu
344 wxLogLastError(wxT("ModifyMenu"));
347 } // end of wxMenuItem::SetText
349 void wxMenuItem::SetCheckable(
353 wxMenuItemBase::SetCheckable(bCheckable
);
354 OWNER_DRAWN_ONLY(wxOwnerDrawn::SetCheckable(bCheckable
));
355 } // end of wxMenuItem::SetCheckable
357 // ----------------------------------------------------------------------------
359 // ----------------------------------------------------------------------------
361 wxMenuItem
* wxMenuItemBase::New(
364 , const wxString
& rName
365 , const wxString
& rHelp
370 return new wxMenuItem( pParentMenu
377 } // end of wxMenuItemBase::New