mcomponent.h

Go to the documentation of this file.
00001 
00016 #ifndef _MGUI_NCSCTRL_CMPT_H
00017 #define _MGUI_NCSCTRL_CMPT_H
00018 
00019 #ifdef __cplusplus
00020 extern "C"{
00021 #endif
00022 
00023 #include <stdarg.h>
00024 
00034 #define MAXLEN_CLASSNAME    15
00035 
00039 #define NCSCLASSNAME(name)     name _MGNCS_CLASS_SUFFIX
00040 
00041 #define BEGIN_CMPT_CLASS(clss, superCls) \
00042         static const char comp_##clss##_class_name[] = (#clss _MGNCS_CLASS_SUFFIX) ; \
00043         BEGIN_MINI_CLASS(clss, superCls) \
00044         _class->className = comp_##clss##_class_name + 1; 
00045 
00046 #define END_CMPT_CLASS END_MINI_CLASS
00047 
00048 #ifndef BIND_PROP
00049 #define BIND_PROP
00050 typedef struct _mBindProp mBindProp;
00051 #endif
00052 
00053 typedef void (*PFreeSpecificData)(DWORD key, DWORD value);
00054 
00055 #define MAX_USER_SPECIAL_KEY   0x80000000L
00056 
00057 typedef struct _mComponentClass mComponentClass;
00058 typedef struct _mComponent mComponent;
00059 
00060 #define mComponentClassHeader(clss, superCls) \
00061         mObjectClassHeader(clss, superCls) \
00062         const char* className; \
00063         clss * (*createComponent)(mComponent* parent, ClassType(clss)*, DWORD addValue); \
00064         WNDPROC _window_proc ; \
00065         BOOL (*setProperty)(clss *self, int id, DWORD value); \
00066         DWORD (*getProperty)(clss *self, int id); \
00067         int (*setId)(clss *self, int id); \
00068         int (*getId)(clss *self); \
00069         mComponent* (*getReleated)(clss*self, int releated); \
00070         mComponent* (*setReleated)(clss *self, mComponent* comp,  int releated); \
00071         mComponent* (*getChild)(clss* self, int id);  \
00072         void        (*removeChild)(clss* self, mComponent* child);  \
00073         PUBLIC DWORD (*getPropertyByPath)(clss* self, int *id_path); \
00074         PUBLIC BOOL  (*setPropertyByPath)(clss* self, int *id_path, DWORD value); \
00075         PUBLIC BOOL  (*addEventListenerByPath)(clss* self, int *id_path, mObject* listener, NCS_CB_ONOBJEVENT on_event); \
00076         PUBLIC BOOL  (*addBindPropByPath)(clss* self, int *id_path, int event_id, int prop_type, int flags, mBindProp *prop, int bind_type); \
00077         PUBLIC BOOL  (*queryByPath)(clss* self, int *id_path, DWORD *pret, ...); \
00078         PUBLIC BOOL  (*vqueryByPath)(clss* self, int *id_path, DWORD* pret, va_list va); \
00079         PUBLIC BOOL  (*isMainObj)(clss* self);  \
00080         BOOL  (*setSpecificData)(clss* self, DWORD key, DWORD value, PFreeSpecificData freeSpecific); \
00081         DWORD (*getSpecificData)(clss* self, DWORD key, BOOL *pOk);
00082 
00162 enum ncsComponentReleated{
00163         NCS_CMPT_NEXT = 0,
00164         NCS_CMPT_PREV,
00165         NCS_CMPT_PARENT,
00166         NCS_CMPT_CHILDREN
00167 };
00190 enum mComponentQueryCmd{
00194         QPC_SET_PROP = 0,
00198         QPC_GET_PROP,
00202         QPC_ADD_EVENT,
00206         QPC_ADD_BIND,
00210         QPC_USER
00211 };
00212 
00213 struct _mComponentClass {
00214         mComponentClassHeader(mComponent, mObject)
00215 };
00216 
00217 MGNCS_EXPORT mComponent *ncsCompGetMainParent(mComponent*self);
00218 
00219 MGNCS_EXPORT mComponent *ncsCompGetRoot(mComponent* self);
00220 
00221 #define IDPATH_END -1
00222 
00223 #define IDPATH_ME     -2
00224 #define IDPATH_PARENT -3
00225 #define IDPATH_MAINPARENT -4
00226 #define IDPATH_ROOT -5
00227 
00228 #define ISVALID_IDPATH(id_path) \
00229         ((id_path) && (id_path)[0] != IDPATH_END)
00230 
00231 #define IDPATH_ISOBJ(id_path) \
00232         ((id_path)[1] != IDPATH_END)
00233 
00234 #define BYPATHFUNCEX(baseclass, base_check, err_ret, func, finaly_func_ex, ...) do{ \
00235         mComponent* cmp; \
00236         if(!ISVALID_IDPATH(id_path)) \
00237                 return 0;  \
00238         while(IDPATH_ISOBJ(id_path)) { \
00239                 if(id_path[0] == IDPATH_ME){ \
00240                         id_path ++; \
00241                         continue; \
00242                 } else if(id_path[0] == IDPATH_PARENT) \
00243                         cmp = _c(self)->getReleated(self, NCS_CMPT_PARENT); \
00244                 else if(id_path[0] == IDPATH_MAINPARENT) \
00245                         cmp = ncsCompGetMainParent((mComponent*)self); \
00246                 else if(id_path[0] == IDPATH_ROOT) \
00247                         cmp = ncsCompGetRoot((mComponent*)self); \
00248                 else  \
00249                         cmp = _c(self)->getChild(self, id_path[0]); \
00250                 if(!cmp && base_check(cmp,baseclass)) return err_ret; \
00251                 return _c(baseclass*)->func((baseclass*)cmp, ++id_path, ##__VA_ARGS__); \
00252         } \
00253         finaly_func_ex(self, id_path[0], ##__VA_ARGS__); \
00254 }while(0)
00255 
00256 #define BYPATHFUNC(baseclass, base_check,err_ret, func, final_func, ...) \
00257         BYPATHFUNCEX(baseclass, base_check,err_ret, func, return (_c(self)->final_func), ##__VA_ARGS__)
00258 
00259 #define IDPATH_NOBASECHECK(cmp, baseclass)   1
00260 
00265 MGNCS_EXPORT extern mComponentClass g_stmComponentCls; //Class(mComponent);
00266 
00273 typedef struct _NCS_EVENT_HANDLER_NODE {
00277         int message;
00285         void *handler;
00289         struct _NCS_EVENT_HANDLER_NODE *next;
00290 }NCS_EVENT_HANDLER_NODE;
00291 
00292 typedef struct _mSpecificDataNode {
00293         DWORD key;
00294         DWORD value;
00295         PFreeSpecificData freeSpecific;
00296         struct _mSpecificDataNode* next;
00297 }mSpecificDataNode;
00298 
00299 #define mComponentHeader(clss) \
00300         mObjectHeader(clss) \
00301         NCS_EVENT_HANDLER_NODE * event_handlers; \
00302         mSpecificDataNode* specificHead;
00303 
00314 struct _mComponent {
00315         mComponentHeader(mComponent)
00316 };
00317 
00330 
00331 
00338 typedef struct _NCS_EVENT_HANDLER {
00342         int message;
00346         void *handler;
00347 }NCS_EVENT_HANDLER;
00348 
00361 MGNCS_EXPORT void * ncsSetComponentHandler(mComponent* comp, int message, void *handler);
00362 
00376 MGNCS_EXPORT void ncsSetComponentHandlers(mComponent* comp, NCS_EVENT_HANDLER* handlers, int count);
00377 
00387 MGNCS_EXPORT void* ncsGetComponentHandler(mComponent* comp, int message);
00388 
00395 typedef struct _NCS_EVENT_CONNECT_INFO {
00399         int id_sender;
00403         int id_listener;
00407         int event_id;
00411         NCS_CB_ONOBJEVENT event;
00412 }NCS_EVENT_CONNECT_INFO;
00413 
00424 MGNCS_EXPORT BOOL ncsComponentConnectEvents(mComponent* comps, NCS_EVENT_CONNECT_INFO *connects, int counts/*=-1*/);
00425 
00435 MGNCS_EXPORT BOOL ncsIsClass(const char* className, mComponentClass* clss);
00436 
00443 #define ISCLASS(class_name, clssName) ncsIsClass((const char*)(class_name), (mComponentClass*)(&Class(clssName)))
00444 
00454 MGNCS_EXPORT BOOL ncsIsChildClass(const char* childClassName, const char* parentClassName);
00455 
00470 MGNCS_EXPORT BOOL ncsRegisterComponent(mComponentClass *compCls, DWORD dwStyle, DWORD dwExStyle, int idCursor, int idBkColor);
00471 
00483 MGNCS_EXPORT mComponentClass * ncsGetComponentClass(const char* className, BOOL check);
00484 
00485 MGNCS_EXPORT mComponentClass * ncsClassFromMagicNum(DWORD magic_num, BOOL check, const char* class_name);
00486 
00489 #define MGNCS_REGISTER_COMPONENT_EX(className, dwStyle, dwExStyle, idCursor, idBkColor) \
00490         do {if(!ncsRegisterComponent((mComponentClass*)MGNCS_INIT_CLASS(className), \
00491                 dwStyle, dwExStyle, idCursor, idBkColor)) \
00492                 return FALSE;}while(0)
00493 
00494 #define MGNCS_REGISTER_COMPONENT(className) \
00495         MGNCS_REGISTER_COMPONENT_EX(className, \
00496                 WS_NONE, WS_EX_NONE, IDC_ARROW, WE_MAINC_THREED_BODY)
00497 
00498 #define MGNCS_UNREG_COMPONENT(clssName) \
00499         UnregisterWindowClass(Class(clssName).className)        
00500 
00501 #define NCS_SET_PROP(self, id, value) \
00502         _c(self)->setProperty(self, (id), (value))
00503 #define NCS_GET_PROP(self, id)        \
00504         _c(self)->getProperty(self, (id))
00505 
00508 #ifdef __cplusplus
00509 }
00510 #endif
00511 
00512 #endif
00513 
Generated on Fri Jun 10 11:18:06 2011 for New Control Set V1.0.0 API Reference by  doxygen 1.6.3