]> git.saurik.com Git - wxWidgets.git/blob - src/msw/menu.cpp
don't use built-in support for menu bitmaps if they are too big, they don't come...
[wxWidgets.git] / src / msw / menu.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/menu.cpp
3 // Purpose: wxMenu, wxMenuBar, wxMenuItem
4 // Author: Julian Smart
5 // Modified by: Vadim Zeitlin
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_MENUS
28
29 #include "wx/menu.h"
30
31 #ifndef WX_PRECOMP
32 #include "wx/frame.h"
33 #include "wx/utils.h"
34 #include "wx/intl.h"
35 #include "wx/log.h"
36 #endif
37
38 #if wxUSE_OWNER_DRAWN
39 #include "wx/ownerdrw.h"
40 #endif
41
42 #include "wx/ptr_scpd.h"
43
44 #include "wx/msw/private.h"
45 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
46
47 #ifdef __WXWINCE__
48 #include <windows.h>
49 #include <windowsx.h>
50 #include <tchar.h>
51 #include <ole2.h>
52 #include <shellapi.h>
53 #if (_WIN32_WCE < 400) && !defined(__HANDHELDPC__)
54 #include <aygshell.h>
55 #endif
56
57 #include "wx/msw/wince/missing.h"
58
59 #endif
60
61 // other standard headers
62 #include <string.h>
63
64 //VC6 needs these defining, though they are in winuser.h
65 #ifndef MIIM_BITMAP
66 #define MIIM_STRING 0x00000040
67 #define MIIM_BITMAP 0x00000080
68 #define MIIM_FTYPE 0x00000100
69 #define HBMMENU_CALLBACK ((HBITMAP) -1)
70 typedef struct tagMENUINFO
71 {
72 DWORD cbSize;
73 DWORD fMask;
74 DWORD dwStyle;
75 UINT cyMax;
76 HBRUSH hbrBack;
77 DWORD dwContextHelpID;
78 DWORD dwMenuData;
79 } MENUINFO, FAR *LPMENUINFO;
80 #endif
81
82 #if wxUSE_OWNER_DRAWN
83 #include "wx/dynlib.h"
84 #endif
85
86 #ifndef MNS_CHECKORBMP
87 #define MNS_CHECKORBMP 0x04000000
88 #endif
89 #ifndef MIM_STYLE
90 #define MIM_STYLE 0x00000010
91 #endif
92
93 // ----------------------------------------------------------------------------
94 // global variables
95 // ----------------------------------------------------------------------------
96
97 // ----------------------------------------------------------------------------
98 // constants
99 // ----------------------------------------------------------------------------
100
101 // the (popup) menu title has this special id
102 static const UINT idMenuTitle = (UINT)-3;
103
104 // ----------------------------------------------------------------------------
105 // private functions
106 // ----------------------------------------------------------------------------
107
108 namespace
109 {
110
111 // make the given menu item default
112 void SetDefaultMenuItem(HMENU WXUNUSED_IN_WINCE(hmenu),
113 UINT WXUNUSED_IN_WINCE(id))
114 {
115 #ifndef __WXWINCE__
116 MENUITEMINFO mii;
117 wxZeroMemory(mii);
118 mii.cbSize = sizeof(MENUITEMINFO);
119 mii.fMask = MIIM_STATE;
120 mii.fState = MFS_DEFAULT;
121
122 if ( !::SetMenuItemInfo(hmenu, id, FALSE, &mii) )
123 {
124 wxLogLastError(wxT("SetMenuItemInfo"));
125 }
126 #endif
127 }
128
129 #ifdef __WXWINCE__
130 UINT GetMenuState(HMENU hMenu, UINT id, UINT flags)
131 {
132 MENUITEMINFO info;
133 wxZeroMemory(info);
134 info.cbSize = sizeof(info);
135 info.fMask = MIIM_STATE;
136 // MF_BYCOMMAND is zero so test MF_BYPOSITION
137 if ( !::GetMenuItemInfo(hMenu, id, flags & MF_BYPOSITION ? TRUE : FALSE , & info) )
138 wxLogLastError(wxT("GetMenuItemInfo"));
139 return info.fState;
140 }
141 #endif // __WXWINCE__
142
143 bool IsLessThanStdSize(const wxBitmap& bmp)
144 {
145 // FIXME: these +4 are chosen so that 16*16 bitmaps pass this test with
146 // default SM_CXMENUCHECK value but I have no idea what do we really
147 // need to use here
148 return bmp.GetWidth() < ::GetSystemMetrics(SM_CXMENUCHECK) + 4 &&
149 bmp.GetHeight() < ::GetSystemMetrics(SM_CYMENUCHECK) + 4;
150 }
151
152 } // anonymous namespace
153
154 // ============================================================================
155 // implementation
156 // ============================================================================
157
158 #include "wx/listimpl.cpp"
159
160 WX_DEFINE_LIST( wxMenuInfoList )
161
162 #if wxUSE_EXTENDED_RTTI
163
164 WX_DEFINE_FLAGS( wxMenuStyle )
165
166 wxBEGIN_FLAGS( wxMenuStyle )
167 wxFLAGS_MEMBER(wxMENU_TEAROFF)
168 wxEND_FLAGS( wxMenuStyle )
169
170 IMPLEMENT_DYNAMIC_CLASS_XTI(wxMenu, wxEvtHandler,"wx/menu.h")
171
172 wxCOLLECTION_TYPE_INFO( wxMenuItem * , wxMenuItemList ) ;
173
174 template<> void wxCollectionToVariantArray( wxMenuItemList const &theList, wxxVariantArray &value)
175 {
176 wxListCollectionToVariantArray<wxMenuItemList::compatibility_iterator>( theList , value ) ;
177 }
178
179 wxBEGIN_PROPERTIES_TABLE(wxMenu)
180 wxEVENT_PROPERTY( Select , wxEVT_COMMAND_MENU_SELECTED , wxCommandEvent)
181 wxPROPERTY( Title, wxString , SetTitle, GetTitle, wxString(), 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
182 wxREADONLY_PROPERTY_FLAGS( MenuStyle , wxMenuStyle , long , GetStyle , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
183 wxPROPERTY_COLLECTION( MenuItems , wxMenuItemList , wxMenuItem* , Append , GetMenuItems , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
184 wxEND_PROPERTIES_TABLE()
185
186 wxBEGIN_HANDLERS_TABLE(wxMenu)
187 wxEND_HANDLERS_TABLE()
188
189 wxDIRECT_CONSTRUCTOR_2( wxMenu , wxString , Title , long , MenuStyle )
190
191 WX_DEFINE_FLAGS( wxMenuBarStyle )
192
193 wxBEGIN_FLAGS( wxMenuBarStyle )
194 wxFLAGS_MEMBER(wxMB_DOCKABLE)
195 wxEND_FLAGS( wxMenuBarStyle )
196
197 // the negative id would lead the window (its superclass !) to vetoe streaming out otherwise
198 bool wxMenuBarStreamingCallback( const wxObject *WXUNUSED(object), wxWriter * , wxPersister * , wxxVariantArray & )
199 {
200 return true ;
201 }
202
203 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxMenuBar, wxWindow ,"wx/menu.h",wxMenuBarStreamingCallback)
204
205 IMPLEMENT_DYNAMIC_CLASS_XTI(wxMenuInfo, wxObject , "wx/menu.h" )
206
207 wxBEGIN_PROPERTIES_TABLE(wxMenuInfo)
208 wxREADONLY_PROPERTY( Menu , wxMenu* , GetMenu , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
209 wxREADONLY_PROPERTY( Title , wxString , GetTitle , wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
210 wxEND_PROPERTIES_TABLE()
211
212 wxBEGIN_HANDLERS_TABLE(wxMenuInfo)
213 wxEND_HANDLERS_TABLE()
214
215 wxCONSTRUCTOR_2( wxMenuInfo , wxMenu* , Menu , wxString , Title )
216
217 wxCOLLECTION_TYPE_INFO( wxMenuInfo * , wxMenuInfoList ) ;
218
219 template<> void wxCollectionToVariantArray( wxMenuInfoList const &theList, wxxVariantArray &value)
220 {
221 wxListCollectionToVariantArray<wxMenuInfoList::compatibility_iterator>( theList , value ) ;
222 }
223
224 wxBEGIN_PROPERTIES_TABLE(wxMenuBar)
225 wxPROPERTY_COLLECTION( MenuInfos , wxMenuInfoList , wxMenuInfo* , Append , GetMenuInfos , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
226 wxEND_PROPERTIES_TABLE()
227
228 wxBEGIN_HANDLERS_TABLE(wxMenuBar)
229 wxEND_HANDLERS_TABLE()
230
231 wxCONSTRUCTOR_DUMMY( wxMenuBar )
232
233 #else
234 IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler)
235 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxWindow)
236 IMPLEMENT_DYNAMIC_CLASS(wxMenuInfo, wxObject)
237 #endif
238
239 const wxMenuInfoList& wxMenuBar::GetMenuInfos() const
240 {
241 wxMenuInfoList* list = const_cast< wxMenuInfoList* >( &m_menuInfos ) ;
242 WX_CLEAR_LIST( wxMenuInfoList , *list ) ;
243 for( size_t i = 0 ; i < GetMenuCount() ; ++i )
244 {
245 wxMenuInfo* info = new wxMenuInfo() ;
246 info->Create( const_cast<wxMenuBar*>(this)->GetMenu(i) , GetMenuLabel(i) ) ;
247 list->Append( info ) ;
248 }
249 return m_menuInfos ;
250 }
251
252 // ---------------------------------------------------------------------------
253 // wxMenu construction, adding and removing menu items
254 // ---------------------------------------------------------------------------
255
256 // Construct a menu with optional title (then use append)
257 void wxMenu::Init()
258 {
259 m_doBreak = false;
260 m_startRadioGroup = -1;
261
262 // create the menu
263 m_hMenu = (WXHMENU)CreatePopupMenu();
264 if ( !m_hMenu )
265 {
266 wxLogLastError(wxT("CreatePopupMenu"));
267 }
268
269 // if we have a title, insert it in the beginning of the menu
270 if ( !m_title.empty() )
271 {
272 Append(idMenuTitle, m_title);
273 AppendSeparator();
274 }
275 }
276
277 // The wxWindow destructor will take care of deleting the submenus.
278 wxMenu::~wxMenu()
279 {
280 // we should free Windows resources only if Windows doesn't do it for us
281 // which happens if we're attached to a menubar or a submenu of another
282 // menu
283 if ( !IsAttached() && !GetParent() )
284 {
285 if ( !::DestroyMenu(GetHmenu()) )
286 {
287 wxLogLastError(wxT("DestroyMenu"));
288 }
289 }
290
291 #if wxUSE_ACCEL
292 // delete accels
293 WX_CLEAR_ARRAY(m_accels);
294 #endif // wxUSE_ACCEL
295 }
296
297 void wxMenu::Break()
298 {
299 // this will take effect during the next call to Append()
300 m_doBreak = true;
301 }
302
303 void wxMenu::Attach(wxMenuBarBase *menubar)
304 {
305 wxMenuBase::Attach(menubar);
306
307 EndRadioGroup();
308 }
309
310 #if wxUSE_ACCEL
311
312 int wxMenu::FindAccel(int id) const
313 {
314 size_t n, count = m_accels.GetCount();
315 for ( n = 0; n < count; n++ )
316 {
317 if ( m_accels[n]->m_command == id )
318 return n;
319 }
320
321 return wxNOT_FOUND;
322 }
323
324 void wxMenu::UpdateAccel(wxMenuItem *item)
325 {
326 if ( item->IsSubMenu() )
327 {
328 wxMenu *submenu = item->GetSubMenu();
329 wxMenuItemList::compatibility_iterator node = submenu->GetMenuItems().GetFirst();
330 while ( node )
331 {
332 UpdateAccel(node->GetData());
333
334 node = node->GetNext();
335 }
336 }
337 else if ( !item->IsSeparator() )
338 {
339 // recurse upwards: we should only modify m_accels of the top level
340 // menus, not of the submenus as wxMenuBar doesn't look at them
341 // (alternative and arguable cleaner solution would be to recurse
342 // downwards in GetAccelCount() and CopyAccels())
343 if ( GetParent() )
344 {
345 GetParent()->UpdateAccel(item);
346 return;
347 }
348
349 // find the (new) accel for this item
350 wxAcceleratorEntry *accel = wxAcceleratorEntry::Create(item->GetItemLabel());
351 if ( accel )
352 accel->m_command = item->GetId();
353
354 // find the old one
355 int n = FindAccel(item->GetId());
356 if ( n == wxNOT_FOUND )
357 {
358 // no old, add new if any
359 if ( accel )
360 m_accels.Add(accel);
361 else
362 return; // skipping RebuildAccelTable() below
363 }
364 else
365 {
366 // replace old with new or just remove the old one if no new
367 delete m_accels[n];
368 if ( accel )
369 m_accels[n] = accel;
370 else
371 m_accels.RemoveAt(n);
372 }
373
374 if ( IsAttached() )
375 {
376 GetMenuBar()->RebuildAccelTable();
377 }
378 }
379 //else: it is a separator, they can't have accels, nothing to do
380 }
381
382 #endif // wxUSE_ACCEL
383
384 // append a new item or submenu to the menu
385 bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos)
386 {
387 #if wxUSE_ACCEL
388 UpdateAccel(pItem);
389 #endif // wxUSE_ACCEL
390
391 // we should support disabling the item even prior to adding it to the menu
392 UINT flags = pItem->IsEnabled() ? MF_ENABLED : MF_GRAYED;
393
394 // if "Break" has just been called, insert a menu break before this item
395 // (and don't forget to reset the flag)
396 if ( m_doBreak ) {
397 flags |= MF_MENUBREAK;
398 m_doBreak = false;
399 }
400
401 if ( pItem->IsSeparator() ) {
402 flags |= MF_SEPARATOR;
403 }
404
405 // id is the numeric id for normal menu items and HMENU for submenus as
406 // required by ::AppendMenu() API
407 UINT_PTR id;
408 wxMenu *submenu = pItem->GetSubMenu();
409 if ( submenu != NULL ) {
410 wxASSERT_MSG( submenu->GetHMenu(), wxT("invalid submenu") );
411
412 submenu->SetParent(this);
413
414 id = (UINT_PTR)submenu->GetHMenu();
415
416 flags |= MF_POPUP;
417 }
418 else {
419 id = pItem->GetMSWId();
420 }
421
422
423 // prepare to insert the item in the menu
424 wxString itemText = pItem->GetItemLabel();
425 LPCTSTR pData = NULL;
426 if ( pos == (size_t)-1 )
427 {
428 // append at the end (note that the item is already appended to
429 // internal data structures)
430 pos = GetMenuItemCount() - 1;
431 }
432
433 // adjust position to account for the title, if any
434 if ( !m_title.empty() )
435 pos += 2; // for the title itself and its separator
436
437 BOOL ok = false;
438
439 #if wxUSE_OWNER_DRAWN
440 // Currently, mixing owner-drawn and non-owner-drawn items results in
441 // inconsistent margins, so we force this to be owner-drawn if any other
442 // items already are. Later we might want to use a boolean in the wxMenu
443 // to avoid search. Also we might make this fix unnecessary by getting the correct
444 // margin using NONCLIENTMETRICS.
445 if ( !pItem->IsOwnerDrawn() && !pItem->IsSeparator() )
446 {
447 // Check if any other items are ownerdrawn, and make ownerdrawn if so
448 wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
449 while (node)
450 {
451 if (node->GetData()->IsOwnerDrawn())
452 {
453 pItem->SetOwnerDrawn(true);
454 break;
455 }
456 node = node->GetNext();
457 }
458 }
459 #endif
460
461 // check if we have something more than a simple text item
462 #if wxUSE_OWNER_DRAWN
463 if ( pItem->IsOwnerDrawn() )
464 {
465 #ifndef __DMC__
466 // if the item is owner-drawn just because of the [checked] bitmap and
467 // the bitmap uses standard menu bitmap size we can avoid making it
468 // owner-drawn and use built-in support for menu bitmaps instead
469 bool mustUseOwnerDrawn = pItem->GetTextColour().Ok() ||
470 pItem->GetBackgroundColour().Ok() ||
471 pItem->GetFont().Ok();
472 if ( !mustUseOwnerDrawn )
473 {
474 const wxBitmap& bmpUnchecked = pItem->GetBitmap(false),
475 bmpChecked = pItem->GetBitmap(true);
476 if ( (bmpUnchecked.Ok() && !IsLessThanStdSize(bmpUnchecked)) ||
477 (bmpChecked.Ok() && !IsLessThanStdSize(bmpChecked)) )
478 {
479 mustUseOwnerDrawn = true;
480 }
481 }
482
483 // MIIM_BITMAP only works under WinME/2000+
484 if ( !mustUseOwnerDrawn && wxGetWinVersion() >= wxWinVersion_98 )
485 {
486 // use InsertMenuItem() as it's guaranteed to look correct while
487 // our owner-drawn code is not
488 WinStruct<MENUITEMINFO> mii;
489 mii.fMask = MIIM_STRING | MIIM_DATA | MIIM_BITMAP;
490 if ( pItem->IsCheckable() )
491 {
492 // need to set checked/unchecked bitmaps as otherwise our
493 // MSWOnDrawItem() item is not called
494 mii.fMask |= MIIM_CHECKMARKS;
495 }
496
497 mii.cch = itemText.length();
498 mii.dwTypeData = const_cast<wxChar *>(itemText.wx_str());
499
500 if (flags & MF_POPUP)
501 {
502 mii.fMask |= MIIM_SUBMENU;
503 mii.hSubMenu = (HMENU)pItem->GetSubMenu()->GetHMenu();
504 }
505 else
506 {
507 mii.fMask |= MIIM_ID;
508 mii.wID = id;
509 }
510
511 // we can't pass HBITMAP directly as hbmpItem for 2 reasons:
512 // 1. we can't draw it with transparency then (this is not
513 // very important now but would be with themed menu bg)
514 // 2. worse, Windows inverts the bitmap for the selected
515 // item and this looks downright ugly
516 //
517 // so instead draw it ourselves in MSWOnDrawItem()
518 mii.dwItemData = reinterpret_cast<ULONG_PTR>(pItem);
519 if ( pItem->IsCheckable() )
520 {
521 mii.hbmpChecked =
522 mii.hbmpUnchecked = HBMMENU_CALLBACK;
523 }
524 mii.hbmpItem = HBMMENU_CALLBACK;
525
526 ok = ::InsertMenuItem(GetHmenu(), pos, TRUE /* by pos */, &mii);
527 if ( !ok )
528 {
529 wxLogLastError(wxT("InsertMenuItem()"));
530 }
531 else // InsertMenuItem() ok
532 {
533 // we need to remove the extra indent which is reserved for
534 // the checkboxes by default as it looks ugly unless check
535 // boxes are used together with bitmaps and this is not the
536 // case in wx API
537 WinStruct<MENUINFO> mi;
538
539 // don't call SetMenuInfo() directly, this would prevent
540 // the app from starting up under Windows 95/NT 4
541 typedef BOOL (WINAPI *SetMenuInfo_t)(HMENU, MENUINFO *);
542
543 wxDynamicLibrary dllUser(_T("user32"));
544 wxDYNLIB_FUNCTION(SetMenuInfo_t, SetMenuInfo, dllUser);
545 if ( pfnSetMenuInfo )
546 {
547 mi.fMask = MIM_STYLE;
548 mi.dwStyle = MNS_CHECKORBMP;
549 if ( !(*pfnSetMenuInfo)(GetHmenu(), &mi) )
550 wxLogLastError(_T("SetMenuInfo(MNS_NOCHECK)"));
551 }
552
553 // tell the item that it's not really owner-drawn but only
554 // needs to draw its bitmap, the rest is done by Windows
555 pItem->ResetOwnerDrawn();
556 }
557 }
558 #endif // __DMC__
559
560 if ( !ok )
561 {
562 // item draws itself, pass pointer to it in data parameter
563 flags |= MF_OWNERDRAW;
564 pData = (LPCTSTR)pItem;
565 }
566 }
567 else
568 #endif // wxUSE_OWNER_DRAWN
569 {
570 // item is just a normal string (passed in data parameter)
571 flags |= MF_STRING;
572
573 #ifdef __WXWINCE__
574 itemText = wxMenuItem::GetLabelText(itemText);
575 #endif
576
577 pData = (wxChar*)itemText.wx_str();
578 }
579
580 // item might have already been inserted by InsertMenuItem() above
581 if ( !ok )
582 {
583 if ( !::InsertMenu(GetHmenu(), pos, flags | MF_BYPOSITION, id, pData) )
584 {
585 wxLogLastError(wxT("InsertMenu[Item]()"));
586
587 return false;
588 }
589 }
590
591
592 // if we just appended the title, highlight it
593 if ( id == idMenuTitle )
594 {
595 // visually select the menu title
596 SetDefaultMenuItem(GetHmenu(), id);
597 }
598
599 // if we're already attached to the menubar, we must update it
600 if ( IsAttached() && GetMenuBar()->IsAttached() )
601 {
602 GetMenuBar()->Refresh();
603 }
604
605 return true;
606 }
607
608 void wxMenu::EndRadioGroup()
609 {
610 // we're not inside a radio group any longer
611 m_startRadioGroup = -1;
612 }
613
614 wxMenuItem* wxMenu::DoAppend(wxMenuItem *item)
615 {
616 wxCHECK_MSG( item, NULL, _T("NULL item in wxMenu::DoAppend") );
617
618 bool check = false;
619
620 if ( item->GetKind() == wxITEM_RADIO )
621 {
622 int count = GetMenuItemCount();
623
624 if ( m_startRadioGroup == -1 )
625 {
626 // start a new radio group
627 m_startRadioGroup = count;
628
629 // for now it has just one element
630 item->SetAsRadioGroupStart();
631 item->SetRadioGroupEnd(m_startRadioGroup);
632
633 // ensure that we have a checked item in the radio group
634 check = true;
635 }
636 else // extend the current radio group
637 {
638 // we need to update its end item
639 item->SetRadioGroupStart(m_startRadioGroup);
640 wxMenuItemList::compatibility_iterator node = GetMenuItems().Item(m_startRadioGroup);
641
642 if ( node )
643 {
644 node->GetData()->SetRadioGroupEnd(count);
645 }
646 else
647 {
648 wxFAIL_MSG( _T("where is the radio group start item?") );
649 }
650 }
651 }
652 else // not a radio item
653 {
654 EndRadioGroup();
655 }
656
657 if ( !wxMenuBase::DoAppend(item) || !DoInsertOrAppend(item) )
658 {
659 return NULL;
660 }
661
662 if ( check )
663 {
664 // check the item initially
665 item->Check(true);
666 }
667
668 return item;
669 }
670
671 wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item)
672 {
673 if (wxMenuBase::DoInsert(pos, item) && DoInsertOrAppend(item, pos))
674 return item;
675 else
676 return NULL;
677 }
678
679 wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
680 {
681 // we need to find the item's position in the child list
682 size_t pos;
683 wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
684 for ( pos = 0; node; pos++ )
685 {
686 if ( node->GetData() == item )
687 break;
688
689 node = node->GetNext();
690 }
691
692 // DoRemove() (unlike Remove) can only be called for an existing item!
693 wxCHECK_MSG( node, NULL, wxT("bug in wxMenu::Remove logic") );
694
695 #if wxUSE_ACCEL
696 // remove the corresponding accel from the accel table
697 int n = FindAccel(item->GetId());
698 if ( n != wxNOT_FOUND )
699 {
700 delete m_accels[n];
701
702 m_accels.RemoveAt(n);
703 }
704 //else: this item doesn't have an accel, nothing to do
705 #endif // wxUSE_ACCEL
706
707 // remove the item from the menu
708 if ( !::RemoveMenu(GetHmenu(), (UINT)pos, MF_BYPOSITION) )
709 {
710 wxLogLastError(wxT("RemoveMenu"));
711 }
712
713 if ( IsAttached() && GetMenuBar()->IsAttached() )
714 {
715 // otherwise, the change won't be visible
716 GetMenuBar()->Refresh();
717 }
718
719 // and from internal data structures
720 return wxMenuBase::DoRemove(item);
721 }
722
723 // ---------------------------------------------------------------------------
724 // accelerator helpers
725 // ---------------------------------------------------------------------------
726
727 #if wxUSE_ACCEL
728
729 // create the wxAcceleratorEntries for our accels and put them into the provided
730 // array - return the number of accels we have
731 size_t wxMenu::CopyAccels(wxAcceleratorEntry *accels) const
732 {
733 size_t count = GetAccelCount();
734 for ( size_t n = 0; n < count; n++ )
735 {
736 *accels++ = *m_accels[n];
737 }
738
739 return count;
740 }
741
742 wxAcceleratorTable *wxMenu::CreateAccelTable() const
743 {
744 const size_t count = m_accels.size();
745 wxScopedArray<wxAcceleratorEntry> accels(new wxAcceleratorEntry[count]);
746 CopyAccels(accels.get());
747
748 return new wxAcceleratorTable(count, accels.get());
749 }
750
751 #endif // wxUSE_ACCEL
752
753 // ---------------------------------------------------------------------------
754 // set wxMenu title
755 // ---------------------------------------------------------------------------
756
757 void wxMenu::SetTitle(const wxString& label)
758 {
759 bool hasNoTitle = m_title.empty();
760 m_title = label;
761
762 HMENU hMenu = GetHmenu();
763
764 if ( hasNoTitle )
765 {
766 if ( !label.empty() )
767 {
768 if ( !::InsertMenu(hMenu, 0u, MF_BYPOSITION | MF_STRING,
769 idMenuTitle, m_title.wx_str()) ||
770 !::InsertMenu(hMenu, 1u, MF_BYPOSITION, (unsigned)-1, NULL) )
771 {
772 wxLogLastError(wxT("InsertMenu"));
773 }
774 }
775 }
776 else
777 {
778 if ( label.empty() )
779 {
780 // remove the title and the separator after it
781 if ( !RemoveMenu(hMenu, 0, MF_BYPOSITION) ||
782 !RemoveMenu(hMenu, 0, MF_BYPOSITION) )
783 {
784 wxLogLastError(wxT("RemoveMenu"));
785 }
786 }
787 else
788 {
789 // modify the title
790 #ifdef __WXWINCE__
791 MENUITEMINFO info;
792 wxZeroMemory(info);
793 info.cbSize = sizeof(info);
794 info.fMask = MIIM_TYPE;
795 info.fType = MFT_STRING;
796 info.cch = m_title.length();
797 info.dwTypeData = const_cast<wxChar *>(m_title.wx_str());
798 if ( !SetMenuItemInfo(hMenu, 0, TRUE, & info) )
799 {
800 wxLogLastError(wxT("SetMenuItemInfo"));
801 }
802 #else
803 if ( !ModifyMenu(hMenu, 0u,
804 MF_BYPOSITION | MF_STRING,
805 idMenuTitle, m_title.wx_str()) )
806 {
807 wxLogLastError(wxT("ModifyMenu"));
808 }
809 #endif
810 }
811 }
812
813 #ifdef __WIN32__
814 // put the title string in bold face
815 if ( !m_title.empty() )
816 {
817 SetDefaultMenuItem(GetHmenu(), idMenuTitle);
818 }
819 #endif // Win32
820 }
821
822 // ---------------------------------------------------------------------------
823 // event processing
824 // ---------------------------------------------------------------------------
825
826 bool wxMenu::MSWCommand(WXUINT WXUNUSED(param), WXWORD id_)
827 {
828 const int id = (signed short)id_;
829
830 // ignore commands from the menu title
831 if ( id != (int)idMenuTitle )
832 {
833 // update the check item when it's clicked
834 wxMenuItem * const item = FindItem(id);
835 if ( item && item->IsCheckable() )
836 item->Toggle();
837
838 // get the status of the menu item: note that it has been just changed
839 // by Toggle() above so here we already get the new state of the item
840 UINT menuState = ::GetMenuState(GetHmenu(), id, MF_BYCOMMAND);
841 SendEvent(id, menuState & MF_CHECKED);
842 }
843
844 return true;
845 }
846
847 // ---------------------------------------------------------------------------
848 // other
849 // ---------------------------------------------------------------------------
850
851 wxWindow *wxMenu::GetWindow() const
852 {
853 if ( m_invokingWindow != NULL )
854 return m_invokingWindow;
855 else if ( GetMenuBar() != NULL)
856 return GetMenuBar()->GetFrame();
857
858 return NULL;
859 }
860
861 // ---------------------------------------------------------------------------
862 // Menu Bar
863 // ---------------------------------------------------------------------------
864
865 void wxMenuBar::Init()
866 {
867 m_eventHandler = this;
868 m_hMenu = 0;
869 #if wxUSE_TOOLBAR && defined(__WXWINCE__)
870 m_toolBar = NULL;
871 #endif
872 // Not using a combined wxToolBar/wxMenuBar? then use
873 // a commandbar in WinCE .NET just to implement the
874 // menubar.
875 #if defined(WINCE_WITH_COMMANDBAR)
876 m_commandBar = NULL;
877 m_adornmentsAdded = false;
878 #endif
879 }
880
881 wxMenuBar::wxMenuBar()
882 {
883 Init();
884 }
885
886 wxMenuBar::wxMenuBar( long WXUNUSED(style) )
887 {
888 Init();
889 }
890
891 wxMenuBar::wxMenuBar(size_t count, wxMenu *menus[], const wxString titles[], long WXUNUSED(style))
892 {
893 Init();
894
895 m_titles.Alloc(count);
896
897 for ( size_t i = 0; i < count; i++ )
898 {
899 m_menus.Append(menus[i]);
900 m_titles.Add(titles[i]);
901
902 menus[i]->Attach(this);
903 }
904 }
905
906 wxMenuBar::~wxMenuBar()
907 {
908 // In Windows CE (not .NET), the menubar is always associated
909 // with a toolbar, which destroys the menu implicitly.
910 #if defined(WINCE_WITHOUT_COMMANDBAR) && defined(__POCKETPC__)
911 if (GetToolBar())
912 {
913 wxToolMenuBar* toolMenuBar = wxDynamicCast(GetToolBar(), wxToolMenuBar);
914 if (toolMenuBar)
915 toolMenuBar->SetMenuBar(NULL);
916 }
917 #else
918 // we should free Windows resources only if Windows doesn't do it for us
919 // which happens if we're attached to a frame
920 if (m_hMenu && !IsAttached())
921 {
922 #if defined(WINCE_WITH_COMMANDBAR)
923 ::DestroyWindow((HWND) m_commandBar);
924 m_commandBar = (WXHWND) NULL;
925 #else
926 ::DestroyMenu((HMENU)m_hMenu);
927 #endif
928 m_hMenu = (WXHMENU)NULL;
929 }
930 #endif
931 }
932
933 // ---------------------------------------------------------------------------
934 // wxMenuBar helpers
935 // ---------------------------------------------------------------------------
936
937 void wxMenuBar::Refresh()
938 {
939 if ( IsFrozen() )
940 return;
941
942 wxCHECK_RET( IsAttached(), wxT("can't refresh unattached menubar") );
943
944 #if defined(WINCE_WITHOUT_COMMANDBAR)
945 if (GetToolBar())
946 {
947 CommandBar_DrawMenuBar((HWND) GetToolBar()->GetHWND(), 0);
948 }
949 #elif defined(WINCE_WITH_COMMANDBAR)
950 if (m_commandBar)
951 DrawMenuBar((HWND) m_commandBar);
952 #else
953 DrawMenuBar(GetHwndOf(GetFrame()));
954 #endif
955 }
956
957 WXHMENU wxMenuBar::Create()
958 {
959 // Note: this doesn't work at all on Smartphone,
960 // since you have to use resources.
961 // We'll have to find another way to add a menu
962 // by changing/adding menu items to an existing menu.
963 #if defined(WINCE_WITHOUT_COMMANDBAR)
964 if ( m_hMenu != 0 )
965 return m_hMenu;
966
967 wxToolMenuBar * const bar = static_cast<wxToolMenuBar *>(GetToolBar());
968 if ( !bar )
969 return NULL;
970
971 HWND hCommandBar = GetHwndOf(bar);
972
973 // notify comctl32.dll about the version of the headers we use before using
974 // any other TB_XXX messages
975 SendMessage(hCommandBar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
976
977 TBBUTTON tbButton;
978 wxZeroMemory(tbButton);
979 tbButton.iBitmap = I_IMAGENONE;
980 tbButton.fsState = TBSTATE_ENABLED;
981 tbButton.fsStyle = TBSTYLE_DROPDOWN |
982 TBSTYLE_NO_DROPDOWN_ARROW |
983 TBSTYLE_AUTOSIZE;
984
985 for ( unsigned i = 0; i < GetMenuCount(); i++ )
986 {
987 HMENU hPopupMenu = (HMENU) GetMenu(i)->GetHMenu();
988 tbButton.dwData = (DWORD)hPopupMenu;
989 wxString label = wxStripMenuCodes(GetMenuLabel(i));
990 tbButton.iString = (int) label.wx_str();
991
992 tbButton.idCommand = NewControlId();
993 if ( !::SendMessage(hCommandBar, TB_INSERTBUTTON, i, (LPARAM)&tbButton) )
994 {
995 wxLogLastError(wxT("TB_INSERTBUTTON"));
996 }
997 }
998
999 m_hMenu = bar->GetHMenu();
1000 return m_hMenu;
1001 #else // !__WXWINCE__
1002 if ( m_hMenu != 0 )
1003 return m_hMenu;
1004
1005 m_hMenu = (WXHMENU)::CreateMenu();
1006
1007 if ( !m_hMenu )
1008 {
1009 wxLogLastError(wxT("CreateMenu"));
1010 }
1011 else
1012 {
1013 size_t count = GetMenuCount(), i;
1014 wxMenuList::iterator it;
1015 for ( i = 0, it = m_menus.begin(); i < count; i++, it++ )
1016 {
1017 if ( !::AppendMenu((HMENU)m_hMenu, MF_POPUP | MF_STRING,
1018 (UINT_PTR)(*it)->GetHMenu(),
1019 m_titles[i].wx_str()) )
1020 {
1021 wxLogLastError(wxT("AppendMenu"));
1022 }
1023 }
1024 }
1025
1026 return m_hMenu;
1027 #endif // __WXWINCE__/!__WXWINCE__
1028 }
1029
1030 int wxMenuBar::MSWPositionForWxMenu(wxMenu *menu, int wxpos)
1031 {
1032 wxASSERT(menu);
1033 wxASSERT(menu->GetHMenu());
1034 wxASSERT(m_hMenu);
1035
1036 #if defined(__WXWINCE__)
1037 int totalMSWItems = GetMenuCount();
1038 #else
1039 int totalMSWItems = GetMenuItemCount((HMENU)m_hMenu);
1040 #endif
1041
1042 int i; // For old C++ compatibility
1043 for(i=wxpos; i<totalMSWItems; i++)
1044 {
1045 if(GetSubMenu((HMENU)m_hMenu,i)==(HMENU)menu->GetHMenu())
1046 return i;
1047 }
1048 for(i=0; i<wxpos; i++)
1049 {
1050 if(GetSubMenu((HMENU)m_hMenu,i)==(HMENU)menu->GetHMenu())
1051 return i;
1052 }
1053 wxFAIL;
1054 return -1;
1055 }
1056
1057 // ---------------------------------------------------------------------------
1058 // wxMenuBar functions to work with the top level submenus
1059 // ---------------------------------------------------------------------------
1060
1061 // NB: we don't support owner drawn top level items for now, if we do these
1062 // functions would have to be changed to use wxMenuItem as well
1063
1064 void wxMenuBar::EnableTop(size_t pos, bool enable)
1065 {
1066 wxCHECK_RET( IsAttached(), wxT("doesn't work with unattached menubars") );
1067 wxCHECK_RET( pos < GetMenuCount(), wxT("invalid menu index") );
1068
1069 int flag = enable ? MF_ENABLED : MF_GRAYED;
1070
1071 EnableMenuItem((HMENU)m_hMenu, MSWPositionForWxMenu(GetMenu(pos),pos), MF_BYPOSITION | flag);
1072
1073 Refresh();
1074 }
1075
1076 void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label)
1077 {
1078 wxCHECK_RET( pos < GetMenuCount(), wxT("invalid menu index") );
1079
1080 m_titles[pos] = label;
1081
1082 if ( !IsAttached() )
1083 {
1084 return;
1085 }
1086 //else: have to modify the existing menu
1087
1088 int mswpos = MSWPositionForWxMenu(GetMenu(pos),pos);
1089
1090 UINT_PTR id;
1091 UINT flagsOld = ::GetMenuState((HMENU)m_hMenu, mswpos, MF_BYPOSITION);
1092 if ( flagsOld == 0xFFFFFFFF )
1093 {
1094 wxLogLastError(wxT("GetMenuState"));
1095
1096 return;
1097 }
1098
1099 if ( flagsOld & MF_POPUP )
1100 {
1101 // HIBYTE contains the number of items in the submenu in this case
1102 flagsOld &= 0xff;
1103 id = (UINT_PTR)::GetSubMenu((HMENU)m_hMenu, mswpos);
1104 }
1105 else
1106 {
1107 id = pos;
1108 }
1109
1110 #ifdef __WXWINCE__
1111 MENUITEMINFO info;
1112 wxZeroMemory(info);
1113 info.cbSize = sizeof(info);
1114 info.fMask = MIIM_TYPE;
1115 info.fType = MFT_STRING;
1116 info.cch = label.length();
1117 info.dwTypeData = const_cast<wxChar *>(label.wx_str());
1118 if ( !SetMenuItemInfo(GetHmenu(), id, TRUE, &info) )
1119 {
1120 wxLogLastError(wxT("SetMenuItemInfo"));
1121 }
1122
1123 #else
1124 if ( ::ModifyMenu(GetHmenu(), mswpos, MF_BYPOSITION | MF_STRING | flagsOld,
1125 id, label.wx_str()) == (int)0xFFFFFFFF )
1126 {
1127 wxLogLastError(wxT("ModifyMenu"));
1128 }
1129 #endif
1130
1131 Refresh();
1132 }
1133
1134 wxString wxMenuBar::GetMenuLabel(size_t pos) const
1135 {
1136 wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString,
1137 wxT("invalid menu index in wxMenuBar::GetMenuLabel") );
1138
1139 return m_titles[pos];
1140 }
1141
1142 // ---------------------------------------------------------------------------
1143 // wxMenuBar construction
1144 // ---------------------------------------------------------------------------
1145
1146 wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
1147 {
1148 wxMenu *menuOld = wxMenuBarBase::Replace(pos, menu, title);
1149 if ( !menuOld )
1150 return NULL;
1151
1152 m_titles[pos] = title;
1153
1154 #if defined(WINCE_WITHOUT_COMMANDBAR)
1155 if (IsAttached())
1156 #else
1157 if (GetHmenu())
1158 #endif
1159 {
1160 int mswpos = MSWPositionForWxMenu(menuOld,pos);
1161
1162 // can't use ModifyMenu() because it deletes the submenu it replaces
1163 if ( !::RemoveMenu(GetHmenu(), (UINT)mswpos, MF_BYPOSITION) )
1164 {
1165 wxLogLastError(wxT("RemoveMenu"));
1166 }
1167
1168 if ( !::InsertMenu(GetHmenu(), (UINT)mswpos,
1169 MF_BYPOSITION | MF_POPUP | MF_STRING,
1170 (UINT_PTR)GetHmenuOf(menu), title.wx_str()) )
1171 {
1172 wxLogLastError(wxT("InsertMenu"));
1173 }
1174
1175 #if wxUSE_ACCEL
1176 if ( menuOld->HasAccels() || menu->HasAccels() )
1177 {
1178 // need to rebuild accell table
1179 RebuildAccelTable();
1180 }
1181 #endif // wxUSE_ACCEL
1182
1183 if (IsAttached())
1184 Refresh();
1185 }
1186
1187 return menuOld;
1188 }
1189
1190 bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
1191 {
1192 // Find out which MSW item before which we'll be inserting before
1193 // wxMenuBarBase::Insert is called and GetMenu(pos) is the new menu.
1194 // If IsAttached() is false this won't be used anyway
1195 bool isAttached =
1196 #if defined(WINCE_WITHOUT_COMMANDBAR)
1197 IsAttached();
1198 #else
1199 (GetHmenu() != 0);
1200 #endif
1201
1202 int mswpos = (!isAttached || (pos == m_menus.GetCount()))
1203 ? -1 // append the menu
1204 : MSWPositionForWxMenu(GetMenu(pos),pos);
1205
1206 if ( !wxMenuBarBase::Insert(pos, menu, title) )
1207 return false;
1208
1209 m_titles.Insert(title, pos);
1210
1211 if ( isAttached )
1212 {
1213 #if defined(WINCE_WITHOUT_COMMANDBAR)
1214 if (!GetToolBar())
1215 return false;
1216 TBBUTTON tbButton;
1217 memset(&tbButton, 0, sizeof(TBBUTTON));
1218 tbButton.iBitmap = I_IMAGENONE;
1219 tbButton.fsState = TBSTATE_ENABLED;
1220 tbButton.fsStyle = TBSTYLE_DROPDOWN | TBSTYLE_NO_DROPDOWN_ARROW | TBSTYLE_AUTOSIZE;
1221
1222 HMENU hPopupMenu = (HMENU) menu->GetHMenu() ;
1223 tbButton.dwData = (DWORD)hPopupMenu;
1224 wxString label = wxStripMenuCodes(title);
1225 tbButton.iString = (int) label.wx_str();
1226
1227 tbButton.idCommand = NewControlId();
1228 if (!::SendMessage((HWND) GetToolBar()->GetHWND(), TB_INSERTBUTTON, pos, (LPARAM)&tbButton))
1229 {
1230 wxLogLastError(wxT("TB_INSERTBUTTON"));
1231 return false;
1232 }
1233 wxUnusedVar(mswpos);
1234 #else
1235 if ( !::InsertMenu(GetHmenu(), mswpos,
1236 MF_BYPOSITION | MF_POPUP | MF_STRING,
1237 (UINT_PTR)GetHmenuOf(menu), title.wx_str()) )
1238 {
1239 wxLogLastError(wxT("InsertMenu"));
1240 }
1241 #endif
1242 #if wxUSE_ACCEL
1243 if ( menu->HasAccels() )
1244 {
1245 // need to rebuild accell table
1246 RebuildAccelTable();
1247 }
1248 #endif // wxUSE_ACCEL
1249
1250 if (IsAttached())
1251 Refresh();
1252 }
1253
1254 return true;
1255 }
1256
1257 bool wxMenuBar::Append(wxMenu *menu, const wxString& title)
1258 {
1259 WXHMENU submenu = menu ? menu->GetHMenu() : 0;
1260 wxCHECK_MSG( submenu, false, wxT("can't append invalid menu to menubar") );
1261
1262 if ( !wxMenuBarBase::Append(menu, title) )
1263 return false;
1264
1265 m_titles.Add(title);
1266
1267 #if defined(WINCE_WITHOUT_COMMANDBAR)
1268 if (IsAttached())
1269 #else
1270 if (GetHmenu())
1271 #endif
1272 {
1273 #if defined(WINCE_WITHOUT_COMMANDBAR)
1274 if (!GetToolBar())
1275 return false;
1276 TBBUTTON tbButton;
1277 memset(&tbButton, 0, sizeof(TBBUTTON));
1278 tbButton.iBitmap = I_IMAGENONE;
1279 tbButton.fsState = TBSTATE_ENABLED;
1280 tbButton.fsStyle = TBSTYLE_DROPDOWN | TBSTYLE_NO_DROPDOWN_ARROW | TBSTYLE_AUTOSIZE;
1281
1282 size_t pos = GetMenuCount();
1283 HMENU hPopupMenu = (HMENU) menu->GetHMenu() ;
1284 tbButton.dwData = (DWORD)hPopupMenu;
1285 wxString label = wxStripMenuCodes(title);
1286 tbButton.iString = (int) label.wx_str();
1287
1288 tbButton.idCommand = NewControlId();
1289 if (!::SendMessage((HWND) GetToolBar()->GetHWND(), TB_INSERTBUTTON, pos, (LPARAM)&tbButton))
1290 {
1291 wxLogLastError(wxT("TB_INSERTBUTTON"));
1292 return false;
1293 }
1294 #else
1295 if ( !::AppendMenu(GetHmenu(), MF_POPUP | MF_STRING,
1296 (UINT_PTR)submenu, title.wx_str()) )
1297 {
1298 wxLogLastError(wxT("AppendMenu"));
1299 }
1300 #endif
1301
1302 #if wxUSE_ACCEL
1303 if ( menu->HasAccels() )
1304 {
1305 // need to rebuild accelerator table
1306 RebuildAccelTable();
1307 }
1308 #endif // wxUSE_ACCEL
1309
1310 if (IsAttached())
1311 Refresh();
1312 }
1313
1314 return true;
1315 }
1316
1317 wxMenu *wxMenuBar::Remove(size_t pos)
1318 {
1319 wxMenu *menu = wxMenuBarBase::Remove(pos);
1320 if ( !menu )
1321 return NULL;
1322
1323 #if defined(WINCE_WITHOUT_COMMANDBAR)
1324 if (IsAttached())
1325 #else
1326 if (GetHmenu())
1327 #endif
1328 {
1329 #if defined(WINCE_WITHOUT_COMMANDBAR)
1330 if (GetToolBar())
1331 {
1332 if (!::SendMessage((HWND) GetToolBar()->GetHWND(), TB_DELETEBUTTON, (UINT) pos, (LPARAM) 0))
1333 {
1334 wxLogLastError(wxT("TB_DELETEBUTTON"));
1335 }
1336 }
1337 #else
1338 if ( !::RemoveMenu(GetHmenu(), (UINT)MSWPositionForWxMenu(menu,pos), MF_BYPOSITION) )
1339 {
1340 wxLogLastError(wxT("RemoveMenu"));
1341 }
1342 #endif
1343
1344 #if wxUSE_ACCEL
1345 if ( menu->HasAccels() )
1346 {
1347 // need to rebuild accell table
1348 RebuildAccelTable();
1349 }
1350 #endif // wxUSE_ACCEL
1351
1352 if (IsAttached())
1353 Refresh();
1354 }
1355
1356 m_titles.RemoveAt(pos);
1357
1358 return menu;
1359 }
1360
1361 #if wxUSE_ACCEL
1362
1363 void wxMenuBar::RebuildAccelTable()
1364 {
1365 // merge the accelerators of all menus into one accel table
1366 size_t nAccelCount = 0;
1367 size_t i, count = GetMenuCount();
1368 wxMenuList::iterator it;
1369 for ( i = 0, it = m_menus.begin(); i < count; i++, it++ )
1370 {
1371 nAccelCount += (*it)->GetAccelCount();
1372 }
1373
1374 if ( nAccelCount )
1375 {
1376 wxAcceleratorEntry *accelEntries = new wxAcceleratorEntry[nAccelCount];
1377
1378 nAccelCount = 0;
1379 for ( i = 0, it = m_menus.begin(); i < count; i++, it++ )
1380 {
1381 nAccelCount += (*it)->CopyAccels(&accelEntries[nAccelCount]);
1382 }
1383
1384 SetAcceleratorTable(wxAcceleratorTable(nAccelCount, accelEntries));
1385
1386 delete [] accelEntries;
1387 }
1388 }
1389
1390 #endif // wxUSE_ACCEL
1391
1392 void wxMenuBar::Attach(wxFrame *frame)
1393 {
1394 wxMenuBarBase::Attach(frame);
1395
1396 #if defined(WINCE_WITH_COMMANDBAR)
1397 if (!m_hMenu)
1398 this->Create();
1399 if (!m_commandBar)
1400 m_commandBar = (WXHWND) CommandBar_Create(wxGetInstance(), (HWND) frame->GetHWND(), NewControlId());
1401 if (m_commandBar)
1402 {
1403 if (m_hMenu)
1404 {
1405 if (!CommandBar_InsertMenubarEx((HWND) m_commandBar, NULL, (LPTSTR) m_hMenu, 0))
1406 {
1407 wxLogLastError(wxT("CommandBar_InsertMenubarEx"));
1408 }
1409 }
1410 }
1411 #endif
1412
1413 #if wxUSE_ACCEL
1414 RebuildAccelTable();
1415 #endif // wxUSE_ACCEL
1416 }
1417
1418 #if defined(WINCE_WITH_COMMANDBAR)
1419 bool wxMenuBar::AddAdornments(long style)
1420 {
1421 if (m_adornmentsAdded || !m_commandBar)
1422 return false;
1423
1424 if (style & wxCLOSE_BOX)
1425 {
1426 if (!CommandBar_AddAdornments((HWND) m_commandBar, 0, 0))
1427 wxLogLastError(wxT("CommandBar_AddAdornments"));
1428 else
1429 return true;
1430 }
1431 return false;
1432 }
1433 #endif
1434
1435 void wxMenuBar::Detach()
1436 {
1437 wxMenuBarBase::Detach();
1438 }
1439
1440 #endif // wxUSE_MENUS