📄 widget.h
字号:
#ifndef __WIDGET_H
#define __WIDGET_H
#include <wx/window.h>
#include <wx/image.h>
#include <wx/panel.h>
#include <wx/sizer.h>
#include <tinyxml/tinyxml.h>
#include <settings.h>
#include <manager.h>
#include <messagemanager.h>
#include "wxsglobals.h"
#include "wxsproperties.h"
#include "wxswindoweditor.h"
#include "wxsstyle.h"
#define DebLog Manager::Get()->GetMessageManager()->DebugLog
class wxsWidgetManager;
class wxsWidget;
class wxsWidgetEvents;
class wxsEventDesc;
/** Structure containing info aboul widget */
struct wxsWidgetInfo
{
wxString Name; ///< Widget's name
wxString License; ///< Widget's license
wxString Author; ///< Widget's author
wxString AuthorEmail; ///< Widget's authos's email
wxString AuthorSite; ///< Widget's author's site
wxString WidgetsSite; ///< Site about this widget
wxString Category; ///< Widget's category
wxString DefaultVarName; ///< Prefix for default variable name
bool Container; ///< True if this widget can have other widgets inside
bool Sizer; ///< True if this widget is a sizer (Container must also be true)
bool Spacer; ///< True if this is a spacer
unsigned short VerHi; ///< Lower number of version
unsigned short VerLo; ///< Higher number of version
wxBitmap* Icon; ///< Icon used in pallette
wxsWidgetManager* Manager; ///< Manager handling this widget
int Id; ///< Identifier used inside manager to handle this widget, must be same as 'Number' in GetWidgetInfo call
int TreeIconId;
wxsStyle* Styles; ///< Set of available styles, ending with NULL-named style
wxsEventDesc *Events; ///< Set of events supported by this widget, enging with NULL-named entry
wxString HeaderFile; ///< Header file (including '<' and '>' or '"') for this file
wxString ExtHeaderFile; ///< Additional header file
/** Types of extended widgets */
enum ExTypeT
{
exNone = 0, ///< This is widget from standard set (no new coded nor additional library needed)
exCode, ///< This widget provides it's source code, currently not supported
exLibrary ///< This widget is provided in additional library, currently not supported
};
ExTypeT ExType; ///< Type of extended widget
wxString WidgetCodeDefinition; ///< Code with definition of class for this widget
wxString WidgetCodeDeclaration; ///< Code with declaration of class for this widget
wxString WidgetLibrary; ///< Library including this widget (empty for no library)
};
/** Structure describing default widget's options */
struct wxsWidgetBaseParams
{
wxString IdName; ///< Widget's identifier
wxString VarName; ///< Widget's variable used inside main window
bool IsMember; ///< True if widget's variable won't be stored inside main window
int PosX, PosY; ///< Widget's position
bool DefaultPosition; ///< Widget has default position
int SizeX, SizeY; ///< Widget's size
bool DefaultSize; ///< Widget has default size
int Style; ///< Current style
bool Enabled; ///< If false, widget is disabled (true by deefault)
bool Focused; ///< If true, widget is focused (false by default)
bool Hidden; ///< If true, widget is hidden (false by default)
wxUint32 FgType; ///< Type of Fg colour (wxSYS_COLOUR_XXX or wxsCUSTOM_COLOUR or wxsNO_COLOUR)
wxColour Fg; ///< Foreground colour when using custom colour
wxUint32 BgType; ///< Type of Bg colour (wxSYS_COLOUR_XXX or wxsCUSTOM_COLOUR or wxsNO_COLOUR)
wxColour Bg; ///< Background colour when using custom colour
bool UseFont; ///< Must be true to allow using font
wxFont Font; ///< Font
wxString ToolTip; ///< Tooltip
wxsWidgetBaseParams():
IdName(_T("")),
VarName(_T("")),
IsMember(true),
PosX(-1), PosY(-1),
DefaultPosition(true),
SizeX(-1), SizeY(-1),
DefaultSize(true),
Style(0),
Enabled(true),
Focused(false),
Hidden(false),
FgType(wxsNO_COLOUR),
Fg(0,0,0),
BgType(wxsNO_COLOUR),
Bg(0,0,0),
UseFont(false),
Font(wxNullFont),
ToolTip(_T(""))
{}
};
/** Structure containing all data needed while generating code */
struct wxsCodeParams
{
wxString ParentName;
bool IsDirectParent;
int UniqueNumber;
};
/** Class representing one widget */
class wxsWidget
{
public:
/** Type representing base properties set while creating widget */
typedef unsigned long BasePropertiesType;
static const BasePropertiesType bptPosition = 0x0001; ///< this widget is using position
static const BasePropertiesType bptSize = 0x0002; ///< this widget is using size
static const BasePropertiesType bptId = 0x0004; ///< this widget is using identifier
static const BasePropertiesType bptVariable = 0x0008; ///< this widget is using variable
static const BasePropertiesType bptStyle = 0x0010; ///< this widget is using style
static const BasePropertiesType bptEnabled = 0x0020; ///< this widget uses Enabled property
static const BasePropertiesType bptFocused = 0x0040; ///< this widget uses Focused property
static const BasePropertiesType bptHidden = 0x0080; ///< this widget uses Hidden property
static const BasePropertiesType bptColours = 0x0100; ///< this widget uses colour properties (Fg and Bg)
static const BasePropertiesType bptToolTip = 0x0200; ///< this widget uses tooltips
static const BasePropertiesType bptFont = 0x0400; ///< this widget uses font
/** BasePropertiesType with no default properties */
static const BasePropertiesType propNone = 0;
/** VasePropertiesTyue usede by common windows */
static const BasePropertiesType propWindow = bptStyle | bptColours | bptToolTip | bptFont;
/** BasePropertiesType used by common widgets */
static const BasePropertiesType propWidget = bptPosition | bptSize | bptId | bptVariable | bptStyle | bptEnabled | bptFocused | bptHidden | bptColours | bptToolTip | bptFont;
/** BasePropertiesType used by common sizers */
static const BasePropertiesType propSizer = bptVariable;
/** BasePropertiesType used by spacer */
static const BasePropertiesType propSpacer = bptSize;
/** Default constructor */
wxsWidget(wxsWidgetManager* Man,wxsWindowRes* Res,BasePropertiesType pType = propNone);
/** Constructor used by containers
*
* \param Man - widgets manager
* \param ISwxWindow - true if this container is an wxWindow object,
* false otherwise (usually for wxSizer objects
* \param MaxChildren - maximal number of children which can be handled by this container
*/
wxsWidget(wxsWidgetManager* Man, wxsWindowRes* Res, bool ISwxWindow, int MaxChild,BasePropertiesType pType = propNone);
/** Destructor */
virtual ~wxsWidget();
/** Getting widget's info */
virtual const wxsWidgetInfo& GetInfo() = 0;
/** Getting manager of this widget */
inline wxsWidgetManager* GetManager() { return Manager; }
/** Getting parent widget of this one */
inline wxsWidget* GetParent() { return Parent; }
/** Getting resource tree of this widget */
inline wxTreeItemId GetTreeId() { return TreeId; }
/** Getting BasePropertiesType for this widget */
inline BasePropertiesType GetBPType() { return BPType; }
/** Getting resource owning this widget */
inline wxsWindowRes* GetResource() { return Resource; }
/** Getting default properties object */
inline wxsProperties& GetPropertiesObj() { return PropertiesObject; }
/** Getting editor for this widget (or NULL if there's no editor) */
wxsWindowEditor* GetEditor();
/** Getting events object */
wxsWidgetEvents* GetEvents();
/** Function building resource tree for this widget */
void BuildTree(wxTreeCtrl* Tree,wxTreeItemId WhereToAdd,int InsertIndex=-1);
/** Deleting tree for this widget and for all it's children */
void KillTree(wxTreeCtrl* Tree);
/******************************************************************************/
/* Preview */
/******************************************************************************/
public:
/** This should create new preview object */
wxWindow* CreatePreview(wxWindow* Parent,wxsWindowEditor* Editor);
/** This should kill preview object */
void KillPreview();
/** Function returning current pereview window */
inline wxWindow* GetPreview() { return Preview; }
/** Function applying some default properties to preview
*
* Properties applied: Enabled, Focused, Hidden, Colours, Font and ToolTip
*/
void PreviewApplyDefaults(wxWindow* Preview);
/** Function processing mouse event passed from preview */
virtual void PreviewMouseEvent(wxMouseEvent& event) { }
/** Function ensuring that given child widget is visible
*
* This function should be propagated into root widget, the easiest
* way is to call wxsWidget::EnsurePreviewVisible at the end of masking
* function.
*/
virtual void EnsurePreviewVisible(wxsWidget* Child) { if ( GetParent() ) GetParent()->EnsurePreviewVisible(this); }
protected:
/** This function should create preview window for widget.
* It is granted that this funcntion will be called when there's no
* preview yet.
*/
virtual wxWindow* MyCreatePreview(wxWindow* Parent) = 0;
/** This fuunction can be used to update all properties for preview
* after creating it's children.
*/
virtual void MyFinalUpdatePreview(wxWindow* Preview) {}
private:
/** Function used to clear preview if it was deleted from parent level */
void PreviewDestroyed();
/******************************************************************************/
/* Properties */
/******************************************************************************/
public:
/** Function returning base configuration params for this widget */
inline wxsWidgetBaseParams& GetBaseParams() { return BaseParams; }
/** Getting properties window for this widget */
inline wxWindow* CreatePropertiesWindow(wxWindow* Parent)
{
if ( !PropertiesCreated )
{
CreateObjectProperties();
AddParentProperties();
PropertiesCreated = true;
}
if ( !Properties ) Properties = MyCreatePropertiesWindow(Parent);
return Properties;
}
/** getting properties which are currently used */
inline wxWindow* GetProperties() { return Properties; }
/** This should kill properties window */
inline void KillProperties()
{
if ( Properties != NULL )
{
DeleteProperties(Properties);
Properties = NULL;
}
}
/** Function which should update content of current properties window */
virtual void UpdateProperties()
{
if ( Updating ) return;
Updating = true;
MyUpdateProperties();
Updating = false;
}
/** Function notifying that properties were changed inside properties editor
* \param Validate - if true, changed properties should be validated
* \param Correct - if true, invalid properties should be automatically corrected
* \return true - properties valid, false - properties invalid (before correction)
* always returns true if Validate == false
*/
virtual bool PropertiesUpdated(bool Validate,bool Correct);
protected:
/** This function should create properties view for widget. It is granted
* that there are no properties created yet.
*/
virtual wxWindow* MyCreatePropertiesWindow(wxWindow* Parent)
{
return GenBaseParamsConfig(Parent);
}
/** This function should delete properties window. Usually should be
* left as default. Put here to aviod conflicts between different
* memory heaps.
*/
virtual void DeleteProperties(wxWindow* Properties) { delete Properties; }
/** Function which should update content of current properties window */
virtual void MyUpdateProperties()
{
if ( GetProperties() ) PropertiesObject.UpdateProperties();
}
/** Function initializing properties for this widget.
* This should add all properties.
* Call to this function is made when properties window is created for the
* first time
*/
virtual void CreateObjectProperties()
{
AddDefaultProperties(BPType);
}
/** Getting wingow's style */
inline int GetStyle() { return BaseParams.Style; }
/** Getting window's position */
inline wxPoint GetPosition()
{
return BaseParams.DefaultPosition ?
wxDefaultPosition :
wxPoint(BaseParams.PosX,BaseParams.PosY);
}
/** Getting window's size */
inline wxSize GetSize()
{
return BaseParams.DefaultSize ?
wxDefaultSize :
wxSize(BaseParams.SizeX,BaseParams.SizeY);
}
private:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -