mGNCS API Reference  v1.5.0
A new control set and a new framework for MiniGUI apps
mcomponent.h
Go to the documentation of this file.
1 //
3 // IMPORTANT NOTICE
4 //
5 // The following open source license statement does not apply to any
6 // entity in the Exception List published by FMSoft.
7 //
8 // For more information, please visit:
9 //
10 // https://www.fmsoft.cn/exception-list
11 //
13 
54 #ifndef _MGUI_NCSCTRL_CMPT_H
55 #define _MGUI_NCSCTRL_CMPT_H
56 
57 #ifdef __cplusplus
58 extern "C"{
59 #endif
60 
61 #include <stdarg.h>
62 
73 #define MAXLEN_CLASSNAME 31
74 
79 #define NCSCLASSNAME(name) name _MGNCS_CLASS_SUFFIX
80 
81 #define BEGIN_CMPT_CLASS(clss, superCls) \
82  static const char comp_##clss##_class_name[] = (#clss _MGNCS_CLASS_SUFFIX) ; \
83  BEGIN_MINI_CLASS(clss, superCls) \
84  _class->className = comp_##clss##_class_name + 1;
85 
86 #define END_CMPT_CLASS END_MINI_CLASS
87 
88 #ifndef BIND_PROP
89 #define BIND_PROP
90 typedef struct _mBindProp mBindProp;
91 #endif
92 
93 typedef void (*PFreeSpecificData)(DWORD key, DWORD value);
94 
95 #define MAX_USER_SPECIAL_KEY 0x80000000L
96 
97 typedef struct _mComponentClass mComponentClass;
98 typedef struct _mComponent mComponent;
99 
100 #define mComponentClassHeader(clss, superCls) \
101  mObjectClassHeader(clss, superCls) \
102  const char* className; \
103  clss * (*createComponent)(mComponent* parent, ClassType(clss)*, DWORD addValue); \
104  WNDPROC _window_proc ; \
105  BOOL (*setProperty)(clss *self, int id, DWORD value); \
106  DWORD (*getProperty)(clss *self, int id); \
107  int (*setId)(clss *self, int id); \
108  int (*getId)(clss *self); \
109  mComponent* (*getReleated)(clss*self, int releated); \
110  mComponent* (*setReleated)(clss *self, mComponent* comp, int releated); \
111  mComponent* (*getChild)(clss* self, int id); \
112  void (*removeChild)(clss* self, mComponent* child); \
113  PUBLIC DWORD (*getPropertyByPath)(clss* self, int *id_path); \
114  PUBLIC BOOL (*setPropertyByPath)(clss* self, int *id_path, DWORD value); \
115  PUBLIC BOOL (*addEventListenerByPath)(clss* self, int *id_path, mObject* listener, NCS_CB_ONOBJEVENT on_event); \
116  PUBLIC BOOL (*addBindPropByPath)(clss* self, int *id_path, int event_id, int prop_type, int flags, mBindProp *prop, int bind_type); \
117  PUBLIC BOOL (*queryByPath)(clss* self, int *id_path, DWORD *pret, ...); \
118  PUBLIC BOOL (*vqueryByPath)(clss* self, int *id_path, DWORD* pret, va_list va); \
119  PUBLIC BOOL (*isMainObj)(clss* self); \
120  BOOL (*setSpecificData)(clss* self, DWORD key, DWORD value, PFreeSpecificData freeSpecific); \
121  DWORD (*getSpecificData)(clss* self, DWORD key, BOOL *pOk);
122 
207 };
251 };
252 
253 struct _mComponentClass {
254  mComponentClassHeader(mComponent, mObject)
255 };
256 
257 MGNCS_EXPORT mComponent *ncsCompGetMainParent(mComponent*self);
258 
259 MGNCS_EXPORT mComponent *ncsCompGetRoot(mComponent* self);
260 
261 #define IDPATH_END -1
262 
263 #define IDPATH_ME -2
264 #define IDPATH_PARENT -3
265 #define IDPATH_MAINPARENT -4
266 #define IDPATH_ROOT -5
267 
268 #define ISVALID_IDPATH(id_path) \
269  ((id_path) && (id_path)[0] != IDPATH_END)
270 
271 #define IDPATH_ISOBJ(id_path) \
272  ((id_path)[1] != IDPATH_END)
273 
274 #define BYPATHFUNCEX(baseclass, base_check, err_ret, func, finaly_func_ex, ...) do{ \
275  mComponent* cmp; \
276  if(!ISVALID_IDPATH(id_path)) \
277  return 0; \
278  while(IDPATH_ISOBJ(id_path)) { \
279  if(id_path[0] == IDPATH_ME){ \
280  id_path ++; \
281  continue; \
282  } else if(id_path[0] == IDPATH_PARENT) \
283  cmp = _c(self)->getReleated(self, NCS_CMPT_PARENT); \
284  else if(id_path[0] == IDPATH_MAINPARENT) \
285  cmp = ncsCompGetMainParent((mComponent*)self); \
286  else if(id_path[0] == IDPATH_ROOT) \
287  cmp = ncsCompGetRoot((mComponent*)self); \
288  else \
289  cmp = _c(self)->getChild(self, id_path[0]); \
290  if(!cmp && base_check(cmp,baseclass)) return err_ret; \
291  return _c(baseclass*)->func((baseclass*)cmp, ++id_path, ##__VA_ARGS__); \
292  } \
293  finaly_func_ex(self, id_path[0], ##__VA_ARGS__); \
294 }while(0)
295 
296 #define BYPATHFUNC(baseclass, base_check,err_ret, func, final_func, ...) \
297  BYPATHFUNCEX(baseclass, base_check,err_ret, func, return (_c(self)->final_func), ##__VA_ARGS__)
298 
299 #define IDPATH_NOBASECHECK(cmp, baseclass) 1
300 
305 MGNCS_EXPORT extern mComponentClass g_stmComponentCls; //Class(mComponent);
306 
313 typedef struct _NCS_EVENT_HANDLER_NODE {
317  UINT message;
325  void *handler;
331 
332 typedef struct _mSpecificDataNode {
333  DWORD key;
334  DWORD value;
335  PFreeSpecificData freeSpecific;
336  struct _mSpecificDataNode* next;
337 }mSpecificDataNode;
338 
339 #define mComponentHeader(clss) \
340  mObjectHeader(clss) \
341  NCS_EVENT_HANDLER_NODE * event_handlers; \
342  mSpecificDataNode* specificHead;
343 
354 struct _mComponent {
355  mComponentHeader(mComponent)
356 };
357 
370 
378 typedef struct _NCS_EVENT_HANDLER {
382  UINT message;
386  void *handler;
388 
401 MGNCS_EXPORT void * ncsSetComponentHandler(mComponent* comp, UINT message, void *handler);
402 
416 MGNCS_EXPORT void ncsSetComponentHandlers(mComponent* comp, NCS_EVENT_HANDLER* handlers, int count);
417 
427 MGNCS_EXPORT void* ncsGetComponentHandler(mComponent* comp, UINT message);
428 
435 typedef struct _NCS_EVENT_CONNECT_INFO {
447  int event_id;
451  NCS_CB_ONOBJEVENT event;
453 
464 MGNCS_EXPORT BOOL ncsComponentConnectEvents(mComponent* comps, NCS_EVENT_CONNECT_INFO *connects, int counts/*=-1*/);
465 
475 MGNCS_EXPORT BOOL ncsIsClass(const char* className, mComponentClass* clss);
476 
483 #define ISCLASS(class_name, clssName) ncsIsClass((const char*)(class_name), (mComponentClass*)(&Class(clssName)))
484 
494 MGNCS_EXPORT BOOL ncsIsChildClass(const char* childClassName, const char* parentClassName);
495 
510 MGNCS_EXPORT BOOL ncsRegisterComponent(mComponentClass *compCls, DWORD dwStyle, DWORD dwExStyle, int idCursor, int idBkColor);
511 
523 MGNCS_EXPORT mComponentClass * ncsGetComponentClass(const char* className, BOOL check);
524 
525 MGNCS_EXPORT mComponentClass * ncsClassFromMagicNum(DWORD magic_num, BOOL check, const char* class_name);
526 
529 #define MGNCS_REGISTER_COMPONENT_EX(className, dwStyle, dwExStyle, idCursor, idBkColor) \
530  do {if(!ncsRegisterComponent((mComponentClass*)MGNCS_INIT_CLASS(className), \
531  dwStyle, dwExStyle, idCursor, idBkColor)) \
532  return FALSE;}while(0)
533 
534 /* NOTE: use WE_BGC_WINDOW as the default background color instead of WE_MAINC_THREED_BODY */
535 #define MGNCS_REGISTER_COMPONENT(className) \
536  MGNCS_REGISTER_COMPONENT_EX(className, \
537  WS_NONE, WS_EX_NONE, IDC_ARROW, WE_BGC_WINDOW)
538 
539 #define MGNCS_UNREG_COMPONENT(clssName) \
540  UnregisterWindowClass(Class(clssName).className)
541 
542 #define NCS_SET_PROP(self, id, value) \
543  _c(self)->setProperty(self, (id), (value))
544 #define NCS_GET_PROP(self, id) \
545  _c(self)->getProperty(self, (id))
546 
549 #ifdef __cplusplus
550 }
551 #endif
552 
553 #endif
554 
mComponent
the component member define
ncsIsChildClass
MGNCS_EXPORT BOOL ncsIsChildClass(const char *childClassName, const char *parentClassName)
check a class name is derived class of a special class
mObject
the Object struct
_NCS_EVENT_CONNECT_INFO
Definition: mcomponent.h:435
NCS_CMPT_PREV
@ NCS_CMPT_PREV
prev sliding component
Definition: mcomponent.h:204
ncsSetComponentHandler
MGNCS_EXPORT void * ncsSetComponentHandler(mComponent *comp, UINT message, void *handler)
set the component handler
NCS_EVENT_HANDLER
struct _NCS_EVENT_HANDLER NCS_EVENT_HANDLER
g_stmComponentCls
MGNCS_EXPORT mComponentClass g_stmComponentCls
the singleton of mComponentClass
ncsGetComponentClass
MGNCS_EXPORT mComponentClass * ncsGetComponentClass(const char *className, BOOL check)
Get a mComponentClass instance from MiniGUI.
NCS_CMPT_CHILDREN
@ NCS_CMPT_CHILDREN
the first child component
Definition: mcomponent.h:206
_NCS_EVENT_HANDLER
Definition: mcomponent.h:378
ncsIsClass
MGNCS_EXPORT BOOL ncsIsClass(const char *className, mComponentClass *clss)
check a class name is a special class type or not
_NCS_EVENT_CONNECT_INFO::event
NCS_CB_ONOBJEVENT event
Definition: mcomponent.h:451
_NCS_EVENT_CONNECT_INFO::event_id
int event_id
Definition: mcomponent.h:447
_NCS_EVENT_CONNECT_INFO::id_sender
int id_sender
Definition: mcomponent.h:439
ncsSetComponentHandlers
MGNCS_EXPORT void ncsSetComponentHandlers(mComponent *comp, NCS_EVENT_HANDLER *handlers, int count)
set an array of event handlers
ncsComponentReleated
ncsComponentReleated
The releation between components.
Definition: mcomponent.h:202
_NCS_EVENT_HANDLER::handler
void * handler
Definition: mcomponent.h:386
QPC_USER
@ QPC_USER
Definition: mcomponent.h:250
ncsComponentConnectEvents
MGNCS_EXPORT BOOL ncsComponentConnectEvents(mComponent *comps, NCS_EVENT_CONNECT_INFO *connects, int counts)
connect the events between parent and its children, used by ncsCreateMainWindowIndirectFromID
_NCS_EVENT_HANDLER::message
UINT message
Definition: mcomponent.h:382
_NCS_EVENT_HANDLER_NODE::message
UINT message
Definition: mcomponent.h:317
_NCS_EVENT_HANDLER_NODE
Definition: mcomponent.h:313
NCS_CMPT_PARENT
@ NCS_CMPT_PARENT
the parent component
Definition: mcomponent.h:205
NCS_EVENT_CONNECT_INFO
struct _NCS_EVENT_CONNECT_INFO NCS_EVENT_CONNECT_INFO
ncsRegisterComponent
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...
QPC_ADD_BIND
@ QPC_ADD_BIND
Definition: mcomponent.h:246
_NCS_EVENT_HANDLER_NODE::next
struct _NCS_EVENT_HANDLER_NODE * next
Definition: mcomponent.h:329
NCS_CMPT_NEXT
@ NCS_CMPT_NEXT
next sliding component
Definition: mcomponent.h:203
QPC_GET_PROP
@ QPC_GET_PROP
Definition: mcomponent.h:238
mComponentQueryCmd
mComponentQueryCmd
queryByPath and vqueryByPath's cmd_id
Definition: mcomponent.h:230
_NCS_EVENT_HANDLER_NODE::handler
void * handler
Definition: mcomponent.h:325
QPC_ADD_EVENT
@ QPC_ADD_EVENT
Definition: mcomponent.h:242
mComponentClass
the basic class of components, windows. Drived by mObjectClass
ncsGetComponentHandler
MGNCS_EXPORT void * ncsGetComponentHandler(mComponent *comp, UINT message)
get an event callback
NCS_EVENT_HANDLER_NODE
struct _NCS_EVENT_HANDLER_NODE NCS_EVENT_HANDLER_NODE
QPC_SET_PROP
@ QPC_SET_PROP
Definition: mcomponent.h:234
_NCS_EVENT_CONNECT_INFO::id_listener
int id_listener
Definition: mcomponent.h:443