1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
|
///////////////////////////////////////////////////////////////////////////////
//
// wxFormBuilder - A Visual Dialog Editor for wxWidgets.
// Copyright (C) 2005 José Antonio Hurtado
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// Written by
// José Antonio Hurtado - joseantonio.hurtado@gmail.com
// Juan Antonio Ortega - jortegalalmolda@gmail.com
//
///////////////////////////////////////////////////////////////////////////////
#ifndef SDK_PLUGIN_INTERFACE_COMPONENT_H
#define SDK_PLUGIN_INTERFACE_COMPONENT_H
#include <wx/wx.h>
#include <utility>
#include <vector>
#include "fontcontainer.h"
namespace tinyxml2
{
class XMLElement;
}
class IComponentLibrary;
/**
* @brief Object interface for plugins
*
* This interface is used by plugin components to query properties for the objects they create.
*/
class IObject
{
public:
virtual ~IObject() = default;
virtual wxString GetClassName() const = 0;
virtual wxString GetObjectTypeName() const = 0;
virtual std::size_t GetChildCount() const = 0;
virtual IObject* GetChildObject(std::size_t index) const = 0;
virtual wxString GetChildFromParentProperty(const wxString& parentName, const wxString& childName) const = 0;
virtual bool IsPropertyNull(const wxString& name) const = 0;
virtual int GetPropertyAsInteger(const wxString& name) const = 0;
virtual double GetPropertyAsFloat(const wxString& name) const = 0;
virtual wxString GetPropertyAsString(const wxString& name) const = 0;
virtual wxPoint GetPropertyAsPoint(const wxString& name) const = 0;
virtual wxSize GetPropertyAsSize(const wxString& name) const = 0;
virtual wxBitmap GetPropertyAsBitmap(const wxString& name) const = 0;
virtual wxColour GetPropertyAsColour(const wxString& name) const = 0;
virtual wxFontContainer GetPropertyAsFont(const wxString& name) const = 0;
virtual wxArrayInt GetPropertyAsArrayInt(const wxString& name) const = 0;
virtual wxArrayString GetPropertyAsArrayString(const wxString& name) const = 0;
virtual std::vector<std::pair<int, int>> GetPropertyAsVectorIntPair(const wxString& name) const = 0;
};
/**
* @brief Placeholder object for objects not part of a wxWindow hierarchy
*
* Plugin components must always create an object, even if they create non-visual elements.
* Objects of this class must be returned for such elements.
*/
class wxNoObject : public wxObject
{
};
/**
* @brief Manager interface for plugins
*
* This interface is used by plugin components to interact with the main application.
*/
class IManager
{
public:
virtual ~IManager() = default;
/**
* @brief Get the object interface of the object
*
* @param wxobject Object
* @return Object interface
*/
virtual IObject* GetIObject(wxObject* wxobject) const = 0;
/**
* @brief Get the count of child objects
*
* @param wxobject Object
* @return Number of child objects
*/
virtual std::size_t GetChildCount(wxObject* wxobject) const = 0;
/**
* @brief Get a child object
*
* @param wxobject Object
* @param childIndex Child index
* @return Child object at childIndex
*/
virtual wxObject* GetChild(wxObject* wxobject, std::size_t childIndex) const = 0;
/**
* @brief Get the parent object
*
* @param wxobject Object
* @return Parent object of object
*/
virtual wxObject* GetParent(wxObject* wxobject) const = 0;
/**
* @brief Get the object interface of the parent object
*
* @param wxobject Object
* @return Object interface of parent object of object
*/
virtual IObject* GetIParent(wxObject* wxobject) const = 0;
/**
* @brief Select the object in the object tree
*
* @param wxobject The object to select
* @return True, if the selection did change, false, if the object was already selected
*/
virtual bool SelectObject(wxObject* wxobject) = 0;
/**
* @brief Modify the property of the object
*
* @param wxobject Object to modify
* @param property Property to modify
* @param value New value of the property
* @param allowUndo If true, the property change will be placed into the undo stack, otherwise the change will be
* silent
*/
virtual void ModifyProperty(
wxObject* wxobject, const wxString& property, const wxString& value, bool allowUndo = true) = 0;
/**
* @brief Create a wxNoObject
*
* TODO: This shall ensure that these objects are created in the main application and the dynamic cast to test for
* them does work there, but is this really necessary? All other objects are created inside the plugin and
* deleted by wxWidgets in the main application.
*
* @return A wxNoObject
*/
virtual wxNoObject* NewNoObject() = 0;
};
/**
* @brief Base interface of a plugin component
*
* A plugin component implements the functionality to create objects of a specific type for usage by the main
* application.
*/
class IComponent
{
public:
/**
* @brief Type of the component
*/
enum class Type {
/// Non-visual element, won't be inserted into a wxWindow hierarchy
Abstract = 0,
/// Visual element that will be inserted into a wxWindow hierarchy
Window,
/// Sizer element
Sizer,
};
public:
virtual ~IComponent() = default;
/**
* @return Type of this component
*/
virtual Type GetType() const = 0;
/**
* @brief Get the component library of this object
*
* @return The component library of this object, this is never nullptr
*/
virtual IComponentLibrary* GetLibrary() const = 0;
/**
* @brief Create a new object
*
* @param obj Properties of the object to create
* @param parent Parent object of the object to create
* @return The created object
*/
virtual wxObject* Create(IObject* obj, wxObject* parent) = 0;
/**
* @brief Perform additional cleanup actions before deleting the object
*
* This function gets called just before the object is about to be deleted
* and allows to perform additional cleanup actions.
*
* @param wxobject Object created by Create(IObject*, wxObject*)
*/
virtual void Cleanup(wxObject* wxobject) = 0;
/**
* @brief Callback function executed after the creation of the object
*
* This function gets called after the object has been created and registered into
* the internal data structure. This function can be used to perform additional steps,
* e.g. abstract components like notebookpage or sizeritem can add the created widget to
* the notebook or sizer.
*
* @param wxobject The object that was created
* @param wxparent The parent object of the created object
*/
virtual void OnCreated(wxObject* wxobject, wxWindow* wxparent) = 0;
/**
* @brief Callback function executed after the object has been selected in the object tree
*
* This function can be used to perform additional steps after the object has been selected,
* e.g. after selecting a notebookpage the notebook could switch to that page.
*
* @param wxobject The selected object
*/
virtual void OnSelected(wxObject* wxobject) = 0;
/**
* @brief Export object properties into a XRC node
*
* @param xrc Target node, must be an empty node
* @param obj Object properties
* @return On success, xrc is returned, otherwise nullptr
*/
virtual tinyxml2::XMLElement* ExportToXrc(tinyxml2::XMLElement* xrc, const IObject* obj) = 0;
/**
* @brief Import object properties from a XRC node
*
* The properties are converted into a XML node of a wxFormBuilder project file
*
* @param xfb Target node, must be an empty node
* @param xrc XRC node
* @return On success, xfb is returned, otherwise nullptr
*/
virtual tinyxml2::XMLElement* ImportFromXrc(tinyxml2::XMLElement* xfb, const tinyxml2::XMLElement* xrc) = 0;
};
/**
* @brief Component library interface of a plugin
*
* This interface is used by the plugin to register all its components.
* The main application uses this interface to access the components of the plugin.
*/
class IComponentLibrary
{
public:
virtual ~IComponentLibrary() = default;
/**
* @brief Register a component
*
* @param name Name of the component
* @param component Component implementation, ownership is claimed
*/
virtual void RegisterComponent(const wxString& name, IComponent* component) = 0;
/**
* @brief Register a macro
*
* @param macro Symbolic name of the macro
* @param value Value of the macro
*/
virtual void RegisterMacro(const wxString& macro, int value) = 0;
/**
* @brief Register a macro synonymous
*
* @param synonymous Synonymous name of the macro
* @param macro Symbolic name of the macro
*/
virtual void RegisterSynonymous(const wxString& synonymous, const wxString& macro) = 0;
/**
* @brief Get the used manager object
*
* @return Manager object, this is never nullptr
*/
virtual IManager* GetManager() const = 0;
/**
* @brief Replace a macro synonymous by the macro itself
*
* @param synonymous Synonymous name of the macro
* @param replaced If not nullptr, set to true if a replacement was done, otherwise to false
* @return The macro name or synonymous if the given value is not a synonymous of a macro
*/
virtual wxString ReplaceSynonymous(const wxString& synonymous, bool* replaced = nullptr) const = 0;
/**
* @brief Get all registered components
*
* @return All registered comonents, the objects are owned by this instance and must not be deleted
*/
virtual std::vector<std::pair<wxString, IComponent*>> GetComponents() const = 0;
/**
* @brief Get all registered macros
*
* @return All registered macros
*/
virtual std::vector<std::pair<wxString, int>> GetMacros() const = 0;
};
// The component library interface functions are part of a statically linked library that
// gets linked into a shared library. The implementation itself is done directly inside the
// shared library though. Since the shared library is loaded dynamically and the functions
// are resolved dynamically, this very limited export specification is sufficient.
#ifdef BUILD_DLL
#define DLL_FUNC extern "C" WXEXPORT
#else
#define DLL_FUNC extern "C"
#endif
/**
* @brief Create a component library object
*
* Creates a new instance of the component library of the plugin using the given manager object.
*
* @param manager Manager object used by the component library
* @return The component library object
*/
DLL_FUNC IComponentLibrary* CreateComponentLibrary(IManager* manager);
/**
* @brief Deletes a component library object
*
* @param lib The component library object, it must have been created by this plugin
*/
DLL_FUNC void FreeComponentLibrary(IComponentLibrary* lib);
#endif // SDK_PLUGIN_INTERFACE_COMPONENT_H
|