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