1 // SHE library 2 // Copyright (C) 2017 David Capello 3 // 4 // This file is released under the terms of the MIT license. 5 // Read LICENSE.txt for more information. 6 7 #ifndef SHE_MENUS_H_INCLUDED 8 #define SHE_MENUS_H_INCLUDED 9 #pragma once 10 11 #include "she/keys.h" 12 #include "she/shortcut.h" 13 14 #include <functional> 15 #include <string> 16 17 namespace she { 18 class MenuItem; 19 20 struct MenuItemInfo { 21 enum Type { 22 Normal, 23 Separator 24 }; 25 26 enum Action { 27 UserDefined, 28 29 // macOS standard commands 30 Hide, 31 HideOthers, 32 ShowAll, 33 Quit, 34 Minimize, 35 Zoom, 36 }; 37 38 Type type; 39 Action action; 40 std::string text; 41 Shortcut shortcut; 42 std::function<void()> execute; 43 std::function<void(she::MenuItem*)> validate; 44 45 explicit MenuItemInfo(const Type type = Normal, 46 const Action action = UserDefined) typeMenuItemInfo47 : type(type) 48 , action(action) { 49 } 50 51 explicit MenuItemInfo(const char* text, 52 const Action action = UserDefined) typeMenuItemInfo53 : type(Normal) 54 , action(action) 55 , text(text) { 56 } 57 }; 58 59 class Menu; 60 class MenuItem; 61 class Menus; 62 63 class MenuItem { 64 public: ~MenuItem()65 virtual ~MenuItem() { } 66 virtual void dispose() = 0; 67 virtual void setText(const std::string& text) = 0; 68 virtual void setSubmenu(Menu* submenu) = 0; 69 virtual void setEnabled(bool state) = 0; 70 virtual void setChecked(bool state) = 0; 71 virtual void setShortcut(const Shortcut& shortcut) = 0; 72 }; 73 74 class Menu { 75 public: ~Menu()76 virtual ~Menu() { } 77 virtual void dispose() = 0; 78 virtual void addItem(MenuItem* item) = 0; 79 virtual void insertItem(const int index, MenuItem* item) = 0; 80 }; 81 82 class Menus { 83 public: ~Menus()84 virtual ~Menus() { } 85 virtual Menu* createMenu() = 0; 86 virtual MenuItem* createMenuItem(const MenuItemInfo& info) = 0; 87 virtual void setAppMenu(Menu* menu) = 0; 88 }; 89 90 } // namespace she 91 92 #endif 93