15 KiB
Chapter 3 of Part 2 Introduction of the Foundation Class
mObject
Introduction of mObject
mObject is the foundation class of all mGNCS, it:
- Encapsulates mGNCS inheritance and virtual function realization
- Defines the most fundamental class member structure
At the same time, a group of operation functions are defined to control the behavior of class
The class is foundation class and cannot be used directly
- Direct child class:
mComponent
Operation Function of mObject
In NCS, many operations about class have mObject pointer as the parameter,
and these are
- Type judgment operation:
ncsInstanceOf,equivalent to instanceof of operator of java, case of judging if a pointer is the appointed class
%CODE{cpp}%
/**
- \fn
BOOLncsInstanceOf(mObject*object,mObjectClass*clss); - \brief check an object is the class instance or not,
- same as \b instanceof operator in Java
- \param object - the pointer of object being to test
- \param clss - the pointer of class for test
- \return
TRUE- object is instance of clss,FALSE- not */BOOLncsInstanceOf(mObject*object,mObjectClass*clss);
Example
%CODE{cpp}%
if(INSTANCEOF(obj, mWidget)) //Judge if object obj is a mWidget object
.....
Corresponding macro is %CODE{cpp}% /**
- \def
CHECKOBJ - \brief the wrapper of
ncsIsValidObj - \sa
ncsIsValidObj*/ #defineCHECKOBJ(obj)ncsIsValidObj((mObject*)obj)
Corresponding macro is %CODE{cpp}% /**
- \def
SAFE_CAST - \brief wrapper of
ncsSafeCast,check the class type before cast. - \note this macro is same as \b
dynamic_castin C++ - \sa
ncsSafeCast*/ #defineSAFE_CAST(Type,obj)
TYPE_CAST(Type,ncsSafeCast((mObject*)obj,(mObjectClass*)(void*)(&(Class(Type)))))
- Other functions:
newObject,deleteOBject,TYPENAMEmacro. %CODE{cpp}% /**
- \fn
mObject*newObject(mObjectClass*_class); - \brief new a object instance, like \b new operator in C++
- \param _class - the class of the object
- \return the new pointer of object
/
mObject * newObject(mObjectClass _class);
/
- \fn void
deleteObject(mObject*obj); - \brief delete a object intance, like \b delete operator in C++
- \param obj - the object want to delete
*/
void deleteObject(mObject *obj);
/**
- \def
TYPENAME - \brief Get the class name form a Object pointer
*/
#define
TYPENAME(obj)((obj)?(((obj)->_class)?((obj)->_class)->typeName:""):"")
- Set property of the component
- Return:
TRUE– setting successful;FALSE–setting failed - Params
- int id -
IDof property DWORDvalue – property value
getProperty
%CODE{cpp}%DWORD(*getProperty)(clss *_this, int id);
- Set Id of the component
- Return: return old Id
- Params
- int id - new id
getId
%CODE{cpp}% int (*getId)(clss *_this);
- Get components related to the component, such as parent component, child component and brother component
- Return:
NULLor corresponding component object pointer - Params:
- int releated: relation type: one of
NCS_COMP_NEXT,NCS_COMP_PREV,NCS_COMP_PARENTandNCS_COMP_CHILDREN
setReleated:%CODE{cpp}%mComponent*(*setReleated)(clss *_this,mComponent*comp, int releated);
- Get child component appointed by id
- Return :
NULLor corresponding component pointer - Params:
- int id – id of the component to get
Operation Function of mComponent
Component supports some universal operations
- Event installation and unloading function
%CODE{cpp}% /**
- A struct of event-handler map
- \note only used for param
- \sa
NCS_EVENT_HANDLER_NODE/ typedef struct _NCS_EVENT_HANDLER { /* - The event code / int message; /*
- The event callback pointer */ void *handler; }NCS_EVENT_HANDLER;
/**
- \fn void *
ncsSetComponentHandler(mComponent*comp, int message, void *handler); - \brief set the component handler
- \param comp the compont to set
- \param message the event code
- \param handler the event callback pointer
- \return old event callback if it has been set
- \sa
ncsSetComponentHandlers*/ void *ncsSetComponentHandler(mComponent*comp, int message, void *handler);
/**
- \fn void
ncsSetComponentHandlers(mComponent*comp,
NCS_EVENT_HANDLER*handlers,
int count); - \brief set an array of event handlers
- \param comp - the component to set
- \param handlers - the array of \ref
NCS_EVENT_HANDLER - \param count - the count of array handlers.
- \note if count == -1, handlers must end by {-1,
NULL}; - anywhere,
ncsSetComponentHandlerswould stop - if it find an element of array handlers is equal {-1,
NULL}, - whether count is equal -1 or not
- \sa
ncsSetComponentHandler*/ voidncsSetComponentHandlers(mComponent*comp,
NCS_EVENT_HANDLER*handlers,
int count);
/**
- \fn void*
ncsGetComponentHandler(mComponent*comp, int message); - \brief get an event callback
- \param comp
- \param message - event code
- \return void * the handler of message, or
NULLif not set / voidncsGetComponentHandler(mComponent*comp, int message);
mWidget
Introduction of mWidget
mWidget is the foundation class of all the controls
- Inherited from
mComponent - Direct child class
mStaticmButtonmPanelmScrollWidgetmProgressBarmPropSheetmSlidermSpinbox
Style of mWidget
| *Style ID* | Property Name of miniStudio | Explanation ||
| NCSS_NOTIFY | Notify | Decide if the control generates Notification event |
Property of mWidget
| Property name |Property name of miniStudio | Type | RW | Explanation |
| NCSP_WIDGET_RDR | Renderer |const char* | W | Set current renderer of the control |
| NCSP_WIDGET_TEXT | Text |const char* | W | Set text content of the current control |
| NCSP_WIDGET_BKIMAGE | BkImage |PBITMAP | RW | Set or get current background image |
| NCSP_WIDGET_BKIMAGE_MODE| BkImageMode | ImageDrawMode | Set or get current background image drawing mode |
| NCSP_WIDGET_BKIMAGE_FILE | - |const char* | Set current background image, and automatically load from the file name |
Method of mWidget
None
Event of mWidget
MSG_NCCREATE- Description: the first message of the window when the window non client area is created. Now the window is still not built, and the functions with the window sentence handle as the parameter cannot be called
- Callback: void (*
NCS_CB_ONNCCREATE)(mWidget*);
- Returned value: none
- Parameter
mWidget* event generator object pointer
MSG_CREATE- Description: generated when the window is created.
- Callback: typedef
BOOL(*)NCS_CB_ONCREATE(mWidget *,DWORDdwAddData)
- Returned value:
TRUE– continue creating;FALSE– exit creating - Parameter
mWidget*DWORDdwAddDataadditional data
- Notification message
- All the events generated from the notification message use the callback
- void (*
NCS_CB_NOTIFY)(mWidget*, intnc_code);
- Returned value: none
- Parameter
mWidget* event generator object pointer- int
nc_code: event notification code, used to distinguish different events
*Note: Callback of all the notification events is NCS_CB_NOTIFY*
Operation Function of mWidget
- Functions that create controls %CODE{cpp}% /**
- A struct wrap the
NCS_CREATE_INFO - \note only allowed using in \ref
ncsCreateMainWindow - Don't use it directly
- \sa
NCS_CREATE_INFO,ncsCreateMainWindow,ncsCreateMainWindowIndirect/ typedef struct _NCS_MAIN_CREATE_INFO { /* - The class name of a
mMainWndor its child class - \note if
classNameisNULLor an invalidate class name - \ref
ncsCreateMainWindowandncsCreateMainWindowIndirect - use \ref
CTRL_MINIMAINWNDreplaced - \sa
CTRL_MINIMAINWND/ const charclassName;/** NCS_CREATE_INFOpointer */NCS_CREATE_INFO*create_info;}NCS_MAIN_CREATE_INFO;
/**
- \fn
mWidget*ncsCreateMainWindow(const char *class_name, const char *caption, DWORDstyle,DWORDex_style,\- int id, int x, int y, int w, int h,
HWNDhost, \ HICONhIcon,HMENUhMenu,NCS_PROP_ENTRY* props, \NCS_RDR_INFO*rdr_info,\NCS_EVENT_HANDLER* handlers, \DWORDadd_data);- \brief create a NCS main window
- \param
class_namethe class name of widget. - the class name must be register by \ref
ncsRegisterComponent. - And must be \ref
CTRL_MINIMAINWNDor its dirved class. - \param caption the caption of the main window
- \param style the style of main window
- \param
ex_stylethe extend style of main window - \param id the id of main window
- \param x the x position of main window
- \param y the y position of main window
- \param w the width of main window
- \param h the height of main window
- \param host the handle of host window, can be
NULL - \param
hIconthe icon of main window - \param
hMenuthe menu bar handle - \param props the properties array pointer, end by {-1, 0} if it's not
NULL - \param
rdr_infothe renderer info pointer - \param handlers the handlers of event array pointer,
- end by {-1,
NULL},if it's notNULL - \param
add_datathe additional data send to callback \refNCS_CB_ONCREATE - and \ref
NCS_CB_ONINITDLG - \return
mWidget*- amWidgetpointer, must be amMainWndinstance - \sa
ncsCreateWindow,ncsCreateWindowIndirect,nscCreateMainWindowIndirect, NCS_PROP_ENTRY,NCS_RDR_INFO,NCS_EVENT_HANDLER,NCS_CB_ONCREATE,mWidget,mInvisibleComponent,mMainWnd
*/
mWidget* ncsCreateMainWindow (const char *class_name, const char *caption,
DWORD style, DWORD ex_style,
int id, int x, int y, int w, int h, HWND host,
HICON hIcon, HMENU hMenu,
NCS_PROP_ENTRY * props,
NCS_RDR_INFO * rdr_info,
NCS_EVENT_HANDLER * handlers,
DWORD add_data);
/**
- A struct include all the creating info, used by
ncsCreateWindowIndirect - \sa
NCS_CREATE_INFO/ struct _NCS_WND_TEMPLATE{ /* - The class name of
mComponent,must be registered by \refncsRegisterComponent - \note support \ref
mInvisibleComponentclass / const charclass_name;/** - The id of commponet / int id; /*
- The Location and Size of
mWidget,ignored ifclass_name - is a \ref
mInvisibleComponent/ int x, y, w, h; /* - The style of
mWidget,ignored ifclass_nameis a \refmInvisibleComponent/DWORDstyle; /* - The extend style of
mWidget,ignored ifclass_nameis a \refmInvisibleComponent/DWORDex_style;/* - The caption of
mWidget,ignored ifclass_nameis a \refmInvisibleComponent/ const char caption;
//same struct as NCS_CREATE_INFO
/**
- Same as
NCS_CREATE_INFO - \sa
NCS_CREATE_INFO*/NCS_PROP_ENTRY*props;NCS_RDR_INFO*rdr_info;NCS_EVENT_HANDLER*handlers;NCS_WND_TEMPLATE*ctrls; int count;DWORDuser_data;
//FIXED ME Maybe I should not put these two param here
DWORD bk_color;
PLOGFONT font;
};
//create control window indirect /**
- \fn
mWidget*ncsCreateWindowIndirect(constNCS_WND_TEMPLATE*tmpl,HWNDhParent); - \brief create a
mComponentby \refNCS_WND_TEMPLATE, - \param tmpl the template pointer
- \param
hParentthe parent handle, ifNCS_WND_TEMPLATE. - is a \ref
mInvisibleComponent,hParentmust releated amWidgetobject - \return
mWidget*- then pointer of object orNULLif failed - \sa
ncsCreateWindow,NCS_WND_TEMPLATE*/mWidget*ncsCreateWindowIndirect(constNCS_WND_TEMPLATE*tmpl,HWNDhParent);
/**
- A struct include all the creating info for
ncsCreateMainWindowIndirect, - \note same as \ref
ncsCreateMainWindow's params - \sa
NCS_WND_TEMPLATE,ncsCreateMainWindow/ typedef struct _NCS_MAINWND_TEMPLATE{ const charclass_name;int id; int x, y, w, h;DWORDstyle;DWORDex_style;const char* caption;
NCS_PROP_ENTRY* props;
NCS_RDR_INFO* rdr_info;
NCS_EVENT_HANDLER* handlers;
NCS_WND_TEMPLATE* ctrls;
int count;
DWORD user_data;
//FIXED ME Maybe I should not put these two param here
DWORD bk_color;
PLOGFONT font;
HICON hIcon;
HMENU hMenu;
}NCS_MAINWND_TEMPLATE;
/**
- \fn
mWidget*ncsCreateMainWindowIndirect(constNCS_MAINWND_TEMPLATE*tmpl,HWNDhHost); - \biref create a main window from a template
- \param tmpl - the template of main window
- \param
hHost- the host window handler of the main window - \return
mWidget* - the Instance ofmMainWndorNULL - \sa
ncsCreateMainWindow,NCS_MAINWND_TEMPLATE*/mWidget*ncsCreateMainWindowIndirect(constNCS_MAINWND_TEMPLATE*tmpl,HWNDhHost);
Example of mWidget
mWidget cannot be used directly
[Next](MStudioMGNCSV1dot0PGENP1C2][Previous]] < MStudioMGNCSV1dot0PGEN][Index > [[MStudioMGNCSV1dot0PGENP2C4)
-- Main.XiaodongLi - 24 Feb 2010
<< | Table of Contents | >>