1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-2006,2008 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
26 usedBufferLength = 0;
\r
27 totalBufferLength = 0;
\r
30 CDlgTemplate(LPCTSTR caption, DWORD style, short x, short y, short w, short h,
\r
31 LPCTSTR font = NULL, LONG fontSize = 8)
\r
34 usedBufferLength = sizeof(DLGTEMPLATE );
\r
35 totalBufferLength = usedBufferLength;
\r
37 dialogTemplate = (DLGTEMPLATE*)malloc(totalBufferLength);
\r
39 dialogTemplate->style = style;
\r
41 dialogTemplate->style |= DS_SETFONT;
\r
43 dialogTemplate->x = x;
\r
44 dialogTemplate->y = y;
\r
45 dialogTemplate->cx = w;
\r
46 dialogTemplate->cy = h;
\r
47 dialogTemplate->cdit = 0;
\r
49 dialogTemplate->dwExtendedStyle = 0;
\r
51 //the dialog box doesn't have a menu or a special class
\r
53 AppendData(_T("\0"), 2);
\r
54 AppendData(_T("\0"), 2);
\r
56 //add the dialog's caption to the template
\r
58 AppendString(caption);
\r
60 AppendData(&fontSize, sizeof(WORD));
\r
65 void AddComponent(LPCTSTR type, LPCTSTR caption, DWORD style, DWORD exStyle,
\r
66 short x, short y, short w, short h, WORD id)
\r
69 DLGITEMTEMPLATE item;
\r
78 item.dwExtendedStyle = exStyle;
\r
80 AppendData(&item, sizeof(DLGITEMTEMPLATE));
\r
83 AppendString(caption);
\r
85 WORD creationDataLength = 0;
\r
86 AppendData(&creationDataLength, sizeof(WORD));
\r
88 //increment the component count
\r
90 dialogTemplate->cdit++;
\r
94 void AddButton(LPCTSTR caption, DWORD style, DWORD exStyle, short x, short y,
\r
95 short w, short h, WORD id)
\r
98 AddStandardComponent(0x0080, caption, style, exStyle, x, y, w, h, id);
\r
100 WORD creationDataLength = 0;
\r
101 AppendData(&creationDataLength, sizeof(WORD));
\r
105 void AddEditBox(LPCTSTR caption, DWORD style, DWORD exStyle, short x, short y,
\r
106 short w, short h, WORD id)
\r
109 AddStandardComponent(0x0081, caption, style, exStyle, x, y, w, h, id);
\r
111 WORD creationDataLength = 0;
\r
112 AppendData(&creationDataLength, sizeof(WORD));
\r
116 void AddStatic(LPCTSTR caption, DWORD style, DWORD exStyle, short x, short y,
\r
117 short w, short h, WORD id)
\r
120 AddStandardComponent(0x0082, caption, style, exStyle, x, y, w, h, id);
\r
122 WORD creationDataLength = 0;
\r
123 AppendData(&creationDataLength, sizeof(WORD));
\r
127 void AddListBox(LPCTSTR caption, DWORD style, DWORD exStyle, short x, short y,
\r
128 short w, short h, WORD id)
\r
131 AddStandardComponent(0x0083, caption, style, exStyle, x, y, w, h, id);
\r
133 WORD creationDataLength = 0;
\r
134 AppendData(&creationDataLength, sizeof(WORD));
\r
138 void AddScrollBar(LPCTSTR caption, DWORD style, DWORD exStyle, short x, short y,
\r
139 short w, short h, WORD id)
\r
142 AddStandardComponent(0x0084, caption, style, exStyle, x, y, w, h, id);
\r
144 WORD creationDataLength = 0;
\r
145 AppendData(&creationDataLength, sizeof(WORD));
\r
149 void AddComboBox(LPCTSTR caption, DWORD style, DWORD exStyle, short x, short y,
\r
150 short w, short h, WORD id)
\r
153 AddStandardComponent(0x0085, caption, style, exStyle, x, y, w, h, id);
\r
155 WORD creationDataLength = 0;
\r
156 AppendData(&creationDataLength, sizeof(WORD));
\r
161 * Returns a pointer to the Win32 dialog template which the object
\r
162 * represents. This pointer may become invalid if additional
\r
163 * components are added to the template.
\r
166 operator const DLGTEMPLATE*() const
\r
168 return dialogTemplate;
\r
171 virtual ~CDlgTemplate()
\r
173 free(dialogTemplate);
\r
178 void AddStandardComponent(WORD type, LPCTSTR caption, DWORD style,
\r
179 DWORD exStyle, short x, short y, short w, short h, WORD id)
\r
182 DLGITEMTEMPLATE item;
\r
184 // DWORD align the beginning of the component data
\r
186 AlignData(sizeof(DWORD));
\r
188 item.style = style;
\r
195 item.dwExtendedStyle = exStyle;
\r
197 AppendData(&item, sizeof(DLGITEMTEMPLATE));
\r
199 WORD preType = 0xFFFF;
\r
201 AppendData(&preType, sizeof(WORD));
\r
202 AppendData(&type, sizeof(WORD));
\r
204 AppendString(caption);
\r
206 // Increment the component count
\r
208 dialogTemplate->cdit++;
\r
212 void AlignData(int size)
\r
215 int paddingSize = usedBufferLength % size;
\r
217 if (paddingSize != 0)
\r
219 EnsureSpace(paddingSize);
\r
220 usedBufferLength += paddingSize;
\r
225 void AppendString(LPCTSTR string)
\r
228 int length = MultiByteToWideChar(CP_ACP, 0, string, -1, NULL, 0);
\r
230 int length = (int)wcslen(string)+1;
\r
232 WCHAR* wideString = (WCHAR*)malloc(sizeof(WCHAR) * length);
\r
234 MultiByteToWideChar(CP_ACP, 0, string, -1, wideString, length);
\r
236 wcscpy_s(wideString, length, string);
\r
238 AppendData(wideString, length * sizeof(WCHAR));
\r
242 void AppendData(void* data, int dataLength)
\r
245 EnsureSpace(dataLength);
\r
247 memcpy((char*)dialogTemplate + usedBufferLength, data, dataLength);
\r
248 usedBufferLength += dataLength;
\r
252 void EnsureSpace(int length)
\r
255 if (length + usedBufferLength > totalBufferLength)
\r
258 totalBufferLength += length * 2;
\r
260 void* newBuffer = malloc(totalBufferLength);
\r
261 memcpy(newBuffer, dialogTemplate, usedBufferLength);
\r
263 free(dialogTemplate);
\r
264 dialogTemplate = (DLGTEMPLATE*)newBuffer;
\r
272 DLGTEMPLATE* dialogTemplate;
\r
274 int totalBufferLength;
\r
275 int usedBufferLength;
\r