ASPiK SDK
uiactions.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 __uiactions__
6 #define __uiactions__
7 
8 #include "iaction.h"
9 
10 #if VSTGUI_LIVE_EDITING
11 
12 #include "uiselection.h"
13 #include "../uiviewfactory.h"
14 #include "../../lib/ccolor.h"
15 #include "../../lib/cgradient.h"
16 #include <list>
17 #include <map>
18 #include <vector>
19 #include <string>
20 
21 namespace VSTGUI {
22 class UIViewFactory;
23 class IUIDescription;
24 class UIDescription;
25 class CViewContainer;
26 class CView;
27 
28 //-----------------------------------------------------------------------------
29 template <class T>
30 class BaseSelectionOperation : public IAction, protected std::list<T>
31 {
32 public:
33  BaseSelectionOperation (UISelection* selection) : selection (selection) {}
34 
35 protected:
36  SharedPointer<UISelection> selection;
37 };
38 
39 //-----------------------------------------------------------------------------
40 class SizeToFitOperation : public BaseSelectionOperation<std::pair<SharedPointer<CView>, CRect> >
41 {
42 public:
43  SizeToFitOperation (UISelection* selection);
44  ~SizeToFitOperation () override = default;
45 
46  UTF8StringPtr getName () override;
47 
48  void perform () override;
49  void undo () override;
50 };
51 
52 //-----------------------------------------------------------------------------
53 class UnembedViewOperation : public BaseSelectionOperation<SharedPointer<CView> >
54 {
55 public:
56  UnembedViewOperation (UISelection* selection, const IViewFactory* factory);
57  ~UnembedViewOperation () override = default;
58 
59  UTF8StringPtr getName () override;
60 
61  void perform () override;
62  void undo () override;
63 
64 protected:
65  void collectSubviews (CViewContainer* container, bool deep);
66  const IViewFactory* factory;
67  SharedPointer<CViewContainer> containerView;
68  CViewContainer* parent;
69 };
70 
71 //-----------------------------------------------------------------------------
72 class EmbedViewOperation : public BaseSelectionOperation<std::pair<SharedPointer<CView>, CRect> >
73 {
74 public:
75  EmbedViewOperation (UISelection* selection, CViewContainer* newContainer);
76  ~EmbedViewOperation () override = default;
77 
78  UTF8StringPtr getName () override;
79  void perform () override;
80  void undo () override;
81 
82 protected:
83  SharedPointer<CViewContainer> newContainer;
84  CViewContainer* parent;
85 };
86 
87 //-----------------------------------------------------------------------------
88 class ViewCopyOperation : public IAction, protected std::list<SharedPointer<CView> >
89 {
90 public:
91  ViewCopyOperation (UISelection* copySelection, UISelection* workingSelection, CViewContainer* parent, const CPoint& offset, IUIDescription* desc);
92  ~ViewCopyOperation () override = default;
93 
94  UTF8StringPtr getName () override;
95  void perform () override;
96  void undo () override;
97 protected:
98  SharedPointer<CViewContainer> parent;
99  SharedPointer<UISelection> copySelection;
100  SharedPointer<UISelection> workingSelection;
101  std::list<SharedPointer<CView> > oldSelectedViews;
102 };
103 
104 //-----------------------------------------------------------------------------
105 class ViewSizeChangeOperation : public BaseSelectionOperation<std::pair<SharedPointer<CView>, CRect> >
106 {
107 public:
108  ViewSizeChangeOperation (UISelection* selection, bool sizing, bool autosizingEnabled);
109  ~ViewSizeChangeOperation () override = default;
110 
111  UTF8StringPtr getName () override;
112  void perform () override;
113  void undo () override;
114 
115  bool didChange ();
116 protected:
117  bool first;
118  bool sizing;
119  bool autosizing;
120 };
121 
122 //----------------------------------------------------------------------------------------------------
123 struct DeleteOperationViewAndNext
124 {
125  DeleteOperationViewAndNext (CView* view, CView* nextView) : view (view), nextView (nextView) {}
126  DeleteOperationViewAndNext (const DeleteOperationViewAndNext& copy) : view (copy.view), nextView (copy.nextView) {}
127  SharedPointer<CView> view;
128  SharedPointer<CView> nextView;
129 };
130 
131 //----------------------------------------------------------------------------------------------------
132 class DeleteOperation : public IAction, protected std::multimap<SharedPointer<CViewContainer>, DeleteOperationViewAndNext>
133 {
134 public:
135  DeleteOperation (UISelection* selection);
136  ~DeleteOperation () override = default;
137 
138  UTF8StringPtr getName () override;
139  void perform () override;
140  void undo () override;
141 protected:
142  SharedPointer<UISelection> selection;
143 };
144 
145 //-----------------------------------------------------------------------------
146 class InsertViewOperation : public IAction
147 {
148 public:
149  InsertViewOperation (CViewContainer* parent, CView* view, UISelection* selection);
150  ~InsertViewOperation () override = default;
151 
152  UTF8StringPtr getName () override;
153  void perform () override;
154  void undo () override;
155 protected:
156  SharedPointer<CViewContainer> parent;
157  SharedPointer<CView> view;
158  SharedPointer<UISelection> selection;
159 };
160 
161 //-----------------------------------------------------------------------------
162 class TransformViewTypeOperation : public IAction
163 {
164 public:
165  TransformViewTypeOperation (UISelection* selection, IdStringPtr viewClassName, UIDescription* desc, const UIViewFactory* factory);
166  ~TransformViewTypeOperation () override;
167 
168  UTF8StringPtr getName () override;
169 
170  void exchangeSubViews (CViewContainer* src, CViewContainer* dst);
171  void perform () override;
172  void undo () override;
173 protected:
174  SharedPointer<CView> view;
175  CView* newView;
176  SharedPointer<CView> beforeView;
177  SharedPointer<CViewContainer> parent;
178  SharedPointer<UISelection> selection;
179  const UIViewFactory* factory;
180  SharedPointer<UIDescription> description;
181 };
182 
183 //-----------------------------------------------------------------------------
184 class AttributeChangeAction : public IAction, protected std::map<SharedPointer<CView>, std::string>
185 {
186 public:
187  AttributeChangeAction (UIDescription* desc, UISelection* selection, const std::string& attrName, const std::string& attrValue);
188  ~AttributeChangeAction () override = default;
189 
190  UTF8StringPtr getName () override;
191  void perform () override;
192  void undo () override;
193 protected:
194  void updateSelection ();
195 
196  UIDescription* desc;
197  SharedPointer<UISelection> selection;
198  std::string attrName;
199  std::string attrValue;
200  std::string name;
201 };
202 
203 //----------------------------------------------------------------------------------------------------
204 class MultipleAttributeChangeAction : public IAction, public std::vector<std::pair<SharedPointer<CView>, std::string> >
205 {
206 public:
207  MultipleAttributeChangeAction (UIDescription* description, const std::list<CView*>& views, IViewCreator::AttrType attrType, UTF8StringPtr oldValue, UTF8StringPtr newValue);
208  UTF8StringPtr getName () override { return "multiple view attribute changes"; }
209  void perform () override;
210  void undo () override;
211 protected:
212  void setAttributeValue (UTF8StringPtr value);
213  static void collectAllSubViews (CView* view, std::list<CView*>& views);
214  void collectViewsWithAttributeValue (const UIViewFactory* viewFactory, IUIDescription* desc, CView* startView, IViewCreator::AttrType type, const std::string& value);
215 
216  SharedPointer<UIDescription> description;
217  std::string oldValue;
218  std::string newValue;
219 };
220 
221 //----------------------------------------------------------------------------------------------------
222 class TagChangeAction : public IAction
223 {
224 public:
225  TagChangeAction (UIDescription* description, UTF8StringPtr name, UTF8StringPtr newTagString, bool remove, bool performOrUndo);
226 
227  UTF8StringPtr getName () override;
228  void perform () override;
229  void undo () override;
230 
231  bool isAddTag () const { return isNewTag; }
232 protected:
233  SharedPointer<UIDescription> description;
234  std::string name;
235  std::string newTag;
236  std::string originalTag;
237  bool remove;
238  bool performOrUndo;
239  bool isNewTag;
240 };
241 
242 //----------------------------------------------------------------------------------------------------
243 class TagNameChangeAction : public IAction
244 {
245 public:
246  TagNameChangeAction (UIDescription* description, UTF8StringPtr oldName, UTF8StringPtr newName, bool performOrUndo);
247 
248  UTF8StringPtr getName () override;
249  void perform () override;
250  void undo () override;
251 protected:
252  SharedPointer<UIDescription> description;
253  std::string oldName;
254  std::string newName;
255  bool performOrUndo;
256 };
257 
258 //----------------------------------------------------------------------------------------------------
259 class ColorChangeAction : public IAction
260 {
261 public:
262  ColorChangeAction (UIDescription* description, UTF8StringPtr name, const CColor& color, bool remove, bool performOrUndo);
263 
264  UTF8StringPtr getName () override;
265  void perform () override;
266  void undo () override;
267 
268  bool isAddColor () const { return isNewColor; }
269 protected:
270  SharedPointer<UIDescription> description;
271  std::string name;
272  CColor newColor;
273  CColor oldColor;
274  bool remove;
275  bool performOrUndo;
276  bool isNewColor;
277 };
278 
279 //----------------------------------------------------------------------------------------------------
280 class ColorNameChangeAction : public IAction
281 {
282 public:
283  ColorNameChangeAction (UIDescription* description, UTF8StringPtr oldName, UTF8StringPtr newName, bool performOrUndo);
284 
285  UTF8StringPtr getName () override;
286  void perform () override;
287  void undo () override;
288 protected:
289  SharedPointer<UIDescription> description;
290  std::string oldName;
291  std::string newName;
292  bool performOrUndo;
293 };
294 
295 //----------------------------------------------------------------------------------------------------
296 class BitmapChangeAction : public IAction
297 {
298 public:
299  BitmapChangeAction (UIDescription* description, UTF8StringPtr name, UTF8StringPtr path, bool remove, bool performOrUndo);
300 
301  UTF8StringPtr getName () override;
302  void perform () override;
303  void undo () override;
304 
305  bool isAddBitmap () const { return isNewBitmap; }
306 protected:
307  SharedPointer<UIDescription> description;
308  std::string name;
309  std::string path;
310  std::string originalPath;
311  bool remove;
312  bool performOrUndo;
313  bool isNewBitmap;
314 };
315 
316 //----------------------------------------------------------------------------------------------------
317 class BitmapNameChangeAction : public IAction
318 {
319 public:
320  BitmapNameChangeAction (UIDescription* description, UTF8StringPtr oldName, UTF8StringPtr newName, bool performOrUndo);
321 
322  UTF8StringPtr getName () override;
323  void perform () override;
324  void undo () override;
325 protected:
326  SharedPointer<UIDescription> description;
327  std::string oldName;
328  std::string newName;
329  bool performOrUndo;
330 };
331 
332 //----------------------------------------------------------------------------------------------------
333 class NinePartTiledBitmapChangeAction : public IAction
334 {
335 public:
336  NinePartTiledBitmapChangeAction (UIDescription* description, UTF8StringPtr name, const CRect* rect, bool performOrUndo);
337  ~NinePartTiledBitmapChangeAction () override;
338 
339  UTF8StringPtr getName () override;
340  void perform () override;
341  void undo () override;
342 protected:
343  SharedPointer<UIDescription> description;
344  std::string name;
345  CRect* oldRect;
346  CRect* newRect;
347  bool performOrUndo;
348 };
349 
350 //----------------------------------------------------------------------------------------------------
351 class BitmapFilterChangeAction : public IAction
352 {
353 public:
354  BitmapFilterChangeAction (UIDescription* description, UTF8StringPtr bitmapName, const std::list<SharedPointer<UIAttributes> >& attributes, bool performOrUndo);
355  ~BitmapFilterChangeAction () override = default;
356 
357  UTF8StringPtr getName () override;
358  void perform () override;
359  void undo () override;
360 protected:
361  SharedPointer<UIDescription> description;
362  std::string bitmapName;
363  std::list<SharedPointer<UIAttributes> > newAttributes;
364  std::list<SharedPointer<UIAttributes> > oldAttributes;
365  bool performOrUndo;
366 };
367 
368 //----------------------------------------------------------------------------------------------------
369 class GradientChangeAction : public IAction
370 {
371 public:
372  GradientChangeAction (UIDescription* description, UTF8StringPtr name, CGradient* gradient, bool remove, bool performOrUndo);
373 
374  UTF8StringPtr getName () override;
375  void perform () override;
376  void undo () override;
377 
378  bool isAddGradient () const { return originalGradient == 0; }
379 protected:
380  SharedPointer<UIDescription> description;
381  std::string name;
382  SharedPointer<CGradient> gradient;
383  SharedPointer<CGradient> originalGradient;
384  bool remove;
385  bool performOrUndo;
386 };
387 
388 //----------------------------------------------------------------------------------------------------
389 class GradientNameChangeAction : public IAction
390 {
391 public:
392  GradientNameChangeAction (UIDescription* description, UTF8StringPtr oldName, UTF8StringPtr newName, bool performOrUndo);
393 
394  UTF8StringPtr getName () override;
395  void perform () override;
396  void undo () override;
397 protected:
398  SharedPointer<UIDescription> description;
399  std::string oldName;
400  std::string newName;
401  bool performOrUndo;
402 };
403 
404 //----------------------------------------------------------------------------------------------------
405 class FontChangeAction : public IAction
406 {
407 public:
408  FontChangeAction (UIDescription* description, UTF8StringPtr name, CFontRef font, bool remove, bool performOrUndo);
409 
410  UTF8StringPtr getName () override;
411  void perform () override;
412  void undo () override;
413 
414  bool isAddFont () const { return originalFont == 0; }
415 protected:
416  SharedPointer<UIDescription> description;
417  std::string name;
418  std::string alternativeNames;
419  SharedPointer<CFontDesc> font;
420  SharedPointer<CFontDesc> originalFont;
421  bool remove;
422  bool performOrUndo;
423 };
424 
425 //----------------------------------------------------------------------------------------------------
426 class FontNameChangeAction : public IAction
427 {
428 public:
429  FontNameChangeAction (UIDescription* description, UTF8StringPtr oldName, UTF8StringPtr newName, bool performOrUndo);
430 
431  UTF8StringPtr getName () override;
432  void perform () override;
433  void undo () override;
434 protected:
435  SharedPointer<UIDescription> description;
436  std::string oldName;
437  std::string newName;
438  bool performOrUndo;
439 };
440 
441 //-----------------------------------------------------------------------------
442 class AlternateFontChangeAction : public IAction
443 {
444 public:
445  AlternateFontChangeAction (UIDescription* description, UTF8StringPtr fontName, UTF8StringPtr newAlternateFontNames);
446  UTF8StringPtr getName () override;
447  void perform () override;
448  void undo () override;
449 protected:
450  SharedPointer<UIDescription> description;
451  std::string fontName;
452  std::string newAlternateFontNames;
453  std::string oldAlternateFontNames;
454 };
455 
456 //-----------------------------------------------------------------------------
457 class HierarchyMoveViewOperation : public IAction
458 {
459 public:
460  HierarchyMoveViewOperation (CView* view, UISelection* selection, bool up);
461  ~HierarchyMoveViewOperation () override = default;
462 
463  UTF8StringPtr getName () override;
464  void perform () override;
465  void undo () override;
466 protected:
467  SharedPointer<CView> view;
468  SharedPointer<CViewContainer> parent;
469  SharedPointer<UISelection> selection;
470  bool up;
471 };
472 
473 //-----------------------------------------------------------------------------
474 class TemplateNameChangeAction : public IAction
475 {
476 public:
477  TemplateNameChangeAction (UIDescription* description, IActionPerformer* actionPerformer, UTF8StringPtr oldName, UTF8StringPtr newName);
478 
479  UTF8StringPtr getName () override;
480  void perform () override;
481  void undo () override;
482 protected:
483  SharedPointer<UIDescription> description;
484  IActionPerformer* actionPerformer;
485  std::string oldName;
486  std::string newName;
487 };
488 
489 //-----------------------------------------------------------------------------
490 class CreateNewTemplateAction : public IAction
491 {
492 public:
493  CreateNewTemplateAction (UIDescription* description, IActionPerformer* actionPerformer, UTF8StringPtr name, UTF8StringPtr baseViewClassName);
494 
495  UTF8StringPtr getName () override;
496  void perform () override;
497  void undo () override;
498 protected:
499  SharedPointer<UIDescription> description;
500  IActionPerformer* actionPerformer;
501  SharedPointer<CView> view;
502  std::string name;
503  std::string baseViewClassName;
504 };
505 
506 //-----------------------------------------------------------------------------
507 class DuplicateTemplateAction : public IAction
508 {
509 public:
510  DuplicateTemplateAction (UIDescription* description, IActionPerformer* actionPerformer, UTF8StringPtr name, UTF8StringPtr dupName);
511 
512  UTF8StringPtr getName () override;
513  void perform () override;
514  void undo () override;
515 protected:
516  SharedPointer<UIDescription> description;
517  IActionPerformer* actionPerformer;
518  SharedPointer<CView> view;
519  std::string name;
520  std::string dupName;
521 };
522 
523 //-----------------------------------------------------------------------------
524 class DeleteTemplateAction : public IAction
525 {
526 public:
527  DeleteTemplateAction (UIDescription* description, IActionPerformer* actionPerformer, CView* view, UTF8StringPtr name);
528 
529  UTF8StringPtr getName () override;
530  void perform () override;
531  void undo () override;
532 protected:
533  SharedPointer<UIDescription> description;
534  IActionPerformer* actionPerformer;
535  SharedPointer<CView> view;
536  SharedPointer<UIAttributes> attributes;
537  std::string name;
538 };
539 
540 } // namespace
541 
542 #endif // VSTGUI_LIVE_EDITING
543 
544 #endif // __uiactions__
void perform(Context context, Task &&task)
Definition: macasync.mm:29
Definition: customcontrols.cpp:8