From 48caa7cde00a76f016eba7543dc7a31d5afb3dbd Mon Sep 17 00:00:00 2001 From: Vincent Wei Date: Fri, 14 Feb 2020 17:53:03 +0800 Subject: [PATCH] adjust WINDOWINFO, CONTROL, and MAINWIN structures for virtual window; remove iFgColor field in CONTROL, MAINWIN, and CTRLCLASSINFO; add VIRTWIN structure --- include/window.h | 80 ++++++++++++++-------- src/include/ctrlclass.h | 108 +++++++++++++++-------------- src/include/internals.h | 146 ++++++++++++++++++++++------------------ 3 files changed, 191 insertions(+), 143 deletions(-) diff --git a/include/window.h b/include/window.h index bfc6f48d..af5af967 100644 --- a/include/window.h +++ b/include/window.h @@ -3384,7 +3384,7 @@ BOOL GUIAPI Send2ActiveWindow (const MG_Layer* layer, #endif /* _MGRM_PROCESSES */ -#else /* !_MGRM_THREADS */ +#else /* not defined _MGRM_THREADS */ /** * \fn LRESULT PostSyncMessage (HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam) @@ -3429,7 +3429,7 @@ MG_EXPORT LRESULT GUIAPI PostSyncMessage (HWND hWnd, UINT nMsg, WPARAM wParam, L * \sa PostSyncMessage */ MG_EXPORT LRESULT GUIAPI SendAsyncMessage (HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam); -#endif +#endif /* defined _MGRM_THREADS */ /** * \fn int SendNotifyMessage (HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam) @@ -3641,7 +3641,7 @@ MG_EXPORT int GUIAPI ThrowAwayMessages (HWND pMainWnd); */ MG_EXPORT BOOL GUIAPI EmptyMessageQueue (HWND hWnd); -#endif +#endif /* not defined _MGRM_THREADS */ #ifdef _MGHAVE_MSG_STRING @@ -3680,7 +3680,7 @@ MG_EXPORT const char* GUIAPI Message2Str (UINT message); MG_EXPORT void GUIAPI PrintMessage (FILE* fp, HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam); -#endif +#endif /* defined _MGHAVE_MSG_STRING */ /** @} end of msg_pass_fns */ @@ -4400,6 +4400,27 @@ MG_EXPORT HWND GUIAPI RegisterMouseHookWindow (HWND hwnd, DWORD flag); #define WE_LFSKIN_TBSLIDER_V (WE_ATTR_TYPE_RDR | 27) #endif +/** + * \var typedef int (* WNDPROC)(HWND, int, WPARAM, LPARAM) + * \brief Type of the window callback procedure. + */ +typedef LRESULT (* WNDPROC)(HWND, UINT, WPARAM, LPARAM); + +/** + * \var typedef void (* NOTIFPROC)(HWND hwnd, LINT id, int nc, DWORD add_data) + * \brief Type of the notification callback procedure. + * + * This is the function type of Notification Callback Procedure. + * If you set the Notification Callback Procedure for a control, + * when a notification occurred the control will call this callback + * procedure. + * + * \note The type of \a id changed from int to LINT since v3.2. + * + * \sa SetNotificationCallback + */ +typedef void (* NOTIFPROC) (HWND hwnd, LINT id, int nc, DWORD add_data); + /** The window element attributes structure. */ typedef struct _WINDOW_ELEMENT_ATTR { /** The attribute identifier. */ @@ -4980,9 +5001,32 @@ typedef struct _WINDOW_ELEMENT_RENDERER { /** * The window information structure. + * + * \note The layout of this structure changed since 4.2.0 to + * support virtual window. */ typedef struct _WINDOWINFO { + unsigned char _padding1; + unsigned char _padding2; + unsigned short _padding3; + +#ifdef _MGRM_THREADS + pthread_t _padding4; +#endif + void* _padding5; + + /** The window procedure */ + WNDPROC WinProc; + + /** The notification callback procedure. */ + NOTIFPROC NotifProc; + + /** The first additional data of this window */ + DWORD dwAddData; + /** The second additional data of this window */ + DWORD dwAddData2; + /** The position and size of window.*/ int left, top; int right, bottom; @@ -4996,8 +5040,9 @@ typedef struct _WINDOWINFO /** The extended styles of window.*/ DWORD dwExStyle; - /** The foreground pixel value (not used).*/ - gal_pixel iFgColor; + /** The index of znode for this window + * (only for a main window and a control as main window. */ + int idx_znode; /** The background pixel value of this window. */ gal_pixel iBkColor; @@ -5016,7 +5061,7 @@ typedef struct _WINDOWINFO PLOGFONT pLogFont; /** The caption of window.*/ - char* spCaption; + const char* spCaption; /** The identifier of window. * \note The type changed from int to LINT since v3.2. */ @@ -5825,12 +5870,6 @@ MG_EXPORT int GUIAPI SetWindowZOrder(HWND hWnd, int zorder); * @{ */ -/** - * \var typedef int (* WNDPROC)(HWND, int, WPARAM, LPARAM) - * \brief Type of the window callback procedure. - */ -typedef LRESULT (* WNDPROC)(HWND, UINT, WPARAM, LPARAM); - extern MG_EXPORT HWND __mg_hwnd_desktop; /** @@ -8657,21 +8696,6 @@ static inline HWND GUIAPI CreateWindowEx (const char* spClassName, */ MG_EXPORT BOOL GUIAPI DestroyWindow (HWND hWnd); -/** - * \var typedef void (* NOTIFPROC)(HWND hwnd, LINT id, int nc, DWORD add_data) - * \brief Type of the notification callback procedure. - * - * This is the function type of Notification Callback Procedure. - * If you set the Notification Callback Procedure for a control, - * when a notification occurred the control will call this callback - * procedure. - * - * \note The type of \a id changed from int to LINT since v3.2. - * - * \sa SetNotificationCallback - */ -typedef void (* NOTIFPROC) (HWND hwnd, LINT id, int nc, DWORD add_data); - /** * \fn NOTIFPROC GUIAPI SetNotificationCallback (HWND hwnd, \ * NOTIFPROC notif_proc) diff --git a/src/include/ctrlclass.h b/src/include/ctrlclass.h index 6365d4b9..ed1da84f 100644 --- a/src/include/ctrlclass.h +++ b/src/include/ctrlclass.h @@ -69,8 +69,8 @@ typedef struct _CTRLCLASSINFO #ifdef _MGSCHEMA_COMPOSITING DWORD dwBkColor; // control background color. #else - gal_pixel iFgColor; // control foreground color. - gal_pixel iBkColor; // control background color. + // gal_pixel iFgColor; // control foreground color; removed since 4.2.0. + gal_pixel iBkColor; // control background color (pixel value) #endif LRESULT (*ControlProc)(HWND, UINT, WPARAM, LPARAM); @@ -81,13 +81,42 @@ typedef struct _CTRLCLASSINFO int nUseCount; // use count. struct _CTRLCLASSINFO* next; // next class info -}CTRLCLASSINFO; +} CTRLCLASSINFO; typedef CTRLCLASSINFO* PCTRLCLASSINFO; -typedef struct tagCONTROL +typedef struct _CONTROL { /* - * These fields are similiar with MAINWIN struct. + * These following fields are similiar with MAINWIN struct. + */ + + /* + * Fields for data type + * VM[2020-02-14]: Move these fields back to header. + * VM[2018-01-18]: Move these fields from header to here to compatible with + * WINDOWINFO + */ + unsigned char DataType; // the data type + unsigned char WinType; // the window type + unsigned short Flags; // speical runtime flags, such EraseBkGnd flags + + /* + * Common fields for both control, virtual window, and main window. + * VM[2020-02-14]: Move these fields to here to support virtual window. + */ +#ifdef _MGRM_THREADS + pthread_t _padding; // no use, only for padding. +#endif + PCTRLCLASSINFO pcci; // pointer to Control Class Info struct. + + WNDPROC ControlProc; // the window procedure of this control. + NOTIFPROC notif_proc; // the notification callback procedure. + + DWORD dwAddData; // the additional data. + DWORD dwAddData2; // the second addtional data. + + /* + * Fields for appearance of this control. */ int left, top; // the position of control in main window's int right, bottom; // client area. @@ -98,8 +127,10 @@ typedef struct tagCONTROL DWORD dwStyle; // the styles of child window. DWORD dwExStyle; // the extended styles of child window. - gal_pixel iFgColor; // control foreground color. - gal_pixel iBkColor; // control background color. + int idx_znode; // the z-node; only works for control as main window. + //gal_pixel iFgColor; // control foreground color (pixel value). + gal_pixel iBkColor; // control background color (pixel value) + HMENU hMenu; // handle of menu. HACCEL hAccel; // handle of accelerator table. HCURSOR hCursor; // handle of cursor. @@ -113,70 +144,46 @@ typedef struct tagCONTROL LFSCROLLBARINFO vscroll; // the vertical scroll bar information. LFSCROLLBARINFO hscroll; // the horizital scroll bar information. - /** the window renderer */ - WINDOW_ELEMENT_RENDERER* we_rdr; + /* + * Fields for window element data. + */ + WINDOW_ELEMENT_RENDERER* we_rdr; // the window renderer + struct _wnd_element_data* wed; // the data of window elements HDC privCDC; // the private client DC. INVRGN InvRgn; // the invalid region of this control. #ifdef _MGSCHEMA_COMPOSITING - struct GAL_Surface* surf; // the shared surface of this main window. + struct GAL_Surface* surf; // the shared surface of the main window. #else PGCRINFO pGCRInfo; // pointer to global clip region info struct. #endif - // the Z order node, - // only for control with WS_EX_CTRLASMAINWIN. - int idx_znode; - PCARETINFO pCaretInfo; // pointer to system caret info struct. - DWORD dwAddData; // the additional data. - DWORD dwAddData2; // the second addtional data. - - LRESULT (*ControlProc) (HWND, UINT, WPARAM, LPARAM); - - PMAINWIN pMainWin; // the main window that contains this control. - - struct tagCONTROL* pParent;// the parent of this control. - /* - * Child windows. + * Fields to manage the relationship among main windows and controls. */ - struct tagCONTROL* children; - // the first child control. - struct tagCONTROL* active; - // the active child control. - struct tagCONTROL* old_under_pointer; - // the old under pointer child control. - struct tagCONTROL* primitive; - // the primitive child of mouse event. + PMAINWIN pMainWin; // the main window that contains this control. - NOTIFPROC notif_proc; // the notification callback procedure. + struct _CONTROL* pParent; // the parent of this control. - /* - * window element data. - */ - struct _wnd_element_data* wed; - /* - * some internal fields - * VM[2018-01-18]: Move these fields from header to here to compatible with WINDOWINFO - */ - unsigned char DataType; // the data type - unsigned char WinType; // the window type - unsigned short Flags; // speical runtime flags, such EraseBkGnd flags + struct _CONTROL* children; // the first child control. + struct _CONTROL* active; // the active child control. + struct _CONTROL* old_under_pointer; // the old child under pointer. + struct _CONTROL* primitive; // the primitive child of mouse event. /* * The following members are only implemented for control. */ - struct tagCONTROL* next; // the next sibling control. - struct tagCONTROL* prev; // the prev sibling control. + struct _CONTROL* next; // the next sibling control. + struct _CONTROL* prev; // the prev sibling control. - PCTRLCLASSINFO pcci; // pointer to Control Class Info struct. MASKRECT * mask_rects; - //if a control is has WS_EX_CTRLASMAINWIN, this proc is the next control as main window /* + * if a control is has WS_EX_CTRLASMAINWIN, + * this field is the next control as main window * MainWindow->hFirstChildAsMainWin ---> * control1->next_ctrl_as_main ----> * control2->next_ctrl_as_main ----> @@ -199,9 +206,8 @@ typedef struct tagCONTROL * ITSELF FROM PARENT'S hFirstChildAsMainWin'S LIST * */ - struct tagCONTROL* next_ctrl_as_main; - -}CONTROL; + struct _CONTROL* next_ctrl_as_main; +} CONTROL; typedef CONTROL* PCONTROL; /* Function definitions */ diff --git a/src/include/internals.h b/src/include/internals.h index c2dfe453..218ed060 100644 --- a/src/include/internals.h +++ b/src/include/internals.h @@ -77,6 +77,7 @@ #define TYPE_MAINWIN 0x11 #define TYPE_CONTROL 0x12 #define TYPE_ROOTWIN 0x13 + #define TYPE_VIRTWIN 0x14 #define TYPE_HMENU 0x02 #define TYPE_MENUBAR 0x21 #define TYPE_PPPMENU 0x22 @@ -243,8 +244,7 @@ static inline void SetDskIdleHandler (IDLEHANDLER idle_handler) { __mg_dsk_msg_queue->OnIdle = idle_handler; } - -#endif +#endif /* not defined _MGRM_THREADS */ #ifdef _MGRM_THREADS @@ -263,7 +263,7 @@ static inline void SetDskIdleHandler (IDLEHANDLER idle_handler) } \ } while(0) -#else +#else /* defined _MGRM_THREADS */ #define MG_MUTEX_INIT(lock) #define MG_MUTEX_DESTROY(lock) @@ -272,7 +272,7 @@ static inline void SetDskIdleHandler (IDLEHANDLER idle_handler) #define POST_MSGQ(pMsgQueue) -#endif +#endif /* not defined _MGRM_THREADS */ #define LOCK_MSGQ(pMsgQueue) MG_MUTEX_LOCK(&(pMsgQueue)->lock) #define UNLOCK_MSGQ(pMsgQueue) MG_MUTEX_UNLOCK(&(pMsgQueue)->lock) @@ -281,11 +281,63 @@ struct _wnd_element_data; #define WF_ERASEBKGND 0x01 //flags to erase bkground or not -// this struct is an internal struct +typedef struct _VIRTWIN +{ + /* + * Fields for data type + */ + unsigned char DataType; // the data type. + unsigned char WinType; // the window type, always be TYPE_VIRTWIN. + unsigned short _padding; // no use, just a padding. + + /* + * Fields for both virtual window and main window. + */ +#ifdef _MGRM_THREADS + pthread_t th; // the thread which creates this virtual window. +#endif + PMSGQUEUE pMessages; // the message queue. + + LRESULT (*VirtualWindowProc)(HWND, UINT, WPARAM, LPARAM); + // the address of the virtual window procedure. + DWORD dwAddData; // the additional data. + DWORD dwAddData2; // the second addtional data. +} VIRTWIN; + +// the structure represents a real main window. typedef struct _MAINWIN { /* - * These fields are similiar with CONTROL struct. + * These following fields are similiar with CONTROL struct. + */ + + /* + * Fields for data type + * VM[2020-02-14]: Move these fields back to support virtual main window. + * VM[2018-01-18]: Move these fields from header to here to compatible with + * WINDOWINFO + */ + unsigned char DataType; // the data type. + unsigned char WinType; // the window type. + unsigned short Flags; // special runtime flags, such EraseBkGnd flags + + /* + * Common fields for both control, virtual window, and main window. + * VM[2020-02-14]: Move these fields to header to support virtual window. + */ +#ifdef _MGRM_THREADS + pthread_t th; // the thread which creates this main window. +#endif + PMSGQUEUE pMessages; // the message queue. + + WNDPROC MainWindowProc; // the window procedure of this main window. + NOTIFPROC NotifProc; // the notification callback procedure. + + DWORD dwAddData; // the additional data. + DWORD dwAddData2; // the second addtional data. + + /* + * Fields for appearance of this main window. */ int left, top; // the position and size of main window. int right, bottom; @@ -296,8 +348,10 @@ typedef struct _MAINWIN DWORD dwStyle; // the styles of main window. DWORD dwExStyle; // the extended styles of main window. - gal_pixel iFgColor; // the foreground color. + int idx_znode; // the index of the z-node. + //gal_pixel iFgColor; // the foreground color. gal_pixel iBkColor; // the background color. + HMENU hMenu; // handle of menu. HACCEL hAccel; // handle of accelerator table. HCURSOR hCursor; // handle of cursor. @@ -308,86 +362,50 @@ typedef struct _MAINWIN char* spCaption; // the caption of main window. LINT id; // the identifier of main window. - LFSCROLLBARINFO vscroll; - // the vertical scroll bar information. - LFSCROLLBARINFO hscroll; - // the horizital scroll bar information. + LFSCROLLBARINFO vscroll; // the vertical scroll bar information. + LFSCROLLBARINFO hscroll; // the horizital scroll bar information. - /** the window renderer */ - WINDOW_ELEMENT_RENDERER* we_rdr; + /* + * Fields for window element data. + */ + WINDOW_ELEMENT_RENDERER* we_rdr; // the window renderer + struct _wnd_element_data* wed; // the data of window elements HDC privCDC; // the private client DC. INVRGN InvRgn; // the invalid region of this main window. #ifdef _MGSCHEMA_COMPOSITING struct GAL_Surface* surf; // the shared surface of this main window. #else - PGCRINFO pGCRInfo; // pointer to global clip region info struct. + PGCRINFO pGCRInfo; // pointer to global clip region info struct. #endif - // the Z order node. - int idx_znode; - - PCARETINFO pCaretInfo; - // pointer to system caret info struct. - - DWORD dwAddData; // the additional data. - DWORD dwAddData2; // the second addtional data. - - LRESULT (*MainWindowProc)(HWND, UINT, WPARAM, LPARAM); - // the address of main window procedure. - - struct _MAINWIN* pMainWin; - // the main window that contains this window. - // for main window, always be itself. - - HWND hParent; // the parent of this window. - // for main window, always be HWND_DESKTOP. + PCARETINFO pCaretInfo; // pointer to system caret info struct. /* - * Child windows. + * Fields to manage the relationship among main windows and controls. */ - HWND hFirstChild; // the handle of first child window. - HWND hActiveChild; // the currently active child window. + struct _MAINWIN* pMainWin; // the main window that contains this window. + // for main window, always be itself. + HWND hParent; // the parent of this window. + // for main window, always be HWND_DESKTOP. + + HWND hFirstChild; // the handle of first child window. + HWND hActiveChild; // the currently active child window. HWND hOldUnderPointer; // the old child window under pointer. - HWND hPrimitive; // the premitive child of mouse event. - - NOTIFPROC NotifProc; // the notification callback procedure. - - /* - * window element data. - */ - struct _wnd_element_data* wed; - - /* - * some internal fields - * VM[2018-01-18]: Move these fields from header to here to compatible with WINDOWINFO - */ - unsigned char DataType; // the data type. - unsigned char WinType; // the window type. - unsigned short Flags; // special runtime flags, such EraseBkGnd flags + HWND hPrimitive; // the premitive child of mouse event. /* * The following members are only implemented for main window. - * Main Window hosting. */ - struct _MAINWIN* pHosting; - // the hosting main window. - struct _MAINWIN* pFirstHosted; - // the first hosted main window. - struct _MAINWIN* pNextHosted; - // the next hosted main window. - - PMSGQUEUE pMessages; - // the message queue. + struct _MAINWIN* pHosting; // the hosting main window. + struct _MAINWIN* pFirstHosted; // the first hosted main window. + struct _MAINWIN* pNextHosted; // the next hosted main window. #ifndef _MGSCHEMA_COMPOSITING GCRINFO GCRInfo; // the global clip region info struct. // put here to avoid invoking malloc function. #endif -#ifdef _MGRM_THREADS - pthread_t th; // the thread which creates this main window. -#endif //the controls as main HWND hFirstChildAsMainWin;