mGNCS API Reference  v1.2.0
A new control set and a new framework for MiniGUI apps
mcomponent.h
Go to the documentation of this file.
1 
42 #ifndef _MGUI_NCSCTRL_CMPT_H
43 #define _MGUI_NCSCTRL_CMPT_H
44 
45 #ifdef __cplusplus
46 extern "C"{
47 #endif
48 
49 #include <stdarg.h>
50 
61 #define MAXLEN_CLASSNAME 31
62 
67 #define NCSCLASSNAME(name) name _MGNCS_CLASS_SUFFIX
68 
69 #define BEGIN_CMPT_CLASS(clss, superCls) \
70  static const char comp_##clss##_class_name[] = (#clss _MGNCS_CLASS_SUFFIX) ; \
71  BEGIN_MINI_CLASS(clss, superCls) \
72  _class->className = comp_##clss##_class_name + 1;
73 
74 #define END_CMPT_CLASS END_MINI_CLASS
75 
76 #ifndef BIND_PROP
77 #define BIND_PROP
78 typedef struct _mBindProp mBindProp;
79 #endif
80 
81 typedef void (*PFreeSpecificData)(DWORD key, DWORD value);
82 
83 #define MAX_USER_SPECIAL_KEY 0x80000000L
84 
85 typedef struct _mComponentClass mComponentClass;
86 typedef struct _mComponent mComponent;
87 
88 #define mComponentClassHeader(clss, superCls) \
89  mObjectClassHeader(clss, superCls) \
90  const char* className; \
91  clss * (*createComponent)(mComponent* parent, ClassType(clss)*, DWORD addValue); \
92  WNDPROC _window_proc ; \
93  BOOL (*setProperty)(clss *self, int id, DWORD value); \
94  DWORD (*getProperty)(clss *self, int id); \
95  int (*setId)(clss *self, int id); \
96  int (*getId)(clss *self); \
97  mComponent* (*getReleated)(clss*self, int releated); \
98  mComponent* (*setReleated)(clss *self, mComponent* comp, int releated); \
99  mComponent* (*getChild)(clss* self, int id); \
100  void (*removeChild)(clss* self, mComponent* child); \
101  PUBLIC DWORD (*getPropertyByPath)(clss* self, int *id_path); \
102  PUBLIC BOOL (*setPropertyByPath)(clss* self, int *id_path, DWORD value); \
103  PUBLIC BOOL (*addEventListenerByPath)(clss* self, int *id_path, mObject* listener, NCS_CB_ONOBJEVENT on_event); \
104  PUBLIC BOOL (*addBindPropByPath)(clss* self, int *id_path, int event_id, int prop_type, int flags, mBindProp *prop, int bind_type); \
105  PUBLIC BOOL (*queryByPath)(clss* self, int *id_path, DWORD *pret, ...); \
106  PUBLIC BOOL (*vqueryByPath)(clss* self, int *id_path, DWORD* pret, va_list va); \
107  PUBLIC BOOL (*isMainObj)(clss* self); \
108  BOOL (*setSpecificData)(clss* self, DWORD key, DWORD value, PFreeSpecificData freeSpecific); \
109  DWORD (*getSpecificData)(clss* self, DWORD key, BOOL *pOk);
110 
195 };
239 };
240 
241 struct _mComponentClass {
242  mComponentClassHeader(mComponent, mObject)
243 };
244 
245 MGNCS_EXPORT mComponent *ncsCompGetMainParent(mComponent*self);
246 
247 MGNCS_EXPORT mComponent *ncsCompGetRoot(mComponent* self);
248 
249 #define IDPATH_END -1
250 
251 #define IDPATH_ME -2
252 #define IDPATH_PARENT -3
253 #define IDPATH_MAINPARENT -4
254 #define IDPATH_ROOT -5
255 
256 #define ISVALID_IDPATH(id_path) \
257  ((id_path) && (id_path)[0] != IDPATH_END)
258 
259 #define IDPATH_ISOBJ(id_path) \
260  ((id_path)[1] != IDPATH_END)
261 
262 #define BYPATHFUNCEX(baseclass, base_check, err_ret, func, finaly_func_ex, ...) do{ \
263  mComponent* cmp; \
264  if(!ISVALID_IDPATH(id_path)) \
265  return 0; \
266  while(IDPATH_ISOBJ(id_path)) { \
267  if(id_path[0] == IDPATH_ME){ \
268  id_path ++; \
269  continue; \
270  } else if(id_path[0] == IDPATH_PARENT) \
271  cmp = _c(self)->getReleated(self, NCS_CMPT_PARENT); \
272  else if(id_path[0] == IDPATH_MAINPARENT) \
273  cmp = ncsCompGetMainParent((mComponent*)self); \
274  else if(id_path[0] == IDPATH_ROOT) \
275  cmp = ncsCompGetRoot((mComponent*)self); \
276  else \
277  cmp = _c(self)->getChild(self, id_path[0]); \
278  if(!cmp && base_check(cmp,baseclass)) return err_ret; \
279  return _c(baseclass*)->func((baseclass*)cmp, ++id_path, ##__VA_ARGS__); \
280  } \
281  finaly_func_ex(self, id_path[0], ##__VA_ARGS__); \
282 }while(0)
283 
284 #define BYPATHFUNC(baseclass, base_check,err_ret, func, final_func, ...) \
285  BYPATHFUNCEX(baseclass, base_check,err_ret, func, return (_c(self)->final_func), ##__VA_ARGS__)
286 
287 #define IDPATH_NOBASECHECK(cmp, baseclass) 1
288 
293 MGNCS_EXPORT extern mComponentClass g_stmComponentCls; //Class(mComponent);
294 
301 typedef struct _NCS_EVENT_HANDLER_NODE {
305  UINT message;
313  void *handler;
319 
320 typedef struct _mSpecificDataNode {
321  DWORD key;
322  DWORD value;
323  PFreeSpecificData freeSpecific;
324  struct _mSpecificDataNode* next;
325 }mSpecificDataNode;
326 
327 #define mComponentHeader(clss) \
328  mObjectHeader(clss) \
329  NCS_EVENT_HANDLER_NODE * event_handlers; \
330  mSpecificDataNode* specificHead;
331 
342 struct _mComponent {
343  mComponentHeader(mComponent)
344 };
345 
358 
366 typedef struct _NCS_EVENT_HANDLER {
370  UINT message;
374  void *handler;
376 
389 MGNCS_EXPORT void * ncsSetComponentHandler(mComponent* comp, UINT message, void *handler);
390 
404 MGNCS_EXPORT void ncsSetComponentHandlers(mComponent* comp, NCS_EVENT_HANDLER* handlers, int count);
405 
415 MGNCS_EXPORT void* ncsGetComponentHandler(mComponent* comp, UINT message);
416 
423 typedef struct _NCS_EVENT_CONNECT_INFO {
435  int event_id;
441 
452 MGNCS_EXPORT BOOL ncsComponentConnectEvents(mComponent* comps, NCS_EVENT_CONNECT_INFO *connects, int counts/*=-1*/);
453 
463 MGNCS_EXPORT BOOL ncsIsClass(const char* className, mComponentClass* clss);
464 
471 #define ISCLASS(class_name, clssName) ncsIsClass((const char*)(class_name), (mComponentClass*)(&Class(clssName)))
472 
482 MGNCS_EXPORT BOOL ncsIsChildClass(const char* childClassName, const char* parentClassName);
483 
498 MGNCS_EXPORT BOOL ncsRegisterComponent(mComponentClass *compCls, DWORD dwStyle, DWORD dwExStyle, int idCursor, int idBkColor);
499 
511 MGNCS_EXPORT mComponentClass * ncsGetComponentClass(const char* className, BOOL check);
512 
513 MGNCS_EXPORT mComponentClass * ncsClassFromMagicNum(DWORD magic_num, BOOL check, const char* class_name);
514 
517 #define MGNCS_REGISTER_COMPONENT_EX(className, dwStyle, dwExStyle, idCursor, idBkColor) \
518  do {if(!ncsRegisterComponent((mComponentClass*)MGNCS_INIT_CLASS(className), \
519  dwStyle, dwExStyle, idCursor, idBkColor)) \
520  return FALSE;}while(0)
521 
522 /* NOTE: use WE_BGC_WINDOW as the default background color instead of WE_MAINC_THREED_BODY */
523 #define MGNCS_REGISTER_COMPONENT(className) \
524  MGNCS_REGISTER_COMPONENT_EX(className, \
525  WS_NONE, WS_EX_NONE, IDC_ARROW, WE_BGC_WINDOW)
526 
527 #define MGNCS_UNREG_COMPONENT(clssName) \
528  UnregisterWindowClass(Class(clssName).className)
529 
530 #define NCS_SET_PROP(self, id, value) \
531  _c(self)->setProperty(self, (id), (value))
532 #define NCS_GET_PROP(self, id) \
533  _c(self)->getProperty(self, (id))
534 
537 #ifdef __cplusplus
538 }
539 #endif
540 
541 #endif
542 
struct _NCS_EVENT_HANDLER_NODE NCS_EVENT_HANDLER_NODE
ncsComponentReleated
The releation between components.
Definition: mcomponent.h:190
MGNCS_EXPORT mComponentClass g_stmComponentCls
the singleton of mComponentClass
struct _NCS_EVENT_HANDLER_NODE * next
Definition: mcomponent.h:317
the Object struct
the parent component
Definition: mcomponent.h:193
prev sliding component
Definition: mcomponent.h:192
next sliding component
Definition: mcomponent.h:191
MGNCS_EXPORT void * ncsSetComponentHandler(mComponent *comp, UINT message, void *handler)
set the component handler
the first child component
Definition: mcomponent.h:194
MGNCS_EXPORT void * ncsGetComponentHandler(mComponent *comp, UINT message)
get an event callback
MGNCS_EXPORT void ncsSetComponentHandlers(mComponent *comp, NCS_EVENT_HANDLER *handlers, int count)
set an array of event handlers
struct _NCS_EVENT_HANDLER NCS_EVENT_HANDLER
the component member define
MGNCS_EXPORT BOOL ncsIsChildClass(const char *childClassName, const char *parentClassName)
check a class name is derived class of a special class
MGNCS_EXPORT BOOL ncsIsClass(const char *className, mComponentClass *clss)
check a class name is a special class type or not
the basic class of components, windows. Drived by mObjectClass
MGNCS_EXPORT BOOL ncsRegisterComponent(mComponentClass *compCls, DWORD dwStyle, DWORD dwExStyle, int idCursor, int idBkColor)
register a component class into MiniGUI, so that ncsCreateWindow and ncsCreateWindow can find a mComp...
MGNCS_EXPORT mComponentClass * ncsGetComponentClass(const char *className, BOOL check)
Get a mComponentClass instance from MiniGUI.
mComponentQueryCmd
queryByPath and vqueryByPath&#39;s cmd_id
Definition: mcomponent.h:218
MGNCS_EXPORT BOOL ncsComponentConnectEvents(mComponent *comps, NCS_EVENT_CONNECT_INFO *connects, int counts)
connect the events between parent and its children, used by ncsCreateMainWindowIndirectFromID ...
BOOL(* NCS_CB_ONOBJEVENT)(mObject *self, mObject *sender, int eventId, DWORD param)
The Callback of connection.
Definition: mobject.h:499
struct _NCS_EVENT_CONNECT_INFO NCS_EVENT_CONNECT_INFO
NCS_CB_ONOBJEVENT event
Definition: mcomponent.h:439