📄 widget.h
字号:
inline void AddParentProperties()
{
if ( GetParent() )
{
GetParent()->AddChildProperties(GetParent()->FindChild(this));
}
}
/******************************************************************************/
/* Code generation */
/******************************************************************************/
public:
/** Function generating code which should produce widget
* It's called BEFORE widget's children are created and
* must set up BaseParams.VarName variable inside code.
*/
virtual wxString GetProducingCode(wxsCodeParams& Params) { return _T(""); }
/** Function generating code which finishes production process of this
* widget, it will be called AFTER child widgets are created
*
* It can be used f.ex. by sizers to bind to parent item.
* UniqueNumber is same as in GetProducingCode
*/
virtual wxString GetFinalizingCode(wxsCodeParams& Params) { return _T(""); }
/** Function generating code which generates variable containing this
* widget. If there's no variable (f.ex. space inside sizers), it should
* return empty string
*/
virtual wxString GetDeclarationCode(wxsCodeParams& Params) { return _T(""); }
/** Structure deeclaring some code-defines which could be usefull while
* creating widget's code
*/
struct CodeDefines
{
wxString Style; ///< Widget's style in form 'wxSTYLE1|wxSTYLE2'
wxString Pos; ///< Widget's position
wxString Size; ///< Widget's size
wxString InitCode; ///< Code initializing Enabled / Focused / Hidden flags, Colours, ToolTip and Font
};
/** Function creating current coded defines */
virtual const CodeDefines& GetCodeDefines();
/**********************************************************************/
/* Support for containers */
/**********************************************************************/
/** Checking if this widget is an container */
inline bool IsContainer() { return ContainerType != NoContainer; }
/** Getting max number of children */
inline int GetMaxChildren() { return IsContainer() ? MaxChildren : 0; }
/** Checking if this container is a window (children are connected
* directly to it)
*/
inline bool IsContWindow() { return ContainerType == ContainerWindow; }
/** Getting number of internal widgets */
virtual int GetChildCount() { return 0; }
/** Getting pointer to given child */
virtual wxsWidget* GetChild(int Id) { return NULL; }
/** Function checking if given widget can be added as child,
*
* \param InsertBeforeThis - proposed position, shouldn't be
* considered as certain thing
*/
virtual bool CanAddChild(wxsWidget* NewWidget,int InsertBeforethis = -1) { return false; }
/** Binding child
*
* \param InsertAfterThis - position where to add new widget, if -1,
* adding at the end
*/
virtual int AddChild(wxsWidget* NewWidget,int InsertBeforeThis = -1) { return -1; }
/** Unbinding child
*
* This structure must inbing child window from this one, must NOT delete
* child
*/
virtual bool DelChildId(int Id) { return false; }
/** Unbinding child
*
* This structure must inbing child window from this one, must NOT delete
* child
*/
virtual bool DelChild(wxsWidget* Widget) { return false; }
/** Searching for specified widget
* \param Widget - widget we're looking for
* \param Level - max depth level (0 - unlimited, 1 - direct children only, >1 - children and subchildren)
* \return >= 0 if found (when Level == 1, this value is Id of widget, 0<=Id<ChildCount, otherwise it's 0),
* -1 if there's no such child
*/
virtual int FindChild(wxsWidget* Widget,int Level = 1) { return -1; }
/** Changing position of widget in child list */
virtual bool ChangeChildPos(int PrevPos, int NewPos) { return false; }
protected:
/** Adding additional properties to child object */
virtual void AddChildProperties(int ChildIndex) { }
/** Loading child object from xml node
*
* Note that node passed to this function may contain different
* data. In such case this funcntino should return and only real
* children should be processed.
* Default implementation process <object> Xml elements.
*/
virtual bool XmlLoadChild(TiXmlElement* Element);
/** Saving child to Xml node
*
* Default implementation save <object> Xml element
*/
virtual bool XmlSaveChild(int ChildIndex,TiXmlElement* AddHere);
/**********************************************************************/
/* Support for base widget's parameters */
/**********************************************************************/
protected:
/** Function creating wxPanel object which contains panel with
* configuration of base widget's properties
*/
inline wxWindow* GenBaseParamsConfig(wxWindow* Parent)
{
return PropertiesObject.GenerateWindow(Parent);
}
/** This function updates content of given base properties panel,
* should be called when any operation on preview changes any of
* base properties.
*/
inline void UpdateBaseParamsConfig()
{
PropertiesObject.UpdateProperties();
}
/** Base parameters describing this widget */
wxsWidgetBaseParams BaseParams;
/** Base object used to handle properties */
wxsProperties PropertiesObject;
/******************************************************************************/
/* XML Operations */
/******************************************************************************/
public:
/** Loading widget from xml source */
inline bool XmlLoad(TiXmlElement* Element)
{
XmlAssignElement(Element);
bool Result = MyXmlLoad();
if ( !XmlLoadDefaults() ) Result = false;
XmlAssignElement(NULL);
return Result;
}
inline bool XmlSave(TiXmlElement* Element)
{
XmlAssignElement(Element);
bool Result = MyXmlSave();
if ( !XmlSaveDefaults() ) Result = false;
XmlAssignElement(NULL);
return Result;
}
protected:
/** Internal function loading data from xml tree
*
* This functino can be overriden inside derivedd classes
* to allow loading additional data. This data should be loadedd
* from node returned by XmlElem function (all XmlGet... functions
* are also using this one). See bptxxx and propxxx to find out which
* settings are loaded automatically.
*/
virtual bool MyXmlLoad() { return true; }
/** Internal function saving xml tree.
*
* This function can be overriden inside derived classes
* to allow saving additional data. This data should be saved
* from node returned by XmlElem function (all XmlSet... functions
* are also using this one). See bptxxx and propxxx to find out which
* settings are saved automatically.
*/
virtual bool MyXmlSave() { return true; }
/** Getting currenlty associated xml element */
inline TiXmlElement* XmlElem() { return XmlElement; }
/**********************************************************************/
/* Helpful functions which could be used while operating on resources */
/**********************************************************************/
/** Getting value from given name */
virtual wxString XmlGetVariable(const wxString& Name);
/** Getting integer from given name
*
* \param Name - name of xml tag
* \param IsInvalid - redeference to boolean variable which will get
* information about read success
* \param DefaultValue - value which will be returned in case of any error
* (IsInvalid=true)
* \returns value of variable
*/
virtual int XmlGetInteger(const wxString &Name,bool& IsInvalid,int DefaultValue=0);
/** Getting integer from given name without returning error */
inline int XmlGetInteger(const wxString &Name,int DefaultValue=0)
{
bool Temp;
return XmlGetInteger(Name,Temp,DefaultValue);
}
/** Getting size/position from given name */
virtual bool XmlGetIntPair(const wxString& Name,int& P1,int& P2,int DefP1=-1,int DefP2=-1);
// Added by cyberkoa
/** Getting a series of string with given parent element and child element name */
virtual bool wxsWidget::XmlGetStringArray(const wxString &ParentName,const wxString& ChildName, wxArrayString& stringArray);
//End Add
/** Setting string value */
virtual bool XmlSetVariable(const wxString &Name,const wxString& Value);
/** Setting integer value */
virtual bool XmlSetInteger(const wxString &Name,int Value);
/** Setting 2 integers */
virtual bool XmlSetIntPair(const wxString &Name,int Val1,int Val2);
/** Function assigning element which will be used while processing
* xml resources. Usually this function is calleed automatically
* from outside so there's no need to care about currently
* associateed Xml element. This functino should be called when
* there's need to parse external xml elements using functions
* inside wxsWidget class.
*/
void XmlAssignElement(TiXmlElement* Element);
// Added by cyberkoa
/** Set a series of string with the same given element name */
virtual bool wxsWidget::XmlSetStringArray(const wxString &ParentName,const wxString& ChildName, wxArrayString& stringArray);
//End Add
/** Reading all default values for widget */
inline bool XmlLoadDefaults() { return XmlLoadDefaultsT(BPType); }
/** Reading default values for widget using given set of base properties */
virtual bool XmlLoadDefaultsT(BasePropertiesType pType);
/** Saving all default values for widget */
inline bool XmlSaveDefaults() { return XmlSaveDefaultsT(BPType); }
/** Saving default values for widget using given set of base properties */
virtual bool XmlSaveDefaultsT(BasePropertiesType pType);
/** Loading all children
*
* Valid for compound objects only
*/
virtual bool XmlLoadChildren();
/** Saving all children
*
* Valid for compouund objects only, if current widget is a sizer,
* additional "sizeritem" object will be created
*/
virtual bool XmlSaveChildren();
private:
/** Adding default properties to properties manager */
virtual void AddDefaultProperties(BasePropertiesType Props);
/** Invalidating tree item id for this widget and all of it's children */
void InvalidateTreeIds();
wxsWidgetManager* Manager; ///< Widget's manager
wxWindow* Preview; ///< Currently opened preview window (NULL if there's no one)
wxsWindowRes* Resource; ///< Resource owning this widget
wxWindow* Properties; ///< Currently opened properties window (NULL if there's no one)
wxsWidget* Parent; ///< Parent widget of this one
int MaxChildren; ///< Num of max. Childs, -1 if no limit, valid for containers only
TiXmlElement* XmlElement; ///< Currently selected xml element
enum CType { NoContainer, ContainerSizer, ContainerWindow };
CType ContainerType; ///< Type of container (or mark that it's no container)
bool Updating; ///< Set to true while any update is made (to avoid infinite loops and data loos)
bool PropertiesCreated;
BasePropertiesType BPType; ///< Set of base properties used inside constructor
CodeDefines CDefines; ///< Will be filled and returned inside GetCodedeDefines
wxTreeItemId TreeId; ///< Id of item in resource tree
bool AssignedToTree; ///< True if this widget has it's entry inside resource tree
wxsWidgetEvents* Events; ///< Events used for this widget
friend class wxBaseParamsPanel;
friend class wxsWindowEditor;
friend class wxsContainer;
friend class wxsProject;
friend class wxsPalette;
friend class wxsWidgetFactory;
friend class wxsWindowResDataObject;
};
/** Class managing widget */
class wxsWidgetManager
{
public:
wxsWidgetManager() {}
virtual ~wxsWidgetManager() {}
/** Funcntion initializing manager */
virtual bool Initialize() { return true; }
/** Returns number of handled widgets */
virtual int GetCount() = 0;
/** Getting widget's info */
virtual const wxsWidgetInfo* GetWidgetInfo(int Number) = 0;
/** Getting new widget */
virtual wxsWidget* ProduceWidget(int Id,wxsWindowRes* Res) = 0;
/** Killing widget */
virtual void KillWidget(wxsWidget* Widget) = 0;
/** Fuunction registering this manager into main widget's factory */
virtual bool RegisterInFactory();
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -