Fix wxHtmlWindow to correctly decide whether to show scrollbars.
[wxWidgets.git] / src / msw / menuitem.cpp
CommitLineData
2bda0e17 1///////////////////////////////////////////////////////////////////////////////
e4db172a 2// Name: src/msw/menuitem.cpp
2bda0e17
KB
3// Purpose: wxMenuItem implementation
4// Author: Vadim Zeitlin
c2dcfdef 5// Modified by:
2bda0e17
KB
6// Created: 11.11.97
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10///////////////////////////////////////////////////////////////////////////////
11
c2dcfdef
VZ
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
2bda0e17
KB
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
c2dcfdef 24 #pragma hdrstop
2bda0e17
KB
25#endif
26
1e6feb95
VZ
27#if wxUSE_MENUS
28
3b3dc801 29#include "wx/menuitem.h"
ee0a94cf 30#include "wx/stockitem.h"
e4db172a 31
2bda0e17 32#ifndef WX_PRECOMP
9d043a92
VZ
33 #include "wx/app.h"
34 #include "wx/dcmemory.h"
c2dcfdef
VZ
35 #include "wx/font.h"
36 #include "wx/bitmap.h"
37 #include "wx/settings.h"
4e938f5b 38 #include "wx/window.h"
0c589ad0 39 #include "wx/accel.h"
0c589ad0 40 #include "wx/string.h"
e4db172a 41 #include "wx/log.h"
3b3dc801 42 #include "wx/menu.h"
2bda0e17
KB
43#endif
44
717a57c2
VZ
45#if wxUSE_ACCEL
46 #include "wx/accel.h"
47#endif // wxUSE_ACCEL
48
42e69d6b 49#include "wx/msw/private.h"
98fbab9e 50#include "wx/msw/dc.h"
ce3ed50d 51
4676948b
JS
52#ifdef __WXWINCE__
53// Implemented in menu.cpp
54UINT GetMenuState(HMENU hMenu, UINT id, UINT flags) ;
55#endif
56
aa4919ed
VZ
57#if wxUSE_UXTHEME
58 #include "wx/msw/uxtheme.h"
59#endif
60
c2dcfdef 61// ---------------------------------------------------------------------------
974e8d94 62// macro
c2dcfdef
VZ
63// ---------------------------------------------------------------------------
64
974e8d94 65// hide the ugly cast
c2dcfdef
VZ
66#define GetHMenuOf(menu) ((HMENU)menu->GetHMenu())
67
2bda0e17
KB
68// ============================================================================
69// implementation
70// ============================================================================
71
98fbab9e
VZ
72#if wxUSE_OWNER_DRAWN
73
74#include "wx/fontutil.h"
75#include "wx/msw/private/metrics.h"
76
77#ifndef SPI_GETKEYBOARDCUES
78#define SPI_GETKEYBOARDCUES 0x100A
79#endif
80
81#ifndef DSS_HIDEPREFIX
82#define DSS_HIDEPREFIX 0x0200
83#endif
84
aa4919ed
VZ
85#if wxUSE_UXTHEME
86
87enum MENUPARTS
88{
89 MENU_MENUITEM_TMSCHEMA = 1,
90 MENU_SEPARATOR_TMSCHEMA = 6,
91 MENU_POPUPBACKGROUND = 9,
92 MENU_POPUPBORDERS = 10,
93 MENU_POPUPCHECK = 11,
94 MENU_POPUPCHECKBACKGROUND = 12,
95 MENU_POPUPGUTTER = 13,
96 MENU_POPUPITEM = 14,
97 MENU_POPUPSEPARATOR = 15,
98 MENU_POPUPSUBMENU = 16,
99};
100
101
102enum POPUPITEMSTATES
103{
104 MPI_NORMAL = 1,
105 MPI_HOT = 2,
106 MPI_DISABLED = 3,
107 MPI_DISABLEDHOT = 4,
108};
109
110enum POPUPCHECKBACKGROUNDSTATES
111{
112 MCB_DISABLED = 1,
113 MCB_NORMAL = 2,
114 MCB_BITMAP = 3,
115};
116
117enum POPUPCHECKSTATES
118{
119 MC_CHECKMARKNORMAL = 1,
120 MC_CHECKMARKDISABLED = 2,
121 MC_BULLETNORMAL = 3,
122 MC_BULLETDISABLED = 4,
123};
124
125const int TMT_MENUFONT = 803;
126const int TMT_BORDERSIZE = 2403;
127const int TMT_CONTENTMARGINS = 3602;
128const int TMT_SIZINGMARGINS = 3601;
129
130#endif // wxUSE_UXTHEME
131
98fbab9e
VZ
132#endif // wxUSE_OWNER_DRAWN
133
2bda0e17
KB
134// ----------------------------------------------------------------------------
135// dynamic classes implementation
136// ----------------------------------------------------------------------------
137
e70b4f10
SC
138#if wxUSE_EXTENDED_RTTI
139
140bool wxMenuItemStreamingCallback( const wxObject *object, wxWriter * , wxPersister * , wxxVariantArray & )
141{
142 const wxMenuItem * mitem = dynamic_cast<const wxMenuItem*>(object) ;
3b3dc801 143 if ( mitem->GetMenu() && !mitem->GetMenu()->GetTitle().empty() )
e70b4f10
SC
144 {
145 // we don't stream out the first two items for menus with a title, they will be reconstructed
146 if ( mitem->GetMenu()->FindItemByPosition(0) == mitem || mitem->GetMenu()->FindItemByPosition(1) == mitem )
147 return false ;
148 }
149 return true ;
150}
151
3ff066a4 152wxBEGIN_ENUM( wxItemKind )
598ddd96
WS
153 wxENUM_MEMBER( wxITEM_SEPARATOR )
154 wxENUM_MEMBER( wxITEM_NORMAL )
155 wxENUM_MEMBER( wxITEM_CHECK )
156 wxENUM_MEMBER( wxITEM_RADIO )
3ff066a4 157wxEND_ENUM( wxItemKind )
e70b4f10
SC
158
159IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxMenuItem, wxObject,"wx/menuitem.h",wxMenuItemStreamingCallback)
160
3ff066a4 161wxBEGIN_PROPERTIES_TABLE(wxMenuItem)
598ddd96
WS
162 wxPROPERTY( Parent,wxMenu*, SetMenu, GetMenu, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
163 wxPROPERTY( Id,int, SetId, GetId, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
3ff066a4
SC
164 wxPROPERTY( Text, wxString , SetText, GetText, wxString(), 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
165 wxPROPERTY( Help, wxString , SetHelp, GetHelp, wxString(), 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
af498247 166 wxREADONLY_PROPERTY( Kind, wxItemKind , GetKind , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
598ddd96
WS
167 wxPROPERTY( SubMenu,wxMenu*, SetSubMenu, GetSubMenu, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
168 wxPROPERTY( Enabled , bool , Enable , IsEnabled , wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
169 wxPROPERTY( Checked , bool , Check , IsChecked , wxxVariant((bool)false) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
170 wxPROPERTY( Checkable , bool , SetCheckable , IsCheckable , wxxVariant((bool)false) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
3ff066a4
SC
171wxEND_PROPERTIES_TABLE()
172
173wxBEGIN_HANDLERS_TABLE(wxMenuItem)
174wxEND_HANDLERS_TABLE()
175
176wxDIRECT_CONSTRUCTOR_6( wxMenuItem , wxMenu* , Parent , int , Id , wxString , Text , wxString , Help , wxItemKind , Kind , wxMenu* , SubMenu )
e70b4f10 177#else
621b3e21 178IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
e70b4f10 179#endif
2bda0e17
KB
180
181// ----------------------------------------------------------------------------
182// wxMenuItem
183// ----------------------------------------------------------------------------
184
98fbab9e
VZ
185#if wxUSE_OWNER_DRAWN
186
aa4919ed
VZ
187namespace
188{
189
190// helper class to keep information about metrics and other stuff
191// needed for measuring and drawing menu item
192class MenuDrawData
193{
194public:
195
196 struct Margins
197 {
198 int left;
199 int right;
200 int top;
201 int bottom;
202
203 Margins()
204 : left(0),
205 right(0),
206 top(0),
207 bottom(0)
208 {}
209 };
210
211 Margins ItemMargin; // popup item margins
212
213 Margins CheckMargin; // popup check margins
214 Margins CheckBgMargin; // popup check background margins
215
9c32ed26
VZ
216 Margins ArrowMargin; // popup submenu arrow margins
217
aa4919ed
VZ
218 Margins SeparatorMargin; // popup separator margins
219
220 SIZE CheckSize; // popup check size metric
9c32ed26 221 SIZE ArrowSize; // popup submenu arrow size metric
aa4919ed
VZ
222 SIZE SeparatorSize; // popup separator size metric
223
aa4919ed
VZ
224 int TextBorder; // popup border space between
225 // item text and gutter
226
9c32ed26
VZ
227 int AccelBorder; // popup border space between
228 // item text and accelerator
229
230 int ArrowBorder; // popup border space between
231 // item accelerator and submenu arrow
232
233 int Offset; // system added space at the end of the menu,
234 // add this offset for remove the extra space
235
aa4919ed
VZ
236 wxFont Font; // default menu font
237
238 bool AlwaysShowCues; // must keyboard cues always be shown?
239
240 bool Theme; // is data initialized for FullTheme?
241
242 static const MenuDrawData* Get()
243 {
244 #if wxUSE_UXTHEME
245 bool theme = MenuLayout() == FullTheme;
246 if ( ms_instance->Theme != theme )
247 ms_instance->Init();
248 #endif // wxUSE_UXTHEME
249 return ms_instance;
250 }
251
252 MenuDrawData()
253 {
254 ms_instance = this;
255 Init();
256 }
257
258
259 // get the theme engine or NULL if themes
260 // are not available or not supported on menu
261 static wxUxThemeEngine *GetUxThemeEngine()
262 {
263 #if wxUSE_UXTHEME
264 if ( MenuLayout() == FullTheme )
265 return wxUxThemeEngine::GetIfActive();
266 #endif // wxUSE_UXTHEME
267 return NULL;
268 }
269
270
271 enum MenuLayoutType
272 {
273 FullTheme, // full menu themes (Vista or new)
274 PseudoTheme, // pseudo menu themes (on XP)
275 Classic
276 };
277
278 static MenuLayoutType MenuLayout()
279 {
280 MenuLayoutType menu = Classic;
281 #if wxUSE_UXTHEME
282 if ( wxUxThemeEngine::GetIfActive() != NULL )
283 {
284 static wxWinVersion ver = wxGetWinVersion();
285 if ( ver >= wxWinVersion_Vista )
286 menu = FullTheme;
287 else if ( ver == wxWinVersion_XP )
288 menu = PseudoTheme;
289 }
290 #endif // wxUSE_UXTHEME
291 return menu;
292 }
293
294private:
295 void Init();
296
297 static MenuDrawData* ms_instance;
298};
299
300MenuDrawData* MenuDrawData::ms_instance = NULL;
301
302MenuDrawData s_menuData;
303
304void MenuDrawData::Init()
305{
306#if wxUSE_UXTHEME
307 wxUxThemeEngine* theme = GetUxThemeEngine();
308 if ( theme )
309 {
310 wxWindow* window = static_cast<wxApp*>(wxApp::GetInstance())->GetTopWindow();
311 wxUxThemeHandle hTheme(window, L"MENU");
312
313 theme->GetThemeMargins(hTheme, NULL, MENU_POPUPITEM, 0,
314 TMT_CONTENTMARGINS, NULL,
315 reinterpret_cast<MARGINS*>(&ItemMargin));
316
317 theme->GetThemeMargins(hTheme, NULL, MENU_POPUPCHECK, 0,
318 TMT_CONTENTMARGINS, NULL,
319 reinterpret_cast<MARGINS*>(&CheckMargin));
320 theme->GetThemeMargins(hTheme, NULL, MENU_POPUPCHECKBACKGROUND, 0,
321 TMT_CONTENTMARGINS, NULL,
322 reinterpret_cast<MARGINS*>(&CheckBgMargin));
323
9c32ed26
VZ
324 theme->GetThemeMargins(hTheme, NULL, MENU_POPUPSUBMENU, 0,
325 TMT_CONTENTMARGINS, NULL,
326 reinterpret_cast<MARGINS*>(&ArrowMargin));
327
aa4919ed
VZ
328 theme->GetThemeMargins(hTheme, NULL, MENU_POPUPSEPARATOR, 0,
329 TMT_SIZINGMARGINS, NULL,
330 reinterpret_cast<MARGINS*>(&SeparatorMargin));
331
332 theme->GetThemePartSize(hTheme, NULL, MENU_POPUPCHECK, 0,
333 NULL, TS_TRUE, &CheckSize);
334
9c32ed26
VZ
335 theme->GetThemePartSize(hTheme, NULL, MENU_POPUPSUBMENU, 0,
336 NULL, TS_TRUE, &ArrowSize);
337
aa4919ed
VZ
338 theme->GetThemePartSize(hTheme, NULL, MENU_POPUPSEPARATOR, 0,
339 NULL, TS_TRUE, &SeparatorSize);
340
aa4919ed
VZ
341 theme->GetThemeInt(hTheme, MENU_POPUPBACKGROUND, 0, TMT_BORDERSIZE, &TextBorder);
342
9c32ed26
VZ
343 AccelBorder = 34;
344 ArrowBorder = 0;
345
346 Offset = -14;
347
aa4919ed
VZ
348 wxNativeFontInfo fontInfo;
349 theme->GetThemeSysFont(hTheme, TMT_MENUFONT, &fontInfo.lf);
350 Font = wxFont(fontInfo);
351
352 Theme = true;
353
354 // native menu doesn't uses the vertical margins
355 ItemMargin.top = ItemMargin.bottom = 0;
356
357 // native menu uses small top margin for separator
358 if ( SeparatorMargin.top >= 2 )
359 SeparatorMargin.top -= 2;
360 }
361 else
362#endif // wxUSE_UXTHEME
363 {
364 const NONCLIENTMETRICS& metrics = wxMSWImpl::GetNonClientMetrics();
365
366 ItemMargin = Margins();
367
368 CheckMargin.left =
369 CheckMargin.right = ::GetSystemMetrics(SM_CXEDGE);
370 CheckMargin.top =
371 CheckMargin.bottom = ::GetSystemMetrics(SM_CYEDGE);
372
373 CheckBgMargin = Margins();
374
375 CheckSize.cx = ::GetSystemMetrics(SM_CXMENUCHECK);
376 CheckSize.cy = ::GetSystemMetrics(SM_CYMENUCHECK);
377
9c32ed26
VZ
378 ArrowMargin = Margins();
379
380 ArrowSize = CheckSize;
381
aa4919ed
VZ
382 // separator height with margins
383 int sepFullSize = metrics.iMenuHeight / 2;
384
385 SeparatorMargin.left =
386 SeparatorMargin.right = 1;
387 SeparatorMargin.top =
388 SeparatorMargin.bottom = sepFullSize / 2 - 1;
389
390 SeparatorSize.cx = 1;
391 SeparatorSize.cy = sepFullSize - SeparatorMargin.top - SeparatorMargin.bottom;
392
393 TextBorder = 0;
394 AccelBorder = 8;
9c32ed26
VZ
395 ArrowBorder = 6;
396
397 Offset = -12;
aa4919ed
VZ
398
399 Font = wxFont(wxNativeFontInfo(metrics.lfMenuFont));
400
401 Theme = false;
402 }
403
404 int value;
405 if ( ::SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &value, 0) == 0 )
406 {
407 // if it's not supported, we must be on an old Windows version
408 // which always shows them
409 value = 1;
410 }
411
412 AlwaysShowCues = value == 1;
413
414}
415
416} // anonymous namespace
98fbab9e
VZ
417
418#endif // wxUSE_OWNER_DRAWN
419
420
2bda0e17
KB
421// ctor & dtor
422// -----------
423
974e8d94
VZ
424wxMenuItem::wxMenuItem(wxMenu *pParentMenu,
425 int id,
426 const wxString& text,
427 const wxString& strHelp,
d65c269b 428 wxItemKind kind,
90002c49 429 wxMenu *pSubMenu)
d65c269b 430 : wxMenuItemBase(pParentMenu, id, text, strHelp, kind, pSubMenu)
2bda0e17 431{
2368dcda
VZ
432 Init();
433}
2bda0e17 434
efebabb7 435#if WXWIN_COMPATIBILITY_2_8
2368dcda
VZ
436wxMenuItem::wxMenuItem(wxMenu *parentMenu,
437 int id,
438 const wxString& text,
439 const wxString& help,
440 bool isCheckable,
441 wxMenu *subMenu)
442 : wxMenuItemBase(parentMenu, id, text, help,
443 isCheckable ? wxITEM_CHECK : wxITEM_NORMAL, subMenu)
2368dcda
VZ
444{
445 Init();
446}
efebabb7 447#endif
2368dcda
VZ
448
449void wxMenuItem::Init()
450{
be15b995 451 m_radioGroup.start = -1;
598ddd96 452 m_isRadioGroupStart = false;
0472ece7 453
47d67540 454#if wxUSE_OWNER_DRAWN
c2dcfdef 455
51d2fa37
VZ
456 // when the color is not valid, wxOwnerDraw takes the default ones.
457 // If we set the colors here and they are changed by the user during
458 // the execution, then the colors are not updated until the application
459 // is restarted and our menus look bad
460 SetTextColour(wxNullColour);
461 SetBackgroundColour(wxNullColour);
6d5b2a57 462
271fa250 463 // setting default colors switched ownerdraw on: switch it off again
98fbab9e 464 SetOwnerDrawn(false);
2bda0e17 465
271fa250 466 // switch ownerdraw back on if using a non default margin
fa7134b0 467 if ( !IsSeparator() )
271fa250
JS
468 SetMarginWidth(GetMarginWidth());
469
974e8d94 470#endif // wxUSE_OWNER_DRAWN
2bda0e17
KB
471}
472
c2dcfdef 473wxMenuItem::~wxMenuItem()
2bda0e17
KB
474{
475}
476
477// misc
478// ----
479
c2dcfdef 480// return the id for calling Win32 API functions
dca0f651 481WXWPARAM wxMenuItem::GetMSWId() const
c2dcfdef 482{
660e7fda
VZ
483 // we must use ids in unsigned short range with Windows functions, if we
484 // pass ids > USHRT_MAX to them they get very confused (e.g. start
485 // generating WM_COMMAND messages with negative high word of wParam), so
486 // use the cast to ensure the id is in range
dca0f651 487 return m_subMenu ? wxPtrToUInt(m_subMenu->GetHMenu())
5c33522f 488 : static_cast<unsigned short>(GetId());
c2dcfdef
VZ
489}
490
3dfac970
VZ
491// get item state
492// --------------
493
a8cfd0cb 494bool wxMenuItem::IsChecked() const
3dfac970 495{
654c223b
VZ
496 // fix that RTTI is always getting the correct state (separators cannot be
497 // checked, but the Windows call below returns true
fa7134b0 498 if ( IsSeparator() )
654c223b 499 return false;
e70b4f10 500
654c223b
VZ
501 // the item might not be attached to a menu yet
502 //
503 // TODO: shouldn't we just always call the base class version? It seems
504 // like it ought to always be in sync
505 if ( !m_parentMenu )
506 return wxMenuItemBase::IsChecked();
507
508 HMENU hmenu = GetHMenuOf(m_parentMenu);
509 int flag = ::GetMenuState(hmenu, GetMSWId(), MF_BYCOMMAND);
3dfac970 510
4aee367e 511 return (flag & MF_CHECKED) != 0;
3dfac970
VZ
512}
513
be15b995
VZ
514// radio group stuff
515// -----------------
516
517void wxMenuItem::SetAsRadioGroupStart()
518{
598ddd96 519 m_isRadioGroupStart = true;
be15b995
VZ
520}
521
522void wxMenuItem::SetRadioGroupStart(int start)
523{
524 wxASSERT_MSG( !m_isRadioGroupStart,
9a83f860 525 wxT("should only be called for the next radio items") );
be15b995
VZ
526
527 m_radioGroup.start = start;
528}
529
530void wxMenuItem::SetRadioGroupEnd(int end)
531{
532 wxASSERT_MSG( m_isRadioGroupStart,
9a83f860 533 wxT("should only be called for the first radio item") );
be15b995
VZ
534
535 m_radioGroup.end = end;
536}
537
2bda0e17
KB
538// change item state
539// -----------------
540
717a57c2 541void wxMenuItem::Enable(bool enable)
2bda0e17 542{
717a57c2
VZ
543 if ( m_isEnabled == enable )
544 return;
545
654c223b
VZ
546 if ( m_parentMenu )
547 {
548 long rc = EnableMenuItem(GetHMenuOf(m_parentMenu),
549 GetMSWId(),
550 MF_BYCOMMAND |
551 (enable ? MF_ENABLED : MF_GRAYED));
c2dcfdef 552
654c223b
VZ
553 if ( rc == -1 )
554 {
555 wxLogLastError(wxT("EnableMenuItem"));
556 }
c2dcfdef 557 }
717a57c2
VZ
558
559 wxMenuItemBase::Enable(enable);
2bda0e17
KB
560}
561
717a57c2 562void wxMenuItem::Check(bool check)
2bda0e17 563{
d65c269b 564 wxCHECK_RET( IsCheckable(), wxT("only checkable items may be checked") );
c2dcfdef 565
717a57c2
VZ
566 if ( m_isChecked == check )
567 return;
c2dcfdef 568
654c223b 569 if ( m_parentMenu )
0472ece7 570 {
654c223b
VZ
571 int flags = check ? MF_CHECKED : MF_UNCHECKED;
572 HMENU hmenu = GetHMenuOf(m_parentMenu);
0472ece7 573
654c223b 574 if ( GetKind() == wxITEM_RADIO )
be15b995 575 {
654c223b
VZ
576 // it doesn't make sense to uncheck a radio item -- what would this
577 // do?
578 if ( !check )
579 return;
580
581 // get the index of this item in the menu
582 const wxMenuItemList& items = m_parentMenu->GetMenuItems();
583 int pos = items.IndexOf(this);
584 wxCHECK_RET( pos != wxNOT_FOUND,
9a83f860 585 wxT("menuitem not found in the menu items list?") );
654c223b
VZ
586
587 // get the radio group range
588 int start,
589 end;
590
591 if ( m_isRadioGroupStart )
592 {
593 // we already have all information we need
594 start = pos;
595 end = m_radioGroup.end;
596 }
597 else // next radio group item
598 {
599 // get the radio group end from the start item
600 start = m_radioGroup.start;
601 end = items.Item(start)->GetData()->m_radioGroup.end;
602 }
be15b995 603
0472ece7 604#ifdef __WIN32__
654c223b
VZ
605 // calling CheckMenuRadioItem() with such parameters hangs my system
606 // (NT4 SP6) and I suspect this could happen to the others as well,
607 // so don't do it!
608 wxCHECK_RET( start != -1 && end != -1,
9a83f860 609 wxT("invalid ::CheckMenuRadioItem() parameter(s)") );
654c223b
VZ
610
611 if ( !::CheckMenuRadioItem(hmenu,
612 start, // the first radio group item
613 end, // the last one
614 pos, // the one to check
615 MF_BYPOSITION) )
616 {
9a83f860 617 wxLogLastError(wxT("CheckMenuRadioItem"));
654c223b 618 }
0472ece7
VZ
619#endif // __WIN32__
620
654c223b
VZ
621 // also uncheck all the other items in this radio group
622 wxMenuItemList::compatibility_iterator node = items.Item(start);
623 for ( int n = start; n <= end && node; n++ )
0472ece7 624 {
654c223b
VZ
625 if ( n != pos )
626 {
627 node->GetData()->m_isChecked = false;
628 }
0472ece7 629
654c223b
VZ
630 node = node->GetNext();
631 }
0472ece7 632 }
654c223b 633 else // check item
0472ece7 634 {
654c223b
VZ
635 if ( ::CheckMenuItem(hmenu,
636 GetMSWId(),
637 MF_BYCOMMAND | flags) == (DWORD)-1 )
638 {
9a83f860 639 wxFAIL_MSG(wxT("CheckMenuItem() failed, item not in the menu?"));
654c223b 640 }
0472ece7 641 }
c2dcfdef 642 }
717a57c2
VZ
643
644 wxMenuItemBase::Check(check);
c2dcfdef
VZ
645}
646
52af3158 647void wxMenuItem::SetItemLabel(const wxString& txt)
c2dcfdef 648{
ee0a94cf
RR
649 wxString text = txt;
650
c2dcfdef 651 // don't do anything if label didn't change
ee0a94cf 652 if ( m_text == txt )
c2dcfdef
VZ
653 return;
654
345319d6 655 // wxMenuItemBase will do stock ID checks
52af3158 656 wxMenuItemBase::SetItemLabel(text);
345319d6 657
5c6aad47
VZ
658 // the item can be not attached to any menu yet and SetItemLabel() is still
659 // valid to call in this case and should do nothing else
3350ab0c
VZ
660 if ( !m_parentMenu )
661 return;
662
654c223b
VZ
663#if wxUSE_ACCEL
664 m_parentMenu->UpdateAccel(this);
665#endif // wxUSE_ACCEL
666
5c6aad47
VZ
667 const UINT id = GetMSWId();
668 HMENU hMenu = GetHMenuOf(m_parentMenu);
669 if ( !hMenu || ::GetMenuState(hMenu, id, MF_BYCOMMAND) == (UINT)-1 )
670 return;
671
3d45718d
VZ
672#if wxUSE_OWNER_DRAWN
673 if ( IsOwnerDrawn() )
c2dcfdef 674 {
3d45718d
VZ
675 // we don't need to do anything for owner drawn items, they will redraw
676 // themselves using the new text the next time they're displayed
677 return;
c2dcfdef 678 }
3d45718d 679#endif // owner drawn
c2dcfdef 680
3d45718d 681 // update the text of the native menu item
3d45718d 682 WinStruct<MENUITEMINFO> info;
c2dcfdef 683
3d45718d
VZ
684 // surprisingly, calling SetMenuItemInfo() with just MIIM_STRING doesn't
685 // work as it resets the menu bitmap, so we need to first get the old item
686 // state and then modify it
687 const bool isLaterThanWin95 = wxGetWinVersion() > wxWinVersion_95;
d4290fa5
VZ
688 info.fMask = MIIM_STATE |
689 MIIM_ID |
690 MIIM_SUBMENU |
691 MIIM_CHECKMARKS |
692 MIIM_DATA;
3d45718d
VZ
693 if ( isLaterThanWin95 )
694 info.fMask |= MIIM_BITMAP | MIIM_FTYPE;
695 else
d4290fa5 696 info.fMask |= MIIM_TYPE;
3d45718d
VZ
697 if ( !::GetMenuItemInfo(hMenu, id, FALSE, &info) )
698 {
699 wxLogLastError(wxT("GetMenuItemInfo"));
700 return;
701 }
702
703 if ( isLaterThanWin95 )
704 info.fMask |= MIIM_STRING;
705 //else: MIIM_TYPE already specified
706 info.dwTypeData = (LPTSTR)m_text.wx_str();
707 info.cch = m_text.length();
708 if ( !::SetMenuItemInfo(hMenu, id, FALSE, &info) )
709 {
710 wxLogLastError(wxT("SetMenuItemInfo"));
c2dcfdef
VZ
711 }
712}
2bda0e17 713
98fbab9e
VZ
714#if wxUSE_OWNER_DRAWN
715
9c32ed26
VZ
716int wxMenuItem::MeasureAccelWidth() const
717{
718 wxString accel = GetItemLabel().AfterFirst(wxT('\t'));
719
720 wxMemoryDC dc;
721 wxFont font;
722 GetFontToUse(font);
723 dc.SetFont(font);
724
725 wxCoord w;
726 dc.GetTextExtent(accel, &w, NULL);
727
728 return w;
729}
730
98fbab9e 731wxString wxMenuItem::GetName() const
974e8d94 732{
98fbab9e 733 return GetItemLabelText();
974e8d94
VZ
734}
735
98fbab9e
VZ
736bool wxMenuItem::OnMeasureItem(size_t *width, size_t *height)
737{
aa4919ed
VZ
738 const MenuDrawData* data = MenuDrawData::Get();
739
98fbab9e
VZ
740 if ( IsOwnerDrawn() )
741 {
aa4919ed
VZ
742 *width = data->ItemMargin.left + data->ItemMargin.right;
743 *height = data->ItemMargin.top + data->ItemMargin.bottom;
98fbab9e 744
aa4919ed 745 if ( IsSeparator() )
98fbab9e 746 {
aa4919ed
VZ
747 *width += data->SeparatorSize.cx
748 + data->SeparatorMargin.left + data->SeparatorMargin.right;
749 *height += data->SeparatorSize.cy
750 + data->SeparatorMargin.top + data->SeparatorMargin.bottom;
751 return true;
98fbab9e
VZ
752 }
753
9c32ed26 754 wxString str = GetName();
aa4919ed 755
98fbab9e
VZ
756 wxMemoryDC dc;
757 wxFont font;
758 GetFontToUse(font);
759 dc.SetFont(font);
760
761 wxCoord w, h;
762 dc.GetTextExtent(str, &w, &h);
aa4919ed 763
9c32ed26 764 *width = data->TextBorder + w + data->AccelBorder;
98fbab9e 765 *height = h;
aa4919ed 766
9c32ed26
VZ
767 w = m_parentMenu->GetMaxAccelWidth();
768 if ( w > 0 )
769 *width += w + data->ArrowBorder;
770
771 *width += data->Offset;
772 *width += data->ArrowMargin.left + data->ArrowSize.cx + data->ArrowMargin.right;
98fbab9e
VZ
773 }
774 else // don't draw the text, just the bitmap (if any)
775 {
776 *width = 0;
777 *height = 0;
778 }
779
aa4919ed
VZ
780 // bitmap
781
782 if ( IsOwnerDrawn() )
98fbab9e 783 {
03cc2991 784 // width of menu icon with margins in ownerdrawn menu
aa4919ed
VZ
785 // if any bitmap is not set, the width of space reserved for icon
786 // image is equal to the width of std check mark,
787 // if bitmap is set, then the width is set to the width of the widest
788 // bitmap in menu (GetMarginWidth()) unless std check mark is wider,
789 // then it's is set to std mark's width
790 int imgWidth = wxMax(GetMarginWidth(), data->CheckSize.cx)
791 + data->CheckMargin.left + data->CheckMargin.right;
792
793 *width += imgWidth + data->CheckBgMargin.left + data->CheckBgMargin.right;
794 }
795
796 if ( m_bmpChecked.IsOk() || m_bmpChecked.IsOk() )
797 {
798 // get size of bitmap always return valid value (0 for invalid bitmap),
799 // so we don't needed check if bitmap is valid ;)
800 size_t heightBmp = wxMax(m_bmpChecked.GetHeight(), m_bmpUnchecked.GetHeight());
801 size_t widthtBmp = wxMax(m_bmpChecked.GetWidth(), m_bmpUnchecked.GetWidth());
98fbab9e 802
98fbab9e
VZ
803 if ( IsOwnerDrawn() )
804 {
aa4919ed 805 heightBmp += data->CheckMargin.top + data->CheckMargin.bottom;
98fbab9e 806 }
aa4919ed 807 else
98fbab9e 808 {
aa4919ed
VZ
809 // we must allocate enough space for the bitmap
810 *width += widthtBmp;
98fbab9e 811 }
98fbab9e 812
aa4919ed
VZ
813 // Is BMP height larger than text height?
814 if ( *height < heightBmp )
815 *height = heightBmp;
98fbab9e
VZ
816 }
817
818 // make sure that this item is at least as tall as the system menu height
aa4919ed
VZ
819 const size_t menuHeight = data->CheckMargin.top + data->CheckMargin.bottom
820 + data->CheckSize.cy;
821 if (*height < menuHeight)
822 *height = menuHeight;
98fbab9e
VZ
823
824 return true;
825}
826
827bool wxMenuItem::OnDrawItem(wxDC& dc, const wxRect& rc,
828 wxODAction WXUNUSED(act), wxODStatus stat)
829{
aa4919ed 830 const MenuDrawData* data = MenuDrawData::Get();
98fbab9e 831
aa4919ed
VZ
832 wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl();
833 HDC hdc = GetHdcOf(*impl);
98fbab9e 834
aa4919ed
VZ
835 RECT rect;
836 wxCopyRectToRECT(rc, rect);
98fbab9e 837
03cc2991 838 int imgWidth = wxMax(GetMarginWidth(), data->CheckSize.cx);
98fbab9e
VZ
839
840 if ( IsOwnerDrawn() )
841 {
aa4919ed
VZ
842 // font and colors to use
843 wxFont font;
844 GetFontToUse(font);
845
846 wxColour colText1, colBack1;
847 GetColourToUse(stat, colText1, colBack1);
848
849 DWORD colText = wxColourToPalRGB(colText1);
850 DWORD colBack = wxColourToPalRGB(colBack1);
851
852 // calculate metrics of item parts
853 RECT rcSelection;
854 RECT rcSeparator;
855 RECT rcGutter;
856 RECT rcText;
857
858 SetRect(&rcSelection,
859 rect.left + data->ItemMargin.left,
860 rect.top + data->ItemMargin.top,
861 rect.right - data->ItemMargin.right,
862 rect.bottom - data->ItemMargin.bottom);
863
864 SetRect(&rcSeparator,
865 rcSelection.left + data->SeparatorMargin.left,
866 rcSelection.top + data->SeparatorMargin.top,
867 rcSelection.right - data->SeparatorMargin.right,
868 rcSelection.bottom - data->SeparatorMargin.bottom);
869
870 CopyRect(&rcGutter, &rcSelection);
871 rcGutter.right = data->ItemMargin.left
872 + data->CheckBgMargin.left
03cc2991 873 + data->CheckMargin.left
aa4919ed 874 + imgWidth
03cc2991 875 + data->CheckMargin.right
aa4919ed
VZ
876 + data->CheckBgMargin.right;
877
878 CopyRect(&rcText, &rcSelection);
879 rcText.left = rcGutter.right + data->TextBorder;
880
03cc2991
VZ
881 // we draw the text label vertically centered, but this results in it
882 // being 1px too low compared to native menus for some reason, fix it
883 if ( data->MenuLayout() != MenuDrawData::FullTheme )
884 rcText.top--;
885
aa4919ed
VZ
886#if wxUSE_UXTHEME
887 wxUxThemeEngine* theme = MenuDrawData::GetUxThemeEngine();
888 if ( theme )
98fbab9e 889 {
aa4919ed
VZ
890 POPUPITEMSTATES state;
891 if ( stat & wxODDisabled )
892 {
893 state = (stat & wxODSelected) ? MPI_DISABLEDHOT
894 : MPI_DISABLED;
895 }
896 else if ( stat & wxODSelected )
897 {
898 state = MPI_HOT;
899 }
900 else
901 {
902 state = MPI_NORMAL;
903 }
98fbab9e 904
aa4919ed 905 wxUxThemeHandle hTheme(GetMenu()->GetWindow(), L"MENU");
98fbab9e 906
aa4919ed
VZ
907 if ( theme->IsThemeBackgroundPartiallyTransparent(hTheme,
908 MENU_POPUPITEM, state) )
909 {
910 theme->DrawThemeBackground(hTheme, hdc,
911 MENU_POPUPBACKGROUND,
912 0, &rect, NULL);
913 }
98fbab9e 914
aa4919ed
VZ
915 theme->DrawThemeBackground(hTheme, hdc, MENU_POPUPGUTTER,
916 0, &rcGutter, NULL);
98fbab9e 917
aa4919ed
VZ
918 if ( IsSeparator() )
919 {
920 rcSeparator.left = rcGutter.right;
921 theme->DrawThemeBackground(hTheme, hdc, MENU_POPUPSEPARATOR,
922 0, &rcSeparator, NULL);
923 return true;
924 }
98fbab9e 925
aa4919ed
VZ
926 theme->DrawThemeBackground(hTheme, hdc, MENU_POPUPITEM,
927 state, &rcSelection, NULL);
98fbab9e 928
aa4919ed
VZ
929 }
930 else
931#endif // wxUSE_UXTHEME
932 {
933 if ( IsSeparator() )
934 {
935 DrawEdge(hdc, &rcSeparator, EDGE_ETCHED, BF_TOP);
936 return true;
937 }
98fbab9e 938
aa4919ed
VZ
939 AutoHBRUSH hbr(colBack);
940 SelectInHDC selBrush(hdc, hbr);
941 ::FillRect(hdc, &rcSelection, hbr);
942 }
98fbab9e 943
98fbab9e 944
aa4919ed
VZ
945 // draw text label
946 // using native API because it recognizes '&'
98fbab9e 947
aa4919ed
VZ
948 COLORREF colOldText = ::SetTextColor(hdc, colText);
949 COLORREF colOldBack = ::SetBkColor(hdc, colBack);
98fbab9e 950
aa4919ed 951 int prevMode = SetBkMode(hdc, TRANSPARENT);
98fbab9e 952
98fbab9e
VZ
953 SelectInHDC selFont(hdc, GetHfontOf(font));
954
98fbab9e 955
aa4919ed
VZ
956 // item text name without menemonic for calculating size
957 wxString text = GetName();
958
959 SIZE textSize;
960 ::GetTextExtentPoint32(hdc, text.c_str(), text.length(), &textSize);
98fbab9e 961
aa4919ed
VZ
962 // item text name with menemonic
963 text = GetItemLabel().BeforeFirst('\t');
98fbab9e
VZ
964
965 int flags = DST_PREFIXTEXT;
aa4919ed
VZ
966 // themes menu is using specified color for disabled labels
967 if ( data->MenuLayout() == MenuDrawData::Classic &&
968 (stat & wxODDisabled) && !(stat & wxODSelected) )
98fbab9e
VZ
969 flags |= DSS_DISABLED;
970
aa4919ed 971 if ( (stat & wxODHidePrefix) && !data->AlwaysShowCues )
98fbab9e
VZ
972 flags |= DSS_HIDEPREFIX;
973
aa4919ed
VZ
974 int x = rcText.left;
975 int y = rcText.top + (rcText.bottom - rcText.top - textSize.cy) / 2;
98fbab9e
VZ
976
977 ::DrawState(hdc, NULL, NULL, (LPARAM)text.wx_str(),
aa4919ed 978 text.length(), x, y, 0, 0, flags);
98fbab9e
VZ
979
980 // ::SetTextAlign(hdc, TA_RIGHT) doesn't work with DSS_DISABLED or DSS_MONO
981 // as the last parameter in DrawState() (at least with Windows98). So we have
982 // to take care of right alignment ourselves.
983 wxString accel = GetItemLabel().AfterFirst(wxT('\t'));
984 if ( !accel.empty() )
985 {
aa4919ed
VZ
986 SIZE accelSize;
987 ::GetTextExtentPoint32(hdc, accel.c_str(), accel.length(), &accelSize);
98fbab9e
VZ
988
989 int flags = DST_TEXT;
aa4919ed
VZ
990 // themes menu is using specified color for disabled labels
991 if ( data->MenuLayout() == MenuDrawData::Classic &&
992 (stat & wxODDisabled) && !(stat & wxODSelected) )
98fbab9e
VZ
993 flags |= DSS_DISABLED;
994
9c32ed26
VZ
995 int x = rcText.right - data->ArrowMargin.left
996 - data->ArrowSize.cx
997 - data->ArrowMargin.right
998 - data->ArrowBorder;
999
1000 // right align accel on FullTheme menu, left otherwise
1001 if ( data->MenuLayout() == MenuDrawData::FullTheme)
1002 x -= accelSize.cx;
1003 else
1004 x -= m_parentMenu->GetMaxAccelWidth();
98fbab9e 1005
aa4919ed
VZ
1006 int y = rcText.top + (rcText.bottom - rcText.top - accelSize.cy) / 2;
1007
98fbab9e
VZ
1008 ::DrawState(hdc, NULL, NULL, (LPARAM)accel.wx_str(),
1009 accel.length(), x, y, 0, 0, flags);
1010 }
1011
1012 ::SetBkMode(hdc, prevMode);
aa4919ed
VZ
1013 ::SetBkColor(hdc, colOldBack);
1014 ::SetTextColor(hdc, colOldText);
98fbab9e
VZ
1015 }
1016
1017
1018 // draw the bitmap
aa4919ed
VZ
1019
1020 RECT rcImg;
1021 SetRect(&rcImg,
03cc2991
VZ
1022 rect.left + data->ItemMargin.left
1023 + data->CheckBgMargin.left
1024 + data->CheckMargin.left,
1025 rect.top + data->ItemMargin.top
1026 + data->CheckBgMargin.top
1027 + data->CheckMargin.top,
1028 rect.left + data->ItemMargin.left
1029 + data->CheckBgMargin.left
1030 + data->CheckMargin.left
1031 + imgWidth,
1032 rect.bottom - data->ItemMargin.bottom
1033 - data->CheckBgMargin.bottom
1034 - data->CheckMargin.bottom);
aa4919ed 1035
98fbab9e
VZ
1036 if ( IsCheckable() && !m_bmpChecked.Ok() )
1037 {
1038 if ( stat & wxODChecked )
1039 {
b8190883 1040 DrawStdCheckMark((WXHDC)hdc, &rcImg, stat);
98fbab9e
VZ
1041 }
1042 }
1043 else
1044 {
1045 wxBitmap bmp;
1046
1047 if ( stat & wxODDisabled )
1048 {
1049 bmp = GetDisabledBitmap();
1050 }
1051
1052 if ( !bmp.Ok() )
1053 {
1054 // for not checkable bitmaps we should always use unchecked one
1055 // because their checked bitmap is not set
1056 bmp = GetBitmap(!IsCheckable() || (stat & wxODChecked));
1057
1058#if wxUSE_IMAGE
1059 if ( bmp.Ok() && stat & wxODDisabled )
1060 {
1061 // we need to grey out the bitmap as we don't have any specific
1062 // disabled bitmap
1063 wxImage imgGrey = bmp.ConvertToImage().ConvertToGreyscale();
1064 if ( imgGrey.Ok() )
1065 bmp = wxBitmap(imgGrey);
1066 }
1067#endif // wxUSE_IMAGE
1068 }
1069
1070 if ( bmp.Ok() )
1071 {
1072 wxMemoryDC dcMem(&dc);
1073 dcMem.SelectObjectAsSource(bmp);
1074
1075 // center bitmap
aa4919ed 1076 int nBmpWidth = bmp.GetWidth(),
98fbab9e
VZ
1077 nBmpHeight = bmp.GetHeight();
1078
1079 // there should be enough space!
aa4919ed 1080 wxASSERT( nBmpWidth <= imgWidth && nBmpHeight <= (rcImg.bottom - rcImg.top) );
98fbab9e 1081
aa4919ed
VZ
1082 int x = rcImg.left + (imgWidth - nBmpWidth) / 2;
1083 int y = rcImg.top + (rcImg.bottom - rcImg.top - nBmpHeight) / 2;
1084 dc.Blit(x, y, nBmpWidth, nBmpHeight, &dcMem, 0, 0, wxCOPY, true);
98fbab9e
VZ
1085 }
1086 }
1087
98fbab9e
VZ
1088 return true;
1089
1090}
1091
ee009313
VZ
1092namespace
1093{
1094
1095// helper function for draw coloured check mark
1096void DrawColorCheckMark(HDC hdc, int x, int y, int cx, int cy, HDC hdcCheckMask, int idxColor)
1097{
1098 const COLORREF colBlack = RGB(0, 0, 0);
1099 const COLORREF colWhite = RGB(255, 255, 255);
1100
1101 COLORREF colOldText = ::SetTextColor(hdc, colBlack);
1102 COLORREF colOldBack = ::SetBkColor(hdc, colWhite);
1103 int prevMode = SetBkMode(hdc, TRANSPARENT);
1104
1105 // memory DC for color bitmap
1106 MemoryHDC hdcMem(hdc);
1107 CompatibleBitmap hbmpMem(hdc, cx, cy);
1108 SelectInHDC selMem(hdcMem, hbmpMem);
1109
1110 RECT rect = { 0, 0, cx, cy };
1111 ::FillRect(hdcMem, &rect, ::GetSysColorBrush(idxColor));
1112
1113 const COLORREF colCheck = ::GetSysColor(idxColor);
1114 if ( colCheck == colWhite )
1115 {
1116 ::BitBlt(hdc, x, y, cx, cy, hdcCheckMask, 0, 0, MERGEPAINT);
1117 ::BitBlt(hdc, x, y, cx, cy, hdcMem, 0, 0, SRCAND);
1118 }
1119 else
1120 {
1121 if ( colCheck != colBlack )
1122 {
1123 const DWORD ROP_DSna = 0x00220326; // dest = (NOT src) AND dest
1124 ::BitBlt(hdcMem, 0, 0, cx, cy, hdcCheckMask, 0, 0, ROP_DSna);
1125 }
1126
1127 ::BitBlt(hdc, x, y, cx, cy, hdcCheckMask, 0, 0, SRCAND);
1128 ::BitBlt(hdc, x, y, cx, cy, hdcMem, 0, 0, SRCPAINT);
1129 }
1130
1131 ::SetBkMode(hdc, prevMode);
1132 ::SetBkColor(hdc, colOldBack);
1133 ::SetTextColor(hdc, colOldText);
1134}
1135
1136} // anonymous namespace
1137
b8190883 1138void wxMenuItem::DrawStdCheckMark(WXHDC hdc_, const RECT* rc, wxODStatus stat)
ee009313 1139{
b8190883
VZ
1140 HDC hdc = (HDC)hdc_;
1141
ee009313
VZ
1142#if wxUSE_UXTHEME
1143 wxUxThemeEngine* theme = MenuDrawData::GetUxThemeEngine();
1144 if ( theme )
1145 {
1146 wxUxThemeHandle hTheme(GetMenu()->GetWindow(), L"MENU");
1147
03cc2991
VZ
1148 const MenuDrawData* data = MenuDrawData::Get();
1149
1150 // rect for background must be without check margins
1151 RECT rcBg;
1152 SetRect(&rcBg,
1153 rc->left - data->CheckMargin.left,
1154 rc->top - data->CheckMargin.top,
1155 rc->right + data->CheckMargin.right,
1156 rc->bottom + data->CheckMargin.bottom);
1157
ee009313
VZ
1158 POPUPCHECKBACKGROUNDSTATES stateCheckBg = (stat & wxODDisabled)
1159 ? MCB_DISABLED
1160 : MCB_NORMAL;
1161
1162 theme->DrawThemeBackground(hTheme, hdc, MENU_POPUPCHECKBACKGROUND,
03cc2991 1163 stateCheckBg, &rcBg, NULL);
ee009313
VZ
1164
1165 POPUPCHECKSTATES stateCheck;
1166 if ( GetKind() == wxITEM_CHECK )
1167 {
1168 stateCheck = (stat & wxODDisabled) ? MC_CHECKMARKDISABLED
1169 : MC_CHECKMARKNORMAL;
1170 }
1171 else
1172 {
1173 stateCheck = (stat & wxODDisabled) ? MC_BULLETDISABLED
1174 : MC_BULLETNORMAL;
1175 }
1176
1177 theme->DrawThemeBackground(hTheme, hdc, MENU_POPUPCHECK,
1178 stateCheck, rc, NULL);
1179 }
1180 else
1181#endif // wxUSE_UXTHEME
1182 {
1183 int cx = rc->right - rc->left;
1184 int cy = rc->bottom - rc->top;
1185
1186 // first create mask of check mark
1187 MemoryHDC hdcMask(hdc);
1188 MonoBitmap hbmpMask(cx, cy);
1189 SelectInHDC selMask(hdcMask,hbmpMask);
1190
1191 // then draw a check mark into it
1192 UINT stateCheck = (GetKind() == wxITEM_CHECK) ? DFCS_MENUCHECK
1193 : DFCS_MENUBULLET;
1194 RECT rect = { 0, 0, cx, cy };
1195 ::DrawFrameControl(hdcMask, &rect, DFC_MENU, stateCheck);
1196
1197 // first draw shadow if disabled
1198 if ( (stat & wxODDisabled) && !(stat & wxODSelected) )
1199 {
1200 DrawColorCheckMark(hdc, rc->left + 1, rc->top + 1,
1201 cx, cy, hdcMask, COLOR_3DHILIGHT);
1202 }
1203
1204 // then draw a check mark
1205 int color = COLOR_MENUTEXT;
1206 if ( stat & wxODDisabled )
1207 color = COLOR_BTNSHADOW;
1208 else if ( stat & wxODSelected )
1209 color = COLOR_HIGHLIGHTTEXT;
1210
1211 DrawColorCheckMark(hdc, rc->left, rc->top, cx, cy, hdcMask, color);
1212 }
1213}
1214
98fbab9e
VZ
1215void wxMenuItem::GetFontToUse(wxFont& font) const
1216{
1217 font = GetFont();
1218 if ( !font.IsOk() )
aa4919ed 1219 font = MenuDrawData::Get()->Font;
98fbab9e
VZ
1220}
1221
aa4919ed
VZ
1222void wxMenuItem::GetColourToUse(wxODStatus stat, wxColour& colText, wxColour& colBack) const
1223{
1224#if wxUSE_UXTHEME
1225 wxUxThemeEngine* theme = MenuDrawData::GetUxThemeEngine();
1226 if ( theme )
1227 {
1228 wxUxThemeHandle hTheme(GetMenu()->GetWindow(), L"MENU");
1229
1230 if ( stat & wxODDisabled)
1231 {
1232 wxRGBToColour(colText, theme->GetThemeSysColor(hTheme, COLOR_GRAYTEXT));
1233 }
1234 else
1235 {
1236 colText = GetTextColour();
1237 if ( !colText.IsOk() )
1238 wxRGBToColour(colText, theme->GetThemeSysColor(hTheme, COLOR_MENUTEXT));
1239 }
1240
1241 if ( stat & wxODSelected )
1242 {
1243 wxRGBToColour(colBack, theme->GetThemeSysColor(hTheme, COLOR_HIGHLIGHT));
1244 }
1245 else
1246 {
1247 colBack = GetBackgroundColour();
1248 if ( !colBack.IsOk() )
1249 wxRGBToColour(colBack, theme->GetThemeSysColor(hTheme, COLOR_MENU));
1250 }
1251 }
1252 else
1253#endif // wxUSE_UXTHEME
1254 {
1255 wxOwnerDrawn::GetColourToUse(stat, colText, colBack);
1256 }
1257}
98fbab9e
VZ
1258#endif // wxUSE_OWNER_DRAWN
1259
974e8d94
VZ
1260// ----------------------------------------------------------------------------
1261// wxMenuItemBase
1262// ----------------------------------------------------------------------------
1263
1264wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
1265 int id,
1266 const wxString& name,
1267 const wxString& help,
d65c269b 1268 wxItemKind kind,
974e8d94
VZ
1269 wxMenu *subMenu)
1270{
d65c269b 1271 return new wxMenuItem(parentMenu, id, name, help, kind, subMenu);
974e8d94 1272}
1e6feb95
VZ
1273
1274#endif // wxUSE_MENUS