ASPiK SDK
uieditmenucontroller.h
1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #ifndef __uieditmenucontroller__
6 #define __uieditmenucontroller__
7 
8 #include "../uidescription.h"
9 
10 #if VSTGUI_LIVE_EDITING
11 
12 #include "uiselection.h"
13 #include "uiundomanager.h"
14 #include "../delegationcontroller.h"
15 
16 namespace VSTGUI {
17 class IActionPerformer;
18 
19 namespace UIEditing {
20 
21 //----------------------------------------------------------------------------------------------------
22 struct MenuEntry {
23  UTF8StringPtr category;
24  UTF8StringPtr name;
25  UTF8StringPtr key;
26  int32_t modifier;
27  int32_t virtualKey;
28  int32_t menuFlags;
29 
30  enum {
31  kSubMenu = (1 << 0),
32  kSubMenuEnd = (1 << 1),
33  kSubMenuCheckStyle = (1 << 2),
34  kMenuItemIsTitle = (1 << 3)
35  };
36 };
37 
38 //----------------------------------------------------------------------------------------------------
39 static const MenuEntry kMenuSeparator = { "Separator", 0, 0, 0, 0 };
40 static const MenuEntry kSubMenuEnd = { 0, 0 , 0, 0, 0, MenuEntry::kSubMenuEnd };
41 
42 //----------------------------------------------------------------------------------------------------
43 static const MenuEntry editMenu[] = {
44  { "Edit", "Undo" , "z", kControl },
45  { "Edit", "Redo" , "z", kControl|kShift },
46  kMenuSeparator,
47  { "Edit", "Cut" , "x", kControl },
48  { "Edit", "Copy" , "c", kControl },
49  { "Edit", "Paste" , "v", kControl },
50  { "Edit", "Delete" , 0, kControl, VKEY_BACK },
51  kMenuSeparator,
52  { "Edit", "Selection" , 0, 0, 0, MenuEntry::kSubMenu},
53 
54  { "Selection", "Move" , 0, 0, 0, MenuEntry::kSubMenu},
55  { "", "By Grid" , 0, 0, 0, MenuEntry::kMenuItemIsTitle},
56  kMenuSeparator,
57  { "SelectionMoveByGrid", "Move Up" , 0, kControl, VKEY_UP },
58  { "SelectionMoveByGrid", "Move Down" , 0, kControl, VKEY_DOWN },
59  { "SelectionMoveByGrid", "Move Left" , 0, kControl, VKEY_LEFT },
60  { "SelectionMoveByGrid", "Move Right" , 0, kControl, VKEY_RIGHT },
61  kMenuSeparator,
62  { "", "By Pixel" , 0, 0, 0, MenuEntry::kMenuItemIsTitle},
63  kMenuSeparator,
64  { "SelectionMoveByPixel", "Move Up" , 0, kControl|kShift, VKEY_UP },
65  { "SelectionMoveByPixel", "Move Down" , 0, kControl|kShift, VKEY_DOWN },
66  { "SelectionMoveByPixel", "Move Left" , 0, kControl|kShift, VKEY_LEFT },
67  { "SelectionMoveByPixel", "Move Right" , 0, kControl|kShift, VKEY_RIGHT },
68  kSubMenuEnd,
69 
70  { "Selection", "Size" , 0, 0, 0, MenuEntry::kSubMenu},
71  { "", "By Grid" , 0, 0, 0, MenuEntry::kMenuItemIsTitle},
72  kMenuSeparator,
73  { "SelectionSizeByGrid", "Increase Size Width" , 0, kControl|kAlt, VKEY_RIGHT },
74  { "SelectionSizeByGrid", "Increase Size Height" , 0, kControl|kAlt, VKEY_DOWN },
75  { "SelectionSizeByGrid", "Decrease Size Width" , 0, kControl|kAlt, VKEY_LEFT },
76  { "SelectionSizeByGrid", "Decrease Size Height" , 0, kControl|kAlt, VKEY_UP },
77  kMenuSeparator,
78  { "", "By Pixel" , 0, 0, 0, MenuEntry::kMenuItemIsTitle},
79  kMenuSeparator,
80  { "SelectionSizeByPixel", "Increase Size Width" , 0, kControl|kAlt|kShift, VKEY_RIGHT },
81  { "SelectionSizeByPixel", "Increase Size Height" , 0, kControl|kAlt|kShift, VKEY_DOWN },
82  { "SelectionSizeByPixel", "Decrease Size Width" , 0, kControl|kAlt|kShift, VKEY_LEFT },
83  { "SelectionSizeByPixel", "Decrease Size Height" , 0, kControl|kAlt|kShift, VKEY_UP },
84  kSubMenuEnd,
85 
86  { "Selection", "Z-Order" , 0, 0, 0, MenuEntry::kSubMenu},
87  { "SelectionZOrder", "Lower" , 0, kAlt, VKEY_UP },
88  { "SelectionZOrder", "Raise" , 0, kAlt, VKEY_DOWN },
89  kSubMenuEnd,
90  kMenuSeparator,
91  { "Selection", "Select All Children" , 0, 0, 0 },
92 
93  kSubMenuEnd,
94  kMenuSeparator,
95  { "Zoom", "Zoom" , 0, 0, 0, MenuEntry::kSubMenu},
96  { "Zoom", "Zoom In" , "=", kControl },
97  { "Zoom", "Zoom Out" , "-", kControl },
98  kMenuSeparator,
99  { "Zoom", "Zoom 100%" , "0", kControl|kAlt },
100  kSubMenuEnd,
101 
102  kMenuSeparator,
103  { "Edit", "Size To Fit" , 0, 0, 0 },
104  { "Edit", "Unembed Views" , 0, 0, 0 },
105  { "Edit", "Embed Into" , 0, 0, 0 },
106  { "Edit", "Transform View Type" , 0, 0, 0 },
107  { "Edit", "Insert Template" , 0, 0, 0 },
108  kMenuSeparator,
109  { "Edit", "Add New Template" , 0, 0, 0 },
110  { "Edit", "Delete Template" , 0, 0, 0 },
111  { "Edit", "Duplicate Template" , 0, 0, 0 },
112  kMenuSeparator,
113  { "Edit", "Template Settings..." , 0, kControl, VKEY_ENTER },
114  { "Edit", "Focus Drawing Settings..." , 0, 0, 0 },
115  {0}
116 };
117 
118 //----------------------------------------------------------------------------------------------------
119 static const MenuEntry fileMenu[] = {
120  { "File", "Save Options" , 0, 0, 0, MenuEntry::kSubMenu|MenuEntry::kSubMenuCheckStyle },
121  { "File", "Encode Bitmaps in XML" , 0, 0, 0 },
122  { "File", "Write Windows RC File on Save" , 0, 0, 0 },
123  kSubMenuEnd,
124  kMenuSeparator,
125  {0}
126 };
127 
128 } // namespace UIEditing
129 
130 //----------------------------------------------------------------------------------------------------
131 class UIEditMenuController : public CBaseObject, public DelegationController
132 {
133 public:
134  UIEditMenuController (IController* baseController, UISelection* selection, UIUndoManager* undoManager, UIDescription* description, IActionPerformer* actionPerformer);
135  ~UIEditMenuController () noexcept override = default;
136 
137  COptionMenu* getFileMenu () const { return fileMenu; }
138  COptionMenu* getEditMenu () const { return editMenu; }
139 
140  int32_t processKeyCommand (const VstKeyCode& key);
141  bool handleCommand (const UTF8StringPtr category, const UTF8StringPtr name);
142  bool canHandleCommand (const UTF8StringPtr category, const UTF8StringPtr name) const;
143 
144  CMessageResult notify (CBaseObject* sender, IdStringPtr message) override;
145  void valueChanged (CControl* pControl) override;
146 
147  static bool createUniqueTemplateName (std::list<const std::string*>& names, std::string& name);
148 protected:
149  bool validateMenuItem (CCommandMenuItem& item);
150  CCommandMenuItem* findKeyCommandItem (COptionMenu* menu, const VstKeyCode& key);
151  void createEditMenu (COptionMenu* menu);
152  void createFileMenu (COptionMenu* menu);
153 
154  CView* verifyView (CView* view, const UIAttributes& attributes, const IUIDescription* description) override;
155  IControlListener* getControlListener (UTF8StringPtr name) override { return this; }
156  void controlBeginEdit (CControl* pControl) override;
157  void controlEndEdit (CControl* pControl) override;
158 
159  SharedPointer<UISelection> selection;
160  SharedPointer<UIUndoManager> undoManager;
161  SharedPointer<UIDescription> description;
162  SharedPointer<CVSTGUITimer> highlightTimer;
163  IActionPerformer* actionPerformer;
164 
165  COptionMenu* fileMenu {nullptr};
166  COptionMenu* editMenu {nullptr};
167  SharedPointer<CTextLabel> fileLabel;
168  SharedPointer<CTextLabel> editLabel;
169 
170  enum {
171  kMenuFileTag = 100,
172  kMenuEditTag = 101
173  };
174 
175 };
176 
177 } // namespace
178 
179 #endif // VSTGUI_LIVE_EDITING
180 
181 #endif // __uieditmenucontroller__
Definition: vstkeycode.h:12
Definition: customcontrols.cpp:8