Repository navigation
Expand file tree
/
Copy pathmenu.cpp
More file actions
1176 lines (1029 loc) · 31.9 KB
/
Copy pathmenu.cpp
File metadata and controls
1176 lines (1029 loc) · 31.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/////////////////////////////////////////////////////////////////////////////
// Name: src/os2/menu.cpp
// Purpose: wxMenu, wxMenuBar, wxMenuItem
// Author: David Webster
// Modified by:
// Created: 10/10/99
// RCS-ID: $Id$
// Copyright: (c) David Webster
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#include "wx/menu.h"
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/frame.h"
#include "wx/utils.h"
#include "wx/intl.h"
#include "wx/log.h"
#endif
#if wxUSE_OWNER_DRAWN
#include "wx/ownerdrw.h"
#endif
#include "wx/os2/private.h"
// other standard headers
#include <string.h>
// ----------------------------------------------------------------------------
// global variables
// ----------------------------------------------------------------------------
extern wxMenu* wxCurrentPopupMenu;
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
//
// The (popup) menu title has this special id
//
static const int idMenuTitle = -3;
//
// The unique ID for Menus
//
USHORT wxMenu::m_nextMenuId = 0;
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler)
IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler)
// ============================================================================
// implementation
// ============================================================================
// ---------------------------------------------------------------------------
// wxMenu construction, adding and removing menu items
// ---------------------------------------------------------------------------
//
// Construct a menu with optional title (then use append)
//
void wxMenu::Init()
{
m_bDoBreak = false;
m_nStartRadioGroup = -1;
//
// Create the menu (to be used as a submenu or a popup)
//
if ((m_hMenu = ::WinCreateWindow( HWND_DESKTOP
,WC_MENU
,"Menu"
,0L
,0L
,0L
,0L
,0L
,NULLHANDLE
,HWND_TOP
,0L
,NULL
,NULL
)) == 0)
{
wxLogLastError(wxT("WinLoadMenu"));
}
m_vMenuData.iPosition = 0;
m_vMenuData.afStyle = MIS_SUBMENU | MIS_TEXT;
m_vMenuData.afAttribute = (USHORT)0;
m_vMenuData.id = m_nextMenuId++;
m_vMenuData.hwndSubMenu = m_hMenu;
m_vMenuData.hItem = NULLHANDLE;
//
// If we have a title, insert it in the beginning of the menu
//
if (!m_title.empty())
{
Append( idMenuTitle
,m_title
,wxEmptyString
,wxITEM_NORMAL
);
AppendSeparator();
}
} // end of wxMenu::Init
//
// The wxWindow destructor will take care of deleting the submenus.
//
wxMenu::~wxMenu()
{
//
// We should free PM resources only if PM doesn't do it for us
// which happens if we're attached to a menubar or a submenu of another
// menu
if (!IsAttached() && !GetParent())
{
if (!::WinDestroyWindow((HWND)GetHmenu()) )
{
wxLogLastError(wxT("WinDestroyWindow"));
}
}
#if wxUSE_ACCEL
//
// Delete accels
//
WX_CLEAR_ARRAY(m_vAccels);
#endif // wxUSE_ACCEL
} // end of wxMenu::~wxMenu
void wxMenu::Break()
{
// this will take effect during the next call to Append()
m_bDoBreak = true;
} // end of wxMenu::Break
void wxMenu::Attach(
wxMenuBarBase* pMenubar
)
{
wxMenuBase::Attach(pMenubar);
EndRadioGroup();
} // end of wxMenu::Break;
#if wxUSE_ACCEL
int wxMenu::FindAccel(
int nId
) const
{
size_t n;
size_t nCount = m_vAccels.GetCount();
for (n = 0; n < nCount; n++)
if (m_vAccels[n]->m_command == nId)
return n;
return wxNOT_FOUND;
} // end of wxMenu::FindAccel
void wxMenu::UpdateAccel(
wxMenuItem* pItem
)
{
if (pItem->IsSubMenu())
{
wxMenu* pSubmenu = pItem->GetSubMenu();
wxMenuItemList::compatibility_iterator node = pSubmenu->GetMenuItems().GetFirst();
while (node)
{
UpdateAccel(node->GetData());
node = node->GetNext();
}
}
else if (!pItem->IsSeparator())
{
//
// Recurse upwards: we should only modify m_accels of the top level
// menus, not of the submenus as wxMenuBar doesn't look at them
// (alternative and arguable cleaner solution would be to recurse
// downwards in GetAccelCount() and CopyAccels())
//
if (GetParent())
{
GetParent()->UpdateAccel(pItem);
return;
}
//
// Find the (new) accel for this item
//
wxAcceleratorEntry* pAccel = wxAcceleratorEntry::Create(pItem->GetItemLabel());
if (pAccel)
pAccel->m_command = pItem->GetId();
//
// Find the old one
//
size_t n = FindAccel(pItem->GetId());
if (n == (size_t)wxNOT_FOUND)
{
//
// No old, add new if any
//
if (pAccel)
m_vAccels.Add(pAccel);
else
return;
}
else
{
//
// Replace old with new or just remove the old one if no new
//
delete m_vAccels[n];
if (pAccel)
m_vAccels[n] = pAccel;
else
m_vAccels.RemoveAt(n);
}
if (IsAttached())
{
GetMenuBar()->RebuildAccelTable();
}
}
} // wxMenu::UpdateAccel
#endif // wxUSE_ACCEL
//
// Append a new item or submenu to the menu
//
bool wxMenu::DoInsertOrAppend( wxMenuItem* pItem,
size_t nPos )
{
wxMenu* pSubmenu = pItem->GetSubMenu();
MENUITEM& rItem = (pSubmenu != NULL)?pSubmenu->m_vMenuData:
pItem->m_vMenuData;
ERRORID vError;
wxString sError;
#if wxUSE_ACCEL
UpdateAccel(pItem);
#endif // wxUSE_ACCEL
//
// If "Break" has just been called, insert a menu break before this item
// (and don't forget to reset the flag)
//
if (m_bDoBreak)
{
rItem.afStyle |= MIS_BREAK;
m_bDoBreak = false;
}
//
// Id is the numeric id for normal menu items and HMENU for submenus as
// required by ::MM_INSERTITEM message API
//
if (pSubmenu != NULL)
{
wxASSERT_MSG(pSubmenu->GetHMenu(), wxT("invalid submenu"));
pSubmenu->SetParent(this);
rItem.iPosition = 0; // submenus have a 0 position
rItem.id = (USHORT)pSubmenu->GetHMenu();
rItem.afStyle |= MIS_SUBMENU | MIS_TEXT;
}
else
{
rItem.id = (USHORT)pItem->GetId();
}
char *pData = NULL;
#if wxUSE_OWNER_DRAWN
if (pItem->IsOwnerDrawn())
{
//
// Want to get {Measure|Draw}Item messages?
// item draws itself, passing pointer to data doesn't work in OS/2
// Will eventually need to set the image handle somewhere into vItem.hItem
//
rItem.afStyle |= MIS_OWNERDRAW;
pData = NULL;
rItem.hItem = (HBITMAP)pItem->GetBitmap().GetHBITMAP();
pItem->m_vMenuData.afStyle = rItem.afStyle;
pItem->m_vMenuData.hItem = rItem.hItem;
}
else
#endif
if (pItem->IsSeparator())
{
rItem.afStyle = MIS_SEPARATOR;
}
else
{
if (pItem->GetId() == idMenuTitle)
{
// Item is an unselectable title to be passed via pData
rItem.afStyle = MIS_STATIC;
}
else
{
//
// Menu is just a normal string (passed in data parameter)
//
rItem.afStyle |= MIS_TEXT;
}
pData = (char*) pItem->GetItemLabel().wx_str();
}
if (nPos == (size_t)-1)
{
rItem.iPosition = MIT_END;
}
else
{
rItem.iPosition = (SHORT)nPos;
}
APIRET rc;
rc = (APIRET)::WinSendMsg( GetHmenu()
,MM_INSERTITEM
,(MPARAM)&rItem
,(MPARAM)pData
);
#if wxUSE_OWNER_DRAWN
if (pItem->IsOwnerDrawn())
{
MENUITEM vMenuItem;
::WinSendMsg( GetHmenu()
,MM_QUERYITEM
,MPFROM2SHORT( (USHORT)pItem->GetId()
,(USHORT)(FALSE)
)
,&vMenuItem
);
}
#endif
if (rc == (APIRET)MIT_MEMERROR || rc == (APIRET)MIT_ERROR)
{
vError = ::WinGetLastError(vHabmain);
sError = wxPMErrorToStr(vError);
wxLogError(wxT("Error inserting or appending a menuitem. Error: %s\n"), sError.c_str());
wxLogLastError(wxT("Insert or AppendMenu"));
return false;
}
//
// If we're already attached to the menubar, we must update it
//
if (IsAttached() && GetMenuBar()->IsAttached())
{
GetMenuBar()->Refresh();
}
return true;
} // end of wxMenu::DoInsertOrAppend
void wxMenu::EndRadioGroup()
{
//
// We're not inside a radio group any longer
//
m_nStartRadioGroup = -1;
} // end of wxMenu::EndRadioGroup
wxMenuItem* wxMenu::DoAppend( wxMenuItem* pItem )
{
wxCHECK_MSG( pItem, NULL, _T("NULL item in wxMenu::DoAppend") );
bool bCheck = false;
if (pItem->GetKind() == wxITEM_RADIO)
{
int nCount = GetMenuItemCount();
if (m_nStartRadioGroup == -1)
{
//
// Start a new radio group
//
m_nStartRadioGroup = nCount;
//
// For now it has just one element
//
pItem->SetAsRadioGroupStart();
pItem->SetRadioGroupEnd(m_nStartRadioGroup);
//
// Ensure that we have a checked item in the radio group
//
bCheck = true;
}
else // extend the current radio group
{
//
// We need to update its end item
//
pItem->SetRadioGroupStart(m_nStartRadioGroup);
wxMenuItemList::compatibility_iterator node = GetMenuItems().Item(m_nStartRadioGroup);
if (node)
{
node->GetData()->SetRadioGroupEnd(nCount);
}
else
{
wxFAIL_MSG( _T("where is the radio group start item?") );
}
}
}
else // not a radio item
{
EndRadioGroup();
}
if (!wxMenuBase::DoAppend(pItem) || !DoInsertOrAppend(pItem))
{
return NULL;
}
if (bCheck)
{
//
// Check the item initially
//
pItem->Check(true);
}
return pItem;
} // end of wxMenu::DoAppend
wxMenuItem* wxMenu::DoInsert(
size_t nPos
, wxMenuItem* pItem
)
{
if ( wxMenuBase::DoInsert( nPos
,pItem) &&
DoInsertOrAppend( pItem
,nPos
))
return pItem;
else
return NULL;
} // end of wxMenu::DoInsert
wxMenuItem* wxMenu::DoRemove(
wxMenuItem* pItem
)
{
//
// We need to find the items position in the child list
//
size_t nPos;
wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
for (nPos = 0; node; nPos++)
{
if (node->GetData() == pItem)
break;
node = node->GetNext();
}
//
// DoRemove() (unlike Remove) can only be called for existing item!
//
wxCHECK_MSG(node, NULL, wxT("bug in wxMenu::Remove logic"));
#if wxUSE_ACCEL
//
// Remove the corresponding accel from the accel table
//
int n = FindAccel(pItem->GetId());
if (n != wxNOT_FOUND)
{
delete m_vAccels[n];
m_vAccels.RemoveAt(n);
}
#endif // wxUSE_ACCEL
//
// Remove the item from the menu
//
::WinSendMsg( GetHmenu()
,MM_REMOVEITEM
,MPFROM2SHORT(pItem->GetId(), TRUE)
,(MPARAM)0
);
if (IsAttached() && GetMenuBar()->IsAttached())
{
//
// Otherwise, the chane won't be visible
//
GetMenuBar()->Refresh();
}
//
// And from internal data structures
//
return wxMenuBase::DoRemove(pItem);
} // end of wxMenu::DoRemove
// ---------------------------------------------------------------------------
// accelerator helpers
// ---------------------------------------------------------------------------
#if wxUSE_ACCEL
//
// Create the wxAcceleratorEntries for our accels and put them into provided
// array - return the number of accels we have
//
size_t wxMenu::CopyAccels(
wxAcceleratorEntry* pAccels
) const
{
size_t nCount = GetAccelCount();
for (size_t n = 0; n < nCount; n++)
{
*pAccels++ = *m_vAccels[n];
}
return nCount;
} // end of wxMenu::CopyAccels
#endif // wxUSE_ACCEL
// ---------------------------------------------------------------------------
// set wxMenu title
// ---------------------------------------------------------------------------
void wxMenu::SetTitle( const wxString& rLabel )
{
bool bHasNoTitle = m_title.empty();
HWND hMenu = GetHmenu();
m_title = rLabel;
if (bHasNoTitle)
{
if (!rLabel.empty())
{
if (!::WinSetWindowText(hMenu, rLabel.c_str()))
{
wxLogLastError(wxT("SetMenuTitle"));
}
}
}
else
{
if (rLabel.empty() )
{
::WinSendMsg( GetHmenu()
,MM_REMOVEITEM
,MPFROM2SHORT(hMenu, TRUE)
,(MPARAM)0
);
}
else
{
//
// Modify the title
//
if (!::WinSetWindowText(hMenu, rLabel.c_str()))
{
wxLogLastError(wxT("SetMenuTitle"));
}
}
}
} // end of wxMenu::SetTitle
// ---------------------------------------------------------------------------
// event processing
// ---------------------------------------------------------------------------
bool wxMenu::OS2Command( WXUINT WXUNUSED(uParam),
WXWORD vId )
{
//
// Ignore commands from the menu title
//
if (vId != (WXWORD)idMenuTitle)
{
SendEvent( vId
,(int)::WinSendMsg( GetHmenu()
,MM_QUERYITEMATTR
,MPFROMSHORT(vId)
,(MPARAM)MIA_CHECKED
)
);
}
return true;
} // end of wxMenu::OS2Command
// ---------------------------------------------------------------------------
// other
// ---------------------------------------------------------------------------
wxWindow* wxMenu::GetWindow() const
{
if (m_invokingWindow != NULL)
return m_invokingWindow;
else if ( GetMenuBar() != NULL)
return GetMenuBar()->GetFrame();
return NULL;
} // end of wxMenu::GetWindow
// recursive search for item by id
wxMenuItem* wxMenu::FindItem(
int nItemId
, ULONG hItem
, wxMenu** ppItemMenu
) const
{
if ( ppItemMenu )
*ppItemMenu = NULL;
wxMenuItem* pItem = NULL;
for ( wxMenuItemList::compatibility_iterator node = m_items.GetFirst();
node && !pItem;
node = node->GetNext() )
{
pItem = node->GetData();
if ( pItem->GetId() == nItemId && pItem->m_vMenuData.hItem == hItem)
{
if ( ppItemMenu )
*ppItemMenu = (wxMenu *)this;
}
else if ( pItem->IsSubMenu() )
{
pItem = pItem->GetSubMenu()->FindItem( nItemId
,hItem
,ppItemMenu
);
if (pItem)
break;
}
else
{
// don't exit the loop
pItem = NULL;
}
}
return pItem;
} // end of wxMenu::FindItem
// ---------------------------------------------------------------------------
// Menu Bar
// ---------------------------------------------------------------------------
void wxMenuBar::Init()
{
m_eventHandler = this;
m_menuBarFrame = NULL;
m_hMenu = 0;
} // end of wxMenuBar::Init
wxMenuBar::wxMenuBar()
{
Init();
} // end of wxMenuBar::wxMenuBar
wxMenuBar::wxMenuBar(
long WXUNUSED(lStyle)
)
{
Init();
} // end of wxMenuBar::wxMenuBar
wxMenuBar::wxMenuBar(
int nCount
, wxMenu* vMenus[]
, const wxString sTitles[]
, long WXUNUSED(lStyle)
)
{
Init();
m_titles.Alloc(nCount);
for ( int i = 0; i < nCount; i++ )
{
m_menus.Append(vMenus[i]);
m_titles.Add(sTitles[i]);
vMenus[i]->Attach(this);
}
} // end of wxMenuBar::wxMenuBar
wxMenuBar::~wxMenuBar()
{
//
// We should free PM's resources only if PM doesn't do it for us
// which happens if we're attached to a frame
//
if (m_hMenu && !IsAttached())
{
::WinDestroyWindow((HMENU)m_hMenu);
m_hMenu = (WXHMENU)NULL;
}
} // end of wxMenuBar::~wxMenuBar
// ---------------------------------------------------------------------------
// wxMenuBar helpers
// ---------------------------------------------------------------------------
void wxMenuBar::Refresh()
{
wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") );
WinSendMsg(GetWinHwnd(m_menuBarFrame), WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0);
} // end of wxMenuBar::Refresh
WXHMENU wxMenuBar::Create()
{
HWND hFrame;
if (m_hMenu != 0 )
return m_hMenu;
wxCHECK_MSG(!m_hMenu, TRUE, wxT("menubar already created"));
//
// Menubars should be associated with a frame otherwise they are popups
//
if (m_menuBarFrame != NULL)
hFrame = GetWinHwnd(m_menuBarFrame);
else
hFrame = HWND_DESKTOP;
//
// Create an empty menu and then fill it with insertions
//
if ((m_hMenu = ::WinCreateWindow( hFrame
,WC_MENU
,NULL
,MS_ACTIONBAR | WS_SYNCPAINT | WS_VISIBLE
,0L
,0L
,0L
,0L
,hFrame
,HWND_TOP
,FID_MENU
,NULL
,NULL
)) == 0)
{
wxLogLastError(wxT("WinLoadMenu"));
}
else
{
size_t nCount = GetMenuCount(), i;
wxMenuList::iterator it;
for (i = 0, it = m_menus.begin(); i < nCount; i++, it++)
{
APIRET rc;
ERRORID vError;
wxString sError;
HWND hSubMenu;
//
// Set the parent and owner of the submenues to be the menubar, not the desktop
//
hSubMenu = (*it)->m_vMenuData.hwndSubMenu;
if (!::WinSetParent((*it)->m_vMenuData.hwndSubMenu, m_hMenu, FALSE))
{
vError = ::WinGetLastError(vHabmain);
sError = wxPMErrorToStr(vError);
wxLogError(wxT("Error setting parent for submenu. Error: %s\n"), sError.c_str());
return NULLHANDLE;
}
if (!::WinSetOwner((*it)->m_vMenuData.hwndSubMenu, m_hMenu))
{
vError = ::WinGetLastError(vHabmain);
sError = wxPMErrorToStr(vError);
wxLogError(wxT("Error setting parent for submenu. Error: %s\n"), sError.c_str());
return NULLHANDLE;
}
(*it)->m_vMenuData.iPosition = (SHORT)i;
rc = (APIRET)::WinSendMsg(m_hMenu, MM_INSERTITEM, (MPARAM)&(*it)->m_vMenuData, (MPARAM)m_titles[i].wx_str());
if (rc == (APIRET)MIT_MEMERROR || rc == (APIRET)MIT_ERROR)
{
vError = ::WinGetLastError(vHabmain);
sError = wxPMErrorToStr(vError);
wxLogError(wxT("Error inserting or appending a menuitem. Error: %s\n"), sError.c_str());
return NULLHANDLE;
}
}
}
return m_hMenu;
} // end of wxMenuBar::Create
// ---------------------------------------------------------------------------
// wxMenuBar functions to work with the top level submenus
// ---------------------------------------------------------------------------
//
// NB: we don't support owner drawn top level items for now, if we do these
// functions would have to be changed to use wxMenuItem as well
//
void wxMenuBar::EnableTop(
size_t nPos
, bool bEnable
)
{
wxCHECK_RET(IsAttached(), wxT("doesn't work with unattached menubars"));
USHORT uFlag = 0;
SHORT nId;
if(!bEnable)
uFlag = MIA_DISABLED;
nId = SHORT1FROMMR(::WinSendMsg((HWND)m_hMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT(nPos), (MPARAM)0));
if (nId == MIT_ERROR)
{
wxLogLastError(wxT("LogLastError"));
return;
}
::WinSendMsg((HWND)m_hMenu, MM_SETITEMATTR, MPFROM2SHORT(nId, TRUE), MPFROM2SHORT(MIA_DISABLED, uFlag));
Refresh();
} // end of wxMenuBar::EnableTop
void wxMenuBar::SetMenuLabel(
size_t nPos
, const wxString& rLabel
)
{
SHORT nId;
MENUITEM vItem;
wxCHECK_RET(nPos < GetMenuCount(), wxT("invalid menu index"));
m_titles[nPos] = rLabel;
if (!IsAttached())
{
return;
}
nId = SHORT1FROMMR(::WinSendMsg((HWND)m_hMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT(nPos), (MPARAM)0));
if (nId == MIT_ERROR)
{
wxLogLastError(wxT("LogLastError"));
return;
}
if(!::WinSendMsg( (HWND)m_hMenu
,MM_QUERYITEM
,MPFROM2SHORT(nId, TRUE)
,MPARAM(&vItem)
))
{
wxLogLastError(wxT("QueryItem"));
}
nId = vItem.id;
if (::WinSendMsg(GetHmenu(), MM_SETITEMTEXT, MPFROMSHORT(nId), (MPARAM)rLabel.wx_str()));
{
wxLogLastError(wxT("ModifyMenu"));
}
Refresh();
} // end of wxMenuBar::SetMenuLabel
wxString wxMenuBar::GetMenuLabel(
size_t nPos
) const
{
wxCHECK_MSG( nPos < GetMenuCount(), wxEmptyString,
wxT("invalid menu index in wxMenuBar::GetMenuLabel") );
return m_titles[nPos];
} // end of wxMenuBar::GetMenuLabel
// ---------------------------------------------------------------------------
// wxMenuBar construction
// ---------------------------------------------------------------------------
wxMenu* wxMenuBar::Replace(
size_t nPos
, wxMenu* pMenu
, const wxString& rTitle
)
{
SHORT nId;
wxString sTitle = wxPMTextToLabel(rTitle);
wxMenu* pMenuOld = wxMenuBarBase::Replace( nPos
,pMenu
,sTitle
);
nId = SHORT1FROMMR(::WinSendMsg((HWND)m_hMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT(nPos), (MPARAM)0));
if (nId == MIT_ERROR)
{
wxLogLastError(wxT("LogLastError"));
return NULL;
}
if (!pMenuOld)
return NULL;
m_titles[nPos] = sTitle;
if (IsAttached())
{
::WinSendMsg((HWND)m_hMenu, MM_REMOVEITEM, MPFROM2SHORT(nId, TRUE), (MPARAM)0);
::WinSendMsg((HWND)m_hMenu, MM_INSERTITEM, (MPARAM)&pMenu->m_vMenuData, (MPARAM)sTitle.wx_str());
#if wxUSE_ACCEL
if (pMenuOld->HasAccels() || pMenu->HasAccels())
{
//
// Need to rebuild accell table
//
RebuildAccelTable();
}
#endif // wxUSE_ACCEL
Refresh();
}
return pMenuOld;
} // end of wxMenuBar::Replace
bool wxMenuBar::Insert( size_t nPos,
wxMenu* pMenu,
const wxString& rTitle )
{
wxString sTitle = wxPMTextToLabel(rTitle);
if (!wxMenuBarBase::Insert( nPos, pMenu, sTitle ))
return false;
m_titles.Insert( sTitle, nPos );
if (IsAttached())
{
pMenu->m_vMenuData.iPosition = (SHORT)nPos;
::WinSendMsg( (HWND)m_hMenu
,MM_INSERTITEM
,(MPARAM)&pMenu->m_vMenuData
,(MPARAM)sTitle.wx_str()
);
#if wxUSE_ACCEL
if (pMenu->HasAccels())
{
// need to rebuild accell table
RebuildAccelTable();
}
#endif // wxUSE_ACCEL
Refresh();
}
return true;
} // end of wxMenuBar::Insert
bool wxMenuBar::Append( wxMenu* pMenu,
const wxString& rsTitle )
{
WXHMENU hSubmenu = pMenu ? pMenu->GetHMenu() : 0;
wxCHECK_MSG(hSubmenu, false, wxT("can't append invalid menu to menubar"));
wxString sTitle = wxPMTextToLabel(rsTitle);
if (!wxMenuBarBase::Append(pMenu, sTitle))
return false;
m_titles.Add(sTitle);
if ( IsAttached() )
{
pMenu->m_vMenuData.iPosition = MIT_END;
::WinSendMsg((HWND)m_hMenu, MM_INSERTITEM, (MPARAM)&pMenu->m_vMenuData, (MPARAM)sTitle.wx_str());
#if wxUSE_ACCEL
if (pMenu->HasAccels())
{
//
// Need to rebuild accell table
//
RebuildAccelTable();