]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
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 | ||
a3b46648 UU |
12 | #ifdef __GNUG__ |
13 | #pragma implementation "menuitem.h" | |
14 | #endif | |
2bda0e17 KB |
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" | |
2432b92d JS |
25 | #include "wx/font.h" |
26 | #include "wx/bitmap.h" | |
27 | #include "wx/settings.h" | |
28 | #include "wx/font.h" | |
2bda0e17 KB |
29 | #endif |
30 | ||
31 | #include "wx/ownerdrw.h" | |
32 | #include "wx/menuitem.h" | |
33 | ||
34 | #include <windows.h> | |
35 | ||
36 | // ============================================================================ | |
37 | // implementation | |
38 | // ============================================================================ | |
39 | ||
40 | // ---------------------------------------------------------------------------- | |
41 | // dynamic classes implementation | |
42 | // ---------------------------------------------------------------------------- | |
43 | ||
44 | #if !defined(USE_SHARED_LIBRARY) || !USE_SHARED_LIBRARY | |
47d67540 | 45 | #if wxUSE_OWNER_DRAWN |
2bda0e17 KB |
46 | IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem, wxObject, wxOwnerDrawn) |
47 | #else //!USE_OWNER_DRAWN | |
48 | IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject) | |
49 | #endif //USE_OWNER_DRAWN | |
50 | ||
51 | #endif //USE_SHARED_LIBRARY | |
52 | ||
53 | // ---------------------------------------------------------------------------- | |
54 | // wxMenuItem | |
55 | // ---------------------------------------------------------------------------- | |
56 | ||
57 | // ctor & dtor | |
58 | // ----------- | |
59 | ||
60 | wxMenuItem::wxMenuItem(wxMenu *pParentMenu, int id, | |
3aadbb82 | 61 | const wxString& strName, const wxString& strHelp, |
2bda0e17 KB |
62 | bool bCheckable, |
63 | wxMenu *pSubMenu) : | |
47d67540 | 64 | #if wxUSE_OWNER_DRAWN |
2bda0e17 KB |
65 | wxOwnerDrawn(strName, bCheckable), |
66 | #else //no owner drawn support | |
67 | m_bCheckable(bCheckable), | |
68 | m_strName(strName), | |
69 | #endif //owner drawn | |
70 | m_strHelp(strHelp) | |
71 | { | |
72 | wxASSERT( pParentMenu != NULL ); | |
73 | ||
47d67540 | 74 | #if wxUSE_OWNER_DRAWN |
2bda0e17 KB |
75 | // set default menu colors |
76 | #define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c)) | |
77 | ||
78 | SetTextColour(SYS_COLOR(MENUTEXT)); | |
79 | SetBackgroundColour(SYS_COLOR(MENU)); | |
80 | ||
81 | // we don't want normal items be owner-drawn | |
82 | ResetOwnerDrawn(); | |
83 | ||
84 | #undef SYS_COLOR | |
85 | #endif | |
86 | ||
87 | m_pParentMenu = pParentMenu; | |
88 | m_pSubMenu = pSubMenu; | |
89 | m_idItem = id; | |
90 | m_bEnabled = TRUE; | |
91 | } | |
92 | ||
93 | wxMenuItem::~wxMenuItem() | |
94 | { | |
95 | } | |
96 | ||
97 | // misc | |
98 | // ---- | |
99 | ||
100 | // delete the sub menu | |
101 | void wxMenuItem::DeleteSubMenu() | |
102 | { | |
103 | wxASSERT( m_pSubMenu != NULL ); | |
104 | ||
105 | delete m_pSubMenu; | |
106 | m_pSubMenu = NULL; | |
107 | } | |
108 | ||
109 | // change item state | |
110 | // ----------------- | |
111 | ||
112 | void wxMenuItem::Enable(bool bDoEnable) | |
113 | { | |
114 | if ( m_bEnabled != bDoEnable ) { | |
115 | if ( m_pSubMenu == NULL ) { // normal menu item | |
116 | EnableMenuItem((HMENU)m_pParentMenu->GetHMenu(), m_idItem, | |
117 | MF_BYCOMMAND | (bDoEnable ? MF_ENABLED: MF_GRAYED)); | |
118 | } | |
119 | else // submenu | |
120 | { | |
121 | wxMenu *father = m_pSubMenu->m_topLevelMenu ; | |
122 | wxNode *node = father->m_menuItems.First() ; | |
123 | int i = 0 ; | |
124 | while (node) { | |
125 | wxMenuItem *matched = (wxMenuItem*)node->Data(); | |
126 | if ( matched == this) | |
127 | break; | |
128 | i++; | |
129 | node = node->Next(); | |
130 | } | |
131 | EnableMenuItem((HMENU)father->m_savehMenu, i, | |
132 | MF_BYPOSITION | (bDoEnable ? MF_ENABLED: MF_GRAYED)); | |
133 | } | |
134 | ||
135 | m_bEnabled = bDoEnable; | |
136 | } | |
137 | } | |
138 | ||
139 | void wxMenuItem::Check(bool bDoCheck) | |
140 | { | |
1311c7a9 | 141 | wxCHECK_RET( IsCheckable(), "only checkable items may be checked" ); |
2bda0e17 KB |
142 | |
143 | if ( m_bChecked != bDoCheck ) { | |
144 | CheckMenuItem((HMENU)m_pParentMenu->GetHMenu(), m_idItem, | |
145 | MF_BYCOMMAND | (bDoCheck ? MF_CHECKED : MF_UNCHECKED)); | |
146 | ||
147 | m_bChecked = bDoCheck; | |
148 | } | |
149 | } |