Menu_Popup_ToBeChecked,
Menu_Popup_Submenu,
+ Menu_PopupChoice,
+
Menu_Max
};
// main frame
bool MyApp::OnInit()
{
+ if ( !wxApp::OnInit() )
+ return false;
+
// Create the main frame window
MyFrame* frame = new MyFrame;
wxTE_MULTILINE);
m_textctrl->SetEditable(false);
- wxLog::SetTimestamp(NULL);
+ wxLog::DisableTimestamp();
m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_textctrl));
wxLogMessage(_T("Brief explanations: the commands or the \"Menu\" menu ")
wxCHECK_RET( count, _T("no last menu?") );
wxLogMessage(_T("The label of the last menu item is '%s'"),
- mbar->GetLabelTop(count - 1).c_str());
+ mbar->GetMenuLabel(count - 1).c_str());
}
#if wxUSE_TEXTDLG
(
_T("Enter new label: "),
_T("Change last menu text"),
- mbar->GetLabelTop(count - 1),
+ mbar->GetMenuLabel(count - 1),
this
);
if ( !label.empty() )
{
- mbar->SetLabelTop(count - 1, label);
+ mbar->SetMenuLabel(count - 1, label);
}
}
if ( item )
{
+ wxString label = item->GetItemLabel();
wxLogMessage(_T("The label of the last menu item is '%s'"),
- item->GetLabel().c_str());
+ label.c_str());
}
}
(
_T("Enter new label: "),
_T("Change last menu item text"),
- item->GetLabel(),
+ item->GetItemLabel(),
this
);
label.Replace( _T("\\t"), _T("\t") );
if ( !label.empty() )
{
- item->SetText(label);
+ item->SetItemLabel(label);
}
}
}
{
wxMenu menu;
- menu.Append(Menu_Help_About, _T("&About"));
- menu.Append(Menu_Popup_Submenu, _T("&Submenu"), CreateDummyMenu(NULL));
- menu.Append(Menu_Popup_ToBeDeleted, _T("To be &deleted"));
- menu.AppendCheckItem(Menu_Popup_ToBeChecked, _T("To be &checked"));
- menu.Append(Menu_Popup_ToBeGreyed, _T("To be &greyed"),
- _T("This menu item should be initially greyed out"));
- menu.AppendSeparator();
- menu.Append(Menu_File_Quit, _T("E&xit"));
-
- menu.Delete(Menu_Popup_ToBeDeleted);
- menu.Check(Menu_Popup_ToBeChecked, true);
- menu.Enable(Menu_Popup_ToBeGreyed, false);
-
- PopupMenu(&menu, pos.x, pos.y);
-
- // test for destroying items in popup menus
+ if ( wxGetKeyState(WXK_SHIFT) )
+ {
+ // when Shift is pressed, demonstrate the use of a simple function
+ // returning the id of the item selected in the popup menu
+ menu.SetTitle("Choose one of:");
+ static const char *choices[] = { "Apple", "Banana", "Cherry" };
+ for ( size_t n = 0; n < WXSIZEOF(choices); n++ )
+ menu.Append(Menu_PopupChoice + n, choices[n]);
+
+ const int rc = GetPopupMenuSelectionFromUser(menu, pos);
+ if ( rc == wxID_NONE )
+ {
+ wxLogMessage("No selection");
+ }
+ else
+ {
+ wxLogMessage("You have selected \"%s\"",
+ choices[rc - Menu_PopupChoice]);
+ }
+ }
+ else // normal case, shift not pressed
+ {
+ menu.Append(Menu_Help_About, _T("&About"));
+ menu.Append(Menu_Popup_Submenu, _T("&Submenu"), CreateDummyMenu(NULL));
+ menu.Append(Menu_Popup_ToBeDeleted, _T("To be &deleted"));
+ menu.AppendCheckItem(Menu_Popup_ToBeChecked, _T("To be &checked"));
+ menu.Append(Menu_Popup_ToBeGreyed, _T("To be &greyed"),
+ _T("This menu item should be initially greyed out"));
+ menu.AppendSeparator();
+ menu.Append(Menu_File_Quit, _T("E&xit"));
+
+ menu.Delete(Menu_Popup_ToBeDeleted);
+ menu.Check(Menu_Popup_ToBeChecked, true);
+ menu.Enable(Menu_Popup_ToBeGreyed, false);
+
+ PopupMenu(&menu, pos);
+
+ // test for destroying items in popup menus
#if 0 // doesn't work in wxGTK!
- menu.Destroy(Menu_Popup_Submenu);
+ menu.Destroy(Menu_Popup_Submenu);
- PopupMenu( &menu, event.GetX(), event.GetY() );
+ PopupMenu( &menu, event.GetX(), event.GetY() );
#endif // 0
+ }
}
void MyFrame::OnTestNormal(wxCommandEvent& WXUNUSED(event))