summaryrefslogtreecommitdiff
path: root/src/modules/utils/resizer.cpp
blob: 0f9b0b418f1ff5b332d13d7787a340ec186c27ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*

Miranda IM: the free IM client for Microsoft* Windows*

Copyright 2000-2009 Miranda ICQ/IM project, 
all portions of this codebase are copyrighted to the people 
listed in contributors.txt.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
#include "..\..\core\commonheaders.h"

typedef struct {
	DWORD  helpID;
	DWORD  exStyle;
	DWORD  style;
	short  x;
	short  y;
	short  cx;
	short  cy;
	DWORD  id;
} START_OF_DLGITEMTEMPLATEEX;

typedef struct {
	WORD   dlgVer;
	WORD   signature;
	DWORD  helpID;
	DWORD  exStyle;
	DWORD  style;
	WORD   cDlgItems;
	short  x;
	short  y;
	short  cx;
	short  cy;
} START_OF_DLGTEMPLATEEX;

INT_PTR ResizeDialog(WPARAM, LPARAM lParam)
{
	UTILRESIZEDIALOG *urd = (UTILRESIZEDIALOG*)lParam;
	HDWP hDwp;
	int i;
	DLGITEMTEMPLATE *pItem = NULL;
	START_OF_DLGITEMTEMPLATEEX *pItemEx = NULL;
	RECT rc;
	PWORD pWord;
	DLGTEMPLATE *pTemplate;
	START_OF_DLGTEMPLATEEX *pTemplateEx;
	UTILRESIZECONTROL urc;
	int procResult;
	int extendedDlg, itemCount;

	if (urd == NULL || urd->cbSize != sizeof(UTILRESIZEDIALOG)) return 1;
	pTemplate = (DLGTEMPLATE*)LockResource(LoadResource(urd->hInstance, FindResourceA(urd->hInstance, urd->lpTemplate, MAKEINTRESOURCEA(5))));
	pTemplateEx = (START_OF_DLGTEMPLATEEX*)pTemplate;
	extendedDlg = pTemplateEx->signature == 0xFFFF;
	if (extendedDlg && pTemplateEx->dlgVer != 1)
		return 1;

	if (extendedDlg) pWord = (PWORD)(pTemplateEx+1);
	else pWord = (PWORD)(pTemplate+1);
	if (*pWord == 0xFFFF) pWord+=2; else while (*pWord++);   //menu
	if (*pWord == 0xFFFF) pWord+=2; else while (*pWord++);   //class
	while (*pWord++);   //title
	if (extendedDlg) {
		if (pTemplateEx->style&DS_SETFONT) {
			pWord+=3;    //font size, weight, italic
			while (*pWord++);   //font name
		}
	}
	else {
		if (pTemplate->style&DS_SETFONT) {
			pWord++;    //font size
			while (*pWord++);   //font name
		}
	}

	urc.cbSize = sizeof(UTILRESIZECONTROL);
	rc.left = 0; rc.top = 0;
	if (extendedDlg) {rc.right = pTemplateEx->cx; rc.bottom = pTemplateEx->cy;}
	else {rc.right = pTemplate->cx; rc.bottom = pTemplate->cy;}
	MapDialogRect(urd->hwndDlg, &rc);
	urc.dlgOriginalSize.cx = rc.right; urc.dlgOriginalSize.cy = rc.bottom;
	GetClientRect(urd->hwndDlg, &rc);
	urc.dlgNewSize.cx = rc.right; urc.dlgNewSize.cy = rc.bottom;

	if (extendedDlg) itemCount = pTemplateEx->cDlgItems;
	else itemCount = pTemplate->cdit;
	hDwp = BeginDeferWindowPos(itemCount);
	for (i=0;i<itemCount;i++) {
		if ((UINT_PTR)pWord&2) pWord++;       //dword align

		if (extendedDlg) {
			pItemEx = (START_OF_DLGITEMTEMPLATEEX*)pWord;
			pWord = (PWORD)(pItemEx+1);

			urc.wId = pItemEx->id;
			urc.rcItem.left = pItemEx->x; urc.rcItem.top = pItemEx->y;
			urc.rcItem.right = urc.rcItem.left+pItemEx->cx; urc.rcItem.bottom = urc.rcItem.top+pItemEx->cy;
		}
		else {
			pItem = (DLGITEMTEMPLATE*)pWord;
			pWord = (PWORD)(pItem+1);

			urc.wId = pItem->id;
			urc.rcItem.left = pItem->x; urc.rcItem.top = pItem->y;
			urc.rcItem.right = urc.rcItem.left+pItem->cx; urc.rcItem.bottom = urc.rcItem.top+pItem->cy;
		}
		if (*pWord == 0xFFFF) pWord+=2; else while (*pWord++);   //menu
		if (*pWord == 0xFFFF) pWord+=2; else while (*pWord++);   //class
		pWord+=1+(1+*pWord)/2;     //creation data

		if (urc.wId == 65535) continue;  //using this breaks the dwp, so just ignore it

		MapDialogRect(urd->hwndDlg, &urc.rcItem);
		procResult = (urd->pfnResizer)(urd->hwndDlg, urd->lParam, &urc);
		if (procResult&RD_ANCHORX_RIGHT) {
			urc.rcItem.left+=urc.dlgNewSize.cx-urc.dlgOriginalSize.cx;
			urc.rcItem.right+=urc.dlgNewSize.cx-urc.dlgOriginalSize.cx;
		}
		else if (procResult&RD_ANCHORX_WIDTH)
			urc.rcItem.right+=urc.dlgNewSize.cx-urc.dlgOriginalSize.cx;
		else if (procResult&RD_ANCHORX_CENTRE) {
			urc.rcItem.left+=(urc.dlgNewSize.cx-urc.dlgOriginalSize.cx)/2;
			urc.rcItem.right+=(urc.dlgNewSize.cx-urc.dlgOriginalSize.cx)/2;
		}
		if (procResult&RD_ANCHORY_BOTTOM) {
			urc.rcItem.top+=urc.dlgNewSize.cy-urc.dlgOriginalSize.cy;
			urc.rcItem.bottom+=urc.dlgNewSize.cy-urc.dlgOriginalSize.cy;
		}
		else if (procResult&RD_ANCHORY_HEIGHT)
			urc.rcItem.bottom+=urc.dlgNewSize.cy-urc.dlgOriginalSize.cy;
		else if (procResult&RD_ANCHORY_CENTRE) {
			urc.rcItem.top+=(urc.dlgNewSize.cy-urc.dlgOriginalSize.cy)/2;
			urc.rcItem.bottom+=(urc.dlgNewSize.cy-urc.dlgOriginalSize.cy)/2;
		}
		hDwp = DeferWindowPos(hDwp, GetDlgItem(urd->hwndDlg, extendedDlg?pItemEx->id:pItem->id), 0, urc.rcItem.left, urc.rcItem.top, urc.rcItem.right-urc.rcItem.left, urc.rcItem.bottom-urc.rcItem.top, SWP_NOZORDER);
	}
	EndDeferWindowPos(hDwp);
	return 0;
}