ASPiK SDK
uidescription.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 __uidescription__
6 #define __uidescription__
7 
8 #include "../lib/idependency.h"
9 #include "iuidescription.h"
10 #include "uidescriptionfwd.h"
11 #include "xmlparser.h"
12 #include <list>
13 #include <string>
14 #include <memory>
15 
16 namespace VSTGUI {
17 
18 class UINode;
19 
20 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 {
26 public:
27  UIDescription (const CResourceDescription& xmlFile, IViewFactory* viewFactory = nullptr);
28  UIDescription (Xml::IContentProvider* xmlContentProvider, IViewFactory* viewFactory = nullptr);
29  ~UIDescription () noexcept override;
30 
31  virtual bool parse ();
32 
33  enum SaveFlags {
34  kWriteWindowsResourceFile = 1 << 0,
35  kWriteImagesIntoXMLFile = 1 << 1
36  };
37 
38  virtual bool save (UTF8StringPtr filename, int32_t flags = kWriteWindowsResourceFile);
39  virtual bool saveWindowsRCFile (UTF8StringPtr filename);
40 
41  bool storeViews (const std::list<CView*>& views, OutputStream& stream, UIAttributes* customData = nullptr) const;
42  bool restoreViews (InputStream& stream, std::list<SharedPointer<CView> >& views, UIAttributes** customData = nullptr);
43 
44  UTF8StringPtr getFilePath () const;
45  void setFilePath (UTF8StringPtr path);
46 
47  void setSharedResources (const SharedPointer<UIDescription>& resources);
48  const SharedPointer<UIDescription>& getSharedResources () const;
49 
50  const UIAttributes* getViewAttributes (UTF8StringPtr name) const;
51 
52  void setController (IController* controller) const;
53 
54  CView* createView (UTF8StringPtr name, IController* controller) const override;
55  CBitmap* getBitmap (UTF8StringPtr name) const override;
56  CFontRef getFont (UTF8StringPtr name) const override;
57  bool getColor (UTF8StringPtr name, CColor& color) const override;
58  CGradient* getGradient (UTF8StringPtr name) const override;
59  int32_t getTagForName (UTF8StringPtr name) const override;
60  IControlListener* getControlListener (UTF8StringPtr name) const override;
61  IController* getController () const override;
62  const IViewFactory* getViewFactory () const override;
63 
64  UTF8StringPtr lookupColorName (const CColor& color) const override;
65  UTF8StringPtr lookupFontName (const CFontRef font) const override;
66  UTF8StringPtr lookupBitmapName (const CBitmap* bitmap) const override;
67  UTF8StringPtr lookupGradientName (const CGradient* gradient) const override;
68  UTF8StringPtr lookupControlTagName (const int32_t tag) const override;
69 
70  bool getVariable (UTF8StringPtr name, double& value) const override;
71  bool getVariable (UTF8StringPtr name, std::string& value) const override;
72 
73  void collectTemplateViewNames (std::list<const std::string*>& names) const override;
74  void collectColorNames (std::list<const std::string*>& names) const override;
75  void collectFontNames (std::list<const std::string*>& names) const override;
76  void collectBitmapNames (std::list<const std::string*>& names) const override;
77  void collectGradientNames (std::list<const std::string*>& names) const override;
78  void collectControlTagNames (std::list<const std::string*>& names) const override;
79 
80  void changeColorName (UTF8StringPtr oldName, UTF8StringPtr newName);
81  void changeTagName (UTF8StringPtr oldName, UTF8StringPtr newName);
82  void changeFontName (UTF8StringPtr oldName, UTF8StringPtr newName);
83  void changeBitmapName (UTF8StringPtr oldName, UTF8StringPtr newName);
84  void changeGradientName (UTF8StringPtr oldName, UTF8StringPtr newName);
85 
86  void changeColor (UTF8StringPtr name, const CColor& newColor);
87  void changeFont (UTF8StringPtr name, CFontRef newFont);
88  void changeGradient (UTF8StringPtr name, CGradient* newGradient);
89  void changeBitmap (UTF8StringPtr name, UTF8StringPtr newName, const CRect* nineparttiledOffset = nullptr);
90 
91  void changeBitmapFilters (UTF8StringPtr bitmapName, const std::list<SharedPointer<UIAttributes> >& filters);
92  void collectBitmapFilters (UTF8StringPtr bitmapName, std::list<SharedPointer<UIAttributes> >& filters) const;
93 
94  void removeColor (UTF8StringPtr name);
95  void removeTag (UTF8StringPtr name);
96  void removeFont (UTF8StringPtr name);
97  void removeBitmap (UTF8StringPtr name);
98  void removeGradient (UTF8StringPtr name);
99 
100  void changeAlternativeFontNames (UTF8StringPtr name, UTF8StringPtr alternativeFonts);
101  bool getAlternativeFontNames (UTF8StringPtr name, std::string& alternativeFonts) const;
102 
103  bool hasColorName (UTF8StringPtr name) const;
104  bool hasTagName (UTF8StringPtr name) const;
105  bool hasFontName (UTF8StringPtr name) const;
106  bool hasBitmapName (UTF8StringPtr name) const;
107  bool hasGradientName (UTF8StringPtr name) const;
108 
109  void updateViewDescription (UTF8StringPtr name, CView* view);
110  bool getTemplateNameFromView (CView* view, std::string& templateName) const;
111  bool addNewTemplate (UTF8StringPtr name, UIAttributes* attr); // owns attributes
112  bool removeTemplate (UTF8StringPtr name);
113  bool changeTemplateName (UTF8StringPtr name, UTF8StringPtr newName);
114  bool duplicateTemplate (UTF8StringPtr name, UTF8StringPtr duplicateName);
115 
116  bool setCustomAttributes (UTF8StringPtr name, UIAttributes* attr); //owns attributes
117  UIAttributes* getCustomAttributes (UTF8StringPtr name) const;
118  UIAttributes* getCustomAttributes (UTF8StringPtr name, bool create);
119 
120  bool getControlTagString (UTF8StringPtr tagName, std::string& tagString) const;
121  bool changeControlTagString (UTF8StringPtr tagName, const std::string& newTagString, bool create = false);
122 
123  bool calculateStringValue (UTF8StringPtr str, double& result) const;
124 
125  void registerListener (UIDescriptionListener* listener);
126  void unregisterListener (UIDescriptionListener* listener);
127 
128  void setBitmapCreator (IBitmapCreator* bitmapCreator);
129 
131  {
132  bool enabled {false};
133  CCoord width {1};
134  UTF8String colorName;
135  };
136  FocusDrawing getFocusDrawingSettings () const;
137  void setFocusDrawingSettings (const FocusDrawing& fd);
138 
139  void freePlatformResources ();
140 
141  static bool parseColor (const std::string& colorString, CColor& color);
142  static CViewAttributeID kTemplateNameAttributeID;
143 
144  static IdStringPtr kMessageTagChanged;
145  static IdStringPtr kMessageColorChanged;
146  static IdStringPtr kMessageFontChanged;
147  static IdStringPtr kMessageBitmapChanged;
148  static IdStringPtr kMessageTemplateChanged;
149  static IdStringPtr kMessageGradientChanged;
150  static IdStringPtr kMessageBeforeSave;
151 protected:
152  void addDefaultNodes ();
153 
154  bool saveToStream (OutputStream& stream, int32_t flags);
155 
156  bool parsed () const;
157  void setXmlContentProvider (Xml::IContentProvider* provider);
158 
159  const CResourceDescription& getXmlFile () const;
160 private:
161  // Xml::IHandler
162  void startXmlElement (Xml::Parser* parser, IdStringPtr elementName, UTF8StringPtr* elementAttributes) override;
163  void endXmlElement (Xml::Parser* parser, IdStringPtr name) override;
164  void xmlCharData (Xml::Parser* parser, const int8_t* data, int32_t length) override;
165  void xmlComment (Xml::Parser* parser, IdStringPtr comment) override;
166 
167  CView* createViewFromNode (UINode* node) const;
168  UINode* getBaseNode (UTF8StringPtr name) const;
169  UINode* findChildNodeByNameAttribute (UINode* node, UTF8StringPtr nameAttribute) const;
170  UINode* findNodeForView (CView* view) const;
171  bool updateAttributesForView (UINode* node, CView* view, bool deep = true);
172  void removeNode (UTF8StringPtr name, IdStringPtr mainNodeName, IdStringPtr changeMsg);
173  template<typename NodeType, typename ObjType, typename CompareFunction> UTF8StringPtr lookupName (const ObjType& obj, IdStringPtr mainNodeName, CompareFunction compare) const;
174  template<typename NodeType> void changeNodeName (UTF8StringPtr oldName, UTF8StringPtr newName, IdStringPtr mainNodeName, IdStringPtr changeMsg);
175  template<typename NodeType> void collectNamesFromNode (IdStringPtr mainNodeName, std::list<const std::string*>& names) const;
176 
177  struct Impl;
178  std::unique_ptr<Impl> impl;
179 };
180 
181 //-----------------------------------------------------------------------------
183 {
184 public:
185  virtual ~IBitmapCreator () noexcept = default;
186 
187  virtual SharedPointer<IPlatformBitmap> createBitmap (const UIAttributes& attributes) = 0;
188 };
189 
190 } // namespace
191 
192 #endif
Definition: xmlparser.h:26
Describes a resource by name or by ID.
Definition: cresourcedescription.h:16
Definition: cstream.h:50
font class
Definition: cfont.h:31
Rect structure.
Definition: crect.h:17
Definition: iuidescription.h:19
Definition: xmlparse.c:181
Definition: iviewfactory.h:15
Definition: xmlparser.h:18
Definition: vstguibase.h:299
Definition: uidescriptionlistener.h:14
RGBA Color structure.
Definition: ccolor.h:15
Definition: uidescription.cpp:665
XML description parser and view creator.
Definition: uidescription.h:24
Definition: cstream.h:21
Gradient Object [new in 4.0].
Definition: cgradient.h:19
Encapsulates various platform depended kinds of bitmaps.
Definition: cbitmap.h:21
Definition: customcontrols.cpp:8
Definition: uiattributes.h:21
Definition: uidescription.h:130
extension to IControlListener used by UIDescription
Definition: icontroller.h:20
Definition: vstguibase.h:247
Definition: uidescription.h:182
Base Class of all view objects.
Definition: cview.h:44
holds an UTF8 encoded string and a platform representation of it
Definition: cstring.h:56
Definition: xmlparser.h:36
Definition: icontrollistener.h:14
simple dependency between objects.
Definition: idependency.h:26