From 1fb3f15aff34cde3d4b7bed844bf3887f63778ee Mon Sep 17 00:00:00 2001 From: Twan van Laarhoven Date: Fri, 1 May 2020 03:26:02 +0200 Subject: [PATCH] Generate image for disabled toolbar buttons and menu items. Fixes #13. Removed IconMenu class, use add_menu_item/add_menu_item_tr instead. Added _tr variants that automatically do locale translation --- resource/{ => tool}/combine_and.png | Bin resource/{ => tool}/combine_and_dark.png | Bin resource/{ => tool}/combine_border.png | Bin resource/{ => tool}/combine_or.png | Bin resource/{ => tool}/combine_over.png | Bin resource/{ => tool}/combine_sub.png | Bin resource/{ => tool}/combine_sub_dark.png | Bin resource/{ => tool}/combine_xor.png | Bin resource/{ => tool}/symbol_group.png | Bin resource/{ => tool}/symmetry_reflection.png | Bin resource/{ => tool}/symmetry_rotation.png | Bin resource/win32_res.rc | 22 ++-- src/gui/control/card_editor.cpp | 10 +- src/gui/control/card_list.cpp | 14 +-- src/gui/control/keyword_list.cpp | 14 +-- src/gui/icon_menu.cpp | 100 ------------------ src/gui/icon_menu.hpp | 36 ------- src/gui/set/cards_panel.cpp | 103 ++++++++----------- src/gui/set/cards_panel.hpp | 3 +- src/gui/set/keywords_panel.cpp | 19 ++-- src/gui/set/keywords_panel.hpp | 3 +- src/gui/set/set_info_panel.cpp | 23 +++-- src/gui/set/stats_panel.cpp | 23 ++--- src/gui/set/stats_panel.hpp | 3 +- src/gui/set/window.cpp | 107 ++++++++++---------- src/gui/set/window.hpp | 7 +- src/gui/symbol/basic_shape_editor.cpp | 8 +- src/gui/symbol/point_editor.cpp | 10 +- src/gui/symbol/select_editor.cpp | 12 +-- src/gui/symbol/symmetry_editor.cpp | 8 +- src/gui/symbol/window.cpp | 76 +++++++------- src/gui/util.cpp | 74 ++++++++++++-- src/gui/util.hpp | 22 +++- src/gui/value/editor.hpp | 3 +- src/gui/value/text.cpp | 5 +- src/gui/value/text.hpp | 2 +- test/locale/validate_locale.pl | 62 ++++++++---- 37 files changed, 355 insertions(+), 414 deletions(-) rename resource/{ => tool}/combine_and.png (100%) rename resource/{ => tool}/combine_and_dark.png (100%) rename resource/{ => tool}/combine_border.png (100%) rename resource/{ => tool}/combine_or.png (100%) rename resource/{ => tool}/combine_over.png (100%) rename resource/{ => tool}/combine_sub.png (100%) rename resource/{ => tool}/combine_sub_dark.png (100%) rename resource/{ => tool}/combine_xor.png (100%) rename resource/{ => tool}/symbol_group.png (100%) rename resource/{ => tool}/symmetry_reflection.png (100%) rename resource/{ => tool}/symmetry_rotation.png (100%) delete mode 100644 src/gui/icon_menu.cpp delete mode 100644 src/gui/icon_menu.hpp diff --git a/resource/combine_and.png b/resource/tool/combine_and.png similarity index 100% rename from resource/combine_and.png rename to resource/tool/combine_and.png diff --git a/resource/combine_and_dark.png b/resource/tool/combine_and_dark.png similarity index 100% rename from resource/combine_and_dark.png rename to resource/tool/combine_and_dark.png diff --git a/resource/combine_border.png b/resource/tool/combine_border.png similarity index 100% rename from resource/combine_border.png rename to resource/tool/combine_border.png diff --git a/resource/combine_or.png b/resource/tool/combine_or.png similarity index 100% rename from resource/combine_or.png rename to resource/tool/combine_or.png diff --git a/resource/combine_over.png b/resource/tool/combine_over.png similarity index 100% rename from resource/combine_over.png rename to resource/tool/combine_over.png diff --git a/resource/combine_sub.png b/resource/tool/combine_sub.png similarity index 100% rename from resource/combine_sub.png rename to resource/tool/combine_sub.png diff --git a/resource/combine_sub_dark.png b/resource/tool/combine_sub_dark.png similarity index 100% rename from resource/combine_sub_dark.png rename to resource/tool/combine_sub_dark.png diff --git a/resource/combine_xor.png b/resource/tool/combine_xor.png similarity index 100% rename from resource/combine_xor.png rename to resource/tool/combine_xor.png diff --git a/resource/symbol_group.png b/resource/tool/symbol_group.png similarity index 100% rename from resource/symbol_group.png rename to resource/tool/symbol_group.png diff --git a/resource/symmetry_reflection.png b/resource/tool/symmetry_reflection.png similarity index 100% rename from resource/symmetry_reflection.png rename to resource/tool/symmetry_reflection.png diff --git a/resource/symmetry_rotation.png b/resource/tool/symmetry_rotation.png similarity index 100% rename from resource/symmetry_rotation.png rename to resource/tool/symmetry_rotation.png diff --git a/resource/win32_res.rc b/resource/win32_res.rc index 4050ec75..2b2ef99b 100644 --- a/resource/win32_res.rc +++ b/resource/win32_res.rc @@ -107,17 +107,17 @@ tool/ungroup IMAGE "tool/ungroup.png" tool/symmetry_add IMAGE "tool/symmetry_add.png" tool/symmetry_remove IMAGE "tool/symmetry_remove.png" -combine_or IMAGE "combine_or.png" -combine_sub IMAGE "combine_sub.png" -combine_sub_dark IMAGE "combine_sub_dark.png" -combine_and IMAGE "combine_and.png" -combine_and_dark IMAGE "combine_and_dark.png" -combine_xor IMAGE "combine_xor.png" -combine_over IMAGE "combine_over.png" -combine_border IMAGE "combine_border.png" -symmetry_rotation IMAGE "symmetry_rotation.png" -symmetry_reflection IMAGE "symmetry_reflection.png" -symbol_group IMAGE "symbol_group.png" +tool/combine_or IMAGE "tool/combine_or.png" +tool/combine_sub IMAGE "tool/combine_sub.png" +tool/combine_sub_dark IMAGE "tool/combine_sub_dark.png" +tool/combine_and IMAGE "tool/combine_and.png" +tool/combine_and_dark IMAGE "tool/combine_and_dark.png" +tool/combine_xor IMAGE "tool/combine_xor.png" +tool/combine_over IMAGE "tool/combine_over.png" +tool/combine_border IMAGE "tool/combine_border.png" +tool/symmetry_rotation IMAGE "tool/symmetry_rotation.png" +tool/symmetry_reflection IMAGE "tool/symmetry_reflection.png" +tool/symbol_group IMAGE "tool/symbol_group.png" icon_combine_merge IMAGE "icon_combine_merge.png" icon_combine_subtract IMAGE "icon_combine_subtract.png" diff --git a/src/gui/control/card_editor.cpp b/src/gui/control/card_editor.cpp index 2a9c7d5e..1d0b95c6 100644 --- a/src/gui/control/card_editor.cpp +++ b/src/gui/control/card_editor.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include @@ -424,10 +424,10 @@ void DataEditor::onChar(wxKeyEvent& ev) { void DataEditor::onContextMenu(wxContextMenuEvent& ev) { if (current_editor) { - IconMenu m; - m.Append(ID_EDIT_CUT, _("cut"), _MENU_("cut"), _HELP_("cut")); - m.Append(ID_EDIT_COPY, _("copy"), _MENU_("copy"), _HELP_("copy")); - m.Append(ID_EDIT_PASTE, _("paste"), _MENU_("paste"), _HELP_("paste")); + wxMenu m; + add_menu_item_tr(&m, ID_EDIT_CUT, "cut", "cut"); + add_menu_item_tr(&m, ID_EDIT_COPY, "copy", "copy"); + add_menu_item_tr(&m, ID_EDIT_PASTE, "paste", "paste"); m.Enable(ID_EDIT_CUT, canCut()); m.Enable(ID_EDIT_COPY, canCopy()); m.Enable(ID_EDIT_PASTE, canPaste()); diff --git a/src/gui/control/card_list.cpp b/src/gui/control/card_list.cpp index 37d34073..704dbb73 100644 --- a/src/gui/control/card_list.cpp +++ b/src/gui/control/card_list.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include @@ -382,13 +382,13 @@ void CardListBase::onDrag(wxMouseEvent& ev) { void CardListBase::onContextMenu(wxContextMenuEvent&) { if (allowModify()) { - IconMenu m; - m.Append(wxID_CUT, _("cut"), _CONTEXT_MENU_("cut"), _HELP_("cut card")); - m.Append(wxID_COPY, _("copy"), _CONTEXT_MENU_("copy"), _HELP_("copy card")); - m.Append(wxID_PASTE, _("paste"), _CONTEXT_MENU_("paste"), _HELP_("paste card")); + wxMenu m; + add_menu_item_tr(&m, wxID_CUT, "cut", "cut_card"); + add_menu_item_tr(&m, wxID_COPY, "copy", "copy_card"); + add_menu_item_tr(&m, wxID_PASTE, "paste", "paste_card"); m.AppendSeparator(); - m.Append(ID_CARD_ADD, _("card_add"), _CONTEXT_MENU_("add card"), _HELP_("add card")); - m.Append(ID_CARD_REMOVE,_("card_del"), _CONTEXT_MENU_("remove card"), _HELP_("remove card")); + add_menu_item_tr(&m, ID_CARD_ADD, "card_add", "add card"); + add_menu_item_tr(&m, ID_CARD_REMOVE, "card_del", "remove card"); PopupMenu(&m); } } diff --git a/src/gui/control/keyword_list.cpp b/src/gui/control/keyword_list.cpp index 2f77ce42..9ed2cbf7 100644 --- a/src/gui/control/keyword_list.cpp +++ b/src/gui/control/keyword_list.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include #include @@ -237,13 +237,13 @@ wxListItemAttr* KeywordList::OnGetItemAttr(long pos) const { // ----------------------------------------------------------------------------- : KeywordList : Context menu void KeywordList::onContextMenu(wxContextMenuEvent&) { - IconMenu m; - m.Append(ID_EDIT_CUT, _("cut"), _CONTEXT_MENU_("cut"), _HELP_("cut keyword")); - m.Append(ID_EDIT_COPY, _("copy"), _CONTEXT_MENU_("copy"), _HELP_("copy keyword")); - m.Append(ID_EDIT_PASTE, _("paste"), _CONTEXT_MENU_("paste"), _HELP_("paste keyword")); + wxMenu m; + add_menu_item_tr(&m, ID_EDIT_CUT, "cut", "cut_keyword"); + add_menu_item_tr(&m, ID_EDIT_COPY, "copy", "copy_keyword"); + add_menu_item_tr(&m, ID_EDIT_PASTE, "paste", "paste_keyword"); m.AppendSeparator(); - m.Append(ID_KEYWORD_ADD, _("keyword_add"), _CONTEXT_MENU_("add keyword"), _HELP_("add keyword")); - m.Append(ID_KEYWORD_REMOVE, _("keyword_del"), _CONTEXT_MENU_("remove keyword"), _HELP_("remove keyword")); + add_menu_item_tr(&m, ID_KEYWORD_ADD, "keyword_add", "add_keyword"); + add_menu_item_tr(&m, ID_KEYWORD_REMOVE, "keyword_del", "remove_keyword"); PopupMenu(&m); } diff --git a/src/gui/icon_menu.cpp b/src/gui/icon_menu.cpp deleted file mode 100644 index d10be0ee..00000000 --- a/src/gui/icon_menu.cpp +++ /dev/null @@ -1,100 +0,0 @@ -//+----------------------------------------------------------------------------+ -//| Description: Magic Set Editor - Program to make Magic (tm) cards | -//| Copyright: (C) Twan van Laarhoven and the other MSE developers | -//| License: GNU General Public License 2 or later (see file COPYING) | -//+----------------------------------------------------------------------------+ - -// ----------------------------------------------------------------------------- : Includes - -#include -#include -#include - -// ----------------------------------------------------------------------------- : generateDisabledImage - -// Generate an image to use for the disabled state of menu items -Image generateDisabledImage(const Image& imgIn) { - // Some system colors - Color trans(1,2,3); // mask color used by bitmaps as 'transparent' - Color light = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT); - Color shadow = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW); - // generate disabled bitmap - Image imgOut(16, 16); - imgOut.SetMaskColour(1,2,3); - Byte *in = imgIn.GetData(), *out = imgOut.GetData(); - // For each pixel... - for (int y = 0 ; y < 16 ; ++y) { - for (int x = 0 ; x < 16 ; ++x) { - // is the pixel mask color or white? - Color in1 = trans, in2 = trans; - if (x<15 && y<15) in1 = Color(in[0], in[1], in[2]); - // and the pixel to the left+up? - if (x>0 && y>0 ) in2 = Color(in[0 - 3*17], in[1 - 3*17], in[2 - 3*17]); - // determine output color - Color col; - if (in1 != trans && in1 != light) col = shadow; - else if (in2 != trans && in2 != light) col = light; - else col = trans; - out[0] = col.Red(); - out[1] = col.Green(); - out[2] = col.Blue(); - in += 3; - out += 3; - } - } - return imgOut; -} - -// ----------------------------------------------------------------------------- : set_menu_item_image - -void set_menu_item_image(wxMenuItem* item, const String& resource) { - // load bitmap - Bitmap bitmap = load_resource_tool_image(resource); - #if defined(__WXMSW__) - // make greyed bitmap - bitmap = bitmap.GetSubBitmap(wxRect(0,0,16,16)); - Image disabledImage = generateDisabledImage(bitmap.ConvertToImage()); - item->SetBitmaps(bitmap, bitmap); - item->SetDisabledBitmap(disabledImage); - #else - // Check items can't have bitmaps :( - if (item->GetKind() == wxITEM_NORMAL) { - item->SetBitmap(bitmap); - } - #endif -} - -// ----------------------------------------------------------------------------- : IconMenu - -void IconMenu::Append(int id, const String& resource, const String& text, const String& help, wxItemKind kind, wxMenu* submenu) { - // create menu, load icon - wxMenuItem* item = new wxMenuItem(this, id, text, help, kind, submenu); - set_menu_item_image(item, resource); - // add to menu - wxMenu::Append(item); -} - -void IconMenu::Append(int id, const String& text, const String& help, wxItemKind kind, wxMenu* submenu) { - wxMenuItem* item = new wxMenuItem (this, id, text, help, kind, submenu); - item->SetBitmap(wxNullBitmap); - wxMenu::Append(item); -} - -void IconMenu::Append(wxMenuItem* item) { - item->SetBitmap(wxNullBitmap); - wxMenu::Append(item); -} - -void IconMenu::Insert(size_t pos, int id, const String& resource, const String& text, const String& help, wxItemKind kind, wxMenu* submenu) { - // create menu, load icon - wxMenuItem* item = new wxMenuItem(this, id, text, help, kind, submenu); - set_menu_item_image(item, resource); - // add to menu - wxMenu::Insert(pos,item); -} - -void IconMenu::Insert(size_t pos, int id, const String& text, const String& help, wxItemKind kind, wxMenu* submenu) { - wxMenuItem* item = new wxMenuItem (this, id, text, help, kind, submenu); - item->SetBitmap(wxNullBitmap); - wxMenu::Insert(pos, item); -} diff --git a/src/gui/icon_menu.hpp b/src/gui/icon_menu.hpp deleted file mode 100644 index 6d8adc07..00000000 --- a/src/gui/icon_menu.hpp +++ /dev/null @@ -1,36 +0,0 @@ -//+----------------------------------------------------------------------------+ -//| Description: Magic Set Editor - Program to make Magic (tm) cards | -//| Copyright: (C) Twan van Laarhoven and the other MSE developers | -//| License: GNU General Public License 2 or later (see file COPYING) | -//+----------------------------------------------------------------------------+ - -#pragma once - -// ----------------------------------------------------------------------------- : Includes - -#include "../util/prec.hpp" - -// ----------------------------------------------------------------------------- : IconMenu - -/// Helper class for menus with icons -/** This class functions just like a normal wxMenu. - * The difference is that Append takes an extra parameter: - * the resource name of the bitmap to use. - * Bitmaps are resized (cut) to 16x16 pixels. - */ -class IconMenu : public wxMenu { - public: - /// Append a menu item, with an image (loaded from a resource) - void Append(int id, const String& resource, const String& text, const String& help, wxItemKind kind = wxITEM_NORMAL, wxMenu* submenu = nullptr); - /// Append a menu item, without an image - void Append(int id, const String& text, const String& help, wxItemKind kind = wxITEM_NORMAL, wxMenu* submenu = nullptr); - /// Append a menu item, without an image - void Append(wxMenuItem* item); - /// Insert a menu item, with an image (loaded from a resource) - void Insert(size_t pos, int id, const String& resource, const String& text, const String& help, wxItemKind kind = wxITEM_NORMAL, wxMenu* submenu = nullptr); - /// Insert a menu item, without an image - void Insert(size_t pos, int id, const String& text, const String& help, wxItemKind kind = wxITEM_NORMAL, wxMenu* submenu = nullptr); -}; - -void set_menu_item_image(wxMenuItem* menuitem, const String& resource); - diff --git a/src/gui/set/cards_panel.cpp b/src/gui/set/cards_panel.cpp index bfa704a5..acbc57a1 100644 --- a/src/gui/set/cards_panel.cpp +++ b/src/gui/set/cards_panel.cpp @@ -14,7 +14,6 @@ #include #include // for HoverButton #include -#include #include #include #include @@ -27,12 +26,6 @@ #include #include -#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(Window* parent, int id) @@ -71,34 +64,32 @@ CardsPanel::CardsPanel(Window* parent, int id) SetSizer(s); // init menus - menuCard = new IconMenu(); - menuCard->Append(ID_CARD_PREV, _MENU_("previous card"), _HELP_("previous card")); - menuCard->Append(ID_CARD_NEXT, _MENU_("next card"), _HELP_("next card")); + menuCard = new wxMenu(); + add_menu_item_tr(menuCard, ID_CARD_PREV, nullptr, "previous card"); + add_menu_item_tr(menuCard, ID_CARD_NEXT, nullptr, "next card"); menuCard->AppendSeparator(); - menuCard->Append(ID_CARD_ADD, _("card_add"), _MENU_("add card"), _HELP_("add card")); - insertManyCardsMenu = new wxMenuItem(menuCard, ID_CARD_ADD_MULT, _MENU_("add cards"), _HELP_("add cards")); - set_menu_item_image(insertManyCardsMenu, _("card_add_multiple")); - ((wxMenu*)menuCard)->Append(insertManyCardsMenu); - // NOTE: space after "Del" prevents wx from making del an accellerator - // otherwise we delete a card when delete is pressed inside the editor - // Adding a space never hurts, please keep it just to be safe. - menuCard->Append(ID_CARD_REMOVE, _("card_del"), _MENU_("remove card")+_(" "),_HELP_("remove card")); + add_menu_item_tr(menuCard, ID_CARD_ADD, "card_add", "add_card"); + insertManyCardsMenu = add_menu_item_tr(menuCard, ID_CARD_ADD_MULT, "card_add_multiple", "add cards"); + // NOTE: space after "Del" prevents wx from making del an accellerator + // otherwise we delete a card when delete is pressed inside the editor + // Adding a space never hurts, please keep it just to be safe. + add_menu_item(menuCard, ID_CARD_REMOVE, "card_del", _MENU_("remove card")+_(" "), _HELP_("remove card")); menuCard->AppendSeparator(); - 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); - menuCard->Append(wxID_ANY, _("card_rotate"), _MENU_("orientation"), _HELP_("orientation"), wxITEM_NORMAL, menuRotate); + auto menuRotate = new wxMenu(); + add_menu_item_tr(menuRotate, ID_CARD_ROTATE_0, "card_rotate_0", "rotate_0", wxITEM_CHECK); + add_menu_item_tr(menuRotate, ID_CARD_ROTATE_270, "card_rotate_270", "rotate_270", wxITEM_CHECK); + add_menu_item_tr(menuRotate, ID_CARD_ROTATE_180, "card_rotate_180", "rotate_180", wxITEM_CHECK); + add_menu_item_tr(menuRotate, ID_CARD_ROTATE_90, "card_rotate_90", "rotate_90", wxITEM_CHECK); + add_menu_item_tr(menuCard, wxID_ANY, "card_rotate", "orientation", wxITEM_NORMAL, menuRotate); menuCard->AppendSeparator(); // This probably belongs in the window menu, but there we can't remove the separator once it is added - menuCard->Append(ID_SELECT_COLUMNS, _MENU_("card list columns"),_HELP_("card list columns")); + add_menu_item_tr(menuCard, ID_SELECT_COLUMNS, nullptr, "card_list_columns"); - menuFormat = new IconMenu(); - menuFormat->Append(ID_FORMAT_BOLD, _("bold"), _MENU_("bold"), _HELP_("bold"), wxITEM_CHECK); - menuFormat->Append(ID_FORMAT_ITALIC, _("italic"), _MENU_("italic"), _HELP_("italic"), wxITEM_CHECK); - menuFormat->Append(ID_FORMAT_SYMBOL, _("symbol"), _MENU_("symbols"), _HELP_("symbols"), wxITEM_CHECK); - menuFormat->Append(ID_FORMAT_REMINDER, _("reminder"), _MENU_("reminder text"), _HELP_("reminder text"), wxITEM_CHECK); + menuFormat = new wxMenu(); + add_menu_item_tr(menuFormat, ID_FORMAT_BOLD, "bold", "bold", wxITEM_CHECK); + add_menu_item_tr(menuFormat, ID_FORMAT_ITALIC, "italic", "italic", wxITEM_CHECK); + add_menu_item_tr(menuFormat, ID_FORMAT_SYMBOL, "symbol", "symbols", wxITEM_CHECK); + add_menu_item_tr(menuFormat, ID_FORMAT_REMINDER, "reminder", "reminder_text", wxITEM_CHECK); menuFormat->AppendSeparator(); insertSymbolMenu = new wxMenuItem(menuFormat, ID_INSERT_SYMBOL, _MENU_("insert symbol")); menuFormat->Append(insertSymbolMenu); @@ -161,25 +152,23 @@ void CardsPanel::onChangeSet() { 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 + if (toolAddCard) { + toolAddCard->SetDropdownMenu(makeAddCardsSubmenu(true)); + } } wxMenu* CardsPanel::makeAddCardsSubmenu(bool add_single_card_option) { - IconMenu* cards_scripts_menu = nullptr; + wxMenu* 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 = new wxMenu(); + add_menu_item_tr(cards_scripts_menu, ID_CARD_ADD, "card_add", "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; - if (!cards_scripts_menu) cards_scripts_menu = new IconMenu; + if (!cards_scripts_menu) cards_scripts_menu = new wxMenu(); FOR_EACH(cs, set->game->add_cards_scripts) { cards_scripts_menu->Append(id++, cs->name, cs->description); } @@ -191,30 +180,22 @@ wxMenu* CardsPanel::makeAddCardsSubmenu(bool add_single_card_option) { void CardsPanel::initUI(wxToolBar* tb, wxMenuBar* mb) { // Toolbar - tb->AddTool(ID_FORMAT_BOLD, _(""), load_resource_tool_image(_("bold")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("bold"), _HELP_("bold")); - tb->AddTool(ID_FORMAT_ITALIC, _(""), load_resource_tool_image(_("italic")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("italic"), _HELP_("italic")); - 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")); + add_tool_tr(tb, ID_FORMAT_BOLD, "bold", "bold", false, wxITEM_CHECK); + add_tool_tr(tb, ID_FORMAT_ITALIC, "italic", "italic", false, wxITEM_CHECK); + add_tool_tr(tb, ID_FORMAT_SYMBOL, "symbol", "symbols", false, wxITEM_CHECK); + add_tool_tr(tb, ID_FORMAT_REMINDER, "reminder", "reminder_text", false, wxITEM_CHECK); tb->AddSeparator(); - #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")); + toolAddCard = add_tool_tr(tb, ID_CARD_ADD, "card_add", "add_card", false, wxITEM_DROPDOWN); + toolAddCard->SetDropdownMenu(makeAddCardsSubmenu(true)); + add_tool_tr(tb, ID_CARD_REMOVE, "card_del", "remove_card"); tb->AddSeparator(); - #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 + wxToolBarToolBase* rot = add_tool_tr(tb, ID_CARD_ROTATE, "card_rotate", "rotate_card", false, wxITEM_DROPDOWN); + auto menuRotate = new wxMenu(); + add_menu_item_tr(menuRotate, ID_CARD_ROTATE_0, "card_rotate_0", "rotate_0", wxITEM_CHECK); + add_menu_item_tr(menuRotate, ID_CARD_ROTATE_270, "card_rotate_270", "rotate_270", wxITEM_CHECK); + add_menu_item_tr(menuRotate, ID_CARD_ROTATE_180, "card_rotate_180", "rotate_180", wxITEM_CHECK); + add_menu_item_tr(menuRotate, ID_CARD_ROTATE_90, "card_rotate_90", "rotate_90", wxITEM_CHECK); + rot->SetDropdownMenu(menuRotate); // Filter/search textbox tb->AddSeparator(); assert(!filter); diff --git a/src/gui/set/cards_panel.hpp b/src/gui/set/cards_panel.hpp index 019d9dcf..7e51cc42 100644 --- a/src/gui/set/cards_panel.hpp +++ b/src/gui/set/cards_panel.hpp @@ -15,7 +15,6 @@ class wxSplitterWindow; class FilteredImageCardList; class DataEditor; class TextCtrl; -class IconMenu; class HoverButton; class FindInfo; class FilterCtrl; @@ -91,7 +90,7 @@ class CardsPanel : public SetWindowPanel { virtual bool Layout(); // --------------------------------------------------- : Menus & tools - IconMenu* menuCard, *menuFormat; + wxMenu* menuCard, *menuFormat; wxToolBarToolBase* toolAddCard; wxMenuItem* insertSymbolMenu; // owned by menuFormat, but submenu owned by SymbolFont wxMenuItem* insertManyCardsMenu; // owned my menuCard, but submenu can be changed diff --git a/src/gui/set/keywords_panel.cpp b/src/gui/set/keywords_panel.cpp index b4a1236f..bcca3a10 100644 --- a/src/gui/set/keywords_panel.cpp +++ b/src/gui/set/keywords_panel.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -102,14 +101,14 @@ void KeywordsPanel::initControls() { s2->Add(list_inactive, 1, wxEXPAND);*/ // init menus - menuKeyword = new IconMenu(); - menuKeyword->Append(ID_KEYWORD_PREV, _MENU_("previous keyword"), _HELP_("previous keyword")); - menuKeyword->Append(ID_KEYWORD_NEXT, _MENU_("next keyword"), _HELP_("next keyword")); + menuKeyword = new wxMenu(); + add_menu_item_tr(menuKeyword, ID_KEYWORD_PREV, nullptr, "previous_keyword"); + add_menu_item_tr(menuKeyword, ID_KEYWORD_NEXT, nullptr, "next_keyword"); menuKeyword->AppendSeparator(); - menuKeyword->Append(ID_KEYWORD_ADD, _("keyword_add"), _MENU_("add keyword"), _HELP_("add keyword")); - // NOTE: space after "Del" prevents wx from making del an accellerator - // otherwise we delete a card when delete is pressed inside the editor - menuKeyword->Append(ID_KEYWORD_REMOVE, _("keyword_del"), _MENU_("remove keyword")+_(" "),_HELP_("remove keyword")); + add_menu_item_tr(menuKeyword, ID_KEYWORD_ADD, "keyword_add", "add_keyword"); + // NOTE: space after "Del" prevents wx from making del an accellerator + // otherwise we delete a card when delete is pressed inside the editor + add_menu_item(menuKeyword, ID_KEYWORD_REMOVE, "keyword_del", _MENU_("remove_keyword")+_(" "), _HELP_("remove_keyword")); } KeywordsPanel::~KeywordsPanel() { @@ -127,8 +126,8 @@ void KeywordsPanel::initUI(wxToolBar* tb, wxMenuBar* mb) { onChangeSet(); } // Toolbar - tb->AddTool(ID_KEYWORD_ADD, _(""), load_resource_tool_image(_("keyword_add")), wxNullBitmap, wxITEM_NORMAL,_TOOLTIP_("add keyword"), _HELP_("add keyword")); - tb->AddTool(ID_KEYWORD_REMOVE, _(""), load_resource_tool_image(_("keyword_del")), wxNullBitmap, wxITEM_NORMAL,_TOOLTIP_("remove keyword"),_HELP_("remove keyword")); + add_tool_tr(tb, ID_KEYWORD_ADD, "keyword_add", "add_keyword"); + add_tool_tr(tb, ID_KEYWORD_REMOVE, "keyword_del", "remove_keyword"); // Filter/search textbox tb->AddSeparator(); assert(!filter); diff --git a/src/gui/set/keywords_panel.hpp b/src/gui/set/keywords_panel.hpp index 1b5e2e98..22b571cc 100644 --- a/src/gui/set/keywords_panel.hpp +++ b/src/gui/set/keywords_panel.hpp @@ -15,7 +15,6 @@ class wxSplitterWindow; class KeywordList; class TextCtrl; -class IconMenu; struct KeywordSelectEvent; class FilterCtrl; @@ -63,7 +62,7 @@ class KeywordsPanel : public SetWindowPanel { TextCtrl* match; TextCtrl* reminder; TextCtrl* rules; - IconMenu* menuKeyword; + wxMenu* menuKeyword; wxStaticText* fixedL; wxSizer* fixed; wxStaticText* errors; diff --git a/src/gui/set/set_info_panel.cpp b/src/gui/set/set_info_panel.cpp index 7abc651b..a391aa26 100644 --- a/src/gui/set/set_info_panel.cpp +++ b/src/gui/set/set_info_panel.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include @@ -35,16 +34,17 @@ void SetInfoPanel::onChangeSet() { void SetInfoPanel::initUI(wxToolBar* tb, wxMenuBar* mb) { // Toolbar - tb->AddTool(ID_FORMAT_BOLD, _(""), load_resource_tool_image(_("bold")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("bold"), _HELP_("bold")); - tb->AddTool(ID_FORMAT_ITALIC, _(""), load_resource_tool_image(_("italic")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("italic"), _HELP_("italic")); - tb->AddTool(ID_FORMAT_SYMBOL, _(""), load_resource_tool_image(_("symbol")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("symbols"), _HELP_("symbols")); + add_tool_tr(tb, ID_FORMAT_BOLD, "bold", "bold", false, wxITEM_CHECK); + add_tool_tr(tb, ID_FORMAT_ITALIC, "italic", "italic", false, wxITEM_CHECK); + add_tool_tr(tb, ID_FORMAT_SYMBOL, "symbol", "symbols", false, wxITEM_CHECK); + add_tool_tr(tb, ID_FORMAT_REMINDER, "reminder", "reminder_text", false, wxITEM_CHECK); tb->Realize(); // Menus - IconMenu* menuFormat = new IconMenu(); - menuFormat->Append(ID_FORMAT_BOLD, _("bold"), _MENU_("bold"), _HELP_("bold"), wxITEM_CHECK); - menuFormat->Append(ID_FORMAT_ITALIC, _("italic"), _MENU_("italic"), _HELP_("italic"), wxITEM_CHECK); - menuFormat->Append(ID_FORMAT_SYMBOL, _("symbol"), _MENU_("symbols"), _HELP_("symbols"), wxITEM_CHECK); - menuFormat->Append(ID_FORMAT_REMINDER, _("reminder"), _MENU_("reminder text"), _HELP_("reminder text"), wxITEM_CHECK); + auto menuFormat = new wxMenu(); + add_menu_item_tr(menuFormat, ID_FORMAT_BOLD, "bold", "bold", wxITEM_CHECK); + add_menu_item_tr(menuFormat, ID_FORMAT_ITALIC, "italic", "italic", wxITEM_CHECK); + add_menu_item_tr(menuFormat, ID_FORMAT_SYMBOL, "symbol", "symbols", wxITEM_CHECK); + add_menu_item_tr(menuFormat, ID_FORMAT_REMINDER, "reminder", "reminder_text", wxITEM_CHECK); mb->Insert(2, menuFormat, _MENU_("format")); // focus on editor editor->SetFocus(); @@ -55,13 +55,14 @@ void SetInfoPanel::destroyUI(wxToolBar* tb, wxMenuBar* mb) { tb->DeleteTool(ID_FORMAT_BOLD); tb->DeleteTool(ID_FORMAT_ITALIC); tb->DeleteTool(ID_FORMAT_SYMBOL); + tb->DeleteTool(ID_FORMAT_REMINDER); // Menus delete mb->Remove(2); } void SetInfoPanel::onUpdateUI(wxUpdateUIEvent& ev) { switch (ev.GetId()) { - case ID_FORMAT_BOLD: case ID_FORMAT_ITALIC: case ID_FORMAT_SYMBOL: { + case ID_FORMAT_BOLD: case ID_FORMAT_ITALIC: case ID_FORMAT_SYMBOL: case ID_FORMAT_REMINDER: { ev.Enable(editor->canFormat(ev.GetId())); ev.Check (editor->hasFormat(ev.GetId())); break; @@ -71,7 +72,7 @@ void SetInfoPanel::onUpdateUI(wxUpdateUIEvent& ev) { void SetInfoPanel::onCommand(int id) { switch (id) { - case ID_FORMAT_BOLD: case ID_FORMAT_ITALIC: case ID_FORMAT_SYMBOL: { + case ID_FORMAT_BOLD: case ID_FORMAT_ITALIC: case ID_FORMAT_SYMBOL: case ID_FORMAT_REMINDER: { editor->doFormat(id); break; } diff --git a/src/gui/set/stats_panel.cpp b/src/gui/set/stats_panel.cpp index 3c3767f9..a75b5d57 100644 --- a/src/gui/set/stats_panel.cpp +++ b/src/gui/set/stats_panel.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -315,12 +314,12 @@ void StatsPanel::initControls() { SetSizer(s); // init menu - menuGraph = new IconMenu(); - menuGraph->Append(ID_GRAPH_PIE, _("graph_pie"), _MENU_("pie"), _HELP_("pie"), wxITEM_CHECK); - menuGraph->Append(ID_GRAPH_BAR, _("graph_bar"), _MENU_("bar"), _HELP_("bar"), wxITEM_CHECK); - menuGraph->Append(ID_GRAPH_STACK, _("graph_stack"), _MENU_("stack"), _HELP_("stack"), wxITEM_CHECK); - menuGraph->Append(ID_GRAPH_SCATTER, _("graph_scatter"), _MENU_("scatter"), _HELP_("scatter"), wxITEM_CHECK); - menuGraph->Append(ID_GRAPH_SCATTER_PIE, _("graph_scatter_pie"), _MENU_("scatter pie"), _HELP_("scatter pie"), wxITEM_CHECK); + menuGraph = new wxMenu(); + add_menu_item_tr(menuGraph, ID_GRAPH_PIE, "graph_pie", "pie", wxITEM_CHECK); + add_menu_item_tr(menuGraph, ID_GRAPH_BAR, "graph_bar", "bar", wxITEM_CHECK); + add_menu_item_tr(menuGraph, ID_GRAPH_STACK, "graph_stack", "stack", wxITEM_CHECK); + add_menu_item_tr(menuGraph, ID_GRAPH_SCATTER, "graph_scatter", "scatter", wxITEM_CHECK); + add_menu_item_tr(menuGraph, ID_GRAPH_SCATTER_PIE, "graph_scatter_pie", "scatter pie", wxITEM_CHECK); } StatsPanel::~StatsPanel() { @@ -364,11 +363,11 @@ void StatsPanel::initUI (wxToolBar* tb, wxMenuBar* mb) { if (!up_to_date) showCategory(); // Toolbar #if USE_DIMENSION_LISTS || USE_SEPARATE_DIMENSION_LISTS - tb->AddTool(ID_GRAPH_PIE, _(""), load_resource_tool_image(_("graph_pie")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("pie"), _HELP_("pie")); - tb->AddTool(ID_GRAPH_BAR, _(""), load_resource_tool_image(_("graph_bar")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("bar"), _HELP_("bar")); - tb->AddTool(ID_GRAPH_STACK, _(""), load_resource_tool_image(_("graph_stack")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("stack"), _HELP_("stack")); - tb->AddTool(ID_GRAPH_SCATTER, _(""), load_resource_tool_image(_("graph_scatter")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("scatter"), _HELP_("scatter")); - tb->AddTool(ID_GRAPH_SCATTER_PIE, _(""), load_resource_tool_image(_("graph_scatter_pie")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("scatter pie"), _HELP_("scatter pie")); + add_tool_tr(tb, ID_GRAPH_PIE, "graph_pie", "pie"); + add_tool_tr(tb, ID_GRAPH_BAR, "graph_bar", "bar"); + add_tool_tr(tb, ID_GRAPH_STACK, "graph_stack", "stack"); + add_tool_tr(tb, ID_GRAPH_SCATTER, "graph_scatter", "scatter"); + add_tool_tr(tb, ID_GRAPH_SCATTER_PIE, "graph_scatter_pie", "scatter_pie"); tb->Realize(); // Menu mb->Insert(2, menuGraph, _MENU_("graph")); diff --git a/src/gui/set/stats_panel.hpp b/src/gui/set/stats_panel.hpp index d60dda31..93a594a4 100644 --- a/src/gui/set/stats_panel.hpp +++ b/src/gui/set/stats_panel.hpp @@ -16,7 +16,6 @@ class StatCategoryList; class StatDimensionList; class GraphControl; class FilteredCardList; -class IconMenu; // Pick the style here: #define USE_DIMENSION_LISTS 1 @@ -57,7 +56,7 @@ class StatsPanel : public SetWindowPanel { #endif GraphControl* graph; FilteredCardList* card_list; - IconMenu* menuGraph; + wxMenu* menuGraph; CardP card; ///< Selected card bool up_to_date; ///< Are the graph and card list up to date? diff --git a/src/gui/set/window.cpp b/src/gui/set/window.cpp index 1517935d..0c3768ac 100644 --- a/src/gui/set/window.cpp +++ b/src/gui/set/window.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -52,57 +51,55 @@ SetWindow::SetWindow(Window* parent, const SetP& set) SetIcon(load_resource_icon(_("app"))); // initialize menu bar - wxMenuBar* menuBar = new wxMenuBar(); - IconMenu* menuFile = new IconMenu(); - menuFile->Append(ID_FILE_NEW, _("new"), _MENU_("new set"), _HELP_("new set")); - menuFile->Append(ID_FILE_OPEN, _("open"), _MENU_("open set"), _HELP_("open set")); - menuFile->Append(ID_FILE_SAVE, _("save"), _MENU_("save set"), _HELP_("save set")); - menuFile->Append(ID_FILE_SAVE_AS, _MENU_("save set as"), _HELP_("save set as")); - IconMenu* menuExport = makeExportMenu(); - menuFile->Append(wxID_ANY, _("export"), _MENU_("export"), _HELP_("export"), wxITEM_NORMAL, menuExport); + auto menuBar = new wxMenuBar(); + auto menuFile = new wxMenu(); + add_menu_item_tr(menuFile, ID_FILE_NEW, "new", "new_set"); + add_menu_item_tr(menuFile, ID_FILE_OPEN, "open", "open_set"); + add_menu_item_tr(menuFile, ID_FILE_SAVE, "save", "save_set"); + add_menu_item_tr(menuFile, ID_FILE_SAVE_AS, nullptr, "save_set_as"); + add_menu_item_tr(menuFile, wxID_ANY, "export", "export", wxITEM_NORMAL, makeExportMenu()); menuFile->AppendSeparator(); - menuFile->Append(ID_FILE_CHECK_UPDATES, _MENU_("check updates"), _HELP_("check updates")); + add_menu_item_tr(menuFile, ID_FILE_CHECK_UPDATES, nullptr, "check_updates"); #if USE_SCRIPT_PROFILING - menuFile->Append(ID_FILE_PROFILER, _MENU_("show profiler"), _HELP_("show profiler")); + add_menu_item_tr(menuFile, ID_FILE_PROFILER, nullptr, "show_profiler"); #endif // menuFile->Append(ID_FILE_INSPECT, _("Inspect Internal Data..."), _("Shows a the data in the set using a tree structure")); // menuFile->AppendSeparator(); - menuFile->Append(ID_FILE_RELOAD, _MENU_("reload data"), _HELP_("reload data")); + add_menu_item_tr(menuFile, ID_FILE_RELOAD, nullptr, "reload_data"); menuFile->AppendSeparator(); - menuFile->Append(ID_FILE_PRINT_PREVIEW, _("print_preview"), _MENU_("print preview"), _HELP_("print preview")); - menuFile->Append(ID_FILE_PRINT, _("print"), _MENU_("print"), _HELP_("print")); + add_menu_item_tr(menuFile, ID_FILE_PRINT_PREVIEW, "print_preview", "print_preview"); + add_menu_item_tr(menuFile, ID_FILE_PRINT, "print", "print"); menuFile->AppendSeparator(); // recent files go here menuFile->AppendSeparator(); - menuFile->Append(ID_FILE_EXIT, _MENU_("exit"), _HELP_("exit")); + add_menu_item_tr(menuFile, ID_FILE_EXIT, nullptr, "exit"); menuBar->Append(menuFile, _MENU_("file")); - IconMenu* menuEdit = new IconMenu(); - menuEdit->Append(ID_EDIT_UNDO, _("undo"), _MENU_1_("undo",wxEmptyString), _HELP_("undo")); - menuEdit->Append(ID_EDIT_REDO, _("redo"), _MENU_1_("redo",wxEmptyString), _HELP_("redo")); + auto menuEdit = new wxMenu(); + add_menu_item(menuEdit, ID_EDIT_UNDO, "undo", _MENU_1_("undo",wxEmptyString), _HELP_("undo")); + add_menu_item(menuEdit, ID_EDIT_REDO, "redo", _MENU_1_("redo",wxEmptyString), _HELP_("redo")); menuEdit->AppendSeparator(); - menuEdit->Append(ID_EDIT_CUT, _("cut"), _MENU_("cut"), _HELP_("cut")); - menuEdit->Append(ID_EDIT_COPY, _("copy"), _MENU_("copy"), _HELP_("copy")); - menuEdit->Append(ID_EDIT_PASTE, _("paste"), _MENU_("paste"), _HELP_("paste")); + add_menu_item_tr(menuEdit, ID_EDIT_CUT, "cut", "cut"); + add_menu_item_tr(menuEdit, ID_EDIT_COPY, "copy", "copy"); + add_menu_item_tr(menuEdit, ID_EDIT_PASTE, "paste", "paste"); menuEdit->AppendSeparator(); - menuEdit->Append(ID_EDIT_FIND, _("find"), _MENU_("find"), _HELP_("find")); - menuEdit->Append(ID_EDIT_FIND_NEXT, _MENU_("find next"), _HELP_("find next")); - menuEdit->Append(ID_EDIT_REPLACE, _MENU_("replace"), _HELP_("replace")); - menuEdit->Append(ID_EDIT_AUTO_REPLACE, _MENU_("auto replace"), _HELP_("auto replace")); + add_menu_item_tr(menuEdit, ID_EDIT_FIND, "find", "find"); + add_menu_item_tr(menuEdit, ID_EDIT_FIND_NEXT, nullptr, "find_next"); + add_menu_item_tr(menuEdit, ID_EDIT_REPLACE, nullptr, "replace"); + add_menu_item_tr(menuEdit, ID_EDIT_AUTO_REPLACE, nullptr, "auto_replace"); menuEdit->AppendSeparator(); - menuEdit->Append(ID_EDIT_PREFERENCES, _MENU_("preferences"), _HELP_("preferences")); + add_menu_item_tr(menuEdit, ID_EDIT_PREFERENCES, nullptr, "preferences"); menuBar->Append(menuEdit, _MENU_("edit")); - IconMenu* menuWindow = new IconMenu(); - menuWindow->Append(ID_WINDOW_NEW, _MENU_("new window"), _HELP_("new window")); + auto menuWindow = new wxMenu(); + add_menu_item_tr(menuWindow, ID_WINDOW_NEW, nullptr, "new_window"); menuWindow->AppendSeparator(); menuBar->Append(menuWindow, _MENU_("window")); - IconMenu* menuHelp = new IconMenu(); - menuHelp->Append(ID_HELP_INDEX, _("help"), _MENU_("index"), _HELP_("index")); - menuHelp->Append(ID_HELP_WEBSITE, _MENU_("website"), _HELP_("website")); - menuHelp->AppendSeparator(); - menuHelp->Append(ID_HELP_ABOUT, _MENU_("about"), _HELP_("about")); + auto menuHelp = new wxMenu(); + add_menu_item_tr(menuHelp, ID_HELP_INDEX, "help", "index"); + add_menu_item_tr(menuHelp, ID_HELP_WEBSITE, nullptr, "website"); + add_menu_item_tr(menuHelp, ID_HELP_ABOUT, nullptr, "about"); menuBar->Append(menuHelp, _MENU_("help")); SetMenuBar(menuBar); @@ -113,24 +110,25 @@ SetWindow::SetWindow(Window* parent, const SetP& set) // tool bar wxToolBar* tb = CreateToolBar(wxTB_FLAT | wxNO_BORDER | wxTB_HORIZONTAL); - tb->SetToolBitmapSize(wxSize(18,18)); - tb->AddTool(ID_FILE_NEW, _(""), load_resource_tool_image(_("new")), wxNullBitmap, wxITEM_NORMAL, _TOOLTIP_("new set"), _HELP_("new set")); - tb->AddTool(ID_FILE_OPEN, _(""), load_resource_tool_image(_("open")), wxNullBitmap, wxITEM_NORMAL, _TOOLTIP_("open set"), _HELP_("open set")); - tb->AddTool(ID_FILE_SAVE, _(""), load_resource_tool_image(_("save")), wxNullBitmap, wxITEM_NORMAL, _TOOLTIP_("save set"), _HELP_("save set")); + tb->SetToolBitmapSize(wxSize(20,20)); + add_tool_tr(tb, ID_FILE_NEW, "new", "new_set"); + add_tool_tr(tb, ID_FILE_OPEN, "open", "open_set"); + add_tool_tr(tb, ID_FILE_SAVE, "save", "save_set"); tb->AddSeparator(); - tb->AddTool(ID_FILE_EXPORT, _(""), load_resource_tool_image(_("export")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("export"), _HELP_("export")); + add_tool_tr(tb, ID_FILE_EXPORT, "export", "export"); tb->AddSeparator(); - tb->AddTool(ID_EDIT_CUT, _(""), load_resource_tool_image(_("cut")), wxNullBitmap, wxITEM_NORMAL, _TOOLTIP_("cut"), _HELP_("cut")); - tb->AddTool(ID_EDIT_COPY, _(""), load_resource_tool_image(_("copy")), wxNullBitmap, wxITEM_NORMAL, _TOOLTIP_("copy"), _HELP_("copy")); - tb->AddTool(ID_EDIT_PASTE, _(""), load_resource_tool_image(_("paste")), wxNullBitmap, wxITEM_NORMAL, _TOOLTIP_("paste"), _HELP_("paste")); + add_tool_tr(tb, ID_EDIT_CUT, "cut", "cut"); + add_tool_tr(tb, ID_EDIT_COPY, "copy", "copy"); + add_tool_tr(tb, ID_EDIT_PASTE, "paste", "paste"); tb->AddSeparator(); - tb->AddTool(ID_EDIT_UNDO, _(""), load_resource_tool_image(_("undo")), wxNullBitmap, wxITEM_NORMAL, _TOOLTIP_1_("undo",wxEmptyString)); - tb->AddTool(ID_EDIT_REDO, _(""), load_resource_tool_image(_("redo")), wxNullBitmap, wxITEM_NORMAL, _TOOLTIP_1_("redo",wxEmptyString)); + add_tool(tb, ID_EDIT_UNDO, "undo", {}, _TOOLTIP_1_("undo", {}), _HELP_("undo")); + add_tool(tb, ID_EDIT_REDO, "redo", {}, _TOOLTIP_1_("redo", {}), _HELP_("redo")); tb->AddSeparator(); tb->Realize(); // tab bar, sizer wxToolBar* tabBar = new wxToolBar(this, ID_TAB_BAR, wxDefaultPosition, wxDefaultSize, wxTB_FLAT | wxNO_BORDER | wxTB_HORIZONTAL | wxTB_HORZ_TEXT | wxTB_NOALIGN); + tabBar->SetToolBitmapSize(wxSize(18,18)); wxSizer* s = new wxBoxSizer(wxVERTICAL); s->Add(tabBar, 0, wxEXPAND | wxBOTTOM, 0); SetSizer(s); @@ -178,13 +176,13 @@ SetWindow::SetWindow(Window* parent, const SetP& set) current_panel->Layout(); } -IconMenu* SetWindow::makeExportMenu() { - IconMenu* menuExport = new IconMenu(); - menuExport->Append(ID_FILE_EXPORT_HTML, _("export_html"), _MENU_("export html"), _HELP_("export html")); - menuExport->Append(ID_FILE_EXPORT_IMAGE, _("export_image"), _MENU_("export image"), _HELP_("export image")); - menuExport->Append(ID_FILE_EXPORT_IMAGES, _("export_images"), _MENU_("export images"), _HELP_("export images")); - menuExport->Append(ID_FILE_EXPORT_APPR, _("export_apprentice"), _MENU_("export apprentice"), _HELP_("export apprentice")); - menuExport->Append(ID_FILE_EXPORT_MWS, _("export_mws"), _MENU_("export mws"), _HELP_("export mws")); +wxMenu* SetWindow::makeExportMenu() { + auto menuExport = new wxMenu(); + add_menu_item_tr(menuExport, ID_FILE_EXPORT_HTML, "export_html", "export_html"); + add_menu_item_tr(menuExport, ID_FILE_EXPORT_IMAGE, "export_image", "export_image"); + add_menu_item_tr(menuExport, ID_FILE_EXPORT_IMAGES, "export_images", "export_images"); + add_menu_item_tr(menuExport, ID_FILE_EXPORT_APPR, "export_apprentice", "export_apprentice"); + add_menu_item_tr(menuExport, ID_FILE_EXPORT_MWS, "export_mws", "export_mws"); return menuExport; } @@ -207,7 +205,7 @@ SetWindow::~SetWindow() { // ----------------------------------------------------------------------------- : Panel managment -void SetWindow::addPanel(IconMenu* windowMenu, wxToolBar* tabBar, SetWindowPanel* panel, UInt pos, const String& image_name, const String& name) { +void SetWindow::addPanel(wxMenu* windowMenu, wxToolBar* tabBar, SetWindowPanel* panel, UInt pos, const String& image_name, const String& name) { // insert in list if (panels.size() <= pos) panels.resize(pos + 1); panels[pos] = panel; @@ -221,7 +219,8 @@ void SetWindow::addPanel(IconMenu* windowMenu, wxToolBar* tabBar, SetWindowPanel tabBar->AddTool(id, tab_name + _(" "), load_resource_tool_image(image_name), wxNullBitmap, wxITEM_CHECK, tab_help, description); tabBar->AddSeparator(); // add to menu bar - windowMenu->Append(id, image_name, menu_name, description, wxITEM_CHECK); + auto menu_item = windowMenu->Append(id, menu_name, description, wxITEM_CHECK); + set_menu_item_image(menu_item, image_name); // add to sizer GetSizer()->Add(panel, 1, wxEXPAND); } @@ -541,8 +540,8 @@ void SetWindow::updateRecentSets() { mb->SetLabel(ID_FILE_RECENT + i, String(_("&")) << (i+1) << _(" ") << file); } else { // add new item - int pos = i + FILE_MENU_SIZE_BEFORE_RECENT_SETS; // HUGE HACK, we should calculate the position to insert! - IconMenu* file_menu = static_cast(mb->GetMenu(0)); + wxMenu* file_menu = mb->GetMenu(0); + size_t pos = file_menu->GetMenuItemCount() - 2; // last two items are separator and exit file_menu->Insert(pos, ID_FILE_RECENT + i, String(_("&")) << (i+1) << _(" ") << file, wxEmptyString); } i++; diff --git a/src/gui/set/window.hpp b/src/gui/set/window.hpp index 80af1fd7..ffe0aaba 100644 --- a/src/gui/set/window.hpp +++ b/src/gui/set/window.hpp @@ -13,7 +13,6 @@ #include #include -class IconMenu; class SetWindowPanel; class wxFindDialogEvent; struct CardSelectEvent; @@ -42,7 +41,7 @@ private: // gui items vector panels; ///< All panels on this window SetWindowPanel* current_panel; - IconMenu* export_menu = nullptr; + wxMenu* export_menu = nullptr; /// Number of items in the recent sets list size_t number_of_recentSets; @@ -56,7 +55,7 @@ private: /// Add a panel to the window, as well as to the menu and tab bar /** The position only determines the order in which events will be send. */ - void addPanel(IconMenu* windowMenu, wxToolBar* tabBar, SetWindowPanel* panel, UInt pos, const String& image_name, const String& name); + void addPanel(wxMenu* windowMenu, wxToolBar* tabBar, SetWindowPanel* panel, UInt pos, const String& image_name, const String& name); /// Select a panel, based on a tab id void selectPanel(int id); @@ -113,7 +112,7 @@ private: UInt number_of_recent_sets; void updateRecentSets(); - IconMenu* makeExportMenu(); + wxMenu* makeExportMenu(); // --------------------------------------------------- : Window events - menu - file void onFileNew (wxCommandEvent&); diff --git a/src/gui/symbol/basic_shape_editor.cpp b/src/gui/symbol/basic_shape_editor.cpp index d61c3934..cac7178b 100644 --- a/src/gui/symbol/basic_shape_editor.cpp +++ b/src/gui/symbol/basic_shape_editor.cpp @@ -42,10 +42,10 @@ void SymbolBasicShapeEditor::initUI(wxToolBar* tb, wxMenuBar* mb) { sides->SetHelpText(_HELP_("sides")); sides->SetSize(50, -1); tb->AddSeparator(); - tb->AddTool(ID_SHAPE_CIRCLE, _TOOL_("ellipse"), load_resource_tool_image(_("circle")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("ellipse"), _HELP_("ellipse")); - tb->AddTool(ID_SHAPE_RECTANGLE, _TOOL_("rectangle"), load_resource_tool_image(_("rectangle")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("rectangle"), _HELP_("rectangle")); - tb->AddTool(ID_SHAPE_POLYGON, _TOOL_("polygon"), load_resource_tool_image(_("triangle")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("polygon"), _HELP_("polygon")); - tb->AddTool(ID_SHAPE_STAR, _TOOL_("star"), load_resource_tool_image(_("star")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("star"), _HELP_("star")); + add_tool_tr(tb, ID_SHAPE_CIRCLE, "circle", "ellipse", true, wxITEM_CHECK); + add_tool_tr(tb, ID_SHAPE_RECTANGLE, "rectangle", "rectangle",true, wxITEM_CHECK); + add_tool_tr(tb, ID_SHAPE_POLYGON, "triangle", "polygon", true, wxITEM_CHECK); + add_tool_tr(tb, ID_SHAPE_STAR, "star", "star", true, wxITEM_CHECK); // tb->AddControl(sidesL); tb->AddControl(sides); tb->Realize(); diff --git a/src/gui/symbol/point_editor.cpp b/src/gui/symbol/point_editor.cpp index 962416dd..2b518141 100644 --- a/src/gui/symbol/point_editor.cpp +++ b/src/gui/symbol/point_editor.cpp @@ -154,12 +154,12 @@ wxPen SymbolPointEditor::handlePen(WhichPen p, LockMode lock) { void SymbolPointEditor::initUI(wxToolBar* tb, wxMenuBar* mb) { // Initialize toolbar tb->AddSeparator(); - tb->AddTool(ID_SEGMENT_LINE, _TOOL_("line segment"), load_resource_tool_image(_("line")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("line segment"), _HELP_("line segment")); - tb->AddTool(ID_SEGMENT_CURVE, _TOOL_("curve segment"), load_resource_tool_image(_("curve")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("curve segment"), _HELP_("curve segment")); + add_tool_tr(tb, ID_SEGMENT_LINE, "line", "line_segment", true, wxITEM_CHECK); + add_tool_tr(tb, ID_SEGMENT_CURVE, "curve", "curve_segment", true, wxITEM_CHECK); tb->AddSeparator(); - tb->AddTool(ID_LOCK_FREE, _TOOL_("free point"), load_resource_tool_image(_("lock_free")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("free point"), _HELP_("free point")); - tb->AddTool(ID_LOCK_DIR, _TOOL_("smooth point"), load_resource_tool_image(_("lock_dir")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("smooth point"), _HELP_("smooth point")); - tb->AddTool(ID_LOCK_SIZE, _TOOL_("symmetric point"), load_resource_tool_image(_("lock_size")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("symmetric point"), _HELP_("symmetric point")); + add_tool_tr(tb, ID_LOCK_FREE, "lock_free", "free_point", true, wxITEM_CHECK); + add_tool_tr(tb, ID_LOCK_DIR, "lock_dir", "smooth_point", true, wxITEM_CHECK); + add_tool_tr(tb, ID_LOCK_SIZE, "lock_size", "symmetric point", true, wxITEM_CHECK); tb->Realize(); // TODO : menu bar //mb->Insert(2, curveMenu, _("&Curve")) diff --git a/src/gui/symbol/select_editor.cpp b/src/gui/symbol/select_editor.cpp index 8e603b9a..44cb1e41 100644 --- a/src/gui/symbol/select_editor.cpp +++ b/src/gui/symbol/select_editor.cpp @@ -116,12 +116,12 @@ void SymbolSelectEditor::drawRotationCenter(DC& dc, const Vector2D& pos) { void SymbolSelectEditor::initUI(wxToolBar* tb, wxMenuBar* mb) { tb->AddSeparator(); - tb->AddTool(ID_SYMBOL_COMBINE_MERGE, _TOOL_("merge"), load_resource_image(_("combine_or")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("merge"), _HELP_("merge")); - tb->AddTool(ID_SYMBOL_COMBINE_SUBTRACT, _TOOL_("subtract"), load_resource_image(_("combine_sub_dark")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("subtract"), _HELP_("subtract")); - tb->AddTool(ID_SYMBOL_COMBINE_INTERSECTION, _TOOL_("intersect"), load_resource_image(_("combine_and_dark")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("intersect"), _HELP_("intersect")); - tb->AddTool(ID_SYMBOL_COMBINE_DIFFERENCE, _TOOL_("difference"), load_resource_image(_("combine_xor")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("difference"), _HELP_("difference")); - tb->AddTool(ID_SYMBOL_COMBINE_OVERLAP, _TOOL_("overlap"), load_resource_image(_("combine_over")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("overlap"), _HELP_("overlap")); - tb->AddTool(ID_SYMBOL_COMBINE_BORDER, _TOOL_("border"), load_resource_image(_("combine_border")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("border"), _HELP_("border")); + add_tool_tr(tb, ID_SYMBOL_COMBINE_MERGE, "combine_or", "merge", true, wxITEM_CHECK); + add_tool_tr(tb, ID_SYMBOL_COMBINE_SUBTRACT, "combine_sub_dark", "subtract", true, wxITEM_CHECK); + add_tool_tr(tb, ID_SYMBOL_COMBINE_INTERSECTION, "combine_and_dark", "intersect", true, wxITEM_CHECK); + add_tool_tr(tb, ID_SYMBOL_COMBINE_DIFFERENCE, "combine_xor", "difference", true, wxITEM_CHECK); + add_tool_tr(tb, ID_SYMBOL_COMBINE_OVERLAP, "combine_over", "overlap", true, wxITEM_CHECK); + add_tool_tr(tb, ID_SYMBOL_COMBINE_BORDER, "combine_border", "border", true, wxITEM_CHECK); tb->Realize(); } void SymbolSelectEditor::destroyUI(wxToolBar* tb, wxMenuBar* mb) { diff --git a/src/gui/symbol/symmetry_editor.cpp b/src/gui/symbol/symmetry_editor.cpp index 04b588ee..12ed814f 100644 --- a/src/gui/symbol/symmetry_editor.cpp +++ b/src/gui/symbol/symmetry_editor.cpp @@ -58,11 +58,11 @@ void SymbolSymmetryEditor::initUI(wxToolBar* tb, wxMenuBar* mb) { copies->SetHelpText(_HELP_("copies")); copies->SetSize(50, -1); tb->AddSeparator(); - tb->AddTool(ID_ADD_SYMMETRY, _TOOL_("add symmetry"), load_resource_tool_image(_("symmetry_add")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("add symmetry"), _HELP_("add symmetry")); - tb->AddTool(ID_REMOVE_SYMMETRY, _TOOL_("remove symmetry"), load_resource_tool_image(_("symmetry_remove")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("remove symmetry"), _HELP_("remove symmetry")); + add_tool_tr(tb, ID_ADD_SYMMETRY, "symmetry_add", "add_symmetry", true, wxITEM_CHECK); + add_tool_tr(tb, ID_REMOVE_SYMMETRY, "symmetry_remove", "remove_symmetry", true, wxITEM_CHECK); tb->AddSeparator(); - tb->AddTool(ID_SYMMETRY_ROTATION, _TOOL_("rotation"), load_resource_image(_("symmetry_rotation")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("rotation"), _HELP_("rotation")); - tb->AddTool(ID_SYMMETRY_REFLECTION, _TOOL_("reflection"), load_resource_image(_("symmetry_reflection")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("reflection"), _HELP_("reflection")); + add_tool_tr(tb, ID_SYMMETRY_ROTATION, "symmetry_rotation", "rotation", true, wxITEM_CHECK); + add_tool_tr(tb, ID_SYMMETRY_REFLECTION, "symmetry_reflection", "reflection", true, wxITEM_CHECK); tb->AddSeparator(); tb->AddControl(copies); tb->Realize(); diff --git a/src/gui/symbol/window.cpp b/src/gui/symbol/window.cpp index 68d42683..23a0a6a5 100644 --- a/src/gui/symbol/window.cpp +++ b/src/gui/symbol/window.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -71,35 +70,35 @@ void SymbolWindow::init(Window* parent, SymbolP symbol) { inSelectionEvent = false; // Menu bar - wxMenuBar* menuBar = new wxMenuBar(); - IconMenu* menuFile = new IconMenu(); - menuFile->Append(ID_FILE_NEW, _("new"), _MENU_("new symbol"), _HELP_("new symbol")); - menuFile->Append(ID_FILE_OPEN, _("open"), _MENU_("open symbol"), _HELP_("open symbol")); - menuFile->Append(ID_FILE_SAVE, _("save"), _MENU_("save symbol"), _HELP_("save symbol")); - menuFile->Append(ID_FILE_SAVE_AS, _MENU_("save symbol as"), _HELP_("save symbol as")); + auto menuBar = new wxMenuBar(); + auto menuFile = new wxMenu(); + add_menu_item_tr(menuFile, ID_FILE_NEW, "new", "new_symbol"); + add_menu_item_tr(menuFile, ID_FILE_OPEN, "open", "open_symbol"); + add_menu_item_tr(menuFile, ID_FILE_SAVE, "save", "save_symbol"); + add_menu_item_tr(menuFile, ID_FILE_SAVE_AS, nullptr, "save_symbol_as"); menuFile->AppendSeparator(); - menuFile->Append(ID_FILE_STORE, _("apply"), _MENU_("store symbol"), _HELP_("store symbol")); + add_menu_item_tr(menuFile, ID_FILE_STORE, "apply", "store_symbol"); menuFile->AppendSeparator(); - menuFile->Append(ID_FILE_EXIT, _MENU_("close symbol editor"), _HELP_("close symbol editor")); + add_menu_item_tr(menuFile, ID_FILE_EXIT, nullptr, "close_symbol_editor"); menuBar->Append(menuFile, _MENU_("file")); - IconMenu* menuEdit = new IconMenu(); - menuEdit->Append(ID_EDIT_UNDO, _("undo"), _MENU_1_("undo",wxEmptyString), _HELP_("undo")); - menuEdit->Append(ID_EDIT_REDO, _("redo"), _MENU_1_("redo",wxEmptyString), _HELP_("redo")); + auto menuEdit = new wxMenu(); + add_menu_item(menuEdit, ID_EDIT_UNDO, "undo", _MENU_1_("undo",wxEmptyString), _HELP_("undo")); + add_menu_item(menuEdit, ID_EDIT_REDO, "redo", _MENU_1_("redo",wxEmptyString), _HELP_("redo")); menuEdit->AppendSeparator(); - menuEdit->Append(ID_EDIT_GROUP, _("group"), _MENU_("group"), _HELP_("group")); - menuEdit->Append(ID_EDIT_UNGROUP, _("ungroup"), _MENU_("ungroup"), _HELP_("ungroup")); + add_menu_item_tr(menuEdit, ID_EDIT_GROUP, "group", "group"); + add_menu_item_tr(menuEdit, ID_EDIT_UNGROUP, "ungroup", "ungroup"); menuEdit->AppendSeparator(); - menuEdit->Append(ID_EDIT_DUPLICATE, _("duplicate"), _MENU_("duplicate"), _HELP_("duplicate")); + add_menu_item_tr(menuEdit, ID_EDIT_DUPLICATE, "duplicate", "duplicate"); menuBar->Append(menuEdit, _MENU_("edit")); - IconMenu* menuTool = new IconMenu(); - menuTool->Append(ID_MODE_SELECT, _("mode_select"), _MENU_("select"), _HELP_("select"), wxITEM_CHECK); - menuTool->Append(ID_MODE_ROTATE, _("mode_rotate"), _MENU_("rotate"), _HELP_("rotate"), wxITEM_CHECK); - menuTool->Append(ID_MODE_POINTS, _("mode_curve"), _MENU_("points"), _HELP_("points"), wxITEM_CHECK); - menuTool->Append(ID_MODE_SHAPES, _("circle"), _MENU_("basic shapes"), _HELP_("basic shapes"), wxITEM_CHECK); - menuTool->Append(ID_MODE_SYMMETRY, _("mode_symmetry"), _MENU_("symmetry"), _HELP_("symmetry"), wxITEM_CHECK); - menuTool->Append(ID_MODE_PAINT, _("mode_paint"), _MENU_("paint"), _HELP_("paint"), wxITEM_CHECK); + auto menuTool = new wxMenu(); + add_menu_item_tr(menuTool, ID_MODE_SELECT, "mode_select", "select", wxITEM_CHECK); + add_menu_item_tr(menuTool, ID_MODE_ROTATE, "mode_rotate", "rotate", wxITEM_CHECK); + add_menu_item_tr(menuTool, ID_MODE_POINTS, "mode_curve", "points", wxITEM_CHECK); + add_menu_item_tr(menuTool, ID_MODE_SHAPES, "circle", "basic_shapes", wxITEM_CHECK); + add_menu_item_tr(menuTool, ID_MODE_SYMMETRY, "mode_symmetry", "symmetry", wxITEM_CHECK); + add_menu_item_tr(menuTool, ID_MODE_PAINT, "mode_paint", "paint", wxITEM_CHECK); menuBar->Append(menuTool, _MENU_("tool")); SetMenuBar(menuBar); @@ -110,27 +109,27 @@ void SymbolWindow::init(Window* parent, SymbolP symbol) { // Toolbar wxToolBar* tb = CreateToolBar(wxTB_FLAT | wxNO_BORDER | wxTB_HORIZONTAL | wxTB_TEXT); - tb->AddTool(ID_FILE_STORE, _TOOL_("store symbol"), load_resource_tool_image(_("apply")), wxNullBitmap, wxITEM_NORMAL, _TOOLTIP_("store symbol"), _HELP_("store symbol")); + add_tool_tr(tb, ID_FILE_STORE, "apply", "store_symbol", true); tb->AddSeparator(); - tb->AddTool(ID_EDIT_UNDO, _TOOL_("undo"), load_resource_tool_image(_("undo")), wxNullBitmap, wxITEM_NORMAL, _TOOLTIP_1_("undo",wxEmptyString)); - tb->AddTool(ID_EDIT_REDO, _TOOL_("redo"), load_resource_tool_image(_("redo")), wxNullBitmap, wxITEM_NORMAL, _TOOLTIP_1_("redo",wxEmptyString)); + add_tool(tb, ID_EDIT_UNDO, "undo", _TOOL_("undo"), _TOOLTIP_1_("undo",wxEmptyString), _HELP_("undo")); + add_tool(tb, ID_EDIT_REDO, "redo", _TOOL_("redo"), _TOOLTIP_1_("redo",wxEmptyString), _HELP_("redo")); tb->AddSeparator(); - tb->AddTool(ID_VIEW_GRID, _TOOL_("grid"), load_resource_tool_image(_("grid")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("grid"), _HELP_("grid")); - tb->AddTool(ID_VIEW_GRID_SNAP, _TOOL_("snap"), load_resource_tool_image(_("grid_snap")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("snap"), _HELP_("snap")); + add_tool_tr(tb, ID_VIEW_GRID, "grid", "grid", true, wxITEM_CHECK); + add_tool_tr(tb, ID_VIEW_GRID_SNAP, "grid_snap", "snap", true, wxITEM_CHECK); tb->Realize(); // Edit mode toolbar wxPanel* emp = new wxPanel(this, wxID_ANY); wxToolBar* em = new wxToolBar(emp, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_FLAT | wxTB_VERTICAL | wxTB_HORZ_TEXT); em->SetToolBitmapSize(wxSize(17,17)); - em->AddTool(ID_MODE_SELECT, _TOOL_("select"), load_resource_tool_image(_("mode_select")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("select"), _HELP_("select")); - em->AddTool(ID_MODE_ROTATE, _TOOL_("rotate"), load_resource_tool_image(_("mode_rotate")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("rotate"), _HELP_("rotate")); + add_tool_tr(em, ID_MODE_SELECT, "mode_select", "select", true, wxITEM_CHECK); + add_tool_tr(em, ID_MODE_ROTATE, "mode_rotate", "rotate", true, wxITEM_CHECK); em->AddSeparator(); - em->AddTool(ID_MODE_POINTS, _TOOL_("points"), load_resource_tool_image(_("mode_curve")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("points"), _HELP_("points")); + add_tool_tr(em, ID_MODE_POINTS, "mode_curve", "points", true, wxITEM_CHECK); em->AddSeparator(); - em->AddTool(ID_MODE_SHAPES, _TOOL_("basic shapes"), load_resource_tool_image(_("circle")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("basic shapes"), _HELP_("basic shapes")); - em->AddTool(ID_MODE_SYMMETRY, _TOOL_("symmetry"), load_resource_tool_image(_("mode_symmetry")),wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("symmetry"), _HELP_("symmetry")); - //em->AddTool(ID_MODE_PAINT, _TOOL_("paint"), load_resource_tool_image(_("mode_paint")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("paint"), _HELP_("paint")); + add_tool_tr(em, ID_MODE_SHAPES, "circle", "basic shapes", true, wxITEM_CHECK); + add_tool_tr(em, ID_MODE_SYMMETRY, "mode_symmetry", "symmetry", true, wxITEM_CHECK); + //add_tool_tr(em, ID_MODE_PAINT, "mode_paint", "paint", true, wxITEM_CHECK); em->Realize(); // Lay out @@ -177,14 +176,13 @@ void SymbolWindow::init(Window* parent, SymbolP symbol) { em = new wxToolBar(emp, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_FLAT | wxTB_VERTICAL | wxTB_HORZ_TEXT); em->SetToolBitmapSize(wxSize(17,17)); String spaces(max(0,n-1), _(' ')); - em->AddTool(ID_MODE_SELECT, _TOOL_("select") + spaces, load_resource_tool_image(_("mode_select")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("select"), _HELP_("select")); - em->AddTool(ID_MODE_ROTATE, _TOOL_("rotate") + spaces, load_resource_tool_image(_("mode_rotate")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("rotate"), _HELP_("rotate")); + add_tool(em, ID_MODE_SELECT, "mode_select", _TOOL_("select") + spaces, _TOOLTIP_("select"), _HELP_("select"), wxITEM_CHECK); + add_tool(em, ID_MODE_ROTATE, "mode_rotate", _TOOL_("rotate") + spaces, _TOOLTIP_("rotate"), _HELP_("rotate"), wxITEM_CHECK); em->AddSeparator(); - em->AddTool(ID_MODE_POINTS, _TOOL_("points") + spaces, load_resource_tool_image(_("mode_curve")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("points"), _HELP_("points")); + add_tool(em, ID_MODE_POINTS, "mode_curve", _TOOL_("points") + spaces, _TOOLTIP_("points"), _HELP_("points"), wxITEM_CHECK); em->AddSeparator(); - em->AddTool(ID_MODE_SHAPES, _TOOL_("basic shapes") + spaces, load_resource_tool_image(_("circle")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("basic shapes"),_HELP_("basic shapes")); - em->AddTool(ID_MODE_SYMMETRY, _TOOL_("symmetry") + spaces, load_resource_tool_image(_("mode_symmetry")),wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("symmetry"), _HELP_("symmetry")); - //em->AddTool(ID_MODE_PAINT, _TOOL_("paint") + spaces, load_resource_tool_image(_("mode_paint")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("paint"), _HELP_("paint")); + add_tool(em, ID_MODE_SHAPES, "circle", _TOOL_("basic shapes") + spaces, _TOOLTIP_("basic shapes"),_HELP_("basic shapes"), wxITEM_CHECK); + add_tool(em, ID_MODE_SYMMETRY, "mode_symmetry", _TOOL_("symmetry") + spaces, _TOOLTIP_("symmetry"), _HELP_("symmetry"), wxITEM_CHECK); em->Realize(); es = new wxBoxSizer(wxVERTICAL); diff --git a/src/gui/util.cpp b/src/gui/util.cpp index d2126208..61eed749 100644 --- a/src/gui/util.cpp +++ b/src/gui/util.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #if wxUSE_UXTHEME && defined(__WXMSW__) #include @@ -131,7 +132,7 @@ void draw_checker(RotatedDC& dc, const RealRect& rect) { } -// ----------------------------------------------------------------------------- : Image related +// ----------------------------------------------------------------------------- : Seekable stream /// A wxInputStream in which we can seek, even if the underlying stream can't /** Seeking is used by the wxImage format detection code, to peek at the header. @@ -214,6 +215,8 @@ private: size_t last_read = 0; }; +// ----------------------------------------------------------------------------- : Image related + bool image_load_file(Image& image, wxInputStream &stream) { wxLogNull noLog; // prevent wx from showing popups about sRGB profiles and other notices if (!stream.IsSeekable()) { @@ -229,6 +232,67 @@ bool image_load_file(Image& image, const wxString &name) { return image.LoadFile(name); } +// ----------------------------------------------------------------------------- : Tool/menu bar + +Image generate_disabled_image(Image const& image) { + Image imgOut = image.ConvertToGreyscale(); + set_alpha(imgOut, 0.33); + return imgOut; +} + +void set_menu_item_image(wxMenuItem* item, const String& resource) { + Image bitmap = load_resource_tool_image(resource); + Image disabled_bitmap = generate_disabled_image(bitmap); + item->SetBitmaps(bitmap, bitmap); + item->SetDisabledBitmap(disabled_bitmap); +} + +wxMenuItem* make_menu_item(wxMenu* menu, int id, const char* resource, const String& text, const String& help, wxItemKind kind, wxMenu* submenu) { + wxMenuItem* item = new wxMenuItem(menu, id, text, help, kind, submenu); + if (resource) set_menu_item_image(item, resource); + return item; +} +wxMenuItem* make_menu_item_tr(wxMenu* menu, int id, const char* resource, const String& locale_key, wxItemKind kind, wxMenu* submenu) { + wxMenuItem* item = new wxMenuItem(menu, id, tr(LOCALE_CAT_MENU, locale_key), tr(LOCALE_CAT_HELP, locale_key), kind, submenu); + if (resource) set_menu_item_image(item, resource); + return item; +} +wxMenuItem* add_menu_item(wxMenu* menu, int id, const char* resource, const String& text, const String& help, wxItemKind kind, wxMenu* submenu) { + wxMenuItem* item = make_menu_item(menu, id, resource, text, help, kind, submenu); + menu->Append(item); + return item; +} +wxMenuItem* add_menu_item_tr(wxMenu* menu, int id, const char* resource, const String& locale_key, wxItemKind kind, wxMenu* submenu) { + wxMenuItem* item = make_menu_item_tr(menu, id, resource, locale_key, kind, submenu); + menu->Append(item); + return item; +} + +wxToolBarToolBase* add_tool(wxToolBar* toolbar, int id, const char* resource, const String& label, const String& tooltip, const String& help, wxItemKind kind) { + if (resource) { + // Note: the bitmap must match the toolbar bitmap size, otherwise disabled and normal bitmap look different + // if the size doesn't match, we center the image + auto size = toolbar->GetToolBitmapSize(); + Image bitmap = load_resource_tool_image(resource); + if (bitmap.GetSize() != size) { + wxPoint pos((size.GetWidth() - bitmap.GetWidth()) / 2, (size.GetHeight() - bitmap.GetHeight()) / 2); + bitmap.Resize(size, pos); + } + Image disabled_bitmap = generate_disabled_image(bitmap); + auto tool = new wxToolBarToolBase(toolbar, id, label, bitmap, disabled_bitmap, kind, nullptr, tooltip, help); + toolbar->AddTool(tool); + return tool; + } else { + auto tool = new wxToolBarToolBase(toolbar, id, label, wxNullBitmap, wxNullBitmap, kind, nullptr, tooltip, help); + toolbar->AddTool(tool); + return tool; + } +} + +wxToolBarToolBase* add_tool_tr(wxToolBar* toolbar, int id, const char* resource, const String& locale_key, bool label, wxItemKind kind) { + return add_tool(toolbar, id, resource, label ? tr(LOCALE_CAT_TOOL,locale_key) : String(), tr(LOCALE_CAT_TOOLTIP, locale_key), tr(LOCALE_CAT_HELP, locale_key), kind); +} + // ----------------------------------------------------------------------------- : Resource related Image load_resource_image(const String& name) { @@ -293,12 +357,8 @@ wxIcon load_resource_icon(const String& name) { #endif } -wxBitmap load_resource_tool_image(const String& name) { - #if defined(__WXMSW__) && !defined(__GNUC__) - return load_resource_image(_("tool/") + name); - #else - return load_resource_image(_("tool/") + name); - #endif +wxImage load_resource_tool_image(const String& name) { + return load_resource_image(_("tool/") + name); } diff --git a/src/gui/util.hpp b/src/gui/util.hpp index 717f2b14..1c38309e 100644 --- a/src/gui/util.hpp +++ b/src/gui/util.hpp @@ -47,6 +47,26 @@ bool image_load_file(Image& image, wxInputStream &stream); /// Proxy around Image.LoadFile that suppresses errors. bool image_load_file(Image& image, const wxString &name); +// ----------------------------------------------------------------------------- : Tool/menu bar + +/// Generate an image to use for the disabled state of menu and toolbar items +Image generate_disabled_image(Image const& image); + +void set_menu_item_image(wxMenuItem* item, const String& resource); + +// menu items with images. +// resource may be nullptr +wxMenuItem* make_menu_item(wxMenu*, int id, const char* resource, const String& text, const String& help, wxItemKind kind = wxITEM_NORMAL, wxMenu* submenu = nullptr); +wxMenuItem* make_menu_item_tr(wxMenu*, int id, const char* resource, const String& locale_key, wxItemKind kind = wxITEM_NORMAL, wxMenu* submenu = nullptr); +wxMenuItem* add_menu_item(wxMenu*, int id, const char* resource, const String& text, const String& help, wxItemKind kind = wxITEM_NORMAL, wxMenu* submenu = nullptr); +wxMenuItem* add_menu_item_tr(wxMenu*, int id, const char* resource, const String& locale_key, wxItemKind kind = wxITEM_NORMAL, wxMenu* submenu = nullptr); + +// toolbars with images loaded from resource +// resource may be nullptr +wxToolBarToolBase* add_tool(wxToolBar*, int id, const char* resource, const String& label, const String& tooltip, const String& help, wxItemKind kind = wxITEM_NORMAL); +// add a tool to a toolbar, translate tooltip and help using locale +wxToolBarToolBase* add_tool_tr(wxToolBar*, int id, const char* resource, const String& locale_key, bool label = false, wxItemKind kind = wxITEM_NORMAL); + // ----------------------------------------------------------------------------- : Resource related /// Load an image from a resource @@ -59,7 +79,7 @@ wxCursor load_resource_cursor(const String& name); wxIcon load_resource_icon(const String& name); /// Load an image for use in a toolbar (filename: tool/...) from a resource -wxBitmap load_resource_tool_image(const String& name); +wxImage load_resource_tool_image(const String& name); // ----------------------------------------------------------------------------- : Platform look diff --git a/src/gui/value/editor.hpp b/src/gui/value/editor.hpp index 1c616d80..d456924e 100644 --- a/src/gui/value/editor.hpp +++ b/src/gui/value/editor.hpp @@ -12,7 +12,6 @@ #include #include -class IconMenu; class ValueAction; DECLARE_POINTER_TYPE(ValueActionPerformer); @@ -56,7 +55,7 @@ class ValueEditor { /// a context menu is requested, add extra items to the menu m /** return false to suppress menu */ - virtual bool onContextMenu(IconMenu& m, wxContextMenuEvent& ev) { return true; } + virtual bool onContextMenu(wxMenu& m, wxContextMenuEvent& ev) { return true; } /// Get a special menu, events will be sent to onMenu virtual wxMenu* getMenu(int type) const { return nullptr; } /// A menu item was selected, return true if the command was processed diff --git a/src/gui/value/text.cpp b/src/gui/value/text.cpp index 8836f940..613e735a 100644 --- a/src/gui/value/text.cpp +++ b/src/gui/value/text.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -552,12 +551,12 @@ void TextValueEditor::onLoseFocus() { //selection_start_i = selection_end_i = 0; } -bool TextValueEditor::onContextMenu(IconMenu& m, wxContextMenuEvent& ev) { +bool TextValueEditor::onContextMenu(wxMenu& m, wxContextMenuEvent& ev) { // in a keword? => "reminder text" option size_t kwpos = in_tag(value().value(), _(" show suggestions and "add to dictionary" size_t error_pos = in_tag(value().value(), _("