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