Commit f9cf211f authored by twanvl's avatar twanvl

Added drop down lists to toolbar buttons for:

 - card rotation
 - add (multiple) cards

Requires patch to wx (or the HEAD branch version), see http://trac.wxwidgets.org/ticket/8556
this appears to be for MSW only.
parent cdaa58e7
...@@ -29,6 +29,12 @@ ...@@ -29,6 +29,12 @@
DECLARE_TYPEOF_COLLECTION(AddCardsScriptP); DECLARE_TYPEOF_COLLECTION(AddCardsScriptP);
#ifdef EVT_TOOL_DROPDOWN
// This is only available after patching wx or in version 2.10
// see http://trac.wxwidgets.org/ticket/8556
#define HAVE_TOOLBAR_DROPDOWN_MENU 1
#endif
// ----------------------------------------------------------------------------- : CardsPanel // ----------------------------------------------------------------------------- : CardsPanel
CardsPanel::CardsPanel(Window* parent, int id) CardsPanel::CardsPanel(Window* parent, int id)
...@@ -98,6 +104,8 @@ CardsPanel::CardsPanel(Window* parent, int id) ...@@ -98,6 +104,8 @@ CardsPanel::CardsPanel(Window* parent, int id)
menuFormat->AppendSeparator(); menuFormat->AppendSeparator();
insertSymbolMenu = new wxMenuItem(menuFormat, ID_INSERT_SYMBOL, _MENU_("insert symbol")); insertSymbolMenu = new wxMenuItem(menuFormat, ID_INSERT_SYMBOL, _MENU_("insert symbol"));
menuFormat->Append(insertSymbolMenu); menuFormat->Append(insertSymbolMenu);
toolAddCard = nullptr;
} }
void CardsPanel::updateNotesPosition() { void CardsPanel::updateNotesPosition() {
...@@ -147,20 +155,35 @@ void CardsPanel::onChangeSet() { ...@@ -147,20 +155,35 @@ void CardsPanel::onChangeSet() {
// change insertManyCardsMenu // change insertManyCardsMenu
delete insertManyCardsMenu->GetSubMenu(); delete insertManyCardsMenu->GetSubMenu();
if (!set->game->add_cards_scripts.empty()) { insertManyCardsMenu->SetSubMenu(makeAddCardsSubmenu(false));
// create menu for add_cards_scripts // re-add the menu
menuCard->Remove(ID_CARD_ADD_MULT);
((wxMenu*)menuCard)->Insert(4,insertManyCardsMenu); // HACK: the position is hardcoded
// also for the toolbar dropdown menu
#if HAVE_TOOLBAR_DROPDOWN_MENU
if (toolAddCard) {
toolAddCard->SetDropdownMenu(makeAddCardsSubmenu(true));
}
#endif
}
wxMenu* CardsPanel::makeAddCardsSubmenu(bool add_single_card_option) {
IconMenu* cards_scripts_menu = nullptr;
// default item?
if (add_single_card_option) {
cards_scripts_menu = new IconMenu;
cards_scripts_menu->Append(ID_CARD_ADD, _("card_add"), _MENU_("add card"), _HELP_("add card"));
cards_scripts_menu->AppendSeparator();
}
// create menu for add_cards_scripts
if (set && set->game && !set->game->add_cards_scripts.empty()) {
int id = ID_ADD_CARDS_MENU_MIN; int id = ID_ADD_CARDS_MENU_MIN;
IconMenu* cards_scripts_menu = new IconMenu; if (!cards_scripts_menu) cards_scripts_menu = new IconMenu;
FOR_EACH(cs, set->game->add_cards_scripts) { FOR_EACH(cs, set->game->add_cards_scripts) {
cards_scripts_menu->Append(id++, cs->name, cs->description); cards_scripts_menu->Append(id++, cs->name, cs->description);
} }
insertManyCardsMenu->SetSubMenu(cards_scripts_menu);
} else {
insertManyCardsMenu->SetSubMenu(nullptr);
} }
// re-add the menu return cards_scripts_menu;
menuCard->Remove(ID_CARD_ADD_MULT);
((wxMenu*)menuCard)->Insert(4,insertManyCardsMenu); // HACK: the position is hardcoded
} }
// ----------------------------------------------------------------------------- : UI // ----------------------------------------------------------------------------- : UI
...@@ -172,10 +195,25 @@ void CardsPanel::initUI(wxToolBar* tb, wxMenuBar* mb) { ...@@ -172,10 +195,25 @@ void CardsPanel::initUI(wxToolBar* tb, wxMenuBar* mb) {
tb->AddTool(ID_FORMAT_SYMBOL, _(""), load_resource_tool_image(_("symbol")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("symbols"), _HELP_("symbols")); tb->AddTool(ID_FORMAT_SYMBOL, _(""), load_resource_tool_image(_("symbol")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("symbols"), _HELP_("symbols"));
tb->AddTool(ID_FORMAT_REMINDER, _(""), load_resource_tool_image(_("reminder")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("reminder text"), _HELP_("reminder text")); tb->AddTool(ID_FORMAT_REMINDER, _(""), load_resource_tool_image(_("reminder")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("reminder text"), _HELP_("reminder text"));
tb->AddSeparator(); tb->AddSeparator();
tb->AddTool(ID_CARD_ADD, _(""), load_resource_tool_image(_("card_add")), wxNullBitmap, wxITEM_NORMAL,_TOOLTIP_("add card"), _HELP_("add card")); #if HAVE_TOOLBAR_DROPDOWN_MENU
toolAddCard = tb->AddTool(ID_CARD_ADD, _(""), load_resource_tool_image(_("card_add")), wxNullBitmap, wxITEM_DROPDOWN,_TOOLTIP_("add card"), _HELP_("add card"));
toolAddCard->SetDropdownMenu(makeAddCardsSubmenu(true));
#else
tb->AddTool(ID_CARD_ADD, _(""), load_resource_tool_image(_("card_add")), wxNullBitmap, wxITEM_NORMAL,_TOOLTIP_("add card"), _HELP_("add card"));
#endif
tb->AddTool(ID_CARD_REMOVE, _(""), load_resource_tool_image(_("card_del")), wxNullBitmap, wxITEM_NORMAL,_TOOLTIP_("remove card"), _HELP_("remove card")); tb->AddTool(ID_CARD_REMOVE, _(""), load_resource_tool_image(_("card_del")), wxNullBitmap, wxITEM_NORMAL,_TOOLTIP_("remove card"), _HELP_("remove card"));
tb->AddSeparator(); tb->AddSeparator();
tb->AddTool(ID_CARD_ROTATE, _(""), load_resource_tool_image(_("card_rotate")), wxNullBitmap,wxITEM_NORMAL, _TOOLTIP_("rotate card"), _HELP_("rotate card")); #if HAVE_TOOLBAR_DROPDOWN_MENU
wxToolBarToolBase* rot = tb->AddTool(ID_CARD_ROTATE, _(""), load_resource_tool_image(_("card_rotate")), wxNullBitmap, wxITEM_DROPDOWN, _TOOLTIP_("rotate card"), _HELP_("rotate card"));
IconMenu* menuRotate = new IconMenu();
menuRotate->Append(ID_CARD_ROTATE_0, _("card_rotate_0"), _MENU_("rotate 0"), _HELP_("rotate 0"), wxITEM_CHECK);
menuRotate->Append(ID_CARD_ROTATE_270, _("card_rotate_270"), _MENU_("rotate 270"), _HELP_("rotate 270"), wxITEM_CHECK);
menuRotate->Append(ID_CARD_ROTATE_90, _("card_rotate_90"), _MENU_("rotate 90"), _HELP_("rotate 90"), wxITEM_CHECK);
menuRotate->Append(ID_CARD_ROTATE_180, _("card_rotate_180"), _MENU_("rotate 180"), _HELP_("rotate 180"), wxITEM_CHECK);
rot->SetDropdownMenu(menuRotate);
#else
tb->AddTool(ID_CARD_ROTATE, _(""), load_resource_tool_image(_("card_rotate")), wxNullBitmap,wxITEM_NORMAL, _TOOLTIP_("rotate card"), _HELP_("rotate card"));
#endif
//% tb->AddSeparator(); //% tb->AddSeparator();
//% if (!filter) filter = new wxTextCtrl(tb, wxID_ANY, _(""), wxDefaultPosition, wxDefaultSize, wxSTATIC_BORDER); //% if (!filter) filter = new wxTextCtrl(tb, wxID_ANY, _(""), wxDefaultPosition, wxDefaultSize, wxSTATIC_BORDER);
//% tb->AddControl(filter); //% tb->AddControl(filter);
...@@ -202,6 +240,7 @@ void CardsPanel::destroyUI(wxToolBar* tb, wxMenuBar* mb) { ...@@ -202,6 +240,7 @@ void CardsPanel::destroyUI(wxToolBar* tb, wxMenuBar* mb) {
// Menus // Menus
mb->Remove(3); mb->Remove(3);
mb->Remove(2); mb->Remove(2);
toolAddCard = nullptr;
} }
void CardsPanel::onUpdateUI(wxUpdateUIEvent& ev) { void CardsPanel::onUpdateUI(wxUpdateUIEvent& ev) {
......
...@@ -90,8 +90,11 @@ class CardsPanel : public SetWindowPanel { ...@@ -90,8 +90,11 @@ class CardsPanel : public SetWindowPanel {
// --------------------------------------------------- : Menus & tools // --------------------------------------------------- : Menus & tools
IconMenu* menuCard, *menuFormat; IconMenu* menuCard, *menuFormat;
wxToolBarToolBase* toolAddCard;
wxMenuItem* insertSymbolMenu; // owned by menuFormat, but submenu owned by SymbolFont wxMenuItem* insertSymbolMenu; // owned by menuFormat, but submenu owned by SymbolFont
wxMenuItem* insertManyCardsMenu; // owned my menuCard, but submenu can be changed wxMenuItem* insertManyCardsMenu; // owned my menuCard, but submenu can be changed
wxMenu* makeAddCardsSubmenu(bool add_single_card_option);
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -150,3 +150,9 @@ new: ...@@ -150,3 +150,9 @@ new:
// Under MicroWindows we pass the HFONT as well // Under MicroWindows we pass the HFONT as well
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
purpose: Add support for dropdown arrows in wxToolBar
patch: apply http://trac.wxwidgets.org/ticket/8556
should be in 2.10 and HEAD already
// -----------------------------------------------------------------------------
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment