Skip to content

Commit

Permalink
completed the generalized WM_SIZE/WM_SIZING resize code - now all con…
Browse files Browse the repository at this point in the history
…trols in the dialog stick to whichever side(s) they should.
  • Loading branch information
GerHobbelt committed Apr 21, 2015
1 parent 400ba83 commit 43e8547
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 34 deletions.
100 changes: 74 additions & 26 deletions examples/book_samples_server.c
Expand Up @@ -1311,6 +1311,7 @@ typedef enum child_control_move_mode_t {
static BOOL MoveChildControl(HWND hControl, LPCRECT parent_client_rc, MOVE_MODE mode)
{
int l, r, t, b, w, h;
// Retrieve the child-window identifier. Use it to get at the matching OFFSETS struct in the meta store to help us resize the bugger.
LONG ctrl_id = GetWindowLong(hControl, GWL_ID);
OFFSETS *offsets = getControlOffsets(ctrl_id);

Expand Down Expand Up @@ -1380,6 +1381,65 @@ static BOOL MoveChildControl(HWND hControl, LPCRECT parent_client_rc, MOVE_MODE
return TRUE;
}

typedef struct {
HWND parent_hwnd;
RECT parent_wrect;
RECT parent_clrect;
} CalcInfoClosureData;

BOOL CALLBACK EnumControlsToCalculateOffsets(HWND hWndChild, LPARAM lParam)
{
CalcInfoClosureData *meta = (CalcInfoClosureData *)lParam;

// Retrieve the child-window identifier. Use it to check and, if necessary, re-assign a fresh ID to the control.
// This reassign activity is required to ensure that *all* child controls have unique IDs, including the
// IDC_STATIC ones!
LONG idChild = GetWindowLong(hWndChild, GWL_ID);
if (idChild == IDC_STATIC) {
static int new_index = IDC_STATIC_START_ID;
new_index++;
SetWindowLong(hWndChild, GWL_ID, new_index);
idChild = GetWindowLong(hWndChild, GWL_ID);
}

calculateOffsets(hWndChild, &meta->parent_clrect);

return TRUE;
}

BOOL CALLBACK EnumControlsToResizeThem(HWND hWndChild, LPARAM lParam)
{
CalcInfoClosureData *meta = (CalcInfoClosureData *)lParam;

// Retrieve the child-window identifier. Use it to get at the matching OFFSETS struct in the meta store to help us resize the bugger.
LONG idChild = GetWindowLong(hWndChild, GWL_ID);

switch (idChild) {
default:
MoveChildControl(hWndChild, &meta->parent_clrect, STICK_TO_TOP | RESIZE_WIDTH);
break;

case IDC_STATIC_LOGO:
MoveChildControl(hWndChild, &meta->parent_clrect, STICK_TO_TOP | STICK_TO_LEFT);
break;

case IDC_EDIT_WRAPPER:
case IDC_RICHEDIT4LOG:
MoveChildControl(hWndChild, &meta->parent_clrect, RESIZE_BOTH);
break;

case IDC_BUTTON_CLEAR_LOG:
MoveChildControl(hWndChild, &meta->parent_clrect, STICK_TO_BOTTOM | STICK_TO_LEFT);
break;

case IDC_BUTTON_CREATE_VHOSTS_DIRS:
MoveChildControl(hWndChild, &meta->parent_clrect, STICK_TO_BOTTOM | STICK_TO_RIGHT);
break;
}

return TRUE;
}

#if defined(MONGOOSE_AS_SERVICE)
static int manage_service(int action) {
static const char *service_name = "Mongoose";
Expand Down Expand Up @@ -1514,43 +1574,31 @@ static BOOL CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam,

case WM_SIZE:
if (wParam == SIZE_RESTORED) {
int resize_w = LOWORD(lParam);
int resize_h = HIWORD(lParam);
HWND hEdit = GetDlgItem(hWnd, IDC_RICHEDIT4LOG);
HWND hEditWrapper = GetDlgItem(hWnd, IDC_EDIT_WRAPPER);
HWND hClearButton = GetDlgItem(hWnd, IDC_BUTTON_CLEAR_LOG);
HWND hGenDirsButton = GetDlgItem(hWnd, IDC_BUTTON_CREATE_VHOSTS_DIRS);
HWND hParent = GetParent(hEdit);

RECT parent_wrect = { 0 };
RECT parent_clrect = { 0 };
CalcInfoClosureData meta = { 0 };
meta.parent_hwnd = hWnd;

// Get the client rect of the dialog itself to calculate the *relative* positions
// of the controls inside.
GetWindowRect(hWnd, &parent_wrect);
GetClientRect(hWnd, &parent_clrect);
ClientRectToScreen(hWnd, &parent_clrect);
GetWindowRect(hWnd, &meta.parent_wrect);
GetClientRect(hWnd, &meta.parent_clrect);
ClientRectToScreen(hWnd, &meta.parent_clrect);

MG_ASSERT(hParent == hWnd);
if (!dlgInfo.is_set_up) {
OFFSETS *dlgClientAreaOffsets = &dlgInfo.controlOffsets[0];
dlgInfo.control_index_map[0] = 0xFFFFFFFFul; // mark slot as allocated
dlgClientAreaOffsets->left = parent_clrect.left - parent_wrect.left;
dlgClientAreaOffsets->right = parent_clrect.right - parent_wrect.right;
dlgClientAreaOffsets->top = parent_clrect.top - parent_wrect.top;
dlgClientAreaOffsets->bottom = parent_clrect.bottom - parent_wrect.bottom;
dlgClientAreaOffsets->left = meta.parent_clrect.left - meta.parent_wrect.left;
dlgClientAreaOffsets->right = meta.parent_clrect.right - meta.parent_wrect.right;
dlgClientAreaOffsets->top = meta.parent_clrect.top - meta.parent_wrect.top;
dlgClientAreaOffsets->bottom = meta.parent_clrect.bottom - meta.parent_wrect.bottom;
dlgClientAreaOffsets->width = dlgClientAreaOffsets->left - dlgClientAreaOffsets->right;
dlgClientAreaOffsets->height = dlgClientAreaOffsets->top - dlgClientAreaOffsets->bottom;

calculateOffsets(hEditWrapper, &parent_clrect);
calculateOffsets(hEdit, &parent_clrect);
calculateOffsets(hClearButton, &parent_clrect);
calculateOffsets(hGenDirsButton, &parent_clrect);
EnumChildWindows(hWnd, EnumControlsToCalculateOffsets, (LPARAM)&meta);

dlgInfo.is_set_up = 1;
}
MoveChildControl(hEditWrapper, &parent_clrect, RESIZE_BOTH);
MoveChildControl(hEdit, &parent_clrect, RESIZE_BOTH);
MoveChildControl(hClearButton, &parent_clrect, STICK_TO_BOTTOM | STICK_TO_LEFT);
MoveChildControl(hGenDirsButton, &parent_clrect, STICK_TO_BOTTOM | STICK_TO_RIGHT);

EnumChildWindows(hWnd, EnumControlsToResizeThem, (LPARAM)&meta);
}
return FALSE;

Expand Down
18 changes: 11 additions & 7 deletions win32/examples/mongoose_book_samples_server.rc
Expand Up @@ -74,8 +74,8 @@ CAPTION "xxx"
FONT 8, "MS Shell Dlg", 400, 0, 0x0
BEGIN
GROUPBOX "General Message",IDC_STATIC,7,7,399,46
CTEXT "(Drag and) drop the directory or HTML file you wish to serve anywhere in here...",IDC_STATIC,76,29,296,10
ICON IDI_ICON,IDC_STATIC,22,23,20,20
CTEXT "(Drag and) drop the directory or HTML file you wish to serve anywhere in here...",IDC_STATIC,51,15,350,34,SS_CENTERIMAGE | SS_WORDELLIPSIS | SS_REALSIZECONTROL
ICON IDI_ICON,IDC_STATIC_LOGO,22,23,20,20
GROUPBOX "Server log messages",IDC_EDIT_WRAPPER,7,74,399,157
CONTROL "",IDC_RICHEDIT4LOG,"RICHEDIT60W",WS_BORDER | WS_VSCROLL | WS_TABSTOP | 0x844,9,86,394,143
PUSHBUTTON "Visit URL",IDC_BUTTON_VISIT_URL,7,58,399,16
Expand All @@ -90,8 +90,8 @@ CAPTION "xxx"
FONT 8, "MS Shell Dlg", 400, 0, 0x0
BEGIN
GROUPBOX "General Message",IDC_STATIC,7,7,399,46
CTEXT "(Drag and) drop the directory or HTML file you wish to serve anywhere in here...",IDC_STATIC,76,29,296,10
ICON IDI_ICON,IDC_STATIC,22,23,20,20
CTEXT "(Drag and) drop the directory or HTML file you wish to serve anywhere in here...",IDC_STATIC,51,15,350,34,SS_CENTERIMAGE | SS_WORDELLIPSIS | SS_REALSIZECONTROL
ICON IDI_ICON,IDC_STATIC_LOGO,22,23,20,20
GROUPBOX "Server log messages",IDC_EDIT_WRAPPER,7,74,399,157
CONTROL "",IDC_RICHEDIT4LOG,"RICHEDIT50W",WS_BORDER | WS_VSCROLL | WS_TABSTOP | 0x844,9,86,394,143
PUSHBUTTON "Visit URL",IDC_BUTTON_VISIT_URL,7,58,399,16
Expand All @@ -106,10 +106,10 @@ CAPTION "xxx"
FONT 8, "MS Shell Dlg", 400, 0, 0x0
BEGIN
GROUPBOX "General Message",IDC_STATIC,7,7,399,46
CTEXT "(Drag and) drop the directory or HTML file you wish to serve anywhere in here...",IDC_STATIC,76,29,296,10
ICON IDI_ICON,IDC_STATIC,22,23,20,20
CTEXT "(Drag and) drop the directory or HTML file you wish to serve anywhere in here...",IDC_STATIC,51,15,350,34,SS_CENTERIMAGE | SS_WORDELLIPSIS | SS_REALSIZECONTROL
ICON IDI_ICON,IDC_STATIC_LOGO,22,23,20,20
GROUPBOX "Server log messages",IDC_EDIT_WRAPPER,7,74,399,157
CONTROL "",IDC_RICHEDIT4LOG,"RICHEDIT20W",WS_BORDER | WS_VSCROLL | WS_TABSTOP | 0x844,9,86,394,143
CONTROL "",IDC_RICHEDIT4LOG,"RichEdit20W",ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | WS_BORDER | WS_VSCROLL | WS_TABSTOP,9,86,394,143
PUSHBUTTON "Visit URL",IDC_BUTTON_VISIT_URL,7,58,399,16
PUSHBUTTON "Clear Log",IDC_BUTTON_CLEAR_LOG,6,233,114,16
PUSHBUTTON "Generate the VHosts' directories now",IDC_BUTTON_CREATE_VHOSTS_DIRS,236,233,170,16
Expand All @@ -128,6 +128,10 @@ BEGIN
BEGIN
BOTTOMMARGIN, 252
END

IDD_FORMVIEW20, DIALOG
BEGIN
END
END
#endif // APSTUDIO_INVOKED

Expand Down
4 changes: 3 additions & 1 deletion win32/examples/mongoose_book_samples_server.resource.h
Expand Up @@ -12,9 +12,11 @@
#define IDR_HTML_DEVELOPER_INFO 204
#define IDC_RICHEDIT4LOG 1000
#define IDC_EDIT_WRAPPER 1001
#define IDC_STATIC_LOGO 1002
#define IDC_BUTTON_VISIT_URL 1003
#define IDC_BUTTON_CLEAR_LOG 1004
#define IDC_BUTTON_CREATE_VHOSTS_DIRS 1005
#define IDC_STATIC_START_ID 60000
#define IDC_STATIC -1

// Next default values for new objects
Expand All @@ -24,7 +26,7 @@
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 205
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1002
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

0 comments on commit 43e8547

Please sign in to comment.