00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00022 #ifndef _MGUI_NCSCTRL_WIDGET_H
00023 #define _MGUI_NCSCTRL_WIDGET_H
00024
00025
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029
00030
00031 #define TOWIDGET(x) ((mWidget *)x)
00032 #define TOWIDGETCLASS(x) ((mWidgetClass *)x)
00033
00034 #define RendererType(className) className##Renderer
00035
00036
00046 #define NCSCTRL_WIDGET NCSCLASSNAME("widget")
00047
00048 typedef struct _mWidgetClass mWidgetClass;
00049 typedef struct _mWidget mWidget;
00050
00055 typedef struct _NCS_WND_TEMPLATE NCS_WND_TEMPLATE;
00056
00057
00058
00059
00060 typedef struct _mWidgetRenderer mWidgetRenderer;
00061
00062 #define mWidgetRendererHeader(clsName, parentClass) \
00063 const char* rdr_name; \
00064 \
00065 void (*class_init)(RendererType(clsName)* rdr); \
00066 RendererType(parentClass) *ptrParentClass; \
00067 BOOL (*init_self)(RendererType(clsName) *rdr); \
00068 void (*uninit_self)(RendererType(clsName) *rdr); \
00069 void * prv_data; \
00070 \
00071 void (*drawFocusFrame)(clsName*, HDC, const RECT* ); \
00072 BOOL (*drawBkground)(clsName*, HDC, const RECT*); \
00073 void (*draw3dbox)(clsName*, HDC, const RECT*, DWORD,DWORD); \
00074 void (*drawCheckbox)(clsName*, HDC, const RECT*, DWORD); \
00075 void (*drawRadio)(clsName*, HDC, const RECT*, DWORD); \
00076 void (*drawArrow)(clsName*, HDC, const RECT*, int arrow,DWORD, DWORD); \
00077 void (*drawItem)(clsName*, HDC, const RECT*, DWORD);
00078
00083 enum ncsRendererState{
00084 NCSRS_NORMAL = 0x00,
00085 NCSRS_HIGHLIGHT = 0x01,
00086 NCSRS_SIGNIFICANT = 0x02,
00087 NCSRS_SELECTED = 0x04,
00088 NCSRS_HALFSELECTED = 0x10,
00089 NCSRS_DISABLE = 0x08
00090 };
00117 #define NCSR_STATUS(flag) ((flag)&0xFFFF)
00118
00123 enum ncsRendererFlag{
00124 NCSRF_INNERFRAME = 0x010000,
00125 NCSRF_FILL = 0x020000,
00126 NCSRF_FRAME = 0x040000,
00127 };
00145 enum ncsRDRArrow {
00146 NCSR_ARROW_LEFT = 0,
00147 NCSR_ARROW_RIGHT,
00148 NCSR_ARROW_UP,
00149 NCSR_ARROW_DOWN
00150 };
00255 struct _mWidgetRenderer {
00256 mWidgetRendererHeader(mWidget, mWidget)
00257 };
00258
00259
00260 #define NCSSPEC_OBJ_CONTENT MAX_USER_SPECIAL_KEY + 1
00261
00262 #define mWidgetHeader(clsName) \
00263 mComponentHeader(clsName) \
00264 HWND hwnd; \
00265 RendererType(clsName) *renderer; \
00266 mComponent* comps; \
00267 ImageDrawInfo bkimg; \
00268 mObject *body;
00269
00288 struct _mWidget
00289 {
00290 mWidgetHeader(mWidget)
00291 };
00292
00293 #define mWidgetClassHeader(clsName, parentClass) \
00294 mComponentClassHeader(clsName, parentClass) \
00295 DWORD dlgCode; \
00296 mObject * (*createBody)(clsName*); \
00297 int (*wndProc)(clsName* , int, WPARAM, LPARAM); \
00298 BOOL (*callUserHandler)(clsName* self, void *handler, \
00299 int message, WPARAM wParam, LPARAM lParam, int *pRet); \
00300 BOOL (*onCreate)(clsName*, LPARAM); \
00301 BOOL (*addChildren)(clsName*, NCS_WND_TEMPLATE* children,int count); \
00302 void (*onPaint)(clsName*, HDC, const PCLIPRGN pClip); \
00303 int (*onLButtonDown)(clsName*, int x, int y, DWORD keyFlags); \
00304 int (*onLButtonUp)(clsName*, int x, int y, DWORD keyFlags); \
00305 int (*onMouseMove)(clsName*, int x, int y, DWORD keyFlags); \
00306 int (*onKeyDown)(clsName*, int scancode, DWORD keyFlags); \
00307 int (*onKeyUp)(clsName*, int scancode, DWORD keyFlags); \
00308 int (*onSizeChanged)(clsName*, RECT* rtClient); \
00309 BOOL (*onEraseBkgnd)(clsName*, HDC hdc, const RECT* invRect); \
00310 \
00311 BOOL (*refresh)(clsName *);
00312
00313
00340 struct _mWidgetClass
00341 {
00342 mWidgetClassHeader(mWidget, mComponent)
00343 };
00344
00345 #define SET_DLGCODE(code) _class->dlgCode = (code);
00346
00353 MGNCS_EXPORT extern mWidgetClass g_stmWidgetCls;
00354
00355
00356
00357
00363 enum mWidgetProp{
00364 NCSP_WIDGET_RDR = 1,
00365 NCSP_WIDGET_TEXT,
00366 NCSP_WIDGET_BKIMAGE,
00367 NCSP_WIDGET_BKIMAGE_MODE,
00368 NCSP_WIDGET_BKIMAGE_FILE,
00369 NCSP_WIDGET_MAX
00370 };
00417 #define NCSS_NOTIFY (0x1)
00418
00419 #define IsNotify(self) \
00420 (GetWindowStyle(self->hwnd)&NCSS_NOTIFY)
00421
00422 #define NCSS_WIDGET_SHIFT 1
00423
00424
00425
00426
00427
00428 #define NCSS_EX_UNNEEDIME 0x1
00429
00435 enum mWidgetNotify {
00436 NCSN_WIDGET_CLICKED = 1,
00437 NCSN_WIDGET_DBCLICKED,
00438 NCSN_WIDGET_ENABLED,
00439 NCSN_WIDGET_DISABLED,
00440 NCSN_WIDGET_MAX
00441 };
00442
00471 #define NCSR_CONTINUE_MSG FALSE
00472
00479 #define NCSR_STOP_MSG TRUE
00480
00491 typedef void (*NCS_CB_ONNCCREATE)(mWidget*);
00492
00507 typedef BOOL (*NCS_CB_ONCREATE)(mWidget*, DWORD dwAddData);
00508
00522 typedef BOOL (*NCS_CB_ONINITDLG)(mWidget*, HWND hFocus, DWORD dwAddData);
00523
00534 typedef BOOL (*NCS_CB_ONVOID)(mWidget*, int message);
00546 typedef void (*NCS_CB_ONSZCHGING)(mWidget*, const PRECT prcExpect, PRECT prcResult);
00547
00561 typedef BOOL (*NCS_CB_ONSZCHGED)(mWidget*,PRECT prcClient);
00562
00574 typedef void (*NCS_CB_ONCSZCHGED)(mWidget*, int clientWidth, int clientHeight);
00575
00587 typedef BOOL (*NCS_CB_ONFONTCHGING)(mWidget*, PLOGFONT logFont);
00600 typedef BOOL (*NCS_CB_ONERASEBKGND)(mWidget*, HDC hdc, const PRECT clip);
00610 typedef void (*NCS_CB_ONPAINT)(mWidget*, HDC hdc, const PCLIPRGN clipRgn);
00619 typedef BOOL (*NCS_CB_ONCLOSE)(mWidget*);
00620
00634 typedef BOOL (*NCS_CB_ONKEY)(mWidget*, int message, int code, DWORD keyStatus);
00635
00649 typedef BOOL(*NCS_CB_ONMOUSE)(mWidget*, int message, int x, int y, DWORD keyStatus);
00663 typedef BOOL (*NCS_CB_ONNCMOUSE)(mWidget*, int message, int x, int y, int hitCode);
00675 typedef int (*NCS_CB_ONHITTEST)(mWidget*, int message,int x, int y);
00676
00686 typedef void (*NCS_CB_ONSCROLL)(mWidget*, int message, int code, int pos);
00698 typedef BOOL (*NCS_CB_ONCMD)(mWidget*, int id, int nc, HWND hCtrl);
00707 typedef void (*NCS_CB_WIDGET_ONTIMER)(mWidget*, int id, DWORD count);
00720 typedef int (*NCS_CB_ONMSG)(mWidget*, int message, WPARAM wParam, LPARAM lParam);
00730 typedef void (*NCS_CB_NOTIFY)(mWidget*, int id, int ncCode, DWORD addData);
00731
00738 #define NCS_NOTIFY_CODE(code) (0xFFFF0000 | (code))
00739
00743 #define NCS_MAP_NOTIFY(code, handler) { NCS_NOTIFY_CODE(code), (void*)(handler) }
00744
00745
00747 void mWidget_captureHotPiece(mWidget *self, mObject *hotpice);
00748 mObject * mWidget_getCapturedHotPiece(mWidget *self);
00749 void mWidget_releaseCapturedHotPiece(void);
00750
00751 void mWidget_setHoveringFocus(mWidget *self, mObject *hotpiece);
00752 mObject * mWidget_getHoveringFocus(mWidget *self);
00753 void mWidget_releaseHoveringFocus(void);
00754
00755 void mWidget_setInputFocus(mWidget *self, mObject *hotpiece);
00756 mObject * mWidget_getInputFocus(mWidget *self);
00757 void mWidget_releaseInputFocus(void);
00758
00759 #ifdef _MGNCS_GUIBUILDER_SUPPORT
00760
00761
00762 #define NCSP_DEFAULT_CONTENT 10000
00763 #endif
00764
00765
00789 MGNCS_EXPORT BOOL ncsSetFont (HWND hWnd, const char *fontName);
00790
00803 MGNCS_EXPORT BOOL ncsSetProperty(HWND hWnd, int id, DWORD value);
00815 MGNCS_EXPORT DWORD ncsGetProperty(HWND hWnd, int id);
00816
00824 typedef struct _NCS_PROP_ENTRY {
00828 int id;
00832 DWORD value;
00833 }NCS_PROP_ENTRY;
00834
00842 typedef struct _NCS_RDR_ELEMENT {
00846 int id;
00850 DWORD value;
00851 }NCS_RDR_ELEMENT;
00852
00858 typedef struct _NCS_RDR_INFO {
00862 const char* glb_rdr;
00866 const char* ctl_rdr;
00870 NCS_RDR_ELEMENT* elements;
00871 }NCS_RDR_INFO;
00872
00883 typedef struct _NCS_CREATE_NOTIFY_INFO {
00884 void (*onCreated)(struct _NCS_CREATE_NOTIFY_INFO*, mComponent* , DWORD special_id);
00885 }NCS_CREATE_NOTIFY_INFO;
00886
00887 typedef struct _NCS_CREATE_INFO{
00893 NCS_PROP_ENTRY * props;
00899 NCS_RDR_INFO * rdr_info;
00905 NCS_EVENT_HANDLER *handlers;
00911 NCS_WND_TEMPLATE * ctrls;
00915 int ctrl_count;
00919 DWORD user_data;
00920
00921
00930 DWORD bk_color;
00934 const char* font_name;
00935
00936
00937 HICON hIcon;
00938 HMENU hMenu;
00939
00940 NCS_CREATE_NOTIFY_INFO * notify_info;
00941 DWORD special_id;
00942
00943 }NCS_CREATE_INFO;
00944
00977 MGNCS_EXPORT mWidget* ncsCreateWindow (const char *className, const char *caption, DWORD style, DWORD exStyle, \
00978 int id, int x, int y, int w, int h, HWND parent, \
00979 NCS_PROP_ENTRY * props, \
00980 NCS_RDR_INFO * rdrInfo, \
00981 NCS_EVENT_HANDLER * handlers, \
00982 DWORD addData);
00983
00992 typedef struct _NCS_MAIN_CREATE_INFO {
01002 const char* className;
01006 NCS_CREATE_INFO * create_info;
01007 }NCS_MAIN_CREATE_INFO;
01008
01045 MGNCS_EXPORT mWidget* ncsCreateMainWindow (const char *className, const char *caption,
01046 DWORD style, DWORD exStyle, \
01047 int id, int x, int y, int w, int h, HWND host, \
01048 HICON hIcon, HMENU hMenu,
01049 NCS_PROP_ENTRY * props, \
01050 NCS_RDR_INFO * rdrInfo, \
01051 NCS_EVENT_HANDLER * handlers, \
01052 DWORD addData);
01053
01059 struct _NCS_WND_TEMPLATE{
01065 const char* class_name;
01069 int id;
01073 int x, y, w, h;
01077 DWORD style;
01081 DWORD ex_style;
01085 const char* caption;
01086
01087
01093 NCS_PROP_ENTRY* props;
01094 NCS_RDR_INFO* rdr_info;
01095 NCS_EVENT_HANDLER* handlers;
01096 NCS_WND_TEMPLATE* ctrls;
01097 int count;
01098 DWORD user_data;
01099
01100
01101 DWORD bk_color;
01102 const char* font_name;
01103
01104
01105 HICON hIcon;
01106 HMENU hMenu;
01107
01108 NCS_CREATE_NOTIFY_INFO * notify_info;
01109 DWORD special_id;
01110 };
01111
01112
01125 MGNCS_EXPORT mWidget* ncsCreateWindowIndirect( const NCS_WND_TEMPLATE* tmpl, HWND hParent);
01126
01134 typedef struct _NCS_MNWND_TEMPLATE{
01135 const char* class_name;
01136 int id;
01137 int x, y, w, h;
01138 DWORD style;
01139 DWORD ex_style;
01140 const char* caption;
01141
01142 NCS_PROP_ENTRY* props;
01143 NCS_RDR_INFO* rdr_info;
01144 NCS_EVENT_HANDLER* handlers;
01145 NCS_WND_TEMPLATE* ctrls;
01146 int count;
01147 DWORD user_data;
01148
01149
01150 DWORD bk_color;
01151 const char* font_name;
01152
01153 HICON hIcon;
01154 HMENU hMenu;
01155
01156
01157 NCS_CREATE_NOTIFY_INFO * notify_info;
01158 DWORD special_id;
01159
01160 }NCS_MNWND_TEMPLATE;
01161
01173 MGNCS_EXPORT mWidget* ncsCreateMainWindowIndirect(const NCS_MNWND_TEMPLATE* tmpl, HWND hHost);
01174
01186 MGNCS_EXPORT mWidgetClass* ncsGetMainWndClass(const char* className);
01187
01199 MGNCS_EXPORT void ncsNotifyParentEx(mWidget * self, int code, DWORD addData);
01200
01201 #define ncsNotifyParent(self, code) ncsNotifyParentEx((mWidget*)self, code, 0)
01202
01211 static inline mWidget* ncsObjFromHandle(HWND hwnd)
01212 {
01213 if(IsWindow(hwnd))
01214 return (mWidget*)(GetWindowAdditionalData2(hwnd));
01215 return NULL;
01216 }
01217
01227 static inline mWidget* ncsGetChildObj(HWND hwnd, int id)
01228 {
01229 mWidget * self = ncsObjFromHandle(hwnd);
01230 return (mWidget*)(self?_c(self)->getChild(self, id):NULL);
01231 }
01232
01241 static inline mWidget* ncsGetParentObj(HWND hwnd)
01242 {
01243 return ncsObjFromHandle(GetParent(hwnd));
01244 }
01245
01246
01255 static inline DWORD ncsGetDlgCode(HWND hwnd)
01256 {
01257
01258 #if 0
01259 mWidget * widget;
01260 if((widget=ncsObjFromHandle(hwnd)))
01261 {
01262 return _c(widget)->dlgCode;
01263 }
01264 return 0;
01265 #endif
01266 return (DWORD)SendMessage(hwnd, MSG_GETDLGCODE, 0, 0);
01267 }
01268
01274 MGNCS_EXPORT void ncsDestroyWindow(mWidget* self, DWORD endCode);
01275
01276 #define ncsDeleteWidget(self) ncsDestroyWindow(self, 0)
01277
01278
01279 #define NCS_FETCH_MSGBINDINFO(sender, param, lParam) do{ \
01280 void ** __tmp = (void**)(lParam); \
01281 if(__tmp){ \
01282 register DWORD* __param = (DWORD*)(void*)&(param); \
01283 register void** __sender = (void**)(void*)&(sender); \
01284 *__param = (DWORD)__tmp[0]; \
01285 *__sender = __tmp[1]; \
01286 free(__tmp); \
01287 } \
01288 }while(0)
01289
01290 MGNCS_EXPORT BOOL ncsBindEventsToMessage(mObject *sender, HWND hwnd_listener, int message, int* event_ids);
01291 MGNCS_EXPORT BOOL ncsBindEventToMessage(mObject* sender, HWND hwnd_listener, int message, int event_ids);
01292 MGNCS_EXPORT void ncsRemoveBindWindow(HWND hwnd_listener);
01293 MGNCS_EXPORT void ncsRemoveBindMessage(HWND hwnd_listener, int message,mObject* sender, int event_id);
01294
01295
01301 #ifdef __cplusplus
01302 }
01303 #endif
01304
01305 #endif
01306