ReactOS 0.4.15-dev-8102-g108db8f
layout.h
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS headers
3 * LICENSE: LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
4 * PURPOSE: The layout engine of resizable dialog boxes / windows
5 * COPYRIGHT: Copyright 2020-2021 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6 */
7#pragma once
8#include <assert.h>
9
10typedef struct LAYOUT_INFO {
12 UINT m_uEdges; /* BF_* flags */
17
18typedef struct LAYOUT_DATA {
24
25static __inline void
27{
28 if (bEnableResize)
29 {
30 GetSystemMenu(pData->m_hwndParent, TRUE); /* revert */
31 }
32 else
33 {
34 HMENU hSysMenu = GetSystemMenu(pData->m_hwndParent, FALSE);
38 }
39}
40
41static __inline HDWP
43{
44 if (!IsWindowVisible(pData->m_hwndGrip))
45 return hDwp;
46
49 RECT rcClient;
50 GetClientRect(pData->m_hwndParent, &rcClient);
51
52 if (hDwp)
53 {
54 hDwp = DeferWindowPos(hDwp, pData->m_hwndGrip, NULL,
55 rcClient.right - size.cx, rcClient.bottom - size.cy,
56 size.cx, size.cy, uFlags);
57 }
58 else
59 {
60 SetWindowPos(pData->m_hwndGrip, NULL,
61 rcClient.right - size.cx, rcClient.bottom - size.cy,
62 size.cx, size.cy, uFlags);
63 }
64 return hDwp;
65}
66
67static __inline void
69{
73 DWORD new_style = (bShow ? (style | WS_SIZEBOX) : (style & ~WS_SIZEBOX));
74 if (style != new_style)
75 {
76 SetWindowLongPtrW(pData->m_hwndParent, GWL_STYLE, new_style); /* change style */
77 SetWindowPos(pData->m_hwndParent, NULL, 0, 0, 0, 0, uSWP); /* frame changed */
78 }
79
80 if (!bShow)
81 {
82 ShowWindow(pData->m_hwndGrip, SW_HIDE);
83 return;
84 }
85
86 if (pData->m_hwndGrip == NULL)
87 {
89 pData->m_hwndGrip = CreateWindowExW(0, L"SCROLLBAR", NULL, style,
90 0, 0, 0, 0, pData->m_hwndParent,
92 }
95}
96
97static __inline void
98_layout_GetPercents(LPRECT prcPercents, UINT uEdges)
99{
100 prcPercents->left = (uEdges & BF_LEFT) ? 0 : 100;
101 prcPercents->right = (uEdges & BF_RIGHT) ? 100 : 0;
102 prcPercents->top = (uEdges & BF_TOP) ? 0 : 100;
103 prcPercents->bottom = (uEdges & BF_BOTTOM) ? 100 : 0;
104}
105
106static __inline HDWP
108 const RECT *rcClient)
109{
110 RECT rcChild, NewRect, rcPercents;
111 LONG nWidth, nHeight;
112
113 if (!GetWindowRect(pLayout->m_hwndCtrl, &rcChild))
114 return hDwp;
115 MapWindowPoints(NULL, pData->m_hwndParent, (LPPOINT)&rcChild, 2);
116
117 nWidth = rcClient->right - rcClient->left;
118 nHeight = rcClient->bottom - rcClient->top;
119
120 _layout_GetPercents(&rcPercents, pLayout->m_uEdges);
121 NewRect.left = pLayout->m_margin1.cx + nWidth * rcPercents.left / 100;
122 NewRect.top = pLayout->m_margin1.cy + nHeight * rcPercents.top / 100;
123 NewRect.right = pLayout->m_margin2.cx + nWidth * rcPercents.right / 100;
124 NewRect.bottom = pLayout->m_margin2.cy + nHeight * rcPercents.bottom / 100;
125
126 if (!EqualRect(&NewRect, &rcChild))
127 {
128 hDwp = DeferWindowPos(hDwp, pLayout->m_hwndCtrl, NULL, NewRect.left, NewRect.top,
129 NewRect.right - NewRect.left, NewRect.bottom - NewRect.top,
131 }
132 return hDwp;
133}
134
135static __inline void
137{
138 RECT rcClient;
139 UINT iItem;
140 HDWP hDwp = BeginDeferWindowPos(pData->m_cLayouts + 1);
141 if (hDwp == NULL)
142 return;
143
144 GetClientRect(pData->m_hwndParent, &rcClient);
145
146 for (iItem = 0; iItem < pData->m_cLayouts; ++iItem)
147 hDwp = _layout_DoMoveItem(pData, hDwp, &pData->m_pLayouts[iItem], &rcClient);
148
149 hDwp = _layout_MoveGrip(pData, hDwp);
150 EndDeferWindowPos(hDwp);
151}
152
153static __inline void
155{
156 RECT rcClient, rcChild, rcPercents;
157 LONG nWidth, nHeight;
158 UINT iItem;
159
160 GetClientRect(pData->m_hwndParent, &rcClient);
161 nWidth = rcClient.right - rcClient.left;
162 nHeight = rcClient.bottom - rcClient.top;
163
164 for (iItem = 0; iItem < pData->m_cLayouts; ++iItem)
165 {
166 LAYOUT_INFO *pInfo = &pData->m_pLayouts[iItem];
167 if (pInfo->m_hwndCtrl == NULL)
168 {
169 pInfo->m_hwndCtrl = GetDlgItem(pData->m_hwndParent, pInfo->m_nCtrlID);
170 if (pInfo->m_hwndCtrl == NULL)
171 continue;
172 }
173
174 GetWindowRect(pInfo->m_hwndCtrl, &rcChild);
175 MapWindowPoints(NULL, pData->m_hwndParent, (LPPOINT)&rcChild, 2);
176
177 _layout_GetPercents(&rcPercents, pInfo->m_uEdges);
178 pInfo->m_margin1.cx = rcChild.left - nWidth * rcPercents.left / 100;
179 pInfo->m_margin1.cy = rcChild.top - nHeight * rcPercents.top / 100;
180 pInfo->m_margin2.cx = rcChild.right - nWidth * rcPercents.right / 100;
181 pInfo->m_margin2.cy = rcChild.bottom - nHeight * rcPercents.bottom / 100;
182 }
183}
184
185/* NOTE: Please call LayoutUpdate on parent's WM_SIZE. */
186static __inline void
187LayoutUpdate(HWND ignored1, LAYOUT_DATA *pData, LPCVOID ignored2, UINT ignored3)
188{
189 UNREFERENCED_PARAMETER(ignored1);
190 UNREFERENCED_PARAMETER(ignored2);
191 UNREFERENCED_PARAMETER(ignored3);
192 if (pData == NULL || !pData->m_hwndParent)
193 return;
194 assert(IsWindow(pData->m_hwndParent));
196}
197
198static __inline void
200{
203}
204
205static __inline LAYOUT_DATA *
206LayoutInit(HWND hwndParent, const LAYOUT_INFO *pLayouts, INT cLayouts)
207{
208 BOOL bShowGrip;
209 SIZE_T cb;
211 if (pData == NULL)
212 {
213 assert(0);
214 return NULL;
215 }
216
217 if (cLayouts < 0) /* NOTE: If cLayouts was negative, then don't show size grip */
218 {
219 cLayouts = -cLayouts;
220 bShowGrip = FALSE;
221 }
222 else
223 {
224 bShowGrip = TRUE;
225 }
226
227 cb = cLayouts * sizeof(LAYOUT_INFO);
228 pData->m_cLayouts = cLayouts;
229 pData->m_pLayouts = (LAYOUT_INFO *)HeapAlloc(GetProcessHeap(), 0, cb);
230 if (pData->m_pLayouts == NULL)
231 {
232 assert(0);
234 return NULL;
235 }
236 memcpy(pData->m_pLayouts, pLayouts, cb);
237
239
240 pData->m_hwndParent = hwndParent;
241
242 pData->m_hwndGrip = NULL;
243 if (bShowGrip)
244 LayoutShowGrip(pData, bShowGrip);
245
247 return pData;
248}
249
250static __inline void
252{
253 if (!pData)
254 return;
255 HeapFree(GetProcessHeap(), 0, pData->m_pLayouts);
257}
Arabic default style
Definition: afstyles.h:94
static HWND hwndParent
Definition: cryptui.c:300
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
UINT uFlags
Definition: api.c:59
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define assert(x)
Definition: debug.h:53
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
static __inline void LayoutEnableResize(LAYOUT_DATA *pData, BOOL bEnable)
Definition: layout.h:199
static __inline void _layout_ModifySystemMenu(LAYOUT_DATA *pData, BOOL bEnableResize)
Definition: layout.h:26
static __inline void _layout_ArrangeLayout(LAYOUT_DATA *pData)
Definition: layout.h:136
static __inline LAYOUT_DATA * LayoutInit(HWND hwndParent, const LAYOUT_INFO *pLayouts, INT cLayouts)
Definition: layout.h:206
static __inline void LayoutDestroy(LAYOUT_DATA *pData)
Definition: layout.h:251
static __inline HDWP _layout_DoMoveItem(LAYOUT_DATA *pData, HDWP hDwp, const LAYOUT_INFO *pLayout, const RECT *rcClient)
Definition: layout.h:107
static __inline void _layout_InitLayouts(LAYOUT_DATA *pData)
Definition: layout.h:154
static __inline HDWP _layout_MoveGrip(LAYOUT_DATA *pData, HDWP hDwp OPTIONAL)
Definition: layout.h:42
static __inline void LayoutUpdate(HWND ignored1, LAYOUT_DATA *pData, LPCVOID ignored2, UINT ignored3)
Definition: layout.h:187
static __inline void _layout_GetPercents(LPRECT prcPercents, UINT uEdges)
Definition: layout.h:98
static __inline void LayoutShowGrip(LAYOUT_DATA *pData, BOOL bShow)
Definition: layout.h:68
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
unsigned int UINT
Definition: ndis.h:50
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define L(x)
Definition: ntvdm.h:50
#define WS_CHILD
Definition: pedump.c:617
#define WS_SIZEBOX
Definition: pedump.c:642
long LONG
Definition: pedump.c:60
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
UINT m_cLayouts
Definition: layout.h:22
LAYOUT_INFO * m_pLayouts
Definition: layout.h:21
HWND m_hwndGrip
Definition: layout.h:20
HWND m_hwndParent
Definition: layout.h:19
UINT m_uEdges
Definition: layout.h:12
SIZE m_margin2
Definition: layout.h:15
HWND m_hwndCtrl
Definition: layout.h:13
SIZE m_margin1
Definition: layout.h:14
UINT m_nCtrlID
Definition: layout.h:11
LONG cx
Definition: kdterminal.h:27
LONG cy
Definition: kdterminal.h:28
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
ULONG_PTR SIZE_T
Definition: typedefs.h:80
int32_t INT
Definition: typedefs.h:58
_In_ BOOL bEnable
Definition: winddi.h:3426
CONST void * LPCVOID
Definition: windef.h:191
BOOL WINAPI IsWindow(_In_opt_ HWND)
#define SW_HIDE
Definition: winuser.h:768
#define SWP_NOACTIVATE
Definition: winuser.h:1242
#define MF_BYCOMMAND
Definition: winuser.h:202
#define GetWindowLongPtrW
Definition: winuser.h:4829
#define SWP_NOREPOSITION
Definition: winuser.h:1250
#define SWP_FRAMECHANGED
Definition: winuser.h:1240
#define SBS_SIZEGRIP
Definition: winuser.h:332
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define SM_CXVSCROLL
Definition: winuser.h:961
#define SWP_NOMOVE
Definition: winuser.h:1244
#define BF_LEFT
Definition: winuser.h:454
#define SW_SHOWNOACTIVATE
Definition: winuser.h:774
#define SWP_NOSIZE
Definition: winuser.h:1245
#define BF_BOTTOM
Definition: winuser.h:457
HMENU WINAPI GetSystemMenu(_In_ HWND, _In_ BOOL)
BOOL WINAPI EndDeferWindowPos(_In_ HDWP)
int WINAPI MapWindowPoints(_In_opt_ HWND hWndFrom, _In_opt_ HWND hWndTo, _Inout_updates_(cPoints) LPPOINT lpPoints, _In_ UINT cPoints)
#define SM_CYHSCROLL
Definition: winuser.h:962
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define SC_SIZE
Definition: winuser.h:2584
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define SWP_NOCOPYBITS
Definition: winuser.h:1243
#define BF_TOP
Definition: winuser.h:455
HWND WINAPI CreateWindowExW(_In_ DWORD dwExStyle, _In_opt_ LPCWSTR lpClassName, _In_opt_ LPCWSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
#define BF_RIGHT
Definition: winuser.h:456
BOOL WINAPI RemoveMenu(_In_ HMENU, _In_ UINT, _In_ UINT)
#define SWP_NOOWNERZORDER
Definition: winuser.h:1249
HDWP WINAPI DeferWindowPos(_In_ HDWP, _In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define SWP_NOZORDER
Definition: winuser.h:1247
#define SetWindowLongPtrW
Definition: winuser.h:5346
#define GWL_STYLE
Definition: winuser.h:852
#define SC_RESTORE
Definition: winuser.h:2598
BOOL WINAPI IsWindowVisible(_In_ HWND)
BOOL WINAPI EqualRect(_In_ LPCRECT, _In_ LPCRECT)
int WINAPI GetSystemMetrics(_In_ int)
#define SC_MAXIMIZE
Definition: winuser.h:2588
HDWP WINAPI BeginDeferWindowPos(_In_ int)