diff options
| -rw-r--r-- | alf/alf.cpp | 164 | ||||
| -rw-r--r-- | alf/alf.h | 40 | ||||
| -rw-r--r-- | alf/alfbutton.cpp | 2 | ||||
| -rw-r--r-- | alf/alfcombobox.cpp | 2 | ||||
| -rw-r--r-- | alf/alfedit.cpp | 2 | ||||
| -rw-r--r-- | alf/alflabel.cpp | 2 | ||||
| -rw-r--r-- | widgetfactory.cpp | 3 |
7 files changed, 203 insertions, 12 deletions
diff --git a/alf/alf.cpp b/alf/alf.cpp index 981d1e7..6936436 100644 --- a/alf/alf.cpp +++ b/alf/alf.cpp @@ -274,7 +274,7 @@ ALF_ApplyLayout(HWND hwnd, ALFWindowPriv *win) } static void -ALF_InternalAddWidget(HWND hwnd, ALFWindowPriv *priv, ALFAddWidgetParams *params) +ALF_InternalAddWidget(HWND hwnd, ALFWindowPriv *priv, ALFWidgetLayoutParams *params) { ALFWidgetPriv *w = (ALFWidgetPriv*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY|HEAP_GENERATE_EXCEPTIONS, sizeof(ALFWidgetPriv)); w->hwnd = params->hwnd; @@ -297,6 +297,64 @@ ALF_InternalAddWidget(HWND hwnd, ALFWindowPriv *priv, ALFAddWidgetParams *params ALF_UpdateFontForWidget(priv, w); } +static BOOL +ALF_InternalSetLayoutParams(ALFWindowPriv *priv, HWND widget, const ALFWidgetLayoutParams *params) +{ + ALF_FOR_LIST(ALFWidgetPriv, list, &priv->widgets, w) { + if (w->hwnd == widget) { + w->hwnd = params->hwnd; + w->x = params->x; + w->y = params->y; + w->cptWidth = params->width; + w->cptHeight = params->height; + w->flags = params->flags; + w->cptMarginTop = params->margins[0]; + w->cptMarginRight = params->margins[1]; + w->cptMarginBottom = params->margins[2]; + w->cptMarginLeft = params->margins[3]; + + return TRUE; + } + } + + return FALSE; +} + +static BOOL +ALF_InternalGetLayoutParams(ALFWindowPriv *priv, HWND widget, ALFWidgetLayoutParams *params) +{ + ALF_FOR_LIST(ALFWidgetPriv, list, &priv->widgets, w) { + if (w->hwnd == widget) { + params->hwnd = w->hwnd; + params->x = w->x; + params->y = w->y; + params->width = w->cptWidth; + params->height = w->cptHeight; + params->flags = w->flags; + params->margins[0] = w->cptMarginTop; + params->margins[1] = w->cptMarginRight; + params->margins[2] = w->cptMarginBottom; + params->margins[3] = w->cptMarginLeft; + + return TRUE; + } + } + + return FALSE; +} + +static HWND +ALF_InternalGetWidgetAtPos(ALFWindowPriv *priv, UINT x, UINT y) +{ + ALF_FOR_LIST(ALFWidgetPriv, list, &priv->widgets, w) { + if (w->x == x && w->y == y) { + return w->hwnd; + } + } + + return NULL; +} + static void ALF_ApplyFocus(HWND hwnd, ALFWindowPriv *priv, BOOL restoringFocus) { @@ -344,10 +402,22 @@ ALF_DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } if (msg == ALF_WM_ADDWIDGET) { - ALF_InternalAddWidget(hwnd, priv, (ALFAddWidgetParams *)lparam); + ALF_InternalAddWidget(hwnd, priv, (ALFWidgetLayoutParams *)lparam); return 0; } + if (msg == ALF_WM_GETLAYOUTPARAMS) { + return (LRESULT)ALF_InternalGetLayoutParams(priv, (HWND)wparam, (ALFWidgetLayoutParams *)lparam); + } + + if (msg == ALF_WM_SETLAYOUTPARAMS) { + return (LRESULT)ALF_InternalSetLayoutParams(priv, (HWND)wparam, (const ALFWidgetLayoutParams *)lparam); + } + + if (msg == ALF_WM_GETWIDGETATPOS) { + return (LRESULT)ALF_InternalGetWidgetAtPos(priv, ((UINT*)lparam)[0], ((UINT*)lparam)[1]); + } + if (msg == ALF_WM_SETFOCUS) { priv->hwndFocus = (HWND)lparam; ALF_ApplyFocus(hwnd, priv, FALSE); @@ -485,7 +555,7 @@ ALF_DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) void ALF_AddWidget(HWND win, UINT x, UINT y, HWND widget, UINT minWidth, UINT minHeight, DWORD flags) { - ALFAddWidgetParams params; + ALFWidgetLayoutParams params; ZeroMemory(¶ms, sizeof(params)); params.hwnd = widget; params.x = x; @@ -496,10 +566,9 @@ ALF_AddWidget(HWND win, UINT x, UINT y, HWND widget, UINT minWidth, UINT minHeig ALF_AddWidgetEx(win, ¶ms); } -void -ALF_AddWidgetEx(HWND win, const ALFAddWidgetParams *p) +void ALF_AddWidgetEx(HWND win, const ALFWidgetLayoutParams* params) { - SendMessage(win, ALF_WM_ADDWIDGET, 0, (LPARAM)p); + SendMessage(win, ALF_WM_ADDWIDGET, 0, (LPARAM)params); } static LRESULT CALLBACK @@ -787,3 +856,86 @@ ALF_WidgetText(HWND parent, WORD id) return NULL; } + +DWORD +ALF_WidgetLayoutFlags(HWND parent, HWND widget) +{ + ALFWidgetLayoutParams p; + if (SendMessage(parent, ALF_WM_GETLAYOUTPARAMS, (WPARAM)widget, (LPARAM)&p)) { + return p.flags; + } else { + return 0; + } +} + +BOOL +ALF_SetWidgetLayoutFlags(HWND parent, HWND widget, DWORD flags) +{ + ALFWidgetLayoutParams p; + if (SendMessage(parent, ALF_WM_GETLAYOUTPARAMS, (WPARAM)widget, (LPARAM)&p)) { + p.flags = flags; + return SendMessage(parent, ALF_WM_SETLAYOUTPARAMS, (WPARAM)widget, (LPARAM)&p); + } + + return FALSE; +} + +BOOL +ALF_WidgetLayoutPosition(HWND parent, HWND widget, UINT *pX, UINT *pY) +{ + ALFWidgetLayoutParams p; + if (SendMessage(parent, ALF_WM_GETLAYOUTPARAMS, (WPARAM)widget, (LPARAM)&p)) { + *pX = p.x; + *pY = p.y; + return TRUE; + } else { + return FALSE; + } +} + +BOOL +ALF_SetWidgetLayoutPosition(HWND parent, HWND widget, UINT x, UINT y) +{ + ALFWidgetLayoutParams p; + if (SendMessage(parent, ALF_WM_GETLAYOUTPARAMS, (WPARAM)widget, (LPARAM)&p)) { + p.x = x; + p.y = y; + return SendMessage(parent, ALF_WM_SETLAYOUTPARAMS, (WPARAM)widget, (LPARAM)&p); + } + + return FALSE; +} + +BOOL +ALF_WidgetLayoutSize(HWND parent, HWND widget, UINT *pCptWidth, UINT *pCptHeight) +{ + ALFWidgetLayoutParams p; + if (SendMessage(parent, ALF_WM_GETLAYOUTPARAMS, (WPARAM)widget, (LPARAM)&p)) { + *pCptWidth = p.width; + *pCptHeight = p.height; + return TRUE; + } else { + return FALSE; + } +} + +BOOL +ALF_SetWidgetLayoutSize(HWND parent, HWND widget, UINT cptWidth, UINT cptHeight) +{ + ALFWidgetLayoutParams p; + if (SendMessage(parent, ALF_WM_GETLAYOUTPARAMS, (WPARAM)widget, (LPARAM)&p)) { + p.width = cptWidth; + p.height = cptHeight; + return SendMessage(parent, ALF_WM_SETLAYOUTPARAMS, (WPARAM)widget, (LPARAM)&p); + } + + return FALSE; +} + +HWND +ALF_WidgetAtLayoutPosition(HWND parent, UINT x, UINT y) +{ + UINT xy[2] = { x, y }; + + return (HWND)SendMessage(parent, ALF_WM_GETWIDGETATPOS, 0, (LPARAM)&xy); +} @@ -45,6 +45,9 @@ typedef struct { #define ALF_WM_SETFOCUS (ALF_WM__BASE + 10) #define ALF_WM_GETAPPLICATION (ALF_WM__BASE + 11) #define ALF_WM_APPLYSIZE (ALF_WM__BASE + 12) +#define ALF_WM_GETLAYOUTPARAMS (ALF_WM__BASE + 13) +#define ALF_WM_SETLAYOUTPARAMS (ALF_WM__BASE + 14) +#define ALF_WM_GETWIDGETATPOS (ALF_WM__BASE + 15) typedef struct { const TCHAR *className; @@ -60,7 +63,7 @@ typedef struct { UINT height; DWORD flags; UINT margins[4]; -} ALFAddWidgetParams; +} ALFWidgetLayoutParams; typedef struct ALFAppPriv *ALFAPP; @@ -119,7 +122,7 @@ void ALF_AddWidget(HWND win, UINT x, UINT y, HWND widget, UINT cptWidth, UINT cptHeight, DWORD flags); void -ALF_AddWidgetEx(HWND win, const ALFAddWidgetParams *params); +ALF_AddWidgetEx(HWND win, const ALFWidgetLayoutParams *params); HWND ALF_WidgetHwndById(HWND win, WORD id); @@ -157,6 +160,39 @@ ALF_Text(HWND hwnd); TCHAR * // free with HeapFree ALF_WidgetText(HWND parent, WORD id); +DWORD +ALF_WidgetLayoutFlags(HWND parent, HWND widget); + +BOOL +ALF_SetWidgetLayoutFlags(HWND parent, HWND widget, DWORD flags); + +static inline void +ALF_AddWidgetLayoutFlag(HWND parent, HWND widget, DWORD flag) +{ + ALF_SetWidgetLayoutFlags(parent, widget, ALF_WidgetLayoutFlags(parent, widget) | flag); +} + +static inline void +ALF_RemoveWidgetLayoutFlag(HWND parent, HWND widget, DWORD flag) +{ + ALF_SetWidgetLayoutFlags(parent, widget, ALF_WidgetLayoutFlags(parent, widget) & ~flag); +} + +BOOL +ALF_WidgetLayoutPosition(HWND parent, HWND widget, UINT *pX, UINT *pY); + +BOOL +ALF_SetWidgetLayoutPosition(HWND parent, HWND widget, UINT x, UINT y); + +BOOL +ALF_WidgetLayoutSize(HWND parent, HWND widget, UINT *pCptWidth, UINT *pCptHeight); + +BOOL +ALF_SetWidgetLayoutSize(HWND parent, HWND widget, UINT cptWidth, UINT cptHeight); + +HWND +ALF_WidgetAtLayoutPosition(HWND parent, UINT x, UINT y); + // combo box HWND diff --git a/alf/alfbutton.cpp b/alf/alfbutton.cpp index 729e7ee..95e8e8d 100644 --- a/alf/alfbutton.cpp +++ b/alf/alfbutton.cpp @@ -90,7 +90,7 @@ ALF_AddButton(HWND win, WORD id, UINT x, UINT y, const TCHAR *text) app->compatFn->SetWindowSubclass(hwndButton, ALF__ButtonSubclassProc, 0, (DWORD_PTR)app); SetWindowPos(hwndButton, NULL, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED); - ALFAddWidgetParams p; + ALFWidgetLayoutParams p; ZeroMemory(&p, sizeof(p)); p.hwnd = hwndButton; p.x = x; diff --git a/alf/alfcombobox.cpp b/alf/alfcombobox.cpp index 90e53ad..3007a20 100644 --- a/alf/alfcombobox.cpp +++ b/alf/alfcombobox.cpp @@ -277,7 +277,7 @@ ALF_InternalAddComboBox(HWND win, WORD id, UINT x, UINT y, DWORD style, const TC if (defaultText) SetWindowText(hwndCombo, defaultText); - ALFAddWidgetParams p; + ALFWidgetLayoutParams p; ZeroMemory(&p, sizeof(p)); p.hwnd = hwndCombo; p.x = x; diff --git a/alf/alfedit.cpp b/alf/alfedit.cpp index 1d259a8..fc1d876 100644 --- a/alf/alfedit.cpp +++ b/alf/alfedit.cpp @@ -71,7 +71,7 @@ ALF_AddEdit(HWND win, WORD id, UINT x, UINT y, const TCHAR *text) app->compatFn->SetWindowSubclass(hwndEdit, ALF__EditSubclassProc, 0, (DWORD_PTR)app); SetWindowPos(hwndEdit, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_FRAMECHANGED); - ALFAddWidgetParams p; + ALFWidgetLayoutParams p; ZeroMemory(&p, sizeof(p)); p.hwnd = hwndEdit; p.x = x; diff --git a/alf/alflabel.cpp b/alf/alflabel.cpp index 59e2ca3..a0dc138 100644 --- a/alf/alflabel.cpp +++ b/alf/alflabel.cpp @@ -90,7 +90,7 @@ ALF_AddLabel(HWND win, WORD id, UINT x, UINT y, const TCHAR *text) ALFAPP app = ALF_ApplicationFromWindow(win); app->compatFn->SetWindowSubclass(hwndLabel, ALF__LabelSubclassProc, 0, (DWORD_PTR)app); - ALFAddWidgetParams p; + ALFWidgetLayoutParams p; ZeroMemory(&p, sizeof(p)); p.hwnd = hwndLabel; p.x = x; diff --git a/widgetfactory.cpp b/widgetfactory.cpp index 64e4e60..42eb987 100644 --- a/widgetfactory.cpp +++ b/widgetfactory.cpp @@ -136,6 +136,9 @@ WinMain HWND hwndCombo2 = ALF_AddSelectionOnlyComboBox(win, ID_COMBO2, 1, 4); ALF_AddButton(win, ID_B4, 2, 4, TEXT("Lol")); + /*HWND b4 = ALF_WidgetAtLayoutPosition(win, 2, 4); + ALF_SetWidgetLayoutSize(win, b4, 6427, 0);*/ + ALF_ComboBoxAddString(hwndCombo2, TEXT("Hello World!")); ALF_ComboBoxAddString(hwndCombo2, TEXT("Goodbye World!")); ALF_ComboBoxAddString(hwndCombo2, TEXT("The quick brown fox jumps over the lazy dog")); |
