]> git.saurik.com Git - wxWidgets.git/blob - src/msw/menuitem.cpp
i18n fixes
[wxWidgets.git] / src / msw / menuitem.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: menuitem.cpp
3 // Purpose: wxMenuItem implementation
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 11.11.97
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "menuitem.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/menu.h"
25 #include "wx/font.h"
26 #include "wx/bitmap.h"
27 #include "wx/settings.h"
28 #include "wx/font.h"
29 #endif
30
31 #include "wx/ownerdrw.h"
32 #include "wx/menuitem.h"
33
34 #include <windows.h>
35
36 #ifdef GetClassInfo
37 #undef GetClassInfo
38 #endif
39
40 #ifdef GetClassName
41 #undef GetClassName
42 #endif
43
44 // ============================================================================
45 // implementation
46 // ============================================================================
47
48 // ----------------------------------------------------------------------------
49 // dynamic classes implementation
50 // ----------------------------------------------------------------------------
51
52 #if !defined(USE_SHARED_LIBRARY) || !USE_SHARED_LIBRARY
53 #if wxUSE_OWNER_DRAWN
54 IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem, wxObject, wxOwnerDrawn)
55 #else //!USE_OWNER_DRAWN
56 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
57 #endif //USE_OWNER_DRAWN
58
59 #endif //USE_SHARED_LIBRARY
60
61 // ----------------------------------------------------------------------------
62 // wxMenuItem
63 // ----------------------------------------------------------------------------
64
65 // ctor & dtor
66 // -----------
67
68 wxMenuItem::wxMenuItem(wxMenu *pParentMenu, int id,
69 const wxString& strName, const wxString& strHelp,
70 bool bCheckable,
71 wxMenu *pSubMenu) :
72 #if wxUSE_OWNER_DRAWN
73 wxOwnerDrawn(strName, bCheckable),
74 #else //no owner drawn support
75 m_bCheckable(bCheckable),
76 m_strName(strName),
77 #endif //owner drawn
78 m_strHelp(strHelp)
79 {
80 wxASSERT( pParentMenu != NULL );
81
82 #if wxUSE_OWNER_DRAWN
83 // set default menu colors
84 #define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c))
85
86 SetTextColour(SYS_COLOR(MENUTEXT));
87 SetBackgroundColour(SYS_COLOR(MENU));
88
89 // we don't want normal items be owner-drawn
90 ResetOwnerDrawn();
91
92 #undef SYS_COLOR
93 #endif
94
95 m_pParentMenu = pParentMenu;
96 m_pSubMenu = pSubMenu;
97 m_idItem = id;
98 m_bEnabled = TRUE;
99 }
100
101 wxMenuItem::~wxMenuItem()
102 {
103 }
104
105 // misc
106 // ----
107
108 // delete the sub menu
109 void wxMenuItem::DeleteSubMenu()
110 {
111 wxASSERT( m_pSubMenu != NULL );
112
113 delete m_pSubMenu;
114 m_pSubMenu = NULL;
115 }
116
117 // change item state
118 // -----------------
119
120 void wxMenuItem::Enable(bool bDoEnable)
121 {
122 if ( m_bEnabled != bDoEnable ) {
123 if ( m_pSubMenu == NULL ) { // normal menu item
124 EnableMenuItem((HMENU)m_pParentMenu->GetHMenu(), m_idItem,
125 MF_BYCOMMAND | (bDoEnable ? MF_ENABLED: MF_GRAYED));
126 }
127 else // submenu
128 {
129 wxMenu *father = m_pSubMenu->m_topLevelMenu ;
130 wxNode *node = father->m_menuItems.First() ;
131 int i = 0 ;
132 while (node) {
133 wxMenuItem *matched = (wxMenuItem*)node->Data();
134 if ( matched == this)
135 break;
136 i++;
137 node = node->Next();
138 }
139 EnableMenuItem((HMENU)father->m_savehMenu, i,
140 MF_BYPOSITION | (bDoEnable ? MF_ENABLED: MF_GRAYED));
141 }
142
143 m_bEnabled = bDoEnable;
144 }
145 }
146
147 void wxMenuItem::Check(bool bDoCheck)
148 {
149 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
150
151 if ( m_bChecked != bDoCheck ) {
152 CheckMenuItem((HMENU)m_pParentMenu->GetHMenu(), m_idItem,
153 MF_BYCOMMAND | (bDoCheck ? MF_CHECKED : MF_UNCHECKED));
154
155 m_bChecked = bDoCheck;
156 }
157 }