Mercurial > dwindows
comparison win/dw.c @ 617:4d1d9aeb0bbc
Add rudimentary internal logging for debug
Fix checked menus
Added dw_menu_item_set_state() to set checked status of menu item and ability to enable/disable menu items.
dw_menu_item_set_check() is deprecated
author | mhessling@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 06 Apr 2008 00:33:45 +0000 |
parents | 0ab21b3b1d52 |
children | 7d93356f250a |
comparison
equal
deleted
inserted
replaced
616:2dcfe0b33284 | 617:4d1d9aeb0bbc |
---|---|
47 #endif | 47 #endif |
48 | 48 |
49 static BOOL (WINAPI* MyGetMenuInfo)(HMENU, LPCMENUINFO) = 0; | 49 static BOOL (WINAPI* MyGetMenuInfo)(HMENU, LPCMENUINFO) = 0; |
50 static BOOL (WINAPI* MySetMenuInfo)(HMENU, LPCMENUINFO) = 0; | 50 static BOOL (WINAPI* MySetMenuInfo)(HMENU, LPCMENUINFO) = 0; |
51 | 51 |
52 FILE *dbgfp = NULL; | |
53 | |
52 int main(int argc, char *argv[]); | 54 int main(int argc, char *argv[]); |
53 | 55 |
54 #define ICON_INDEX_LIMIT 200 | 56 #define ICON_INDEX_LIMIT 200 |
55 HICON lookup[200]; | 57 HICON lookup[200]; |
56 HIMAGELIST hSmall = 0, hLarge = 0; | 58 HIMAGELIST hSmall = 0, hLarge = 0; |
63 COLORREF _background[THREAD_LIMIT]; | 65 COLORREF _background[THREAD_LIMIT]; |
64 HPEN _hPen[THREAD_LIMIT]; | 66 HPEN _hPen[THREAD_LIMIT]; |
65 HBRUSH _hBrush[THREAD_LIMIT]; | 67 HBRUSH _hBrush[THREAD_LIMIT]; |
66 char *_clipboard_contents[THREAD_LIMIT]; | 68 char *_clipboard_contents[THREAD_LIMIT]; |
67 | 69 |
68 BYTE _red[] = { 0x00, 0xbb, 0x00, 0xaa, 0x00, 0xbb, 0x00, 0xaa, 0x77, | 70 BYTE _red[] = { 0x00, 0xbb, 0x00, 0xaa, 0x00, 0xbb, 0x00, 0xaa, 0x77, |
69 0xff, 0x00, 0xee, 0x00, 0xff, 0x00, 0xff, 0xaa, 0x00 }; | 71 0xff, 0x00, 0xee, 0x00, 0xff, 0x00, 0xff, 0xaa, 0x00 }; |
70 BYTE _green[] = { 0x00, 0x00, 0xbb, 0xaa, 0x00, 0x00, 0xbb, 0xaa, 0x77, | 72 BYTE _green[] = { 0x00, 0x00, 0xbb, 0xaa, 0x00, 0x00, 0xbb, 0xaa, 0x77, |
71 0x00, 0xff, 0xee, 0x00, 0x00, 0xee, 0xff, 0xaa, 0x00 }; | 73 0x00, 0xff, 0xee, 0x00, 0x00, 0xee, 0xff, 0xaa, 0x00 }; |
72 BYTE _blue[] = { 0x00, 0x00, 0x00, 0x00, 0xcc, 0xbb, 0xbb, 0xaa, 0x77, | 74 BYTE _blue[] = { 0x00, 0x00, 0x00, 0x00, 0xcc, 0xbb, 0xbb, 0xaa, 0x77, |
73 0x00, 0x00, 0x00, 0xff, 0xff, 0xee, 0xff, 0xaa, 0x00}; | 75 0x00, 0x00, 0x00, 0xff, 0xff, 0xee, 0xff, 0xaa, 0x00}; |
74 | 76 |
75 HBRUSH _colors[18]; | 77 HBRUSH _colors[18]; |
76 | 78 |
77 | 79 |
78 LRESULT CALLBACK _browserWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); | 80 LRESULT CALLBACK _browserWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); |
81 int _lookup_icon(HWND handle, HICON hicon, int type); | 83 int _lookup_icon(HWND handle, HICON hicon, int type); |
82 HFONT _acquire_font(HWND handle, char *fontname); | 84 HFONT _acquire_font(HWND handle, char *fontname); |
83 | 85 |
84 typedef struct _sighandler | 86 typedef struct _sighandler |
85 { | 87 { |
86 struct _sighandler *next; | 88 struct _sighandler *next; |
87 ULONG message; | 89 ULONG message; |
88 HWND window; | 90 HWND window; |
89 int id; | 91 int id; |
90 void *signalfunction; | 92 void *signalfunction; |
91 void *data; | 93 void *data; |
92 | 94 |
93 } SignalHandler; | 95 } SignalHandler; |
94 | 96 |
95 SignalHandler *Root = NULL; | 97 SignalHandler *Root = NULL; |
96 | 98 |
97 typedef struct | 99 typedef struct |
98 { | 100 { |
99 ULONG message; | 101 ULONG message; |
100 char name[30]; | 102 char name[30]; |
101 | 103 |
102 } SignalList; | 104 } SignalList; |
103 | 105 |
104 static int in_checkbox_handler = 0; | 106 static int in_checkbox_handler = 0; |
105 | 107 |
106 /* List of signals and their equivilent Win32 message */ | 108 /* List of signals and their equivilent Win32 message */ |
107 #define SIGNALMAX 17 | 109 #define SIGNALMAX 17 |
108 | 110 |
109 SignalList SignalTranslate[SIGNALMAX] = { | 111 SignalList SignalTranslate[SIGNALMAX] = { |
110 { WM_SIZE, DW_SIGNAL_CONFIGURE }, | 112 { WM_SIZE, DW_SIGNAL_CONFIGURE }, |
111 { WM_CHAR, DW_SIGNAL_KEY_PRESS }, | 113 { WM_CHAR, DW_SIGNAL_KEY_PRESS }, |
112 { WM_LBUTTONDOWN, DW_SIGNAL_BUTTON_PRESS }, | 114 { WM_LBUTTONDOWN, DW_SIGNAL_BUTTON_PRESS }, |
113 { WM_LBUTTONUP, DW_SIGNAL_BUTTON_RELEASE }, | 115 { WM_LBUTTONUP, DW_SIGNAL_BUTTON_RELEASE }, |
114 { WM_MOUSEMOVE, DW_SIGNAL_MOTION_NOTIFY }, | 116 { WM_MOUSEMOVE, DW_SIGNAL_MOTION_NOTIFY }, |
115 { WM_CLOSE, DW_SIGNAL_DELETE }, | 117 { WM_CLOSE, DW_SIGNAL_DELETE }, |
116 { WM_PAINT, DW_SIGNAL_EXPOSE }, | 118 { WM_PAINT, DW_SIGNAL_EXPOSE }, |
117 { WM_COMMAND, DW_SIGNAL_CLICKED }, | 119 { WM_COMMAND, DW_SIGNAL_CLICKED }, |
118 { NM_DBLCLK, DW_SIGNAL_ITEM_ENTER }, | 120 { NM_DBLCLK, DW_SIGNAL_ITEM_ENTER }, |
119 { NM_RCLICK, DW_SIGNAL_ITEM_CONTEXT }, | 121 { NM_RCLICK, DW_SIGNAL_ITEM_CONTEXT }, |
120 { LBN_SELCHANGE, DW_SIGNAL_LIST_SELECT }, | 122 { LBN_SELCHANGE, DW_SIGNAL_LIST_SELECT }, |
121 { TVN_SELCHANGED, DW_SIGNAL_ITEM_SELECT }, | 123 { TVN_SELCHANGED, DW_SIGNAL_ITEM_SELECT }, |
122 { WM_SETFOCUS, DW_SIGNAL_SET_FOCUS }, | 124 { WM_SETFOCUS, DW_SIGNAL_SET_FOCUS }, |
123 { WM_VSCROLL, DW_SIGNAL_VALUE_CHANGED }, | 125 { WM_VSCROLL, DW_SIGNAL_VALUE_CHANGED }, |
124 { TCN_SELCHANGE, DW_SIGNAL_SWITCH_PAGE }, | 126 { TCN_SELCHANGE, DW_SIGNAL_SWITCH_PAGE }, |
125 { LVN_COLUMNCLICK, DW_SIGNAL_COLUMN_CLICK }, | 127 { LVN_COLUMNCLICK, DW_SIGNAL_COLUMN_CLICK }, |
126 { TVN_ITEMEXPANDED,DW_SIGNAL_TREE_EXPAND } | 128 { TVN_ITEMEXPANDED,DW_SIGNAL_TREE_EXPAND } |
127 }; | 129 }; |
130 | |
131 static void _dw_log( char *format, ... ) | |
132 { | |
133 va_list args; | |
134 va_start(args, format); | |
135 if ( dbgfp != NULL ) | |
136 { | |
137 vfprintf( dbgfp, format, args ); | |
138 fflush( dbgfp ); | |
139 } | |
140 va_end(args); | |
141 } | |
128 | 142 |
129 #ifdef BUILD_DLL | 143 #ifdef BUILD_DLL |
130 void Win32_Set_Instance(HINSTANCE hInstance) | 144 void Win32_Set_Instance(HINSTANCE hInstance) |
131 { | 145 { |
132 DWInstance = hInstance; | 146 DWInstance = hInstance; |
133 } | 147 } |
134 #else | 148 #else |
135 char **_convertargs(int *count, char *start) | 149 char **_convertargs(int *count, char *start) |
136 { | 150 { |
137 char *tmp, *argstart, **argv; | 151 char *tmp, *argstart, **argv; |
138 int loc = 0, inquotes = 0; | 152 int loc = 0, inquotes = 0; |
139 | 153 |
140 (*count) = 1; | 154 (*count) = 1; |
141 | 155 |
142 tmp = start; | 156 tmp = start; |
143 | 157 |
144 /* Count the number of entries */ | 158 /* Count the number of entries */ |
145 if(*start) | 159 if(*start) |
146 { | 160 { |
147 (*count)++; | 161 (*count)++; |
148 | 162 |
149 while(*tmp) | 163 while(*tmp) |
150 { | 164 { |
151 if(*tmp == '"' && inquotes) | 165 if(*tmp == '"' && inquotes) |
152 inquotes = 0; | 166 inquotes = 0; |
153 else if(*tmp == '"' && !inquotes) | 167 else if(*tmp == '"' && !inquotes) |
154 inquotes = 1; | 168 inquotes = 1; |
155 else if(*tmp == ' ' && !inquotes) | 169 else if(*tmp == ' ' && !inquotes) |
156 { | 170 { |
157 /* Push past any white space */ | 171 /* Push past any white space */ |
158 while(*(tmp+1) == ' ') | 172 while(*(tmp+1) == ' ') |
159 tmp++; | 173 tmp++; |
160 /* If we aren't at the end of the command | 174 /* If we aren't at the end of the command |
161 * line increment the count. | 175 * line increment the count. |
162 */ | 176 */ |
163 if(*(tmp+1)) | 177 if(*(tmp+1)) |
164 (*count)++; | 178 (*count)++; |
165 } | 179 } |
166 tmp++; | 180 tmp++; |
167 } | 181 } |
168 } | 182 } |
169 | 183 |
170 argv = (char **)malloc(sizeof(char *) * ((*count)+1)); | 184 argv = (char **)malloc(sizeof(char *) * ((*count)+1)); |
171 argv[0] = malloc(260); | 185 argv[0] = malloc(260); |
172 GetModuleFileName(DWInstance, argv[0], 260); | 186 GetModuleFileName(DWInstance, argv[0], 260); |
173 | 187 |
174 argstart = tmp = start; | 188 argstart = tmp = start; |
175 | 189 |
176 if(*start) | 190 if(*start) |
177 { | 191 { |
178 loc = 1; | 192 loc = 1; |
179 | 193 |
180 while(*tmp) | 194 while(*tmp) |
181 { | 195 { |
182 if(*tmp == '"' && inquotes) | 196 if(*tmp == '"' && inquotes) |
183 { | 197 { |
184 *tmp = 0; | 198 *tmp = 0; |
185 inquotes = 0; | 199 inquotes = 0; |
186 } | 200 } |
187 else if(*tmp == '"' && !inquotes) | 201 else if(*tmp == '"' && !inquotes) |
188 { | 202 { |
189 argstart = tmp+1; | 203 argstart = tmp+1; |
190 inquotes = 1; | 204 inquotes = 1; |
191 } | 205 } |
192 else if(*tmp == ' ' && !inquotes) | 206 else if(*tmp == ' ' && !inquotes) |
193 { | 207 { |
194 *tmp = 0; | 208 *tmp = 0; |
195 argv[loc] = strdup(argstart); | 209 argv[loc] = strdup(argstart); |
196 | 210 |
197 /* Push past any white space */ | 211 /* Push past any white space */ |
198 while(*(tmp+1) == ' ') | 212 while(*(tmp+1) == ' ') |
199 tmp++; | 213 tmp++; |
200 | 214 |
201 /* Move the start pointer */ | 215 /* Move the start pointer */ |
202 argstart = tmp+1; | 216 argstart = tmp+1; |
203 | 217 |
204 /* If we aren't at the end of the command | 218 /* If we aren't at the end of the command |
205 * line increment the count. | 219 * line increment the count. |
206 */ | 220 */ |
207 if(*(tmp+1)) | 221 if(*(tmp+1)) |
208 loc++; | 222 loc++; |
209 } | 223 } |
210 tmp++; | 224 tmp++; |
211 } | 225 } |
212 if(*argstart) | 226 if(*argstart) |
213 argv[loc] = strdup(argstart); | 227 argv[loc] = strdup(argstart); |
214 } | 228 } |
215 argv[loc+1] = NULL; | 229 argv[loc+1] = NULL; |
216 return argv; | 230 return argv; |
217 } | 231 } |
218 | 232 |
219 /* Ok this is a really big hack but what the hell ;) */ | 233 /* Ok this is a really big hack but what the hell ;) */ |
220 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) | 234 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) |
221 { | 235 { |
222 char **argv; | 236 char **argv; |
223 int argc; | 237 int argc; |
224 | 238 |
225 DWInstance = hInstance; | 239 DWInstance = hInstance; |
226 | 240 |
227 argv = _convertargs(&argc, lpCmdLine); | 241 argv = _convertargs(&argc, lpCmdLine); |
228 | 242 |
229 return main(argc, argv); | 243 return main(argc, argv); |
230 } | 244 } |
231 #endif | 245 #endif |
232 | 246 |
233 /* This should return true for WinNT/2K/XP and false on Win9x */ | 247 /* This should return true for WinNT/2K/XP and false on Win9x */ |
234 int IsWinNT(void) | 248 int IsWinNT(void) |
235 { | 249 { |
236 static int isnt = -1; | 250 static int isnt = -1; |
237 | 251 |
238 if(isnt == -1) | 252 if(isnt == -1) |
239 { | 253 { |
240 if (GetVersion() < 0x80000000) | 254 if (GetVersion() < 0x80000000) |
241 isnt = 1; | 255 isnt = 1; |
242 else | 256 else |
243 isnt = 0; | 257 isnt = 0; |
244 } | 258 } |
245 return isnt; | 259 return isnt; |
246 } | 260 } |
247 | 261 |
248 DWORD GetDllVersion(LPCTSTR lpszDllName) | 262 DWORD GetDllVersion(LPCTSTR lpszDllName) |
249 { | 263 { |
250 | 264 |
251 HINSTANCE hinstDll; | 265 HINSTANCE hinstDll; |
252 DWORD dwVersion = 0; | 266 DWORD dwVersion = 0; |
253 | 267 |
254 hinstDll = LoadLibrary(lpszDllName); | 268 hinstDll = LoadLibrary(lpszDllName); |
255 | 269 |
256 if(hinstDll) | 270 if(hinstDll) |
257 { | 271 { |
258 DLLGETVERSIONPROC pDllGetVersion; | 272 DLLGETVERSIONPROC pDllGetVersion; |
259 | 273 |
260 pDllGetVersion = (DLLGETVERSIONPROC) GetProcAddress(hinstDll, "DllGetVersion"); | 274 pDllGetVersion = (DLLGETVERSIONPROC) GetProcAddress(hinstDll, "DllGetVersion"); |
261 | 275 |
262 /* Because some DLLs might not implement this function, you | 276 /* Because some DLLs might not implement this function, you |
263 * must test for it explicitly. Depending on the particular | 277 * must test for it explicitly. Depending on the particular |
264 * DLL, the lack of a DllGetVersion function can be a useful | 278 * DLL, the lack of a DllGetVersion function can be a useful |
265 * indicator of the version. | 279 * indicator of the version. |
266 */ | 280 */ |
267 if(pDllGetVersion) | 281 if(pDllGetVersion) |
268 { | 282 { |
269 DLLVERSIONINFO dvi; | 283 DLLVERSIONINFO dvi; |
270 HRESULT hr; | 284 HRESULT hr; |
271 | 285 |
272 ZeroMemory(&dvi, sizeof(dvi)); | 286 ZeroMemory(&dvi, sizeof(dvi)); |
273 dvi.cbSize = sizeof(dvi); | 287 dvi.cbSize = sizeof(dvi); |
274 | 288 |
275 hr = (*pDllGetVersion)(&dvi); | 289 hr = (*pDllGetVersion)(&dvi); |
276 | 290 |
277 if(SUCCEEDED(hr)) | 291 if(SUCCEEDED(hr)) |
278 { | 292 { |
279 dwVersion = PACKVERSION(dvi.dwMajorVersion, dvi.dwMinorVersion); | 293 dwVersion = PACKVERSION(dvi.dwMajorVersion, dvi.dwMinorVersion); |
280 } | 294 } |
281 } | 295 } |
282 | 296 |
283 FreeLibrary(hinstDll); | 297 FreeLibrary(hinstDll); |
284 } | 298 } |
285 return dwVersion; | 299 return dwVersion; |
286 } | 300 } |
287 | 301 |
288 /* This function adds a signal handler callback into the linked list. | 302 /* This function adds a signal handler callback into the linked list. |
289 */ | 303 */ |
290 void _new_signal(ULONG message, HWND window, int id, void *signalfunction, void *data) | 304 void _new_signal(ULONG message, HWND window, int id, void *signalfunction, void *data) |
291 { | 305 { |
292 SignalHandler *new = malloc(sizeof(SignalHandler)); | 306 SignalHandler *new = malloc(sizeof(SignalHandler)); |
293 | 307 |
294 new->message = message; | 308 new->message = message; |
295 new->window = window; | 309 new->window = window; |
296 new->id = id; | 310 new->id = id; |
297 new->signalfunction = signalfunction; | 311 new->signalfunction = signalfunction; |
298 new->data = data; | 312 new->data = data; |
299 new->next = NULL; | 313 new->next = NULL; |
300 | 314 |
301 if (!Root) | 315 if (!Root) |
302 Root = new; | 316 Root = new; |
303 else | 317 else |
304 { | 318 { |
305 SignalHandler *prev = NULL, *tmp = Root; | 319 SignalHandler *prev = NULL, *tmp = Root; |
306 while(tmp) | 320 while(tmp) |
307 { | 321 { |
308 if(tmp->message == message && | 322 if(tmp->message == message && |
309 tmp->window == window && | 323 tmp->window == window && |
310 tmp->id == id && | 324 tmp->id == id && |
311 tmp->signalfunction == signalfunction) | 325 tmp->signalfunction == signalfunction) |
312 { | 326 { |
313 tmp->data = data; | 327 tmp->data = data; |
314 free(new); | 328 free(new); |
315 return; | 329 return; |
316 } | 330 } |
317 prev = tmp; | 331 prev = tmp; |
318 tmp = tmp->next; | 332 tmp = tmp->next; |
319 } | 333 } |
320 if(prev) | 334 if(prev) |
321 prev->next = new; | 335 prev->next = new; |
322 else | 336 else |
323 Root = new; | 337 Root = new; |
324 } | 338 } |
325 } | 339 } |
326 | 340 |
327 /* Finds the message number for a given signal name */ | 341 /* Finds the message number for a given signal name */ |
328 ULONG _findsigmessage(char *signame) | 342 ULONG _findsigmessage(char *signame) |
329 { | 343 { |
330 int z; | 344 int z; |
331 | 345 |
332 for(z=0;z<SIGNALMAX;z++) | 346 for(z=0;z<SIGNALMAX;z++) |
333 { | 347 { |
334 if(stricmp(signame, SignalTranslate[z].name) == 0) | 348 if(stricmp(signame, SignalTranslate[z].name) == 0) |
335 return SignalTranslate[z].message; | 349 return SignalTranslate[z].message; |
336 } | 350 } |
337 return 0L; | 351 return 0L; |
338 } | 352 } |
339 | 353 |
340 /* This function removes and handlers on windows and frees | 354 /* This function removes and handlers on windows and frees |
341 * the user memory allocated to it. | 355 * the user memory allocated to it. |
342 */ | 356 */ |
343 BOOL CALLBACK _free_window_memory(HWND handle, LPARAM lParam) | 357 BOOL CALLBACK _free_window_memory(HWND handle, LPARAM lParam) |
344 { | 358 { |
345 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 359 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
346 HFONT oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0); | 360 HFONT oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0); |
347 HICON oldicon = (HICON)SendMessage(handle, WM_GETICON, 0, 0); | 361 HICON oldicon = (HICON)SendMessage(handle, WM_GETICON, 0, 0); |
348 char tmpbuf[100]; | 362 char tmpbuf[100]; |
349 | 363 |
350 GetClassName(handle, tmpbuf, 99); | 364 GetClassName(handle, tmpbuf, 99); |
351 | 365 |
352 /* Don't try to free memory from an OLE embedded IE */ | 366 /* Don't try to free memory from an OLE embedded IE */ |
353 if(strncmp(tmpbuf, "Internet Explorer_Server", 25) == 0) | 367 if(strncmp(tmpbuf, "Internet Explorer_Server", 25) == 0) |
354 return TRUE; | 368 return TRUE; |
355 | 369 |
356 /* Delete font, icon and bitmap GDI objects in use */ | 370 /* Delete font, icon and bitmap GDI objects in use */ |
357 if(oldfont) | 371 if(oldfont) |
358 DeleteObject(oldfont); | 372 DeleteObject(oldfont); |
359 if(oldicon) | 373 if(oldicon) |
360 DeleteObject(oldicon); | 374 DeleteObject(oldicon); |
361 | 375 |
362 if(strnicmp(tmpbuf, STATICCLASSNAME, strlen(STATICCLASSNAME)+1)==0) | 376 if(strnicmp(tmpbuf, STATICCLASSNAME, strlen(STATICCLASSNAME)+1)==0) |
363 { | 377 { |
364 HBITMAP oldbitmap = (HBITMAP)SendMessage(handle, STM_GETIMAGE, IMAGE_BITMAP, 0); | 378 HBITMAP oldbitmap = (HBITMAP)SendMessage(handle, STM_GETIMAGE, IMAGE_BITMAP, 0); |
365 | 379 |
366 if(oldbitmap) | 380 if(oldbitmap) |
367 DeleteObject(oldbitmap); | 381 DeleteObject(oldbitmap); |
368 } | 382 } |
369 if(strnicmp(tmpbuf, BUTTONCLASSNAME, strlen(BUTTONCLASSNAME)+1)==0) | 383 if(strnicmp(tmpbuf, BUTTONCLASSNAME, strlen(BUTTONCLASSNAME)+1)==0) |
370 { | 384 { |
371 HBITMAP oldbitmap = (HBITMAP)SendMessage(handle, BM_GETIMAGE, IMAGE_BITMAP, 0); | 385 HBITMAP oldbitmap = (HBITMAP)SendMessage(handle, BM_GETIMAGE, IMAGE_BITMAP, 0); |
372 | 386 |
373 if(oldbitmap) | 387 if(oldbitmap) |
374 DeleteObject(oldbitmap); | 388 DeleteObject(oldbitmap); |
375 } | 389 } |
376 else if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1)==0) | 390 else if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1)==0) |
377 { | 391 { |
378 Box *box = (Box *)thiscinfo; | 392 Box *box = (Box *)thiscinfo; |
379 | 393 |
380 if(box && box->count && box->items) | 394 if(box && box->count && box->items) |
381 free(box->items); | 395 free(box->items); |
382 } | 396 } |
383 else if(strnicmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0) | 397 else if(strnicmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0) |
384 { | 398 { |
385 void *data = dw_window_get_data(handle, "_dw_percent"); | 399 void *data = dw_window_get_data(handle, "_dw_percent"); |
386 | 400 |
387 if(data) | 401 if(data) |
388 free(data); | 402 free(data); |
389 } | 403 } |
390 else if(strnicmp(tmpbuf, WC_TREEVIEW, strlen(WC_TREEVIEW)+1)==0) | 404 else if(strnicmp(tmpbuf, WC_TREEVIEW, strlen(WC_TREEVIEW)+1)==0) |
391 { | 405 { |
392 dw_tree_clear(handle); | 406 dw_tree_clear(handle); |
393 } | 407 } |
394 else if(strnicmp(tmpbuf, WC_TABCONTROL, strlen(WC_TABCONTROL)+1)==0) /* Notebook */ | 408 else if(strnicmp(tmpbuf, WC_TABCONTROL, strlen(WC_TABCONTROL)+1)==0) /* Notebook */ |
395 { | 409 { |
396 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); | 410 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); |
397 | 411 |
398 if(array) | 412 if(array) |
399 { | 413 { |
400 int z; | 414 int z; |
401 | 415 |
402 for(z=0;z<256;z++) | 416 for(z=0;z<256;z++) |
403 { | 417 { |
404 if(array[z]) | 418 if(array[z]) |
405 { | 419 { |
406 _free_window_memory(array[z]->hwnd, 0); | 420 _free_window_memory(array[z]->hwnd, 0); |
407 EnumChildWindows(array[z]->hwnd, _free_window_memory, 0); | 421 EnumChildWindows(array[z]->hwnd, _free_window_memory, 0); |
408 DestroyWindow(array[z]->hwnd); | 422 DestroyWindow(array[z]->hwnd); |
409 free(array[z]); | 423 free(array[z]); |
410 } | 424 } |
411 } | 425 } |
412 free(array); | 426 free(array); |
413 } | 427 } |
414 } | 428 } |
415 | 429 |
416 dw_signal_disconnect_by_window(handle); | 430 dw_signal_disconnect_by_window(handle); |
417 | 431 |
418 if(thiscinfo) | 432 if(thiscinfo) |
419 { | 433 { |
420 SubclassWindow(handle, thiscinfo->pOldProc); | 434 SubclassWindow(handle, thiscinfo->pOldProc); |
421 | 435 |
422 /* Delete the brush so as not to leak GDI objects */ | 436 /* Delete the brush so as not to leak GDI objects */ |
423 if(thiscinfo->hbrush) | 437 if(thiscinfo->hbrush) |
424 DeleteObject(thiscinfo->hbrush); | 438 DeleteObject(thiscinfo->hbrush); |
425 | 439 |
426 /* Free user data linked list memory */ | 440 /* Free user data linked list memory */ |
427 if(thiscinfo->root) | 441 if(thiscinfo->root) |
428 dw_window_set_data(handle, NULL, NULL); | 442 dw_window_set_data(handle, NULL, NULL); |
429 | 443 |
430 SetWindowLongPtr(handle, GWLP_USERDATA, 0); | 444 SetWindowLongPtr(handle, GWLP_USERDATA, 0); |
431 free(thiscinfo); | 445 free(thiscinfo); |
432 } | 446 } |
433 return TRUE; | 447 return TRUE; |
434 } | 448 } |
435 | 449 |
436 void _free_menu_data(HMENU menu) | 450 void _free_menu_data(HMENU menu) |
437 { | 451 { |
438 if(!IS_WINNTOR95) | 452 if (!IS_WINNTOR95 ) |
439 { | 453 { |
440 int i, count = GetMenuItemCount(menu); | 454 int i, count = GetMenuItemCount(menu); |
441 | 455 |
442 for(i=0;i<count;i++) | 456 for(i=0;i<count;i++) |
443 { | 457 { |
444 MENUITEMINFO mii; | 458 MENUITEMINFO mii; |
445 | 459 |
446 mii.cbSize = sizeof(MENUITEMINFO); | 460 mii.cbSize = sizeof(MENUITEMINFO); |
447 mii.fMask = MIIM_SUBMENU; | 461 mii.fMask = MIIM_SUBMENU; |
448 | 462 |
449 if(GetMenuItemInfo(menu, i, TRUE, &mii) | 463 if ( GetMenuItemInfo( menu, i, TRUE, &mii ) |
450 && mii.hSubMenu) | 464 && mii.hSubMenu ) |
451 _free_menu_data(mii.hSubMenu); | 465 _free_menu_data(mii.hSubMenu); |
452 } | 466 } |
453 } | 467 } |
454 dw_signal_disconnect_by_name((HWND)menu, DW_SIGNAL_CLICKED); | 468 dw_signal_disconnect_by_name((HWND)menu, DW_SIGNAL_CLICKED); |
455 } | 469 } |
456 | 470 |
457 /* Convert to our internal color scheme */ | 471 /* Convert to our internal color scheme */ |
458 ULONG _internal_color(ULONG color) | 472 ULONG _internal_color(ULONG color) |
459 { | 473 { |
460 if(color == DW_CLR_DEFAULT) | 474 if(color == DW_CLR_DEFAULT) |
461 return DW_RGB_TRANSPARENT; | 475 return DW_RGB_TRANSPARENT; |
462 if(color < 18) | 476 if(color < 18) |
463 return DW_RGB(_red[color], _green[color], _blue[color]); | 477 return DW_RGB(_red[color], _green[color], _blue[color]); |
464 return color; | 478 return color; |
465 } | 479 } |
466 | 480 |
467 /* This function returns 1 if the window (widget) handle | 481 /* This function returns 1 if the window (widget) handle |
468 * passed to it is a valid window that can gain input focus. | 482 * passed to it is a valid window that can gain input focus. |
469 */ | 483 */ |
470 int _validate_focus(HWND handle) | 484 int _validate_focus(HWND handle) |
471 { | 485 { |
472 char tmpbuf[100]; | 486 char tmpbuf[100]; |
473 | 487 |
474 if(!handle) | 488 if(!handle) |
475 return 0; | 489 return 0; |
476 | 490 |
477 if(!IsWindowEnabled(handle)) | 491 if(!IsWindowEnabled(handle)) |
478 return 0; | 492 return 0; |
479 | 493 |
480 GetClassName(handle, tmpbuf, 99); | 494 GetClassName(handle, tmpbuf, 99); |
481 | 495 |
482 /* These are the window classes which can | 496 /* These are the window classes which can |
483 * obtain input focus. | 497 * obtain input focus. |
484 */ | 498 */ |
485 if(strnicmp(tmpbuf, EDITCLASSNAME, strlen(EDITCLASSNAME)+1)==0 || /* Entryfield */ | 499 if(strnicmp(tmpbuf, EDITCLASSNAME, strlen(EDITCLASSNAME)+1)==0 || /* Entryfield */ |
486 strnicmp(tmpbuf, BUTTONCLASSNAME, strlen(BUTTONCLASSNAME)+1)==0 || /* Button */ | 500 strnicmp(tmpbuf, BUTTONCLASSNAME, strlen(BUTTONCLASSNAME)+1)==0 || /* Button */ |
487 strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0 || /* Combobox */ | 501 strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0 || /* Combobox */ |
488 strnicmp(tmpbuf, LISTBOXCLASSNAME, strlen(LISTBOXCLASSNAME)+1)==0 || /* List box */ | 502 strnicmp(tmpbuf, LISTBOXCLASSNAME, strlen(LISTBOXCLASSNAME)+1)==0 || /* List box */ |
489 strnicmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1)==0 || /* Spinbutton */ | 503 strnicmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1)==0 || /* Spinbutton */ |
490 strnicmp(tmpbuf, TRACKBAR_CLASS, strlen(TRACKBAR_CLASS)+1)==0 || /* Slider */ | 504 strnicmp(tmpbuf, TRACKBAR_CLASS, strlen(TRACKBAR_CLASS)+1)==0 || /* Slider */ |
491 strnicmp(tmpbuf, WC_LISTVIEW, strlen(WC_LISTVIEW)+1)== 0 || /* Container */ | 505 strnicmp(tmpbuf, WC_LISTVIEW, strlen(WC_LISTVIEW)+1)== 0 || /* Container */ |
492 strnicmp(tmpbuf, WC_TREEVIEW, strlen(WC_TREEVIEW)+1)== 0) /* Tree */ | 506 strnicmp(tmpbuf, WC_TREEVIEW, strlen(WC_TREEVIEW)+1)== 0) /* Tree */ |
493 return 1; | 507 return 1; |
494 return 0; | 508 return 0; |
495 } | 509 } |
496 | 510 |
497 HWND _normalize_handle(HWND handle) | 511 HWND _normalize_handle(HWND handle) |
498 { | 512 { |
499 char tmpbuf[100] = ""; | 513 char tmpbuf[100] = ""; |
500 | 514 |
501 GetClassName(handle, tmpbuf, 99); | 515 GetClassName(handle, tmpbuf, 99); |
502 if(strnicmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS))==0) /* Spinner */ | 516 if(strnicmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS))==0) /* Spinner */ |
503 { | 517 { |
504 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 518 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
505 | 519 |
506 if(cinfo && cinfo->buddy) | 520 if(cinfo && cinfo->buddy) |
507 return cinfo->buddy; | 521 return cinfo->buddy; |
508 } | 522 } |
509 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME))==0) /* Combobox */ | 523 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME))==0) /* Combobox */ |
510 { | 524 { |
511 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 525 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
512 | 526 |
513 if(cinfo && cinfo->buddy) | 527 if(cinfo && cinfo->buddy) |
514 return cinfo->buddy; | 528 return cinfo->buddy; |
515 } | 529 } |
516 return handle; | 530 return handle; |
517 } | 531 } |
518 | 532 |
519 int _focus_check_box(Box *box, HWND handle, int start, HWND defaultitem) | 533 int _focus_check_box(Box *box, HWND handle, int start, HWND defaultitem) |
520 { | 534 { |
521 int z; | 535 int z; |
522 static HWND lasthwnd, firsthwnd; | 536 static HWND lasthwnd, firsthwnd; |
523 static int finish_searching; | 537 static int finish_searching; |
524 | 538 |
525 /* Start is 2 when we have cycled completely and | 539 /* Start is 2 when we have cycled completely and |
526 * need to set the focus to the last widget we found | 540 * need to set the focus to the last widget we found |
527 * that was valid. | 541 * that was valid. |
528 */ | 542 */ |
529 if(start == 2) | 543 if(start == 2) |
530 { | 544 { |
531 if(lasthwnd) | 545 if(lasthwnd) |
532 SetFocus(lasthwnd); | 546 SetFocus(lasthwnd); |
533 return 0; | 547 return 0; |
534 } | 548 } |
535 | 549 |
536 /* Start is 1 when we are entering the function | 550 /* Start is 1 when we are entering the function |
537 * for the first time, it is zero when entering | 551 * for the first time, it is zero when entering |
538 * the function recursively. | 552 * the function recursively. |
539 */ | 553 */ |
540 if(start == 1) | 554 if(start == 1) |
541 { | 555 { |
542 lasthwnd = handle; | 556 lasthwnd = handle; |
543 finish_searching = 0; | 557 finish_searching = 0; |
544 firsthwnd = 0; | 558 firsthwnd = 0; |
545 } | 559 } |
546 | 560 |
547 for(z=box->count-1;z>-1;z--) | 561 for(z=box->count-1;z>-1;z--) |
548 { | 562 { |
549 if(box->items[z].type == TYPEBOX) | 563 if(box->items[z].type == TYPEBOX) |
550 { | 564 { |
551 Box *thisbox = (Box *)GetWindowLongPtr(box->items[z].hwnd, GWLP_USERDATA); | 565 Box *thisbox = (Box *)GetWindowLongPtr(box->items[z].hwnd, GWLP_USERDATA); |
552 | 566 |
553 if(thisbox && _focus_check_box(thisbox, handle, start == 3 ? 3 : 0, defaultitem)) | 567 if(thisbox && _focus_check_box(thisbox, handle, start == 3 ? 3 : 0, defaultitem)) |
554 return 1; | 568 return 1; |
555 } | 569 } |
556 else | 570 else |
557 { | 571 { |
558 if(box->items[z].hwnd == handle) | 572 if(box->items[z].hwnd == handle) |
559 { | 573 { |
560 if(lasthwnd == handle && firsthwnd) | 574 if(lasthwnd == handle && firsthwnd) |
561 SetFocus(firsthwnd); | 575 SetFocus(firsthwnd); |
562 else if(lasthwnd == handle && !firsthwnd) | 576 else if(lasthwnd == handle && !firsthwnd) |
563 finish_searching = 1; | 577 finish_searching = 1; |
564 else | 578 else |
565 SetFocus(lasthwnd); | 579 SetFocus(lasthwnd); |
566 | 580 |
567 /* If we aren't looking for the last handle, | 581 /* If we aren't looking for the last handle, |
568 * return immediately. | 582 * return immediately. |
569 */ | 583 */ |
570 if(!finish_searching) | 584 if(!finish_searching) |
571 return 1; | 585 return 1; |
572 } | 586 } |
573 if(_validate_focus(box->items[z].hwnd)) | 587 if(_validate_focus(box->items[z].hwnd)) |
574 { | 588 { |
575 /* Start is 3 when we are looking for the | 589 /* Start is 3 when we are looking for the |
576 * first valid item in the layout. | 590 * first valid item in the layout. |
577 */ | 591 */ |
578 if(start == 3) | 592 if(start == 3) |
579 { | 593 { |
580 if(!defaultitem || (defaultitem && box->items[z].hwnd == defaultitem)) | 594 if(!defaultitem || (defaultitem && box->items[z].hwnd == defaultitem)) |
581 { | 595 { |
582 SetFocus(_normalize_handle(box->items[z].hwnd)); | 596 SetFocus(_normalize_handle(box->items[z].hwnd)); |
583 return 1; | 597 return 1; |
584 } | 598 } |
585 } | 599 } |
586 | 600 |
587 if(!firsthwnd) | 601 if(!firsthwnd) |
588 firsthwnd = _normalize_handle(box->items[z].hwnd); | 602 firsthwnd = _normalize_handle(box->items[z].hwnd); |
589 | 603 |
590 lasthwnd = _normalize_handle(box->items[z].hwnd); | 604 lasthwnd = _normalize_handle(box->items[z].hwnd); |
591 } | 605 } |
592 else | 606 else |
593 { | 607 { |
594 char tmpbuf[100] = ""; | 608 char tmpbuf[100] = ""; |
595 | 609 |
596 GetClassName(box->items[z].hwnd, tmpbuf, 99); | 610 GetClassName(box->items[z].hwnd, tmpbuf, 99); |
597 | 611 |
598 if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0) | 612 if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0) |
599 { | 613 { |
600 /* Then try the bottom or right box */ | 614 /* Then try the bottom or right box */ |
601 HWND mybox = (HWND)dw_window_get_data(box->items[z].hwnd, "_dw_bottomright"); | 615 HWND mybox = (HWND)dw_window_get_data(box->items[z].hwnd, "_dw_bottomright"); |
602 | 616 |
603 if(mybox) | 617 if(mybox) |
604 { | 618 { |
605 Box *splitbox = (Box *)GetWindowLongPtr(mybox, GWLP_USERDATA); | 619 Box *splitbox = (Box *)GetWindowLongPtr(mybox, GWLP_USERDATA); |
606 | 620 |
607 if(splitbox && _focus_check_box(splitbox, handle, start == 3 ? 3 : 0, defaultitem)) | 621 if(splitbox && _focus_check_box(splitbox, handle, start == 3 ? 3 : 0, defaultitem)) |
608 return 1; | 622 return 1; |
609 } | 623 } |
610 | 624 |
611 /* Try the top or left box */ | 625 /* Try the top or left box */ |
612 mybox = (HWND)dw_window_get_data(box->items[z].hwnd, "_dw_topleft"); | 626 mybox = (HWND)dw_window_get_data(box->items[z].hwnd, "_dw_topleft"); |
613 | 627 |
614 if(mybox) | 628 if(mybox) |
615 { | 629 { |
616 Box *splitbox = (Box *)GetWindowLongPtr(mybox, GWLP_USERDATA); | 630 Box *splitbox = (Box *)GetWindowLongPtr(mybox, GWLP_USERDATA); |
617 | 631 |
618 if(splitbox && _focus_check_box(splitbox, handle, start == 3 ? 3 : 0, defaultitem)) | 632 if(splitbox && _focus_check_box(splitbox, handle, start == 3 ? 3 : 0, defaultitem)) |
619 return 1; | 633 return 1; |
620 } | 634 } |
621 } | 635 } |
622 else if(strnicmp(tmpbuf, WC_TABCONTROL, strlen(WC_TABCONTROL))==0) /* Notebook */ | 636 else if(strnicmp(tmpbuf, WC_TABCONTROL, strlen(WC_TABCONTROL))==0) /* Notebook */ |
623 { | 637 { |
624 NotebookPage **array = (NotebookPage **)dw_window_get_data(box->items[z].hwnd, "_dw_array"); | 638 NotebookPage **array = (NotebookPage **)dw_window_get_data(box->items[z].hwnd, "_dw_array"); |
625 int pageid = TabCtrl_GetCurSel(box->items[z].hwnd); | 639 int pageid = TabCtrl_GetCurSel(box->items[z].hwnd); |
626 | 640 |
627 if(pageid > -1 && array && array[pageid]) | 641 if(pageid > -1 && array && array[pageid]) |
628 { | 642 { |
629 Box *notebox; | 643 Box *notebox; |
630 | 644 |
631 if(array[pageid]->hwnd) | 645 if(array[pageid]->hwnd) |
632 { | 646 { |
633 notebox = (Box *)GetWindowLongPtr(array[pageid]->hwnd, GWLP_USERDATA); | 647 notebox = (Box *)GetWindowLongPtr(array[pageid]->hwnd, GWLP_USERDATA); |
634 | 648 |
635 if(notebox && _focus_check_box(notebox, handle, start == 3 ? 3 : 0, defaultitem)) | 649 if(notebox && _focus_check_box(notebox, handle, start == 3 ? 3 : 0, defaultitem)) |
636 return 1; | 650 return 1; |
637 } | 651 } |
638 } | 652 } |
639 } | 653 } |
640 } | 654 } |
641 } | 655 } |
642 } | 656 } |
643 return 0; | 657 return 0; |
644 } | 658 } |
645 | 659 |
646 int _focus_check_box_back(Box *box, HWND handle, int start, HWND defaultitem) | 660 int _focus_check_box_back(Box *box, HWND handle, int start, HWND defaultitem) |
647 { | 661 { |
648 int z; | 662 int z; |
649 static HWND lasthwnd, firsthwnd; | 663 static HWND lasthwnd, firsthwnd; |
650 static int finish_searching; | 664 static int finish_searching; |
651 | 665 |
652 /* Start is 2 when we have cycled completely and | 666 /* Start is 2 when we have cycled completely and |
653 * need to set the focus to the last widget we found | 667 * need to set the focus to the last widget we found |
654 * that was valid. | 668 * that was valid. |
655 */ | 669 */ |
656 if(start == 2) | 670 if(start == 2) |
657 { | 671 { |
658 if(lasthwnd) | 672 if(lasthwnd) |
659 SetFocus(lasthwnd); | 673 SetFocus(lasthwnd); |
660 return 0; | 674 return 0; |
661 } | 675 } |
662 | 676 |
663 /* Start is 1 when we are entering the function | 677 /* Start is 1 when we are entering the function |
664 * for the first time, it is zero when entering | 678 * for the first time, it is zero when entering |
665 * the function recursively. | 679 * the function recursively. |
666 */ | 680 */ |
667 if(start == 1) | 681 if(start == 1) |
668 { | 682 { |
669 lasthwnd = handle; | 683 lasthwnd = handle; |
670 finish_searching = 0; | 684 finish_searching = 0; |
671 firsthwnd = 0; | 685 firsthwnd = 0; |
672 } | 686 } |
673 | 687 |
674 for(z=0;z<box->count;z++) | 688 for(z=0;z<box->count;z++) |
675 { | 689 { |
676 if(box->items[z].type == TYPEBOX) | 690 if(box->items[z].type == TYPEBOX) |
677 { | 691 { |
678 Box *thisbox = (Box *)GetWindowLongPtr(box->items[z].hwnd, GWLP_USERDATA); | 692 Box *thisbox = (Box *)GetWindowLongPtr(box->items[z].hwnd, GWLP_USERDATA); |
679 | 693 |
680 if(thisbox && _focus_check_box_back(thisbox, handle, start == 3 ? 3 : 0, defaultitem)) | 694 if(thisbox && _focus_check_box_back(thisbox, handle, start == 3 ? 3 : 0, defaultitem)) |
681 return 1; | 695 return 1; |
682 } | 696 } |
683 else | 697 else |
684 { | 698 { |
685 if(box->items[z].hwnd == handle) | 699 if(box->items[z].hwnd == handle) |
686 { | 700 { |
687 if(lasthwnd == handle && firsthwnd) | 701 if(lasthwnd == handle && firsthwnd) |
688 SetFocus(firsthwnd); | 702 SetFocus(firsthwnd); |
689 else if(lasthwnd == handle && !firsthwnd) | 703 else if(lasthwnd == handle && !firsthwnd) |
690 finish_searching = 1; | 704 finish_searching = 1; |
691 else | 705 else |
692 SetFocus(lasthwnd); | 706 SetFocus(lasthwnd); |
693 | 707 |
694 /* If we aren't looking for the last handle, | 708 /* If we aren't looking for the last handle, |
695 * return immediately. | 709 * return immediately. |
696 */ | 710 */ |
697 if(!finish_searching) | 711 if(!finish_searching) |
698 return 1; | 712 return 1; |
699 } | 713 } |
700 if(_validate_focus(box->items[z].hwnd)) | 714 if(_validate_focus(box->items[z].hwnd)) |
701 { | 715 { |
702 /* Start is 3 when we are looking for the | 716 /* Start is 3 when we are looking for the |
703 * first valid item in the layout. | 717 * first valid item in the layout. |
704 */ | 718 */ |
705 if(start == 3) | 719 if(start == 3) |
706 { | 720 { |
707 if(!defaultitem || (defaultitem && box->items[z].hwnd == defaultitem)) | 721 if(!defaultitem || (defaultitem && box->items[z].hwnd == defaultitem)) |
708 { | 722 { |
709 SetFocus(_normalize_handle(box->items[z].hwnd)); | 723 SetFocus(_normalize_handle(box->items[z].hwnd)); |
710 return 1; | 724 return 1; |
711 } | 725 } |
712 } | 726 } |
713 | 727 |
714 if(!firsthwnd) | 728 if(!firsthwnd) |
715 firsthwnd = _normalize_handle(box->items[z].hwnd); | 729 firsthwnd = _normalize_handle(box->items[z].hwnd); |
716 | 730 |
717 lasthwnd = _normalize_handle(box->items[z].hwnd); | 731 lasthwnd = _normalize_handle(box->items[z].hwnd); |
718 } | 732 } |
719 else | 733 else |
720 { | 734 { |
721 char tmpbuf[100] = ""; | 735 char tmpbuf[100] = ""; |
722 | 736 |
723 GetClassName(box->items[z].hwnd, tmpbuf, 99); | 737 GetClassName(box->items[z].hwnd, tmpbuf, 99); |
724 | 738 |
725 if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0) | 739 if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0) |
726 { | 740 { |
727 /* Try the top or left box */ | 741 /* Try the top or left box */ |
728 HWND mybox = (HWND)dw_window_get_data(box->items[z].hwnd, "_dw_topleft"); | 742 HWND mybox = (HWND)dw_window_get_data(box->items[z].hwnd, "_dw_topleft"); |
729 | 743 |
730 if(mybox) | 744 if(mybox) |
731 { | 745 { |
732 Box *splitbox = (Box *)GetWindowLongPtr(mybox, GWLP_USERDATA); | 746 Box *splitbox = (Box *)GetWindowLongPtr(mybox, GWLP_USERDATA); |
733 | 747 |
734 if(splitbox && _focus_check_box_back(splitbox, handle, start == 3 ? 3 : 0, defaultitem)) | 748 if(splitbox && _focus_check_box_back(splitbox, handle, start == 3 ? 3 : 0, defaultitem)) |
735 return 1; | 749 return 1; |
736 } | 750 } |
737 | 751 |
738 /* Then try the bottom or right box */ | 752 /* Then try the bottom or right box */ |
739 mybox = (HWND)dw_window_get_data(box->items[z].hwnd, "_dw_bottomright"); | 753 mybox = (HWND)dw_window_get_data(box->items[z].hwnd, "_dw_bottomright"); |
740 | 754 |
741 if(mybox) | 755 if(mybox) |
742 { | 756 { |
743 Box *splitbox = (Box *)GetWindowLongPtr(mybox, GWLP_USERDATA); | 757 Box *splitbox = (Box *)GetWindowLongPtr(mybox, GWLP_USERDATA); |
744 | 758 |
745 if(splitbox && _focus_check_box_back(splitbox, handle, start == 3 ? 3 : 0, defaultitem)) | 759 if(splitbox && _focus_check_box_back(splitbox, handle, start == 3 ? 3 : 0, defaultitem)) |
746 return 1; | 760 return 1; |
747 } | 761 } |
748 } | 762 } |
749 else if(strnicmp(tmpbuf, WC_TABCONTROL, strlen(WC_TABCONTROL))==0) /* Notebook */ | 763 else if(strnicmp(tmpbuf, WC_TABCONTROL, strlen(WC_TABCONTROL))==0) /* Notebook */ |
750 { | 764 { |
751 NotebookPage **array = (NotebookPage **)dw_window_get_data(box->items[z].hwnd, "_dw_array"); | 765 NotebookPage **array = (NotebookPage **)dw_window_get_data(box->items[z].hwnd, "_dw_array"); |
752 int pageid = TabCtrl_GetCurSel(box->items[z].hwnd); | 766 int pageid = TabCtrl_GetCurSel(box->items[z].hwnd); |
753 | 767 |
754 if(pageid > -1 && array && array[pageid]) | 768 if(pageid > -1 && array && array[pageid]) |
755 { | 769 { |
756 Box *notebox; | 770 Box *notebox; |
757 | 771 |
758 if(array[pageid]->hwnd) | 772 if(array[pageid]->hwnd) |
759 { | 773 { |
760 notebox = (Box *)GetWindowLongPtr(array[pageid]->hwnd, GWLP_USERDATA); | 774 notebox = (Box *)GetWindowLongPtr(array[pageid]->hwnd, GWLP_USERDATA); |
761 | 775 |
762 if(notebox && _focus_check_box_back(notebox, handle, start == 3 ? 3 : 0, defaultitem)) | 776 if(notebox && _focus_check_box_back(notebox, handle, start == 3 ? 3 : 0, defaultitem)) |
763 return 1; | 777 return 1; |
764 } | 778 } |
765 } | 779 } |
766 } | 780 } |
767 } | 781 } |
768 } | 782 } |
769 } | 783 } |
770 return 0; | 784 return 0; |
771 } | 785 } |
772 | 786 |
773 /* This function finds the first widget in the | 787 /* This function finds the first widget in the |
774 * layout and moves the current focus to it. | 788 * layout and moves the current focus to it. |
775 */ | 789 */ |
776 void _initial_focus(HWND handle) | 790 void _initial_focus(HWND handle) |
777 { | 791 { |
778 Box *thisbox; | 792 Box *thisbox; |
779 char tmpbuf[100]; | 793 char tmpbuf[100]; |
780 | 794 |
781 if(!handle) | 795 if(!handle) |
782 return; | 796 return; |
783 | 797 |
784 GetClassName(handle, tmpbuf, 99); | 798 GetClassName(handle, tmpbuf, 99); |
785 | 799 |
786 if(strnicmp(tmpbuf, ClassName, strlen(ClassName))!=0) | 800 if(strnicmp(tmpbuf, ClassName, strlen(ClassName))!=0) |
787 return; | 801 return; |
788 | 802 |
789 | 803 |
790 if(handle) | 804 if(handle) |
791 thisbox = (Box *)GetWindowLongPtr(handle, GWLP_USERDATA); | 805 thisbox = (Box *)GetWindowLongPtr(handle, GWLP_USERDATA); |
792 | 806 |
793 if(thisbox) | 807 if(thisbox) |
794 { | 808 { |
795 _focus_check_box(thisbox, handle, 3, thisbox->defaultitem); | 809 _focus_check_box(thisbox, handle, 3, thisbox->defaultitem); |
796 } | 810 } |
797 } | 811 } |
798 | 812 |
799 HWND _toplevel_window(HWND handle) | 813 HWND _toplevel_window(HWND handle) |
800 { | 814 { |
801 HWND box, lastbox = GetParent(handle); | 815 HWND box, lastbox = GetParent(handle); |
802 | 816 |
803 /* Find the toplevel window */ | 817 /* Find the toplevel window */ |
804 while((box = GetParent(lastbox))) | 818 while((box = GetParent(lastbox))) |
805 { | 819 { |
806 lastbox = box; | 820 lastbox = box; |
807 } | 821 } |
808 if(lastbox) | 822 if(lastbox) |
809 return lastbox; | 823 return lastbox; |
810 return handle; | 824 return handle; |
811 } | 825 } |
812 | 826 |
813 /* This function finds the current widget in the | 827 /* This function finds the current widget in the |
814 * layout and moves the current focus to the next item. | 828 * layout and moves the current focus to the next item. |
815 */ | 829 */ |
816 void _shift_focus(HWND handle) | 830 void _shift_focus(HWND handle) |
817 { | 831 { |
818 Box *thisbox; | 832 Box *thisbox; |
819 | 833 |
820 HWND box, lastbox = GetParent(handle); | 834 HWND box, lastbox = GetParent(handle); |
821 | 835 |
822 /* Find the toplevel window */ | 836 /* Find the toplevel window */ |
823 while((box = GetParent(lastbox))) | 837 while((box = GetParent(lastbox))) |
824 { | 838 { |
825 lastbox = box; | 839 lastbox = box; |
826 } | 840 } |
827 | 841 |
828 thisbox = (Box *)GetWindowLongPtr(lastbox, GWLP_USERDATA); | 842 thisbox = (Box *)GetWindowLongPtr(lastbox, GWLP_USERDATA); |
829 if(thisbox) | 843 if(thisbox) |
830 { | 844 { |
831 if(_focus_check_box(thisbox, handle, 1, 0) == 0) | 845 if(_focus_check_box(thisbox, handle, 1, 0) == 0) |
832 _focus_check_box(thisbox, handle, 2, 0); | 846 _focus_check_box(thisbox, handle, 2, 0); |
833 } | 847 } |
834 } | 848 } |
835 | 849 |
836 /* This function finds the current widget in the | 850 /* This function finds the current widget in the |
837 * layout and moves the current focus to the next item. | 851 * layout and moves the current focus to the next item. |
838 */ | 852 */ |
839 void _shift_focus_back(HWND handle) | 853 void _shift_focus_back(HWND handle) |
840 { | 854 { |
841 Box *thisbox; | 855 Box *thisbox; |
842 | 856 |
843 HWND box, lastbox = GetParent(handle); | 857 HWND box, lastbox = GetParent(handle); |
844 | 858 |
845 /* Find the toplevel window */ | 859 /* Find the toplevel window */ |
846 while((box = GetParent(lastbox))) | 860 while((box = GetParent(lastbox))) |
847 { | 861 { |
848 lastbox = box; | 862 lastbox = box; |
849 } | 863 } |
850 | 864 |
851 thisbox = (Box *)GetWindowLongPtr(lastbox, GWLP_USERDATA); | 865 thisbox = (Box *)GetWindowLongPtr(lastbox, GWLP_USERDATA); |
852 if(thisbox) | 866 if(thisbox) |
853 { | 867 { |
854 if(_focus_check_box_back(thisbox, handle, 1, 0) == 0) | 868 if(_focus_check_box_back(thisbox, handle, 1, 0) == 0) |
855 _focus_check_box_back(thisbox, handle, 2, 0); | 869 _focus_check_box_back(thisbox, handle, 2, 0); |
856 } | 870 } |
857 } | 871 } |
858 | 872 |
859 /* ResetWindow: | 873 /* ResetWindow: |
860 * Resizes window to the exact same size to trigger | 874 * Resizes window to the exact same size to trigger |
861 * recalculation of frame. | 875 * recalculation of frame. |
862 */ | 876 */ |
863 void _ResetWindow(HWND hwndFrame) | 877 void _ResetWindow(HWND hwndFrame) |
864 { | 878 { |
865 RECT rcl; | 879 RECT rcl; |
866 | 880 |
867 GetWindowRect(hwndFrame, &rcl); | 881 GetWindowRect(hwndFrame, &rcl); |
868 SetWindowPos(hwndFrame, HWND_TOP, 0, 0, rcl.right - rcl.left, | 882 SetWindowPos(hwndFrame, HWND_TOP, 0, 0, rcl.right - rcl.left, |
869 rcl.bottom - rcl.top - 1, SWP_NOMOVE | SWP_NOZORDER); | 883 rcl.bottom - rcl.top - 1, SWP_NOMOVE | SWP_NOZORDER); |
870 SetWindowPos(hwndFrame, HWND_TOP, 0, 0, rcl.right - rcl.left, | 884 SetWindowPos(hwndFrame, HWND_TOP, 0, 0, rcl.right - rcl.left, |
871 rcl.bottom - rcl.top, SWP_NOMOVE | SWP_NOZORDER); | 885 rcl.bottom - rcl.top, SWP_NOMOVE | SWP_NOZORDER); |
872 } | 886 } |
873 | 887 |
874 /* This function calculates how much space the widgets and boxes require | 888 /* This function calculates how much space the widgets and boxes require |
875 * and does expansion as necessary. | 889 * and does expansion as necessary. |
876 */ | 890 */ |
877 int _resize_box(Box *thisbox, int *depth, int x, int y, int *usedx, int *usedy, | 891 int _resize_box(Box *thisbox, int *depth, int x, int y, int *usedx, int *usedy, |
878 int pass, int *usedpadx, int *usedpady) | 892 int pass, int *usedpadx, int *usedpady) |
879 { | 893 { |
880 int z, currentx = 0, currenty = 0; | 894 int z, currentx = 0, currenty = 0; |
881 int uymax = 0, uxmax = 0; | 895 int uymax = 0, uxmax = 0; |
882 int upymax = 0, upxmax = 0; | 896 int upymax = 0, upxmax = 0; |
883 /* Used for the SIZEEXPAND */ | 897 /* Used for the SIZEEXPAND */ |
884 int nux = *usedx, nuy = *usedy; | 898 int nux = *usedx, nuy = *usedy; |
885 int nupx = *usedpadx, nupy = *usedpady; | 899 int nupx = *usedpadx, nupy = *usedpady; |
886 | 900 |
887 (*usedx) += (thisbox->pad * 2); | 901 (*usedx) += (thisbox->pad * 2); |
888 (*usedy) += (thisbox->pad * 2); | 902 (*usedy) += (thisbox->pad * 2); |
889 | 903 |
890 if(thisbox->grouphwnd) | 904 if(thisbox->grouphwnd) |
891 { | 905 { |
892 char *text = dw_window_get_text(thisbox->grouphwnd); | 906 char *text = dw_window_get_text(thisbox->grouphwnd); |
893 | 907 |
894 thisbox->grouppady = 0; | 908 thisbox->grouppady = 0; |
895 | 909 |
896 if(text) | 910 if(text) |
897 { | 911 { |
898 dw_font_text_extents_get(thisbox->grouphwnd, 0, text, NULL, &thisbox->grouppady); | 912 dw_font_text_extents_get(thisbox->grouphwnd, 0, text, NULL, &thisbox->grouppady); |
899 dw_free(text); | 913 dw_free(text); |
900 } | 914 } |
901 | 915 |
902 if(thisbox->grouppady) | 916 if(thisbox->grouppady) |
903 thisbox->grouppady += 3; | 917 thisbox->grouppady += 3; |
904 else | 918 else |
905 thisbox->grouppady = 6; | 919 thisbox->grouppady = 6; |
906 | 920 |
907 thisbox->grouppadx = 6; | 921 thisbox->grouppadx = 6; |
908 | 922 |
909 (*usedx) += thisbox->grouppadx; | 923 (*usedx) += thisbox->grouppadx; |
910 (*usedpadx) += thisbox->grouppadx; | 924 (*usedpadx) += thisbox->grouppadx; |
911 (*usedy) += thisbox->grouppady; | 925 (*usedy) += thisbox->grouppady; |
912 (*usedpady) += thisbox->grouppady; | 926 (*usedpady) += thisbox->grouppady; |
913 } | 927 } |
914 | 928 |
915 for(z=0;z<thisbox->count;z++) | 929 for(z=0;z<thisbox->count;z++) |
916 { | 930 { |
917 if(thisbox->items[z].type == TYPEBOX) | 931 if(thisbox->items[z].type == TYPEBOX) |
918 { | 932 { |
919 int initialx, initialy; | 933 int initialx, initialy; |
920 Box *tmp = (Box *)GetWindowLongPtr(thisbox->items[z].hwnd, GWLP_USERDATA); | 934 Box *tmp = (Box *)GetWindowLongPtr(thisbox->items[z].hwnd, GWLP_USERDATA); |
921 | 935 |
922 initialx = x - (*usedx); | 936 initialx = x - (*usedx); |
923 initialy = y - (*usedy); | 937 initialy = y - (*usedy); |
924 | 938 |
925 if(tmp) | 939 if(tmp) |
926 { | 940 { |
927 int newx, newy; | 941 int newx, newy; |
928 int nux = *usedx, nuy = *usedy; | 942 int nux = *usedx, nuy = *usedy; |
929 int upx = *usedpadx + (tmp->pad*2), upy = *usedpady + (tmp->pad*2); | 943 int upx = *usedpadx + (tmp->pad*2), upy = *usedpady + (tmp->pad*2); |
930 | 944 |
931 /* On the second pass we know how big the box needs to be and how | 945 /* On the second pass we know how big the box needs to be and how |
932 * much space we have, so we can calculate a ratio for the new box. | 946 * much space we have, so we can calculate a ratio for the new box. |
933 */ | 947 */ |
934 if(pass == 2) | 948 if(pass == 2) |
935 { | 949 { |
936 int deep = *depth + 1; | 950 int deep = *depth + 1; |
937 | 951 |
938 _resize_box(tmp, &deep, x, y, &nux, &nuy, 1, &upx, &upy); | 952 _resize_box(tmp, &deep, x, y, &nux, &nuy, 1, &upx, &upy); |
939 | 953 |
940 tmp->upx = upx - *usedpadx; | 954 tmp->upx = upx - *usedpadx; |
941 tmp->upy = upy - *usedpady; | 955 tmp->upy = upy - *usedpady; |
942 | 956 |
943 newx = x - nux; | 957 newx = x - nux; |
944 newy = y - nuy; | 958 newy = y - nuy; |
945 | 959 |
946 tmp->width = thisbox->items[z].width = initialx - newx; | 960 tmp->width = thisbox->items[z].width = initialx - newx; |
947 tmp->height = thisbox->items[z].height = initialy - newy; | 961 tmp->height = thisbox->items[z].height = initialy - newy; |
948 | 962 |
949 tmp->parentxratio = thisbox->xratio; | 963 tmp->parentxratio = thisbox->xratio; |
950 tmp->parentyratio = thisbox->yratio; | 964 tmp->parentyratio = thisbox->yratio; |
951 | 965 |
952 tmp->parentpad = tmp->pad; | 966 tmp->parentpad = tmp->pad; |
953 | 967 |
954 /* Just in case */ | 968 /* Just in case */ |
955 tmp->xratio = thisbox->xratio; | 969 tmp->xratio = thisbox->xratio; |
956 tmp->yratio = thisbox->yratio; | 970 tmp->yratio = thisbox->yratio; |
957 | 971 |
958 if(thisbox->type == DW_VERT) | 972 if(thisbox->type == DW_VERT) |
959 { | 973 { |
960 int tmppad = (thisbox->items[z].pad*2)+(tmp->pad*2)+tmp->grouppady; | 974 int tmppad = (thisbox->items[z].pad*2)+(tmp->pad*2)+tmp->grouppady; |
961 | 975 |
962 if((thisbox->items[z].width - tmppad)!=0) | 976 if((thisbox->items[z].width - tmppad)!=0) |
963 tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-tmppad))/((float)(thisbox->items[z].width-tmppad)); | 977 tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-tmppad))/((float)(thisbox->items[z].width-tmppad)); |
964 } | 978 } |
965 else | 979 else |
966 { | 980 { |
967 if((thisbox->items[z].width-tmp->upx)!=0) | 981 if((thisbox->items[z].width-tmp->upx)!=0) |
968 tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-tmp->upx))/((float)(thisbox->items[z].width-tmp->upx)); | 982 tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-tmp->upx))/((float)(thisbox->items[z].width-tmp->upx)); |
969 } | 983 } |
970 if(thisbox->type == DW_HORZ) | 984 if(thisbox->type == DW_HORZ) |
971 { | 985 { |
972 int tmppad = (thisbox->items[z].pad*2)+(tmp->pad*2)+tmp->grouppadx; | 986 int tmppad = (thisbox->items[z].pad*2)+(tmp->pad*2)+tmp->grouppadx; |
973 | 987 |
974 if((thisbox->items[z].height-tmppad)!=0) | 988 if((thisbox->items[z].height-tmppad)!=0) |
975 tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-tmppad))/((float)(thisbox->items[z].height-tmppad)); | 989 tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-tmppad))/((float)(thisbox->items[z].height-tmppad)); |
976 } | 990 } |
977 else | 991 else |
978 { | 992 { |
979 if((thisbox->items[z].height-tmp->upy)!=0) | 993 if((thisbox->items[z].height-tmp->upy)!=0) |
980 tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-tmp->upy))/((float)(thisbox->items[z].height-tmp->upy)); | 994 tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-tmp->upy))/((float)(thisbox->items[z].height-tmp->upy)); |
981 } | 995 } |
982 | 996 |
983 nux = *usedx; nuy = *usedy; | 997 nux = *usedx; nuy = *usedy; |
984 upx = *usedpadx + (tmp->pad*2); upy = *usedpady + (tmp->pad*2); | 998 upx = *usedpadx + (tmp->pad*2); upy = *usedpady + (tmp->pad*2); |
985 } | 999 } |
986 | 1000 |
987 (*depth)++; | 1001 (*depth)++; |
988 | 1002 |
989 _resize_box(tmp, depth, x, y, &nux, &nuy, pass, &upx, &upy); | 1003 _resize_box(tmp, depth, x, y, &nux, &nuy, pass, &upx, &upy); |
990 | 1004 |
991 (*depth)--; | 1005 (*depth)--; |
992 | 1006 |
993 newx = x - nux; | 1007 newx = x - nux; |
994 newy = y - nuy; | 1008 newy = y - nuy; |
995 | 1009 |
996 tmp->minwidth = thisbox->items[z].width = initialx - newx; | 1010 tmp->minwidth = thisbox->items[z].width = initialx - newx; |
997 tmp->minheight = thisbox->items[z].height = initialy - newy; | 1011 tmp->minheight = thisbox->items[z].height = initialy - newy; |
998 } | 1012 } |
999 } | 1013 } |
1000 | 1014 |
1001 if(pass > 1 && *depth > 0) | 1015 if(pass > 1 && *depth > 0) |
1002 { | 1016 { |
1003 if(thisbox->type == DW_VERT) | 1017 if(thisbox->type == DW_VERT) |
1004 { | 1018 { |
1005 int tmppad = (thisbox->items[z].pad*2)+(thisbox->parentpad*2)+thisbox->grouppadx; | 1019 int tmppad = (thisbox->items[z].pad*2)+(thisbox->parentpad*2)+thisbox->grouppadx; |
1006 | 1020 |
1007 if((thisbox->minwidth-tmppad) == 0) | 1021 if((thisbox->minwidth-tmppad) == 0) |
1008 thisbox->items[z].xratio = 1.0; | 1022 thisbox->items[z].xratio = 1.0; |
1009 else | 1023 else |
1010 thisbox->items[z].xratio = ((float)((thisbox->width * thisbox->parentxratio)-tmppad))/((float)(thisbox->minwidth-tmppad)); | 1024 thisbox->items[z].xratio = ((float)((thisbox->width * thisbox->parentxratio)-tmppad))/((float)(thisbox->minwidth-tmppad)); |
1011 } | 1025 } |
1012 else | 1026 else |
1013 { | 1027 { |
1014 if(thisbox->minwidth-thisbox->upx == 0) | 1028 if(thisbox->minwidth-thisbox->upx == 0) |
1015 thisbox->items[z].xratio = 1.0; | 1029 thisbox->items[z].xratio = 1.0; |
1016 else | 1030 else |
1017 thisbox->items[z].xratio = ((float)((thisbox->width * thisbox->parentxratio)-thisbox->upx))/((float)(thisbox->minwidth-thisbox->upx)); | 1031 thisbox->items[z].xratio = ((float)((thisbox->width * thisbox->parentxratio)-thisbox->upx))/((float)(thisbox->minwidth-thisbox->upx)); |
1018 } | 1032 } |
1019 | 1033 |
1020 if(thisbox->type == DW_HORZ) | 1034 if(thisbox->type == DW_HORZ) |
1021 { | 1035 { |
1022 int tmppad = (thisbox->items[z].pad*2)+(thisbox->parentpad*2)+thisbox->grouppady; | 1036 int tmppad = (thisbox->items[z].pad*2)+(thisbox->parentpad*2)+thisbox->grouppady; |
1023 | 1037 |
1024 if((thisbox->minheight-tmppad) == 0) | 1038 if((thisbox->minheight-tmppad) == 0) |
1025 thisbox->items[z].yratio = 1.0; | 1039 thisbox->items[z].yratio = 1.0; |
1026 else | 1040 else |
1027 thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-tmppad))/((float)(thisbox->minheight-tmppad)); | 1041 thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-tmppad))/((float)(thisbox->minheight-tmppad)); |
1028 } | 1042 } |
1029 else | 1043 else |
1030 { | 1044 { |
1031 if(thisbox->minheight-thisbox->upy == 0) | 1045 if(thisbox->minheight-thisbox->upy == 0) |
1032 thisbox->items[z].yratio = 1.0; | 1046 thisbox->items[z].yratio = 1.0; |
1033 else | 1047 else |
1034 thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-thisbox->upy))/((float)(thisbox->minheight-thisbox->upy)); | 1048 thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-thisbox->upy))/((float)(thisbox->minheight-thisbox->upy)); |
1035 } | 1049 } |
1036 | 1050 |
1037 if(thisbox->items[z].type == TYPEBOX) | 1051 if(thisbox->items[z].type == TYPEBOX) |
1038 { | 1052 { |
1039 Box *tmp = (Box *)GetWindowLongPtr(thisbox->items[z].hwnd, GWLP_USERDATA); | 1053 Box *tmp = (Box *)GetWindowLongPtr(thisbox->items[z].hwnd, GWLP_USERDATA); |
1040 | 1054 |
1041 if(tmp) | 1055 if(tmp) |
1042 { | 1056 { |
1043 tmp->parentxratio = thisbox->items[z].xratio; | 1057 tmp->parentxratio = thisbox->items[z].xratio; |
1044 tmp->parentyratio = thisbox->items[z].yratio; | 1058 tmp->parentyratio = thisbox->items[z].yratio; |
1045 } | 1059 } |
1046 } | 1060 } |
1047 } | 1061 } |
1048 else | 1062 else |
1049 { | 1063 { |
1050 thisbox->items[z].xratio = thisbox->xratio; | 1064 thisbox->items[z].xratio = thisbox->xratio; |
1051 thisbox->items[z].yratio = thisbox->yratio; | 1065 thisbox->items[z].yratio = thisbox->yratio; |
1052 } | 1066 } |
1053 | 1067 |
1054 if(thisbox->type == DW_VERT) | 1068 if(thisbox->type == DW_VERT) |
1055 { | 1069 { |
1056 int itemwidth = (thisbox->items[z].pad*2) + thisbox->items[z].width; | 1070 int itemwidth = (thisbox->items[z].pad*2) + thisbox->items[z].width; |
1057 | 1071 |
1058 if(itemwidth > uxmax) | 1072 if(itemwidth > uxmax) |
1059 uxmax = itemwidth; | 1073 uxmax = itemwidth; |
1060 if(thisbox->items[z].hsize != SIZEEXPAND) | 1074 if(thisbox->items[z].hsize != SIZEEXPAND) |
1061 { | 1075 { |
1062 if(itemwidth > upxmax) | 1076 if(itemwidth > upxmax) |
1063 upxmax = itemwidth; | 1077 upxmax = itemwidth; |
1064 } | 1078 } |
1065 else | 1079 else |
1066 { | 1080 { |
1067 if(thisbox->items[z].pad*2 > upxmax) | 1081 if(thisbox->items[z].pad*2 > upxmax) |
1068 upxmax = thisbox->items[z].pad*2; | 1082 upxmax = thisbox->items[z].pad*2; |
1069 } | 1083 } |
1070 } | 1084 } |
1071 else | 1085 else |
1072 { | 1086 { |
1073 if(thisbox->items[z].width == -1) | 1087 if(thisbox->items[z].width == -1) |
1074 { | 1088 { |
1075 /* figure out how much space this item requires */ | 1089 /* figure out how much space this item requires */ |
1076 /* thisbox->items[z].width = */ | 1090 /* thisbox->items[z].width = */ |
1077 } | 1091 } |
1078 else | 1092 else |
1079 { | 1093 { |
1080 (*usedx) += thisbox->items[z].width + (thisbox->items[z].pad*2); | 1094 (*usedx) += thisbox->items[z].width + (thisbox->items[z].pad*2); |
1081 if(thisbox->items[z].hsize != SIZEEXPAND) | 1095 if(thisbox->items[z].hsize != SIZEEXPAND) |
1082 (*usedpadx) += (thisbox->items[z].pad*2) + thisbox->items[z].width; | 1096 (*usedpadx) += (thisbox->items[z].pad*2) + thisbox->items[z].width; |
1083 else | 1097 else |
1084 (*usedpadx) += thisbox->items[z].pad*2; | 1098 (*usedpadx) += thisbox->items[z].pad*2; |
1085 } | 1099 } |
1086 } | 1100 } |
1087 if(thisbox->type == DW_HORZ) | 1101 if(thisbox->type == DW_HORZ) |
1088 { | 1102 { |
1089 int itemheight = (thisbox->items[z].pad*2) + thisbox->items[z].height; | 1103 int itemheight = (thisbox->items[z].pad*2) + thisbox->items[z].height; |
1090 | 1104 |
1091 if(itemheight > uymax) | 1105 if(itemheight > uymax) |
1092 uymax = itemheight; | 1106 uymax = itemheight; |
1093 if(thisbox->items[z].vsize != SIZEEXPAND) | 1107 if(thisbox->items[z].vsize != SIZEEXPAND) |
1094 { | 1108 { |
1095 if(itemheight > upymax) | 1109 if(itemheight > upymax) |
1096 upymax = itemheight; | 1110 upymax = itemheight; |
1097 } | 1111 } |
1098 else | 1112 else |
1099 { | 1113 { |
1100 if(thisbox->items[z].pad*2 > upymax) | 1114 if(thisbox->items[z].pad*2 > upymax) |
1101 upymax = thisbox->items[z].pad*2; | 1115 upymax = thisbox->items[z].pad*2; |
1102 } | 1116 } |
1103 } | 1117 } |
1104 else | 1118 else |
1105 { | 1119 { |
1106 if(thisbox->items[z].height == -1) | 1120 if(thisbox->items[z].height == -1) |
1107 { | 1121 { |
1108 /* figure out how much space this item requires */ | 1122 /* figure out how much space this item requires */ |
1109 /* thisbox->items[z].height = */ | 1123 /* thisbox->items[z].height = */ |
1110 } | 1124 } |
1111 else | 1125 else |
1112 { | 1126 { |
1113 (*usedy) += thisbox->items[z].height + (thisbox->items[z].pad*2); | 1127 (*usedy) += thisbox->items[z].height + (thisbox->items[z].pad*2); |
1114 if(thisbox->items[z].vsize != SIZEEXPAND) | 1128 if(thisbox->items[z].vsize != SIZEEXPAND) |
1115 (*usedpady) += (thisbox->items[z].pad*2) + thisbox->items[z].height; | 1129 (*usedpady) += (thisbox->items[z].pad*2) + thisbox->items[z].height; |
1116 else | 1130 else |
1117 (*usedpady) += thisbox->items[z].pad*2; | 1131 (*usedpady) += thisbox->items[z].pad*2; |
1118 } | 1132 } |
1119 } | 1133 } |
1120 } | 1134 } |
1121 | 1135 |
1122 (*usedx) += uxmax; | 1136 (*usedx) += uxmax; |
1123 (*usedy) += uymax; | 1137 (*usedy) += uymax; |
1124 (*usedpadx) += upxmax; | 1138 (*usedpadx) += upxmax; |
1125 (*usedpady) += upymax; | 1139 (*usedpady) += upymax; |
1126 | 1140 |
1127 currentx += thisbox->pad; | 1141 currentx += thisbox->pad; |
1128 currenty += thisbox->pad; | 1142 currenty += thisbox->pad; |
1129 | 1143 |
1130 if(thisbox->grouphwnd) | 1144 if(thisbox->grouphwnd) |
1131 { | 1145 { |
1132 currentx += 3; | 1146 currentx += 3; |
1133 currenty += thisbox->grouppady - 3; | 1147 currenty += thisbox->grouppady - 3; |
1134 } | 1148 } |
1135 | 1149 |
1136 /* The second pass is for expansion and actual placement. */ | 1150 /* The second pass is for expansion and actual placement. */ |
1137 if(pass > 1) | 1151 if(pass > 1) |
1138 { | 1152 { |
1139 /* Any SIZEEXPAND items should be set to uxmax/uymax */ | 1153 /* Any SIZEEXPAND items should be set to uxmax/uymax */ |
1140 for(z=0;z<thisbox->count;z++) | 1154 for(z=0;z<thisbox->count;z++) |
1141 { | 1155 { |
1142 if(thisbox->items[z].hsize == SIZEEXPAND && thisbox->type == DW_VERT) | 1156 if(thisbox->items[z].hsize == SIZEEXPAND && thisbox->type == DW_VERT) |
1143 thisbox->items[z].width = uxmax-(thisbox->items[z].pad*2); | 1157 thisbox->items[z].width = uxmax-(thisbox->items[z].pad*2); |
1144 if(thisbox->items[z].vsize == SIZEEXPAND && thisbox->type == DW_HORZ) | 1158 if(thisbox->items[z].vsize == SIZEEXPAND && thisbox->type == DW_HORZ) |
1145 thisbox->items[z].height = uymax-(thisbox->items[z].pad*2); | 1159 thisbox->items[z].height = uymax-(thisbox->items[z].pad*2); |
1146 /* Run this code segment again to finalize the sized after setting uxmax/uymax values. */ | 1160 /* Run this code segment again to finalize the sized after setting uxmax/uymax values. */ |
1147 if(thisbox->items[z].type == TYPEBOX) | 1161 if(thisbox->items[z].type == TYPEBOX) |
1148 { | 1162 { |
1149 Box *tmp = (Box *)GetWindowLongPtr(thisbox->items[z].hwnd, GWLP_USERDATA); | 1163 Box *tmp = (Box *)GetWindowLongPtr(thisbox->items[z].hwnd, GWLP_USERDATA); |
1150 | 1164 |
1151 if(tmp) | 1165 if(tmp) |
1152 { | 1166 { |
1153 if(*depth > 0) | 1167 if(*depth > 0) |
1154 { | 1168 { |
1155 float calcval; | 1169 float calcval; |
1156 | 1170 |
1157 if(thisbox->type == DW_VERT) | 1171 if(thisbox->type == DW_VERT) |
1158 { | 1172 { |
1159 calcval = (float)(tmp->minwidth-((thisbox->items[z].pad*2)+(thisbox->pad*2))); | 1173 calcval = (float)(tmp->minwidth-((thisbox->items[z].pad*2)+(thisbox->pad*2))); |
1160 if(calcval == 0.0) | 1174 if(calcval == 0.0) |
1161 tmp->xratio = thisbox->xratio; | 1175 tmp->xratio = thisbox->xratio; |
1162 else | 1176 else |
1163 tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-((thisbox->items[z].pad*2)+(thisbox->pad*2))))/calcval; | 1177 tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-((thisbox->items[z].pad*2)+(thisbox->pad*2))))/calcval; |
1164 tmp->width = thisbox->items[z].width; | 1178 tmp->width = thisbox->items[z].width; |
1165 } | 1179 } |
1166 if(thisbox->type == DW_HORZ) | 1180 if(thisbox->type == DW_HORZ) |
1167 { | 1181 { |
1168 calcval = (float)(tmp->minheight-((thisbox->items[z].pad*2)+(thisbox->pad*2))); | 1182 calcval = (float)(tmp->minheight-((thisbox->items[z].pad*2)+(thisbox->pad*2))); |
1169 if(calcval == 0.0) | 1183 if(calcval == 0.0) |
1170 tmp->yratio = thisbox->yratio; | 1184 tmp->yratio = thisbox->yratio; |
1171 else | 1185 else |
1172 tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-((thisbox->items[z].pad*2)+(thisbox->pad*2))))/calcval; | 1186 tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-((thisbox->items[z].pad*2)+(thisbox->pad*2))))/calcval; |
1173 tmp->height = thisbox->items[z].height; | 1187 tmp->height = thisbox->items[z].height; |
1174 } | 1188 } |
1175 } | 1189 } |
1176 | 1190 |
1177 (*depth)++; | 1191 (*depth)++; |
1178 | 1192 |
1179 _resize_box(tmp, depth, x, y, &nux, &nuy, 3, &nupx, &nupy); | 1193 _resize_box(tmp, depth, x, y, &nux, &nuy, 3, &nupx, &nupy); |
1180 | 1194 |
1181 (*depth)--; | 1195 (*depth)--; |
1182 | 1196 |
1183 } | 1197 } |
1184 } | 1198 } |
1185 } | 1199 } |
1186 | 1200 |
1187 for(z=0;z<(thisbox->count);z++) | 1201 for(z=0;z<(thisbox->count);z++) |
1188 { | 1202 { |
1189 int height = thisbox->items[z].height; | 1203 int height = thisbox->items[z].height; |
1190 int width = thisbox->items[z].width; | 1204 int width = thisbox->items[z].width; |
1191 int pad = thisbox->items[z].pad; | 1205 int pad = thisbox->items[z].pad; |
1192 HWND handle = thisbox->items[z].hwnd; | 1206 HWND handle = thisbox->items[z].hwnd; |
1193 int vectorx, vectory; | 1207 int vectorx, vectory; |
1194 | 1208 |
1195 /* When upxmax != pad*2 then ratios are incorrect. */ | 1209 /* When upxmax != pad*2 then ratios are incorrect. */ |
1196 vectorx = (int)((width*thisbox->items[z].xratio)-width); | 1210 vectorx = (int)((width*thisbox->items[z].xratio)-width); |
1197 vectory = (int)((height*thisbox->items[z].yratio)-height); | 1211 vectory = (int)((height*thisbox->items[z].yratio)-height); |
1198 | 1212 |
1199 if(width > 0 && height > 0) | 1213 if(width > 0 && height > 0) |
1200 { | 1214 { |
1201 char tmpbuf[100]; | 1215 char tmpbuf[100]; |
1202 /* This is a hack to fix rounding of the sizing */ | 1216 /* This is a hack to fix rounding of the sizing */ |
1203 if(*depth == 0) | 1217 if(*depth == 0) |
1204 { | 1218 { |
1205 vectorx++; | 1219 vectorx++; |
1206 vectory++; | 1220 vectory++; |
1207 } | 1221 } |
1208 | 1222 |
1209 /* If this item isn't going to expand... reset the vectors to 0 */ | 1223 /* If this item isn't going to expand... reset the vectors to 0 */ |
1210 if(thisbox->items[z].vsize != SIZEEXPAND) | 1224 if(thisbox->items[z].vsize != SIZEEXPAND) |
1211 vectory = 0; | 1225 vectory = 0; |
1212 if(thisbox->items[z].hsize != SIZEEXPAND) | 1226 if(thisbox->items[z].hsize != SIZEEXPAND) |
1213 vectorx = 0; | 1227 vectorx = 0; |
1214 | 1228 |
1215 GetClassName(handle, tmpbuf, 99); | 1229 GetClassName(handle, tmpbuf, 99); |
1216 | 1230 |
1217 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) | 1231 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) |
1218 { | 1232 { |
1219 /* Handle special case Combobox */ | 1233 /* Handle special case Combobox */ |
1220 MoveWindow(handle, currentx + pad, currenty + pad, | 1234 MoveWindow(handle, currentx + pad, currenty + pad, |
1221 width + vectorx, (height + vectory) + 400, FALSE); | 1235 width + vectorx, (height + vectory) + 400, FALSE); |
1222 } | 1236 } |
1223 else if(strnicmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1)==0) | 1237 else if(strnicmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1)==0) |
1224 { | 1238 { |
1225 /* Handle special case Spinbutton */ | 1239 /* Handle special case Spinbutton */ |
1226 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 1240 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
1227 | 1241 |
1228 MoveWindow(handle, currentx + pad + ((width + vectorx) - 20), currenty + pad, | 1242 MoveWindow(handle, currentx + pad + ((width + vectorx) - 20), currenty + pad, |
1229 20, height + vectory, FALSE); | 1243 20, height + vectory, FALSE); |
1230 | 1244 |
1231 if(cinfo) | 1245 if(cinfo) |
1232 { | 1246 { |
1233 MoveWindow(cinfo->buddy, currentx + pad, currenty + pad, | 1247 MoveWindow(cinfo->buddy, currentx + pad, currenty + pad, |
1234 (width + vectorx) - 20, height + vectory, FALSE); | 1248 (width + vectorx) - 20, height + vectory, FALSE); |
1235 } | 1249 } |
1236 } | 1250 } |
1237 else if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0) | 1251 else if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0) |
1238 { | 1252 { |
1239 /* Then try the bottom or right box */ | 1253 /* Then try the bottom or right box */ |
1240 float *percent = (float *)dw_window_get_data(handle, "_dw_percent"); | 1254 float *percent = (float *)dw_window_get_data(handle, "_dw_percent"); |
1241 int type = (int)dw_window_get_data(handle, "_dw_type"); | 1255 int type = (int)dw_window_get_data(handle, "_dw_type"); |
1242 int cx = width + vectorx; | 1256 int cx = width + vectorx; |
1243 int cy = height + vectory; | 1257 int cy = height + vectory; |
1244 | 1258 |
1245 MoveWindow(handle, currentx + pad, currenty + pad, | 1259 MoveWindow(handle, currentx + pad, currenty + pad, |
1246 cx, cy, FALSE); | 1260 cx, cy, FALSE); |
1247 | 1261 |
1248 if(cx > 0 && cy > 0 && percent) | 1262 if(cx > 0 && cy > 0 && percent) |
1249 _handle_splitbar_resize(handle, *percent, type, cx, cy); | 1263 _handle_splitbar_resize(handle, *percent, type, cx, cy); |
1250 } | 1264 } |
1251 else if(strnicmp(tmpbuf, STATICCLASSNAME, strlen(STATICCLASSNAME)+1)==0) | 1265 else if(strnicmp(tmpbuf, STATICCLASSNAME, strlen(STATICCLASSNAME)+1)==0) |
1252 { | 1266 { |
1253 /* Handle special case Vertically Center static text */ | 1267 /* Handle special case Vertically Center static text */ |
1254 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 1268 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
1255 | 1269 |
1256 if(cinfo && cinfo->vcenter) | 1270 if(cinfo && cinfo->vcenter) |
1257 { | 1271 { |
1258 /* We are centered so calculate a new position */ | 1272 /* We are centered so calculate a new position */ |
1259 char tmpbuf[1024]; | 1273 char tmpbuf[1024]; |
1260 int textheight, diff, total = height + vectory; | 1274 int textheight, diff, total = height + vectory; |
1261 | 1275 |
1262 GetWindowText(handle, tmpbuf, 1023); | 1276 GetWindowText(handle, tmpbuf, 1023); |
1263 | 1277 |
1264 /* Figure out how big the text is */ | 1278 /* Figure out how big the text is */ |
1265 dw_font_text_extents_get(handle, 0, tmpbuf, 0, &textheight); | 1279 dw_font_text_extents_get(handle, 0, tmpbuf, 0, &textheight); |
1266 | 1280 |
1267 diff = (total - textheight) / 2; | 1281 diff = (total - textheight) / 2; |
1268 | 1282 |
1269 MoveWindow(handle, currentx + pad, currenty + pad + diff, | 1283 MoveWindow(handle, currentx + pad, currenty + pad + diff, |
1270 width + vectorx, height + vectory - diff, FALSE); | 1284 width + vectorx, height + vectory - diff, FALSE); |
1271 } | 1285 } |
1272 else | 1286 else |
1273 { | 1287 { |
1274 MoveWindow(handle, currentx + pad, currenty + pad, | 1288 MoveWindow(handle, currentx + pad, currenty + pad, |
1275 width + vectorx, height + vectory, FALSE); | 1289 width + vectorx, height + vectory, FALSE); |
1276 } | 1290 } |
1277 } | 1291 } |
1278 else | 1292 else |
1279 { | 1293 { |
1280 /* Everything else */ | 1294 /* Everything else */ |
1281 MoveWindow(handle, currentx + pad, currenty + pad, | 1295 MoveWindow(handle, currentx + pad, currenty + pad, |
1282 width + vectorx, height + vectory, FALSE); | 1296 width + vectorx, height + vectory, FALSE); |
1283 if(thisbox->items[z].type == TYPEBOX) | 1297 if(thisbox->items[z].type == TYPEBOX) |
1284 { | 1298 { |
1285 Box *boxinfo = (Box *)GetWindowLongPtr(handle, GWLP_USERDATA); | 1299 Box *boxinfo = (Box *)GetWindowLongPtr(handle, GWLP_USERDATA); |
1286 | 1300 |
1287 if(boxinfo && boxinfo->grouphwnd) | 1301 if(boxinfo && boxinfo->grouphwnd) |
1288 MoveWindow(boxinfo->grouphwnd, 0, 0, | 1302 MoveWindow(boxinfo->grouphwnd, 0, 0, |
1289 width + vectorx, height + vectory, FALSE); | 1303 width + vectorx, height + vectory, FALSE); |
1290 | 1304 |
1291 } | 1305 } |
1292 } | 1306 } |
1293 | 1307 |
1294 /* Notebook dialog requires additional processing */ | 1308 /* Notebook dialog requires additional processing */ |
1295 if(strncmp(tmpbuf, WC_TABCONTROL, strlen(WC_TABCONTROL))==0) | 1309 if(strncmp(tmpbuf, WC_TABCONTROL, strlen(WC_TABCONTROL))==0) |
1296 { | 1310 { |
1297 RECT rect; | 1311 RECT rect; |
1298 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); | 1312 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); |
1299 int pageid = TabCtrl_GetCurSel(handle); | 1313 int pageid = TabCtrl_GetCurSel(handle); |
1300 | 1314 |
1301 if(pageid > -1 && array && array[pageid]) | 1315 if(pageid > -1 && array && array[pageid]) |
1302 { | 1316 { |
1303 GetClientRect(handle,&rect); | 1317 GetClientRect(handle,&rect); |
1304 TabCtrl_AdjustRect(handle,FALSE,&rect); | 1318 TabCtrl_AdjustRect(handle,FALSE,&rect); |
1305 MoveWindow(array[pageid]->hwnd, rect.left, rect.top, | 1319 MoveWindow(array[pageid]->hwnd, rect.left, rect.top, |
1306 rect.right - rect.left, rect.bottom-rect.top, FALSE); | 1320 rect.right - rect.left, rect.bottom-rect.top, FALSE); |
1307 } | 1321 } |
1308 } | 1322 } |
1309 | 1323 |
1310 if(thisbox->type == DW_HORZ) | 1324 if(thisbox->type == DW_HORZ) |
1311 currentx += width + vectorx + (pad * 2); | 1325 currentx += width + vectorx + (pad * 2); |
1312 if(thisbox->type == DW_VERT) | 1326 if(thisbox->type == DW_VERT) |
1313 currenty += height + vectory + (pad * 2); | 1327 currenty += height + vectory + (pad * 2); |
1314 } | 1328 } |
1315 } | 1329 } |
1316 } | 1330 } |
1317 return 0; | 1331 return 0; |
1318 } | 1332 } |
1319 | 1333 |
1320 void _do_resize(Box *thisbox, int x, int y) | 1334 void _do_resize(Box *thisbox, int x, int y) |
1321 { | 1335 { |
1322 if(x != 0 && y != 0) | 1336 if(x != 0 && y != 0) |
1323 { | 1337 { |
1324 if(thisbox) | 1338 if(thisbox) |
1325 { | 1339 { |
1326 int usedx = 0, usedy = 0, depth = 0, usedpadx = 0, usedpady = 0; | 1340 int usedx = 0, usedy = 0, depth = 0, usedpadx = 0, usedpady = 0; |
1327 | 1341 |
1328 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 1, &usedpadx, &usedpady); | 1342 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 1, &usedpadx, &usedpady); |
1329 | 1343 |
1330 if(usedx-usedpadx == 0 || usedy-usedpady == 0) | 1344 if(usedx-usedpadx == 0 || usedy-usedpady == 0) |
1331 return; | 1345 return; |
1332 | 1346 |
1333 thisbox->xratio = ((float)(x-usedpadx))/((float)(usedx-usedpadx)); | 1347 thisbox->xratio = ((float)(x-usedpadx))/((float)(usedx-usedpadx)); |
1334 thisbox->yratio = ((float)(y-usedpady))/((float)(usedy-usedpady)); | 1348 thisbox->yratio = ((float)(y-usedpady))/((float)(usedy-usedpady)); |
1335 | 1349 |
1336 usedpadx = usedpady = usedx = usedy = depth = 0; | 1350 usedpadx = usedpady = usedx = usedy = depth = 0; |
1337 | 1351 |
1338 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 2, &usedpadx, &usedpady); | 1352 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 2, &usedpadx, &usedpady); |
1339 } | 1353 } |
1340 } | 1354 } |
1341 } | 1355 } |
1342 | 1356 |
1343 int _HandleScroller(HWND handle, int pos, int which) | 1357 int _HandleScroller(HWND handle, int pos, int which) |
1344 { | 1358 { |
1345 SCROLLINFO si; | 1359 SCROLLINFO si; |
1346 | 1360 |
1347 si.cbSize = sizeof(SCROLLINFO); | 1361 si.cbSize = sizeof(SCROLLINFO); |
1348 si.fMask = SIF_ALL; | 1362 si.fMask = SIF_ALL; |
1349 | 1363 |
1350 SendMessage(handle, SBM_GETSCROLLINFO, 0, (LPARAM)&si); | 1364 SendMessage(handle, SBM_GETSCROLLINFO, 0, (LPARAM)&si); |
1351 | 1365 |
1352 switch(which) | 1366 switch(which) |
1353 { | 1367 { |
1354 case SB_THUMBTRACK: | 1368 case SB_THUMBTRACK: |
1355 return pos; | 1369 return pos; |
1356 /*case SB_PAGEDOWN:*/ | 1370 /*case SB_PAGEDOWN:*/ |
1357 case SB_PAGELEFT: | 1371 case SB_PAGELEFT: |
1358 pos = si.nPos - si.nPage; | 1372 pos = si.nPos - si.nPage; |
1359 if(pos < si.nMin) | 1373 if(pos < si.nMin) |
1360 pos = si.nMin; | 1374 pos = si.nMin; |
1361 return pos; | 1375 return pos; |
1362 /*case SB_PAGEUP:*/ | 1376 /*case SB_PAGEUP:*/ |
1363 case SB_PAGERIGHT: | 1377 case SB_PAGERIGHT: |
1364 pos = si.nPos + si.nPage; | 1378 pos = si.nPos + si.nPage; |
1365 if(pos > (si.nMax - si.nPage) + 1) | 1379 if(pos > (si.nMax - si.nPage) + 1) |
1366 pos = (si.nMax - si.nPage) + 1; | 1380 pos = (si.nMax - si.nPage) + 1; |
1367 return pos; | 1381 return pos; |
1368 /*case SB_LINEDOWN:*/ | 1382 /*case SB_LINEDOWN:*/ |
1369 case SB_LINELEFT: | 1383 case SB_LINELEFT: |
1370 pos = si.nPos - 1; | 1384 pos = si.nPos - 1; |
1371 if(pos < si.nMin) | 1385 if(pos < si.nMin) |
1372 pos = si.nMin; | 1386 pos = si.nMin; |
1373 return pos; | 1387 return pos; |
1374 /*case SB_LINEUP:*/ | 1388 /*case SB_LINEUP:*/ |
1375 case SB_LINERIGHT: | 1389 case SB_LINERIGHT: |
1376 pos = si.nPos + 1; | 1390 pos = si.nPos + 1; |
1377 if(pos > (si.nMax - si.nPage) + 1) | 1391 if(pos > (si.nMax - si.nPage) + 1) |
1378 pos = (si.nMax - si.nPage) + 1; | 1392 pos = (si.nMax - si.nPage) + 1; |
1379 return pos; | 1393 return pos; |
1380 } | 1394 } |
1381 return -1; | 1395 return -1; |
1382 } | 1396 } |
1383 | 1397 |
1384 HMENU _get_owner(HMENU menu) | 1398 HMENU _get_owner(HMENU menu) |
1385 { | 1399 { |
1386 MENUINFO mi; | 1400 MENUINFO mi; |
1387 | 1401 |
1388 mi.cbSize = sizeof(MENUINFO); | 1402 mi.cbSize = sizeof(MENUINFO); |
1389 mi.fMask = MIM_MENUDATA; | 1403 mi.fMask = MIM_MENUDATA; |
1390 | 1404 |
1391 if(MyGetMenuInfo(menu, &mi)) | 1405 if ( MyGetMenuInfo( menu, &mi ) ) |
1392 return (HMENU)mi.dwMenuData; | 1406 return (HMENU)mi.dwMenuData; |
1393 return (HMENU)0; | 1407 return (HMENU)0; |
1394 } | 1408 } |
1395 | 1409 |
1396 /* Find the desktop window handle */ | 1410 /* Find the desktop window handle */ |
1397 HMENU _menu_owner(HMENU handle) | 1411 HMENU _menu_owner(HMENU handle) |
1398 { | 1412 { |
1399 HMENU menuowner = 0, lastowner = _get_owner(handle); | 1413 HMENU menuowner = 0, lastowner = _get_owner(handle); |
1400 | 1414 |
1401 /* Find the toplevel menu */ | 1415 /* Find the toplevel menu */ |
1402 while((menuowner = _get_owner(lastowner)) != 0) | 1416 while((menuowner = _get_owner(lastowner)) != 0) |
1403 { | 1417 { |
1404 if(menuowner == (HMENU)1) | 1418 if(menuowner == (HMENU)1) |
1405 return lastowner; | 1419 return lastowner; |
1406 lastowner = menuowner; | 1420 lastowner = menuowner; |
1407 } | 1421 } |
1408 return (HMENU)0; | 1422 return (HMENU)0; |
1423 } | |
1424 | |
1425 /* | |
1426 * Determine if this is a checkable menu. If it is get the current state | |
1427 * and toggle it. Windows doesn't do this automatically :-( | |
1428 */ | |
1429 static void _dw_toggle_checkable_menu_item( HWND window, int id ) | |
1430 { | |
1431 char buffer[40]; | |
1432 int checkable; | |
1433 sprintf( buffer, "_dw_checkable%ld", id ); | |
1434 checkable = (int)dw_window_get_data(DW_HWND_OBJECT, buffer); | |
1435 if ( checkable ) | |
1436 { | |
1437 int is_checked; | |
1438 sprintf( buffer, "_dw_ischecked%ld", id ); | |
1439 is_checked = (int)dw_window_get_data(DW_HWND_OBJECT, buffer); | |
1440 is_checked = (is_checked) ? 0 : 1; | |
1441 dw_menu_item_set_check( window, id, is_checked ); | |
1442 } | |
1409 } | 1443 } |
1410 | 1444 |
1411 /* The main window procedure for Dynamic Windows, all the resizing code is done here. */ | 1445 /* The main window procedure for Dynamic Windows, all the resizing code is done here. */ |
1412 BOOL CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) | 1446 BOOL CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) |
1413 { | 1447 { |
1414 int result = -1, taskbar = FALSE; | 1448 int result = -1, taskbar = FALSE; |
1415 static int command_active = 0; | 1449 static int command_active = 0; |
1416 SignalHandler *tmp = Root; | 1450 SignalHandler *tmp = Root; |
1417 void (*windowfunc)(PVOID); | 1451 void (*windowfunc)(PVOID); |
1418 ULONG origmsg = msg; | 1452 ULONG origmsg = msg; |
1419 | 1453 |
1420 /* Deal with translating some messages */ | 1454 /* Deal with translating some messages */ |
1421 if(msg == WM_USER+2) | 1455 if (msg == WM_USER+2) |
1422 { | 1456 { |
1423 taskbar = TRUE; | 1457 taskbar = TRUE; |
1424 origmsg = msg = (UINT)mp2; /* no else here */ | 1458 origmsg = msg = (UINT)mp2; /* no else here */ |
1425 } | 1459 } |
1426 if(msg == WM_RBUTTONDOWN || msg == WM_MBUTTONDOWN) | 1460 if (msg == WM_RBUTTONDOWN || msg == WM_MBUTTONDOWN) |
1427 msg = WM_LBUTTONDOWN; | 1461 msg = WM_LBUTTONDOWN; |
1428 else if(msg == WM_RBUTTONUP || msg == WM_MBUTTONUP) | 1462 else if (msg == WM_RBUTTONUP || msg == WM_MBUTTONUP) |
1429 msg = WM_LBUTTONUP; | 1463 msg = WM_LBUTTONUP; |
1430 else if(msg == WM_HSCROLL) | 1464 else if (msg == WM_HSCROLL) |
1431 msg = WM_VSCROLL; | 1465 msg = WM_VSCROLL; |
1432 else if(msg == WM_KEYDOWN) /* && mp1 >= VK_F1 && mp1 <= VK_F24) allow ALL special keys */ | 1466 else if (msg == WM_KEYDOWN) /* && mp1 >= VK_F1 && mp1 <= VK_F24) allow ALL special keys */ |
1433 msg = WM_CHAR; | 1467 msg = WM_CHAR; |
1434 | 1468 |
1435 if(result == -1) | 1469 if (result == -1) |
1436 { | 1470 { |
1437 /* Avoid infinite recursion */ | 1471 /* Avoid infinite recursion */ |
1438 command_active = 1; | 1472 command_active = 1; |
1439 | 1473 |
1440 /* Find any callbacks for this function */ | 1474 /* Find any callbacks for this function */ |
1441 while(tmp) | 1475 while (tmp) |
1442 { | 1476 { |
1443 if(tmp->message == msg || msg == WM_COMMAND || msg == WM_NOTIFY || tmp->message == WM_USER+1) | 1477 if (tmp->message == msg || msg == WM_COMMAND || msg == WM_NOTIFY || tmp->message == WM_USER+1) |
1444 { | 1478 { |
1445 switch(msg) | 1479 switch (msg) |
1446 { | 1480 { |
1447 case WM_TIMER: | 1481 case WM_TIMER: |
1448 { | 1482 { |
1449 if(!hWnd) | 1483 if (!hWnd) |
1450 { | 1484 { |
1451 int (*timerfunc)(void *) = tmp->signalfunction; | 1485 int (*timerfunc)(void *) = tmp->signalfunction; |
1452 if(tmp->id == (int)mp1) | 1486 if (tmp->id == (int)mp1) |
1453 { | 1487 { |
1454 if(!timerfunc(tmp->data)) | 1488 if (!timerfunc(tmp->data)) |
1455 dw_timer_disconnect(tmp->id); | 1489 dw_timer_disconnect(tmp->id); |
1456 tmp = NULL; | 1490 tmp = NULL; |
1457 } | 1491 } |
1458 } | 1492 } |
1459 result = 0; | 1493 result = 0; |
1460 } | 1494 } |
1461 break; | 1495 break; |
1462 case WM_SETFOCUS: | 1496 case WM_SETFOCUS: |
1463 { | 1497 { |
1464 int (*setfocusfunc)(HWND, void *) = (int (*)(HWND, void *))tmp->signalfunction; | 1498 int (*setfocusfunc)(HWND, void *) = (int (*)(HWND, void *))tmp->signalfunction; |
1465 | 1499 |
1466 if(hWnd == tmp->window) | 1500 if(hWnd == tmp->window) |
1467 { | 1501 { |
1468 result = setfocusfunc(tmp->window, tmp->data); | 1502 result = setfocusfunc(tmp->window, tmp->data); |
1469 tmp = NULL; | 1503 tmp = NULL; |
1470 } | 1504 } |
1471 } | 1505 } |
1472 break; | 1506 break; |
1473 case WM_SIZE: | 1507 case WM_SIZE: |
1474 { | 1508 { |
1475 int (*sizefunc)(HWND, int, int, void *) = tmp->signalfunction; | 1509 int (*sizefunc)(HWND, int, int, void *) = tmp->signalfunction; |
1476 | 1510 |
1477 if(hWnd == tmp->window) | 1511 if(hWnd == tmp->window) |
1478 { | 1512 { |
1479 result = sizefunc(tmp->window, LOWORD(mp2), HIWORD(mp2), tmp->data); | 1513 result = sizefunc(tmp->window, LOWORD(mp2), HIWORD(mp2), tmp->data); |
1480 tmp = NULL; | 1514 tmp = NULL; |
1481 } | 1515 } |
1482 } | 1516 } |
1483 break; | 1517 break; |
1484 case WM_LBUTTONDOWN: | 1518 case WM_LBUTTONDOWN: |
1485 { | 1519 { |
1486 int (*buttonfunc)(HWND, int, int, int, void *) = (int (*)(HWND, int, int, int, void *))tmp->signalfunction; | 1520 int (*buttonfunc)(HWND, int, int, int, void *) = (int (*)(HWND, int, int, int, void *))tmp->signalfunction; |
1487 | 1521 |
1488 if(hWnd == tmp->window) | 1522 if(hWnd == tmp->window) |
1489 { | 1523 { |
1490 int button=0; | 1524 int button=0; |
1491 | 1525 |
1492 switch(origmsg) | 1526 switch(origmsg) |
1493 { | 1527 { |
1494 case WM_LBUTTONDOWN: | 1528 case WM_LBUTTONDOWN: |
1495 button = 1; | 1529 button = 1; |
1496 break; | 1530 break; |
1497 case WM_RBUTTONDOWN: | 1531 case WM_RBUTTONDOWN: |
1498 button = 2; | 1532 button = 2; |
1499 break; | 1533 break; |
1500 case WM_MBUTTONDOWN: | 1534 case WM_MBUTTONDOWN: |
1501 button = 3; | 1535 button = 3; |
1502 break; | 1536 break; |
1503 } | 1537 } |
1504 if(taskbar) | 1538 if(taskbar) |
1505 { | 1539 { |
1506 POINT ptl; | 1540 POINT ptl; |
1507 GetCursorPos(&ptl); | 1541 GetCursorPos(&ptl); |
1508 result = buttonfunc(tmp->window, ptl.x, ptl.y, button, tmp->data); | 1542 result = buttonfunc(tmp->window, ptl.x, ptl.y, button, tmp->data); |
1509 } | 1543 } |
1510 else | 1544 else |
1511 { | 1545 { |
1512 POINTS pts = MAKEPOINTS(mp2); | 1546 POINTS pts = MAKEPOINTS(mp2); |
1513 result = buttonfunc(tmp->window, pts.x, pts.y, button, tmp->data); | 1547 result = buttonfunc(tmp->window, pts.x, pts.y, button, tmp->data); |
1514 } | 1548 } |
1515 tmp = NULL; | 1549 tmp = NULL; |
1516 } | 1550 } |
1517 } | 1551 } |
1518 break; | 1552 break; |
1519 case WM_LBUTTONUP: | 1553 case WM_LBUTTONUP: |
1520 { | 1554 { |
1521 int (*buttonfunc)(HWND, int, int, int, void *) = (int (*)(HWND, int, int, int, void *))tmp->signalfunction; | 1555 int (*buttonfunc)(HWND, int, int, int, void *) = (int (*)(HWND, int, int, int, void *))tmp->signalfunction; |
1522 | 1556 |
1523 if(hWnd == tmp->window) | 1557 if(hWnd == tmp->window) |
1524 { | 1558 { |
1525 int button=0; | 1559 int button=0; |
1526 | 1560 |
1527 switch(origmsg) | 1561 switch(origmsg) |
1528 { | 1562 { |
1529 case WM_LBUTTONUP: | 1563 case WM_LBUTTONUP: |
1530 button = 1; | 1564 button = 1; |
1531 break; | 1565 break; |
1532 case WM_RBUTTONUP: | 1566 case WM_RBUTTONUP: |
1533 button = 2; | 1567 button = 2; |
1534 break; | 1568 break; |
1535 case WM_MBUTTONUP: | 1569 case WM_MBUTTONUP: |
1536 button = 3; | 1570 button = 3; |
1537 break; | 1571 break; |
1538 } | 1572 } |
1539 if(taskbar) | 1573 if(taskbar) |
1540 { | 1574 { |
1541 POINT ptl; | 1575 POINT ptl; |
1542 GetCursorPos(&ptl); | 1576 GetCursorPos(&ptl); |
1543 result = buttonfunc(tmp->window, ptl.x, ptl.y, button, tmp->data); | 1577 result = buttonfunc(tmp->window, ptl.x, ptl.y, button, tmp->data); |
1544 } | 1578 } |
1545 else | 1579 else |
1546 { | 1580 { |
1547 POINTS pts = MAKEPOINTS(mp2); | 1581 POINTS pts = MAKEPOINTS(mp2); |
1548 result = buttonfunc(tmp->window, pts.x, pts.y, button, tmp->data); | 1582 result = buttonfunc(tmp->window, pts.x, pts.y, button, tmp->data); |
1549 } | 1583 } |
1550 tmp = NULL; | 1584 tmp = NULL; |
1551 } | 1585 } |
1552 } | 1586 } |
1553 break; | 1587 break; |
1554 case WM_MOUSEMOVE: | 1588 case WM_MOUSEMOVE: |
1555 { | 1589 { |
1556 POINTS pts = MAKEPOINTS(mp2); | 1590 POINTS pts = MAKEPOINTS(mp2); |
1557 int (*motionfunc)(HWND, int, int, int, void *) = (int (*)(HWND, int, int, int, void *))tmp->signalfunction; | 1591 int (*motionfunc)(HWND, int, int, int, void *) = (int (*)(HWND, int, int, int, void *))tmp->signalfunction; |
1558 | 1592 |
1559 if(hWnd == tmp->window) | 1593 if(hWnd == tmp->window) |
1560 { | 1594 { |
1561 int keys = 0; | 1595 int keys = 0; |
1562 | 1596 |
1563 if (mp1 & MK_LBUTTON) | 1597 if (mp1 & MK_LBUTTON) |
1564 keys = DW_BUTTON1_MASK; | 1598 keys = DW_BUTTON1_MASK; |
1565 if (mp1 & MK_RBUTTON) | 1599 if (mp1 & MK_RBUTTON) |
1566 keys |= DW_BUTTON2_MASK; | 1600 keys |= DW_BUTTON2_MASK; |
1567 if (mp1 & MK_MBUTTON) | 1601 if (mp1 & MK_MBUTTON) |
1568 keys |= DW_BUTTON3_MASK; | 1602 keys |= DW_BUTTON3_MASK; |
1569 | 1603 |
1570 result = motionfunc(tmp->window, pts.x, pts.y, keys, tmp->data); | 1604 result = motionfunc(tmp->window, pts.x, pts.y, keys, tmp->data); |
1571 tmp = NULL; | 1605 tmp = NULL; |
1572 } | 1606 } |
1573 } | 1607 } |
1574 break; | 1608 break; |
1575 case WM_CHAR: | 1609 case WM_CHAR: |
1576 { | 1610 { |
1577 int (*keypressfunc)(HWND, char, int, int, void *) = tmp->signalfunction; | 1611 int (*keypressfunc)(HWND, char, int, int, void *) = tmp->signalfunction; |
1578 | 1612 |
1579 if(hWnd == tmp->window || _toplevel_window(hWnd) == tmp->window) | 1613 if(hWnd == tmp->window || _toplevel_window(hWnd) == tmp->window) |
1580 { | 1614 { |
1581 int special = 0; | 1615 int special = 0; |
1582 char ch = 0; | 1616 char ch = 0; |
1583 | 1617 |
1584 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) | 1618 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) |
1585 special |= KC_SHIFT; | 1619 special |= KC_SHIFT; |
1586 if(GetAsyncKeyState(VK_CONTROL) & 0x8000) | 1620 if(GetAsyncKeyState(VK_CONTROL) & 0x8000) |
1587 special |= KC_CTRL; | 1621 special |= KC_CTRL; |
1588 if(mp2 & (1 << 29)) | 1622 if(mp2 & (1 << 29)) |
1589 special |= KC_ALT; | 1623 special |= KC_ALT; |
1590 | 1624 |
1591 if(origmsg == WM_CHAR && mp1 < 128) | 1625 if(origmsg == WM_CHAR && mp1 < 128) |
1592 ch = (char)mp1; | 1626 ch = (char)mp1; |
1593 | 1627 |
1594 result = keypressfunc(tmp->window, ch, mp1, special, tmp->data); | 1628 result = keypressfunc(tmp->window, ch, mp1, special, tmp->data); |
1595 tmp = NULL; | 1629 tmp = NULL; |
1596 } | 1630 } |
1597 } | 1631 } |
1598 break; | 1632 break; |
1599 case WM_CLOSE: | 1633 case WM_CLOSE: |
1600 { | 1634 { |
1601 int (*closefunc)(HWND, void *) = tmp->signalfunction; | 1635 int (*closefunc)(HWND, void *) = tmp->signalfunction; |
1602 | 1636 |
1603 if(hWnd == tmp->window) | 1637 if(hWnd == tmp->window) |
1604 { | 1638 { |
1605 result = closefunc(tmp->window, tmp->data); | 1639 result = closefunc(tmp->window, tmp->data); |
1606 tmp = NULL; | 1640 tmp = NULL; |
1607 } | 1641 } |
1608 } | 1642 } |
1609 break; | 1643 break; |
1610 case WM_PAINT: | 1644 case WM_PAINT: |
1611 { | 1645 { |
1612 PAINTSTRUCT ps; | 1646 PAINTSTRUCT ps; |
1613 DWExpose exp; | 1647 DWExpose exp; |
1614 int (*exposefunc)(HWND, DWExpose *, void *) = tmp->signalfunction; | 1648 int (*exposefunc)(HWND, DWExpose *, void *) = tmp->signalfunction; |
1615 | 1649 |
1616 if(hWnd == tmp->window) | 1650 if(hWnd == tmp->window) |
1617 { | 1651 { |
1618 BeginPaint(hWnd, &ps); | 1652 BeginPaint(hWnd, &ps); |
1619 exp.x = ps.rcPaint.left; | 1653 exp.x = ps.rcPaint.left; |
1620 exp.y = ps.rcPaint.top; | 1654 exp.y = ps.rcPaint.top; |
1621 exp.width = ps.rcPaint.right - ps.rcPaint.left; | 1655 exp.width = ps.rcPaint.right - ps.rcPaint.left; |
1622 exp.height = ps.rcPaint.bottom - ps.rcPaint.top; | 1656 exp.height = ps.rcPaint.bottom - ps.rcPaint.top; |
1623 result = exposefunc(hWnd, &exp, tmp->data); | 1657 result = exposefunc(hWnd, &exp, tmp->data); |
1624 EndPaint(hWnd, &ps); | 1658 EndPaint(hWnd, &ps); |
1625 } | 1659 } |
1626 } | 1660 } |
1627 break; | 1661 break; |
1628 case WM_NOTIFY: | 1662 case WM_NOTIFY: |
1629 { | 1663 { |
1630 if(tmp->message == TVN_SELCHANGED || | 1664 if(tmp->message == TVN_SELCHANGED || |
1631 tmp->message == NM_RCLICK || | 1665 tmp->message == NM_RCLICK || |
1632 tmp->message == TVN_ITEMEXPANDED) | 1666 tmp->message == TVN_ITEMEXPANDED) |
1633 { | 1667 { |
1634 NMTREEVIEW FAR *tem=(NMTREEVIEW FAR *)mp2; | 1668 NMTREEVIEW FAR *tem=(NMTREEVIEW FAR *)mp2; |
1635 NMLISTVIEW FAR *lem=(NMLISTVIEW FAR *)mp2; | 1669 NMLISTVIEW FAR *lem=(NMLISTVIEW FAR *)mp2; |
1636 char tmpbuf[100]; | 1670 char tmpbuf[100]; |
1637 | 1671 |
1638 GetClassName(tem->hdr.hwndFrom, tmpbuf, 99); | 1672 GetClassName(tem->hdr.hwndFrom, tmpbuf, 99); |
1639 | 1673 |
1640 if(strnicmp(tmpbuf, WC_TREEVIEW, strlen(WC_TREEVIEW))==0) | 1674 if(strnicmp(tmpbuf, WC_TREEVIEW, strlen(WC_TREEVIEW))==0) |
1641 { | 1675 { |
1642 if(tem->hdr.code == TVN_SELCHANGED && tmp->message == TVN_SELCHANGED) | 1676 if(tem->hdr.code == TVN_SELCHANGED && tmp->message == TVN_SELCHANGED) |
1643 { | 1677 { |
1644 if(tmp->window == tem->hdr.hwndFrom && !dw_window_get_data(tmp->window, "_dw_select_item")) | 1678 if(tmp->window == tem->hdr.hwndFrom && !dw_window_get_data(tmp->window, "_dw_select_item")) |
1645 { | 1679 { |
1646 int (*treeselectfunc)(HWND, HTREEITEM, char *, void *, void *) = tmp->signalfunction; | 1680 int (*treeselectfunc)(HWND, HTREEITEM, char *, void *, void *) = tmp->signalfunction; |
1647 TVITEM tvi; | 1681 TVITEM tvi; |
1648 void **ptrs; | 1682 void **ptrs; |
1649 | 1683 |
1650 tvi.mask = TVIF_HANDLE; | 1684 tvi.mask = TVIF_HANDLE; |
1651 tvi.hItem = tem->itemNew.hItem; | 1685 tvi.hItem = tem->itemNew.hItem; |
1652 | 1686 |
1653 TreeView_GetItem(tmp->window, &tvi); | 1687 TreeView_GetItem(tmp->window, &tvi); |
1654 | 1688 |
1655 ptrs = (void **)tvi.lParam; | 1689 ptrs = (void **)tvi.lParam; |
1656 if(ptrs) | 1690 if(ptrs) |
1657 result = treeselectfunc(tmp->window, tem->itemNew.hItem, (char *)ptrs[0], tmp->data, (void *)ptrs[1]); | 1691 result = treeselectfunc(tmp->window, tem->itemNew.hItem, (char *)ptrs[0], tmp->data, (void *)ptrs[1]); |
1658 | 1692 |
1659 tmp = NULL; | 1693 tmp = NULL; |
1660 } | 1694 } |
1661 } | 1695 } |
1662 else if(tem->hdr.code == TVN_ITEMEXPANDED && tmp->message == TVN_ITEMEXPANDED) | 1696 else if(tem->hdr.code == TVN_ITEMEXPANDED && tmp->message == TVN_ITEMEXPANDED) |
1663 { | 1697 { |
1664 if(tmp->window == tem->hdr.hwndFrom && tem->action == TVE_EXPAND) | 1698 if(tmp->window == tem->hdr.hwndFrom && tem->action == TVE_EXPAND) |
1665 { | 1699 { |
1666 int (*treeexpandfunc)(HWND, HTREEITEM, void *) = tmp->signalfunction; | 1700 int (*treeexpandfunc)(HWND, HTREEITEM, void *) = tmp->signalfunction; |
1667 | 1701 |
1668 result = treeexpandfunc(tmp->window, tem->itemNew.hItem, tmp->data); | 1702 result = treeexpandfunc(tmp->window, tem->itemNew.hItem, tmp->data); |
1669 tmp = NULL; | 1703 tmp = NULL; |
1670 } | 1704 } |
1671 } | 1705 } |
1672 else if(tem->hdr.code == NM_RCLICK && tmp->message == NM_RCLICK) | 1706 else if(tem->hdr.code == NM_RCLICK && tmp->message == NM_RCLICK) |
1673 { | 1707 { |
1674 if(tmp->window == tem->hdr.hwndFrom) | 1708 if(tmp->window == tem->hdr.hwndFrom) |
1675 { | 1709 { |
1676 int (*containercontextfunc)(HWND, char *, int, int, void *, void *) = tmp->signalfunction; | 1710 int (*containercontextfunc)(HWND, char *, int, int, void *, void *) = tmp->signalfunction; |
1677 HTREEITEM hti, last; | 1711 HTREEITEM hti, last; |
1678 TVITEM tvi; | 1712 TVITEM tvi; |
1679 TVHITTESTINFO thi; | 1713 TVHITTESTINFO thi; |
1680 void **ptrs = NULL; | 1714 void **ptrs = NULL; |
1681 LONG x, y; | 1715 LONG x, y; |
1682 | 1716 |
1683 dw_pointer_query_pos(&x, &y); | 1717 dw_pointer_query_pos(&x, &y); |
1684 | 1718 |
1685 thi.pt.x = x; | 1719 thi.pt.x = x; |
1686 thi.pt.y = y; | 1720 thi.pt.y = y; |
1687 | 1721 |
1688 MapWindowPoints(HWND_DESKTOP, tmp->window, &thi.pt, 1); | 1722 MapWindowPoints(HWND_DESKTOP, tmp->window, &thi.pt, 1); |
1689 | 1723 |
1690 last = TreeView_GetSelection(tmp->window); | 1724 last = TreeView_GetSelection(tmp->window); |
1691 hti = TreeView_HitTest(tmp->window, &thi); | 1725 hti = TreeView_HitTest(tmp->window, &thi); |
1692 | 1726 |
1693 if(hti) | 1727 if(hti) |
1694 { | 1728 { |
1695 tvi.mask = TVIF_HANDLE; | 1729 tvi.mask = TVIF_HANDLE; |
1696 tvi.hItem = hti; | 1730 tvi.hItem = hti; |
1697 | 1731 |
1698 TreeView_GetItem(tmp->window, &tvi); | 1732 TreeView_GetItem(tmp->window, &tvi); |
1699 TreeView_SelectItem(tmp->window, hti); | 1733 TreeView_SelectItem(tmp->window, hti); |
1700 | 1734 |
1701 ptrs = (void **)tvi.lParam; | 1735 ptrs = (void **)tvi.lParam; |
1702 } | 1736 } |
1703 containercontextfunc(tmp->window, ptrs ? (char *)ptrs[0] : NULL, x, y, tmp->data, ptrs ? ptrs[1] : NULL); | 1737 containercontextfunc(tmp->window, ptrs ? (char *)ptrs[0] : NULL, x, y, tmp->data, ptrs ? ptrs[1] : NULL); |
1704 tmp = NULL; | 1738 tmp = NULL; |
1705 } | 1739 } |
1706 } | 1740 } |
1707 } | 1741 } |
1708 else if(strnicmp(tmpbuf, WC_LISTVIEW, strlen(WC_LISTVIEW)+1)==0) | 1742 else if(strnicmp(tmpbuf, WC_LISTVIEW, strlen(WC_LISTVIEW)+1)==0) |
1709 { | 1743 { |
1710 if((lem->hdr.code == LVN_ITEMCHANGED && (lem->uChanged & LVIF_STATE)) && tmp->message == TVN_SELCHANGED) | 1744 if((lem->hdr.code == LVN_ITEMCHANGED && (lem->uChanged & LVIF_STATE)) && tmp->message == TVN_SELCHANGED) |
1711 { | 1745 { |
1712 if(tmp->window == tem->hdr.hwndFrom) | 1746 if(tmp->window == tem->hdr.hwndFrom) |
1713 { | 1747 { |
1714 LV_ITEM lvi; | 1748 LV_ITEM lvi; |
1715 int iItem; | 1749 int iItem; |
1716 | 1750 |
1717 iItem = ListView_GetNextItem(tmp->window, -1, LVNI_SELECTED); | 1751 iItem = ListView_GetNextItem(tmp->window, -1, LVNI_SELECTED); |
1718 | 1752 |
1719 memset(&lvi, 0, sizeof(LV_ITEM)); | 1753 memset(&lvi, 0, sizeof(LV_ITEM)); |
1720 | 1754 |
1721 if(iItem > -1) | 1755 if(iItem > -1) |
1722 { | 1756 { |
1723 int (*treeselectfunc)(HWND, HWND, char *, void *, void *) = tmp->signalfunction; | 1757 int (*treeselectfunc)(HWND, HWND, char *, void *, void *) = tmp->signalfunction; |
1724 | 1758 |
1725 lvi.iItem = iItem; | 1759 lvi.iItem = iItem; |
1726 lvi.mask = LVIF_PARAM; | 1760 lvi.mask = LVIF_PARAM; |
1727 | 1761 |
1728 ListView_GetItem(tmp->window, &lvi); | 1762 ListView_GetItem(tmp->window, &lvi); |
1729 | 1763 |
1730 /* Seems to be having lParam as 1 which really sucks */ | 1764 /* Seems to be having lParam as 1 which really sucks */ |
1731 if(lvi.lParam < 100) | 1765 if(lvi.lParam < 100) |
1732 lvi.lParam = 0; | 1766 lvi.lParam = 0; |
1733 | 1767 |
1734 treeselectfunc(tmp->window, 0, (char *)lvi.lParam, tmp->data, 0); | 1768 treeselectfunc(tmp->window, 0, (char *)lvi.lParam, tmp->data, 0); |
1735 tmp = NULL; | 1769 tmp = NULL; |
1736 } | 1770 } |
1737 } | 1771 } |
1738 } | 1772 } |
1739 } | 1773 } |
1740 } | 1774 } |
1741 else if(tmp->message == TCN_SELCHANGE) | 1775 else if(tmp->message == TCN_SELCHANGE) |
1742 { | 1776 { |
1743 NMHDR FAR *tem=(NMHDR FAR *)mp2; | 1777 NMHDR FAR *tem=(NMHDR FAR *)mp2; |
1744 if(tmp->window == tem->hwndFrom && tem->code == tmp->message) | 1778 if(tmp->window == tem->hwndFrom && tem->code == tmp->message) |
1745 { | 1779 { |
1746 int (*switchpagefunc)(HWND, unsigned long, void *) = tmp->signalfunction; | 1780 int (*switchpagefunc)(HWND, unsigned long, void *) = tmp->signalfunction; |
1747 unsigned long num=dw_notebook_page_get(tem->hwndFrom); | 1781 unsigned long num=dw_notebook_page_get(tem->hwndFrom); |
1748 result = switchpagefunc(tem->hwndFrom, num, tmp->data); | 1782 result = switchpagefunc(tem->hwndFrom, num, tmp->data); |
1749 tmp = NULL; | 1783 tmp = NULL; |
1750 } | 1784 } |
1751 } | 1785 } |
1752 else if(tmp->message == LVN_COLUMNCLICK) | 1786 else if(tmp->message == LVN_COLUMNCLICK) |
1753 { | 1787 { |
1754 NMLISTVIEW FAR *tem=(NMLISTVIEW FAR *)mp2; | 1788 NMLISTVIEW FAR *tem=(NMLISTVIEW FAR *)mp2; |
1755 if(tmp->window == tem->hdr.hwndFrom && tem->hdr.code == tmp->message) | 1789 if(tmp->window == tem->hdr.hwndFrom && tem->hdr.code == tmp->message) |
1756 { | 1790 { |
1757 int (*columnclickfunc)(HWND, int, void *) = tmp->signalfunction; | 1791 int (*columnclickfunc)(HWND, int, void *) = tmp->signalfunction; |
1758 result = columnclickfunc(tem->hdr.hwndFrom, tem->iSubItem, tmp->data); | 1792 result = columnclickfunc(tem->hdr.hwndFrom, tem->iSubItem, tmp->data); |
1759 tmp = NULL; | 1793 tmp = NULL; |
1760 } | 1794 } |
1761 } | 1795 } |
1762 } | 1796 } |
1763 break; | 1797 break; |
1764 case WM_COMMAND: | 1798 case WM_COMMAND: |
1765 { | 1799 { |
1766 int (*clickfunc)(HWND, void *) = tmp->signalfunction; | 1800 int (*clickfunc)(HWND, void *) = tmp->signalfunction; |
1767 HWND command; | 1801 HWND command; |
1768 ULONG passthru = (ULONG)LOWORD(mp1); | 1802 ULONG passthru = (ULONG)LOWORD(mp1); |
1769 ULONG message = HIWORD(mp1); | 1803 ULONG message = HIWORD(mp1); |
1770 | 1804 |
1771 command = (HWND)passthru; | 1805 command = (HWND)passthru; |
1772 | 1806 |
1773 if(message == LBN_SELCHANGE || message == CBN_SELCHANGE) | 1807 if (message == LBN_SELCHANGE || message == CBN_SELCHANGE) |
1774 { | 1808 { |
1775 int (*listboxselectfunc)(HWND, int, void *) = tmp->signalfunction; | 1809 int (*listboxselectfunc)(HWND, int, void *) = tmp->signalfunction; |
1776 | 1810 |
1777 if(tmp->message == LBN_SELCHANGE && tmp->window == (HWND)mp2) | 1811 if (tmp->message == LBN_SELCHANGE && tmp->window == (HWND)mp2) |
1778 { | 1812 { |
1779 result = listboxselectfunc(tmp->window, dw_listbox_selected(tmp->window), tmp->data); | 1813 result = listboxselectfunc(tmp->window, dw_listbox_selected(tmp->window), tmp->data); |
1780 tmp = NULL; | 1814 tmp = NULL; |
1781 } | 1815 } |
1782 } | 1816 } |
1783 else if(!IS_WINNTOR95 && tmp->id && passthru == tmp->id) | 1817 else if (!IS_WINNTOR95 && tmp->id && passthru == tmp->id) |
1784 { | 1818 { |
1785 HMENU hwndmenu = GetMenu(hWnd), menuowner = _menu_owner((HMENU)tmp->window); | 1819 HMENU hwndmenu = GetMenu(hWnd), menuowner = _menu_owner((HMENU)tmp->window); |
1786 | 1820 |
1787 if(menuowner == hwndmenu || !menuowner) | 1821 if (menuowner == hwndmenu || !menuowner) |
1788 { | 1822 { |
1789 result = clickfunc(tmp->window, tmp->data); | 1823 _dw_toggle_checkable_menu_item( tmp->window, tmp->id ); |
1790 tmp = NULL; | 1824 /* |
1791 } | 1825 * Call the user supplied callback |
1792 } /* Make sure it's the right window, and the right ID */ | 1826 */ |
1793 else if(tmp->window < (HWND)65536 && command == tmp->window) | 1827 result = clickfunc(tmp->window, tmp->data); |
1794 { | 1828 tmp = NULL; |
1795 result = clickfunc(popup ? popup : tmp->window, tmp->data); | 1829 } |
1796 tmp = NULL; | 1830 } /* Make sure it's the right window, and the right ID */ |
1797 } | 1831 else if (tmp->window < (HWND)65536 && command == tmp->window) |
1798 } | 1832 { |
1799 break; | 1833 _dw_toggle_checkable_menu_item( popup ? popup : tmp->window, (int)tmp->data ); |
1800 case WM_HSCROLL: | 1834 result = clickfunc(popup ? popup : tmp->window, tmp->data); |
1801 case WM_VSCROLL: | 1835 tmp = NULL; |
1802 { | 1836 } |
1803 char tmpbuf[100]; | 1837 } |
1804 HWND handle = (HWND)mp2; | 1838 break; |
1805 int (*valuechangefunc)(HWND, int, void *) = tmp->signalfunction; | 1839 case WM_HSCROLL: |
1806 | 1840 case WM_VSCROLL: |
1807 GetClassName(handle, tmpbuf, 99); | 1841 { |
1808 | 1842 char tmpbuf[100]; |
1809 if(strnicmp(tmpbuf, TRACKBAR_CLASS, strlen(TRACKBAR_CLASS)+1)==0) | 1843 HWND handle = (HWND)mp2; |
1810 { | 1844 int (*valuechangefunc)(HWND, int, void *) = tmp->signalfunction; |
1811 | 1845 |
1812 if(handle == tmp->window) | 1846 GetClassName(handle, tmpbuf, 99); |
1813 { | 1847 |
1814 int value = (int)SendMessage(handle, TBM_GETPOS, 0, 0); | 1848 if (strnicmp(tmpbuf, TRACKBAR_CLASS, strlen(TRACKBAR_CLASS)+1)==0) |
1815 int max = (int)SendMessage(handle, TBM_GETRANGEMAX, 0, 0); | 1849 { |
1816 ULONG currentstyle = GetWindowLong(handle, GWL_STYLE); | 1850 |
1817 | 1851 if (handle == tmp->window) |
1818 if(currentstyle & TBS_VERT) | 1852 { |
1819 result = valuechangefunc(tmp->window, max - value, tmp->data); | 1853 int value = (int)SendMessage(handle, TBM_GETPOS, 0, 0); |
1820 else | 1854 int max = (int)SendMessage(handle, TBM_GETRANGEMAX, 0, 0); |
1821 result = valuechangefunc(tmp->window, value, tmp->data); | 1855 ULONG currentstyle = GetWindowLong(handle, GWL_STYLE); |
1822 tmp = NULL; | 1856 |
1823 } | 1857 if(currentstyle & TBS_VERT) |
1824 } | 1858 result = valuechangefunc(tmp->window, max - value, tmp->data); |
1825 else if(strnicmp(tmpbuf, SCROLLBARCLASSNAME, strlen(SCROLLBARCLASSNAME)+1)==0) | 1859 else |
1826 { | 1860 result = valuechangefunc(tmp->window, value, tmp->data); |
1827 if(handle == tmp->window) | 1861 tmp = NULL; |
1828 { | 1862 } |
1829 int value = _HandleScroller(handle, (int)HIWORD(mp1), (int)LOWORD(mp1)); | 1863 } |
1830 | 1864 else if(strnicmp(tmpbuf, SCROLLBARCLASSNAME, strlen(SCROLLBARCLASSNAME)+1)==0) |
1831 if(value > -1) | 1865 { |
1832 { | 1866 if(handle == tmp->window) |
1833 dw_scrollbar_set_pos(tmp->window, value); | 1867 { |
1834 result = valuechangefunc(tmp->window, value, tmp->data); | 1868 int value = _HandleScroller(handle, (int)HIWORD(mp1), (int)LOWORD(mp1)); |
1835 } | 1869 |
1836 tmp = NULL; | 1870 if(value > -1) |
1837 msg = 0; | 1871 { |
1838 } | 1872 dw_scrollbar_set_pos(tmp->window, value); |
1839 } | 1873 result = valuechangefunc(tmp->window, value, tmp->data); |
1840 } | 1874 } |
1841 break; | 1875 tmp = NULL; |
1842 } | 1876 msg = 0; |
1843 } | 1877 } |
1844 if(tmp) | 1878 } |
1845 tmp = tmp->next; | 1879 } |
1846 } | 1880 break; |
1847 command_active = 0; | 1881 } |
1848 } | 1882 } |
1849 | 1883 if(tmp) |
1850 /* Now that any handlers are done... do normal processing */ | 1884 tmp = tmp->next; |
1851 switch( msg ) | 1885 } |
1852 { | 1886 command_active = 0; |
1853 case WM_PAINT: | 1887 } |
1854 { | 1888 |
1855 PAINTSTRUCT ps; | 1889 /* Now that any handlers are done... do normal processing */ |
1856 | 1890 switch( msg ) |
1857 BeginPaint(hWnd, &ps); | 1891 { |
1858 EndPaint(hWnd, &ps); | 1892 case WM_PAINT: |
1859 } | 1893 { |
1860 break; | 1894 PAINTSTRUCT ps; |
1861 case WM_SIZE: | 1895 |
1862 { | 1896 BeginPaint(hWnd, &ps); |
1863 static int lastx = -1, lasty = -1; | 1897 EndPaint(hWnd, &ps); |
1864 static HWND lasthwnd = 0; | 1898 } |
1865 | 1899 break; |
1866 if(lastx != LOWORD(mp2) || lasty != HIWORD(mp2) || lasthwnd != hWnd) | 1900 case WM_SIZE: |
1867 { | 1901 { |
1868 Box *mybox = (Box *)GetWindowLongPtr(hWnd, GWLP_USERDATA); | 1902 static int lastx = -1, lasty = -1; |
1869 | 1903 static HWND lasthwnd = 0; |
1870 if(mybox && mybox->count) | 1904 |
1871 { | 1905 if(lastx != LOWORD(mp2) || lasty != HIWORD(mp2) || lasthwnd != hWnd) |
1872 lastx = LOWORD(mp2); | 1906 { |
1873 lasty = HIWORD(mp2); | 1907 Box *mybox = (Box *)GetWindowLongPtr(hWnd, GWLP_USERDATA); |
1874 lasthwnd = hWnd; | 1908 |
1875 | 1909 if(mybox && mybox->count) |
1876 ShowWindow(mybox->items[0].hwnd, SW_HIDE); | 1910 { |
1877 _do_resize(mybox,LOWORD(mp2),HIWORD(mp2)); | 1911 lastx = LOWORD(mp2); |
1878 ShowWindow(mybox->items[0].hwnd, SW_SHOW); | 1912 lasty = HIWORD(mp2); |
1879 return 0; | 1913 lasthwnd = hWnd; |
1880 } | 1914 |
1881 } | 1915 ShowWindow(mybox->items[0].hwnd, SW_HIDE); |
1882 } | 1916 _do_resize(mybox,LOWORD(mp2),HIWORD(mp2)); |
1883 break; | 1917 ShowWindow(mybox->items[0].hwnd, SW_SHOW); |
1884 case WM_CHAR: | 1918 return 0; |
1885 if(LOWORD(mp1) == '\t') | 1919 } |
1886 { | 1920 } |
1887 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) | 1921 } |
1888 _shift_focus_back(hWnd); | 1922 break; |
1889 else | 1923 case WM_CHAR: |
1890 _shift_focus(hWnd); | 1924 if(LOWORD(mp1) == '\t') |
1891 return TRUE; | 1925 { |
1892 } | 1926 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) |
1893 break; | 1927 _shift_focus_back(hWnd); |
1894 case WM_USER: | 1928 else |
1895 windowfunc = (void *)mp1; | 1929 _shift_focus(hWnd); |
1896 | 1930 return TRUE; |
1897 if(windowfunc) | 1931 } |
1898 windowfunc((void *)mp2); | 1932 break; |
1899 break; | 1933 case WM_USER: |
1900 case WM_USER+5: | 1934 windowfunc = (void *)mp1; |
1901 _free_menu_data((HMENU)mp1); | 1935 |
1902 DestroyMenu((HMENU)mp1); | 1936 if(windowfunc) |
1903 break; | 1937 windowfunc((void *)mp2); |
1904 case WM_NOTIFY: | 1938 break; |
1905 { | 1939 case WM_USER+5: |
1906 NMHDR FAR *tem=(NMHDR FAR *)mp2; | 1940 _free_menu_data((HMENU)mp1); |
1907 | 1941 DestroyMenu((HMENU)mp1); |
1908 if(tem->code == TCN_SELCHANGING) | 1942 break; |
1909 { | 1943 case WM_NOTIFY: |
1910 int num=TabCtrl_GetCurSel(tem->hwndFrom); | 1944 { |
1911 NotebookPage **array = (NotebookPage **)dw_window_get_data(tem->hwndFrom, "_dw_array"); | 1945 NMHDR FAR *tem=(NMHDR FAR *)mp2; |
1912 | 1946 |
1913 if(num > -1 && array && array[num]) | 1947 if(tem->code == TCN_SELCHANGING) |
1914 SetParent(array[num]->hwnd, DW_HWND_OBJECT); | 1948 { |
1915 | 1949 int num=TabCtrl_GetCurSel(tem->hwndFrom); |
1916 } | 1950 NotebookPage **array = (NotebookPage **)dw_window_get_data(tem->hwndFrom, "_dw_array"); |
1917 else if(tem->code == TCN_SELCHANGE) | 1951 |
1918 { | 1952 if(num > -1 && array && array[num]) |
1919 int num=TabCtrl_GetCurSel(tem->hwndFrom); | 1953 SetParent(array[num]->hwnd, DW_HWND_OBJECT); |
1920 NotebookPage **array = (NotebookPage **)dw_window_get_data(tem->hwndFrom, "_dw_array"); | 1954 |
1921 | 1955 } |
1922 if(num > -1 && array && array[num]) | 1956 else if(tem->code == TCN_SELCHANGE) |
1923 SetParent(array[num]->hwnd, tem->hwndFrom); | 1957 { |
1924 | 1958 int num=TabCtrl_GetCurSel(tem->hwndFrom); |
1925 _resize_notebook_page(tem->hwndFrom, num); | 1959 NotebookPage **array = (NotebookPage **)dw_window_get_data(tem->hwndFrom, "_dw_array"); |
1926 } | 1960 |
1927 } | 1961 if(num > -1 && array && array[num]) |
1928 break; | 1962 SetParent(array[num]->hwnd, tem->hwndFrom); |
1929 case WM_HSCROLL: | 1963 |
1930 case WM_VSCROLL: | 1964 _resize_notebook_page(tem->hwndFrom, num); |
1931 { | 1965 } |
1932 HWND handle = (HWND)mp2; | 1966 } |
1933 | 1967 break; |
1934 if(dw_window_get_data(handle, "_dw_scrollbar")) | 1968 case WM_HSCROLL: |
1935 { | 1969 case WM_VSCROLL: |
1936 int value = _HandleScroller(handle, (int)HIWORD(mp1), (int)LOWORD(mp1)); | 1970 { |
1937 | 1971 HWND handle = (HWND)mp2; |
1938 if(value > -1) | 1972 |
1939 dw_scrollbar_set_pos(handle, value); | 1973 if(dw_window_get_data(handle, "_dw_scrollbar")) |
1940 } | 1974 { |
1941 } | 1975 int value = _HandleScroller(handle, (int)HIWORD(mp1), (int)LOWORD(mp1)); |
1942 break; | 1976 |
1943 case WM_GETMINMAXINFO: | 1977 if(value > -1) |
1944 { | 1978 dw_scrollbar_set_pos(handle, value); |
1945 MINMAXINFO *info = (MINMAXINFO *)mp2; | 1979 } |
1946 info->ptMinTrackSize.x = 8; | 1980 } |
1947 info->ptMinTrackSize.y = 8; | 1981 break; |
1948 return 0; | 1982 case WM_GETMINMAXINFO: |
1949 } | 1983 { |
1950 break; | 1984 MINMAXINFO *info = (MINMAXINFO *)mp2; |
1951 case WM_DESTROY: | 1985 info->ptMinTrackSize.x = 8; |
1952 { | 1986 info->ptMinTrackSize.y = 8; |
1953 HMENU menu = GetMenu(hWnd); | 1987 return 0; |
1954 | 1988 } |
1955 if(menu) | 1989 break; |
1956 _free_menu_data(menu); | 1990 case WM_DESTROY: |
1957 | 1991 { |
1958 /* Free memory before destroying */ | 1992 HMENU menu = GetMenu(hWnd); |
1959 _free_window_memory(hWnd, 0); | 1993 |
1960 EnumChildWindows(hWnd, _free_window_memory, 0); | 1994 if(menu) |
1961 } | 1995 _free_menu_data(menu); |
1962 break; | 1996 |
1963 case WM_MOUSEMOVE: | 1997 /* Free memory before destroying */ |
1964 { | 1998 _free_window_memory(hWnd, 0); |
1965 HCURSOR cursor; | 1999 EnumChildWindows(hWnd, _free_window_memory, 0); |
1966 | 2000 } |
1967 if((cursor = (HCURSOR)dw_window_get_data(hWnd, "_dw_cursor")) || | 2001 break; |
1968 (cursor = (HCURSOR)dw_window_get_data(_toplevel_window(hWnd), "_dw_cursor"))) | 2002 case WM_MOUSEMOVE: |
1969 { | 2003 { |
1970 SetCursor(cursor); | 2004 HCURSOR cursor; |
1971 } | 2005 |
1972 } | 2006 if((cursor = (HCURSOR)dw_window_get_data(hWnd, "_dw_cursor")) || |
1973 break; | 2007 (cursor = (HCURSOR)dw_window_get_data(_toplevel_window(hWnd), "_dw_cursor"))) |
1974 case WM_CTLCOLORSTATIC: | 2008 { |
1975 case WM_CTLCOLORLISTBOX: | 2009 SetCursor(cursor); |
1976 case WM_CTLCOLORBTN: | 2010 } |
1977 case WM_CTLCOLOREDIT: | 2011 } |
1978 case WM_CTLCOLORMSGBOX: | 2012 break; |
1979 case WM_CTLCOLORSCROLLBAR: | 2013 case WM_CTLCOLORSTATIC: |
1980 case WM_CTLCOLORDLG: | 2014 case WM_CTLCOLORLISTBOX: |
1981 { | 2015 case WM_CTLCOLORBTN: |
1982 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLongPtr((HWND)mp2, GWLP_USERDATA); | 2016 case WM_CTLCOLOREDIT: |
1983 if(thiscinfo && thiscinfo->fore != -1 && thiscinfo->back != -1) | 2017 case WM_CTLCOLORMSGBOX: |
1984 { | 2018 case WM_CTLCOLORSCROLLBAR: |
1985 /* Handle foreground */ | 2019 case WM_CTLCOLORDLG: |
1986 if(thiscinfo->fore > -1 && thiscinfo->fore < 18) | 2020 { |
1987 { | 2021 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLongPtr((HWND)mp2, GWLP_USERDATA); |
1988 if(thiscinfo->fore != DW_CLR_DEFAULT) | 2022 if(thiscinfo && thiscinfo->fore != -1 && thiscinfo->back != -1) |
1989 { | 2023 { |
1990 SetTextColor((HDC)mp1, RGB(_red[thiscinfo->fore], | 2024 /* Handle foreground */ |
1991 _green[thiscinfo->fore], | 2025 if(thiscinfo->fore > -1 && thiscinfo->fore < 18) |
1992 _blue[thiscinfo->fore])); | 2026 { |
1993 } | 2027 if(thiscinfo->fore != DW_CLR_DEFAULT) |
1994 } | 2028 { |
1995 else if((thiscinfo->fore & DW_RGB_COLOR) == DW_RGB_COLOR) | 2029 SetTextColor((HDC)mp1, RGB(_red[thiscinfo->fore], |
1996 { | 2030 _green[thiscinfo->fore], |
1997 SetTextColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->fore), | 2031 _blue[thiscinfo->fore])); |
1998 DW_GREEN_VALUE(thiscinfo->fore), | 2032 } |
1999 DW_BLUE_VALUE(thiscinfo->fore))); | 2033 } |
2000 } | 2034 else if((thiscinfo->fore & DW_RGB_COLOR) == DW_RGB_COLOR) |
2001 /* Handle background */ | 2035 { |
2002 if(thiscinfo->back > -1 && thiscinfo->back < 18) | 2036 SetTextColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->fore), |
2003 { | 2037 DW_GREEN_VALUE(thiscinfo->fore), |
2004 if(thiscinfo->back == DW_CLR_DEFAULT) | 2038 DW_BLUE_VALUE(thiscinfo->fore))); |
2005 { | 2039 } |
2006 HBRUSH hbr = GetSysColorBrush(COLOR_3DFACE); | 2040 /* Handle background */ |
2007 | 2041 if(thiscinfo->back > -1 && thiscinfo->back < 18) |
2008 SelectObject((HDC)mp1, hbr); | 2042 { |
2009 return (LONG)hbr; | 2043 if(thiscinfo->back == DW_CLR_DEFAULT) |
2010 } | 2044 { |
2011 else | 2045 HBRUSH hbr = GetSysColorBrush(COLOR_3DFACE); |
2012 { | 2046 |
2013 SetBkColor((HDC)mp1, RGB(_red[thiscinfo->back], | 2047 SelectObject((HDC)mp1, hbr); |
2014 _green[thiscinfo->back], | 2048 return (LONG)hbr; |
2015 _blue[thiscinfo->back])); | 2049 } |
2016 if(thiscinfo->hbrush) | 2050 else |
2017 DeleteObject(thiscinfo->hbrush); | 2051 { |
2018 thiscinfo->hbrush = CreateSolidBrush(RGB(_red[thiscinfo->back], | 2052 SetBkColor((HDC)mp1, RGB(_red[thiscinfo->back], |
2019 _green[thiscinfo->back], | 2053 _green[thiscinfo->back], |
2020 _blue[thiscinfo->back])); | 2054 _blue[thiscinfo->back])); |
2021 SelectObject((HDC)mp1, thiscinfo->hbrush); | 2055 if(thiscinfo->hbrush) |
2022 } | 2056 DeleteObject(thiscinfo->hbrush); |
2023 return (LONG)thiscinfo->hbrush; | 2057 thiscinfo->hbrush = CreateSolidBrush(RGB(_red[thiscinfo->back], |
2024 } | 2058 _green[thiscinfo->back], |
2025 else if((thiscinfo->back & DW_RGB_COLOR) == DW_RGB_COLOR) | 2059 _blue[thiscinfo->back])); |
2026 { | 2060 SelectObject((HDC)mp1, thiscinfo->hbrush); |
2027 SetBkColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->back), | 2061 } |
2028 DW_GREEN_VALUE(thiscinfo->back), | 2062 return (LONG)thiscinfo->hbrush; |
2029 DW_BLUE_VALUE(thiscinfo->back))); | 2063 } |
2030 if(thiscinfo->hbrush) | 2064 else if((thiscinfo->back & DW_RGB_COLOR) == DW_RGB_COLOR) |
2031 DeleteObject(thiscinfo->hbrush); | 2065 { |
2032 thiscinfo->hbrush = CreateSolidBrush(RGB(DW_RED_VALUE(thiscinfo->back), | 2066 SetBkColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->back), |
2033 DW_GREEN_VALUE(thiscinfo->back), | 2067 DW_GREEN_VALUE(thiscinfo->back), |
2034 DW_BLUE_VALUE(thiscinfo->back))); | 2068 DW_BLUE_VALUE(thiscinfo->back))); |
2035 SelectObject((HDC)mp1, thiscinfo->hbrush); | 2069 if(thiscinfo->hbrush) |
2036 return (LONG)thiscinfo->hbrush; | 2070 DeleteObject(thiscinfo->hbrush); |
2037 } | 2071 thiscinfo->hbrush = CreateSolidBrush(RGB(DW_RED_VALUE(thiscinfo->back), |
2038 } | 2072 DW_GREEN_VALUE(thiscinfo->back), |
2039 | 2073 DW_BLUE_VALUE(thiscinfo->back))); |
2040 } | 2074 SelectObject((HDC)mp1, thiscinfo->hbrush); |
2041 break; | 2075 return (LONG)thiscinfo->hbrush; |
2042 } | 2076 } |
2043 if(result != -1) | 2077 } |
2044 return result; | 2078 |
2045 else | 2079 } |
2046 return DefWindowProc(hWnd, msg, mp1, mp2); | 2080 break; |
2081 } | |
2082 if(result != -1) | |
2083 return result; | |
2084 else | |
2085 return DefWindowProc(hWnd, msg, mp1, mp2); | |
2047 } | 2086 } |
2048 | 2087 |
2049 VOID CALLBACK _TimerProc(HWND hwnd, UINT msg, UINT_PTR idEvent, DWORD dwTime) | 2088 VOID CALLBACK _TimerProc(HWND hwnd, UINT msg, UINT_PTR idEvent, DWORD dwTime) |
2050 { | 2089 { |
2051 _wndproc(hwnd, msg, (WPARAM)idEvent, 0); | 2090 _wndproc(hwnd, msg, (WPARAM)idEvent, 0); |
2052 } | 2091 } |
2053 | 2092 |
2054 BOOL CALLBACK _framewndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) | 2093 BOOL CALLBACK _framewndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) |
2055 { | 2094 { |
2056 switch( msg ) | 2095 switch( msg ) |
2057 { | 2096 { |
2058 case WM_LBUTTONDOWN: | 2097 case WM_LBUTTONDOWN: |
2059 case WM_MBUTTONDOWN: | 2098 case WM_MBUTTONDOWN: |
2060 case WM_RBUTTONDOWN: | 2099 case WM_RBUTTONDOWN: |
2061 SetActiveWindow(hWnd); | 2100 SetActiveWindow(hWnd); |
2062 SetFocus(hWnd); | 2101 SetFocus(hWnd); |
2063 break; | 2102 break; |
2064 case WM_COMMAND: | 2103 case WM_COMMAND: |
2065 case WM_NOTIFY: | 2104 case WM_NOTIFY: |
2066 case WM_MOUSEMOVE: | 2105 case WM_MOUSEMOVE: |
2067 _wndproc(hWnd, msg, mp1, mp2); | 2106 _wndproc(hWnd, msg, mp1, mp2); |
2068 break; | 2107 break; |
2069 #if 0 | 2108 #if 0 |
2070 case WM_ERASEBKGND: | 2109 case WM_ERASEBKGND: |
2071 { | 2110 { |
2072 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); | 2111 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); |
2073 | 2112 |
2074 if(thiscinfo && thiscinfo->fore != -1 && thiscinfo->back != -1) | 2113 if(thiscinfo && thiscinfo->fore != -1 && thiscinfo->back != -1) |
2075 return FALSE; | 2114 return FALSE; |
2076 } | 2115 } |
2077 break; | 2116 break; |
2078 #endif | 2117 #endif |
2079 case WM_PAINT: | 2118 case WM_PAINT: |
2080 { | 2119 { |
2081 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); | 2120 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); |
2082 | 2121 |
2083 if(thiscinfo && thiscinfo->fore != -1 && thiscinfo->back != -1) | 2122 if(thiscinfo && thiscinfo->fore != -1 && thiscinfo->back != -1) |
2084 { | 2123 { |
2085 PAINTSTRUCT ps; | 2124 PAINTSTRUCT ps; |
2086 HDC hdcPaint = BeginPaint(hWnd, &ps); | 2125 HDC hdcPaint = BeginPaint(hWnd, &ps); |
2087 int success = FALSE; | 2126 int success = FALSE; |
2088 | 2127 |
2089 if(thiscinfo && thiscinfo->fore != -1 && thiscinfo->back != -1) | 2128 if(thiscinfo && thiscinfo->fore != -1 && thiscinfo->back != -1) |
2090 { | 2129 { |
2091 /* Handle foreground */ | 2130 /* Handle foreground */ |
2092 if(thiscinfo->fore > -1 && thiscinfo->fore < 18) | 2131 if(thiscinfo->fore > -1 && thiscinfo->fore < 18) |
2093 { | 2132 { |
2094 if(thiscinfo->fore != DW_CLR_DEFAULT) | 2133 if(thiscinfo->fore != DW_CLR_DEFAULT) |
2095 { | 2134 { |
2096 SetTextColor((HDC)mp1, RGB(_red[thiscinfo->fore], | 2135 SetTextColor((HDC)mp1, RGB(_red[thiscinfo->fore], |
2097 _green[thiscinfo->fore], | 2136 _green[thiscinfo->fore], |
2098 _blue[thiscinfo->fore])); | 2137 _blue[thiscinfo->fore])); |
2099 } | 2138 } |
2100 } | 2139 } |
2101 else if((thiscinfo->fore & DW_RGB_COLOR) == DW_RGB_COLOR) | 2140 else if((thiscinfo->fore & DW_RGB_COLOR) == DW_RGB_COLOR) |
2102 { | 2141 { |
2103 SetTextColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->fore), | 2142 SetTextColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->fore), |
2104 DW_GREEN_VALUE(thiscinfo->fore), | 2143 DW_GREEN_VALUE(thiscinfo->fore), |
2105 DW_BLUE_VALUE(thiscinfo->fore))); | 2144 DW_BLUE_VALUE(thiscinfo->fore))); |
2106 } | 2145 } |
2107 /* Handle background */ | 2146 /* Handle background */ |
2108 if(thiscinfo->back > -1 && thiscinfo->back < 18) | 2147 if(thiscinfo->back > -1 && thiscinfo->back < 18) |
2109 { | 2148 { |
2110 if(thiscinfo->back != DW_CLR_DEFAULT) | 2149 if(thiscinfo->back != DW_CLR_DEFAULT) |
2111 { | 2150 { |
2112 SetBkColor((HDC)mp1, RGB(_red[thiscinfo->back], | 2151 SetBkColor((HDC)mp1, RGB(_red[thiscinfo->back], |
2113 _green[thiscinfo->back], | 2152 _green[thiscinfo->back], |
2114 _blue[thiscinfo->back])); | 2153 _blue[thiscinfo->back])); |
2115 if(thiscinfo->hbrush) | 2154 if(thiscinfo->hbrush) |
2116 DeleteObject(thiscinfo->hbrush); | 2155 DeleteObject(thiscinfo->hbrush); |
2117 thiscinfo->hbrush = CreateSolidBrush(RGB(_red[thiscinfo->back], | 2156 thiscinfo->hbrush = CreateSolidBrush(RGB(_red[thiscinfo->back], |
2118 _green[thiscinfo->back], | 2157 _green[thiscinfo->back], |
2119 _blue[thiscinfo->back])); | 2158 _blue[thiscinfo->back])); |
2120 SelectObject(hdcPaint, thiscinfo->hbrush); | 2159 SelectObject(hdcPaint, thiscinfo->hbrush); |
2121 Rectangle(hdcPaint, ps.rcPaint.left - 1, ps.rcPaint.top - 1, ps.rcPaint.right + 1, ps.rcPaint.bottom + 1); | 2160 Rectangle(hdcPaint, ps.rcPaint.left - 1, ps.rcPaint.top - 1, ps.rcPaint.right + 1, ps.rcPaint.bottom + 1); |
2122 success = TRUE; | 2161 success = TRUE; |
2123 } | 2162 } |
2124 } | 2163 } |
2125 else if((thiscinfo->back & DW_RGB_COLOR) == DW_RGB_COLOR) | 2164 else if((thiscinfo->back & DW_RGB_COLOR) == DW_RGB_COLOR) |
2126 { | 2165 { |
2127 SetBkColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->back), | 2166 SetBkColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->back), |
2128 DW_GREEN_VALUE(thiscinfo->back), | 2167 DW_GREEN_VALUE(thiscinfo->back), |
2129 DW_BLUE_VALUE(thiscinfo->back))); | 2168 DW_BLUE_VALUE(thiscinfo->back))); |
2130 if(thiscinfo->hbrush) | 2169 if(thiscinfo->hbrush) |
2131 DeleteObject(thiscinfo->hbrush); | 2170 DeleteObject(thiscinfo->hbrush); |
2132 thiscinfo->hbrush = CreateSolidBrush(RGB(DW_RED_VALUE(thiscinfo->back), | 2171 thiscinfo->hbrush = CreateSolidBrush(RGB(DW_RED_VALUE(thiscinfo->back), |
2133 DW_GREEN_VALUE(thiscinfo->back), | 2172 DW_GREEN_VALUE(thiscinfo->back), |
2134 DW_BLUE_VALUE(thiscinfo->back))); | 2173 DW_BLUE_VALUE(thiscinfo->back))); |
2135 SelectObject(hdcPaint, thiscinfo->hbrush); | 2174 SelectObject(hdcPaint, thiscinfo->hbrush); |
2136 Rectangle(hdcPaint, ps.rcPaint.left - 1, ps.rcPaint.top - 1, ps.rcPaint.right + 1, ps.rcPaint.bottom + 1); | 2175 Rectangle(hdcPaint, ps.rcPaint.left - 1, ps.rcPaint.top - 1, ps.rcPaint.right + 1, ps.rcPaint.bottom + 1); |
2137 success = TRUE; | 2176 success = TRUE; |
2138 } | 2177 } |
2139 } | 2178 } |
2140 | 2179 |
2141 EndPaint(hWnd, &ps); | 2180 EndPaint(hWnd, &ps); |
2142 if(success) | 2181 if(success) |
2143 return FALSE; | 2182 return FALSE; |
2144 } | 2183 } |
2145 | 2184 |
2146 } | 2185 } |
2147 break; | 2186 break; |
2148 } | 2187 } |
2149 return DefWindowProc(hWnd, msg, mp1, mp2); | 2188 return DefWindowProc(hWnd, msg, mp1, mp2); |
2150 } | 2189 } |
2151 | 2190 |
2152 BOOL CALLBACK _rendwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) | 2191 BOOL CALLBACK _rendwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) |
2153 { | 2192 { |
2154 switch( msg ) | 2193 switch( msg ) |
2155 { | 2194 { |
2156 case WM_LBUTTONDOWN: | 2195 case WM_LBUTTONDOWN: |
2157 case WM_MBUTTONDOWN: | 2196 case WM_MBUTTONDOWN: |
2158 case WM_RBUTTONDOWN: | 2197 case WM_RBUTTONDOWN: |
2159 SetFocus(hWnd); | 2198 SetFocus(hWnd); |
2160 _wndproc(hWnd, msg, mp1, mp2); | 2199 _wndproc(hWnd, msg, mp1, mp2); |
2161 break; | 2200 break; |
2162 case WM_LBUTTONUP: | 2201 case WM_LBUTTONUP: |
2163 case WM_MBUTTONUP: | 2202 case WM_MBUTTONUP: |
2164 case WM_RBUTTONUP: | 2203 case WM_RBUTTONUP: |
2165 case WM_MOUSEMOVE: | 2204 case WM_MOUSEMOVE: |
2166 case WM_PAINT: | 2205 case WM_PAINT: |
2167 case WM_SIZE: | 2206 case WM_SIZE: |
2168 case WM_COMMAND: | 2207 case WM_COMMAND: |
2169 case WM_CHAR: | 2208 case WM_CHAR: |
2170 case WM_KEYDOWN: | 2209 case WM_KEYDOWN: |
2171 _wndproc(hWnd, msg, mp1, mp2); | 2210 _wndproc(hWnd, msg, mp1, mp2); |
2172 break; | 2211 break; |
2173 } | 2212 } |
2174 return DefWindowProc(hWnd, msg, mp1, mp2); | 2213 return DefWindowProc(hWnd, msg, mp1, mp2); |
2175 } | 2214 } |
2176 | 2215 |
2177 BOOL CALLBACK _spinnerwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) | 2216 BOOL CALLBACK _spinnerwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) |
2178 { | 2217 { |
2179 ColorInfo *cinfo; | 2218 ColorInfo *cinfo; |
2180 | 2219 |
2181 cinfo = (ColorInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); | 2220 cinfo = (ColorInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); |
2182 | 2221 |
2183 if(msg == WM_MOUSEMOVE) | 2222 if(msg == WM_MOUSEMOVE) |
2184 _wndproc(hWnd, msg, mp1, mp2); | 2223 _wndproc(hWnd, msg, mp1, mp2); |
2185 | 2224 |
2186 if(cinfo) | 2225 if(cinfo) |
2187 { | 2226 { |
2188 switch( msg ) | 2227 switch( msg ) |
2189 { | 2228 { |
2190 case WM_LBUTTONDOWN: | 2229 case WM_LBUTTONDOWN: |
2191 case WM_MBUTTONDOWN: | 2230 case WM_MBUTTONDOWN: |
2192 case WM_RBUTTONDOWN: | 2231 case WM_RBUTTONDOWN: |
2193 case WM_KEYDOWN: | 2232 case WM_KEYDOWN: |
2194 { | 2233 { |
2195 BOOL ret; | 2234 BOOL ret; |
2196 | 2235 |
2197 if(!cinfo || !cinfo->pOldProc) | 2236 if(!cinfo || !cinfo->pOldProc) |
2198 ret = DefWindowProc(hWnd, msg, mp1, mp2); | 2237 ret = DefWindowProc(hWnd, msg, mp1, mp2); |
2199 ret = CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); | 2238 ret = CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); |
2200 | 2239 |
2201 /* Tell the edit control that a buttonpress has | 2240 /* Tell the edit control that a buttonpress has |
2202 * occured and to update it's window title. | 2241 * occured and to update it's window title. |
2203 */ | 2242 */ |
2204 if(cinfo && cinfo->buddy) | 2243 if(cinfo && cinfo->buddy) |
2205 SendMessage(cinfo->buddy, WM_USER+10, 0, 0); | 2244 SendMessage(cinfo->buddy, WM_USER+10, 0, 0); |
2206 | 2245 |
2207 SetTimer(hWnd, 100, 100, (TIMERPROC)NULL); | 2246 SetTimer(hWnd, 100, 100, (TIMERPROC)NULL); |
2208 | 2247 |
2209 return ret; | 2248 return ret; |
2210 } | 2249 } |
2211 break; | 2250 break; |
2212 case WM_LBUTTONUP: | 2251 case WM_LBUTTONUP: |
2213 case WM_MBUTTONUP: | 2252 case WM_MBUTTONUP: |
2214 case WM_RBUTTONUP: | 2253 case WM_RBUTTONUP: |
2215 case WM_KEYUP: | 2254 case WM_KEYUP: |
2216 { | 2255 { |
2217 BOOL ret; | 2256 BOOL ret; |
2218 | 2257 |
2219 if(!cinfo || !cinfo->pOldProc) | 2258 if(!cinfo || !cinfo->pOldProc) |
2220 ret = DefWindowProc(hWnd, msg, mp1, mp2); | 2259 ret = DefWindowProc(hWnd, msg, mp1, mp2); |
2221 ret = CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); | 2260 ret = CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); |
2222 | 2261 |
2223 /* Tell the edit control that a buttonpress has | 2262 /* Tell the edit control that a buttonpress has |
2224 * occured and to update it's window title. | 2263 * occured and to update it's window title. |
2225 */ | 2264 */ |
2226 if(cinfo && cinfo->buddy) | 2265 if(cinfo && cinfo->buddy) |
2227 SendMessage(cinfo->buddy, WM_USER+10, 0, 0); | 2266 SendMessage(cinfo->buddy, WM_USER+10, 0, 0); |
2228 | 2267 |
2229 if(hWnd) | 2268 if(hWnd) |
2230 KillTimer(hWnd, 100); | 2269 KillTimer(hWnd, 100); |
2231 | 2270 |
2232 return ret; | 2271 return ret; |
2233 } | 2272 } |
2234 break; | 2273 break; |
2235 case WM_TIMER: | 2274 case WM_TIMER: |
2236 { | 2275 { |
2237 if(mp1 == 100) | 2276 if(mp1 == 100) |
2238 { | 2277 { |
2239 BOOL ret; | 2278 BOOL ret; |
2240 | 2279 |
2241 if(cinfo && cinfo->buddy) | 2280 if(cinfo && cinfo->buddy) |
2242 SendMessage(cinfo->buddy, WM_USER+10, 0, 0); | 2281 SendMessage(cinfo->buddy, WM_USER+10, 0, 0); |
2243 | 2282 |
2244 if(!cinfo || !cinfo->pOldProc) | 2283 if(!cinfo || !cinfo->pOldProc) |
2245 ret = DefWindowProc(hWnd, msg, mp1, mp2); | 2284 ret = DefWindowProc(hWnd, msg, mp1, mp2); |
2246 ret = CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); | 2285 ret = CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); |
2247 | 2286 |
2248 /* Tell the edit control that a buttonpress has | 2287 /* Tell the edit control that a buttonpress has |
2249 * occured and to update it's window title. | 2288 * occured and to update it's window title. |
2250 */ | 2289 */ |
2251 if(cinfo && cinfo->buddy) | 2290 if(cinfo && cinfo->buddy) |
2252 SendMessage(cinfo->buddy, WM_USER+10, 0, 0); | 2291 SendMessage(cinfo->buddy, WM_USER+10, 0, 0); |
2253 | 2292 |
2254 return ret; | 2293 return ret; |
2255 } | 2294 } |
2256 } | 2295 } |
2257 break; | 2296 break; |
2258 case WM_USER+10: | 2297 case WM_USER+10: |
2259 { | 2298 { |
2260 if(cinfo->buddy) | 2299 if(cinfo->buddy) |
2261 { | 2300 { |
2262 char tempbuf[100] = ""; | 2301 char tempbuf[100] = ""; |
2263 long position; | 2302 long position; |
2264 | 2303 |
2265 GetWindowText(cinfo->buddy, tempbuf, 99); | 2304 GetWindowText(cinfo->buddy, tempbuf, 99); |
2266 | 2305 |
2267 position = atol(tempbuf); | 2306 position = atol(tempbuf); |
2268 | 2307 |
2269 if(IS_IE5PLUS) | 2308 if(IS_IE5PLUS) |
2270 SendMessage(hWnd, UDM_SETPOS32, 0, (LPARAM)position); | 2309 SendMessage(hWnd, UDM_SETPOS32, 0, (LPARAM)position); |
2271 else | 2310 else |
2272 SendMessage(hWnd, UDM_SETPOS, 0, (LPARAM)MAKELONG((short)position, 0)); | 2311 SendMessage(hWnd, UDM_SETPOS, 0, (LPARAM)MAKELONG((short)position, 0)); |
2273 } | 2312 } |
2274 } | 2313 } |
2275 break; | 2314 break; |
2276 } | 2315 } |
2277 } | 2316 } |
2278 | 2317 |
2279 if(!cinfo || !cinfo->pOldProc) | 2318 if(!cinfo || !cinfo->pOldProc) |
2280 return DefWindowProc(hWnd, msg, mp1, mp2); | 2319 return DefWindowProc(hWnd, msg, mp1, mp2); |
2281 return CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); | 2320 return CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); |
2282 } | 2321 } |
2283 | 2322 |
2284 void _click_default(HWND handle) | 2323 void _click_default(HWND handle) |
2285 { | 2324 { |
2286 char tmpbuf[100]; | 2325 char tmpbuf[100]; |
2287 | 2326 |
2288 GetClassName(handle, tmpbuf, 99); | 2327 GetClassName(handle, tmpbuf, 99); |
2289 | 2328 |
2290 /* These are the window classes which can | 2329 /* These are the window classes which can |
2291 * obtain input focus. | 2330 * obtain input focus. |
2292 */ | 2331 */ |
2293 if(strnicmp(tmpbuf, BUTTONCLASSNAME, strlen(BUTTONCLASSNAME))==0) | 2332 if (strnicmp(tmpbuf, BUTTONCLASSNAME, strlen(BUTTONCLASSNAME))==0) |
2294 { | 2333 { |
2295 /* Generate click on default item */ | 2334 /* Generate click on default item */ |
2296 SignalHandler *tmp = Root; | 2335 SignalHandler *tmp = Root; |
2297 | 2336 |
2298 /* Find any callbacks for this function */ | 2337 /* Find any callbacks for this function */ |
2299 while(tmp) | 2338 while (tmp) |
2300 { | 2339 { |
2301 if(tmp->message == WM_COMMAND) | 2340 if (tmp->message == WM_COMMAND) |
2302 { | 2341 { |
2303 int (*clickfunc)(HWND, void *) = tmp->signalfunction; | 2342 int (*clickfunc)(HWND, void *) = tmp->signalfunction; |
2304 | 2343 |
2305 /* Make sure it's the right window, and the right ID */ | 2344 /* Make sure it's the right window, and the right ID */ |
2306 if(tmp->window == handle) | 2345 if (tmp->window == handle) |
2307 { | 2346 { |
2308 clickfunc(tmp->window, tmp->data); | 2347 clickfunc(tmp->window, tmp->data); |
2309 tmp = NULL; | 2348 tmp = NULL; |
2310 } | 2349 } |
2311 } | 2350 } |
2312 if(tmp) | 2351 if (tmp) |
2313 tmp= tmp->next; | 2352 tmp= tmp->next; |
2314 } | 2353 } |
2315 } | 2354 } |
2316 else | 2355 else |
2317 SetFocus(handle); | 2356 SetFocus(handle); |
2318 } | 2357 } |
2319 | 2358 |
2320 BOOL CALLBACK _colorwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) | 2359 BOOL CALLBACK _colorwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) |
2321 { | 2360 { |
2322 ColorInfo *cinfo; | 2361 ColorInfo *cinfo; |
2323 char tmpbuf[100]; | 2362 char tmpbuf[100]; |
2324 WNDPROC pOldProc = 0; | 2363 WNDPROC pOldProc = 0; |
2325 | 2364 |
2326 cinfo = (ColorInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); | 2365 cinfo = (ColorInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); |
2327 | 2366 |
2328 GetClassName(hWnd, tmpbuf, 99); | 2367 GetClassName(hWnd, tmpbuf, 99); |
2329 if(strcmp(tmpbuf, FRAMECLASSNAME) == 0) | 2368 if(strcmp(tmpbuf, FRAMECLASSNAME) == 0) |
2330 cinfo = &(((Box *)cinfo)->cinfo); | 2369 cinfo = &(((Box *)cinfo)->cinfo); |
2331 | 2370 |
2332 if(msg == WM_MOUSEMOVE) | 2371 if(msg == WM_MOUSEMOVE) |
2333 _wndproc(hWnd, msg, mp1, mp2); | 2372 _wndproc(hWnd, msg, mp1, mp2); |
2334 | 2373 |
2335 if(cinfo) | 2374 if (cinfo) |
2336 { | 2375 { |
2337 pOldProc = cinfo->pOldProc; | 2376 pOldProc = cinfo->pOldProc; |
2338 | 2377 |
2339 switch( msg ) | 2378 switch( msg ) |
2340 { | 2379 { |
2341 case WM_SETFOCUS: | 2380 case WM_SETFOCUS: |
2342 if(cinfo->combo) | 2381 if(cinfo->combo) |
2343 _wndproc(cinfo->combo, msg, mp1, mp2); | 2382 _wndproc(cinfo->combo, msg, mp1, mp2); |
2344 else | 2383 else |
2345 _wndproc(hWnd, msg, mp1, mp2); | 2384 _wndproc(hWnd, msg, mp1, mp2); |
2346 break; | 2385 break; |
2347 case WM_VSCROLL: | 2386 case WM_VSCROLL: |
2348 case WM_HSCROLL: | 2387 case WM_HSCROLL: |
2349 _wndproc(hWnd, msg, mp1, mp2); | 2388 _wndproc(hWnd, msg, mp1, mp2); |
2350 break; | 2389 break; |
2351 case WM_KEYDOWN: | 2390 case WM_KEYDOWN: |
2352 case WM_KEYUP: | 2391 case WM_KEYUP: |
2353 { | 2392 { |
2354 if(hWnd && (mp1 == VK_UP || mp1 == VK_DOWN)) | 2393 if (hWnd && (mp1 == VK_UP || mp1 == VK_DOWN)) |
2355 { | 2394 { |
2356 BOOL ret; | 2395 BOOL ret; |
2357 | 2396 |
2358 if(!cinfo || !cinfo->pOldProc) | 2397 if (!cinfo || !cinfo->pOldProc) |
2359 ret = DefWindowProc(hWnd, msg, mp1, mp2); | 2398 ret = DefWindowProc(hWnd, msg, mp1, mp2); |
2360 ret = CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); | 2399 ret = CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); |
2361 | 2400 |
2362 /* Tell the spinner control that a keypress has | 2401 /* Tell the spinner control that a keypress has |
2363 * occured and to update it's internal value. | 2402 * occured and to update it's internal value. |
2364 */ | 2403 */ |
2365 if(cinfo && cinfo->buddy && !cinfo->combo) | 2404 if (cinfo && cinfo->buddy && !cinfo->combo) |
2366 PostMessage(hWnd, WM_USER+10, 0, 0); | 2405 PostMessage(hWnd, WM_USER+10, 0, 0); |
2367 | 2406 |
2368 if(msg == WM_KEYDOWN) | 2407 if(msg == WM_KEYDOWN) |
2369 SetTimer(hWnd, 101, 100, (TIMERPROC)NULL); | 2408 SetTimer(hWnd, 101, 100, (TIMERPROC)NULL); |
2370 else | 2409 else |
2371 KillTimer(hWnd, 101); | 2410 KillTimer(hWnd, 101); |
2372 | 2411 |
2373 return ret; | 2412 return ret; |
2374 } | 2413 } |
2375 } | 2414 } |
2376 break; | 2415 break; |
2377 case WM_TIMER: | 2416 case WM_TIMER: |
2378 { | 2417 { |
2379 if(mp1 == 101) | 2418 if(mp1 == 101) |
2380 { | 2419 { |
2381 BOOL ret; | 2420 BOOL ret; |
2382 | 2421 |
2383 if(!cinfo || !cinfo->pOldProc) | 2422 if(!cinfo || !cinfo->pOldProc) |
2384 ret = DefWindowProc(hWnd, msg, mp1, mp2); | 2423 ret = DefWindowProc(hWnd, msg, mp1, mp2); |
2385 ret = CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); | 2424 ret = CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); |
2386 | 2425 |
2387 /* Tell the spinner control that a keypress has | 2426 /* Tell the spinner control that a keypress has |
2388 * occured and to update it's internal value. | 2427 * occured and to update it's internal value. |
2389 */ | 2428 */ |
2390 if(cinfo && cinfo->buddy && !cinfo->combo) | 2429 if(cinfo && cinfo->buddy && !cinfo->combo) |
2391 PostMessage(hWnd, WM_USER+10, 0, 0); | 2430 PostMessage(hWnd, WM_USER+10, 0, 0); |
2392 | 2431 |
2393 return ret; | 2432 return ret; |
2394 } | 2433 } |
2395 } | 2434 } |
2396 break; | 2435 break; |
2397 case WM_CHAR: | 2436 case WM_CHAR: |
2398 _wndproc(hWnd, msg, mp1, mp2); | 2437 _wndproc(hWnd, msg, mp1, mp2); |
2399 if(LOWORD(mp1) == '\t') | 2438 if (LOWORD(mp1) == '\t') |
2400 { | 2439 { |
2401 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) | 2440 if (GetAsyncKeyState(VK_SHIFT) & 0x8000) |
2402 { | 2441 { |
2403 if(cinfo->combo) | 2442 if (cinfo->combo) |
2404 _shift_focus_back(cinfo->combo); | 2443 _shift_focus_back(cinfo->combo); |
2405 else if(cinfo->buddy) | 2444 else if(cinfo->buddy) |
2406 _shift_focus_back(cinfo->buddy); | 2445 _shift_focus_back(cinfo->buddy); |
2407 else | 2446 else |
2408 _shift_focus_back(hWnd); | 2447 _shift_focus_back(hWnd); |
2409 } | 2448 } |
2410 else | 2449 else |
2411 { | 2450 { |
2412 if(cinfo->combo) | 2451 if (cinfo->combo) |
2413 _shift_focus(cinfo->combo); | 2452 _shift_focus(cinfo->combo); |
2414 else if(cinfo->buddy) | 2453 else if(cinfo->buddy) |
2415 _shift_focus(cinfo->buddy); | 2454 _shift_focus(cinfo->buddy); |
2416 else | 2455 else |
2417 _shift_focus(hWnd); | 2456 _shift_focus(hWnd); |
2418 } | 2457 } |
2419 return FALSE; | 2458 return FALSE; |
2420 } | 2459 } |
2421 else if(LOWORD(mp1) == '\r') | 2460 else if(LOWORD(mp1) == '\r') |
2422 { | 2461 { |
2423 if(cinfo->clickdefault) | 2462 if (cinfo->clickdefault) |
2424 _click_default(cinfo->clickdefault); | 2463 { |
2425 | 2464 _click_default(cinfo->clickdefault); |
2426 } | 2465 } |
2427 | 2466 } |
2428 /* Tell the spinner control that a keypress has | 2467 |
2429 * occured and to update it's internal value. | 2468 /* Tell the spinner control that a keypress has |
2430 */ | 2469 * occured and to update it's internal value. |
2431 if(cinfo->buddy && !cinfo->combo) | 2470 */ |
2432 { | 2471 if (cinfo->buddy && !cinfo->combo) |
2433 if(IsWinNT()) | 2472 { |
2434 PostMessage(cinfo->buddy, WM_USER+10, 0, 0); | 2473 if (IsWinNT()) |
2435 else | 2474 PostMessage(cinfo->buddy, WM_USER+10, 0, 0); |
2436 SendMessage(cinfo->buddy, WM_USER+10, 0, 0); | 2475 else |
2437 } | 2476 SendMessage(cinfo->buddy, WM_USER+10, 0, 0); |
2438 break; | 2477 } |
2439 case WM_USER+10: | 2478 break; |
2440 { | 2479 case WM_USER+10: |
2441 if(cinfo->buddy) | 2480 { |
2442 { | 2481 if(cinfo->buddy) |
2443 long val; | 2482 { |
2444 | 2483 long val; |
2445 if(IS_IE5PLUS) | 2484 |
2446 val = (long)SendMessage(cinfo->buddy, UDM_GETPOS32, 0, 0); | 2485 if(IS_IE5PLUS) |
2447 else | 2486 val = (long)SendMessage(cinfo->buddy, UDM_GETPOS32, 0, 0); |
2448 val = (long)SendMessage(cinfo->buddy, UDM_GETPOS, 0, 0); | 2487 else |
2449 | 2488 val = (long)SendMessage(cinfo->buddy, UDM_GETPOS, 0, 0); |
2450 sprintf(tmpbuf, "%ld", val); | 2489 |
2451 SetWindowText(hWnd, tmpbuf); | 2490 sprintf(tmpbuf, "%ld", val); |
2452 } | 2491 SetWindowText(hWnd, tmpbuf); |
2453 } | 2492 } |
2454 break; | 2493 } |
2455 case WM_CTLCOLORSTATIC: | 2494 break; |
2456 case WM_CTLCOLORLISTBOX: | 2495 case WM_CTLCOLORSTATIC: |
2457 case WM_CTLCOLORBTN: | 2496 case WM_CTLCOLORLISTBOX: |
2458 case WM_CTLCOLOREDIT: | 2497 case WM_CTLCOLORBTN: |
2459 case WM_CTLCOLORMSGBOX: | 2498 case WM_CTLCOLOREDIT: |
2460 case WM_CTLCOLORSCROLLBAR: | 2499 case WM_CTLCOLORMSGBOX: |
2461 case WM_CTLCOLORDLG: | 2500 case WM_CTLCOLORSCROLLBAR: |
2462 { | 2501 case WM_CTLCOLORDLG: |
2463 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLongPtr((HWND)mp2, GWLP_USERDATA); | 2502 { |
2464 if(thiscinfo && thiscinfo->fore != -1 && thiscinfo->back != -1) | 2503 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLongPtr((HWND)mp2, GWLP_USERDATA); |
2465 { | 2504 if(thiscinfo && thiscinfo->fore != -1 && thiscinfo->back != -1) |
2466 /* Handle foreground */ | 2505 { |
2467 if(thiscinfo->fore > -1 && thiscinfo->fore < 18) | 2506 /* Handle foreground */ |
2468 { | 2507 if(thiscinfo->fore > -1 && thiscinfo->fore < 18) |
2469 if(thiscinfo->fore != DW_CLR_DEFAULT) | 2508 { |
2470 { | 2509 if(thiscinfo->fore != DW_CLR_DEFAULT) |
2471 SetTextColor((HDC)mp1, RGB(_red[thiscinfo->fore], | 2510 { |
2472 _green[thiscinfo->fore], | 2511 SetTextColor((HDC)mp1, RGB(_red[thiscinfo->fore], |
2473 _blue[thiscinfo->fore])); | 2512 _green[thiscinfo->fore], |
2474 } | 2513 _blue[thiscinfo->fore])); |
2475 } | 2514 } |
2476 else if((thiscinfo->fore & DW_RGB_COLOR) == DW_RGB_COLOR) | 2515 } |
2477 { | 2516 else if((thiscinfo->fore & DW_RGB_COLOR) == DW_RGB_COLOR) |
2478 SetTextColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->fore), | 2517 { |
2479 DW_GREEN_VALUE(thiscinfo->fore), | 2518 SetTextColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->fore), |
2480 DW_BLUE_VALUE(thiscinfo->fore))); | 2519 DW_GREEN_VALUE(thiscinfo->fore), |
2481 } | 2520 DW_BLUE_VALUE(thiscinfo->fore))); |
2482 /* Handle background */ | 2521 } |
2483 if(thiscinfo->back > -1 && thiscinfo->back < 18) | 2522 /* Handle background */ |
2484 { | 2523 if(thiscinfo->back > -1 && thiscinfo->back < 18) |
2485 if(thiscinfo->back == DW_CLR_DEFAULT) | 2524 { |
2486 { | 2525 if(thiscinfo->back == DW_CLR_DEFAULT) |
2487 HBRUSH hbr = GetSysColorBrush(COLOR_3DFACE); | 2526 { |
2488 | 2527 HBRUSH hbr = GetSysColorBrush(COLOR_3DFACE); |
2489 SetBkColor((HDC)mp1, GetSysColor(COLOR_3DFACE)); | 2528 |
2490 | 2529 SetBkColor((HDC)mp1, GetSysColor(COLOR_3DFACE)); |
2491 | 2530 |
2492 SelectObject((HDC)mp1, hbr); | 2531 |
2493 return (LONG)hbr; | 2532 SelectObject((HDC)mp1, hbr); |
2494 } | 2533 return (LONG)hbr; |
2495 else | 2534 } |
2496 { | 2535 else |
2497 SetBkColor((HDC)mp1, RGB(_red[thiscinfo->back], | 2536 { |
2498 _green[thiscinfo->back], | 2537 SetBkColor((HDC)mp1, RGB(_red[thiscinfo->back], |
2499 _blue[thiscinfo->back])); | 2538 _green[thiscinfo->back], |
2500 if(thiscinfo->hbrush) | 2539 _blue[thiscinfo->back])); |
2501 DeleteObject(thiscinfo->hbrush); | 2540 if(thiscinfo->hbrush) |
2502 thiscinfo->hbrush = CreateSolidBrush(RGB(_red[thiscinfo->back], | 2541 DeleteObject(thiscinfo->hbrush); |
2503 _green[thiscinfo->back], | 2542 thiscinfo->hbrush = CreateSolidBrush(RGB(_red[thiscinfo->back], |
2504 _blue[thiscinfo->back])); | 2543 _green[thiscinfo->back], |
2505 SelectObject((HDC)mp1, thiscinfo->hbrush); | 2544 _blue[thiscinfo->back])); |
2506 } | 2545 SelectObject((HDC)mp1, thiscinfo->hbrush); |
2507 return (LONG)thiscinfo->hbrush; | 2546 } |
2508 } | 2547 return (LONG)thiscinfo->hbrush; |
2509 else if((thiscinfo->back & DW_RGB_COLOR) == DW_RGB_COLOR) | 2548 } |
2510 { | 2549 else if((thiscinfo->back & DW_RGB_COLOR) == DW_RGB_COLOR) |
2511 SetBkColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->back), | 2550 { |
2512 DW_GREEN_VALUE(thiscinfo->back), | 2551 SetBkColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->back), |
2513 DW_BLUE_VALUE(thiscinfo->back))); | 2552 DW_GREEN_VALUE(thiscinfo->back), |
2514 if(thiscinfo->hbrush) | 2553 DW_BLUE_VALUE(thiscinfo->back))); |
2515 DeleteObject(thiscinfo->hbrush); | 2554 if(thiscinfo->hbrush) |
2516 thiscinfo->hbrush = CreateSolidBrush(RGB(DW_RED_VALUE(thiscinfo->back), | 2555 DeleteObject(thiscinfo->hbrush); |
2517 DW_GREEN_VALUE(thiscinfo->back), | 2556 thiscinfo->hbrush = CreateSolidBrush(RGB(DW_RED_VALUE(thiscinfo->back), |
2518 DW_BLUE_VALUE(thiscinfo->back))); | 2557 DW_GREEN_VALUE(thiscinfo->back), |
2519 SelectObject((HDC)mp1, thiscinfo->hbrush); | 2558 DW_BLUE_VALUE(thiscinfo->back))); |
2520 return (LONG)thiscinfo->hbrush; | 2559 SelectObject((HDC)mp1, thiscinfo->hbrush); |
2521 } | 2560 return (LONG)thiscinfo->hbrush; |
2522 } | 2561 } |
2523 | 2562 } |
2524 } | 2563 |
2525 break; | 2564 } |
2526 } | 2565 break; |
2527 } | 2566 } |
2528 | 2567 } |
2529 if(!pOldProc) | 2568 |
2530 return DefWindowProc(hWnd, msg, mp1, mp2); | 2569 if(!pOldProc) |
2531 return CallWindowProc(pOldProc, hWnd, msg, mp1, mp2); | 2570 return DefWindowProc(hWnd, msg, mp1, mp2); |
2571 return CallWindowProc(pOldProc, hWnd, msg, mp1, mp2); | |
2532 } | 2572 } |
2533 | 2573 |
2534 BOOL CALLBACK _containerwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) | 2574 BOOL CALLBACK _containerwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) |
2535 { | 2575 { |
2536 ContainerInfo *cinfo; | 2576 ContainerInfo *cinfo; |
2537 | 2577 |
2538 cinfo = (ContainerInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); | 2578 cinfo = (ContainerInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); |
2539 | 2579 |
2540 switch( msg ) | 2580 switch( msg ) |
2541 { | 2581 { |
2542 case WM_COMMAND: | 2582 case WM_COMMAND: |
2543 case WM_NOTIFY: | 2583 case WM_NOTIFY: |
2544 case WM_MOUSEMOVE: | 2584 case WM_MOUSEMOVE: |
2545 _wndproc(hWnd, msg, mp1, mp2); | 2585 _wndproc(hWnd, msg, mp1, mp2); |
2546 break; | 2586 break; |
2547 case WM_LBUTTONDBLCLK: | 2587 case WM_LBUTTONDBLCLK: |
2548 case WM_CHAR: | 2588 case WM_CHAR: |
2549 { | 2589 { |
2550 LV_ITEM lvi; | 2590 LV_ITEM lvi; |
2551 int iItem; | 2591 int iItem; |
2552 | 2592 |
2553 if(LOWORD(mp1) == '\t') | 2593 if(LOWORD(mp1) == '\t') |
2554 { | 2594 { |
2555 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) | 2595 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) |
2556 _shift_focus_back(hWnd); | 2596 _shift_focus_back(hWnd); |
2557 else | 2597 else |
2558 _shift_focus(hWnd); | 2598 _shift_focus(hWnd); |
2559 return FALSE; | 2599 return FALSE; |
2560 } | 2600 } |
2561 | 2601 |
2562 if(msg == WM_CHAR && (char)mp1 != '\r') | 2602 if(msg == WM_CHAR && (char)mp1 != '\r') |
2563 break; | 2603 break; |
2564 | 2604 |
2565 iItem = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED); | 2605 iItem = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED); |
2566 | 2606 |
2567 memset(&lvi, 0, sizeof(LV_ITEM)); | 2607 memset(&lvi, 0, sizeof(LV_ITEM)); |
2568 | 2608 |
2569 if(iItem > -1) | 2609 if(iItem > -1) |
2570 { | 2610 { |
2571 lvi.iItem = iItem; | 2611 lvi.iItem = iItem; |
2572 lvi.mask = LVIF_PARAM; | 2612 lvi.mask = LVIF_PARAM; |
2573 | 2613 |
2574 ListView_GetItem(hWnd, &lvi); | 2614 ListView_GetItem(hWnd, &lvi); |
2575 } | 2615 } |
2576 | 2616 |
2577 { | 2617 { |
2578 SignalHandler *tmp = Root; | 2618 SignalHandler *tmp = Root; |
2579 | 2619 |
2580 while(tmp) | 2620 while(tmp) |
2581 { | 2621 { |
2582 if(tmp->message == NM_DBLCLK && tmp->window == hWnd) | 2622 if(tmp->message == NM_DBLCLK && tmp->window == hWnd) |
2583 { | 2623 { |
2584 int (*containerselectfunc)(HWND, char *, void *) = tmp->signalfunction; | 2624 int (*containerselectfunc)(HWND, char *, void *) = tmp->signalfunction; |
2585 | 2625 |
2586 /* Seems to be having lParam as 1 which really sucks */ | 2626 /* Seems to be having lParam as 1 which really sucks */ |
2587 if(lvi.lParam < 100) | 2627 if(lvi.lParam < 100) |
2588 lvi.lParam = 0; | 2628 lvi.lParam = 0; |
2589 | 2629 |
2590 containerselectfunc(tmp->window, (char *)lvi.lParam, tmp->data); | 2630 containerselectfunc(tmp->window, (char *)lvi.lParam, tmp->data); |
2591 tmp = NULL; | 2631 tmp = NULL; |
2592 } | 2632 } |
2593 if(tmp) | 2633 if(tmp) |
2594 tmp = tmp->next; | 2634 tmp = tmp->next; |
2595 } | 2635 } |
2596 } | 2636 } |
2597 } | 2637 } |
2598 break; | 2638 break; |
2599 case WM_CONTEXTMENU: | 2639 case WM_CONTEXTMENU: |
2600 { | 2640 { |
2601 SignalHandler *tmp = Root; | 2641 SignalHandler *tmp = Root; |
2602 | 2642 |
2603 while(tmp) | 2643 while(tmp) |
2604 { | 2644 { |
2605 if(tmp->message == NM_RCLICK && tmp->window == hWnd) | 2645 if(tmp->message == NM_RCLICK && tmp->window == hWnd) |
2606 { | 2646 { |
2607 int (*containercontextfunc)(HWND, char *, int, int, void *, void *) = tmp->signalfunction; | 2647 int (*containercontextfunc)(HWND, char *, int, int, void *, void *) = tmp->signalfunction; |
2608 LONG x,y; | 2648 LONG x,y; |
2609 LV_ITEM lvi; | 2649 LV_ITEM lvi; |
2610 int iItem; | 2650 int iItem; |
2611 LVHITTESTINFO lhi; | 2651 LVHITTESTINFO lhi; |
2612 | 2652 |
2613 dw_pointer_query_pos(&x, &y); | 2653 dw_pointer_query_pos(&x, &y); |
2614 | 2654 |
2615 lhi.pt.x = x; | 2655 lhi.pt.x = x; |
2616 lhi.pt.y = y; | 2656 lhi.pt.y = y; |
2617 | 2657 |
2618 MapWindowPoints(HWND_DESKTOP, tmp->window, &lhi.pt, 1); | 2658 MapWindowPoints(HWND_DESKTOP, tmp->window, &lhi.pt, 1); |
2619 | 2659 |
2620 iItem = ListView_HitTest(tmp->window, &lhi); | 2660 iItem = ListView_HitTest(tmp->window, &lhi); |
2621 | 2661 |
2622 memset(&lvi, 0, sizeof(LV_ITEM)); | 2662 memset(&lvi, 0, sizeof(LV_ITEM)); |
2623 | 2663 |
2624 if(iItem > -1) | 2664 if(iItem > -1) |
2625 { | 2665 { |
2626 lvi.iItem = iItem; | 2666 lvi.iItem = iItem; |
2627 lvi.mask = LVIF_PARAM; | 2667 lvi.mask = LVIF_PARAM; |
2628 | 2668 |
2629 ListView_GetItem(tmp->window, &lvi); | 2669 ListView_GetItem(tmp->window, &lvi); |
2630 ListView_SetSelectionMark(tmp->window, iItem); | 2670 ListView_SetSelectionMark(tmp->window, iItem); |
2631 } | 2671 } |
2632 | 2672 |
2633 /* Seems to be having lParam as 1 which really sucks */ | 2673 /* Seems to be having lParam as 1 which really sucks */ |
2634 if(lvi.lParam < 100) | 2674 if(lvi.lParam < 100) |
2635 lvi.lParam = 0; | 2675 lvi.lParam = 0; |
2636 | 2676 |
2637 containercontextfunc(tmp->window, (char *)lvi.lParam, x, y, tmp->data, NULL); | 2677 containercontextfunc(tmp->window, (char *)lvi.lParam, x, y, tmp->data, NULL); |
2638 tmp = NULL; | 2678 tmp = NULL; |
2639 } | 2679 } |
2640 if(tmp) | 2680 if(tmp) |
2641 tmp = tmp->next; | 2681 tmp = tmp->next; |
2642 } | 2682 } |
2643 } | 2683 } |
2644 break; | 2684 break; |
2645 } | 2685 } |
2646 | 2686 |
2647 if(!cinfo || !cinfo->pOldProc) | 2687 if(!cinfo || !cinfo->pOldProc) |
2648 return DefWindowProc(hWnd, msg, mp1, mp2); | 2688 return DefWindowProc(hWnd, msg, mp1, mp2); |
2649 return CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); | 2689 return CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); |
2650 } | 2690 } |
2651 | 2691 |
2652 BOOL CALLBACK _treewndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) | 2692 BOOL CALLBACK _treewndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) |
2653 { | 2693 { |
2654 ContainerInfo *cinfo; | 2694 ContainerInfo *cinfo; |
2655 | 2695 |
2656 cinfo = (ContainerInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); | 2696 cinfo = (ContainerInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); |
2657 | 2697 |
2658 switch( msg ) | 2698 switch( msg ) |
2659 { | 2699 { |
2660 case WM_MOUSEMOVE: | 2700 case WM_MOUSEMOVE: |
2661 _wndproc(hWnd, msg, mp1, mp2); | 2701 _wndproc(hWnd, msg, mp1, mp2); |
2662 break; | 2702 break; |
2663 case WM_CHAR: | 2703 case WM_CHAR: |
2664 if(LOWORD(mp1) == '\t') | 2704 if(LOWORD(mp1) == '\t') |
2665 { | 2705 { |
2666 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) | 2706 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) |
2667 _shift_focus_back(hWnd); | 2707 _shift_focus_back(hWnd); |
2668 else | 2708 else |
2669 _shift_focus(hWnd); | 2709 _shift_focus(hWnd); |
2670 return FALSE; | 2710 return FALSE; |
2671 } | 2711 } |
2672 break; | 2712 break; |
2673 } | 2713 } |
2674 | 2714 |
2675 if(!cinfo || !cinfo->pOldProc) | 2715 if(!cinfo || !cinfo->pOldProc) |
2676 return DefWindowProc(hWnd, msg, mp1, mp2); | 2716 return DefWindowProc(hWnd, msg, mp1, mp2); |
2677 return CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); | 2717 return CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); |
2678 } | 2718 } |
2679 | 2719 |
2680 void _changebox(Box *thisbox, int percent, int type) | 2720 void _changebox(Box *thisbox, int percent, int type) |
2681 { | 2721 { |
2682 int z; | 2722 int z; |
2683 | 2723 |
2684 for(z=0;z<thisbox->count;z++) | 2724 for(z=0;z<thisbox->count;z++) |
2685 { | 2725 { |
2686 if(thisbox->items[z].type == TYPEBOX) | 2726 if(thisbox->items[z].type == TYPEBOX) |
2687 { | 2727 { |
2688 Box *tmp = (Box*)GetWindowLongPtr(thisbox->items[z].hwnd, GWLP_USERDATA); | 2728 Box *tmp = (Box*)GetWindowLongPtr(thisbox->items[z].hwnd, GWLP_USERDATA); |
2689 _changebox(tmp, percent, type); | 2729 _changebox(tmp, percent, type); |
2690 } | 2730 } |
2691 else | 2731 else |
2692 { | 2732 { |
2693 if(type == DW_HORZ) | 2733 if(type == DW_HORZ) |
2694 { | 2734 { |
2695 if(thisbox->items[z].hsize == SIZEEXPAND) | 2735 if(thisbox->items[z].hsize == SIZEEXPAND) |
2696 thisbox->items[z].width = (int)(((float)thisbox->items[z].origwidth) * (((float)percent)/((float)100.0))); | 2736 thisbox->items[z].width = (int)(((float)thisbox->items[z].origwidth) * (((float)percent)/((float)100.0))); |
2697 } | 2737 } |
2698 else | 2738 else |
2699 { | 2739 { |
2700 if(thisbox->items[z].vsize == SIZEEXPAND) | 2740 if(thisbox->items[z].vsize == SIZEEXPAND) |
2701 thisbox->items[z].height = (int)(((float)thisbox->items[z].origheight) * (((float)percent)/((float)100.0))); | 2741 thisbox->items[z].height = (int)(((float)thisbox->items[z].origheight) * (((float)percent)/((float)100.0))); |
2702 } | 2742 } |
2703 } | 2743 } |
2704 } | 2744 } |
2705 } | 2745 } |
2706 | 2746 |
2707 void _handle_splitbar_resize(HWND hwnd, float percent, int type, int x, int y) | 2747 void _handle_splitbar_resize(HWND hwnd, float percent, int type, int x, int y) |
2708 { | 2748 { |
2709 HWND handle1, handle2; | 2749 HWND handle1, handle2; |
2710 Box *tmp; | 2750 Box *tmp; |
2711 | 2751 |
2712 if(type == DW_HORZ) | 2752 if(type == DW_HORZ) |
2713 { | 2753 { |
2714 int newx = x; | 2754 int newx = x; |
2715 float ratio = (float)percent/(float)100.0; | 2755 float ratio = (float)percent/(float)100.0; |
2716 | 2756 |
2717 handle1 = (HWND)dw_window_get_data(hwnd, "_dw_topleft"); | 2757 handle1 = (HWND)dw_window_get_data(hwnd, "_dw_topleft"); |
2718 handle2 = (HWND)dw_window_get_data(hwnd, "_dw_bottomright"); | 2758 handle2 = (HWND)dw_window_get_data(hwnd, "_dw_bottomright"); |
2719 tmp = (Box *)GetWindowLongPtr(handle1, GWLP_USERDATA); | 2759 tmp = (Box *)GetWindowLongPtr(handle1, GWLP_USERDATA); |
2720 | 2760 |
2721 newx = (int)((float)newx * ratio) - (SPLITBAR_WIDTH/2); | 2761 newx = (int)((float)newx * ratio) - (SPLITBAR_WIDTH/2); |
2722 | 2762 |
2723 ShowWindow(handle1, SW_HIDE); | 2763 ShowWindow(handle1, SW_HIDE); |
2724 ShowWindow(handle2, SW_HIDE); | 2764 ShowWindow(handle2, SW_HIDE); |
2725 | 2765 |
2726 MoveWindow(handle1, 0, 0, newx, y, FALSE); | 2766 MoveWindow(handle1, 0, 0, newx, y, FALSE); |
2727 _do_resize(tmp, newx - 1, y - 1); | 2767 _do_resize(tmp, newx - 1, y - 1); |
2728 | 2768 |
2729 tmp = (Box *)GetWindowLongPtr(handle2, GWLP_USERDATA); | 2769 tmp = (Box *)GetWindowLongPtr(handle2, GWLP_USERDATA); |
2730 | 2770 |
2731 newx = x - newx - SPLITBAR_WIDTH; | 2771 newx = x - newx - SPLITBAR_WIDTH; |
2732 | 2772 |
2733 MoveWindow(handle2, x - newx, 0, newx, y, FALSE); | 2773 MoveWindow(handle2, x - newx, 0, newx, y, FALSE); |
2734 _do_resize(tmp, newx - 1, y - 1); | 2774 _do_resize(tmp, newx - 1, y - 1); |
2735 | 2775 |
2736 dw_window_set_data(hwnd, "_dw_start", (void *)newx); | 2776 dw_window_set_data(hwnd, "_dw_start", (void *)newx); |
2737 } | 2777 } |
2738 else | 2778 else |
2739 { | 2779 { |
2740 int newy = y; | 2780 int newy = y; |
2741 float ratio = (float)(100.0-percent)/(float)100.0; | 2781 float ratio = (float)(100.0-percent)/(float)100.0; |
2742 | 2782 |
2743 handle1 = (HWND)dw_window_get_data(hwnd, "_dw_bottomright"); | 2783 handle1 = (HWND)dw_window_get_data(hwnd, "_dw_bottomright"); |
2744 handle2 = (HWND)dw_window_get_data(hwnd, "_dw_topleft"); | 2784 handle2 = (HWND)dw_window_get_data(hwnd, "_dw_topleft"); |
2745 tmp = (Box *)GetWindowLongPtr(handle1, GWLP_USERDATA); | 2785 tmp = (Box *)GetWindowLongPtr(handle1, GWLP_USERDATA); |
2746 | 2786 |
2747 newy = (int)((float)newy * ratio) - (SPLITBAR_WIDTH/2); | 2787 newy = (int)((float)newy * ratio) - (SPLITBAR_WIDTH/2); |
2748 | 2788 |
2749 ShowWindow(handle1, SW_HIDE); | 2789 ShowWindow(handle1, SW_HIDE); |
2750 ShowWindow(handle2, SW_HIDE); | 2790 ShowWindow(handle2, SW_HIDE); |
2751 | 2791 |
2752 MoveWindow(handle1, 0, y - newy, x, newy, FALSE); | 2792 MoveWindow(handle1, 0, y - newy, x, newy, FALSE); |
2753 _do_resize(tmp, x - 1, newy - 1); | 2793 _do_resize(tmp, x - 1, newy - 1); |
2754 | 2794 |
2755 tmp = (Box *)GetWindowLongPtr(handle2, GWLP_USERDATA); | 2795 tmp = (Box *)GetWindowLongPtr(handle2, GWLP_USERDATA); |
2756 | 2796 |
2757 newy = y - newy - SPLITBAR_WIDTH; | 2797 newy = y - newy - SPLITBAR_WIDTH; |
2758 | 2798 |
2759 MoveWindow(handle2, 0, 0, x, newy, FALSE); | 2799 MoveWindow(handle2, 0, 0, x, newy, FALSE); |
2760 _do_resize(tmp, x - 1, newy - 1); | 2800 _do_resize(tmp, x - 1, newy - 1); |
2761 | 2801 |
2762 dw_window_set_data(hwnd, "_dw_start", (void *)newy); | 2802 dw_window_set_data(hwnd, "_dw_start", (void *)newy); |
2763 } | 2803 } |
2764 | 2804 |
2765 ShowWindow(handle1, SW_SHOW); | 2805 ShowWindow(handle1, SW_SHOW); |
2766 ShowWindow(handle2, SW_SHOW); | 2806 ShowWindow(handle2, SW_SHOW); |
2767 } | 2807 } |
2768 | 2808 |
2769 /* This handles any activity on the splitbars (sizers) */ | 2809 /* This handles any activity on the splitbars (sizers) */ |
2770 BOOL CALLBACK _splitwndproc(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2) | 2810 BOOL CALLBACK _splitwndproc(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2) |
2771 { | 2811 { |
2772 switch (msg) | 2812 switch (msg) |
2773 { | 2813 { |
2774 case WM_ACTIVATE: | 2814 case WM_ACTIVATE: |
2775 case WM_SETFOCUS: | 2815 case WM_SETFOCUS: |
2776 return FALSE; | 2816 return FALSE; |
2777 | 2817 |
2778 case WM_PAINT: | 2818 case WM_PAINT: |
2779 { | 2819 { |
2780 PAINTSTRUCT ps; | 2820 PAINTSTRUCT ps; |
2781 HDC hdcPaint; | 2821 HDC hdcPaint; |
2782 int type = (int)dw_window_get_data(hwnd, "_dw_type"); | 2822 int type = (int)dw_window_get_data(hwnd, "_dw_type"); |
2783 int start = (int)dw_window_get_data(hwnd, "_dw_start"); | 2823 int start = (int)dw_window_get_data(hwnd, "_dw_start"); |
2784 | 2824 |
2785 BeginPaint(hwnd, &ps); | 2825 BeginPaint(hwnd, &ps); |
2786 | 2826 |
2787 if((hdcPaint = GetDC(hwnd)) != NULL) | 2827 if((hdcPaint = GetDC(hwnd)) != NULL) |
2788 { | 2828 { |
2789 unsigned long cx, cy; | 2829 unsigned long cx, cy; |
2790 HBRUSH oldBrush = SelectObject(hdcPaint, GetSysColorBrush(COLOR_3DFACE)); | 2830 HBRUSH oldBrush = SelectObject(hdcPaint, GetSysColorBrush(COLOR_3DFACE)); |
2791 HPEN oldPen = SelectObject(hdcPaint, CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DFACE))); | 2831 HPEN oldPen = SelectObject(hdcPaint, CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DFACE))); |
2792 | 2832 |
2793 dw_window_get_pos_size(hwnd, NULL, NULL, &cx, &cy); | 2833 dw_window_get_pos_size(hwnd, NULL, NULL, &cx, &cy); |
2794 | 2834 |
2795 if(type == DW_HORZ) | 2835 if(type == DW_HORZ) |
2796 Rectangle(hdcPaint, cx - start - SPLITBAR_WIDTH, 0, cx - start, cy); | 2836 Rectangle(hdcPaint, cx - start - SPLITBAR_WIDTH, 0, cx - start, cy); |
2797 else | 2837 else |
2798 Rectangle(hdcPaint, 0, start, cx, start + SPLITBAR_WIDTH); | 2838 Rectangle(hdcPaint, 0, start, cx, start + SPLITBAR_WIDTH); |
2799 | 2839 |
2800 SelectObject(hdcPaint, oldBrush); | 2840 SelectObject(hdcPaint, oldBrush); |
2801 DeleteObject(SelectObject(hdcPaint, oldPen)); | 2841 DeleteObject(SelectObject(hdcPaint, oldPen)); |
2802 ReleaseDC(hwnd, hdcPaint); | 2842 ReleaseDC(hwnd, hdcPaint); |
2803 } | 2843 } |
2804 EndPaint(hwnd, &ps); | 2844 EndPaint(hwnd, &ps); |
2805 } | 2845 } |
2806 break; | 2846 break; |
2807 case WM_LBUTTONDOWN: | 2847 case WM_LBUTTONDOWN: |
2808 { | 2848 { |
2809 SetCapture(hwnd); | 2849 SetCapture(hwnd); |
2810 break; | 2850 break; |
2811 } | 2851 } |
2812 case WM_LBUTTONUP: | 2852 case WM_LBUTTONUP: |
2813 { | 2853 { |
2814 if(GetCapture() == hwnd) | 2854 if(GetCapture() == hwnd) |
2815 ReleaseCapture(); | 2855 ReleaseCapture(); |
2816 } | 2856 } |
2817 break; | 2857 break; |
2818 case WM_MOUSEMOVE: | 2858 case WM_MOUSEMOVE: |
2819 { | 2859 { |
2820 float *percent = (float *)dw_window_get_data(hwnd, "_dw_percent"); | 2860 float *percent = (float *)dw_window_get_data(hwnd, "_dw_percent"); |
2821 int type = (int)dw_window_get_data(hwnd, "_dw_type"); | 2861 int type = (int)dw_window_get_data(hwnd, "_dw_type"); |
2822 int start; | 2862 int start; |
2823 | 2863 |
2824 if(type == DW_HORZ) | 2864 if(type == DW_HORZ) |
2825 SetCursor(LoadCursor(NULL, IDC_SIZEWE)); | 2865 SetCursor(LoadCursor(NULL, IDC_SIZEWE)); |
2826 else | 2866 else |
2827 SetCursor(LoadCursor(NULL, IDC_SIZENS)); | 2867 SetCursor(LoadCursor(NULL, IDC_SIZENS)); |
2828 | 2868 |
2829 if(GetCapture() == hwnd && percent) | 2869 if(GetCapture() == hwnd && percent) |
2830 { | 2870 { |
2831 POINT point; | 2871 POINT point; |
2832 RECT rect; | 2872 RECT rect; |
2833 static POINT lastpoint; | 2873 static POINT lastpoint; |
2834 | 2874 |
2835 GetCursorPos(&point); | 2875 GetCursorPos(&point); |
2836 GetWindowRect(hwnd, &rect); | 2876 GetWindowRect(hwnd, &rect); |
2837 | 2877 |
2838 if(memcmp(&point, &lastpoint, sizeof(POINT))) | 2878 if(memcmp(&point, &lastpoint, sizeof(POINT))) |
2839 { | 2879 { |
2840 if(PtInRect(&rect, point)) | 2880 if(PtInRect(&rect, point)) |
2841 { | 2881 { |
2842 int width = (rect.right - rect.left); | 2882 int width = (rect.right - rect.left); |
2843 int height = (rect.bottom - rect.top); | 2883 int height = (rect.bottom - rect.top); |
2844 | 2884 |
2845 if(type == DW_HORZ) | 2885 if(type == DW_HORZ) |
2846 { | 2886 { |
2847 start = point.x - rect.left; | 2887 start = point.x - rect.left; |
2848 if(width - SPLITBAR_WIDTH > 1 && start < width - SPLITBAR_WIDTH) | 2888 if(width - SPLITBAR_WIDTH > 1 && start < width - SPLITBAR_WIDTH) |
2849 *percent = ((float)start / (float)(width - SPLITBAR_WIDTH)) * 100.0; | 2889 *percent = ((float)start / (float)(width - SPLITBAR_WIDTH)) * 100.0; |
2850 } | 2890 } |
2851 else | 2891 else |
2852 { | 2892 { |
2853 start = point.y - rect.top; | 2893 start = point.y - rect.top; |
2854 if(height - SPLITBAR_WIDTH > 1 && start < height - SPLITBAR_WIDTH) | 2894 if(height - SPLITBAR_WIDTH > 1 && start < height - SPLITBAR_WIDTH) |
2855 *percent = ((float)start / (float)(height - SPLITBAR_WIDTH)) * 100.0; | 2895 *percent = ((float)start / (float)(height - SPLITBAR_WIDTH)) * 100.0; |
2856 } | 2896 } |
2857 _handle_splitbar_resize(hwnd, *percent, type, width, height); | 2897 _handle_splitbar_resize(hwnd, *percent, type, width, height); |
2858 } | 2898 } |
2859 memcpy(&lastpoint, &point, sizeof(POINT)); | 2899 memcpy(&lastpoint, &point, sizeof(POINT)); |
2860 } | 2900 } |
2861 } | 2901 } |
2862 break; | 2902 break; |
2863 } | 2903 } |
2864 } | 2904 } |
2865 return DefWindowProc(hwnd, msg, mp1, mp2); | 2905 return DefWindowProc(hwnd, msg, mp1, mp2); |
2866 } | 2906 } |
2867 | 2907 |
2868 /* This handles drawing the status text areas */ | 2908 /* This handles drawing the status text areas */ |
2869 BOOL CALLBACK _statuswndproc(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2) | 2909 BOOL CALLBACK _statuswndproc(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2) |
2870 { | 2910 { |
2871 switch (msg) | 2911 switch (msg) |
2872 { | 2912 { |
2873 case WM_MOUSEMOVE: | 2913 case WM_MOUSEMOVE: |
2874 _wndproc(hwnd, msg, mp1, mp2); | 2914 _wndproc(hwnd, msg, mp1, mp2); |
2875 break; | 2915 break; |
2876 case WM_SETTEXT: | 2916 case WM_SETTEXT: |
2877 { | 2917 { |
2878 /* Make sure the control redraws when there is a text change */ | 2918 /* Make sure the control redraws when there is a text change */ |
2879 int ret = (int)DefWindowProc(hwnd, msg, mp1, mp2); | 2919 int ret = (int)DefWindowProc(hwnd, msg, mp1, mp2); |
2880 | 2920 |
2881 InvalidateRgn(hwnd, NULL, TRUE); | 2921 InvalidateRgn(hwnd, NULL, TRUE); |
2882 return ret; | 2922 return ret; |
2883 } | 2923 } |
2884 case WM_PAINT: | 2924 case WM_PAINT: |
2885 { | 2925 { |
2886 HDC hdcPaint; | 2926 HDC hdcPaint; |
2887 PAINTSTRUCT ps; | 2927 PAINTSTRUCT ps; |
2888 RECT rc; | 2928 RECT rc; |
2889 unsigned long cx, cy; | 2929 unsigned long cx, cy; |
2890 char tempbuf[1024] = ""; | 2930 char tempbuf[1024] = ""; |
2891 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA); | 2931 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA); |
2892 HFONT hfont = _acquire_font(hwnd, cinfo ? cinfo->fontname : NULL); | 2932 HFONT hfont = _acquire_font(hwnd, cinfo ? cinfo->fontname : NULL); |
2893 HFONT oldfont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0); | 2933 HFONT oldfont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0); |
2894 | 2934 |
2895 dw_window_get_pos_size(hwnd, NULL, NULL, &cx, &cy); | 2935 dw_window_get_pos_size(hwnd, NULL, NULL, &cx, &cy); |
2896 GetWindowText(hwnd, tempbuf, 1024); | 2936 GetWindowText(hwnd, tempbuf, 1024); |
2897 | 2937 |
2898 hdcPaint = BeginPaint(hwnd, &ps); | 2938 hdcPaint = BeginPaint(hwnd, &ps); |
2899 if(hfont) | 2939 if(hfont) |
2900 oldfont = (HFONT)SelectObject(hdcPaint, hfont); | 2940 oldfont = (HFONT)SelectObject(hdcPaint, hfont); |
2901 rc.top = rc.left = 0; | 2941 rc.top = rc.left = 0; |
2902 rc.right = cx; | 2942 rc.right = cx; |
2903 rc.bottom = cy; | 2943 rc.bottom = cy; |
2904 DrawStatusText(hdcPaint, &rc, tempbuf, 0); | 2944 DrawStatusText(hdcPaint, &rc, tempbuf, 0); |
2905 if(hfont && oldfont) | 2945 if(hfont && oldfont) |
2906 SelectObject(hdcPaint, oldfont); | 2946 SelectObject(hdcPaint, oldfont); |
2907 if(hfont) | 2947 if(hfont) |
2908 DeleteObject(hfont); | 2948 DeleteObject(hfont); |
2909 EndPaint(hwnd, &ps); | 2949 EndPaint(hwnd, &ps); |
2910 } | 2950 } |
2911 return FALSE; | 2951 return FALSE; |
2912 } | 2952 } |
2913 return DefWindowProc(hwnd, msg, mp1, mp2); | 2953 return DefWindowProc(hwnd, msg, mp1, mp2); |
2914 } | 2954 } |
2915 | 2955 |
2916 /* Function: _BtProc | 2956 /* Function: _BtProc |
2917 * Abstract: Subclass procedure for buttons | 2957 * Abstract: Subclass procedure for buttons |
2918 */ | 2958 */ |
2919 | 2959 |
2920 BOOL CALLBACK _BtProc(HWND hwnd, ULONG msg, WPARAM mp1, LPARAM mp2) | 2960 BOOL CALLBACK _BtProc(HWND hwnd, ULONG msg, WPARAM mp1, LPARAM mp2) |
2921 { | 2961 { |
2922 BubbleButton *bubble; | 2962 BubbleButton *bubble; |
2923 static int bMouseOver = 0; | 2963 static int bMouseOver = 0; |
2924 POINT point; | 2964 POINT point; |
2925 RECT rect; | 2965 RECT rect; |
2926 WNDPROC pOldProc; | 2966 WNDPROC pOldProc; |
2927 | 2967 |
2928 bubble = (BubbleButton *)GetWindowLongPtr(hwnd, GWLP_USERDATA); | 2968 bubble = (BubbleButton *)GetWindowLongPtr(hwnd, GWLP_USERDATA); |
2929 | 2969 |
2930 if(!bubble) | 2970 if(!bubble) |
2931 return DefWindowProc(hwnd, msg, mp1, mp2); | 2971 return DefWindowProc(hwnd, msg, mp1, mp2); |
2932 | 2972 |
2933 /* We must save a pointer to the old | 2973 /* We must save a pointer to the old |
2934 * window procedure because if a signal | 2974 * window procedure because if a signal |
2935 * handler attached here destroys this | 2975 * handler attached here destroys this |
2936 * window it will then be invalid. | 2976 * window it will then be invalid. |
2937 */ | 2977 */ |
2938 pOldProc = bubble->pOldProc; | 2978 pOldProc = bubble->pOldProc; |
2939 | 2979 |
2940 switch(msg) | 2980 switch(msg) |
2941 { | 2981 { |
2942 case WM_CTLCOLORSTATIC: | 2982 case WM_CTLCOLORSTATIC: |
2943 case WM_CTLCOLORLISTBOX: | 2983 case WM_CTLCOLORLISTBOX: |
2944 case WM_CTLCOLORBTN: | 2984 case WM_CTLCOLORBTN: |
2945 case WM_CTLCOLOREDIT: | 2985 case WM_CTLCOLOREDIT: |
2946 case WM_CTLCOLORMSGBOX: | 2986 case WM_CTLCOLORMSGBOX: |
2947 case WM_CTLCOLORSCROLLBAR: | 2987 case WM_CTLCOLORSCROLLBAR: |
2948 case WM_CTLCOLORDLG: | 2988 case WM_CTLCOLORDLG: |
2949 _wndproc(hwnd, msg, mp1, mp2); | 2989 _wndproc(hwnd, msg, mp1, mp2); |
2950 break; | 2990 break; |
2951 case WM_SETFOCUS: | 2991 case WM_SETFOCUS: |
2952 _wndproc(hwnd, msg, mp1, mp2); | 2992 _wndproc(hwnd, msg, mp1, mp2); |
2953 break; | 2993 break; |
2954 case WM_LBUTTONUP: | 2994 case WM_LBUTTONUP: |
2955 { | 2995 { |
2956 SignalHandler *tmp = Root; | 2996 SignalHandler *tmp = Root; |
2957 | 2997 |
2958 /* Find any callbacks for this function */ | 2998 /* Find any callbacks for this function */ |
2959 while(tmp) | 2999 while(tmp) |
2960 { | 3000 { |
2961 if(tmp->message == WM_COMMAND) | 3001 if(tmp->message == WM_COMMAND) |
2962 { | 3002 { |
2963 int (*clickfunc)(HWND, void *) = tmp->signalfunction; | 3003 int (*clickfunc)(HWND, void *) = tmp->signalfunction; |
2964 | 3004 |
2965 /* Make sure it's the right window, and the right ID */ | 3005 /* Make sure it's the right window, and the right ID */ |
2966 if(tmp->window == hwnd) | 3006 if(tmp->window == hwnd) |
2967 { | 3007 { |
2968 if(bubble->checkbox) | 3008 if(bubble->checkbox) |
2969 in_checkbox_handler = 1; | 3009 in_checkbox_handler = 1; |
2970 | 3010 |
2971 clickfunc(tmp->window, tmp->data); | 3011 clickfunc(tmp->window, tmp->data); |
2972 | 3012 |
2973 if(bubble->checkbox) | 3013 if(bubble->checkbox) |
2974 in_checkbox_handler = 0; | 3014 in_checkbox_handler = 0; |
2975 tmp = NULL; | 3015 tmp = NULL; |
2976 } | 3016 } |
2977 } | 3017 } |
2978 if(tmp) | 3018 if(tmp) |
2979 tmp= tmp->next; | 3019 tmp= tmp->next; |
2980 } | 3020 } |
2981 } | 3021 } |
2982 break; | 3022 break; |
2983 case WM_CHAR: | 3023 case WM_CHAR: |
2984 { | 3024 { |
2985 /* A button press should also occur for an ENTER or SPACE press | 3025 /* A button press should also occur for an ENTER or SPACE press |
2986 * while the button has the active input focus. | 3026 * while the button has the active input focus. |
2987 */ | 3027 */ |
2988 if(LOWORD(mp1) == '\r' || LOWORD(mp1) == ' ') | 3028 if(LOWORD(mp1) == '\r' || LOWORD(mp1) == ' ') |
2989 { | 3029 { |
2990 SignalHandler *tmp = Root; | 3030 SignalHandler *tmp = Root; |
2991 | 3031 |
2992 /* Find any callbacks for this function */ | 3032 /* Find any callbacks for this function */ |
2993 while(tmp) | 3033 while(tmp) |
2994 { | 3034 { |
2995 if(tmp->message == WM_COMMAND) | 3035 if(tmp->message == WM_COMMAND) |
2996 { | 3036 { |
2997 int (*clickfunc)(HWND, void *) = tmp->signalfunction; | 3037 int (*clickfunc)(HWND, void *) = tmp->signalfunction; |
2998 | 3038 |
2999 /* Make sure it's the right window, and the right ID */ | 3039 /* Make sure it's the right window, and the right ID */ |
3000 if(tmp->window == hwnd) | 3040 if(tmp->window == hwnd) |
3001 { | 3041 { |
3002 clickfunc(tmp->window, tmp->data); | 3042 clickfunc(tmp->window, tmp->data); |
3003 tmp = NULL; | 3043 tmp = NULL; |
3004 } | 3044 } |
3005 } | 3045 } |
3006 if(tmp) | 3046 if(tmp) |
3007 tmp= tmp->next; | 3047 tmp= tmp->next; |
3008 } | 3048 } |
3009 } | 3049 } |
3010 if(LOWORD(mp1) == '\t') | 3050 if(LOWORD(mp1) == '\t') |
3011 { | 3051 { |
3012 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) | 3052 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) |
3013 _shift_focus_back(hwnd); | 3053 _shift_focus_back(hwnd); |
3014 else | 3054 else |
3015 _shift_focus(hwnd); | 3055 _shift_focus(hwnd); |
3016 return FALSE; | 3056 return FALSE; |
3017 } | 3057 } |
3018 } | 3058 } |
3019 break; | 3059 break; |
3020 case WM_KEYDOWN: | 3060 case WM_KEYDOWN: |
3021 if(mp1 == VK_LEFT || mp1 == VK_UP) | 3061 if(mp1 == VK_LEFT || mp1 == VK_UP) |
3022 _shift_focus_back(hwnd); | 3062 _shift_focus_back(hwnd); |
3023 if(mp1 == VK_RIGHT || mp1 == VK_DOWN) | 3063 if(mp1 == VK_RIGHT || mp1 == VK_DOWN) |
3024 _shift_focus(hwnd); | 3064 _shift_focus(hwnd); |
3025 break; | 3065 break; |
3026 case WM_MOUSEMOVE: | 3066 case WM_MOUSEMOVE: |
3027 GetCursorPos(&point); | 3067 GetCursorPos(&point); |
3028 GetWindowRect(hwnd, &rect); | 3068 GetWindowRect(hwnd, &rect); |
3029 | 3069 |
3030 if(PtInRect(&rect, point)) | 3070 if(PtInRect(&rect, point)) |
3031 { | 3071 { |
3032 if(hwnd != GetCapture()) | 3072 if(hwnd != GetCapture()) |
3033 { | 3073 { |
3034 SetCapture(hwnd); | 3074 SetCapture(hwnd); |
3035 } | 3075 } |
3036 if(!bMouseOver) | 3076 if(!bMouseOver) |
3037 { | 3077 { |
3038 bMouseOver = 1; | 3078 bMouseOver = 1; |
3039 if(!*bubble->bubbletext) | 3079 if(!*bubble->bubbletext) |
3040 break; | 3080 break; |
3041 | 3081 |
3042 if(hwndBubble) | 3082 if(hwndBubble) |
3043 { | 3083 { |
3044 _free_window_memory(hwndBubble, 0); | 3084 _free_window_memory(hwndBubble, 0); |
3045 DestroyWindow(hwndBubble); | 3085 DestroyWindow(hwndBubble); |
3046 hwndBubble = 0; | 3086 hwndBubble = 0; |
3047 } | 3087 } |
3048 | 3088 |
3049 if(!hwndBubble) | 3089 if(!hwndBubble) |
3050 { | 3090 { |
3051 POINTL ptlWork = {0,0}; | 3091 POINTL ptlWork = {0,0}; |
3052 SIZE size; | 3092 SIZE size; |
3053 HFONT hFont, oldFont = (HFONT)0; | 3093 HFONT hFont, oldFont = (HFONT)0; |
3054 HDC hdc; | 3094 HDC hdc; |
3055 RECT rect; | 3095 RECT rect; |
3056 | 3096 |
3057 /* Use the WS_EX_TOOLWINDOW extended style | 3097 /* Use the WS_EX_TOOLWINDOW extended style |
3058 * so the window doesn't get listed in the | 3098 * so the window doesn't get listed in the |
3059 * taskbar. | 3099 * taskbar. |
3060 */ | 3100 */ |
3061 hwndBubble = CreateWindowEx(WS_EX_TOOLWINDOW, | 3101 hwndBubble = CreateWindowEx(WS_EX_TOOLWINDOW, |
3062 STATICCLASSNAME, | 3102 STATICCLASSNAME, |
3063 bubble->bubbletext, | 3103 bubble->bubbletext, |
3064 BS_TEXT | WS_POPUP | | 3104 BS_TEXT | WS_POPUP | |
3065 WS_BORDER | | 3105 WS_BORDER | |
3066 SS_CENTER, | 3106 SS_CENTER, |
3067 0,0,50,20, | 3107 0,0,50,20, |
3068 HWND_DESKTOP, | 3108 HWND_DESKTOP, |
3069 NULL, | 3109 NULL, |
3070 DWInstance, | 3110 DWInstance, |
3071 NULL); | 3111 NULL); |
3072 | 3112 |
3073 dw_window_set_font(hwndBubble, DefaultFont); | 3113 dw_window_set_font(hwndBubble, DefaultFont); |
3074 dw_window_set_color(hwndBubble, DW_CLR_BLACK, DW_CLR_YELLOW); | 3114 dw_window_set_color(hwndBubble, DW_CLR_BLACK, DW_CLR_YELLOW); |
3075 | 3115 |
3076 hFont = (HFONT)SendMessage(hwndBubble, WM_GETFONT, 0, 0); | 3116 hFont = (HFONT)SendMessage(hwndBubble, WM_GETFONT, 0, 0); |
3077 | 3117 |
3078 hdc = GetDC(hwndBubble); | 3118 hdc = GetDC(hwndBubble); |
3079 | 3119 |
3080 if(hFont) | 3120 if(hFont) |
3081 oldFont = (HFONT)SelectObject(hdc, hFont); | 3121 oldFont = (HFONT)SelectObject(hdc, hFont); |
3082 | 3122 |
3083 GetTextExtentPoint32(hdc, bubble->bubbletext, strlen(bubble->bubbletext), &size); | 3123 GetTextExtentPoint32(hdc, bubble->bubbletext, strlen(bubble->bubbletext), &size); |
3084 | 3124 |
3085 if(hFont) | 3125 if(hFont) |
3086 SelectObject(hdc, oldFont); | 3126 SelectObject(hdc, oldFont); |
3087 | 3127 |
3088 MapWindowPoints(hwnd, HWND_DESKTOP, (LPPOINT)&ptlWork, 1); | 3128 MapWindowPoints(hwnd, HWND_DESKTOP, (LPPOINT)&ptlWork, 1); |
3089 | 3129 |
3090 GetWindowRect(hwnd, &rect); | 3130 GetWindowRect(hwnd, &rect); |
3091 | 3131 |
3092 SetWindowPos(hwndBubble, | 3132 SetWindowPos(hwndBubble, |
3093 HWND_TOP, | 3133 HWND_TOP, |
3094 ptlWork.x, | 3134 ptlWork.x, |
3095 ptlWork.y + (rect.bottom-rect.top) + 1, | 3135 ptlWork.y + (rect.bottom-rect.top) + 1, |
3096 size.cx + 8, | 3136 size.cx + 8, |
3097 size.cy + 2, | 3137 size.cy + 2, |
3098 SWP_NOACTIVATE | SWP_SHOWWINDOW); | 3138 SWP_NOACTIVATE | SWP_SHOWWINDOW); |
3099 | 3139 |
3100 ReleaseDC(hwndBubble, hdc); | 3140 ReleaseDC(hwndBubble, hdc); |
3101 } | 3141 } |
3102 } | 3142 } |
3103 } | 3143 } |
3104 else{ | 3144 else{ |
3105 /* Calling ReleaseCapture in Win95 also causes WM_CAPTURECHANGED | 3145 /* Calling ReleaseCapture in Win95 also causes WM_CAPTURECHANGED |
3106 * to be sent. Be sure to account for that. | 3146 * to be sent. Be sure to account for that. |
3107 */ | 3147 */ |
3108 ReleaseCapture(); | 3148 ReleaseCapture(); |
3109 | 3149 |
3110 if(bMouseOver) | 3150 if(bMouseOver) |
3111 { | 3151 { |
3112 bMouseOver = 0; | 3152 bMouseOver = 0; |
3113 _free_window_memory(hwndBubble, 0); | 3153 _free_window_memory(hwndBubble, 0); |
3114 DestroyWindow(hwndBubble); | 3154 DestroyWindow(hwndBubble); |
3115 hwndBubble = 0; | 3155 hwndBubble = 0; |
3116 } | 3156 } |
3117 } | 3157 } |
3118 _wndproc(hwnd, msg, mp1, mp2); | 3158 _wndproc(hwnd, msg, mp1, mp2); |
3119 break; | 3159 break; |
3120 case WM_CAPTURECHANGED: | 3160 case WM_CAPTURECHANGED: |
3121 /* This message means we are losing the capture for some reason | 3161 /* This message means we are losing the capture for some reason |
3122 * Either because we intentionally lost it or another window | 3162 * Either because we intentionally lost it or another window |
3123 * stole it | 3163 * stole it |
3124 */ | 3164 */ |
3125 if(bMouseOver) | 3165 if(bMouseOver) |
3126 { | 3166 { |
3127 bMouseOver = 0; | 3167 bMouseOver = 0; |
3128 _free_window_memory(hwndBubble, 0); | 3168 _free_window_memory(hwndBubble, 0); |
3129 DestroyWindow(hwndBubble); | 3169 DestroyWindow(hwndBubble); |
3130 hwndBubble = 0; | 3170 hwndBubble = 0; |
3131 } | 3171 } |
3132 break; | 3172 break; |
3133 } | 3173 } |
3134 | 3174 |
3135 if(!pOldProc) | 3175 if(!pOldProc) |
3136 return DefWindowProc(hwnd, msg, mp1, mp2); | 3176 return DefWindowProc(hwnd, msg, mp1, mp2); |
3137 return CallWindowProc(pOldProc, hwnd, msg, mp1, mp2); | 3177 return CallWindowProc(pOldProc, hwnd, msg, mp1, mp2); |
3138 } | 3178 } |
3139 | 3179 |
3140 /* This function recalculates a notebook page for example | 3180 /* This function recalculates a notebook page for example |
3141 * during switching of notebook pages. | 3181 * during switching of notebook pages. |
3142 */ | 3182 */ |
3143 void _resize_notebook_page(HWND handle, int pageid) | 3183 void _resize_notebook_page(HWND handle, int pageid) |
3144 { | 3184 { |
3145 RECT rect; | 3185 RECT rect; |
3146 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); | 3186 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); |
3147 | 3187 |
3148 if(array && array[pageid]) | 3188 if(array && array[pageid]) |
3149 { | 3189 { |
3150 Box *box = (Box *)GetWindowLongPtr(array[pageid]->hwnd, GWLP_USERDATA); | 3190 Box *box = (Box *)GetWindowLongPtr(array[pageid]->hwnd, GWLP_USERDATA); |
3151 | 3191 |
3152 GetClientRect(handle,&rect); | 3192 GetClientRect(handle,&rect); |
3153 TabCtrl_AdjustRect(handle,FALSE,&rect); | 3193 TabCtrl_AdjustRect(handle,FALSE,&rect); |
3154 MoveWindow(array[pageid]->hwnd, rect.left, rect.top, | 3194 MoveWindow(array[pageid]->hwnd, rect.left, rect.top, |
3155 rect.right - rect.left, rect.bottom-rect.top, TRUE); | 3195 rect.right - rect.left, rect.bottom-rect.top, TRUE); |
3156 if(box && box->count) | 3196 if(box && box->count) |
3157 { | 3197 { |
3158 ShowWindow(box->items[0].hwnd, SW_HIDE); | 3198 ShowWindow(box->items[0].hwnd, SW_HIDE); |
3159 _do_resize(box, rect.right - rect.left, rect.bottom - rect.top); | 3199 _do_resize(box, rect.right - rect.left, rect.bottom - rect.top); |
3160 ShowWindow(box->items[0].hwnd, SW_SHOW); | 3200 ShowWindow(box->items[0].hwnd, SW_SHOW); |
3161 } | 3201 } |
3162 | 3202 |
3163 ShowWindow(array[pageid]->hwnd, SW_SHOWNORMAL); | 3203 ShowWindow(array[pageid]->hwnd, SW_SHOWNORMAL); |
3164 } | 3204 } |
3165 } | 3205 } |
3166 | 3206 |
3167 /* This function determines the handle for a supplied image filename | 3207 /* This function determines the handle for a supplied image filename |
3168 */ | 3208 */ |
3169 int _dw_get_image_handle(char *filename, HANDLE *icon, HBITMAP *hbitmap) | 3209 int _dw_get_image_handle(char *filename, HANDLE *icon, HBITMAP *hbitmap) |
3232 * newthread: True if this is the only thread. | 3272 * newthread: True if this is the only thread. |
3233 * False if there is already a message loop running. | 3273 * False if there is already a message loop running. |
3234 */ | 3274 */ |
3235 int API dw_init(int newthread, int argc, char *argv[]) | 3275 int API dw_init(int newthread, int argc, char *argv[]) |
3236 { | 3276 { |
3237 WNDCLASS wc; | 3277 WNDCLASS wc; |
3238 int z; | 3278 int z; |
3239 INITCOMMONCONTROLSEX icc; | 3279 INITCOMMONCONTROLSEX icc; |
3240 | 3280 char *fname; |
3241 icc.dwSize = sizeof(INITCOMMONCONTROLSEX); | 3281 |
3242 icc.dwICC = ICC_WIN95_CLASSES|ICC_DATE_CLASSES; | 3282 icc.dwSize = sizeof(INITCOMMONCONTROLSEX); |
3243 | 3283 icc.dwICC = ICC_WIN95_CLASSES|ICC_DATE_CLASSES; |
3244 InitCommonControlsEx(&icc); | 3284 |
3245 | 3285 InitCommonControlsEx(&icc); |
3246 memset(lookup, 0, sizeof(HICON) * ICON_INDEX_LIMIT); | 3286 |
3247 | 3287 memset(lookup, 0, sizeof(HICON) * ICON_INDEX_LIMIT); |
3248 /* Register the generic Dynamic Windows class */ | 3288 |
3249 memset(&wc, 0, sizeof(WNDCLASS)); | 3289 /* Register the generic Dynamic Windows class */ |
3250 wc.style = CS_DBLCLKS; | 3290 memset(&wc, 0, sizeof(WNDCLASS)); |
3251 wc.lpfnWndProc = (WNDPROC)_wndproc; | 3291 wc.style = CS_DBLCLKS; |
3252 wc.cbClsExtra = 0; | 3292 wc.lpfnWndProc = (WNDPROC)_wndproc; |
3253 wc.cbWndExtra = 32; | 3293 wc.cbClsExtra = 0; |
3254 wc.hbrBackground = NULL; | 3294 wc.cbWndExtra = 32; |
3255 wc.lpszMenuName = NULL; | 3295 wc.hbrBackground = NULL; |
3256 wc.lpszClassName = ClassName; | 3296 wc.lpszMenuName = NULL; |
3257 | 3297 wc.lpszClassName = ClassName; |
3258 RegisterClass(&wc); | 3298 |
3259 | 3299 RegisterClass(&wc); |
3260 /* Register the splitbar control */ | 3300 |
3261 memset(&wc, 0, sizeof(WNDCLASS)); | 3301 /* Register the splitbar control */ |
3262 wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; | 3302 memset(&wc, 0, sizeof(WNDCLASS)); |
3263 wc.lpfnWndProc = (WNDPROC)_splitwndproc; | 3303 wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; |
3264 wc.cbClsExtra = 0; | 3304 wc.lpfnWndProc = (WNDPROC)_splitwndproc; |
3265 wc.cbWndExtra = 0; | 3305 wc.cbClsExtra = 0; |
3266 wc.hbrBackground = NULL; | 3306 wc.cbWndExtra = 0; |
3267 wc.lpszMenuName = NULL; | 3307 wc.hbrBackground = NULL; |
3268 wc.lpszClassName = SplitbarClassName; | 3308 wc.lpszMenuName = NULL; |
3269 | 3309 wc.lpszClassName = SplitbarClassName; |
3270 RegisterClass(&wc); | 3310 |
3271 | 3311 RegisterClass(&wc); |
3272 /* Register a frame control like on OS/2 */ | 3312 |
3273 memset(&wc, 0, sizeof(WNDCLASS)); | 3313 /* Register a frame control like on OS/2 */ |
3274 wc.style = CS_DBLCLKS; | 3314 memset(&wc, 0, sizeof(WNDCLASS)); |
3275 wc.lpfnWndProc = (WNDPROC)_framewndproc; | 3315 wc.style = CS_DBLCLKS; |
3276 wc.cbClsExtra = 0; | 3316 wc.lpfnWndProc = (WNDPROC)_framewndproc; |
3277 wc.cbWndExtra = 32; | 3317 wc.cbClsExtra = 0; |
3278 wc.hbrBackground = (HBRUSH)GetSysColorBrush(COLOR_3DFACE); | 3318 wc.cbWndExtra = 32; |
3279 wc.hCursor = LoadCursor(NULL, IDC_ARROW); | 3319 wc.hbrBackground = (HBRUSH)GetSysColorBrush(COLOR_3DFACE); |
3280 wc.lpszMenuName = NULL; | 3320 wc.hCursor = LoadCursor(NULL, IDC_ARROW); |
3281 wc.lpszClassName = FRAMECLASSNAME; | 3321 wc.lpszMenuName = NULL; |
3282 | 3322 wc.lpszClassName = FRAMECLASSNAME; |
3283 RegisterClass(&wc); | 3323 |
3284 | 3324 RegisterClass(&wc); |
3285 /* Register HTML renderer class */ | 3325 |
3286 memset(&wc, 0, sizeof(WNDCLASS)); | 3326 /* Register HTML renderer class */ |
3287 wc.lpfnWndProc = (WNDPROC)_browserWindowProc; | 3327 memset(&wc, 0, sizeof(WNDCLASS)); |
3288 wc.lpszClassName = BrowserClassName; | 3328 wc.lpfnWndProc = (WNDPROC)_browserWindowProc; |
3289 wc.style = CS_HREDRAW|CS_VREDRAW; | 3329 wc.lpszClassName = BrowserClassName; |
3290 RegisterClass(&wc); | 3330 wc.style = CS_HREDRAW|CS_VREDRAW; |
3291 | 3331 RegisterClass(&wc); |
3292 /* Create a set of brushes using the default OS/2 and DOS colors */ | 3332 |
3293 for(z=0;z<18;z++) | 3333 /* Create a set of brushes using the default OS/2 and DOS colors */ |
3294 _colors[z] = CreateSolidBrush(RGB(_red[z],_green[z],_blue[z])); | 3334 for(z=0;z<18;z++) |
3295 | 3335 _colors[z] = CreateSolidBrush(RGB(_red[z],_green[z],_blue[z])); |
3296 /* Register an Object Windows class like OS/2 and Win2k+ | 3336 |
3297 * so similar functionality can be used on earlier releases | 3337 /* Register an Object Windows class like OS/2 and Win2k+ |
3298 * of Windows. | 3338 * so similar functionality can be used on earlier releases |
3299 */ | 3339 * of Windows. |
3300 memset(&wc, 0, sizeof(WNDCLASS)); | 3340 */ |
3301 wc.style = 0; | 3341 memset(&wc, 0, sizeof(WNDCLASS)); |
3302 wc.lpfnWndProc = (WNDPROC)_wndproc; | 3342 wc.style = 0; |
3303 wc.cbClsExtra = 0; | 3343 wc.lpfnWndProc = (WNDPROC)_wndproc; |
3304 wc.cbWndExtra = 0; | 3344 wc.cbClsExtra = 0; |
3305 wc.hbrBackground = NULL; | 3345 wc.cbWndExtra = 0; |
3306 wc.hCursor = LoadCursor(NULL, IDC_ARROW); | 3346 wc.hbrBackground = NULL; |
3307 wc.lpszMenuName = NULL; | 3347 wc.hCursor = LoadCursor(NULL, IDC_ARROW); |
3308 wc.lpszClassName = ObjectClassName; | 3348 wc.lpszMenuName = NULL; |
3309 | 3349 wc.lpszClassName = ObjectClassName; |
3310 RegisterClass(&wc); | 3350 |
3311 | 3351 RegisterClass(&wc); |
3312 /* Since Windows 95/98/NT don't have a HWND_OBJECT class | 3352 |
3313 * also known as a input only window, I will create a | 3353 /* Since Windows 95/98/NT don't have a HWND_OBJECT class |
3314 * temporary window that isn't visible and really does nothing | 3354 * also known as a input only window, I will create a |
3315 * except temporarily hold the child windows before they are | 3355 * temporary window that isn't visible and really does nothing |
3316 * packed into their correct parent. | 3356 * except temporarily hold the child windows before they are |
3317 */ | 3357 * packed into their correct parent. |
3318 | 3358 */ |
3319 DW_HWND_OBJECT = CreateWindow(ObjectClassName, "", 0, 0, 0, | 3359 |
3320 0, 0, HWND_DESKTOP, NULL, DWInstance, NULL); | 3360 DW_HWND_OBJECT = CreateWindow(ObjectClassName, "", 0, 0, 0, |
3321 | 3361 0, 0, HWND_DESKTOP, NULL, DWInstance, NULL); |
3322 if(!DW_HWND_OBJECT) | 3362 |
3323 { | 3363 if(!DW_HWND_OBJECT) |
3324 dw_messagebox("Dynamic Windows", DW_MB_OK|DW_MB_ERROR, "Could not initialize the object window. error code %d", GetLastError()); | 3364 { |
3325 exit(1); | 3365 dw_messagebox("Dynamic Windows", DW_MB_OK|DW_MB_ERROR, "Could not initialize the object window. error code %d", GetLastError()); |
3326 } | 3366 exit(1); |
3327 | 3367 } |
3328 /* We need the version to check capability like up-down controls */ | 3368 |
3329 dwVersion = GetVersion(); | 3369 /* We need the version to check capability like up-down controls */ |
3330 dwComctlVer = GetDllVersion(TEXT("comctl32.dll")); | 3370 dwVersion = GetVersion(); |
3331 | 3371 dwComctlVer = GetDllVersion(TEXT("comctl32.dll")); |
3332 for(z=0;z<THREAD_LIMIT;z++) | 3372 |
3333 { | 3373 for ( z = 0; z < THREAD_LIMIT; z++ ) |
3334 _foreground[z] = RGB(128,128,128); | 3374 { |
3335 _background[z] = DW_RGB_TRANSPARENT; | 3375 _foreground[z] = RGB(128,128,128); |
3336 _hPen[z] = CreatePen(PS_SOLID, 1, _foreground[z]); | 3376 _background[z] = DW_RGB_TRANSPARENT; |
3337 _hBrush[z] = CreateSolidBrush(_foreground[z]); | 3377 _hPen[z] = CreatePen(PS_SOLID, 1, _foreground[z]); |
3338 _clipboard_contents[z] = NULL; | 3378 _hBrush[z] = CreateSolidBrush(_foreground[z]); |
3339 } | 3379 _clipboard_contents[z] = NULL; |
3340 | 3380 } |
3341 if(!IS_WINNTOR95) | 3381 |
3342 { | 3382 if ( !IS_WINNTOR95 ) |
3343 /* Get function pointers for the Win2k/98 menu functions */ | 3383 { |
3344 HANDLE huser = LoadLibrary("user32"); | 3384 /* Get function pointers for the Win2k/98 menu functions */ |
3345 | 3385 HANDLE huser = LoadLibrary("user32"); |
3346 MyGetMenuInfo = (void*)GetProcAddress(huser, "GetMenuInfo"); | 3386 |
3347 MySetMenuInfo = (void*)GetProcAddress(huser, "SetMenuInfo"); | 3387 MyGetMenuInfo = (void*)GetProcAddress(huser, "GetMenuInfo"); |
3348 FreeLibrary(huser); | 3388 MySetMenuInfo = (void*)GetProcAddress(huser, "SetMenuInfo"); |
3349 } | 3389 FreeLibrary(huser); |
3350 | 3390 } |
3351 /* Initialize Security for named events and memory */ | 3391 |
3352 InitializeSecurityDescriptor(&_dwsd, SECURITY_DESCRIPTOR_REVISION); | 3392 /* Initialize Security for named events and memory */ |
3353 SetSecurityDescriptorDacl(&_dwsd, TRUE, (PACL) NULL, FALSE); | 3393 InitializeSecurityDescriptor(&_dwsd, SECURITY_DESCRIPTOR_REVISION); |
3354 | 3394 SetSecurityDescriptorDacl(&_dwsd, TRUE, (PACL) NULL, FALSE); |
3355 OleInitialize(NULL); | 3395 |
3356 return 0; | 3396 OleInitialize(NULL); |
3397 /* | |
3398 * Setup logging/debugging | |
3399 */ | |
3400 if ( (fname = getenv( "DWINDOWS_DEBUGFILE" ) ) != NULL ) | |
3401 { | |
3402 dbgfp = fopen( fname, "w" ); | |
3403 } | |
3404 return 0; | |
3357 } | 3405 } |
3358 | 3406 |
3359 /* | 3407 /* |
3360 * Runs a message loop for Dynamic Windows. | 3408 * Runs a message loop for Dynamic Windows. |
3361 */ | 3409 */ |
3362 void API dw_main(void) | 3410 void API dw_main(void) |
3363 { | 3411 { |
3364 MSG msg; | 3412 MSG msg; |
3365 | 3413 |
3366 _dwtid = dw_thread_id(); | 3414 _dwtid = dw_thread_id(); |
3367 | 3415 |
3368 while(GetMessage(&msg, NULL, 0, 0)) | 3416 while(GetMessage(&msg, NULL, 0, 0)) |
3369 { | 3417 { |
3370 if(msg.hwnd == NULL && msg.message == WM_TIMER) | 3418 if(msg.hwnd == NULL && msg.message == WM_TIMER) |
3371 _wndproc(msg.hwnd, msg.message, msg.wParam, msg.lParam); | 3419 _wndproc(msg.hwnd, msg.message, msg.wParam, msg.lParam); |
3372 else | 3420 else |
3373 { | 3421 { |
3374 TranslateMessage(&msg); | 3422 TranslateMessage(&msg); |
3375 DispatchMessage(&msg); | 3423 DispatchMessage(&msg); |
3376 } | 3424 } |
3377 } | 3425 } |
3378 } | 3426 } |
3379 | 3427 |
3380 /* | 3428 /* |
3381 * Runs a message loop for Dynamic Windows, for a period of milliseconds. | 3429 * Runs a message loop for Dynamic Windows, for a period of milliseconds. |
3382 * Parameters: | 3430 * Parameters: |
3383 * milliseconds: Number of milliseconds to run the loop for. | 3431 * milliseconds: Number of milliseconds to run the loop for. |
3384 */ | 3432 */ |
3385 void API dw_main_sleep(int milliseconds) | 3433 void API dw_main_sleep(int milliseconds) |
3386 { | 3434 { |
3387 MSG msg; | 3435 MSG msg; |
3388 double start = (double)clock(); | 3436 double start = (double)clock(); |
3389 | 3437 |
3390 while(((clock() - start) / (CLOCKS_PER_SEC/1000)) <= milliseconds) | 3438 while(((clock() - start) / (CLOCKS_PER_SEC/1000)) <= milliseconds) |
3391 { | 3439 { |
3392 if(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) | 3440 if(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) |
3393 { | 3441 { |
3394 GetMessage(&msg, NULL, 0, 0); | 3442 GetMessage(&msg, NULL, 0, 0); |
3395 if(msg.hwnd == NULL && msg.message == WM_TIMER) | 3443 if(msg.hwnd == NULL && msg.message == WM_TIMER) |
3396 _wndproc(msg.hwnd, msg.message, msg.wParam, msg.lParam); | 3444 _wndproc(msg.hwnd, msg.message, msg.wParam, msg.lParam); |
3397 else | 3445 else |
3398 { | 3446 { |
3399 TranslateMessage(&msg); | 3447 TranslateMessage(&msg); |
3400 DispatchMessage(&msg); | 3448 DispatchMessage(&msg); |
3401 } | 3449 } |
3402 } | 3450 } |
3403 else | 3451 else |
3404 Sleep(1); | 3452 Sleep(1); |
3405 } | 3453 } |
3406 } | 3454 } |
3407 | 3455 |
3408 /* | 3456 /* |
3409 * Processes a single message iteration and returns. | 3457 * Processes a single message iteration and returns. |
3410 */ | 3458 */ |
3411 void API dw_main_iteration(void) | 3459 void API dw_main_iteration(void) |
3412 { | 3460 { |
3413 MSG msg; | 3461 MSG msg; |
3414 | 3462 |
3415 _dwtid = dw_thread_id(); | 3463 _dwtid = dw_thread_id(); |
3416 | 3464 |
3417 if(GetMessage(&msg, NULL, 0, 0)) | 3465 if(GetMessage(&msg, NULL, 0, 0)) |
3418 { | 3466 { |
3419 if(msg.hwnd == NULL && msg.message == WM_TIMER) | 3467 if(msg.hwnd == NULL && msg.message == WM_TIMER) |
3420 _wndproc(msg.hwnd, msg.message, msg.wParam, msg.lParam); | 3468 _wndproc(msg.hwnd, msg.message, msg.wParam, msg.lParam); |
3421 else | 3469 else |
3422 { | 3470 { |
3423 TranslateMessage(&msg); | 3471 TranslateMessage(&msg); |
3424 DispatchMessage(&msg); | 3472 DispatchMessage(&msg); |
3425 } | 3473 } |
3426 } | 3474 } |
3427 } | 3475 } |
3428 | 3476 |
3429 /* | 3477 /* |
3430 * Free's memory allocated by dynamic windows. | 3478 * Free's memory allocated by dynamic windows. |
3431 * Parameters: | 3479 * Parameters: |
3432 * ptr: Pointer to dynamic windows allocated | 3480 * ptr: Pointer to dynamic windows allocated |
3433 * memory to be free()'d. | 3481 * memory to be free()'d. |
3434 */ | 3482 */ |
3435 void API dw_free(void *ptr) | 3483 void API dw_free(void *ptr) |
3436 { | 3484 { |
3437 free(ptr); | 3485 free(ptr); |
3438 } | 3486 } |
3439 | 3487 |
3440 /* | 3488 /* |
3441 * Allocates and initializes a dialog struct. | 3489 * Allocates and initializes a dialog struct. |
3442 * Parameters: | 3490 * Parameters: |
3443 * data: User defined data to be passed to functions. | 3491 * data: User defined data to be passed to functions. |
3444 */ | 3492 */ |
3445 DWDialog * API dw_dialog_new(void *data) | 3493 DWDialog * API dw_dialog_new(void *data) |
3446 { | 3494 { |
3447 DWDialog *tmp = malloc(sizeof(DWDialog)); | 3495 DWDialog *tmp = malloc(sizeof(DWDialog)); |
3448 | 3496 |
3449 tmp->eve = dw_event_new(); | 3497 tmp->eve = dw_event_new(); |
3450 dw_event_reset(tmp->eve); | 3498 dw_event_reset(tmp->eve); |
3451 tmp->data = data; | 3499 tmp->data = data; |
3452 tmp->done = FALSE; | 3500 tmp->done = FALSE; |
3453 tmp->result = NULL; | 3501 tmp->result = NULL; |
3454 | 3502 |
3455 return tmp; | 3503 return tmp; |
3456 } | 3504 } |
3457 | 3505 |
3458 /* | 3506 /* |
3462 * dialog: Pointer to a dialog struct aquired by dw_dialog_new). | 3510 * dialog: Pointer to a dialog struct aquired by dw_dialog_new). |
3463 * result: Data to be returned by dw_dialog_wait(). | 3511 * result: Data to be returned by dw_dialog_wait(). |
3464 */ | 3512 */ |
3465 int API dw_dialog_dismiss(DWDialog *dialog, void *result) | 3513 int API dw_dialog_dismiss(DWDialog *dialog, void *result) |
3466 { | 3514 { |
3467 dialog->result = result; | 3515 dialog->result = result; |
3468 dw_event_post(dialog->eve); | 3516 dw_event_post(dialog->eve); |
3469 dialog->done = TRUE; | 3517 dialog->done = TRUE; |
3470 return 0; | 3518 return 0; |
3471 } | 3519 } |
3472 | 3520 |
3473 /* | 3521 /* |
3474 * Accepts a dialog struct waits for dw_dialog_dismiss() to be | 3522 * Accepts a dialog struct waits for dw_dialog_dismiss() to be |
3475 * called by a signal handler with the given dialog struct. | 3523 * called by a signal handler with the given dialog struct. |
3476 * Parameters: | 3524 * Parameters: |
3477 * dialog: Pointer to a dialog struct aquired by dw_dialog_new). | 3525 * dialog: Pointer to a dialog struct aquired by dw_dialog_new). |
3478 */ | 3526 */ |
3479 void * API dw_dialog_wait(DWDialog *dialog) | 3527 void * API dw_dialog_wait(DWDialog *dialog) |
3480 { | 3528 { |
3481 MSG msg; | 3529 MSG msg; |
3482 void *tmp; | 3530 void *tmp; |
3483 | 3531 |
3484 while (GetMessage(&msg,NULL,0,0)) | 3532 while (GetMessage(&msg,NULL,0,0)) |
3485 { | 3533 { |
3486 if(msg.hwnd == NULL && msg.message == WM_TIMER) | 3534 if(msg.hwnd == NULL && msg.message == WM_TIMER) |
3487 _wndproc(msg.hwnd, msg.message, msg.wParam, msg.lParam); | 3535 _wndproc(msg.hwnd, msg.message, msg.wParam, msg.lParam); |
3488 else | 3536 else |
3489 { | 3537 { |
3490 TranslateMessage(&msg); | 3538 TranslateMessage(&msg); |
3491 DispatchMessage(&msg); | 3539 DispatchMessage(&msg); |
3492 } | 3540 } |
3493 if(dialog->done) | 3541 if(dialog->done) |
3494 break; | 3542 break; |
3495 } | 3543 } |
3496 dw_event_close(&dialog->eve); | 3544 dw_event_close(&dialog->eve); |
3497 tmp = dialog->result; | 3545 tmp = dialog->result; |
3498 free(dialog); | 3546 free(dialog); |
3499 return tmp; | 3547 return tmp; |
3500 } | 3548 } |
3501 | 3549 |
3502 /* | 3550 /* |
3503 * Displays a Message Box with given text and title.. | 3551 * Displays a Message Box with given text and title.. |
3504 * Parameters: | 3552 * Parameters: |
3506 * format: printf style format string. | 3554 * format: printf style format string. |
3507 * ...: Additional variables for use in the format. | 3555 * ...: Additional variables for use in the format. |
3508 */ | 3556 */ |
3509 int API dw_messagebox(char *title, int flags, char *format, ...) | 3557 int API dw_messagebox(char *title, int flags, char *format, ...) |
3510 { | 3558 { |
3511 va_list args; | 3559 va_list args; |
3512 char outbuf[1024]; | 3560 char outbuf[1024]; |
3513 int rc; | 3561 int rc; |
3514 | 3562 |
3515 va_start(args, format); | 3563 va_start(args, format); |
3516 vsprintf(outbuf, format, args); | 3564 vsprintf(outbuf, format, args); |
3517 va_end(args); | 3565 va_end(args); |
3518 | 3566 |
3519 rc = MessageBox(HWND_DESKTOP, outbuf, title, flags); | 3567 rc = MessageBox(HWND_DESKTOP, outbuf, title, flags); |
3520 if(rc == IDOK) | 3568 if(rc == IDOK) |
3521 return DW_MB_RETURN_OK; | 3569 return DW_MB_RETURN_OK; |
3522 else if(rc == IDYES) | 3570 else if(rc == IDYES) |
3523 return DW_MB_RETURN_YES; | 3571 return DW_MB_RETURN_YES; |
3524 else if(rc == IDNO) | 3572 else if(rc == IDNO) |
3525 return DW_MB_RETURN_NO; | 3573 return DW_MB_RETURN_NO; |
3526 else if(rc == IDCANCEL) | 3574 else if(rc == IDCANCEL) |
3527 return DW_MB_RETURN_CANCEL; | 3575 return DW_MB_RETURN_CANCEL; |
3528 else return 0; | 3576 else return 0; |
3529 } | 3577 } |
3530 | 3578 |
3531 /* | 3579 /* |
3532 * Minimizes or Iconifies a top-level window. | 3580 * Minimizes or Iconifies a top-level window. |
3533 * Parameters: | 3581 * Parameters: |
3534 * handle: The window handle to minimize. | 3582 * handle: The window handle to minimize. |
3535 */ | 3583 */ |
3536 int API dw_window_minimize(HWND handle) | 3584 int API dw_window_minimize(HWND handle) |
3537 { | 3585 { |
3538 return ShowWindow(handle, SW_MINIMIZE); | 3586 return ShowWindow(handle, SW_MINIMIZE); |
3539 } | 3587 } |
3540 | 3588 |
3541 /* | 3589 /* |
3542 * Makes the window topmost. | 3590 * Makes the window topmost. |
3543 * Parameters: | 3591 * Parameters: |
3544 * handle: The window handle to make topmost. | 3592 * handle: The window handle to make topmost. |
3545 */ | 3593 */ |
3546 int API dw_window_raise(HWND handle) | 3594 int API dw_window_raise(HWND handle) |
3547 { | 3595 { |
3548 return SetWindowPos(handle, HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); | 3596 return SetWindowPos(handle, HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); |
3549 } | 3597 } |
3550 | 3598 |
3551 /* | 3599 /* |
3552 * Makes the window bottommost. | 3600 * Makes the window bottommost. |
3553 * Parameters: | 3601 * Parameters: |
3554 * handle: The window handle to make bottommost. | 3602 * handle: The window handle to make bottommost. |
3555 */ | 3603 */ |
3556 int API dw_window_lower(HWND handle) | 3604 int API dw_window_lower(HWND handle) |
3557 { | 3605 { |
3558 return SetWindowPos(handle, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); | 3606 return SetWindowPos(handle, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); |
3559 } | 3607 } |
3560 | 3608 |
3561 /* | 3609 /* |
3562 * Makes the window visible. | 3610 * Makes the window visible. |
3563 * Parameters: | 3611 * Parameters: |
3564 * handle: The window handle to make visible. | 3612 * handle: The window handle to make visible. |
3565 */ | 3613 */ |
3566 int API dw_window_show(HWND handle) | 3614 int API dw_window_show(HWND handle) |
3567 { | 3615 { |
3568 int rc = ShowWindow(handle, SW_SHOW); | 3616 int rc = ShowWindow(handle, SW_SHOW); |
3569 SetFocus(handle); | 3617 SetFocus(handle); |
3570 _initial_focus(handle); | 3618 _initial_focus(handle); |
3571 return rc; | 3619 return rc; |
3572 } | 3620 } |
3573 | 3621 |
3574 /* | 3622 /* |
3575 * Makes the window invisible. | 3623 * Makes the window invisible. |
3576 * Parameters: | 3624 * Parameters: |
3577 * handle: The window handle to make visible. | 3625 * handle: The window handle to make visible. |
3578 */ | 3626 */ |
3579 int API dw_window_hide(HWND handle) | 3627 int API dw_window_hide(HWND handle) |
3580 { | 3628 { |
3581 return ShowWindow(handle, SW_HIDE); | 3629 return ShowWindow(handle, SW_HIDE); |
3582 } | 3630 } |
3583 | 3631 |
3584 /* | 3632 /* |
3585 * Destroys a window and all of it's children. | 3633 * Destroys a window and all of it's children. |
3586 * Parameters: | 3634 * Parameters: |
3587 * handle: The window handle to destroy. | 3635 * handle: The window handle to destroy. |
3588 */ | 3636 */ |
3589 int API dw_window_destroy(HWND handle) | 3637 int API dw_window_destroy(HWND handle) |
3590 { | 3638 { |
3591 HWND parent = GetParent(handle); | 3639 HWND parent = GetParent(handle); |
3592 Box *thisbox = (Box *)GetWindowLongPtr(parent, GWLP_USERDATA); | 3640 Box *thisbox = (Box *)GetWindowLongPtr(parent, GWLP_USERDATA); |
3593 | 3641 |
3594 if(!IS_WINNTOR95) | 3642 if(!IS_WINNTOR95) |
3595 { | 3643 { |
3596 HMENU menu = GetMenu(handle); | 3644 HMENU menu = GetMenu(handle); |
3597 | 3645 |
3598 if(menu) | 3646 if(menu) |
3599 _free_menu_data(menu); | 3647 _free_menu_data(menu); |
3600 } | 3648 } |
3601 | 3649 |
3602 if(parent != HWND_DESKTOP && thisbox && thisbox->count) | 3650 if(parent != HWND_DESKTOP && thisbox && thisbox->count) |
3603 { | 3651 { |
3604 int z, index = -1; | 3652 int z, index = -1; |
3605 Item *tmpitem, *thisitem = thisbox->items; | 3653 Item *tmpitem, *thisitem = thisbox->items; |
3606 | 3654 |
3607 for(z=0;z<thisbox->count;z++) | 3655 for(z=0;z<thisbox->count;z++) |
3608 { | 3656 { |
3609 if(thisitem[z].hwnd == handle) | 3657 if(thisitem[z].hwnd == handle) |
3610 index = z; | 3658 index = z; |
3611 } | 3659 } |
3612 | 3660 |
3613 if(index == -1) | 3661 if(index == -1) |
3614 return 0; | 3662 return 0; |
3615 | 3663 |
3616 tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); | 3664 tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); |
3617 | 3665 |
3618 /* Copy all but the current entry to the new list */ | 3666 /* Copy all but the current entry to the new list */ |
3619 for(z=0;z<index;z++) | 3667 for(z=0;z<index;z++) |
3620 { | 3668 { |
3621 tmpitem[z] = thisitem[z]; | 3669 tmpitem[z] = thisitem[z]; |
3622 } | 3670 } |
3623 for(z=index+1;z<thisbox->count;z++) | 3671 for(z=index+1;z<thisbox->count;z++) |
3624 { | 3672 { |
3625 tmpitem[z-1] = thisitem[z]; | 3673 tmpitem[z-1] = thisitem[z]; |
3626 } | 3674 } |
3627 | 3675 |
3628 thisbox->items = tmpitem; | 3676 thisbox->items = tmpitem; |
3629 free(thisitem); | 3677 free(thisitem); |
3630 thisbox->count--; | 3678 thisbox->count--; |
3631 _free_window_memory(handle, 0); | 3679 _free_window_memory(handle, 0); |
3632 EnumChildWindows(handle, _free_window_memory, 0); | 3680 EnumChildWindows(handle, _free_window_memory, 0); |
3633 } | 3681 } |
3634 return DestroyWindow(handle); | 3682 return DestroyWindow(handle); |
3635 } | 3683 } |
3636 | 3684 |
3637 /* Causes entire window to be invalidated and redrawn. | 3685 /* Causes entire window to be invalidated and redrawn. |
3638 * Parameters: | 3686 * Parameters: |
3639 * handle: Toplevel window handle to be redrawn. | 3687 * handle: Toplevel window handle to be redrawn. |
3640 */ | 3688 */ |
3641 void API dw_window_redraw(HWND handle) | 3689 void API dw_window_redraw(HWND handle) |
3642 { | 3690 { |
3643 Box *mybox = (Box *)GetWindowLongPtr(handle, GWLP_USERDATA); | 3691 Box *mybox = (Box *)GetWindowLongPtr(handle, GWLP_USERDATA); |
3644 | 3692 |
3645 if(mybox) | 3693 if(mybox) |
3646 { | 3694 { |
3647 RECT rect; | 3695 RECT rect; |
3648 int istoplevel = (GetParent(handle) == HWND_DESKTOP); | 3696 int istoplevel = (GetParent(handle) == HWND_DESKTOP); |
3649 | 3697 |
3650 GetClientRect(handle, &rect); | 3698 GetClientRect(handle, &rect); |
3651 | 3699 |
3652 ShowWindow(istoplevel ? mybox->items[0].hwnd : handle, SW_HIDE); | 3700 ShowWindow(istoplevel ? mybox->items[0].hwnd : handle, SW_HIDE); |
3653 _do_resize(mybox, rect.right - rect.left, rect.bottom - rect.top); | 3701 _do_resize(mybox, rect.right - rect.left, rect.bottom - rect.top); |
3654 ShowWindow(istoplevel ? mybox->items[0].hwnd : handle, SW_SHOW); | 3702 ShowWindow(istoplevel ? mybox->items[0].hwnd : handle, SW_SHOW); |
3655 } | 3703 } |
3656 } | 3704 } |
3657 | 3705 |
3658 int instring(char *text, char *buffer) | 3706 int instring(char *text, char *buffer) |
3659 { | 3707 { |
3660 int z, len = strlen(text), buflen = strlen(buffer); | 3708 int z, len = strlen(text), buflen = strlen(buffer); |
3661 | 3709 |
3662 if(buflen > len) | 3710 if(buflen > len) |
3663 { | 3711 { |
3664 for(z=0;z<=(buflen-len);z++) | 3712 for(z=0;z<=(buflen-len);z++) |
3665 { | 3713 { |
3666 if(memcmp(text, &buffer[z], len) == 0) | 3714 if(memcmp(text, &buffer[z], len) == 0) |
3667 return z; | 3715 return z; |
3668 } | 3716 } |
3669 } | 3717 } |
3670 return 0; | 3718 return 0; |
3671 } | 3719 } |
3672 | 3720 |
3673 /* | 3721 /* |
3674 * Changes a window's parent to newparent. | 3722 * Changes a window's parent to newparent. |
3675 * Parameters: | 3723 * Parameters: |
3676 * handle: The window handle to destroy. | 3724 * handle: The window handle to destroy. |
3677 * newparent: The window's new parent window. | 3725 * newparent: The window's new parent window. |
3678 */ | 3726 */ |
3679 void API dw_window_reparent(HWND handle, HWND newparent) | 3727 void API dw_window_reparent(HWND handle, HWND newparent) |
3680 { | 3728 { |
3681 SetParent(handle, newparent); | 3729 SetParent(handle, newparent); |
3682 } | 3730 } |
3683 | 3731 |
3684 HFONT _acquire_font(HWND handle, char *fontname) | 3732 HFONT _acquire_font(HWND handle, char *fontname) |
3685 { | 3733 { |
3686 HFONT hfont = 0; | 3734 HFONT hfont = 0; |
3687 | 3735 |
3688 if(fontname != DefaultFont && fontname[0]) | 3736 if(fontname != DefaultFont && fontname[0]) |
3689 { | 3737 { |
3690 int Italic, Bold; | 3738 int Italic, Bold; |
3691 char *myFontName; | 3739 char *myFontName; |
3692 int z, size = 9; | 3740 int z, size = 9; |
3693 LOGFONT lf; | 3741 LOGFONT lf; |
3694 #if 0 | 3742 #if 0 |
3695 HDC hDC = GetDC(handle); | 3743 HDC hDC = GetDC(handle); |
3696 #endif | 3744 #endif |
3697 for(z=0;z<strlen(fontname);z++) | 3745 for(z=0;z<strlen(fontname);z++) |
3698 { | 3746 { |
3699 if(fontname[z]=='.') | 3747 if(fontname[z]=='.') |
3700 break; | 3748 break; |
3701 } | 3749 } |
3702 size = atoi(fontname) + 5; | 3750 size = atoi(fontname) + 5; |
3703 Italic = instring(" Italic", &fontname[z+1]); | 3751 Italic = instring(" Italic", &fontname[z+1]); |
3704 Bold = instring(" Bold", &fontname[z+1]); | 3752 Bold = instring(" Bold", &fontname[z+1]); |
3705 #if 0 | 3753 #if 0 |
3706 lf.lfHeight = -MulDiv(size, GetDeviceCaps(hDC, LOGPIXELSY), 72); | 3754 lf.lfHeight = -MulDiv(size, GetDeviceCaps(hDC, LOGPIXELSY), 72); |
3707 #endif | 3755 #endif |
3708 lf.lfHeight = size; | 3756 lf.lfHeight = size; |
3709 lf.lfWidth = 0; | 3757 lf.lfWidth = 0; |
3710 lf.lfEscapement = 0; | 3758 lf.lfEscapement = 0; |
3711 lf.lfOrientation = 0; | 3759 lf.lfOrientation = 0; |
3712 lf.lfItalic = Italic ? TRUE : FALSE; | 3760 lf.lfItalic = Italic ? TRUE : FALSE; |
3713 lf.lfUnderline = 0; | 3761 lf.lfUnderline = 0; |
3714 lf.lfStrikeOut = 0; | 3762 lf.lfStrikeOut = 0; |
3715 lf.lfWeight = Bold ? FW_BOLD : FW_NORMAL; | 3763 lf.lfWeight = Bold ? FW_BOLD : FW_NORMAL; |
3716 lf.lfCharSet = DEFAULT_CHARSET; | 3764 lf.lfCharSet = DEFAULT_CHARSET; |
3717 lf.lfOutPrecision = 0; | 3765 lf.lfOutPrecision = 0; |
3718 lf.lfClipPrecision = 0; | 3766 lf.lfClipPrecision = 0; |
3719 lf.lfQuality = DEFAULT_QUALITY; | 3767 lf.lfQuality = DEFAULT_QUALITY; |
3720 lf.lfPitchAndFamily = DEFAULT_PITCH | FW_DONTCARE; | 3768 lf.lfPitchAndFamily = DEFAULT_PITCH | FW_DONTCARE; |
3721 /* | 3769 /* |
3722 * remove any font modifiers | 3770 * remove any font modifiers |
3723 */ | 3771 */ |
3724 myFontName = strdup(&fontname[z+1]); | 3772 myFontName = strdup(&fontname[z+1]); |
3725 if(Italic) | 3773 if(Italic) |
3726 myFontName[Italic] = 0; | 3774 myFontName[Italic] = 0; |
3727 if(Bold) | 3775 if(Bold) |
3728 myFontName[Bold] = 0; | 3776 myFontName[Bold] = 0; |
3729 strcpy(lf.lfFaceName, myFontName); | 3777 strcpy(lf.lfFaceName, myFontName); |
3730 free(myFontName); | 3778 free(myFontName); |
3731 | 3779 |
3732 hfont = CreateFontIndirect(&lf); | 3780 hfont = CreateFontIndirect(&lf); |
3733 #if 0 | 3781 #if 0 |
3734 ReleaseDC(handle, hDC); | 3782 ReleaseDC(handle, hDC); |
3735 #endif | 3783 #endif |
3736 } | 3784 } |
3737 if(!hfont) | 3785 if(!hfont) |
3738 hfont = GetStockObject(DEFAULT_GUI_FONT); | 3786 hfont = GetStockObject(DEFAULT_GUI_FONT); |
3739 return hfont; | 3787 return hfont; |
3740 } | 3788 } |
3741 | 3789 |
3742 /* | 3790 /* |
3743 * Sets the font used by a specified window (widget) handle. | 3791 * Sets the font used by a specified window (widget) handle. |
3744 * Parameters: | 3792 * Parameters: |
3745 * handle: The window (widget) handle. | 3793 * handle: The window (widget) handle. |
3746 * fontname: Name and size of the font in the form "size.fontname" | 3794 * fontname: Name and size of the font in the form "size.fontname" |
3747 */ | 3795 */ |
3748 int API dw_window_set_font(HWND handle, char *fontname) | 3796 int API dw_window_set_font(HWND handle, char *fontname) |
3749 { | 3797 { |
3750 HFONT oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0); | 3798 HFONT oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0); |
3751 HFONT hfont = _acquire_font(handle, fontname); | 3799 HFONT hfont = _acquire_font(handle, fontname); |
3752 ColorInfo *cinfo; | 3800 ColorInfo *cinfo; |
3753 | 3801 |
3754 cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 3802 cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
3755 | 3803 |
3756 if(fontname) | 3804 if(fontname) |
3757 { | 3805 { |
3758 if(cinfo) | 3806 if(cinfo) |
3759 { | 3807 { |
3760 strcpy(cinfo->fontname, fontname); | 3808 strcpy(cinfo->fontname, fontname); |
3761 if(!oldfont) | 3809 if(!oldfont) |
3762 oldfont = cinfo->hfont; | 3810 oldfont = cinfo->hfont; |
3763 cinfo->hfont = hfont; | 3811 cinfo->hfont = hfont; |
3764 } | 3812 } |
3765 else | 3813 else |
3766 { | 3814 { |
3767 cinfo = calloc(1, sizeof(ColorInfo)); | 3815 cinfo = calloc(1, sizeof(ColorInfo)); |
3768 cinfo->fore = cinfo->back = -1; | 3816 cinfo->fore = cinfo->back = -1; |
3769 | 3817 |
3770 strcpy(cinfo->fontname, fontname); | 3818 strcpy(cinfo->fontname, fontname); |
3771 | 3819 |
3772 cinfo->pOldProc = SubclassWindow(handle, _colorwndproc); | 3820 cinfo->pOldProc = SubclassWindow(handle, _colorwndproc); |
3773 SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)cinfo); | 3821 SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)cinfo); |
3774 } | 3822 } |
3775 } | 3823 } |
3776 SendMessage(handle, WM_SETFONT, (WPARAM)hfont, (LPARAM)TRUE); | 3824 SendMessage(handle, WM_SETFONT, (WPARAM)hfont, (LPARAM)TRUE); |
3777 if(oldfont) | 3825 if(oldfont) |
3778 DeleteObject(oldfont); | 3826 DeleteObject(oldfont); |
3779 return 0; | 3827 return 0; |
3780 } | 3828 } |
3781 | 3829 |
3782 /* | 3830 /* |
3783 * Sets the colors used by a specified window (widget) handle. | 3831 * Sets the colors used by a specified window (widget) handle. |
3784 * Parameters: | 3832 * Parameters: |
3786 * fore: Foreground color in RGB format. | 3834 * fore: Foreground color in RGB format. |
3787 * back: Background color in RGB format. | 3835 * back: Background color in RGB format. |
3788 */ | 3836 */ |
3789 int API dw_window_set_color(HWND handle, ULONG fore, ULONG back) | 3837 int API dw_window_set_color(HWND handle, ULONG fore, ULONG back) |
3790 { | 3838 { |
3791 ColorInfo *cinfo; | 3839 ColorInfo *cinfo; |
3792 char tmpbuf[100]; | 3840 char tmpbuf[100]; |
3793 | 3841 |
3794 cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 3842 cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
3795 | 3843 |
3796 GetClassName(handle, tmpbuf, 99); | 3844 GetClassName(handle, tmpbuf, 99); |
3797 | 3845 |
3798 if(strnicmp(tmpbuf, WC_LISTVIEW, strlen(WC_LISTVIEW))==0) | 3846 if(strnicmp(tmpbuf, WC_LISTVIEW, strlen(WC_LISTVIEW))==0) |
3799 { | 3847 { |
3800 fore = _internal_color(fore); | 3848 fore = _internal_color(fore); |
3801 back = _internal_color(back); | 3849 back = _internal_color(back); |
3802 | 3850 |
3803 ListView_SetTextColor(handle, RGB(DW_RED_VALUE(fore), | 3851 ListView_SetTextColor(handle, RGB(DW_RED_VALUE(fore), |
3804 DW_GREEN_VALUE(fore), | 3852 DW_GREEN_VALUE(fore), |
3805 DW_BLUE_VALUE(fore))); | 3853 DW_BLUE_VALUE(fore))); |
3806 ListView_SetTextBkColor(handle, RGB(DW_RED_VALUE(back), | 3854 ListView_SetTextBkColor(handle, RGB(DW_RED_VALUE(back), |
3807 DW_GREEN_VALUE(back), | 3855 DW_GREEN_VALUE(back), |
3808 DW_BLUE_VALUE(back))); | 3856 DW_BLUE_VALUE(back))); |
3809 ListView_SetBkColor(handle, RGB(DW_RED_VALUE(back), | 3857 ListView_SetBkColor(handle, RGB(DW_RED_VALUE(back), |
3810 DW_GREEN_VALUE(back), | 3858 DW_GREEN_VALUE(back), |
3811 DW_BLUE_VALUE(back))); | 3859 DW_BLUE_VALUE(back))); |
3812 InvalidateRgn(handle, NULL, TRUE); | 3860 InvalidateRgn(handle, NULL, TRUE); |
3813 return TRUE; | 3861 return TRUE; |
3814 } | 3862 } |
3815 | 3863 |
3816 if(cinfo) | 3864 if(cinfo) |
3817 { | 3865 { |
3818 cinfo->fore = fore; | 3866 cinfo->fore = fore; |
3819 cinfo->back = back; | 3867 cinfo->back = back; |
3820 } | 3868 } |
3821 else | 3869 else |
3822 { | 3870 { |
3823 cinfo = calloc(1, sizeof(ColorInfo)); | 3871 cinfo = calloc(1, sizeof(ColorInfo)); |
3824 | 3872 |
3825 cinfo->fore = fore; | 3873 cinfo->fore = fore; |
3826 cinfo->back = back; | 3874 cinfo->back = back; |
3827 | 3875 |
3828 cinfo->pOldProc = SubclassWindow(handle, _colorwndproc); | 3876 cinfo->pOldProc = SubclassWindow(handle, _colorwndproc); |
3829 SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)cinfo); | 3877 SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)cinfo); |
3830 } | 3878 } |
3831 InvalidateRgn(handle, NULL, TRUE); | 3879 InvalidateRgn(handle, NULL, TRUE); |
3832 return TRUE; | 3880 return TRUE; |
3833 } | 3881 } |
3834 | 3882 |
3835 /* | 3883 /* |
3836 * Sets the font used by a specified window (widget) handle. | 3884 * Sets the font used by a specified window (widget) handle. |
3837 * Parameters: | 3885 * Parameters: |
3838 * handle: The window (widget) handle. | 3886 * handle: The window (widget) handle. |
3839 * border: Size of the window border in pixels. | 3887 * border: Size of the window border in pixels. |
3840 */ | 3888 */ |
3841 int API dw_window_set_border(HWND handle, int border) | 3889 int API dw_window_set_border(HWND handle, int border) |
3842 { | 3890 { |
3843 return 0; | 3891 return 0; |
3844 } | 3892 } |
3845 | 3893 |
3846 /* | 3894 /* |
3847 * Captures the mouse input to this window. | 3895 * Captures the mouse input to this window. |
3848 * Parameters: | 3896 * Parameters: |
3849 * handle: Handle to receive mouse input. | 3897 * handle: Handle to receive mouse input. |
3850 */ | 3898 */ |
3851 void API dw_window_capture(HWND handle) | 3899 void API dw_window_capture(HWND handle) |
3852 { | 3900 { |
3853 SetCapture(handle); | 3901 SetCapture(handle); |
3854 } | 3902 } |
3855 | 3903 |
3856 /* | 3904 /* |
3857 * Releases previous mouse capture. | 3905 * Releases previous mouse capture. |
3858 */ | 3906 */ |
3859 void API dw_window_release(void) | 3907 void API dw_window_release(void) |
3860 { | 3908 { |
3861 ReleaseCapture(); | 3909 ReleaseCapture(); |
3862 } | 3910 } |
3863 | 3911 |
3864 /* | 3912 /* |
3865 * Changes the appearance of the mouse pointer. | 3913 * Changes the appearance of the mouse pointer. |
3866 * Parameters: | 3914 * Parameters: |
3867 * handle: Handle to widget for which to change. | 3915 * handle: Handle to widget for which to change. |
3868 * cursortype: ID of the pointer you want. | 3916 * cursortype: ID of the pointer you want. |
3869 */ | 3917 */ |
3870 void API dw_window_set_pointer(HWND handle, int pointertype) | 3918 void API dw_window_set_pointer(HWND handle, int pointertype) |
3871 { | 3919 { |
3872 HCURSOR cursor = pointertype < 65536 ? LoadCursor(NULL, MAKEINTRESOURCE(pointertype)) : (HCURSOR)pointertype; | 3920 HCURSOR cursor = pointertype < 65536 ? LoadCursor(NULL, MAKEINTRESOURCE(pointertype)) : (HCURSOR)pointertype; |
3873 | 3921 |
3874 if(!pointertype) | 3922 if(!pointertype) |
3875 dw_window_set_data(handle, "_dw_cursor", 0); | 3923 dw_window_set_data(handle, "_dw_cursor", 0); |
3876 else | 3924 else |
3877 { | 3925 { |
3878 dw_window_set_data(handle, "_dw_cursor", (void *)cursor); | 3926 dw_window_set_data(handle, "_dw_cursor", (void *)cursor); |
3879 SetCursor(cursor); | 3927 SetCursor(cursor); |
3880 } | 3928 } |
3881 } | 3929 } |
3882 | 3930 |
3883 /* | 3931 /* |
3884 * Create a new Window Frame. | 3932 * Create a new Window Frame. |
3885 * Parameters: | 3933 * Parameters: |
3887 * title: The Window title. | 3935 * title: The Window title. |
3888 * flStyle: Style flags, see the DW reference. | 3936 * flStyle: Style flags, see the DW reference. |
3889 */ | 3937 */ |
3890 HWND API dw_window_new(HWND hwndOwner, char *title, ULONG flStyle) | 3938 HWND API dw_window_new(HWND hwndOwner, char *title, ULONG flStyle) |
3891 { | 3939 { |
3892 HWND hwndframe; | 3940 HWND hwndframe; |
3893 Box *newbox = calloc(sizeof(Box), 1); | 3941 Box *newbox = calloc(sizeof(Box), 1); |
3894 ULONG flStyleEx = 0; | 3942 ULONG flStyleEx = 0; |
3895 | 3943 |
3896 newbox->pad = 0; | 3944 newbox->pad = 0; |
3897 newbox->type = DW_VERT; | 3945 newbox->type = DW_VERT; |
3898 newbox->count = 0; | 3946 newbox->count = 0; |
3899 newbox->cinfo.fore = newbox->cinfo.back = -1; | 3947 newbox->cinfo.fore = newbox->cinfo.back = -1; |
3900 | 3948 |
3901 /* Hmm, the "correct" way doesn't seem to be | 3949 /* Hmm, the "correct" way doesn't seem to be |
3902 * working, but the old hackish SetParent() | 3950 * working, but the old hackish SetParent() |
3903 * at the bottom seems to work, so I'll leave | 3951 * at the bottom seems to work, so I'll leave |
3904 * it like this for now. | 3952 * it like this for now. |
3905 */ | 3953 */ |
3906 #if 0 | 3954 #if 0 |
3907 if(hwndOwner) | 3955 if(hwndOwner) |
3908 flStyleEx |= WS_EX_MDICHILD; | 3956 flStyleEx |= WS_EX_MDICHILD; |
3909 #endif | 3957 #endif |
3910 | 3958 |
3911 if(!(flStyle & WS_CAPTION)) | 3959 if(!(flStyle & WS_CAPTION)) |
3912 flStyle |= WS_POPUPWINDOW; | 3960 flStyle |= WS_POPUPWINDOW; |
3913 | 3961 |
3914 if(flStyle & DW_FCF_TASKLIST) | 3962 if(flStyle & DW_FCF_TASKLIST) |
3915 { | 3963 { |
3916 ULONG newflags = (flStyle | WS_CLIPCHILDREN) & ~DW_FCF_TASKLIST; | 3964 ULONG newflags = (flStyle | WS_CLIPCHILDREN) & ~DW_FCF_TASKLIST; |
3917 | 3965 |
3918 hwndframe = CreateWindowEx(flStyleEx, ClassName, title, newflags, CW_USEDEFAULT, CW_USEDEFAULT, | 3966 hwndframe = CreateWindowEx(flStyleEx, ClassName, title, newflags, CW_USEDEFAULT, CW_USEDEFAULT, |
3919 CW_USEDEFAULT, CW_USEDEFAULT, hwndOwner, NULL, DWInstance, NULL); | 3967 CW_USEDEFAULT, CW_USEDEFAULT, hwndOwner, NULL, DWInstance, NULL); |
3920 } | 3968 } |
3921 else | 3969 else |
3922 { | 3970 { |
3923 flStyleEx |= WS_EX_TOOLWINDOW; | 3971 flStyleEx |= WS_EX_TOOLWINDOW; |
3924 | 3972 |
3925 hwndframe = CreateWindowEx(flStyleEx, ClassName, title, flStyle | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, | 3973 hwndframe = CreateWindowEx(flStyleEx, ClassName, title, flStyle | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, |
3926 CW_USEDEFAULT, CW_USEDEFAULT, hwndOwner, NULL, DWInstance, NULL); | 3974 CW_USEDEFAULT, CW_USEDEFAULT, hwndOwner, NULL, DWInstance, NULL); |
3927 } | 3975 } |
3928 SetWindowLongPtr(hwndframe, GWLP_USERDATA, (LONG_PTR)newbox); | 3976 SetWindowLongPtr(hwndframe, GWLP_USERDATA, (LONG_PTR)newbox); |
3929 | 3977 |
3930 if(hwndOwner) | 3978 if(hwndOwner) |
3931 SetParent(hwndframe, hwndOwner); | 3979 SetParent(hwndframe, hwndOwner); |
3932 | 3980 |
3933 return hwndframe; | 3981 return hwndframe; |
3934 } | 3982 } |
3935 | 3983 |
3936 /* | 3984 /* |
3937 * Create a new Box to be packed. | 3985 * Create a new Box to be packed. |
3938 * Parameters: | 3986 * Parameters: |
3939 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal). | 3987 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal). |
3940 * pad: Number of pixels to pad around the box. | 3988 * pad: Number of pixels to pad around the box. |
3941 */ | 3989 */ |
3942 HWND API dw_box_new(int type, int pad) | 3990 HWND API dw_box_new(int type, int pad) |
3943 { | 3991 { |
3944 Box *newbox = calloc(sizeof(Box), 1); | 3992 Box *newbox = calloc(sizeof(Box), 1); |
3945 HWND hwndframe; | 3993 HWND hwndframe; |
3946 | 3994 |
3947 newbox->pad = pad; | 3995 newbox->pad = pad; |
3948 newbox->type = type; | 3996 newbox->type = type; |
3949 newbox->count = 0; | 3997 newbox->count = 0; |
3950 newbox->grouphwnd = (HWND)NULL; | 3998 newbox->grouphwnd = (HWND)NULL; |
3951 newbox->cinfo.fore = newbox->cinfo.back = -1; | 3999 newbox->cinfo.fore = newbox->cinfo.back = -1; |
3952 | 4000 |
3953 hwndframe = CreateWindow(FRAMECLASSNAME, | 4001 hwndframe = CreateWindow(FRAMECLASSNAME, |
3954 "", | 4002 "", |
3955 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, | 4003 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, |
3956 0,0,2000,1000, | 4004 0,0,2000,1000, |
3957 DW_HWND_OBJECT, | 4005 DW_HWND_OBJECT, |
3958 NULL, | 4006 NULL, |
3959 DWInstance, | 4007 DWInstance, |
3960 NULL); | 4008 NULL); |
3961 | 4009 |
3962 newbox->cinfo.pOldProc = SubclassWindow(hwndframe, _colorwndproc); | 4010 newbox->cinfo.pOldProc = SubclassWindow(hwndframe, _colorwndproc); |
3963 newbox->cinfo.fore = newbox->cinfo.back = -1; | 4011 newbox->cinfo.fore = newbox->cinfo.back = -1; |
3964 | 4012 |
3965 SetWindowLongPtr(hwndframe, GWLP_USERDATA, (LONG_PTR)newbox); | 4013 SetWindowLongPtr(hwndframe, GWLP_USERDATA, (LONG_PTR)newbox); |
3966 return hwndframe; | 4014 return hwndframe; |
3967 } | 4015 } |
3968 | 4016 |
3969 /* | 4017 /* |
3970 * Create a new Group Box to be packed. | 4018 * Create a new Group Box to be packed. |
3971 * Parameters: | 4019 * Parameters: |
3973 * pad: Number of pixels to pad around the box. | 4021 * pad: Number of pixels to pad around the box. |
3974 * title: Text to be displayined in the group outline. | 4022 * title: Text to be displayined in the group outline. |
3975 */ | 4023 */ |
3976 HWND API dw_groupbox_new(int type, int pad, char *title) | 4024 HWND API dw_groupbox_new(int type, int pad, char *title) |
3977 { | 4025 { |
3978 Box *newbox = calloc(sizeof(Box), 1); | 4026 Box *newbox = calloc(sizeof(Box), 1); |
3979 HWND hwndframe; | 4027 HWND hwndframe; |
3980 | 4028 |
3981 newbox->pad = pad; | 4029 newbox->pad = pad; |
3982 newbox->type = type; | 4030 newbox->type = type; |
3983 newbox->count = 0; | 4031 newbox->count = 0; |
3984 newbox->cinfo.fore = newbox->cinfo.back = -1; | 4032 newbox->cinfo.fore = newbox->cinfo.back = -1; |
3985 | 4033 |
3986 hwndframe = CreateWindow(FRAMECLASSNAME, | 4034 hwndframe = CreateWindow(FRAMECLASSNAME, |
3987 "", | 4035 "", |
3988 WS_VISIBLE | WS_CHILD, | 4036 WS_VISIBLE | WS_CHILD, |
3989 0,0,2000,1000, | 4037 0,0,2000,1000, |
3990 DW_HWND_OBJECT, | 4038 DW_HWND_OBJECT, |
3991 NULL, | 4039 NULL, |
3992 DWInstance, | 4040 DWInstance, |
3993 NULL); | 4041 NULL); |
3994 | 4042 |
3995 newbox->grouphwnd = CreateWindow(BUTTONCLASSNAME, | 4043 newbox->grouphwnd = CreateWindow(BUTTONCLASSNAME, |
3996 title, | 4044 title, |
3997 WS_CHILD | BS_GROUPBOX | | 4045 WS_CHILD | BS_GROUPBOX | |
3998 WS_VISIBLE | WS_CLIPCHILDREN, | 4046 WS_VISIBLE | WS_CLIPCHILDREN, |
3999 0,0,2000,1000, | 4047 0,0,2000,1000, |
4000 hwndframe, | 4048 hwndframe, |
4001 NULL, | 4049 NULL, |
4002 DWInstance, | 4050 DWInstance, |
4003 NULL); | 4051 NULL); |
4004 | 4052 |
4005 SetWindowLongPtr(hwndframe, GWLP_USERDATA, (LONG_PTR)newbox); | 4053 SetWindowLongPtr(hwndframe, GWLP_USERDATA, (LONG_PTR)newbox); |
4006 dw_window_set_font(newbox->grouphwnd, DefaultFont); | 4054 dw_window_set_font(newbox->grouphwnd, DefaultFont); |
4007 return hwndframe; | 4055 return hwndframe; |
4008 } | 4056 } |
4009 | 4057 |
4010 /* | 4058 /* |
4011 * Create a new MDI Frame to be packed. | 4059 * Create a new MDI Frame to be packed. |
4012 * Parameters: | 4060 * Parameters: |
4013 * id: An ID to be used with dw_window_from_id or 0L. | 4061 * id: An ID to be used with dw_window_from_id or 0L. |
4014 */ | 4062 */ |
4015 HWND API dw_mdi_new(unsigned long id) | 4063 HWND API dw_mdi_new(unsigned long id) |
4016 { | 4064 { |
4017 CLIENTCREATESTRUCT ccs; | 4065 CLIENTCREATESTRUCT ccs; |
4018 HWND hwndframe; | 4066 HWND hwndframe; |
4019 | 4067 |
4020 ccs.hWindowMenu = NULL; | 4068 ccs.hWindowMenu = NULL; |
4021 ccs.idFirstChild = 0; | 4069 ccs.idFirstChild = 0; |
4022 | 4070 |
4023 hwndframe = CreateWindow("MDICLIENT", | 4071 hwndframe = CreateWindow("MDICLIENT", |
4024 "", | 4072 "", |
4025 WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS, | 4073 WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS, |
4026 0,0,2000,1000, | 4074 0,0,2000,1000, |
4027 DW_HWND_OBJECT, | 4075 DW_HWND_OBJECT, |
4028 (HMENU)id, | 4076 (HMENU)id, |
4029 DWInstance, | 4077 DWInstance, |
4030 &ccs); | 4078 &ccs); |
4031 return hwndframe; | 4079 return hwndframe; |
4032 } | 4080 } |
4033 | 4081 |
4034 /* | 4082 /* |
4035 * Create a new HTML browser frame to be packed. | 4083 * Create a new HTML browser frame to be packed. |
4036 * Parameters: | 4084 * Parameters: |
4037 * id: An ID to be used with dw_window_from_id or 0L. | 4085 * id: An ID to be used with dw_window_from_id or 0L. |
4038 */ | 4086 */ |
4039 HWND API dw_html_new(unsigned long id) | 4087 HWND API dw_html_new(unsigned long id) |
4040 { | 4088 { |
4041 return CreateWindow(BrowserClassName, | 4089 return CreateWindow(BrowserClassName, |
4042 "", | 4090 "", |
4043 WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS, | 4091 WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS, |
4044 0,0,2000,1000, | 4092 0,0,2000,1000, |
4045 DW_HWND_OBJECT, | 4093 DW_HWND_OBJECT, |
4046 (HMENU)id, | 4094 (HMENU)id, |
4047 DWInstance, | 4095 DWInstance, |
4048 NULL); | 4096 NULL); |
4049 } | 4097 } |
4050 | 4098 |
4051 /* | 4099 /* |
4052 * Create a bitmap object to be packed. | 4100 * Create a bitmap object to be packed. |
4053 * Parameters: | 4101 * Parameters: |
4054 * id: An ID to be used with dw_window_from_id or 0L. | 4102 * id: An ID to be used with dw_window_from_id or 0L. |
4055 */ | 4103 */ |
4056 HWND API dw_bitmap_new(ULONG id) | 4104 HWND API dw_bitmap_new(ULONG id) |
4057 { | 4105 { |
4058 return CreateWindow(STATICCLASSNAME, | 4106 return CreateWindow(STATICCLASSNAME, |
4059 "", | 4107 "", |
4060 SS_BITMAP | WS_VISIBLE | | 4108 SS_BITMAP | WS_VISIBLE | |
4061 WS_CHILD | WS_CLIPCHILDREN, | 4109 WS_CHILD | WS_CLIPCHILDREN, |
4062 0,0,2000,1000, | 4110 0,0,2000,1000, |
4063 DW_HWND_OBJECT, | 4111 DW_HWND_OBJECT, |
4064 (HMENU)id, | 4112 (HMENU)id, |
4065 DWInstance, | 4113 DWInstance, |
4066 NULL); | 4114 NULL); |
4067 } | 4115 } |
4068 | 4116 |
4069 /* | 4117 /* |
4070 * Create a notebook object to be packed. | 4118 * Create a notebook object to be packed. |
4071 * Parameters: | 4119 * Parameters: |
4072 * id: An ID to be used for getting the resource from the | 4120 * id: An ID to be used for getting the resource from the |
4073 * resource file. | 4121 * resource file. |
4074 */ | 4122 */ |
4075 HWND API dw_notebook_new(ULONG id, int top) | 4123 HWND API dw_notebook_new(ULONG id, int top) |
4076 { | 4124 { |
4077 ULONG flags = 0; | 4125 ULONG flags = 0; |
4078 HWND tmp; | 4126 HWND tmp; |
4079 NotebookPage **array = calloc(256, sizeof(NotebookPage *)); | 4127 NotebookPage **array = calloc(256, sizeof(NotebookPage *)); |
4080 | 4128 |
4081 if(!top) | 4129 if(!top) |
4082 flags = TCS_BOTTOM; | 4130 flags = TCS_BOTTOM; |
4083 | 4131 |
4084 tmp = CreateWindow(WC_TABCONTROL, | 4132 tmp = CreateWindow(WC_TABCONTROL, |
4085 "", | 4133 "", |
4086 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | flags, | 4134 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | flags, |
4087 0,0,2000,1000, | 4135 0,0,2000,1000, |
4088 DW_HWND_OBJECT, | 4136 DW_HWND_OBJECT, |
4089 (HMENU)id, | 4137 (HMENU)id, |
4090 DWInstance, | 4138 DWInstance, |
4091 NULL); | 4139 NULL); |
4092 dw_window_set_data(tmp, "_dw_array", (void *)array); | 4140 dw_window_set_data(tmp, "_dw_array", (void *)array); |
4093 dw_window_set_font(tmp, DefaultFont); | 4141 dw_window_set_font(tmp, DefaultFont); |
4094 return tmp; | 4142 return tmp; |
4095 } | 4143 } |
4096 | 4144 |
4097 /* | 4145 /* |
4098 * Create a menu object to be popped up. | 4146 * Create a menu object to be popped up. |
4099 * Parameters: | 4147 * Parameters: |
4100 * id: An ID to be used for getting the resource from the | 4148 * id: An ID to be used for getting the resource from the |
4101 * resource file. | 4149 * resource file. |
4102 */ | 4150 */ |
4103 HMENUI API dw_menu_new(ULONG id) | 4151 HMENUI API dw_menu_new(ULONG id) |
4104 { | 4152 { |
4105 return (HMENUI)CreatePopupMenu(); | 4153 return (HMENUI)CreatePopupMenu(); |
4106 } | 4154 } |
4107 | 4155 |
4108 /* | 4156 /* |
4109 * Create a menubar on a window. | 4157 * Create a menubar on a window. |
4110 * Parameters: | 4158 * Parameters: |
4111 * location: Handle of a window frame to be attached to. | 4159 * location: Handle of a window frame to be attached to. |
4112 */ | 4160 */ |
4113 HMENUI API dw_menubar_new(HWND location) | 4161 HMENUI API dw_menubar_new(HWND location) |
4114 { | 4162 { |
4115 HMENUI tmp; | 4163 HMENUI tmp; |
4116 | 4164 |
4117 tmp = (HMENUI)CreateMenu(); | 4165 tmp = (HMENUI)CreateMenu(); |
4118 | 4166 |
4119 if(!IS_WINNTOR95) | 4167 if (!IS_WINNTOR95) |
4120 { | 4168 { |
4121 MENUINFO mi; | 4169 MENUINFO mi; |
4122 | 4170 |
4123 mi.cbSize = sizeof(MENUINFO); | 4171 mi.cbSize = sizeof(MENUINFO); |
4124 mi.fMask = MIM_MENUDATA; | 4172 mi.fMask = MIM_MENUDATA; |
4125 mi.dwMenuData = (ULONG_PTR)1; | 4173 mi.dwMenuData = (ULONG_PTR)1; |
4126 | 4174 |
4127 MySetMenuInfo((HMENU)tmp, &mi); | 4175 MySetMenuInfo( (HMENU)tmp, &mi ); |
4128 } | 4176 } |
4129 | 4177 |
4130 dw_window_set_data(location, "_dw_menu", (void *)tmp); | 4178 dw_window_set_data(location, "_dw_menu", (void *)tmp); |
4131 | 4179 |
4132 SetMenu(location, (HMENU)tmp); | 4180 SetMenu(location, (HMENU)tmp); |
4133 return location; | 4181 return location; |
4134 } | 4182 } |
4135 | 4183 |
4136 /* | 4184 /* |
4137 * Destroys a menu created with dw_menubar_new or dw_menu_new. | 4185 * Destroys a menu created with dw_menubar_new or dw_menu_new. |
4138 * Parameters: | 4186 * Parameters: |
4139 * menu: Handle of a menu. | 4187 * menu: Handle of a menu. |
4140 */ | 4188 */ |
4141 void API dw_menu_destroy(HMENUI *menu) | 4189 void API dw_menu_destroy(HMENUI *menu) |
4142 { | 4190 { |
4143 if(menu) | 4191 if(menu) |
4144 { | 4192 { |
4145 HMENU mymenu = (HMENU)*menu; | 4193 HMENU mymenu = (HMENU)*menu; |
4146 | 4194 |
4147 if(IsWindow((HWND)mymenu) && !IsMenu(mymenu)) | 4195 if(IsWindow((HWND)mymenu) && !IsMenu(mymenu)) |
4148 mymenu = (HMENU)dw_window_get_data((HWND)mymenu, "_dw_menu"); | 4196 mymenu = (HMENU)dw_window_get_data((HWND)mymenu, "_dw_menu"); |
4149 if(IsMenu(mymenu)) | 4197 if(IsMenu(mymenu)) |
4150 DestroyMenu(mymenu); | 4198 DestroyMenu(mymenu); |
4151 } | 4199 } |
4152 } | 4200 } |
4153 | 4201 |
4154 /* | 4202 /* |
4155 * Adds a menuitem or submenu to an existing menu. | 4203 * Adds a menuitem or submenu to an existing menu. |
4156 * Parameters: | 4204 * Parameters: |
4162 * flags: Extended attributes to set on the menu. | 4210 * flags: Extended attributes to set on the menu. |
4163 * submenu: Handle to an existing menu to be a submenu or NULL. | 4211 * submenu: Handle to an existing menu to be a submenu or NULL. |
4164 */ | 4212 */ |
4165 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG id, ULONG flags, int end, int check, HMENUI submenu) | 4213 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG id, ULONG flags, int end, int check, HMENUI submenu) |
4166 { | 4214 { |
4167 MENUITEMINFO mii; | 4215 MENUITEMINFO mii; |
4168 HMENU mymenu = (HMENU)menux; | 4216 HMENU mymenu = (HMENU)menux; |
4169 char buffer[15]; | 4217 char buffer[30]; |
4170 | 4218 int is_checked, is_disabled; |
4171 if(IsWindow(menux) && !IsMenu(mymenu)) | 4219 |
4172 mymenu = (HMENU)dw_window_get_data(menux, "_dw_menu"); | 4220 /* |
4173 | 4221 * Check if this is a menubar; if so get the menu object |
4174 mii.cbSize = sizeof(MENUITEMINFO); | 4222 * for the menubar |
4175 mii.fMask = MIIM_ID | MIIM_SUBMENU | MIIM_TYPE; | 4223 */ |
4176 | 4224 if (IsWindow(menux) && !IsMenu(mymenu)) |
4177 /* Convert from OS/2 style accellerators to Win32 style */ | 4225 mymenu = (HMENU)dw_window_get_data(menux, "_dw_menu"); |
4178 if(title) | 4226 |
4179 { | 4227 memset( &mii, 0, sizeof(mii) ); |
4180 char *tmp = title; | 4228 mii.cbSize = sizeof(MENUITEMINFO); |
4181 | 4229 mii.fMask = MIIM_ID | MIIM_SUBMENU | MIIM_TYPE | MIIM_STATE; |
4182 while(*tmp) | 4230 |
4183 { | 4231 /* Convert from OS/2 style accellerators to Win32 style */ |
4184 if(*tmp == '~') | 4232 if (title) |
4185 *tmp = '&'; | 4233 { |
4186 tmp++; | 4234 char *tmp = title; |
4187 } | 4235 |
4188 } | 4236 while(*tmp) |
4189 | 4237 { |
4190 if(title && *title) | 4238 if(*tmp == '~') |
4191 mii.fType = MFT_STRING; | 4239 *tmp = '&'; |
4192 else | 4240 tmp++; |
4193 mii.fType = MFT_SEPARATOR; | 4241 } |
4194 | 4242 } |
4195 mii.wID = id; | 4243 |
4196 if(IsMenu((HMENU)submenu)) | 4244 if (title && *title) |
4197 mii.hSubMenu = (HMENU)submenu; | 4245 mii.fType = MFT_STRING; |
4198 else | 4246 else |
4199 mii.hSubMenu = 0; | 4247 mii.fType = MFT_SEPARATOR; |
4200 mii.dwTypeData = title; | 4248 |
4201 mii.cch = strlen(title); | 4249 /* |
4202 | 4250 * Handle flags |
4203 InsertMenuItem(mymenu, 65535, TRUE, &mii); | 4251 */ |
4204 | 4252 is_checked = (flags & DW_MIS_CHECKED) ? 1 : 0; |
4205 if(!IS_WINNTOR95) | 4253 if ( is_checked ) |
4206 { | 4254 mii.fState |= MFS_CHECKED; |
4207 sprintf(buffer, "_dw_id%ld", id); | 4255 else |
4208 dw_window_set_data(DW_HWND_OBJECT, buffer, (void *)mymenu); | 4256 mii.fState |= MFS_UNCHECKED; |
4209 | 4257 is_disabled = (flags & DW_MIS_DISABLED) ? 1 : 0; |
4210 /* According to the docs this will only work on Win2k/98 and above */ | 4258 if ( is_disabled ) |
4211 if(submenu) | 4259 mii.fState |= MFS_DISABLED; |
4212 { | 4260 else |
4213 MENUINFO mi; | 4261 mii.fState |= MFS_ENABLED; |
4214 | 4262 |
4215 mi.cbSize = sizeof(MENUINFO); | 4263 mii.wID = id; |
4216 mi.fMask = MIM_MENUDATA; | 4264 if (IsMenu((HMENU)submenu)) |
4217 mi.dwMenuData = (ULONG_PTR)mymenu; | 4265 mii.hSubMenu = (HMENU)submenu; |
4218 | 4266 else |
4219 MySetMenuInfo((HMENU)submenu, &mi); | 4267 mii.hSubMenu = 0; |
4220 } | 4268 mii.dwTypeData = title; |
4221 } | 4269 mii.cch = strlen(title); |
4222 | 4270 |
4223 if(IsWindow(menux) && !IsMenu((HMENU)menux)) | 4271 InsertMenuItem(mymenu, 65535, TRUE, &mii); |
4224 DrawMenuBar(menux); | 4272 |
4225 return (HWND)id; | 4273 sprintf(buffer, "_dw_id%ld", id); |
4274 dw_window_set_data( DW_HWND_OBJECT, buffer, (void *)mymenu ); | |
4275 sprintf(buffer, "_dw_checkable%ld", id); | |
4276 dw_window_set_data( DW_HWND_OBJECT, buffer, (void *)check ); | |
4277 sprintf(buffer, "_dw_ischecked%ld", id); | |
4278 dw_window_set_data( DW_HWND_OBJECT, buffer, (void *)is_checked ); | |
4279 sprintf(buffer, "_dw_isdisabled%ld", id); | |
4280 dw_window_set_data( DW_HWND_OBJECT, buffer, (void *)is_disabled ); | |
4281 | |
4282 if (!IS_WINNTOR95) | |
4283 { | |
4284 /* According to the docs this will only work on Win2k/98 and above */ | |
4285 if (submenu) | |
4286 { | |
4287 MENUINFO mi; | |
4288 | |
4289 mi.cbSize = sizeof(MENUINFO); | |
4290 mi.fMask = MIM_MENUDATA; | |
4291 mi.dwMenuData = (ULONG_PTR)mymenu; | |
4292 | |
4293 MySetMenuInfo( (HMENU)submenu, &mi ); | |
4294 } | |
4295 } | |
4296 | |
4297 if (IsWindow(menux) && !IsMenu((HMENU)menux)) | |
4298 DrawMenuBar(menux); | |
4299 return (HWND)id; | |
4226 } | 4300 } |
4227 | 4301 |
4228 /* | 4302 /* |
4229 * Sets the state of a menu item check. | 4303 * Sets the state of a menu item check. |
4304 * Deprecated: use dw_menu_item_set_state() | |
4230 * Parameters: | 4305 * Parameters: |
4231 * menu: The handle to the existing menu. | 4306 * menu: The handle to the existing menu. |
4232 * id: Menuitem id. | 4307 * id: Menuitem id. |
4233 * check: TRUE for checked FALSE for not checked. | 4308 * check: TRUE for checked FALSE for not checked. |
4234 */ | 4309 */ |
4235 void API dw_menu_item_set_check(HMENUI menux, unsigned long id, int check) | 4310 void API dw_menu_item_set_check(HMENUI menux, unsigned long id, int check) |
4236 { | 4311 { |
4237 MENUITEMINFO mii; | 4312 MENUITEMINFO mii; |
4238 HMENU mymenu = (HMENU)menux; | 4313 HMENU mymenu = (HMENU)menux; |
4314 char buffer[30]; | |
4239 | 4315 |
4240 if (IsWindow(menux) && !IsMenu(mymenu)) | 4316 if (IsWindow(menux) && !IsMenu(mymenu)) |
4241 mymenu = (HMENU)dw_window_get_data(menux, "_dw_menu"); | 4317 mymenu = (HMENU)dw_window_get_data(menux, "_dw_menu"); |
4242 | 4318 |
4243 memset( &mii, 0, sizeof(MENUITEMINFO) ); | 4319 /* |
4320 * Get the current state of the menu item in case it already has some other state set on it | |
4321 */ | |
4322 memset( &mii, 0, sizeof(mii) ); | |
4323 GetMenuItemInfo( mymenu, id, FALSE, &mii); | |
4324 | |
4244 mii.cbSize = sizeof(MENUITEMINFO); | 4325 mii.cbSize = sizeof(MENUITEMINFO); |
4245 mii.fMask = MIIM_STATE; | 4326 mii.fMask = MIIM_STATE | MIIM_CHECKMARKS; |
4246 if (check) | 4327 if (check) |
4247 mii.fState = MFS_CHECKED; | 4328 mii.fState |= MFS_CHECKED; |
4248 else | 4329 else |
4249 mii.fState = MFS_UNCHECKED; | 4330 mii.fState |= MFS_UNCHECKED; |
4250 SetMenuItemInfo( mymenu, id, FALSE, &mii ); | 4331 SetMenuItemInfo( mymenu, id, FALSE, &mii ); |
4332 /* | |
4333 * Keep our internal state consistent | |
4334 */ | |
4335 sprintf( buffer, "_dw_ischecked%ld", id ); | |
4336 dw_window_set_data( DW_HWND_OBJECT, buffer, (void *)check ); | |
4337 } | |
4338 | |
4339 /* | |
4340 * Sets the state of a menu item. | |
4341 * Parameters: | |
4342 * menu: The handle to the existing menu. | |
4343 * id: Menuitem id. | |
4344 * flags: DW_MIS_ENABLED/DW_MIS_DISABLED | |
4345 * DW_MIS_CHECKED/DW_MIS_UNCHECKED | |
4346 */ | |
4347 void API dw_menu_item_set_state( HMENUI menux, unsigned long id, unsigned long state) | |
4348 { | |
4349 MENUITEMINFO mii; | |
4350 HMENU mymenu = (HMENU)menux; | |
4351 char buffer1[30],buffer2[30]; | |
4352 int check; | |
4353 int disabled; | |
4354 | |
4355 if (IsWindow(menux) && !IsMenu(mymenu)) | |
4356 mymenu = (HMENU)dw_window_get_data(menux, "_dw_menu"); | |
4357 | |
4358 sprintf( buffer1, "_dw_ischecked%ld", id ); | |
4359 check = (int)dw_window_get_data( DW_HWND_OBJECT, buffer1 ); | |
4360 sprintf( buffer2, "_dw_isdisabled%ld", id ); | |
4361 disabled = (int)dw_window_get_data( DW_HWND_OBJECT, buffer2 ); | |
4362 | |
4363 memset( &mii, 0, sizeof(mii) ); | |
4364 | |
4365 mii.cbSize = sizeof(MENUITEMINFO); | |
4366 mii.fMask = MIIM_STATE | MIIM_CHECKMARKS; | |
4367 if ( (state & DW_MIS_CHECKED) || (state & DW_MIS_UNCHECKED) ) | |
4368 { | |
4369 /* | |
4370 * If we are changing state of "checked" base our setting on the passed flag... | |
4371 */ | |
4372 if ( state & DW_MIS_CHECKED ) | |
4373 { | |
4374 mii.fState |= MFS_CHECKED; | |
4375 check = 1; | |
4376 } | |
4377 else | |
4378 { | |
4379 mii.fState |= MFS_UNCHECKED; | |
4380 check = 0; | |
4381 } | |
4382 } | |
4383 else | |
4384 { | |
4385 /* | |
4386 * ...otherwise base our setting on the current "checked" state. | |
4387 */ | |
4388 if ( check ) | |
4389 { | |
4390 mii.fState |= MFS_CHECKED; | |
4391 } | |
4392 else | |
4393 { | |
4394 mii.fState |= MFS_UNCHECKED; | |
4395 } | |
4396 } | |
4397 if ( (state & DW_MIS_ENABLED) || (state & DW_MIS_DISABLED) ) | |
4398 { | |
4399 if ( state & DW_MIS_DISABLED ) | |
4400 { | |
4401 mii.fState |= MFS_DISABLED; | |
4402 disabled = 1; | |
4403 } | |
4404 else | |
4405 { | |
4406 mii.fState |= MFS_ENABLED; | |
4407 disabled = 0; | |
4408 } | |
4409 } | |
4410 else | |
4411 { | |
4412 /* | |
4413 * ...otherwise base our setting on the current "checked" state. | |
4414 */ | |
4415 if ( disabled ) | |
4416 { | |
4417 mii.fState |= MFS_DISABLED; | |
4418 } | |
4419 else | |
4420 { | |
4421 mii.fState |= MFS_ENABLED; | |
4422 } | |
4423 } | |
4424 SetMenuItemInfo( mymenu, id, FALSE, &mii ); | |
4425 /* | |
4426 * Keep our internal checked state consistent | |
4427 */ | |
4428 dw_window_set_data( DW_HWND_OBJECT, buffer1, (void *)check ); | |
4429 dw_window_set_data( DW_HWND_OBJECT, buffer2, (void *)disabled ); | |
4251 } | 4430 } |
4252 | 4431 |
4253 #if 0 | 4432 #if 0 |
4254 /* | 4433 /* |
4255 * TBD | 4434 * TBD |
4258 * menu: The handle to the menu in which the item was appended. | 4437 * menu: The handle to the menu in which the item was appended. |
4259 * id: Menuitem id. | 4438 * id: Menuitem id. |
4260 */ | 4439 */ |
4261 void API dw_menu_delete_item(HMENUI menux, unsigned long id) | 4440 void API dw_menu_delete_item(HMENUI menux, unsigned long id) |
4262 { | 4441 { |
4263 HMENU mymenu = (HMENU)menux; | 4442 HMENU mymenu = (HMENU)menux; |
4264 | 4443 |
4265 if(IsWindow(menux) && !IsMenu(mymenu)) | 4444 if(IsWindow(menux) && !IsMenu(mymenu)) |
4266 mymenu = (HMENU)dw_window_get_data(menux, "_dw_menu"); | 4445 mymenu = (HMENU)dw_window_get_data(menux, "_dw_menu"); |
4267 | 4446 |
4268 DeleteMenu(mymenu, id, MF_BYCOMMAND); | 4447 DeleteMenu(mymenu, id, MF_BYCOMMAND); |
4269 DrawMenuBar(menux); | 4448 DrawMenuBar(menux); |
4270 } | 4449 } |
4271 #endif | 4450 #endif |
4272 | 4451 |
4273 /* | 4452 /* |
4274 * Pops up a context menu at given x and y coordinates. | 4453 * Pops up a context menu at given x and y coordinates. |
4278 * x: X coordinate. | 4457 * x: X coordinate. |
4279 * y: Y coordinate. | 4458 * y: Y coordinate. |
4280 */ | 4459 */ |
4281 void API dw_menu_popup(HMENUI *menu, HWND parent, int x, int y) | 4460 void API dw_menu_popup(HMENUI *menu, HWND parent, int x, int y) |
4282 { | 4461 { |
4283 if(menu) | 4462 if(menu) |
4284 { | 4463 { |
4285 HMENU mymenu = (HMENU)*menu; | 4464 HMENU mymenu = (HMENU)*menu; |
4286 | 4465 |
4287 if(IsWindow(*menu) && !IsMenu(mymenu)) | 4466 if(IsWindow(*menu) && !IsMenu(mymenu)) |
4288 mymenu = (HMENU)dw_window_get_data(*menu, "_dw_menu"); | 4467 mymenu = (HMENU)dw_window_get_data(*menu, "_dw_menu"); |
4289 | 4468 |
4290 popup = parent; | 4469 popup = parent; |
4291 TrackPopupMenu(mymenu, 0, x, y, 0, parent, NULL); | 4470 TrackPopupMenu(mymenu, 0, x, y, 0, parent, NULL); |
4292 PostMessage(DW_HWND_OBJECT, WM_USER+5, (LPARAM)mymenu, 0); | 4471 PostMessage(DW_HWND_OBJECT, WM_USER+5, (LPARAM)mymenu, 0); |
4293 } | 4472 } |
4294 } | 4473 } |
4295 | 4474 |
4296 | 4475 |
4297 /* | 4476 /* |
4298 * Create a container object to be packed. | 4477 * Create a container object to be packed. |
4300 * id: An ID to be used for getting the resource from the | 4479 * id: An ID to be used for getting the resource from the |
4301 * resource file. | 4480 * resource file. |
4302 */ | 4481 */ |
4303 HWND API dw_container_new(ULONG id, int multi) | 4482 HWND API dw_container_new(ULONG id, int multi) |
4304 { | 4483 { |
4305 HWND tmp = CreateWindow(WC_LISTVIEW, | 4484 HWND tmp = CreateWindow(WC_LISTVIEW, |
4306 "", | 4485 "", |
4307 WS_VISIBLE | WS_CHILD | | 4486 WS_VISIBLE | WS_CHILD | |
4308 (multi ? 0 : LVS_SINGLESEL) | | 4487 (multi ? 0 : LVS_SINGLESEL) | |
4309 LVS_REPORT | LVS_SHOWSELALWAYS | | 4488 LVS_REPORT | LVS_SHOWSELALWAYS | |
4310 LVS_SHAREIMAGELISTS | WS_BORDER | | 4489 LVS_SHAREIMAGELISTS | WS_BORDER | |
4311 WS_CLIPCHILDREN, | 4490 WS_CLIPCHILDREN, |
4312 0,0,2000,1000, | 4491 0,0,2000,1000, |
4313 DW_HWND_OBJECT, | 4492 DW_HWND_OBJECT, |
4314 (HMENU)id, | 4493 (HMENU)id, |
4315 DWInstance, | 4494 DWInstance, |
4316 NULL); | 4495 NULL); |
4317 ContainerInfo *cinfo = (ContainerInfo *)calloc(1, sizeof(ContainerInfo)); | 4496 ContainerInfo *cinfo = (ContainerInfo *)calloc(1, sizeof(ContainerInfo)); |
4318 | 4497 |
4319 if(!cinfo) | 4498 if(!cinfo) |
4320 { | 4499 { |
4321 DestroyWindow(tmp); | 4500 DestroyWindow(tmp); |
4322 return NULL; | 4501 return NULL; |
4323 } | 4502 } |
4324 | 4503 |
4325 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _containerwndproc); | 4504 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _containerwndproc); |
4326 cinfo->cinfo.fore = cinfo->cinfo.back = -1; | 4505 cinfo->cinfo.fore = cinfo->cinfo.back = -1; |
4327 | 4506 |
4328 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); | 4507 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); |
4329 dw_window_set_font(tmp, DefaultFont); | 4508 dw_window_set_font(tmp, DefaultFont); |
4330 return tmp; | 4509 return tmp; |
4331 } | 4510 } |
4332 | 4511 |
4333 /* | 4512 /* |
4334 * Create a tree object to be packed. | 4513 * Create a tree object to be packed. |
4335 * Parameters: | 4514 * Parameters: |
4336 * id: An ID to be used for getting the resource from the | 4515 * id: An ID to be used for getting the resource from the |
4337 * resource file. | 4516 * resource file. |
4338 */ | 4517 */ |
4339 HWND API dw_tree_new(ULONG id) | 4518 HWND API dw_tree_new(ULONG id) |
4340 { | 4519 { |
4341 HWND tmp = CreateWindow(WC_TREEVIEW, | 4520 HWND tmp = CreateWindow(WC_TREEVIEW, |
4342 "", | 4521 "", |
4343 WS_VISIBLE | WS_CHILD | | 4522 WS_VISIBLE | WS_CHILD | |
4344 TVS_HASLINES | TVS_SHOWSELALWAYS | | 4523 TVS_HASLINES | TVS_SHOWSELALWAYS | |
4345 TVS_HASBUTTONS | TVS_LINESATROOT | | 4524 TVS_HASBUTTONS | TVS_LINESATROOT | |
4346 WS_BORDER | WS_CLIPCHILDREN, | 4525 WS_BORDER | WS_CLIPCHILDREN, |
4347 0,0,2000,1000, | 4526 0,0,2000,1000, |
4348 DW_HWND_OBJECT, | 4527 DW_HWND_OBJECT, |
4349 (HMENU)id, | 4528 (HMENU)id, |
4350 DWInstance, | 4529 DWInstance, |
4351 NULL); | 4530 NULL); |
4352 ContainerInfo *cinfo = (ContainerInfo *)calloc(1, sizeof(ContainerInfo)); | 4531 ContainerInfo *cinfo = (ContainerInfo *)calloc(1, sizeof(ContainerInfo)); |
4353 TreeView_SetItemHeight(tmp, 16); | 4532 TreeView_SetItemHeight(tmp, 16); |
4354 | 4533 |
4355 if(!cinfo) | 4534 if(!cinfo) |
4356 { | 4535 { |
4357 DestroyWindow(tmp); | 4536 DestroyWindow(tmp); |
4358 return NULL; | 4537 return NULL; |
4359 } | 4538 } |
4360 | 4539 |
4361 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _treewndproc); | 4540 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _treewndproc); |
4362 cinfo->cinfo.fore = cinfo->cinfo.back = -1; | 4541 cinfo->cinfo.fore = cinfo->cinfo.back = -1; |
4363 | 4542 |
4364 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); | 4543 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); |
4365 dw_window_set_font(tmp, DefaultFont); | 4544 dw_window_set_font(tmp, DefaultFont); |
4366 return tmp; | 4545 return tmp; |
4367 } | 4546 } |
4368 | 4547 |
4369 /* | 4548 /* |
4370 * Returns the current X and Y coordinates of the mouse pointer. | 4549 * Returns the current X and Y coordinates of the mouse pointer. |
4371 * Parameters: | 4550 * Parameters: |
4372 * x: Pointer to variable to store X coordinate. | 4551 * x: Pointer to variable to store X coordinate. |
4373 * y: Pointer to variable to store Y coordinate. | 4552 * y: Pointer to variable to store Y coordinate. |
4374 */ | 4553 */ |
4375 void API dw_pointer_query_pos(long *x, long *y) | 4554 void API dw_pointer_query_pos(long *x, long *y) |
4376 { | 4555 { |
4377 POINT ptl; | 4556 POINT ptl; |
4378 | 4557 |
4379 GetCursorPos(&ptl); | 4558 GetCursorPos(&ptl); |
4380 if(x && y) | 4559 if(x && y) |
4381 { | 4560 { |
4382 *x = ptl.x; | 4561 *x = ptl.x; |
4383 *y = ptl.y; | 4562 *y = ptl.y; |
4384 } | 4563 } |
4385 } | 4564 } |
4386 | 4565 |
4387 /* | 4566 /* |
4388 * Sets the X and Y coordinates of the mouse pointer. | 4567 * Sets the X and Y coordinates of the mouse pointer. |
4389 * Parameters: | 4568 * Parameters: |
4390 * x: X coordinate. | 4569 * x: X coordinate. |
4391 * y: Y coordinate. | 4570 * y: Y coordinate. |
4392 */ | 4571 */ |
4393 void API dw_pointer_set_pos(long x, long y) | 4572 void API dw_pointer_set_pos(long x, long y) |
4394 { | 4573 { |
4395 SetCursorPos(x, y); | 4574 SetCursorPos(x, y); |
4396 } | 4575 } |
4397 | 4576 |
4398 /* | 4577 /* |
4399 * Create a new static text window (widget) to be packed. | 4578 * Create a new static text window (widget) to be packed. |
4400 * Parameters: | 4579 * Parameters: |
4401 * text: The text to be display by the static text widget. | 4580 * text: The text to be display by the static text widget. |
4402 * id: An ID to be used with dw_window_from_id() or 0L. | 4581 * id: An ID to be used with dw_window_from_id() or 0L. |
4403 */ | 4582 */ |
4404 HWND API dw_text_new(char *text, ULONG id) | 4583 HWND API dw_text_new(char *text, ULONG id) |
4405 { | 4584 { |
4406 HWND tmp = CreateWindow(STATICCLASSNAME, | 4585 HWND tmp = CreateWindow(STATICCLASSNAME, |
4407 text, | 4586 text, |
4408 BS_TEXT | WS_VISIBLE | | 4587 BS_TEXT | WS_VISIBLE | |
4409 WS_CHILD | WS_CLIPCHILDREN, | 4588 WS_CHILD | WS_CLIPCHILDREN, |
4410 0,0,2000,1000, | 4589 0,0,2000,1000, |
4411 DW_HWND_OBJECT, | 4590 DW_HWND_OBJECT, |
4412 (HMENU)id, | 4591 (HMENU)id, |
4413 DWInstance, | 4592 DWInstance, |
4414 NULL); | 4593 NULL); |
4415 dw_window_set_font(tmp, DefaultFont); | 4594 dw_window_set_font(tmp, DefaultFont); |
4416 return tmp; | 4595 return tmp; |
4417 } | 4596 } |
4418 | 4597 |
4419 /* | 4598 /* |
4420 * Create a new status text window (widget) to be packed. | 4599 * Create a new status text window (widget) to be packed. |
4421 * Parameters: | 4600 * Parameters: |
4422 * text: The text to be display by the static text widget. | 4601 * text: The text to be display by the static text widget. |
4423 * id: An ID to be used with dw_window_from_id() or 0L. | 4602 * id: An ID to be used with dw_window_from_id() or 0L. |
4424 */ | 4603 */ |
4425 HWND API dw_status_text_new(char *text, ULONG id) | 4604 HWND API dw_status_text_new(char *text, ULONG id) |
4426 { | 4605 { |
4427 HWND tmp = CreateWindow(ObjectClassName, | 4606 HWND tmp = CreateWindow(ObjectClassName, |
4428 text, | 4607 text, |
4429 BS_TEXT | WS_VISIBLE | | 4608 BS_TEXT | WS_VISIBLE | |
4430 WS_CHILD | WS_CLIPCHILDREN, | 4609 WS_CHILD | WS_CLIPCHILDREN, |
4431 0,0,2000,1000, | 4610 0,0,2000,1000, |
4432 DW_HWND_OBJECT, | 4611 DW_HWND_OBJECT, |
4433 (HMENU)id, | 4612 (HMENU)id, |
4434 DWInstance, | 4613 DWInstance, |
4435 NULL); | 4614 NULL); |
4436 dw_window_set_font(tmp, DefaultFont); | 4615 dw_window_set_font(tmp, DefaultFont); |
4437 SubclassWindow(tmp, _statuswndproc); | 4616 SubclassWindow(tmp, _statuswndproc); |
4438 return tmp; | 4617 return tmp; |
4439 } | 4618 } |
4440 | 4619 |
4441 /* | 4620 /* |
4442 * Create a new Multiline Editbox window (widget) to be packed. | 4621 * Create a new Multiline Editbox window (widget) to be packed. |
4443 * Parameters: | 4622 * Parameters: |
4444 * id: An ID to be used with dw_window_from_id() or 0L. | 4623 * id: An ID to be used with dw_window_from_id() or 0L. |
4445 */ | 4624 */ |
4446 HWND API dw_mle_new(ULONG id) | 4625 HWND API dw_mle_new(ULONG id) |
4447 { | 4626 { |
4448 | 4627 |
4449 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, | 4628 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, |
4450 EDITCLASSNAME, | 4629 EDITCLASSNAME, |
4451 "", | 4630 "", |
4452 WS_VISIBLE | WS_BORDER | | 4631 WS_VISIBLE | WS_BORDER | |
4453 WS_VSCROLL | ES_MULTILINE | | 4632 WS_VSCROLL | ES_MULTILINE | |
4454 ES_WANTRETURN | WS_CHILD | | 4633 ES_WANTRETURN | WS_CHILD | |
4455 WS_CLIPCHILDREN, | 4634 WS_CLIPCHILDREN, |
4456 0,0,2000,1000, | 4635 0,0,2000,1000, |
4457 DW_HWND_OBJECT, | 4636 DW_HWND_OBJECT, |
4458 (HMENU)id, | 4637 (HMENU)id, |
4459 DWInstance, | 4638 DWInstance, |
4460 NULL); | 4639 NULL); |
4461 ContainerInfo *cinfo = (ContainerInfo *)calloc(1, sizeof(ContainerInfo)); | 4640 ContainerInfo *cinfo = (ContainerInfo *)calloc(1, sizeof(ContainerInfo)); |
4462 | 4641 |
4463 if(!cinfo) | 4642 if(!cinfo) |
4464 { | 4643 { |
4465 DestroyWindow(tmp); | 4644 DestroyWindow(tmp); |
4466 return NULL; | 4645 return NULL; |
4467 } | 4646 } |
4468 | 4647 |
4469 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _treewndproc); | 4648 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _treewndproc); |
4470 cinfo->cinfo.fore = cinfo->cinfo.back = -1; | 4649 cinfo->cinfo.fore = cinfo->cinfo.back = -1; |
4471 | 4650 |
4472 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); | 4651 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); |
4473 dw_window_set_font(tmp, DefaultFont); | 4652 dw_window_set_font(tmp, DefaultFont); |
4474 return tmp; | 4653 return tmp; |
4475 } | 4654 } |
4476 | 4655 |
4477 /* | 4656 /* |
4478 * Create a new Entryfield window (widget) to be packed. | 4657 * Create a new Entryfield window (widget) to be packed. |
4479 * Parameters: | 4658 * Parameters: |
4480 * text: The default text to be in the entryfield widget. | 4659 * text: The default text to be in the entryfield widget. |
4481 * id: An ID to be used with dw_window_from_id() or 0L. | 4660 * id: An ID to be used with dw_window_from_id() or 0L. |
4482 */ | 4661 */ |
4483 HWND API dw_entryfield_new(char *text, ULONG id) | 4662 HWND API dw_entryfield_new(char *text, ULONG id) |
4484 { | 4663 { |
4485 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, | 4664 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, |
4486 EDITCLASSNAME, | 4665 EDITCLASSNAME, |
4487 text, | 4666 text, |
4488 ES_WANTRETURN | WS_CHILD | | 4667 ES_WANTRETURN | WS_CHILD | |
4489 WS_BORDER | ES_AUTOHSCROLL | | 4668 WS_BORDER | ES_AUTOHSCROLL | |
4490 WS_VISIBLE | WS_CLIPCHILDREN, | 4669 WS_VISIBLE | WS_CLIPCHILDREN, |
4491 0,0,2000,1000, | 4670 0,0,2000,1000, |
4492 DW_HWND_OBJECT, | 4671 DW_HWND_OBJECT, |
4493 (HMENU)id, | 4672 (HMENU)id, |
4494 DWInstance, | 4673 DWInstance, |
4495 NULL); | 4674 NULL); |
4496 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); | 4675 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); |
4497 | 4676 |
4498 cinfo->back = cinfo->fore = -1; | 4677 cinfo->back = cinfo->fore = -1; |
4499 | 4678 |
4500 cinfo->pOldProc = SubclassWindow(tmp, _colorwndproc); | 4679 cinfo->pOldProc = SubclassWindow(tmp, _colorwndproc); |
4501 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); | 4680 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); |
4502 dw_window_set_font(tmp, DefaultFont); | 4681 dw_window_set_font(tmp, DefaultFont); |
4503 return tmp; | 4682 return tmp; |
4504 } | 4683 } |
4505 | 4684 |
4506 /* | 4685 /* |
4507 * Create a new Entryfield passwird window (widget) to be packed. | 4686 * Create a new Entryfield passwird window (widget) to be packed. |
4508 * Parameters: | 4687 * Parameters: |
4509 * text: The default text to be in the entryfield widget. | 4688 * text: The default text to be in the entryfield widget. |
4510 * id: An ID to be used with dw_window_from_id() or 0L. | 4689 * id: An ID to be used with dw_window_from_id() or 0L. |
4511 */ | 4690 */ |
4512 HWND API dw_entryfield_password_new(char *text, ULONG id) | 4691 HWND API dw_entryfield_password_new(char *text, ULONG id) |
4513 { | 4692 { |
4514 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, | 4693 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, |
4515 EDITCLASSNAME, | 4694 EDITCLASSNAME, |
4516 text, | 4695 text, |
4517 ES_WANTRETURN | WS_CHILD | | 4696 ES_WANTRETURN | WS_CHILD | |
4518 ES_PASSWORD | WS_BORDER | WS_VISIBLE | | 4697 ES_PASSWORD | WS_BORDER | WS_VISIBLE | |
4519 ES_AUTOHSCROLL | WS_CLIPCHILDREN, | 4698 ES_AUTOHSCROLL | WS_CLIPCHILDREN, |
4520 0,0,2000,1000, | 4699 0,0,2000,1000, |
4521 DW_HWND_OBJECT, | 4700 DW_HWND_OBJECT, |
4522 (HMENU)id, | 4701 (HMENU)id, |
4523 DWInstance, | 4702 DWInstance, |
4524 NULL); | 4703 NULL); |
4525 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); | 4704 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); |
4526 | 4705 |
4527 cinfo->back = cinfo->fore = -1; | 4706 cinfo->back = cinfo->fore = -1; |
4528 | 4707 |
4529 cinfo->pOldProc = SubclassWindow(tmp, _colorwndproc); | 4708 cinfo->pOldProc = SubclassWindow(tmp, _colorwndproc); |
4530 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); | 4709 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); |
4531 dw_window_set_font(tmp, DefaultFont); | 4710 dw_window_set_font(tmp, DefaultFont); |
4532 return tmp; | 4711 return tmp; |
4533 } | 4712 } |
4534 | 4713 |
4535 BOOL CALLBACK _subclass_child(HWND handle, LPARAM lp) | 4714 BOOL CALLBACK _subclass_child(HWND handle, LPARAM lp) |
4536 { | 4715 { |
4537 ColorInfo *cinfo = (ColorInfo *)lp; | 4716 ColorInfo *cinfo = (ColorInfo *)lp; |
4538 | 4717 |
4539 if(cinfo) | 4718 if(cinfo) |
4540 { | 4719 { |
4541 cinfo->buddy = handle; | 4720 cinfo->buddy = handle; |
4542 cinfo->pOldProc = (WNDPROC)SubclassWindow(handle, _colorwndproc); | 4721 cinfo->pOldProc = (WNDPROC)SubclassWindow(handle, _colorwndproc); |
4543 SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)cinfo); | 4722 SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)cinfo); |
4544 } | 4723 } |
4545 return FALSE; | 4724 return FALSE; |
4546 } | 4725 } |
4547 | 4726 |
4548 /* | 4727 /* |
4549 * Create a new Combobox window (widget) to be packed. | 4728 * Create a new Combobox window (widget) to be packed. |
4550 * Parameters: | 4729 * Parameters: |
4551 * text: The default text to be in the combpbox widget. | 4730 * text: The default text to be in the combpbox widget. |
4552 * id: An ID to be used with dw_window_from_id() or 0L. | 4731 * id: An ID to be used with dw_window_from_id() or 0L. |
4553 */ | 4732 */ |
4554 HWND API dw_combobox_new(char *text, ULONG id) | 4733 HWND API dw_combobox_new(char *text, ULONG id) |
4555 { | 4734 { |
4556 HWND tmp = CreateWindow(COMBOBOXCLASSNAME, | 4735 HWND tmp = CreateWindow(COMBOBOXCLASSNAME, |
4557 text, | 4736 text, |
4558 WS_CHILD | CBS_DROPDOWN | WS_VSCROLL | | 4737 WS_CHILD | CBS_DROPDOWN | WS_VSCROLL | |
4559 WS_CLIPCHILDREN | CBS_AUTOHSCROLL | WS_VISIBLE, | 4738 WS_CLIPCHILDREN | CBS_AUTOHSCROLL | WS_VISIBLE, |
4560 0,0,2000,1000, | 4739 0,0,2000,1000, |
4561 DW_HWND_OBJECT, | 4740 DW_HWND_OBJECT, |
4562 (HMENU)id, | 4741 (HMENU)id, |
4563 DWInstance, | 4742 DWInstance, |
4564 NULL); | 4743 NULL); |
4565 ColorInfo *cinfo = (ColorInfo *)calloc(1, sizeof(ColorInfo)); | 4744 ColorInfo *cinfo = (ColorInfo *)calloc(1, sizeof(ColorInfo)); |
4566 ColorInfo *cinfo2 = (ColorInfo *)calloc(1, sizeof(ColorInfo)); | 4745 ColorInfo *cinfo2 = (ColorInfo *)calloc(1, sizeof(ColorInfo)); |
4567 | 4746 |
4568 if(!cinfo || !cinfo2) | 4747 if(!cinfo || !cinfo2) |
4569 { | 4748 { |
4570 if(cinfo) | 4749 if(cinfo) |
4571 free(cinfo); | 4750 free(cinfo); |
4572 if(cinfo2) | 4751 if(cinfo2) |
4573 free(cinfo2); | 4752 free(cinfo2); |
4574 DestroyWindow(tmp); | 4753 DestroyWindow(tmp); |
4575 return NULL; | 4754 return NULL; |
4576 } | 4755 } |
4577 | 4756 |
4578 cinfo2->fore = cinfo->fore = -1; | 4757 cinfo2->fore = cinfo->fore = -1; |
4579 cinfo2->back = cinfo->back = -1; | 4758 cinfo2->back = cinfo->back = -1; |
4580 cinfo2->combo = cinfo->combo = tmp; | 4759 cinfo2->combo = cinfo->combo = tmp; |
4581 EnumChildWindows(tmp, _subclass_child, (LPARAM)cinfo2); | 4760 EnumChildWindows(tmp, _subclass_child, (LPARAM)cinfo2); |
4582 | 4761 |
4583 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); | 4762 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); |
4584 dw_window_set_font(tmp, DefaultFont); | 4763 dw_window_set_font(tmp, DefaultFont); |
4585 SetWindowText(tmp, text); | 4764 SetWindowText(tmp, text); |
4586 return tmp; | 4765 return tmp; |
4587 } | 4766 } |
4588 | 4767 |
4589 /* | 4768 /* |
4590 * Create a new button window (widget) to be packed. | 4769 * Create a new button window (widget) to be packed. |
4591 * Parameters: | 4770 * Parameters: |
4621 * text: Bubble help text to be displayed. | 4800 * text: Bubble help text to be displayed. |
4622 * id: An ID of a bitmap in the resource file. | 4801 * id: An ID of a bitmap in the resource file. |
4623 */ | 4802 */ |
4624 HWND API dw_bitmapbutton_new(char *text, ULONG id) | 4803 HWND API dw_bitmapbutton_new(char *text, ULONG id) |
4625 { | 4804 { |
4626 HWND tmp; | 4805 HWND tmp; |
4627 BubbleButton *bubble = calloc(1, sizeof(BubbleButton)); | 4806 BubbleButton *bubble = calloc(1, sizeof(BubbleButton)); |
4628 HBITMAP hbitmap = LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); | 4807 HBITMAP hbitmap = LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); |
4629 HICON icon = LoadImage(DWInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_SHARED); | 4808 HICON icon = LoadImage(DWInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_SHARED); |
4630 | 4809 |
4631 tmp = CreateWindow(BUTTONCLASSNAME, | 4810 tmp = CreateWindow(BUTTONCLASSNAME, |
4632 "", | 4811 "", |
4633 WS_CHILD | BS_PUSHBUTTON | | 4812 WS_CHILD | BS_PUSHBUTTON | |
4634 WS_VISIBLE | WS_CLIPCHILDREN | | 4813 WS_VISIBLE | WS_CLIPCHILDREN | |
4635 (icon ? BS_ICON : BS_BITMAP), | 4814 (icon ? BS_ICON : BS_BITMAP), |
4636 0,0,2000,1000, | 4815 0,0,2000,1000, |
4637 DW_HWND_OBJECT, | 4816 DW_HWND_OBJECT, |
4638 (HMENU)id, | 4817 (HMENU)id, |
4639 DWInstance, | 4818 DWInstance, |
4640 NULL); | 4819 NULL); |
4641 | 4820 |
4642 bubble->id = id; | 4821 bubble->id = id; |
4643 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1); | 4822 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1); |
4644 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; | 4823 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; |
4645 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); | 4824 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); |
4646 | 4825 |
4647 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); | 4826 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); |
4648 | 4827 |
4649 if(icon) | 4828 if(icon) |
4650 { | 4829 { |
4651 SendMessage(tmp, BM_SETIMAGE, | 4830 SendMessage(tmp, BM_SETIMAGE, |
4652 (WPARAM) IMAGE_ICON, | 4831 (WPARAM) IMAGE_ICON, |
4653 (LPARAM) icon); | 4832 (LPARAM) icon); |
4654 } | 4833 } |
4655 else if(hbitmap) | 4834 else if(hbitmap) |
4656 { | 4835 { |
4657 SendMessage(tmp, BM_SETIMAGE, | 4836 SendMessage(tmp, BM_SETIMAGE, |
4658 (WPARAM) IMAGE_BITMAP, | 4837 (WPARAM) IMAGE_BITMAP, |
4659 (LPARAM) hbitmap); | 4838 (LPARAM) hbitmap); |
4660 } | 4839 } |
4661 return tmp; | 4840 return tmp; |
4662 } | 4841 } |
4663 | 4842 |
4664 /* | 4843 /* |
4665 * Create a new bitmap button window (widget) to be packed from a file. | 4844 * Create a new bitmap button window (widget) to be packed from a file. |
4666 * Parameters: | 4845 * Parameters: |
4799 * text: The text to be display by the static text widget. | 4978 * text: The text to be display by the static text widget. |
4800 * id: An ID to be used with dw_window_from_id() or 0L. | 4979 * id: An ID to be used with dw_window_from_id() or 0L. |
4801 */ | 4980 */ |
4802 HWND API dw_spinbutton_new(char *text, ULONG id) | 4981 HWND API dw_spinbutton_new(char *text, ULONG id) |
4803 { | 4982 { |
4804 HWND buddy = CreateWindowEx(WS_EX_CLIENTEDGE, | 4983 HWND buddy = CreateWindowEx(WS_EX_CLIENTEDGE, |
4805 EDITCLASSNAME, | 4984 EDITCLASSNAME, |
4806 text, | 4985 text, |
4807 WS_CHILD | WS_BORDER | WS_VISIBLE | | 4986 WS_CHILD | WS_BORDER | WS_VISIBLE | |
4808 ES_NUMBER | WS_CLIPCHILDREN, | 4987 ES_NUMBER | WS_CLIPCHILDREN, |
4809 0,0,2000,1000, | 4988 0,0,2000,1000, |
4810 DW_HWND_OBJECT, | 4989 DW_HWND_OBJECT, |
4811 NULL, | 4990 NULL, |
4812 DWInstance, | 4991 DWInstance, |
4813 NULL); | 4992 NULL); |
4814 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, | 4993 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, |
4815 UPDOWN_CLASS, | 4994 UPDOWN_CLASS, |
4816 NULL, | 4995 NULL, |
4817 WS_CHILD | UDS_ALIGNRIGHT | WS_BORDER | | 4996 WS_CHILD | UDS_ALIGNRIGHT | WS_BORDER | |
4818 UDS_ARROWKEYS | UDS_SETBUDDYINT | | 4997 UDS_ARROWKEYS | UDS_SETBUDDYINT | |
4819 UDS_WRAP | UDS_NOTHOUSANDS | WS_VISIBLE, | 4998 UDS_WRAP | UDS_NOTHOUSANDS | WS_VISIBLE, |
4820 0,0,2000,1000, | 4999 0,0,2000,1000, |
4821 DW_HWND_OBJECT, | 5000 DW_HWND_OBJECT, |
4822 (HMENU)id, | 5001 (HMENU)id, |
4823 DWInstance, | 5002 DWInstance, |
4824 NULL); | 5003 NULL); |
4825 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); | 5004 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); |
4826 | 5005 |
4827 SendMessage(tmp, UDM_SETBUDDY, (WPARAM)buddy, 0); | 5006 SendMessage(tmp, UDM_SETBUDDY, (WPARAM)buddy, 0); |
4828 cinfo->back = cinfo->fore = -1; | 5007 cinfo->back = cinfo->fore = -1; |
4829 cinfo->buddy = tmp; | 5008 cinfo->buddy = tmp; |
4830 | 5009 |
4831 cinfo->pOldProc = SubclassWindow(buddy, _colorwndproc); | 5010 cinfo->pOldProc = SubclassWindow(buddy, _colorwndproc); |
4832 SetWindowLongPtr(buddy, GWLP_USERDATA, (LONG_PTR)cinfo); | 5011 SetWindowLongPtr(buddy, GWLP_USERDATA, (LONG_PTR)cinfo); |
4833 | 5012 |
4834 cinfo = calloc(1, sizeof(ColorInfo)); | 5013 cinfo = calloc(1, sizeof(ColorInfo)); |
4835 cinfo->buddy = buddy; | 5014 cinfo->buddy = buddy; |
4836 cinfo->pOldProc = SubclassWindow(tmp, _spinnerwndproc); | 5015 cinfo->pOldProc = SubclassWindow(tmp, _spinnerwndproc); |
4837 | 5016 |
4838 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); | 5017 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); |
4839 dw_window_set_font(buddy, DefaultFont); | 5018 dw_window_set_font(buddy, DefaultFont); |
4840 return tmp; | 5019 return tmp; |
4841 } | 5020 } |
4842 | 5021 |
4843 /* | 5022 /* |
4844 * Create a new radiobutton window (widget) to be packed. | 5023 * Create a new radiobutton window (widget) to be packed. |
4845 * Parameters: | 5024 * Parameters: |
4846 * text: The text to be display by the static text widget. | 5025 * text: The text to be display by the static text widget. |
4847 * id: An ID to be used with dw_window_from_id() or 0L. | 5026 * id: An ID to be used with dw_window_from_id() or 0L. |
4848 */ | 5027 */ |
4849 HWND API dw_radiobutton_new(char *text, ULONG id) | 5028 HWND API dw_radiobutton_new(char *text, ULONG id) |
4850 { | 5029 { |
4851 HWND tmp = CreateWindow(BUTTONCLASSNAME, | 5030 HWND tmp = CreateWindow(BUTTONCLASSNAME, |
4852 text, | 5031 text, |
4853 WS_CHILD | BS_AUTORADIOBUTTON | | 5032 WS_CHILD | BS_AUTORADIOBUTTON | |
4854 WS_CLIPCHILDREN | WS_VISIBLE, | 5033 WS_CLIPCHILDREN | WS_VISIBLE, |
4855 0,0,2000,1000, | 5034 0,0,2000,1000, |
4856 DW_HWND_OBJECT, | 5035 DW_HWND_OBJECT, |
4857 (HMENU)id, | 5036 (HMENU)id, |
4858 DWInstance, | 5037 DWInstance, |
4859 NULL); | 5038 NULL); |
4860 BubbleButton *bubble = calloc(1, sizeof(BubbleButton)); | 5039 BubbleButton *bubble = calloc(1, sizeof(BubbleButton)); |
4861 bubble->id = id; | 5040 bubble->id = id; |
4862 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); | 5041 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); |
4863 bubble->cinfo.fore = -1; | 5042 bubble->cinfo.fore = -1; |
4864 bubble->cinfo.back = -1; | 5043 bubble->cinfo.back = -1; |
4865 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); | 5044 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); |
4866 dw_window_set_font(tmp, DefaultFont); | 5045 dw_window_set_font(tmp, DefaultFont); |
4867 return tmp; | 5046 return tmp; |
4868 } | 5047 } |
4869 | 5048 |
4870 | 5049 |
4871 /* | 5050 /* |
4872 * Create a new slider window (widget) to be packed. | 5051 * Create a new slider window (widget) to be packed. |
4875 * increments: Number of increments available. | 5054 * increments: Number of increments available. |
4876 * id: An ID to be used with dw_window_from_id() or 0L. | 5055 * id: An ID to be used with dw_window_from_id() or 0L. |
4877 */ | 5056 */ |
4878 HWND API dw_slider_new(int vertical, int increments, ULONG id) | 5057 HWND API dw_slider_new(int vertical, int increments, ULONG id) |
4879 { | 5058 { |
4880 HWND tmp = CreateWindow(TRACKBAR_CLASS, | 5059 HWND tmp = CreateWindow(TRACKBAR_CLASS, |
4881 "", | 5060 "", |
4882 WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | | 5061 WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | |
4883 (vertical ? TBS_VERT : TBS_HORZ), | 5062 (vertical ? TBS_VERT : TBS_HORZ), |
4884 0,0,2000,1000, | 5063 0,0,2000,1000, |
4885 DW_HWND_OBJECT, | 5064 DW_HWND_OBJECT, |
4886 (HMENU)id, | 5065 (HMENU)id, |
4887 DWInstance, | 5066 DWInstance, |
4888 NULL); | 5067 NULL); |
4889 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); | 5068 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); |
4890 | 5069 |
4891 cinfo->back = cinfo->fore = -1; | 5070 cinfo->back = cinfo->fore = -1; |
4892 | 5071 |
4893 cinfo->pOldProc = SubclassWindow(tmp, _colorwndproc); | 5072 cinfo->pOldProc = SubclassWindow(tmp, _colorwndproc); |
4894 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); | 5073 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); |
4895 SendMessage(tmp, TBM_SETRANGE, (WPARAM)FALSE, (LPARAM)MAKELONG(0, increments-1)); | 5074 SendMessage(tmp, TBM_SETRANGE, (WPARAM)FALSE, (LPARAM)MAKELONG(0, increments-1)); |
4896 return tmp; | 5075 return tmp; |
4897 } | 5076 } |
4898 | 5077 |
4899 /* | 5078 /* |
4900 * Create a new scrollbar window (widget) to be packed. | 5079 * Create a new scrollbar window (widget) to be packed. |
4901 * Parameters: | 5080 * Parameters: |
4903 * increments: Number of increments available. | 5082 * increments: Number of increments available. |
4904 * id: An ID to be used with dw_window_from_id() or 0L. | 5083 * id: An ID to be used with dw_window_from_id() or 0L. |
4905 */ | 5084 */ |
4906 HWND API dw_scrollbar_new(int vertical, ULONG id) | 5085 HWND API dw_scrollbar_new(int vertical, ULONG id) |
4907 { | 5086 { |
4908 HWND tmp = CreateWindow(SCROLLBARCLASSNAME, | 5087 HWND tmp = CreateWindow(SCROLLBARCLASSNAME, |
4909 "", | 5088 "", |
4910 WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | | 5089 WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | |
4911 (vertical ? SBS_VERT : SBS_HORZ), | 5090 (vertical ? SBS_VERT : SBS_HORZ), |
4912 0,0,2000,1000, | 5091 0,0,2000,1000, |
4913 DW_HWND_OBJECT, | 5092 DW_HWND_OBJECT, |
4914 (HMENU)id, | 5093 (HMENU)id, |
4915 DWInstance, | 5094 DWInstance, |
4916 NULL); | 5095 NULL); |
4917 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); | 5096 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); |
4918 | 5097 |
4919 cinfo->back = cinfo->fore = -1; | 5098 cinfo->back = cinfo->fore = -1; |
4920 | 5099 |
4921 cinfo->pOldProc = SubclassWindow(tmp, _colorwndproc); | 5100 cinfo->pOldProc = SubclassWindow(tmp, _colorwndproc); |
4922 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); | 5101 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); |
4923 dw_window_set_data(tmp, "_dw_scrollbar", (void *)1); | 5102 dw_window_set_data(tmp, "_dw_scrollbar", (void *)1); |
4924 return tmp; | 5103 return tmp; |
4925 } | 5104 } |
4926 | 5105 |
4927 /* | 5106 /* |
4928 * Create a new percent bar window (widget) to be packed. | 5107 * Create a new percent bar window (widget) to be packed. |
4929 * Parameters: | 5108 * Parameters: |
4930 * id: An ID to be used with dw_window_from_id() or 0L. | 5109 * id: An ID to be used with dw_window_from_id() or 0L. |
4931 */ | 5110 */ |
4932 HWND API dw_percent_new(ULONG id) | 5111 HWND API dw_percent_new(ULONG id) |
4933 { | 5112 { |
4934 return CreateWindow(PROGRESS_CLASS, | 5113 return CreateWindow(PROGRESS_CLASS, |
4935 "", | 5114 "", |
4936 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, | 5115 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, |
4937 0,0,2000,1000, | 5116 0,0,2000,1000, |
4938 DW_HWND_OBJECT, | 5117 DW_HWND_OBJECT, |
4939 (HMENU)id, | 5118 (HMENU)id, |
4940 DWInstance, | 5119 DWInstance, |
4941 NULL); | 5120 NULL); |
4942 } | 5121 } |
4943 | 5122 |
4944 /* | 5123 /* |
4945 * Create a new checkbox window (widget) to be packed. | 5124 * Create a new checkbox window (widget) to be packed. |
4946 * Parameters: | 5125 * Parameters: |
4947 * text: The text to be display by the static text widget. | 5126 * text: The text to be display by the static text widget. |
4948 * id: An ID to be used with dw_window_from_id() or 0L. | 5127 * id: An ID to be used with dw_window_from_id() or 0L. |
4949 */ | 5128 */ |
4950 HWND API dw_checkbox_new(char *text, ULONG id) | 5129 HWND API dw_checkbox_new(char *text, ULONG id) |
4951 { | 5130 { |
4952 BubbleButton *bubble = calloc(1, sizeof(BubbleButton)); | 5131 BubbleButton *bubble = calloc(1, sizeof(BubbleButton)); |
4953 HWND tmp = CreateWindow(BUTTONCLASSNAME, | 5132 HWND tmp = CreateWindow(BUTTONCLASSNAME, |
4954 text, | 5133 text, |
4955 WS_CHILD | BS_AUTOCHECKBOX | | 5134 WS_CHILD | BS_AUTOCHECKBOX | |
4956 BS_TEXT | WS_CLIPCHILDREN | WS_VISIBLE, | 5135 BS_TEXT | WS_CLIPCHILDREN | WS_VISIBLE, |
4957 0,0,2000,1000, | 5136 0,0,2000,1000, |
4958 DW_HWND_OBJECT, | 5137 DW_HWND_OBJECT, |
4959 (HMENU)id, | 5138 (HMENU)id, |
4960 DWInstance, | 5139 DWInstance, |
4961 NULL); | 5140 NULL); |
4962 bubble->id = id; | 5141 bubble->id = id; |
4963 bubble->checkbox = 1; | 5142 bubble->checkbox = 1; |
4964 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); | 5143 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); |
4965 bubble->cinfo.fore = -1; | 5144 bubble->cinfo.fore = -1; |
4966 bubble->cinfo.back = -1; | 5145 bubble->cinfo.back = -1; |
4967 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); | 5146 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); |
4968 dw_window_set_font(tmp, DefaultFont); | 5147 dw_window_set_font(tmp, DefaultFont); |
4969 return tmp; | 5148 return tmp; |
4970 } | 5149 } |
4971 | 5150 |
4972 /* | 5151 /* |
4973 * Create a new listbox window (widget) to be packed. | 5152 * Create a new listbox window (widget) to be packed. |
4974 * Parameters: | 5153 * Parameters: |
4975 * id: An ID to be used with dw_window_from_id() or 0L. | 5154 * id: An ID to be used with dw_window_from_id() or 0L. |
4976 * multi: Multiple select TRUE or FALSE. | 5155 * multi: Multiple select TRUE or FALSE. |
4977 */ | 5156 */ |
4978 HWND API dw_listbox_new(ULONG id, int multi) | 5157 HWND API dw_listbox_new(ULONG id, int multi) |
4979 { | 5158 { |
4980 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, | 5159 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, |
4981 LISTBOXCLASSNAME, | 5160 LISTBOXCLASSNAME, |
4982 "", | 5161 "", |
4983 WS_VISIBLE | LBS_NOINTEGRALHEIGHT | | 5162 WS_VISIBLE | LBS_NOINTEGRALHEIGHT | |
4984 WS_CHILD | LBS_HASSTRINGS | | 5163 WS_CHILD | LBS_HASSTRINGS | |
4985 LBS_NOTIFY | WS_BORDER | WS_CLIPCHILDREN | | 5164 LBS_NOTIFY | WS_BORDER | WS_CLIPCHILDREN | |
4986 WS_VSCROLL | (multi ? LBS_MULTIPLESEL : 0) , | 5165 WS_VSCROLL | (multi ? LBS_MULTIPLESEL : 0) , |
4987 0,0,2000,1000, | 5166 0,0,2000,1000, |
4988 DW_HWND_OBJECT, | 5167 DW_HWND_OBJECT, |
4989 (HMENU)id, | 5168 (HMENU)id, |
4990 DWInstance, | 5169 DWInstance, |
4991 NULL); | 5170 NULL); |
4992 ContainerInfo *cinfo = (ContainerInfo *)calloc(1, sizeof(ContainerInfo)); | 5171 ContainerInfo *cinfo = (ContainerInfo *)calloc(1, sizeof(ContainerInfo)); |
4993 | 5172 |
4994 if(!cinfo) | 5173 if(!cinfo) |
4995 { | 5174 { |
4996 DestroyWindow(tmp); | 5175 DestroyWindow(tmp); |
4997 return NULL; | 5176 return NULL; |
4998 } | 5177 } |
4999 | 5178 |
5000 cinfo->cinfo.fore = -1; | 5179 cinfo->cinfo.fore = -1; |
5001 cinfo->cinfo.back = -1; | 5180 cinfo->cinfo.back = -1; |
5002 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _containerwndproc); | 5181 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _containerwndproc); |
5003 | 5182 |
5004 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); | 5183 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); |
5005 dw_window_set_font(tmp, DefaultFont); | 5184 dw_window_set_font(tmp, DefaultFont); |
5006 return tmp; | 5185 return tmp; |
5007 } | 5186 } |
5008 | 5187 |
5009 /* | 5188 /* |
5010 * Sets the icon used for a given window. | 5189 * Sets the icon used for a given window. |
5011 * Parameters: | 5190 * Parameters: |
5012 * handle: Handle to the window. | 5191 * handle: Handle to the window. |
5013 * id: An ID to be used to specify the icon. | 5192 * id: An ID to be used to specify the icon. |
5014 */ | 5193 */ |
5015 void API dw_window_set_icon(HWND handle, ULONG id) | 5194 void API dw_window_set_icon(HWND handle, ULONG id) |
5016 { | 5195 { |
5017 HICON hicon = id < 65536 ? LoadIcon(DWInstance, MAKEINTRESOURCE(id)) : (HICON)id; | 5196 HICON hicon = id < 65536 ? LoadIcon(DWInstance, MAKEINTRESOURCE(id)) : (HICON)id; |
5018 | 5197 |
5019 SendMessage(handle, WM_SETICON, | 5198 SendMessage(handle, WM_SETICON, |
5020 (WPARAM) IMAGE_ICON, | 5199 (WPARAM) IMAGE_ICON, |
5021 (LPARAM) hicon); | 5200 (LPARAM) hicon); |
5022 } | 5201 } |
5023 | 5202 |
5024 /* | 5203 /* |
5025 * Sets the bitmap used for a given static window. | 5204 * Sets the bitmap used for a given static window. |
5026 * Parameters: | 5205 * Parameters: |
5031 * Windows and a pixmap on Unix, pass | 5210 * Windows and a pixmap on Unix, pass |
5032 * NULL if you use the id param) | 5211 * NULL if you use the id param) |
5033 */ | 5212 */ |
5034 void API dw_window_set_bitmap(HWND handle, unsigned long id, char *filename) | 5213 void API dw_window_set_bitmap(HWND handle, unsigned long id, char *filename) |
5035 { | 5214 { |
5036 HBITMAP hbitmap; | 5215 HBITMAP hbitmap; |
5037 HBITMAP oldbitmap = (HBITMAP)SendMessage(handle, STM_GETIMAGE, IMAGE_BITMAP, 0); | 5216 HBITMAP oldbitmap = (HBITMAP)SendMessage(handle, STM_GETIMAGE, IMAGE_BITMAP, 0); |
5038 HICON icon; | 5217 HICON icon; |
5039 HICON oldicon = (HICON)SendMessage(handle, STM_GETIMAGE, IMAGE_ICON, 0); | 5218 HICON oldicon = (HICON)SendMessage(handle, STM_GETIMAGE, IMAGE_ICON, 0); |
5040 | 5219 |
5041 if(id) | 5220 if(id) |
5042 { | 5221 { |
5043 hbitmap = LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); | 5222 hbitmap = LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); |
5044 icon = LoadImage(DWInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_SHARED); | 5223 icon = LoadImage(DWInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_SHARED); |
5045 } | 5224 } |
5046 else if(filename) | 5225 else if(filename) |
5047 { | 5226 { |
5048 _dw_get_image_handle(filename, &icon, &hbitmap); | 5227 _dw_get_image_handle(filename, &icon, &hbitmap); |
5049 if (icon == 0 && hbitmap == 0) | 5228 if (icon == 0 && hbitmap == 0) |
5050 return; | 5229 return; |
5051 } | 5230 } |
5052 | 5231 |
5053 if(icon) | 5232 if(icon) |
5054 { | 5233 { |
5055 SendMessage(handle, BM_SETIMAGE, | 5234 SendMessage(handle, BM_SETIMAGE, |
5056 (WPARAM) IMAGE_ICON, | 5235 (WPARAM) IMAGE_ICON, |
5057 (LPARAM) icon); | 5236 (LPARAM) icon); |
5058 SendMessage(handle, STM_SETIMAGE, | 5237 SendMessage(handle, STM_SETIMAGE, |
5059 (WPARAM) IMAGE_ICON, | 5238 (WPARAM) IMAGE_ICON, |
5060 (LPARAM) icon); | 5239 (LPARAM) icon); |
5061 } | 5240 } |
5062 else if(hbitmap) | 5241 else if(hbitmap) |
5063 { | 5242 { |
5064 SendMessage(handle, BM_SETIMAGE, | 5243 SendMessage(handle, BM_SETIMAGE, |
5065 (WPARAM) IMAGE_BITMAP, | 5244 (WPARAM) IMAGE_BITMAP, |
5066 (LPARAM) hbitmap); | 5245 (LPARAM) hbitmap); |
5067 SendMessage(handle, STM_SETIMAGE, | 5246 SendMessage(handle, STM_SETIMAGE, |
5068 (WPARAM) IMAGE_BITMAP, | 5247 (WPARAM) IMAGE_BITMAP, |
5069 (LPARAM) hbitmap); | 5248 (LPARAM) hbitmap); |
5070 } | 5249 } |
5071 | 5250 |
5072 if(hbitmap && oldbitmap) | 5251 if(hbitmap && oldbitmap) |
5073 DeleteObject(oldbitmap); | 5252 DeleteObject(oldbitmap); |
5074 else if(icon && oldicon) | 5253 else if(icon && oldicon) |
5075 DeleteObject(oldicon); | 5254 DeleteObject(oldicon); |
5076 } | 5255 } |
5077 | 5256 |
5078 /* | 5257 /* |
5079 * Sets the bitmap used for a given static window from data. | 5258 * Sets the bitmap used for a given static window from data. |
5080 * Parameters: | 5259 * Parameters: |
5158 * handle: Handle to the window. | 5337 * handle: Handle to the window. |
5159 * text: The text associsated with a given window. | 5338 * text: The text associsated with a given window. |
5160 */ | 5339 */ |
5161 void API dw_window_set_text(HWND handle, char *text) | 5340 void API dw_window_set_text(HWND handle, char *text) |
5162 { | 5341 { |
5163 char tmpbuf[100]; | 5342 char tmpbuf[100]; |
5164 | 5343 |
5165 GetClassName(handle, tmpbuf, 99); | 5344 GetClassName(handle, tmpbuf, 99); |
5166 | 5345 |
5167 SetWindowText(handle, text); | 5346 SetWindowText(handle, text); |
5168 | 5347 |
5169 /* Combobox */ | 5348 /* Combobox */ |
5170 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) | 5349 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) |
5171 SendMessage(handle, CB_SETEDITSEL, 0, MAKELPARAM(-1, 0)); | 5350 SendMessage(handle, CB_SETEDITSEL, 0, MAKELPARAM(-1, 0)); |
5172 } | 5351 } |
5173 | 5352 |
5174 /* | 5353 /* |
5175 * Gets the text used for a given window. | 5354 * Gets the text used for a given window. |
5176 * Parameters: | 5355 * Parameters: |
5178 * Returns: | 5357 * Returns: |
5179 * text: The text associsated with a given window. | 5358 * text: The text associsated with a given window. |
5180 */ | 5359 */ |
5181 char * API dw_window_get_text(HWND handle) | 5360 char * API dw_window_get_text(HWND handle) |
5182 { | 5361 { |
5183 int len = GetWindowTextLength(handle); | 5362 int len = GetWindowTextLength(handle); |
5184 char *tempbuf = calloc(1, len + 2); | 5363 char *tempbuf = calloc(1, len + 2); |
5185 | 5364 |
5186 GetWindowText(handle, tempbuf, len + 1); | 5365 GetWindowText(handle, tempbuf, len + 1); |
5187 | 5366 |
5188 return tempbuf; | 5367 return tempbuf; |
5189 } | 5368 } |
5190 | 5369 |
5191 /* | 5370 /* |
5192 * Disables given window (widget). | 5371 * Disables given window (widget). |
5193 * Parameters: | 5372 * Parameters: |
5194 * handle: Handle to the window. | 5373 * handle: Handle to the window. |
5195 */ | 5374 */ |
5196 void API dw_window_disable(HWND handle) | 5375 void API dw_window_disable(HWND handle) |
5197 { | 5376 { |
5198 EnableWindow(handle, FALSE); | 5377 EnableWindow(handle, FALSE); |
5199 } | 5378 } |
5200 | 5379 |
5201 /* | 5380 /* |
5202 * Enables given window (widget). | 5381 * Enables given window (widget). |
5203 * Parameters: | 5382 * Parameters: |
5204 * handle: Handle to the window. | 5383 * handle: Handle to the window. |
5205 */ | 5384 */ |
5206 void API dw_window_enable(HWND handle) | 5385 void API dw_window_enable(HWND handle) |
5207 { | 5386 { |
5208 EnableWindow(handle, TRUE); | 5387 EnableWindow(handle, TRUE); |
5209 } | 5388 } |
5210 | 5389 |
5211 static HWND _dw_wfid_hwnd = NULL; | 5390 static HWND _dw_wfid_hwnd = NULL; |
5212 | 5391 |
5213 BOOL CALLBACK _wfid(HWND handle, LPARAM lParam) | 5392 BOOL CALLBACK _wfid(HWND handle, LPARAM lParam) |
5214 { | 5393 { |
5215 if(GetWindowLong(handle, GWL_ID) == lParam) | 5394 if(GetWindowLong(handle, GWL_ID) == lParam) |
5216 { | 5395 { |
5217 _dw_wfid_hwnd = handle; | 5396 _dw_wfid_hwnd = handle; |
5218 return FALSE; | 5397 return FALSE; |
5219 } | 5398 } |
5220 return TRUE; | 5399 return TRUE; |
5221 } | 5400 } |
5222 | 5401 |
5223 /* | 5402 /* |
5224 * Gets the child window handle with specified ID. | 5403 * Gets the child window handle with specified ID. |
5225 * Parameters: | 5404 * Parameters: |
5226 * handle: Handle to the parent window. | 5405 * handle: Handle to the parent window. |
5227 * id: Integer ID of the child. | 5406 * id: Integer ID of the child. |
5228 */ | 5407 */ |
5229 HWND API dw_window_from_id(HWND handle, int id) | 5408 HWND API dw_window_from_id(HWND handle, int id) |
5230 { | 5409 { |
5231 _dw_wfid_hwnd = NULL; | 5410 _dw_wfid_hwnd = NULL; |
5232 EnumChildWindows(handle, _wfid, (LPARAM)id); | 5411 EnumChildWindows(handle, _wfid, (LPARAM)id); |
5233 return _dw_wfid_hwnd; | 5412 return _dw_wfid_hwnd; |
5234 } | 5413 } |
5235 | 5414 |
5236 /* | 5415 /* |
5237 * Pack windows (widgets) into a box from the start (or top). | 5416 * Pack windows (widgets) into a box from the start (or top). |
5244 * vsize: TRUE if the window (widget) should expand vertically to fill space given. | 5423 * vsize: TRUE if the window (widget) should expand vertically to fill space given. |
5245 * pad: Number of pixels of padding around the item. | 5424 * pad: Number of pixels of padding around the item. |
5246 */ | 5425 */ |
5247 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | 5426 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) |
5248 { | 5427 { |
5249 Box *thisbox; | 5428 Box *thisbox; |
5250 | 5429 |
5251 /* | 5430 /* |
5252 * If you try and pack an item into itself VERY bad things can happen; like at least an | 5431 * If you try and pack an item into itself VERY bad things can happen; like at least an |
5253 * infinite loop on GTK! Lets be safe! | 5432 * infinite loop on GTK! Lets be safe! |
5254 */ | 5433 */ |
5255 if(box == item) | 5434 if(box == item) |
5256 { | 5435 { |
5257 dw_messagebox("dw_box_pack_start()", DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!"); | 5436 dw_messagebox("dw_box_pack_start()", DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!"); |
5258 return; | 5437 return; |
5259 } | 5438 } |
5260 | 5439 |
5261 thisbox = (Box *)GetWindowLongPtr(box, GWLP_USERDATA); | 5440 thisbox = (Box *)GetWindowLongPtr(box, GWLP_USERDATA); |
5262 if(thisbox) | 5441 if(thisbox) |
5263 { | 5442 { |
5264 int z; | 5443 int z; |
5265 Item *tmpitem, *thisitem = thisbox->items; | 5444 Item *tmpitem, *thisitem = thisbox->items; |
5266 char tmpbuf[100]; | 5445 char tmpbuf[100]; |
5267 | 5446 |
5268 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); | 5447 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); |
5269 | 5448 |
5270 for(z=0;z<thisbox->count;z++) | 5449 for(z=0;z<thisbox->count;z++) |
5271 { | 5450 { |
5272 tmpitem[z] = thisitem[z]; | 5451 tmpitem[z] = thisitem[z]; |
5273 } | 5452 } |
5274 | 5453 |
5275 GetClassName(item, tmpbuf, 99); | 5454 GetClassName(item, tmpbuf, 99); |
5276 | 5455 |
5277 if(vsize && !height) | 5456 if(vsize && !height) |
5278 height = 1; | 5457 height = 1; |
5279 if(hsize && !width) | 5458 if(hsize && !width) |
5280 width = 1; | 5459 width = 1; |
5281 | 5460 |
5282 if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1)==0) | 5461 if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1)==0) |
5283 tmpitem[thisbox->count].type = TYPEBOX; | 5462 tmpitem[thisbox->count].type = TYPEBOX; |
5284 else if(strnicmp(tmpbuf, "SysMonthCal32", 13)==0) | 5463 else if(strnicmp(tmpbuf, "SysMonthCal32", 13)==0) |
5285 { | 5464 { |
5286 RECT rc; | 5465 RECT rc; |
5287 MonthCal_GetMinReqRect(item, &rc); | 5466 MonthCal_GetMinReqRect(item, &rc); |
5288 width = 1 + rc.right - rc.left; | 5467 width = 1 + rc.right - rc.left; |
5289 height = 1 + rc.bottom - rc.top; | 5468 height = 1 + rc.bottom - rc.top; |
5290 tmpitem[thisbox->count].type = TYPEITEM; | 5469 tmpitem[thisbox->count].type = TYPEITEM; |
5291 } | 5470 } |
5292 else | 5471 else |
5293 { | 5472 { |
5294 if ( width == 0 && hsize == FALSE ) | 5473 if ( width == 0 && hsize == FALSE ) |
5295 dw_messagebox("dw_box_pack_start()", DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); | 5474 dw_messagebox("dw_box_pack_start()", DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); |
5296 if ( height == 0 && vsize == FALSE ) | 5475 if ( height == 0 && vsize == FALSE ) |
5297 dw_messagebox("dw_box_pack_start()", DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item); | 5476 dw_messagebox("dw_box_pack_start()", DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item); |
5298 | 5477 |
5299 tmpitem[thisbox->count].type = TYPEITEM; | 5478 tmpitem[thisbox->count].type = TYPEITEM; |
5300 } | 5479 } |
5301 | 5480 |
5302 tmpitem[thisbox->count].hwnd = item; | 5481 tmpitem[thisbox->count].hwnd = item; |
5303 tmpitem[thisbox->count].origwidth = tmpitem[thisbox->count].width = width; | 5482 tmpitem[thisbox->count].origwidth = tmpitem[thisbox->count].width = width; |
5304 tmpitem[thisbox->count].origheight = tmpitem[thisbox->count].height = height; | 5483 tmpitem[thisbox->count].origheight = tmpitem[thisbox->count].height = height; |
5305 tmpitem[thisbox->count].pad = pad; | 5484 tmpitem[thisbox->count].pad = pad; |
5306 if(hsize) | 5485 if(hsize) |
5307 tmpitem[thisbox->count].hsize = SIZEEXPAND; | 5486 tmpitem[thisbox->count].hsize = SIZEEXPAND; |
5308 else | 5487 else |
5309 tmpitem[thisbox->count].hsize = SIZESTATIC; | 5488 tmpitem[thisbox->count].hsize = SIZESTATIC; |
5310 | 5489 |
5311 if(vsize) | 5490 if(vsize) |
5312 tmpitem[thisbox->count].vsize = SIZEEXPAND; | 5491 tmpitem[thisbox->count].vsize = SIZEEXPAND; |
5313 else | 5492 else |
5314 tmpitem[thisbox->count].vsize = SIZESTATIC; | 5493 tmpitem[thisbox->count].vsize = SIZESTATIC; |
5315 | 5494 |
5316 thisbox->items = tmpitem; | 5495 thisbox->items = tmpitem; |
5317 | 5496 |
5318 if(thisbox->count) | 5497 if(thisbox->count) |
5319 free(thisitem); | 5498 free(thisitem); |
5320 | 5499 |
5321 thisbox->count++; | 5500 thisbox->count++; |
5322 | 5501 |
5323 SetParent(item, box); | 5502 SetParent(item, box); |
5324 if(strncmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1)==0) | 5503 if(strncmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1)==0) |
5325 { | 5504 { |
5326 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(item, GWLP_USERDATA); | 5505 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(item, GWLP_USERDATA); |
5327 | 5506 |
5328 if(cinfo) | 5507 if(cinfo) |
5329 { | 5508 { |
5330 SetParent(cinfo->buddy, box); | 5509 SetParent(cinfo->buddy, box); |
5331 ShowWindow(cinfo->buddy, SW_SHOW); | 5510 ShowWindow(cinfo->buddy, SW_SHOW); |
5332 SendMessage(item, UDM_SETBUDDY, (WPARAM)cinfo->buddy, 0); | 5511 SendMessage(item, UDM_SETBUDDY, (WPARAM)cinfo->buddy, 0); |
5333 } | 5512 } |
5334 } | 5513 } |
5335 } | 5514 } |
5336 } | 5515 } |
5337 | 5516 |
5338 /* | 5517 /* |
5339 * Sets the size of a given window (widget). | 5518 * Sets the size of a given window (widget). |
5340 * Parameters: | 5519 * Parameters: |
5365 /* | 5544 /* |
5366 * Returns the width of the screen. | 5545 * Returns the width of the screen. |
5367 */ | 5546 */ |
5368 int API dw_screen_width(void) | 5547 int API dw_screen_width(void) |
5369 { | 5548 { |
5370 return GetSystemMetrics(SM_CXSCREEN); | 5549 return GetSystemMetrics(SM_CXSCREEN); |
5371 } | 5550 } |
5372 | 5551 |
5373 /* | 5552 /* |
5374 * Returns the height of the screen. | 5553 * Returns the height of the screen. |
5375 */ | 5554 */ |
5376 int API dw_screen_height(void) | 5555 int API dw_screen_height(void) |
5377 { | 5556 { |
5378 return GetSystemMetrics(SM_CYSCREEN); | 5557 return GetSystemMetrics(SM_CYSCREEN); |
5379 } | 5558 } |
5380 | 5559 |
5381 /* This should return the current color depth */ | 5560 /* This should return the current color depth */ |
5382 unsigned long API dw_color_depth_get(void) | 5561 unsigned long API dw_color_depth_get(void) |
5383 { | 5562 { |
5384 int bpp; | 5563 int bpp; |
5385 HDC hdc = GetDC(HWND_DESKTOP); | 5564 HDC hdc = GetDC(HWND_DESKTOP); |
5386 | 5565 |
5387 bpp = GetDeviceCaps(hdc, BITSPIXEL); | 5566 bpp = GetDeviceCaps(hdc, BITSPIXEL); |
5388 | 5567 |
5389 ReleaseDC(HWND_DESKTOP, hdc); | 5568 ReleaseDC(HWND_DESKTOP, hdc); |
5390 | 5569 |
5391 return bpp; | 5570 return bpp; |
5392 } | 5571 } |
5393 | 5572 |
5394 | 5573 |
5395 /* | 5574 /* |
5396 * Sets the position of a given window (widget). | 5575 * Sets the position of a given window (widget). |
5399 * x: X location from the bottom left. | 5578 * x: X location from the bottom left. |
5400 * y: Y location from the bottom left. | 5579 * y: Y location from the bottom left. |
5401 */ | 5580 */ |
5402 void API dw_window_set_pos(HWND handle, ULONG x, ULONG y) | 5581 void API dw_window_set_pos(HWND handle, ULONG x, ULONG y) |
5403 { | 5582 { |
5404 SetWindowPos(handle, (HWND)NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); | 5583 SetWindowPos(handle, (HWND)NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); |
5405 } | 5584 } |
5406 | 5585 |
5407 /* | 5586 /* |
5408 * Sets the position and size of a given window (widget). | 5587 * Sets the position and size of a given window (widget). |
5409 * Parameters: | 5588 * Parameters: |
5440 * width: Width of the widget. | 5619 * width: Width of the widget. |
5441 * height: Height of the widget. | 5620 * height: Height of the widget. |
5442 */ | 5621 */ |
5443 void API dw_window_get_pos_size(HWND handle, ULONG *x, ULONG *y, ULONG *width, ULONG *height) | 5622 void API dw_window_get_pos_size(HWND handle, ULONG *x, ULONG *y, ULONG *width, ULONG *height) |
5444 { | 5623 { |
5445 WINDOWPLACEMENT wp; | 5624 WINDOWPLACEMENT wp; |
5446 | 5625 |
5447 wp.length = sizeof(WINDOWPLACEMENT); | 5626 wp.length = sizeof(WINDOWPLACEMENT); |
5448 | 5627 |
5449 GetWindowPlacement(handle, &wp); | 5628 GetWindowPlacement(handle, &wp); |
5450 if( wp.showCmd == SW_SHOWMAXIMIZED) | 5629 if( wp.showCmd == SW_SHOWMAXIMIZED) |
5451 { | 5630 { |
5452 if(x) | 5631 if(x) |
5453 *x=0; | 5632 *x=0; |
5454 if(y) | 5633 if(y) |
5455 *y=0; | 5634 *y=0; |
5456 if(width) | 5635 if(width) |
5457 *width=dw_screen_width(); | 5636 *width=dw_screen_width(); |
5458 if(height) | 5637 if(height) |
5459 *height=dw_screen_height(); | 5638 *height=dw_screen_height(); |
5460 } | 5639 } |
5461 else | 5640 else |
5462 { | 5641 { |
5463 if(x) | 5642 if(x) |
5464 *x = wp.rcNormalPosition.left; | 5643 *x = wp.rcNormalPosition.left; |
5465 if(y) | 5644 if(y) |
5466 *y = wp.rcNormalPosition.top; | 5645 *y = wp.rcNormalPosition.top; |
5467 if(width) | 5646 if(width) |
5468 *width = wp.rcNormalPosition.right - wp.rcNormalPosition.left; | 5647 *width = wp.rcNormalPosition.right - wp.rcNormalPosition.left; |
5469 if(height) | 5648 if(height) |
5470 *height = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top; | 5649 *height = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top; |
5471 } | 5650 } |
5472 } | 5651 } |
5473 | 5652 |
5474 /* | 5653 /* |
5475 * Sets the style of a given window (widget). | 5654 * Sets the style of a given window (widget). |
5476 * Parameters: | 5655 * Parameters: |
5478 * width: New width in pixels. | 5657 * width: New width in pixels. |
5479 * height: New height in pixels. | 5658 * height: New height in pixels. |
5480 */ | 5659 */ |
5481 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask) | 5660 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask) |
5482 { | 5661 { |
5483 ULONG tmp, currentstyle = GetWindowLong(handle, GWL_STYLE); | 5662 ULONG tmp, currentstyle = GetWindowLong(handle, GWL_STYLE); |
5484 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 5663 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
5485 | 5664 |
5486 tmp = currentstyle | mask; | 5665 tmp = currentstyle | mask; |
5487 tmp ^= mask; | 5666 tmp ^= mask; |
5488 tmp |= style; | 5667 tmp |= style; |
5489 | 5668 |
5490 | 5669 |
5491 /* We are using SS_NOPREFIX as a VCENTER flag */ | 5670 /* We are using SS_NOPREFIX as a VCENTER flag */ |
5492 if(tmp & SS_NOPREFIX) | 5671 if(tmp & SS_NOPREFIX) |
5493 { | 5672 { |
5494 | 5673 |
5495 if(cinfo) | 5674 if(cinfo) |
5496 cinfo->vcenter = 1; | 5675 cinfo->vcenter = 1; |
5497 else | 5676 else |
5498 { | 5677 { |
5499 cinfo = calloc(1, sizeof(ColorInfo)); | 5678 cinfo = calloc(1, sizeof(ColorInfo)); |
5500 cinfo->fore = cinfo->back = -1; | 5679 cinfo->fore = cinfo->back = -1; |
5501 cinfo->vcenter = 1; | 5680 cinfo->vcenter = 1; |
5502 | 5681 |
5503 cinfo->pOldProc = SubclassWindow(handle, _colorwndproc); | 5682 cinfo->pOldProc = SubclassWindow(handle, _colorwndproc); |
5504 SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)cinfo); | 5683 SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)cinfo); |
5505 } | 5684 } |
5506 } | 5685 } |
5507 else if(cinfo) | 5686 else if(cinfo) |
5508 cinfo->vcenter = 0; | 5687 cinfo->vcenter = 0; |
5509 | 5688 |
5510 SetWindowLong(handle, GWL_STYLE, tmp); | 5689 SetWindowLong(handle, GWL_STYLE, tmp); |
5511 } | 5690 } |
5512 | 5691 |
5513 /* Finds the physical ID from the reference ID */ | 5692 /* Finds the physical ID from the reference ID */ |
5514 int _findnotebookid(NotebookPage **array, int pageid) | 5693 int _findnotebookid(NotebookPage **array, int pageid) |
5515 { | 5694 { |
5516 int z; | 5695 int z; |
5517 | 5696 |
5518 for(z=0;z<256;z++) | 5697 for(z=0;z<256;z++) |
5519 { | 5698 { |
5520 if(array[z] && array[z]->realid == pageid) | 5699 if(array[z] && array[z]->realid == pageid) |
5521 return z; | 5700 return z; |
5522 } | 5701 } |
5523 return -1; | 5702 return -1; |
5524 } | 5703 } |
5525 | 5704 |
5526 /* | 5705 /* |
5527 * Adds a new page to specified notebook. | 5706 * Adds a new page to specified notebook. |
5528 * Parameters: | 5707 * Parameters: |
5530 * flags: Any additional page creation flags. | 5709 * flags: Any additional page creation flags. |
5531 * front: If TRUE page is added at the beginning. | 5710 * front: If TRUE page is added at the beginning. |
5532 */ | 5711 */ |
5533 unsigned long API dw_notebook_page_new(HWND handle, ULONG flags, int front) | 5712 unsigned long API dw_notebook_page_new(HWND handle, ULONG flags, int front) |
5534 { | 5713 { |
5535 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); | 5714 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); |
5536 | 5715 |
5537 if(array) | 5716 if(array) |
5538 { | 5717 { |
5539 int z, refid = -1; | 5718 int z, refid = -1; |
5540 | 5719 |
5541 for(z=0;z<256;z++) | 5720 for(z=0;z<256;z++) |
5542 { | 5721 { |
5543 if(_findnotebookid(array, z) == -1) | 5722 if(_findnotebookid(array, z) == -1) |
5544 { | 5723 { |
5545 refid = z; | 5724 refid = z; |
5546 break; | 5725 break; |
5547 } | 5726 } |
5548 } | 5727 } |
5549 | 5728 |
5550 if(refid == -1) | 5729 if(refid == -1) |
5551 return -1; | 5730 return -1; |
5552 | 5731 |
5553 for(z=0;z<256;z++) | 5732 for(z=0;z<256;z++) |
5554 { | 5733 { |
5555 if(!array[z]) | 5734 if(!array[z]) |
5556 { | 5735 { |
5557 int oldpage = TabCtrl_GetCurSel(handle); | 5736 int oldpage = TabCtrl_GetCurSel(handle); |
5558 | 5737 |
5559 array[z] = calloc(1, sizeof(NotebookPage)); | 5738 array[z] = calloc(1, sizeof(NotebookPage)); |
5560 array[z]->realid = refid; | 5739 array[z]->realid = refid; |
5561 array[z]->item.mask = TCIF_TEXT; | 5740 array[z]->item.mask = TCIF_TEXT; |
5562 array[z]->item.iImage = -1; | 5741 array[z]->item.iImage = -1; |
5563 array[z]->item.pszText = ""; | 5742 array[z]->item.pszText = ""; |
5564 TabCtrl_InsertItem(handle, z, &(array[z]->item)); | 5743 TabCtrl_InsertItem(handle, z, &(array[z]->item)); |
5565 | 5744 |
5566 if(oldpage > -1 && array[oldpage]) | 5745 if(oldpage > -1 && array[oldpage]) |
5567 SetParent(array[oldpage]->hwnd, DW_HWND_OBJECT); | 5746 SetParent(array[oldpage]->hwnd, DW_HWND_OBJECT); |
5568 | 5747 |
5569 TabCtrl_SetCurSel(handle, z); | 5748 TabCtrl_SetCurSel(handle, z); |
5570 return refid; | 5749 return refid; |
5571 } | 5750 } |
5572 } | 5751 } |
5573 } | 5752 } |
5574 return -1; | 5753 return -1; |
5575 } | 5754 } |
5576 | 5755 |
5577 /* | 5756 /* |
5578 * Sets the text on the specified notebook tab. | 5757 * Sets the text on the specified notebook tab. |
5579 * Parameters: | 5758 * Parameters: |
5582 * text: Pointer to the text to set. | 5761 * text: Pointer to the text to set. |
5583 */ | 5762 */ |
5584 void API dw_notebook_page_set_text(HWND handle, ULONG pageidx, char *text) | 5763 void API dw_notebook_page_set_text(HWND handle, ULONG pageidx, char *text) |
5585 { | 5764 { |
5586 | 5765 |
5587 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); | 5766 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); |
5588 int pageid; | 5767 int pageid; |
5589 | 5768 |
5590 if(!array) | 5769 if(!array) |
5591 return; | 5770 return; |
5592 | 5771 |
5593 pageid = _findnotebookid(array, pageidx); | 5772 pageid = _findnotebookid(array, pageidx); |
5594 | 5773 |
5595 if(pageid > -1 && array[pageid]) | 5774 if(pageid > -1 && array[pageid]) |
5596 { | 5775 { |
5597 array[pageid]->item.mask = TCIF_TEXT; | 5776 array[pageid]->item.mask = TCIF_TEXT; |
5598 array[pageid]->item.pszText = text; | 5777 array[pageid]->item.pszText = text; |
5599 TabCtrl_SetItem(handle, pageid, &(array[pageid]->item)); | 5778 TabCtrl_SetItem(handle, pageid, &(array[pageid]->item)); |
5600 _resize_notebook_page(handle, pageid); | 5779 _resize_notebook_page(handle, pageid); |
5601 } | 5780 } |
5602 } | 5781 } |
5603 | 5782 |
5604 /* | 5783 /* |
5605 * Sets the text on the specified notebook tab status area. | 5784 * Sets the text on the specified notebook tab status area. |
5606 * Parameters: | 5785 * Parameters: |
5619 * pageid: Page ID in the notebook which is being packed. | 5798 * pageid: Page ID in the notebook which is being packed. |
5620 * page: Box handle to be packed. | 5799 * page: Box handle to be packed. |
5621 */ | 5800 */ |
5622 void API dw_notebook_pack(HWND handle, ULONG pageidx, HWND page) | 5801 void API dw_notebook_pack(HWND handle, ULONG pageidx, HWND page) |
5623 { | 5802 { |
5624 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); | 5803 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); |
5625 int pageid; | 5804 int pageid; |
5626 | 5805 |
5627 if(!array) | 5806 if(!array) |
5628 return; | 5807 return; |
5629 | 5808 |
5630 pageid = _findnotebookid(array, pageidx); | 5809 pageid = _findnotebookid(array, pageidx); |
5631 | 5810 |
5632 if(pageid > -1 && array[pageid]) | 5811 if(pageid > -1 && array[pageid]) |
5633 { | 5812 { |
5634 HWND tmpbox = dw_box_new(DW_VERT, 0); | 5813 HWND tmpbox = dw_box_new(DW_VERT, 0); |
5635 | 5814 |
5636 dw_box_pack_start(tmpbox, page, 0, 0, TRUE, TRUE, 0); | 5815 dw_box_pack_start(tmpbox, page, 0, 0, TRUE, TRUE, 0); |
5637 SubclassWindow(tmpbox, _wndproc); | 5816 SubclassWindow(tmpbox, _wndproc); |
5638 if(array[pageid]->hwnd) | 5817 if(array[pageid]->hwnd) |
5639 dw_window_destroy(array[pageid]->hwnd); | 5818 dw_window_destroy(array[pageid]->hwnd); |
5640 array[pageid]->hwnd = tmpbox; | 5819 array[pageid]->hwnd = tmpbox; |
5641 if(pageidx == dw_notebook_page_get(handle)) | 5820 if(pageidx == dw_notebook_page_get(handle)) |
5642 { | 5821 { |
5643 SetParent(tmpbox, handle); | 5822 SetParent(tmpbox, handle); |
5644 _resize_notebook_page(handle, pageid); | 5823 _resize_notebook_page(handle, pageid); |
5645 } | 5824 } |
5646 } | 5825 } |
5647 } | 5826 } |
5648 | 5827 |
5649 /* | 5828 /* |
5650 * Remove a page from a notebook. | 5829 * Remove a page from a notebook. |
5651 * Parameters: | 5830 * Parameters: |
5652 * handle: Handle to the notebook widget. | 5831 * handle: Handle to the notebook widget. |
5653 * pageid: ID of the page to be destroyed. | 5832 * pageid: ID of the page to be destroyed. |
5654 */ | 5833 */ |
5655 void API dw_notebook_page_destroy(HWND handle, unsigned int pageidx) | 5834 void API dw_notebook_page_destroy(HWND handle, unsigned int pageidx) |
5656 { | 5835 { |
5657 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); | 5836 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); |
5658 int newid = -1, z, pageid; | 5837 int newid = -1, z, pageid; |
5659 | 5838 |
5660 if(!array) | 5839 if(!array) |
5661 return; | 5840 return; |
5662 | 5841 |
5663 pageid = _findnotebookid(array, pageidx); | 5842 pageid = _findnotebookid(array, pageidx); |
5664 | 5843 |
5665 if(pageid < 0) | 5844 if(pageid < 0) |
5666 return; | 5845 return; |
5667 | 5846 |
5668 if(array[pageid]) | 5847 if(array[pageid]) |
5669 { | 5848 { |
5670 SetParent(array[pageid]->hwnd, DW_HWND_OBJECT); | 5849 SetParent(array[pageid]->hwnd, DW_HWND_OBJECT); |
5671 free(array[pageid]); | 5850 free(array[pageid]); |
5672 array[pageid] = NULL; | 5851 array[pageid] = NULL; |
5673 } | 5852 } |
5674 | 5853 |
5675 TabCtrl_DeleteItem(handle, pageid); | 5854 TabCtrl_DeleteItem(handle, pageid); |
5676 | 5855 |
5677 /* Shift the pages over 1 */ | 5856 /* Shift the pages over 1 */ |
5678 for(z=pageid;z<255;z++) | 5857 for(z=pageid;z<255;z++) |
5679 array[z] = array[z+1]; | 5858 array[z] = array[z+1]; |
5680 array[255] = NULL; | 5859 array[255] = NULL; |
5681 | 5860 |
5682 for(z=0;z<256;z++) | 5861 for(z=0;z<256;z++) |
5683 { | 5862 { |
5684 if(array[z]) | 5863 if(array[z]) |
5685 { | 5864 { |
5686 newid = z; | 5865 newid = z; |
5687 break; | 5866 break; |
5688 } | 5867 } |
5689 } | 5868 } |
5690 if(newid > -1) | 5869 if(newid > -1) |
5691 { | 5870 { |
5692 SetParent(array[newid]->hwnd, handle); | 5871 SetParent(array[newid]->hwnd, handle); |
5693 _resize_notebook_page(handle, newid); | 5872 _resize_notebook_page(handle, newid); |
5694 dw_notebook_page_set(handle, array[newid]->realid); | 5873 dw_notebook_page_set(handle, array[newid]->realid); |
5695 } | 5874 } |
5696 } | 5875 } |
5697 | 5876 |
5698 /* | 5877 /* |
5699 * Queries the currently visible page ID. | 5878 * Queries the currently visible page ID. |
5700 * Parameters: | 5879 * Parameters: |
5701 * handle: Handle to the notebook widget. | 5880 * handle: Handle to the notebook widget. |
5702 */ | 5881 */ |
5703 unsigned long API dw_notebook_page_get(HWND handle) | 5882 unsigned long API dw_notebook_page_get(HWND handle) |
5704 { | 5883 { |
5705 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); | 5884 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); |
5706 int physid = TabCtrl_GetCurSel(handle); | 5885 int physid = TabCtrl_GetCurSel(handle); |
5707 | 5886 |
5708 if(physid > -1 && physid < 256 && array && array[physid]) | 5887 if(physid > -1 && physid < 256 && array && array[physid]) |
5709 return array[physid]->realid; | 5888 return array[physid]->realid; |
5710 return -1; | 5889 return -1; |
5711 } | 5890 } |
5712 | 5891 |
5713 /* | 5892 /* |
5714 * Sets the currently visible page ID. | 5893 * Sets the currently visible page ID. |
5715 * Parameters: | 5894 * Parameters: |
5716 * handle: Handle to the notebook widget. | 5895 * handle: Handle to the notebook widget. |
5717 * pageid: ID of the page to be made visible. | 5896 * pageid: ID of the page to be made visible. |
5718 */ | 5897 */ |
5719 void API dw_notebook_page_set(HWND handle, unsigned int pageidx) | 5898 void API dw_notebook_page_set(HWND handle, unsigned int pageidx) |
5720 { | 5899 { |
5721 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); | 5900 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); |
5722 int pageid; | 5901 int pageid; |
5723 | 5902 |
5724 if(!array) | 5903 if(!array) |
5725 return; | 5904 return; |
5726 | 5905 |
5727 pageid = _findnotebookid(array, pageidx); | 5906 pageid = _findnotebookid(array, pageidx); |
5728 | 5907 |
5729 if(pageid > -1 && pageid < 256) | 5908 if(pageid > -1 && pageid < 256) |
5730 { | 5909 { |
5731 int oldpage = TabCtrl_GetCurSel(handle); | 5910 int oldpage = TabCtrl_GetCurSel(handle); |
5732 | 5911 |
5733 if(oldpage > -1 && array && array[oldpage]) | 5912 if(oldpage > -1 && array && array[oldpage]) |
5734 SetParent(array[oldpage]->hwnd, DW_HWND_OBJECT); | 5913 SetParent(array[oldpage]->hwnd, DW_HWND_OBJECT); |
5735 | 5914 |
5736 TabCtrl_SetCurSel(handle, pageid); | 5915 TabCtrl_SetCurSel(handle, pageid); |
5737 | 5916 |
5738 SetParent(array[pageid]->hwnd, handle); | 5917 SetParent(array[pageid]->hwnd, handle); |
5739 _resize_notebook_page(handle, pageid); | 5918 _resize_notebook_page(handle, pageid); |
5740 } | 5919 } |
5741 } | 5920 } |
5742 | 5921 |
5743 /* | 5922 /* |
5744 * Appends the specified text to the listbox's (or combobox) entry list. | 5923 * Appends the specified text to the listbox's (or combobox) entry list. |
5745 * Parameters: | 5924 * Parameters: |
5746 * handle: Handle to the listbox to be appended to. | 5925 * handle: Handle to the listbox to be appended to. |
5747 * text: Text to append into listbox. | 5926 * text: Text to append into listbox. |
5748 */ | 5927 */ |
5749 void API dw_listbox_append(HWND handle, char *text) | 5928 void API dw_listbox_append(HWND handle, char *text) |
5750 { | 5929 { |
5751 char tmpbuf[100]; | 5930 char tmpbuf[100]; |
5752 | 5931 |
5753 GetClassName(handle, tmpbuf, 99); | 5932 GetClassName(handle, tmpbuf, 99); |
5754 | 5933 |
5755 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) | 5934 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) |
5756 SendMessage(handle, | 5935 SendMessage(handle, |
5757 CB_ADDSTRING, | 5936 CB_ADDSTRING, |
5758 0, (LPARAM)text); | 5937 0, (LPARAM)text); |
5759 else | 5938 else |
5760 SendMessage(handle, | 5939 SendMessage(handle, |
5761 LB_ADDSTRING, | 5940 LB_ADDSTRING, |
5762 0, (LPARAM)text); | 5941 0, (LPARAM)text); |
5763 } | 5942 } |
5764 | 5943 |
5765 /* | 5944 /* |
5766 * Appends the specified text items to the listbox's (or combobox) entry list. | 5945 * Appends the specified text items to the listbox's (or combobox) entry list. |
5767 * Parameters: | 5946 * Parameters: |
5769 * text: Text strings to append into listbox. | 5948 * text: Text strings to append into listbox. |
5770 * count: Number of text strings to append | 5949 * count: Number of text strings to append |
5771 */ | 5950 */ |
5772 void API dw_listbox_list_append(HWND handle, char **text, int count) | 5951 void API dw_listbox_list_append(HWND handle, char **text, int count) |
5773 { | 5952 { |
5774 char tmpbuf[100]; | 5953 char tmpbuf[100]; |
5775 int listbox_type; | 5954 int listbox_type; |
5776 int i; | 5955 int i; |
5777 | 5956 |
5778 GetClassName(handle, tmpbuf, 99); | 5957 GetClassName(handle, tmpbuf, 99); |
5779 | 5958 |
5780 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) | 5959 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) |
5781 listbox_type = CB_ADDSTRING; | 5960 listbox_type = CB_ADDSTRING; |
5782 else | 5961 else |
5783 listbox_type = LB_ADDSTRING; | 5962 listbox_type = LB_ADDSTRING; |
5784 | 5963 |
5785 for(i=0;i<count;i++) | 5964 for(i=0;i<count;i++) |
5786 SendMessage(handle,(WPARAM)listbox_type,0,(LPARAM)text[i]); | 5965 SendMessage(handle,(WPARAM)listbox_type,0,(LPARAM)text[i]); |
5787 } | 5966 } |
5788 | 5967 |
5789 /* | 5968 /* |
5790 * Clears the listbox's (or combobox) list of all entries. | 5969 * Clears the listbox's (or combobox) list of all entries. |
5791 * Parameters: | 5970 * Parameters: |
5792 * handle: Handle to the listbox to be cleared. | 5971 * handle: Handle to the listbox to be cleared. |
5793 */ | 5972 */ |
5794 void API dw_listbox_clear(HWND handle) | 5973 void API dw_listbox_clear(HWND handle) |
5795 { | 5974 { |
5796 char tmpbuf[100]; | 5975 char tmpbuf[100]; |
5797 | 5976 |
5798 GetClassName(handle, tmpbuf, 99); | 5977 GetClassName(handle, tmpbuf, 99); |
5799 | 5978 |
5800 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) | 5979 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) |
5801 { | 5980 { |
5802 char *buf = dw_window_get_text(handle); | 5981 char *buf = dw_window_get_text(handle); |
5803 | 5982 |
5804 SendMessage(handle, | 5983 SendMessage(handle, |
5805 CB_RESETCONTENT, 0L, 0L); | 5984 CB_RESETCONTENT, 0L, 0L); |
5806 | 5985 |
5807 if(buf) | 5986 if(buf) |
5808 { | 5987 { |
5809 dw_window_set_text(handle, buf); | 5988 dw_window_set_text(handle, buf); |
5810 free(buf); | 5989 free(buf); |
5811 } | 5990 } |
5812 } | 5991 } |
5813 else | 5992 else |
5814 SendMessage(handle, | 5993 SendMessage(handle, |
5815 LB_RESETCONTENT, 0L, 0L); | 5994 LB_RESETCONTENT, 0L, 0L); |
5816 } | 5995 } |
5817 | 5996 |
5818 /* | 5997 /* |
5819 * Sets the text of a given listbox entry. | 5998 * Sets the text of a given listbox entry. |
5820 * Parameters: | 5999 * Parameters: |
5822 * index: Index into the list to be queried. | 6001 * index: Index into the list to be queried. |
5823 * buffer: Buffer where text will be copied. | 6002 * buffer: Buffer where text will be copied. |
5824 */ | 6003 */ |
5825 void API dw_listbox_set_text(HWND handle, unsigned int index, char *buffer) | 6004 void API dw_listbox_set_text(HWND handle, unsigned int index, char *buffer) |
5826 { | 6005 { |
5827 char tmpbuf[100]; | 6006 char tmpbuf[100]; |
5828 | 6007 |
5829 GetClassName(handle, tmpbuf, 99); | 6008 GetClassName(handle, tmpbuf, 99); |
5830 | 6009 |
5831 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) | 6010 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) |
5832 { | 6011 { |
5833 SendMessage(handle, CB_DELETESTRING, (WPARAM)index, 0); | 6012 SendMessage(handle, CB_DELETESTRING, (WPARAM)index, 0); |
5834 SendMessage(handle, CB_INSERTSTRING, (WPARAM)index, (LPARAM)buffer); | 6013 SendMessage(handle, CB_INSERTSTRING, (WPARAM)index, (LPARAM)buffer); |
5835 } | 6014 } |
5836 else | 6015 else |
5837 { | 6016 { |
5838 unsigned int sel = (unsigned int)SendMessage(handle, LB_GETCURSEL, 0, 0); | 6017 unsigned int sel = (unsigned int)SendMessage(handle, LB_GETCURSEL, 0, 0); |
5839 SendMessage(handle, LB_DELETESTRING, (WPARAM)index, 0); | 6018 SendMessage(handle, LB_DELETESTRING, (WPARAM)index, 0); |
5840 SendMessage(handle, LB_INSERTSTRING, (WPARAM)index, (LPARAM)buffer); | 6019 SendMessage(handle, LB_INSERTSTRING, (WPARAM)index, (LPARAM)buffer); |
5841 SendMessage(handle, LB_SETCURSEL, (WPARAM)sel, 0); | 6020 SendMessage(handle, LB_SETCURSEL, (WPARAM)sel, 0); |
5842 SendMessage(handle, LB_SETSEL, (WPARAM)TRUE, (LPARAM)sel); | 6021 SendMessage(handle, LB_SETSEL, (WPARAM)TRUE, (LPARAM)sel); |
5843 } | 6022 } |
5844 } | 6023 } |
5845 | 6024 |
5846 /* | 6025 /* |
5847 * Copies the given index item's text into buffer. | 6026 * Copies the given index item's text into buffer. |
5848 * Parameters: | 6027 * Parameters: |
5851 * buffer: Buffer where text will be copied. | 6030 * buffer: Buffer where text will be copied. |
5852 * length: Length of the buffer (including NULL). | 6031 * length: Length of the buffer (including NULL). |
5853 */ | 6032 */ |
5854 void API dw_listbox_get_text(HWND handle, unsigned int index, char *buffer, unsigned int length) | 6033 void API dw_listbox_get_text(HWND handle, unsigned int index, char *buffer, unsigned int length) |
5855 { | 6034 { |
5856 char tmpbuf[100]; | 6035 char tmpbuf[100]; |
5857 int len; | 6036 int len; |
5858 | 6037 |
5859 if(!buffer || !length) | 6038 if(!buffer || !length) |
5860 return; | 6039 return; |
5861 | 6040 |
5862 buffer[0] = 0; | 6041 buffer[0] = 0; |
5863 | 6042 |
5864 GetClassName(handle, tmpbuf, 99); | 6043 GetClassName(handle, tmpbuf, 99); |
5865 | 6044 |
5866 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) | 6045 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) |
5867 { | 6046 { |
5868 len = (int)SendMessage(handle, CB_GETLBTEXTLEN, (WPARAM)index, 0); | 6047 len = (int)SendMessage(handle, CB_GETLBTEXTLEN, (WPARAM)index, 0); |
5869 | 6048 |
5870 if(len < length && len != CB_ERR) | 6049 if(len < length && len != CB_ERR) |
5871 SendMessage(handle, | 6050 SendMessage(handle, |
5872 CB_GETLBTEXT, (WPARAM)index, (LPARAM)buffer); | 6051 CB_GETLBTEXT, (WPARAM)index, (LPARAM)buffer); |
5873 } | 6052 } |
5874 else | 6053 else |
5875 { | 6054 { |
5876 len = (int)SendMessage(handle, LB_GETTEXTLEN, (WPARAM)index, 0); | 6055 len = (int)SendMessage(handle, LB_GETTEXTLEN, (WPARAM)index, 0); |
5877 | 6056 |
5878 if(len < length && len != LB_ERR) | 6057 if(len < length && len != LB_ERR) |
5879 SendMessage(handle, | 6058 SendMessage(handle, |
5880 LB_GETTEXT, (WPARAM)index, (LPARAM)buffer); | 6059 LB_GETTEXT, (WPARAM)index, (LPARAM)buffer); |
5881 } | 6060 } |
5882 } | 6061 } |
5883 | 6062 |
5884 /* | 6063 /* |
5885 * Returns the index to the item in the list currently selected. | 6064 * Returns the index to the item in the list currently selected. |
5886 * Parameters: | 6065 * Parameters: |
5887 * handle: Handle to the listbox to be queried. | 6066 * handle: Handle to the listbox to be queried. |
5888 */ | 6067 */ |
5889 unsigned int API dw_listbox_selected(HWND handle) | 6068 unsigned int API dw_listbox_selected(HWND handle) |
5890 { | 6069 { |
5891 char tmpbuf[100]; | 6070 char tmpbuf[100]; |
5892 | 6071 |
5893 GetClassName(handle, tmpbuf, 99); | 6072 GetClassName(handle, tmpbuf, 99); |
5894 | 6073 |
5895 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) | 6074 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) |
5896 return (unsigned int)SendMessage(handle, | 6075 return (unsigned int)SendMessage(handle, |
5897 CB_GETCURSEL, | 6076 CB_GETCURSEL, |
5898 0, 0); | 6077 0, 0); |
5899 | 6078 |
5900 return (unsigned int)SendMessage(handle, | 6079 return (unsigned int)SendMessage(handle, |
5901 LB_GETCURSEL, | 6080 LB_GETCURSEL, |
5902 0, 0); | 6081 0, 0); |
5903 } | 6082 } |
5904 | 6083 |
5905 /* | 6084 /* |
5906 * Returns the index to the current selected item or -1 when done. | 6085 * Returns the index to the current selected item or -1 when done. |
5907 * Parameters: | 6086 * Parameters: |
5908 * handle: Handle to the listbox to be queried. | 6087 * handle: Handle to the listbox to be queried. |
5909 * where: Either the previous return or -1 to restart. | 6088 * where: Either the previous return or -1 to restart. |
5910 */ | 6089 */ |
5911 int API dw_listbox_selected_multi(HWND handle, int where) | 6090 int API dw_listbox_selected_multi(HWND handle, int where) |
5912 { | 6091 { |
5913 int *array, count, z; | 6092 int *array, count, z; |
5914 char tmpbuf[100]; | 6093 char tmpbuf[100]; |
5915 | 6094 |
5916 GetClassName(handle, tmpbuf, 99); | 6095 GetClassName(handle, tmpbuf, 99); |
5917 | 6096 |
5918 /* This doesn't work on comboboxes */ | 6097 /* This doesn't work on comboboxes */ |
5919 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) | 6098 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) |
5920 return -1; | 6099 return -1; |
5921 | 6100 |
5922 count = (int)SendMessage(handle, LB_GETSELCOUNT, 0, 0); | 6101 count = (int)SendMessage(handle, LB_GETSELCOUNT, 0, 0); |
5923 if(count > 0) | 6102 if(count > 0) |
5924 { | 6103 { |
5925 array = malloc(sizeof(int)*count); | 6104 array = malloc(sizeof(int)*count); |
5926 SendMessage(handle, LB_GETSELITEMS, (WPARAM)count, (LPARAM)array); | 6105 SendMessage(handle, LB_GETSELITEMS, (WPARAM)count, (LPARAM)array); |
5927 | 6106 |
5928 if(where == -1) | 6107 if(where == -1) |
5929 { | 6108 { |
5930 int ret = array[0]; | 6109 int ret = array[0]; |
5931 free(array); | 6110 free(array); |
5932 return ret; | 6111 return ret; |
5933 } | 6112 } |
5934 for(z=0;z<count;z++) | 6113 for(z=0;z<count;z++) |
5935 { | 6114 { |
5936 if(array[z] == where && (z+1) < count) | 6115 if(array[z] == where && (z+1) < count) |
5937 { | 6116 { |
5938 int ret = array[z+1]; | 6117 int ret = array[z+1]; |
5939 free(array); | 6118 free(array); |
5940 return ret; | 6119 return ret; |
5941 } | 6120 } |
5942 } | 6121 } |
5943 free(array); | 6122 free(array); |
5944 } | 6123 } |
5945 return -1; | 6124 return -1; |
5946 } | 6125 } |
5947 | 6126 |
5948 /* | 6127 /* |
5949 * Sets the selection state of a given index. | 6128 * Sets the selection state of a given index. |
5950 * Parameters: | 6129 * Parameters: |
5952 * index: Item index. | 6131 * index: Item index. |
5953 * state: TRUE if selected FALSE if unselected. | 6132 * state: TRUE if selected FALSE if unselected. |
5954 */ | 6133 */ |
5955 void API dw_listbox_select(HWND handle, int index, int state) | 6134 void API dw_listbox_select(HWND handle, int index, int state) |
5956 { | 6135 { |
5957 char tmpbuf[100]; | 6136 char tmpbuf[100]; |
5958 | 6137 |
5959 GetClassName(handle, tmpbuf, 99); | 6138 GetClassName(handle, tmpbuf, 99); |
5960 | 6139 |
5961 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) | 6140 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) |
5962 SendMessage(handle, CB_SETCURSEL, (WPARAM)index, 0); | 6141 SendMessage(handle, CB_SETCURSEL, (WPARAM)index, 0); |
5963 else | 6142 else |
5964 { | 6143 { |
5965 SendMessage(handle, LB_SETCURSEL, (WPARAM)index, 0); | 6144 SendMessage(handle, LB_SETCURSEL, (WPARAM)index, 0); |
5966 SendMessage(handle, LB_SETSEL, (WPARAM)state, (LPARAM)index); | 6145 SendMessage(handle, LB_SETSEL, (WPARAM)state, (LPARAM)index); |
5967 } | 6146 } |
5968 _wndproc(handle, WM_COMMAND, (WPARAM)(LBN_SELCHANGE << 16), (LPARAM)handle); | 6147 _wndproc(handle, WM_COMMAND, (WPARAM)(LBN_SELCHANGE << 16), (LPARAM)handle); |
5969 } | 6148 } |
5970 | 6149 |
5971 /* | 6150 /* |
5972 * Deletes the item with given index from the list. | 6151 * Deletes the item with given index from the list. |
5973 * Parameters: | 6152 * Parameters: |
5974 * handle: Handle to the listbox to be set. | 6153 * handle: Handle to the listbox to be set. |
5975 * index: Item index. | 6154 * index: Item index. |
5976 */ | 6155 */ |
5977 void API dw_listbox_delete(HWND handle, int index) | 6156 void API dw_listbox_delete(HWND handle, int index) |
5978 { | 6157 { |
5979 char tmpbuf[100]; | 6158 char tmpbuf[100]; |
5980 | 6159 |
5981 GetClassName(handle, tmpbuf, 99); | 6160 GetClassName(handle, tmpbuf, 99); |
5982 | 6161 |
5983 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) | 6162 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) |
5984 SendMessage(handle, CB_DELETESTRING, (WPARAM)index, 0); | 6163 SendMessage(handle, CB_DELETESTRING, (WPARAM)index, 0); |
5985 else | 6164 else |
5986 SendMessage(handle, LB_DELETESTRING, (WPARAM)index, 0); | 6165 SendMessage(handle, LB_DELETESTRING, (WPARAM)index, 0); |
5987 } | 6166 } |
5988 | 6167 |
5989 /* | 6168 /* |
5990 * Returns the listbox's item count. | 6169 * Returns the listbox's item count. |
5991 * Parameters: | 6170 * Parameters: |
5992 * handle: Handle to the listbox to be cleared. | 6171 * handle: Handle to the listbox to be cleared. |
5993 */ | 6172 */ |
5994 int API dw_listbox_count(HWND handle) | 6173 int API dw_listbox_count(HWND handle) |
5995 { | 6174 { |
5996 char tmpbuf[100]; | 6175 char tmpbuf[100]; |
5997 | 6176 |
5998 GetClassName(handle, tmpbuf, 99); | 6177 GetClassName(handle, tmpbuf, 99); |
5999 | 6178 |
6000 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) | 6179 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) |
6001 return (int)SendMessage(handle, | 6180 return (int)SendMessage(handle, |
6002 CB_GETCOUNT,0L, 0L); | 6181 CB_GETCOUNT,0L, 0L); |
6003 | 6182 |
6004 return (int)SendMessage(handle, | 6183 return (int)SendMessage(handle, |
6005 LB_GETCOUNT,0L, 0L); | 6184 LB_GETCOUNT,0L, 0L); |
6006 } | 6185 } |
6007 | 6186 |
6008 /* | 6187 /* |
6009 * Sets the topmost item in the viewport. | 6188 * Sets the topmost item in the viewport. |
6010 * Parameters: | 6189 * Parameters: |
6011 * handle: Handle to the listbox to be cleared. | 6190 * handle: Handle to the listbox to be cleared. |
6012 * top: Index to the top item. | 6191 * top: Index to the top item. |
6013 */ | 6192 */ |
6014 void API dw_listbox_set_top(HWND handle, int top) | 6193 void API dw_listbox_set_top(HWND handle, int top) |
6015 { | 6194 { |
6016 char tmpbuf[100]; | 6195 char tmpbuf[100]; |
6017 | 6196 |
6018 GetClassName(handle, tmpbuf, 99); | 6197 GetClassName(handle, tmpbuf, 99); |
6019 | 6198 |
6020 /* This doesn't work on comboboxes */ | 6199 /* This doesn't work on comboboxes */ |
6021 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) | 6200 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) |
6022 return; | 6201 return; |
6023 | 6202 |
6024 SendMessage(handle, LB_SETTOPINDEX, (WPARAM)top, 0); | 6203 SendMessage(handle, LB_SETTOPINDEX, (WPARAM)top, 0); |
6025 } | 6204 } |
6026 | 6205 |
6027 /* | 6206 /* |
6028 * Adds text to an MLE box and returns the current point. | 6207 * Adds text to an MLE box and returns the current point. |
6029 * Parameters: | 6208 * Parameters: |
6031 * buffer: Text buffer to be imported. | 6210 * buffer: Text buffer to be imported. |
6032 * startpoint: Point to start entering text. | 6211 * startpoint: Point to start entering text. |
6033 */ | 6212 */ |
6034 unsigned int API dw_mle_import(HWND handle, char *buffer, int startpoint) | 6213 unsigned int API dw_mle_import(HWND handle, char *buffer, int startpoint) |
6035 { | 6214 { |
6036 int textlen, len = GetWindowTextLength(handle); | 6215 int textlen, len = GetWindowTextLength(handle); |
6037 char *tmpbuf; | 6216 char *tmpbuf; |
6038 | 6217 |
6039 if((textlen = strlen(buffer)) < 1) | 6218 if((textlen = strlen(buffer)) < 1) |
6040 return startpoint; | 6219 return startpoint; |
6041 | 6220 |
6042 startpoint++; | 6221 startpoint++; |
6043 tmpbuf = calloc(1, len + textlen + startpoint + 2); | 6222 tmpbuf = calloc(1, len + textlen + startpoint + 2); |
6044 | 6223 |
6045 if(startpoint < 0) | 6224 if(startpoint < 0) |
6046 startpoint = 0; | 6225 startpoint = 0; |
6047 | 6226 |
6048 if(len) | 6227 if(len) |
6049 { | 6228 { |
6050 char *dest, *start; | 6229 char *dest, *start; |
6051 int copylen = len - startpoint; | 6230 int copylen = len - startpoint; |
6052 | 6231 |
6053 GetWindowText(handle, tmpbuf, len+1); | 6232 GetWindowText(handle, tmpbuf, len+1); |
6054 | 6233 |
6055 dest = &tmpbuf[startpoint+textlen-1]; | 6234 dest = &tmpbuf[startpoint+textlen-1]; |
6056 start = &tmpbuf[startpoint]; | 6235 start = &tmpbuf[startpoint]; |
6057 | 6236 |
6058 if(copylen > 0) | 6237 if(copylen > 0) |
6059 memcpy(dest, start, copylen); | 6238 memcpy(dest, start, copylen); |
6060 } | 6239 } |
6061 memcpy(&tmpbuf[startpoint], buffer, textlen); | 6240 memcpy(&tmpbuf[startpoint], buffer, textlen); |
6062 | 6241 |
6063 SetWindowText(handle, tmpbuf); | 6242 SetWindowText(handle, tmpbuf); |
6064 | 6243 |
6065 free(tmpbuf); | 6244 free(tmpbuf); |
6066 return (startpoint + textlen - 1); | 6245 return (startpoint + textlen - 1); |
6067 } | 6246 } |
6068 | 6247 |
6069 /* | 6248 /* |
6070 * Grabs text from an MLE box. | 6249 * Grabs text from an MLE box. |
6071 * Parameters: | 6250 * Parameters: |
6074 * startpoint: Point to start grabbing text. | 6253 * startpoint: Point to start grabbing text. |
6075 * length: Amount of text to be grabbed. | 6254 * length: Amount of text to be grabbed. |
6076 */ | 6255 */ |
6077 void API dw_mle_export(HWND handle, char *buffer, int startpoint, int length) | 6256 void API dw_mle_export(HWND handle, char *buffer, int startpoint, int length) |
6078 { | 6257 { |
6079 int max, len = GetWindowTextLength(handle); | 6258 int max, len = GetWindowTextLength(handle); |
6080 char *tmpbuf = calloc(1, len+2); | 6259 char *tmpbuf = calloc(1, len+2); |
6081 | 6260 |
6082 if(len) | 6261 if(len) |
6083 GetWindowText(handle, tmpbuf, len+1); | 6262 GetWindowText(handle, tmpbuf, len+1); |
6084 | 6263 |
6085 buffer[0] = 0; | 6264 buffer[0] = 0; |
6086 | 6265 |
6087 if(startpoint < len) | 6266 if(startpoint < len) |
6088 { | 6267 { |
6089 max = MIN(length, len - startpoint); | 6268 max = MIN(length, len - startpoint); |
6090 | 6269 |
6091 memcpy(buffer, &tmpbuf[startpoint], max); | 6270 memcpy(buffer, &tmpbuf[startpoint], max); |
6092 buffer[max] = '\0'; | 6271 buffer[max] = '\0'; |
6093 } | 6272 } |
6094 | 6273 |
6095 free(tmpbuf); | 6274 free(tmpbuf); |
6096 } | 6275 } |
6097 | 6276 |
6098 /* | 6277 /* |
6099 * Obtains information about an MLE box. | 6278 * Obtains information about an MLE box. |
6100 * Parameters: | 6279 * Parameters: |
6102 * bytes: A pointer to a variable to return the total bytes. | 6281 * bytes: A pointer to a variable to return the total bytes. |
6103 * lines: A pointer to a variable to return the number of lines. | 6282 * lines: A pointer to a variable to return the number of lines. |
6104 */ | 6283 */ |
6105 void API dw_mle_get_size(HWND handle, unsigned long *bytes, unsigned long *lines) | 6284 void API dw_mle_get_size(HWND handle, unsigned long *bytes, unsigned long *lines) |
6106 { | 6285 { |
6107 if(bytes) | 6286 if(bytes) |
6108 *bytes = GetWindowTextLength(handle); | 6287 *bytes = GetWindowTextLength(handle); |
6109 if(lines) | 6288 if(lines) |
6110 *lines = (unsigned long)SendMessage(handle, EM_GETLINECOUNT, 0, 0); | 6289 *lines = (unsigned long)SendMessage(handle, EM_GETLINECOUNT, 0, 0); |
6111 } | 6290 } |
6112 | 6291 |
6113 /* | 6292 /* |
6114 * Deletes text from an MLE box. | 6293 * Deletes text from an MLE box. |
6115 * Parameters: | 6294 * Parameters: |
6117 * startpoint: Point to start deleting text. | 6296 * startpoint: Point to start deleting text. |
6118 * length: Amount of text to be deleted. | 6297 * length: Amount of text to be deleted. |
6119 */ | 6298 */ |
6120 void API dw_mle_delete(HWND handle, int startpoint, int length) | 6299 void API dw_mle_delete(HWND handle, int startpoint, int length) |
6121 { | 6300 { |
6122 int len = GetWindowTextLength(handle); | 6301 int len = GetWindowTextLength(handle); |
6123 char *tmpbuf = calloc(1, len+2); | 6302 char *tmpbuf = calloc(1, len+2); |
6124 | 6303 |
6125 GetWindowText(handle, tmpbuf, len+1); | 6304 GetWindowText(handle, tmpbuf, len+1); |
6126 | 6305 |
6127 if(startpoint + length < len) | 6306 if(startpoint + length < len) |
6128 { | 6307 { |
6129 strcpy(&tmpbuf[startpoint], &tmpbuf[startpoint+length]); | 6308 strcpy(&tmpbuf[startpoint], &tmpbuf[startpoint+length]); |
6130 | 6309 |
6131 SetWindowText(handle, tmpbuf); | 6310 SetWindowText(handle, tmpbuf); |
6132 } | 6311 } |
6133 | 6312 |
6134 free(tmpbuf); | 6313 free(tmpbuf); |
6135 } | 6314 } |
6136 | 6315 |
6137 /* | 6316 /* |
6138 * Clears all text from an MLE box. | 6317 * Clears all text from an MLE box. |
6139 * Parameters: | 6318 * Parameters: |
6140 * handle: Handle to the MLE to be cleared. | 6319 * handle: Handle to the MLE to be cleared. |
6141 */ | 6320 */ |
6142 void API dw_mle_clear(HWND handle) | 6321 void API dw_mle_clear(HWND handle) |
6143 { | 6322 { |
6144 SetWindowText(handle, ""); | 6323 SetWindowText(handle, ""); |
6145 } | 6324 } |
6146 | 6325 |
6147 /* | 6326 /* |
6148 * Sets the visible line of an MLE box. | 6327 * Sets the visible line of an MLE box. |
6149 * Parameters: | 6328 * Parameters: |
6150 * handle: Handle to the MLE. | 6329 * handle: Handle to the MLE. |
6151 * line: Line to be visible. | 6330 * line: Line to be visible. |
6152 */ | 6331 */ |
6153 void API dw_mle_set_visible(HWND handle, int line) | 6332 void API dw_mle_set_visible(HWND handle, int line) |
6154 { | 6333 { |
6155 int point = (int)SendMessage(handle, EM_LINEINDEX, (WPARAM)line, 0); | 6334 int point = (int)SendMessage(handle, EM_LINEINDEX, (WPARAM)line, 0); |
6156 dw_mle_set_cursor(handle, point); | 6335 dw_mle_set_cursor(handle, point); |
6157 } | 6336 } |
6158 | 6337 |
6159 /* | 6338 /* |
6160 * Sets the editablity of an MLE box. | 6339 * Sets the editablity of an MLE box. |
6161 * Parameters: | 6340 * Parameters: |
6162 * handle: Handle to the MLE. | 6341 * handle: Handle to the MLE. |
6163 * state: TRUE if it can be edited, FALSE for readonly. | 6342 * state: TRUE if it can be edited, FALSE for readonly. |
6164 */ | 6343 */ |
6165 void API dw_mle_set_editable(HWND handle, int state) | 6344 void API dw_mle_set_editable(HWND handle, int state) |
6166 { | 6345 { |
6167 SendMessage(handle, EM_SETREADONLY, (WPARAM)(state ? FALSE : TRUE), 0); | 6346 SendMessage(handle, EM_SETREADONLY, (WPARAM)(state ? FALSE : TRUE), 0); |
6168 } | 6347 } |
6169 | 6348 |
6170 /* | 6349 /* |
6171 * Sets the word wrap state of an MLE box. | 6350 * Sets the word wrap state of an MLE box. |
6172 * Parameters: | 6351 * Parameters: |
6173 * handle: Handle to the MLE. | 6352 * handle: Handle to the MLE. |
6174 * state: TRUE if it wraps, FALSE if it doesn't. | 6353 * state: TRUE if it wraps, FALSE if it doesn't. |
6175 */ | 6354 */ |
6176 void API dw_mle_set_word_wrap(HWND handle, int state) | 6355 void API dw_mle_set_word_wrap(HWND handle, int state) |
6177 { | 6356 { |
6178 /* If ES_AUTOHSCROLL is not set and there is not | 6357 /* If ES_AUTOHSCROLL is not set and there is not |
6179 * horizontal scrollbar it word wraps. | 6358 * horizontal scrollbar it word wraps. |
6180 */ | 6359 */ |
6181 if(state) | 6360 if(state) |
6182 dw_window_set_style(handle, 0, ES_AUTOHSCROLL); | 6361 dw_window_set_style(handle, 0, ES_AUTOHSCROLL); |
6183 else | 6362 else |
6184 dw_window_set_style(handle, ES_AUTOHSCROLL, ES_AUTOHSCROLL); | 6363 dw_window_set_style(handle, ES_AUTOHSCROLL, ES_AUTOHSCROLL); |
6185 } | 6364 } |
6186 | 6365 |
6187 /* | 6366 /* |
6188 * Sets the current cursor position of an MLE box. | 6367 * Sets the current cursor position of an MLE box. |
6189 * Parameters: | 6368 * Parameters: |
6190 * handle: Handle to the MLE to be positioned. | 6369 * handle: Handle to the MLE to be positioned. |
6191 * point: Point to position cursor. | 6370 * point: Point to position cursor. |
6192 */ | 6371 */ |
6193 void API dw_mle_set_cursor(HWND handle, int point) | 6372 void API dw_mle_set_cursor(HWND handle, int point) |
6194 { | 6373 { |
6195 SendMessage(handle, EM_SETSEL, 0, MAKELONG(point,point)); | 6374 SendMessage(handle, EM_SETSEL, 0, MAKELONG(point,point)); |
6196 SendMessage(handle, EM_SCROLLCARET, 0, 0); | 6375 SendMessage(handle, EM_SCROLLCARET, 0, 0); |
6197 } | 6376 } |
6198 | 6377 |
6199 /* | 6378 /* |
6200 * Finds text in an MLE box. | 6379 * Finds text in an MLE box. |
6201 * Parameters: | 6380 * Parameters: |
6204 * point: Start point of search. | 6383 * point: Start point of search. |
6205 * flags: Search specific flags. | 6384 * flags: Search specific flags. |
6206 */ | 6385 */ |
6207 int API dw_mle_search(HWND handle, char *text, int point, unsigned long flags) | 6386 int API dw_mle_search(HWND handle, char *text, int point, unsigned long flags) |
6208 { | 6387 { |
6209 int len = GetWindowTextLength(handle); | 6388 int len = GetWindowTextLength(handle); |
6210 char *tmpbuf = calloc(1, len+2); | 6389 char *tmpbuf = calloc(1, len+2); |
6211 int z, textlen, retval = 0; | 6390 int z, textlen, retval = 0; |
6212 | 6391 |
6213 GetWindowText(handle, tmpbuf, len+1); | 6392 GetWindowText(handle, tmpbuf, len+1); |
6214 | 6393 |
6215 textlen = strlen(text); | 6394 textlen = strlen(text); |
6216 | 6395 |
6217 if(flags & DW_MLE_CASESENSITIVE) | 6396 if(flags & DW_MLE_CASESENSITIVE) |
6218 { | 6397 { |
6219 for(z=point;z<(len-textlen) && !retval;z++) | 6398 for(z=point;z<(len-textlen) && !retval;z++) |
6220 { | 6399 { |
6221 if(strncmp(&tmpbuf[z], text, textlen) == 0) | 6400 if(strncmp(&tmpbuf[z], text, textlen) == 0) |
6222 retval = z + textlen; | 6401 retval = z + textlen; |
6223 } | 6402 } |
6224 } | 6403 } |
6225 else | 6404 else |
6226 { | 6405 { |
6227 for(z=point;z<(len-textlen) && !retval;z++) | 6406 for(z=point;z<(len-textlen) && !retval;z++) |
6228 { | 6407 { |
6229 if(strnicmp(&tmpbuf[z], text, textlen) == 0) | 6408 if(strnicmp(&tmpbuf[z], text, textlen) == 0) |
6230 retval = z + textlen; | 6409 retval = z + textlen; |
6231 } | 6410 } |
6232 } | 6411 } |
6233 | 6412 |
6234 if(retval) | 6413 if(retval) |
6235 { | 6414 { |
6236 SendMessage(handle, EM_SETSEL, (WPARAM)retval - textlen, (LPARAM)retval); | 6415 SendMessage(handle, EM_SETSEL, (WPARAM)retval - textlen, (LPARAM)retval); |
6237 SendMessage(handle, EM_SCROLLCARET, 0, 0); | 6416 SendMessage(handle, EM_SCROLLCARET, 0, 0); |
6238 } | 6417 } |
6239 | 6418 |
6240 free(tmpbuf); | 6419 free(tmpbuf); |
6241 | 6420 |
6242 return retval; | 6421 return retval; |
6243 } | 6422 } |
6244 | 6423 |
6245 /* | 6424 /* |
6246 * Stops redrawing of an MLE box. | 6425 * Stops redrawing of an MLE box. |
6247 * Parameters: | 6426 * Parameters: |
6266 * handle: Handle to the percent bar to be set. | 6445 * handle: Handle to the percent bar to be set. |
6267 * position: Position of the percent bar withing the range. | 6446 * position: Position of the percent bar withing the range. |
6268 */ | 6447 */ |
6269 void API dw_percent_set_pos(HWND handle, unsigned int position) | 6448 void API dw_percent_set_pos(HWND handle, unsigned int position) |
6270 { | 6449 { |
6271 SendMessage(handle, PBM_SETPOS, (WPARAM)position, 0); | 6450 SendMessage(handle, PBM_SETPOS, (WPARAM)position, 0); |
6272 } | 6451 } |
6273 | 6452 |
6274 /* | 6453 /* |
6275 * Returns the position of the slider. | 6454 * Returns the position of the slider. |
6276 * Parameters: | 6455 * Parameters: |
6277 * handle: Handle to the slider to be queried. | 6456 * handle: Handle to the slider to be queried. |
6278 */ | 6457 */ |
6279 unsigned int API dw_slider_get_pos(HWND handle) | 6458 unsigned int API dw_slider_get_pos(HWND handle) |
6280 { | 6459 { |
6281 int max = (int)SendMessage(handle, TBM_GETRANGEMAX, 0, 0); | 6460 int max = (int)SendMessage(handle, TBM_GETRANGEMAX, 0, 0); |
6282 ULONG currentstyle = GetWindowLong(handle, GWL_STYLE); | 6461 ULONG currentstyle = GetWindowLong(handle, GWL_STYLE); |
6283 | 6462 |
6284 if(currentstyle & TBS_VERT) | 6463 if(currentstyle & TBS_VERT) |
6285 return max - (unsigned int)SendMessage(handle, TBM_GETPOS, 0, 0); | 6464 return max - (unsigned int)SendMessage(handle, TBM_GETPOS, 0, 0); |
6286 return (unsigned int)SendMessage(handle, TBM_GETPOS, 0, 0); | 6465 return (unsigned int)SendMessage(handle, TBM_GETPOS, 0, 0); |
6287 } | 6466 } |
6288 | 6467 |
6289 /* | 6468 /* |
6290 * Sets the slider position. | 6469 * Sets the slider position. |
6291 * Parameters: | 6470 * Parameters: |
6292 * handle: Handle to the slider to be set. | 6471 * handle: Handle to the slider to be set. |
6293 * position: Position of the slider withing the range. | 6472 * position: Position of the slider withing the range. |
6294 */ | 6473 */ |
6295 void API dw_slider_set_pos(HWND handle, unsigned int position) | 6474 void API dw_slider_set_pos(HWND handle, unsigned int position) |
6296 { | 6475 { |
6297 int max = (int)SendMessage(handle, TBM_GETRANGEMAX, 0, 0); | 6476 int max = (int)SendMessage(handle, TBM_GETRANGEMAX, 0, 0); |
6298 ULONG currentstyle = GetWindowLong(handle, GWL_STYLE); | 6477 ULONG currentstyle = GetWindowLong(handle, GWL_STYLE); |
6299 | 6478 |
6300 if(currentstyle & TBS_VERT) | 6479 if(currentstyle & TBS_VERT) |
6301 SendMessage(handle, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)max - position); | 6480 SendMessage(handle, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)max - position); |
6302 else | 6481 else |
6303 SendMessage(handle, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)position); | 6482 SendMessage(handle, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)position); |
6304 } | 6483 } |
6305 | 6484 |
6306 /* | 6485 /* |
6307 * Returns the position of the scrollbar. | 6486 * Returns the position of the scrollbar. |
6308 * Parameters: | 6487 * Parameters: |
6309 * handle: Handle to the scrollbar to be queried. | 6488 * handle: Handle to the scrollbar to be queried. |
6310 */ | 6489 */ |
6311 unsigned int API dw_scrollbar_get_pos(HWND handle) | 6490 unsigned int API dw_scrollbar_get_pos(HWND handle) |
6312 { | 6491 { |
6313 return (unsigned int)SendMessage(handle, SBM_GETPOS, 0, 0); | 6492 return (unsigned int)SendMessage(handle, SBM_GETPOS, 0, 0); |
6314 } | 6493 } |
6315 | 6494 |
6316 /* | 6495 /* |
6317 * Sets the scrollbar position. | 6496 * Sets the scrollbar position. |
6318 * Parameters: | 6497 * Parameters: |
6319 * handle: Handle to the scrollbar to be set. | 6498 * handle: Handle to the scrollbar to be set. |
6320 * position: Position of the scrollbar withing the range. | 6499 * position: Position of the scrollbar withing the range. |
6321 */ | 6500 */ |
6322 void API dw_scrollbar_set_pos(HWND handle, unsigned int position) | 6501 void API dw_scrollbar_set_pos(HWND handle, unsigned int position) |
6323 { | 6502 { |
6324 dw_window_set_data(handle, "_dw_scrollbar_value", (void *)position); | 6503 dw_window_set_data(handle, "_dw_scrollbar_value", (void *)position); |
6325 SendMessage(handle, SBM_SETPOS, (WPARAM)position, (LPARAM)TRUE); | 6504 SendMessage(handle, SBM_SETPOS, (WPARAM)position, (LPARAM)TRUE); |
6326 } | 6505 } |
6327 | 6506 |
6328 /* | 6507 /* |
6329 * Sets the scrollbar range. | 6508 * Sets the scrollbar range. |
6330 * Parameters: | 6509 * Parameters: |
6332 * range: Maximum range value. | 6511 * range: Maximum range value. |
6333 * visible: Visible area relative to the range. | 6512 * visible: Visible area relative to the range. |
6334 */ | 6513 */ |
6335 void API dw_scrollbar_set_range(HWND handle, unsigned int range, unsigned int visible) | 6514 void API dw_scrollbar_set_range(HWND handle, unsigned int range, unsigned int visible) |
6336 { | 6515 { |
6337 SCROLLINFO si; | 6516 SCROLLINFO si; |
6338 | 6517 |
6339 si.cbSize = sizeof(SCROLLINFO); | 6518 si.cbSize = sizeof(SCROLLINFO); |
6340 si.fMask = SIF_RANGE | SIF_PAGE; | 6519 si.fMask = SIF_RANGE | SIF_PAGE; |
6341 si.nMin = 0; | 6520 si.nMin = 0; |
6342 si.nMax = range - 1; | 6521 si.nMax = range - 1; |
6343 si.nPage = visible; | 6522 si.nPage = visible; |
6344 SendMessage(handle, SBM_SETSCROLLINFO, (WPARAM)TRUE, (LPARAM)&si); | 6523 SendMessage(handle, SBM_SETSCROLLINFO, (WPARAM)TRUE, (LPARAM)&si); |
6345 } | 6524 } |
6346 | 6525 |
6347 /* | 6526 /* |
6348 * Sets the spinbutton value. | 6527 * Sets the spinbutton value. |
6349 * Parameters: | 6528 * Parameters: |
6350 * handle: Handle to the spinbutton to be set. | 6529 * handle: Handle to the spinbutton to be set. |
6351 * position: Current value of the spinbutton. | 6530 * position: Current value of the spinbutton. |
6352 */ | 6531 */ |
6353 void API dw_spinbutton_set_pos(HWND handle, long position) | 6532 void API dw_spinbutton_set_pos(HWND handle, long position) |
6354 { | 6533 { |
6355 char tmpbuf[100]; | 6534 char tmpbuf[100]; |
6356 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 6535 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
6357 | 6536 |
6358 sprintf(tmpbuf, "%ld", position); | 6537 sprintf(tmpbuf, "%ld", position); |
6359 | 6538 |
6360 if(cinfo && cinfo->buddy) | 6539 if(cinfo && cinfo->buddy) |
6361 SetWindowText(cinfo->buddy, tmpbuf); | 6540 SetWindowText(cinfo->buddy, tmpbuf); |
6362 | 6541 |
6363 if(IS_IE5PLUS) | 6542 if(IS_IE5PLUS) |
6364 SendMessage(handle, UDM_SETPOS32, 0, (LPARAM)position); | 6543 SendMessage(handle, UDM_SETPOS32, 0, (LPARAM)position); |
6365 else | 6544 else |
6366 SendMessage(handle, UDM_SETPOS, 0, (LPARAM)MAKELONG((short)position, 0)); | 6545 SendMessage(handle, UDM_SETPOS, 0, (LPARAM)MAKELONG((short)position, 0)); |
6367 } | 6546 } |
6368 | 6547 |
6369 /* | 6548 /* |
6370 * Sets the spinbutton limits. | 6549 * Sets the spinbutton limits. |
6371 * Parameters: | 6550 * Parameters: |
6373 * position: Current value of the spinbutton. | 6552 * position: Current value of the spinbutton. |
6374 * position: Current value of the spinbutton. | 6553 * position: Current value of the spinbutton. |
6375 */ | 6554 */ |
6376 void API dw_spinbutton_set_limits(HWND handle, long upper, long lower) | 6555 void API dw_spinbutton_set_limits(HWND handle, long upper, long lower) |
6377 { | 6556 { |
6378 if(IS_IE5PLUS) | 6557 if(IS_IE5PLUS) |
6379 SendMessage(handle, UDM_SETRANGE32, (WPARAM)lower,(LPARAM)upper); | 6558 SendMessage(handle, UDM_SETRANGE32, (WPARAM)lower,(LPARAM)upper); |
6380 else | 6559 else |
6381 SendMessage(handle, UDM_SETRANGE32, (WPARAM)((short)lower), | 6560 SendMessage(handle, UDM_SETRANGE32, (WPARAM)((short)lower), |
6382 (LPARAM)((short)upper)); | 6561 (LPARAM)((short)upper)); |
6383 } | 6562 } |
6384 | 6563 |
6385 /* | 6564 /* |
6386 * Sets the entryfield character limit. | 6565 * Sets the entryfield character limit. |
6387 * Parameters: | 6566 * Parameters: |
6388 * handle: Handle to the spinbutton to be set. | 6567 * handle: Handle to the spinbutton to be set. |
6389 * limit: Number of characters the entryfield will take. | 6568 * limit: Number of characters the entryfield will take. |
6390 */ | 6569 */ |
6391 void API dw_entryfield_set_limit(HWND handle, ULONG limit) | 6570 void API dw_entryfield_set_limit(HWND handle, ULONG limit) |
6392 { | 6571 { |
6393 SendMessage(handle, EM_SETLIMITTEXT, (WPARAM)limit, 0); | 6572 SendMessage(handle, EM_SETLIMITTEXT, (WPARAM)limit, 0); |
6394 } | 6573 } |
6395 | 6574 |
6396 /* | 6575 /* |
6397 * Returns the current value of the spinbutton. | 6576 * Returns the current value of the spinbutton. |
6398 * Parameters: | 6577 * Parameters: |
6399 * handle: Handle to the spinbutton to be queried. | 6578 * handle: Handle to the spinbutton to be queried. |
6400 */ | 6579 */ |
6401 long API dw_spinbutton_get_pos(HWND handle) | 6580 long API dw_spinbutton_get_pos(HWND handle) |
6402 { | 6581 { |
6403 if(IS_IE5PLUS) | 6582 if(IS_IE5PLUS) |
6404 return (long)SendMessage(handle, UDM_GETPOS32, 0, 0); | 6583 return (long)SendMessage(handle, UDM_GETPOS32, 0, 0); |
6405 else | 6584 else |
6406 return (long)SendMessage(handle, UDM_GETPOS, 0, 0); | 6585 return (long)SendMessage(handle, UDM_GETPOS, 0, 0); |
6407 } | 6586 } |
6408 | 6587 |
6409 /* | 6588 /* |
6410 * Returns the state of the checkbox. | 6589 * Returns the state of the checkbox. |
6411 * Parameters: | 6590 * Parameters: |
6412 * handle: Handle to the checkbox to be queried. | 6591 * handle: Handle to the checkbox to be queried. |
6413 */ | 6592 */ |
6414 int API dw_checkbox_get(HWND handle) | 6593 int API dw_checkbox_get(HWND handle) |
6415 { | 6594 { |
6416 if(SendMessage(handle, BM_GETCHECK, 0, 0) == BST_CHECKED) | 6595 if(SendMessage(handle, BM_GETCHECK, 0, 0) == BST_CHECKED) |
6417 return (in_checkbox_handler ? FALSE : TRUE); | 6596 return (in_checkbox_handler ? FALSE : TRUE); |
6418 return (in_checkbox_handler ? TRUE : FALSE); | 6597 return (in_checkbox_handler ? TRUE : FALSE); |
6419 } | 6598 } |
6420 | 6599 |
6421 /* This function unchecks all radiobuttons on a box */ | 6600 /* This function unchecks all radiobuttons on a box */ |
6422 BOOL CALLBACK _uncheck_radios(HWND handle, LPARAM lParam) | 6601 BOOL CALLBACK _uncheck_radios(HWND handle, LPARAM lParam) |
6423 { | 6602 { |
6424 char tmpbuf[100]; | 6603 char tmpbuf[100]; |
6425 | 6604 |
6426 GetClassName(handle, tmpbuf, 99); | 6605 GetClassName(handle, tmpbuf, 99); |
6427 | 6606 |
6428 if(strnicmp(tmpbuf, BUTTONCLASSNAME, strlen(BUTTONCLASSNAME)+1)==0) | 6607 if(strnicmp(tmpbuf, BUTTONCLASSNAME, strlen(BUTTONCLASSNAME)+1)==0) |
6429 { | 6608 { |
6430 BubbleButton *bubble= (BubbleButton *)GetWindowLongPtr(handle, GWLP_USERDATA); | 6609 BubbleButton *bubble= (BubbleButton *)GetWindowLongPtr(handle, GWLP_USERDATA); |
6431 | 6610 |
6432 if(bubble && !bubble->checkbox) | 6611 if(bubble && !bubble->checkbox) |
6433 SendMessage(handle, BM_SETCHECK, 0, 0); | 6612 SendMessage(handle, BM_SETCHECK, 0, 0); |
6434 } | 6613 } |
6435 return TRUE; | 6614 return TRUE; |
6436 } | 6615 } |
6437 /* | 6616 /* |
6438 * Sets the state of the checkbox. | 6617 * Sets the state of the checkbox. |
6439 * Parameters: | 6618 * Parameters: |
6440 * handle: Handle to the checkbox to be queried. | 6619 * handle: Handle to the checkbox to be queried. |
6441 * value: TRUE for checked, FALSE for unchecked. | 6620 * value: TRUE for checked, FALSE for unchecked. |
6442 */ | 6621 */ |
6443 void API dw_checkbox_set(HWND handle, int value) | 6622 void API dw_checkbox_set(HWND handle, int value) |
6444 { | 6623 { |
6445 BubbleButton *bubble= (BubbleButton *)GetWindowLongPtr(handle, GWLP_USERDATA); | 6624 BubbleButton *bubble= (BubbleButton *)GetWindowLongPtr(handle, GWLP_USERDATA); |
6446 | 6625 |
6447 if(bubble && !bubble->checkbox) | 6626 if(bubble && !bubble->checkbox) |
6448 { | 6627 { |
6449 HWND parent = GetParent(handle); | 6628 HWND parent = GetParent(handle); |
6450 | 6629 |
6451 if(parent) | 6630 if(parent) |
6452 EnumChildWindows(parent, _uncheck_radios, 0); | 6631 EnumChildWindows(parent, _uncheck_radios, 0); |
6453 } | 6632 } |
6454 SendMessage(handle, BM_SETCHECK, (WPARAM)value, 0); | 6633 SendMessage(handle, BM_SETCHECK, (WPARAM)value, 0); |
6455 } | 6634 } |
6456 | 6635 |
6457 /* | 6636 /* |
6458 * Inserts an item into a tree window (widget) after another item. | 6637 * Inserts an item into a tree window (widget) after another item. |
6459 * Parameters: | 6638 * Parameters: |
6464 * parent: Parent handle or 0 if root. | 6643 * parent: Parent handle or 0 if root. |
6465 * itemdata: Item specific data. | 6644 * itemdata: Item specific data. |
6466 */ | 6645 */ |
6467 HTREEITEM API dw_tree_insert_after(HWND handle, HTREEITEM item, char *title, unsigned long icon, HTREEITEM parent, void *itemdata) | 6646 HTREEITEM API dw_tree_insert_after(HWND handle, HTREEITEM item, char *title, unsigned long icon, HTREEITEM parent, void *itemdata) |
6468 { | 6647 { |
6469 TVITEM tvi; | 6648 TVITEM tvi; |
6470 TVINSERTSTRUCT tvins; | 6649 TVINSERTSTRUCT tvins; |
6471 HTREEITEM hti; | 6650 HTREEITEM hti; |
6472 void **ptrs= malloc(sizeof(void *) * 2); | 6651 void **ptrs= malloc(sizeof(void *) * 2); |
6473 | 6652 |
6474 ptrs[0] = title; | 6653 ptrs[0] = title; |
6475 ptrs[1] = itemdata; | 6654 ptrs[1] = itemdata; |
6476 | 6655 |
6477 tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; | 6656 tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; |
6478 tvi.pszText = title; | 6657 tvi.pszText = title; |
6479 tvi.lParam = (LONG)ptrs; | 6658 tvi.lParam = (LONG)ptrs; |
6480 tvi.cchTextMax = strlen(title); | 6659 tvi.cchTextMax = strlen(title); |
6481 tvi.iSelectedImage = tvi.iImage = _lookup_icon(handle, (HICON)icon, 1); | 6660 tvi.iSelectedImage = tvi.iImage = _lookup_icon(handle, (HICON)icon, 1); |
6482 | 6661 |
6483 tvins.item = tvi; | 6662 tvins.item = tvi; |
6484 tvins.hParent = parent; | 6663 tvins.hParent = parent; |
6485 tvins.hInsertAfter = item ? item : TVI_FIRST; | 6664 tvins.hInsertAfter = item ? item : TVI_FIRST; |
6486 | 6665 |
6487 hti = TreeView_InsertItem(handle, &tvins); | 6666 hti = TreeView_InsertItem(handle, &tvins); |
6488 | 6667 |
6489 return hti; | 6668 return hti; |
6490 } | 6669 } |
6491 | 6670 |
6492 /* | 6671 /* |
6493 * Inserts an item into a tree window (widget). | 6672 * Inserts an item into a tree window (widget). |
6494 * Parameters: | 6673 * Parameters: |
6498 * parent: Parent handle or 0 if root. | 6677 * parent: Parent handle or 0 if root. |
6499 * itemdata: Item specific data. | 6678 * itemdata: Item specific data. |
6500 */ | 6679 */ |
6501 HTREEITEM API dw_tree_insert(HWND handle, char *title, unsigned long icon, HTREEITEM parent, void *itemdata) | 6680 HTREEITEM API dw_tree_insert(HWND handle, char *title, unsigned long icon, HTREEITEM parent, void *itemdata) |
6502 { | 6681 { |
6503 TVITEM tvi; | 6682 TVITEM tvi; |
6504 TVINSERTSTRUCT tvins; | 6683 TVINSERTSTRUCT tvins; |
6505 HTREEITEM hti; | 6684 HTREEITEM hti; |
6506 void **ptrs= malloc(sizeof(void *) * 2); | 6685 void **ptrs= malloc(sizeof(void *) * 2); |
6507 | 6686 |
6508 ptrs[0] = title; | 6687 ptrs[0] = title; |
6509 ptrs[1] = itemdata; | 6688 ptrs[1] = itemdata; |
6510 | 6689 |
6511 tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; | 6690 tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; |
6512 tvi.pszText = title; | 6691 tvi.pszText = title; |
6513 tvi.lParam = (LONG)ptrs; | 6692 tvi.lParam = (LONG)ptrs; |
6514 tvi.cchTextMax = strlen(title); | 6693 tvi.cchTextMax = strlen(title); |
6515 tvi.iSelectedImage = tvi.iImage = _lookup_icon(handle, (HICON)icon, 1); | 6694 tvi.iSelectedImage = tvi.iImage = _lookup_icon(handle, (HICON)icon, 1); |
6516 | 6695 |
6517 tvins.item = tvi; | 6696 tvins.item = tvi; |
6518 tvins.hParent = parent; | 6697 tvins.hParent = parent; |
6519 tvins.hInsertAfter = TVI_LAST; | 6698 tvins.hInsertAfter = TVI_LAST; |
6520 | 6699 |
6521 hti = TreeView_InsertItem(handle, &tvins); | 6700 hti = TreeView_InsertItem(handle, &tvins); |
6522 | 6701 |
6523 return hti; | 6702 return hti; |
6524 } | 6703 } |
6525 | 6704 |
6526 /* | 6705 /* |
6527 * Sets the text and icon of an item in a tree window (widget). | 6706 * Sets the text and icon of an item in a tree window (widget). |
6528 * Parameters: | 6707 * Parameters: |
6531 * title: The text title of the entry. | 6710 * title: The text title of the entry. |
6532 * icon: Handle to coresponding icon. | 6711 * icon: Handle to coresponding icon. |
6533 */ | 6712 */ |
6534 void API dw_tree_item_change(HWND handle, HTREEITEM item, char *title, unsigned long icon) | 6713 void API dw_tree_item_change(HWND handle, HTREEITEM item, char *title, unsigned long icon) |
6535 { | 6714 { |
6536 TVITEM tvi; | 6715 TVITEM tvi; |
6537 void **ptrs; | 6716 void **ptrs; |
6538 | 6717 |
6539 tvi.mask = TVIF_HANDLE; | 6718 tvi.mask = TVIF_HANDLE; |
6540 tvi.hItem = item; | 6719 tvi.hItem = item; |
6541 | 6720 |
6542 if(TreeView_GetItem(handle, &tvi)) | 6721 if(TreeView_GetItem(handle, &tvi)) |
6543 { | 6722 { |
6544 | 6723 |
6545 ptrs = (void **)tvi.lParam; | 6724 ptrs = (void **)tvi.lParam; |
6546 ptrs[0] = title; | 6725 ptrs[0] = title; |
6547 | 6726 |
6548 tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; | 6727 tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; |
6549 tvi.pszText = title; | 6728 tvi.pszText = title; |
6550 tvi.cchTextMax = strlen(title); | 6729 tvi.cchTextMax = strlen(title); |
6551 tvi.iSelectedImage = tvi.iImage = _lookup_icon(handle, (HICON)icon, 1); | 6730 tvi.iSelectedImage = tvi.iImage = _lookup_icon(handle, (HICON)icon, 1); |
6552 tvi.hItem = (HTREEITEM)item; | 6731 tvi.hItem = (HTREEITEM)item; |
6553 | 6732 |
6554 TreeView_SetItem(handle, &tvi); | 6733 TreeView_SetItem(handle, &tvi); |
6555 } | 6734 } |
6556 } | 6735 } |
6557 | 6736 |
6558 /* | 6737 /* |
6559 * Sets the item data of a tree item. | 6738 * Sets the item data of a tree item. |
6560 * Parameters: | 6739 * Parameters: |
6562 * item: Handle of the item to be modified. | 6741 * item: Handle of the item to be modified. |
6563 * itemdata: User defined data to be associated with item. | 6742 * itemdata: User defined data to be associated with item. |
6564 */ | 6743 */ |
6565 void API dw_tree_item_set_data(HWND handle, HTREEITEM item, void *itemdata) | 6744 void API dw_tree_item_set_data(HWND handle, HTREEITEM item, void *itemdata) |
6566 { | 6745 { |
6567 TVITEM tvi; | 6746 TVITEM tvi; |
6568 void **ptrs; | 6747 void **ptrs; |
6569 | 6748 |
6570 tvi.mask = TVIF_HANDLE; | 6749 tvi.mask = TVIF_HANDLE; |
6571 tvi.hItem = item; | 6750 tvi.hItem = item; |
6572 | 6751 |
6573 if(TreeView_GetItem(handle, &tvi)) | 6752 if(TreeView_GetItem(handle, &tvi)) |
6574 { | 6753 { |
6575 ptrs = (void **)tvi.lParam; | 6754 ptrs = (void **)tvi.lParam; |
6576 ptrs[1] = itemdata; | 6755 ptrs[1] = itemdata; |
6577 } | 6756 } |
6578 } | 6757 } |
6579 | 6758 |
6580 /* | 6759 /* |
6581 * Gets the item data of a tree item. | 6760 * Gets the item data of a tree item. |
6582 * Parameters: | 6761 * Parameters: |
6583 * handle: Handle to the tree containing the item. | 6762 * handle: Handle to the tree containing the item. |
6584 * item: Handle of the item to be modified. | 6763 * item: Handle of the item to be modified. |
6585 */ | 6764 */ |
6586 void * API dw_tree_item_get_data(HWND handle, HTREEITEM item) | 6765 void * API dw_tree_item_get_data(HWND handle, HTREEITEM item) |
6587 { | 6766 { |
6588 TVITEM tvi; | 6767 TVITEM tvi; |
6589 void **ptrs; | 6768 void **ptrs; |
6590 | 6769 |
6591 tvi.mask = TVIF_HANDLE; | 6770 tvi.mask = TVIF_HANDLE; |
6592 tvi.hItem = item; | 6771 tvi.hItem = item; |
6593 | 6772 |
6594 if(TreeView_GetItem(handle, &tvi)) | 6773 if(TreeView_GetItem(handle, &tvi)) |
6595 { | 6774 { |
6596 ptrs = (void **)tvi.lParam; | 6775 ptrs = (void **)tvi.lParam; |
6597 return ptrs[1]; | 6776 return ptrs[1]; |
6598 } | 6777 } |
6599 return NULL; | 6778 return NULL; |
6600 } | 6779 } |
6601 | 6780 |
6602 /* | 6781 /* |
6603 * Gets the text an item in a tree window (widget). | 6782 * Gets the text an item in a tree window (widget). |
6604 * Parameters: | 6783 * Parameters: |
6605 * handle: Handle to the tree containing the item. | 6784 * handle: Handle to the tree containing the item. |
6606 * item: Handle of the item to be modified. | 6785 * item: Handle of the item to be modified. |
6607 */ | 6786 */ |
6608 char * API dw_tree_get_title(HWND handle, HTREEITEM item) | 6787 char * API dw_tree_get_title(HWND handle, HTREEITEM item) |
6609 { | 6788 { |
6610 TVITEM tvi; | 6789 TVITEM tvi; |
6611 | 6790 |
6612 tvi.mask = TVIF_HANDLE; | 6791 tvi.mask = TVIF_HANDLE; |
6613 tvi.hItem = item; | 6792 tvi.hItem = item; |
6614 | 6793 |
6615 if(TreeView_GetItem(handle, &tvi)) | 6794 if(TreeView_GetItem(handle, &tvi)) |
6616 return tvi.pszText; | 6795 return tvi.pszText; |
6617 return NULL; | 6796 return NULL; |
6618 } | 6797 } |
6619 | 6798 |
6620 /* | 6799 /* |
6621 * Gets the text an item in a tree window (widget). | 6800 * Gets the text an item in a tree window (widget). |
6623 * handle: Handle to the tree containing the item. | 6802 * handle: Handle to the tree containing the item. |
6624 * item: Handle of the item to be modified. | 6803 * item: Handle of the item to be modified. |
6625 */ | 6804 */ |
6626 HTREEITEM API dw_tree_get_parent(HWND handle, HTREEITEM item) | 6805 HTREEITEM API dw_tree_get_parent(HWND handle, HTREEITEM item) |
6627 { | 6806 { |
6628 return TreeView_GetParent(handle, item); | 6807 return TreeView_GetParent(handle, item); |
6629 } | 6808 } |
6630 | 6809 |
6631 /* | 6810 /* |
6632 * Sets this item as the active selection. | 6811 * Sets this item as the active selection. |
6633 * Parameters: | 6812 * Parameters: |
6634 * handle: Handle to the tree window (widget) to be selected. | 6813 * handle: Handle to the tree window (widget) to be selected. |
6635 * item: Handle to the item to be selected. | 6814 * item: Handle to the item to be selected. |
6636 */ | 6815 */ |
6637 void API dw_tree_item_select(HWND handle, HTREEITEM item) | 6816 void API dw_tree_item_select(HWND handle, HTREEITEM item) |
6638 { | 6817 { |
6639 dw_window_set_data(handle, "_dw_select_item", (void *)1); | 6818 dw_window_set_data(handle, "_dw_select_item", (void *)1); |
6640 TreeView_SelectItem(handle, item); | 6819 TreeView_SelectItem(handle, item); |
6641 dw_window_set_data(handle, "_dw_select_item", (void *)0); | 6820 dw_window_set_data(handle, "_dw_select_item", (void *)0); |
6642 } | 6821 } |
6643 | 6822 |
6644 /* Delete all tree subitems */ | 6823 /* Delete all tree subitems */ |
6645 void _dw_tree_item_delete_recursive(HWND handle, HTREEITEM node) | 6824 void _dw_tree_item_delete_recursive(HWND handle, HTREEITEM node) |
6646 { | 6825 { |
6647 HTREEITEM hti; | 6826 HTREEITEM hti; |
6648 | 6827 |
6649 hti = TreeView_GetChild(handle, node); | 6828 hti = TreeView_GetChild(handle, node); |
6650 | 6829 |
6651 while(hti) | 6830 while(hti) |
6652 { | 6831 { |
6653 HTREEITEM lastitem = hti; | 6832 HTREEITEM lastitem = hti; |
6654 | 6833 |
6655 hti = TreeView_GetNextSibling(handle, hti); | 6834 hti = TreeView_GetNextSibling(handle, hti); |
6656 dw_tree_item_delete(handle, lastitem); | 6835 dw_tree_item_delete(handle, lastitem); |
6657 } | 6836 } |
6658 } | 6837 } |
6659 | 6838 |
6660 /* | 6839 /* |
6661 * Removes all nodes from a tree. | 6840 * Removes all nodes from a tree. |
6662 * Parameters: | 6841 * Parameters: |
6663 * handle: Handle to the window (widget) to be cleared. | 6842 * handle: Handle to the window (widget) to be cleared. |
6664 */ | 6843 */ |
6665 void API dw_tree_clear(HWND handle) | 6844 void API dw_tree_clear(HWND handle) |
6666 { | 6845 { |
6667 HTREEITEM hti = TreeView_GetRoot(handle); | 6846 HTREEITEM hti = TreeView_GetRoot(handle); |
6668 | 6847 |
6669 dw_window_set_data(handle, "_dw_select_item", (void *)1); | 6848 dw_window_set_data(handle, "_dw_select_item", (void *)1); |
6670 while(hti) | 6849 while(hti) |
6671 { | 6850 { |
6672 HTREEITEM lastitem = hti; | 6851 HTREEITEM lastitem = hti; |
6673 | 6852 |
6674 _dw_tree_item_delete_recursive(handle, hti); | 6853 _dw_tree_item_delete_recursive(handle, hti); |
6675 hti = TreeView_GetNextSibling(handle, hti); | 6854 hti = TreeView_GetNextSibling(handle, hti); |
6676 dw_tree_item_delete(handle, lastitem); | 6855 dw_tree_item_delete(handle, lastitem); |
6677 } | 6856 } |
6678 dw_window_set_data(handle, "_dw_select_item", (void *)0); | 6857 dw_window_set_data(handle, "_dw_select_item", (void *)0); |
6679 } | 6858 } |
6680 | 6859 |
6681 /* | 6860 /* |
6682 * Expands a node on a tree. | 6861 * Expands a node on a tree. |
6683 * Parameters: | 6862 * Parameters: |
6684 * handle: Handle to the tree window (widget). | 6863 * handle: Handle to the tree window (widget). |
6685 * item: Handle to node to be expanded. | 6864 * item: Handle to node to be expanded. |
6686 */ | 6865 */ |
6687 void API dw_tree_item_expand(HWND handle, HTREEITEM item) | 6866 void API dw_tree_item_expand(HWND handle, HTREEITEM item) |
6688 { | 6867 { |
6689 TreeView_Expand(handle, item, TVE_EXPAND); | 6868 TreeView_Expand(handle, item, TVE_EXPAND); |
6690 } | 6869 } |
6691 | 6870 |
6692 /* | 6871 /* |
6693 * Collapses a node on a tree. | 6872 * Collapses a node on a tree. |
6694 * Parameters: | 6873 * Parameters: |
6695 * handle: Handle to the tree window (widget). | 6874 * handle: Handle to the tree window (widget). |
6696 * item: Handle to node to be collapsed. | 6875 * item: Handle to node to be collapsed. |
6697 */ | 6876 */ |
6698 void API dw_tree_item_collapse(HWND handle, HTREEITEM item) | 6877 void API dw_tree_item_collapse(HWND handle, HTREEITEM item) |
6699 { | 6878 { |
6700 TreeView_Expand(handle, item, TVE_COLLAPSE); | 6879 TreeView_Expand(handle, item, TVE_COLLAPSE); |
6701 } | 6880 } |
6702 | 6881 |
6703 /* | 6882 /* |
6704 * Removes a node from a tree. | 6883 * Removes a node from a tree. |
6705 * Parameters: | 6884 * Parameters: |
6706 * handle: Handle to the window (widget) to be cleared. | 6885 * handle: Handle to the window (widget) to be cleared. |
6707 * item: Handle to node to be deleted. | 6886 * item: Handle to node to be deleted. |
6708 */ | 6887 */ |
6709 void API dw_tree_item_delete(HWND handle, HTREEITEM item) | 6888 void API dw_tree_item_delete(HWND handle, HTREEITEM item) |
6710 { | 6889 { |
6711 TVITEM tvi; | 6890 TVITEM tvi; |
6712 void **ptrs=NULL; | 6891 void **ptrs=NULL; |
6713 | 6892 |
6714 if(item == TVI_ROOT || !item) | 6893 if(item == TVI_ROOT || !item) |
6715 return; | 6894 return; |
6716 | 6895 |
6717 tvi.mask = TVIF_HANDLE; | 6896 tvi.mask = TVIF_HANDLE; |
6718 tvi.hItem = item; | 6897 tvi.hItem = item; |
6719 | 6898 |
6720 if(TreeView_GetItem(handle, &tvi)) | 6899 if(TreeView_GetItem(handle, &tvi)) |
6721 ptrs = (void **)tvi.lParam; | 6900 ptrs = (void **)tvi.lParam; |
6722 | 6901 |
6723 _dw_tree_item_delete_recursive(handle, item); | 6902 _dw_tree_item_delete_recursive(handle, item); |
6724 TreeView_DeleteItem(handle, item); | 6903 TreeView_DeleteItem(handle, item); |
6725 if(ptrs) | 6904 if(ptrs) |
6726 free(ptrs); | 6905 free(ptrs); |
6727 } | 6906 } |
6728 | 6907 |
6729 /* | 6908 /* |
6730 * Sets up the container columns. | 6909 * Sets up the container columns. |
6731 * Parameters: | 6910 * Parameters: |
6736 * separator: The column number that contains the main separator. | 6915 * separator: The column number that contains the main separator. |
6737 * (only used on OS/2 but must be >= 0 on all) | 6916 * (only used on OS/2 but must be >= 0 on all) |
6738 */ | 6917 */ |
6739 int API dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator) | 6918 int API dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator) |
6740 { | 6919 { |
6741 ContainerInfo *cinfo = (ContainerInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 6920 ContainerInfo *cinfo = (ContainerInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
6742 int z, l = 0; | 6921 int z, l = 0; |
6743 unsigned long *tempflags = calloc(sizeof(unsigned long), count + 2); | 6922 unsigned long *tempflags = calloc(sizeof(unsigned long), count + 2); |
6744 LVCOLUMN lvc; | 6923 LVCOLUMN lvc; |
6745 | 6924 |
6746 if(separator == -1) | 6925 if(separator == -1) |
6747 { | 6926 { |
6748 tempflags[0] = DW_CFA_RESERVED; | 6927 tempflags[0] = DW_CFA_RESERVED; |
6749 l = 1; | 6928 l = 1; |
6750 } | 6929 } |
6751 | 6930 |
6752 memcpy(&tempflags[l], flags, sizeof(unsigned long) * count); | 6931 memcpy(&tempflags[l], flags, sizeof(unsigned long) * count); |
6753 tempflags[count + l] = 0; | 6932 tempflags[count + l] = 0; |
6754 cinfo->flags = tempflags; | 6933 cinfo->flags = tempflags; |
6755 cinfo->columns = count + l; | 6934 cinfo->columns = count + l; |
6756 | 6935 |
6757 | 6936 |
6758 for(z=0;z<count;z++) | 6937 for(z=0;z<count;z++) |
6759 { | 6938 { |
6760 if(titles[z]) | 6939 if(titles[z]) |
6761 { | 6940 { |
6762 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM | LVCF_FMT; | 6941 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM | LVCF_FMT; |
6763 lvc.pszText = titles[z]; | 6942 lvc.pszText = titles[z]; |
6764 lvc.cchTextMax = strlen(titles[z]); | 6943 lvc.cchTextMax = strlen(titles[z]); |
6765 if(flags[z] & DW_CFA_RIGHT) | 6944 if(flags[z] & DW_CFA_RIGHT) |
6766 lvc.fmt = LVCFMT_RIGHT; | 6945 lvc.fmt = LVCFMT_RIGHT; |
6767 else if(flags[z] & DW_CFA_CENTER) | 6946 else if(flags[z] & DW_CFA_CENTER) |
6768 lvc.fmt = LVCFMT_CENTER; | 6947 lvc.fmt = LVCFMT_CENTER; |
6769 else | 6948 else |
6770 lvc.fmt = LVCFMT_LEFT; | 6949 lvc.fmt = LVCFMT_LEFT; |
6771 lvc.cx = 75; | 6950 lvc.cx = 75; |
6772 lvc.iSubItem = count; | 6951 lvc.iSubItem = count; |
6773 SendMessage(handle, LVM_INSERTCOLUMN, (WPARAM)z + l, (LPARAM)&lvc); | 6952 SendMessage(handle, LVM_INSERTCOLUMN, (WPARAM)z + l, (LPARAM)&lvc); |
6774 } | 6953 } |
6775 } | 6954 } |
6776 ListView_SetExtendedListViewStyle(handle, LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES); | 6955 ListView_SetExtendedListViewStyle(handle, LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES); |
6777 return TRUE; | 6956 return TRUE; |
6778 } | 6957 } |
6779 | 6958 |
6780 /* | 6959 /* |
6781 * Sets up the filesystem columns, note: filesystem always has an icon/filename field. | 6960 * Sets up the filesystem columns, note: filesystem always has an icon/filename field. |
6782 * Parameters: | 6961 * Parameters: |
6785 * titles: An array of strings with column text titles. | 6964 * titles: An array of strings with column text titles. |
6786 * count: The number of columns (this should match the arrays). | 6965 * count: The number of columns (this should match the arrays). |
6787 */ | 6966 */ |
6788 int API dw_filesystem_setup(HWND handle, unsigned long *flags, char **titles, int count) | 6967 int API dw_filesystem_setup(HWND handle, unsigned long *flags, char **titles, int count) |
6789 { | 6968 { |
6790 LV_COLUMN lvc; | 6969 LV_COLUMN lvc; |
6791 | 6970 |
6792 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; | 6971 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; |
6793 lvc.pszText = "Filename"; | 6972 lvc.pszText = "Filename"; |
6794 lvc.cchTextMax = 8; | 6973 lvc.cchTextMax = 8; |
6795 lvc.fmt = 0; | 6974 lvc.fmt = 0; |
6796 if(!count) | 6975 if(!count) |
6797 lvc.cx = 300; | 6976 lvc.cx = 300; |
6798 else | 6977 else |
6799 lvc.cx = 150; | 6978 lvc.cx = 150; |
6800 lvc.iSubItem = count; | 6979 lvc.iSubItem = count; |
6801 SendMessage(handle, LVM_INSERTCOLUMN, (WPARAM)0, (LPARAM)&lvc); | 6980 SendMessage(handle, LVM_INSERTCOLUMN, (WPARAM)0, (LPARAM)&lvc); |
6802 dw_container_setup(handle, flags, titles, count, -1); | 6981 dw_container_setup(handle, flags, titles, count, -1); |
6803 return TRUE; | 6982 return TRUE; |
6804 } | 6983 } |
6805 | 6984 |
6806 /* | 6985 /* |
6807 * Obtains an icon from a module (or header in GTK). | 6986 * Obtains an icon from a module (or header in GTK). |
6808 * Parameters: | 6987 * Parameters: |
6811 * Windows, on GTK this is converted to a pointer | 6990 * Windows, on GTK this is converted to a pointer |
6812 * to an embedded XPM. | 6991 * to an embedded XPM. |
6813 */ | 6992 */ |
6814 unsigned long API dw_icon_load(unsigned long module, unsigned long id) | 6993 unsigned long API dw_icon_load(unsigned long module, unsigned long id) |
6815 { | 6994 { |
6816 return (unsigned long)LoadIcon(DWInstance, MAKEINTRESOURCE(id)); | 6995 return (unsigned long)LoadIcon(DWInstance, MAKEINTRESOURCE(id)); |
6817 } | 6996 } |
6818 | 6997 |
6819 /* | 6998 /* |
6820 * Obtains an icon from a file. | 6999 * Obtains an icon from a file. |
6821 * Parameters: | 7000 * Parameters: |
6823 * DW pick the appropriate file extension. | 7002 * DW pick the appropriate file extension. |
6824 * (ICO on OS/2 or Windows, XPM on Unix) | 7003 * (ICO on OS/2 or Windows, XPM on Unix) |
6825 */ | 7004 */ |
6826 unsigned long API dw_icon_load_from_file(char *filename) | 7005 unsigned long API dw_icon_load_from_file(char *filename) |
6827 { | 7006 { |
6828 char *file = malloc(strlen(filename) + 5); | 7007 char *file = malloc(strlen(filename) + 5); |
6829 HANDLE icon; | 7008 HANDLE icon; |
6830 | 7009 |
6831 if(!file) | 7010 if(!file) |
6832 return 0; | 7011 return 0; |
6833 | 7012 |
6834 strcpy(file, filename); | 7013 strcpy(file, filename); |
6835 | 7014 |
6836 /* check if we can read from this file (it exists and read permission) */ | 7015 /* check if we can read from this file (it exists and read permission) */ |
6837 if(access(file, 04) != 0) | 7016 if(access(file, 04) != 0) |
6838 { | 7017 { |
6839 /* Try with .bmp extention */ | 7018 /* Try with .bmp extention */ |
6840 strcat(file, ".ico"); | 7019 strcat(file, ".ico"); |
6841 if(access(file, 04) != 0) | 7020 if(access(file, 04) != 0) |
6842 { | 7021 { |
6843 free(file); | 7022 free(file); |
6844 return 0; | 7023 return 0; |
6845 } | 7024 } |
6846 } | 7025 } |
6847 icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE); | 7026 icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE); |
6848 free(file); | 7027 free(file); |
6849 return (unsigned long)icon; | 7028 return (unsigned long)icon; |
6850 } | 7029 } |
6851 | 7030 |
6852 /* | 7031 /* |
6853 * Obtains an icon from data | 7032 * Obtains an icon from data |
6854 * Parameters: | 7033 * Parameters: |
6889 * Parameters: | 7068 * Parameters: |
6890 * handle: Handle to icon returned by dw_icon_load(). | 7069 * handle: Handle to icon returned by dw_icon_load(). |
6891 */ | 7070 */ |
6892 void API dw_icon_free(unsigned long handle) | 7071 void API dw_icon_free(unsigned long handle) |
6893 { | 7072 { |
6894 DestroyIcon((HICON)handle); | 7073 DestroyIcon((HICON)handle); |
6895 } | 7074 } |
6896 | 7075 |
6897 /* | 7076 /* |
6898 * Allocates memory used to populate a container. | 7077 * Allocates memory used to populate a container. |
6899 * Parameters: | 7078 * Parameters: |
6900 * handle: Handle to the container window (widget). | 7079 * handle: Handle to the container window (widget). |
6901 * rowcount: The number of items to be populated. | 7080 * rowcount: The number of items to be populated. |
6902 */ | 7081 */ |
6903 void * API dw_container_alloc(HWND handle, int rowcount) | 7082 void * API dw_container_alloc(HWND handle, int rowcount) |
6904 { | 7083 { |
6905 LV_ITEM lvi; | 7084 LV_ITEM lvi; |
6906 int z, item; | 7085 int z, item; |
6907 | 7086 |
6908 lvi.mask = LVIF_DI_SETITEM | LVIF_TEXT | LVIF_IMAGE; | 7087 lvi.mask = LVIF_DI_SETITEM | LVIF_TEXT | LVIF_IMAGE; |
6909 lvi.iSubItem = 0; | 7088 lvi.iSubItem = 0; |
6910 /* Insert at the end */ | 7089 /* Insert at the end */ |
6911 lvi.iItem = 1000000; | 7090 lvi.iItem = 1000000; |
6912 lvi.pszText = ""; | 7091 lvi.pszText = ""; |
6913 lvi.cchTextMax = 1; | 7092 lvi.cchTextMax = 1; |
6914 lvi.iImage = -1; | 7093 lvi.iImage = -1; |
6915 | 7094 |
6916 ShowWindow(handle, SW_HIDE); | 7095 ShowWindow(handle, SW_HIDE); |
6917 item = ListView_InsertItem(handle, &lvi); | 7096 item = ListView_InsertItem(handle, &lvi); |
6918 for(z=1;z<rowcount;z++) | 7097 for(z=1;z<rowcount;z++) |
6919 ListView_InsertItem(handle, &lvi); | 7098 ListView_InsertItem(handle, &lvi); |
6920 dw_window_set_data(handle, "_dw_insertitem", (void *)item); | 7099 dw_window_set_data(handle, "_dw_insertitem", (void *)item); |
6921 return (void *)handle; | 7100 return (void *)handle; |
6922 } | 7101 } |
6923 | 7102 |
6924 /* Finds a icon in the table, otherwise it adds it to the table | 7103 /* Finds a icon in the table, otherwise it adds it to the table |
6925 * and returns the index in the table. | 7104 * and returns the index in the table. |
6926 */ | 7105 */ |
6927 int _lookup_icon(HWND handle, HICON hicon, int type) | 7106 int _lookup_icon(HWND handle, HICON hicon, int type) |
6928 { | 7107 { |
6929 int z; | 7108 int z; |
6930 static HWND lasthwnd = NULL; | 7109 static HWND lasthwnd = NULL; |
6931 | 7110 |
6932 if(!hSmall || !hLarge) | 7111 if(!hSmall || !hLarge) |
6933 { | 7112 { |
6934 hSmall = ImageList_Create(16, 16, ILC_COLOR16 | ILC_MASK, ICON_INDEX_LIMIT, 0); | 7113 hSmall = ImageList_Create(16, 16, ILC_COLOR16 | ILC_MASK, ICON_INDEX_LIMIT, 0); |
6935 hLarge = ImageList_Create(32, 32, ILC_COLOR16 | ILC_MASK, ICON_INDEX_LIMIT, 0); | 7114 hLarge = ImageList_Create(32, 32, ILC_COLOR16 | ILC_MASK, ICON_INDEX_LIMIT, 0); |
6936 } | 7115 } |
6937 for(z=0;z<ICON_INDEX_LIMIT;z++) | 7116 for(z=0;z<ICON_INDEX_LIMIT;z++) |
6938 { | 7117 { |
6939 if(!lookup[z]) | 7118 if(!lookup[z]) |
6940 { | 7119 { |
6941 lookup[z] = hicon; | 7120 lookup[z] = hicon; |
6942 ImageList_AddIcon(hSmall, hicon); | 7121 ImageList_AddIcon(hSmall, hicon); |
6943 ImageList_AddIcon(hLarge, hicon); | 7122 ImageList_AddIcon(hLarge, hicon); |
6944 if(type) | 7123 if(type) |
6945 { | 7124 { |
6946 TreeView_SetImageList(handle, hSmall, TVSIL_NORMAL); | 7125 TreeView_SetImageList(handle, hSmall, TVSIL_NORMAL); |
6947 } | 7126 } |
6948 else | 7127 else |
6949 { | 7128 { |
6950 ListView_SetImageList(handle, hSmall, LVSIL_SMALL); | 7129 ListView_SetImageList(handle, hSmall, LVSIL_SMALL); |
6951 ListView_SetImageList(handle, hLarge, LVSIL_NORMAL); | 7130 ListView_SetImageList(handle, hLarge, LVSIL_NORMAL); |
6952 } | 7131 } |
6953 lasthwnd = handle; | 7132 lasthwnd = handle; |
6954 return z; | 7133 return z; |
6955 } | 7134 } |
6956 | 7135 |
6957 if(hicon == lookup[z]) | 7136 if(hicon == lookup[z]) |
6958 { | 7137 { |
6959 if(lasthwnd != handle) | 7138 if(lasthwnd != handle) |
6960 { | 7139 { |
6961 if(type) | 7140 if(type) |
6962 { | 7141 { |
6963 TreeView_SetImageList(handle, hSmall, TVSIL_NORMAL); | 7142 TreeView_SetImageList(handle, hSmall, TVSIL_NORMAL); |
6964 } | 7143 } |
6965 else | 7144 else |
6966 { | 7145 { |
6967 ListView_SetImageList(handle, hSmall, LVSIL_SMALL); | 7146 ListView_SetImageList(handle, hSmall, LVSIL_SMALL); |
6968 ListView_SetImageList(handle, hLarge, LVSIL_NORMAL); | 7147 ListView_SetImageList(handle, hLarge, LVSIL_NORMAL); |
6969 } | 7148 } |
6970 lasthwnd = handle; | 7149 lasthwnd = handle; |
6971 } | 7150 } |
6972 return z; | 7151 return z; |
6973 } | 7152 } |
6974 } | 7153 } |
6975 return -1; | 7154 return -1; |
6976 } | 7155 } |
6977 | 7156 |
6978 /* | 7157 /* |
6979 * Sets an item in specified row and column to the given data. | 7158 * Sets an item in specified row and column to the given data. |
6980 * Parameters: | 7159 * Parameters: |
6984 * row: Zero based row of data being set. | 7163 * row: Zero based row of data being set. |
6985 * data: Pointer to the data to be added. | 7164 * data: Pointer to the data to be added. |
6986 */ | 7165 */ |
6987 void API dw_filesystem_set_file(HWND handle, void *pointer, int row, char *filename, unsigned long icon) | 7166 void API dw_filesystem_set_file(HWND handle, void *pointer, int row, char *filename, unsigned long icon) |
6988 { | 7167 { |
6989 LV_ITEM lvi; | 7168 LV_ITEM lvi; |
6990 | 7169 |
6991 lvi.iItem = row; | 7170 lvi.iItem = row; |
6992 lvi.iSubItem = 0; | 7171 lvi.iSubItem = 0; |
6993 lvi.mask = LVIF_DI_SETITEM | LVIF_IMAGE | LVIF_TEXT; | 7172 lvi.mask = LVIF_DI_SETITEM | LVIF_IMAGE | LVIF_TEXT; |
6994 lvi.pszText = filename; | 7173 lvi.pszText = filename; |
6995 lvi.cchTextMax = strlen(filename); | 7174 lvi.cchTextMax = strlen(filename); |
6996 lvi.iImage = _lookup_icon(handle, (HICON)icon, 0); | 7175 lvi.iImage = _lookup_icon(handle, (HICON)icon, 0); |
6997 | 7176 |
6998 ListView_SetItem(handle, &lvi); | 7177 ListView_SetItem(handle, &lvi); |
6999 } | 7178 } |
7000 | 7179 |
7001 /* | 7180 /* |
7002 * Sets an item in specified row and column to the given data. | 7181 * Sets an item in specified row and column to the given data. |
7003 * Parameters: | 7182 * Parameters: |
7007 * row: Zero based row of data being set. | 7186 * row: Zero based row of data being set. |
7008 * data: Pointer to the data to be added. | 7187 * data: Pointer to the data to be added. |
7009 */ | 7188 */ |
7010 void API dw_filesystem_set_item(HWND handle, void *pointer, int column, int row, void *data) | 7189 void API dw_filesystem_set_item(HWND handle, void *pointer, int column, int row, void *data) |
7011 { | 7190 { |
7012 dw_container_set_item(handle, pointer, column + 1, row, data); | 7191 dw_container_set_item(handle, pointer, column + 1, row, data); |
7013 } | 7192 } |
7014 | 7193 |
7015 /* | 7194 /* |
7016 * Sets an item in specified row and column to the given data. | 7195 * Sets an item in specified row and column to the given data. |
7017 * Parameters: | 7196 * Parameters: |
7021 * row: Zero based row of data being set. | 7200 * row: Zero based row of data being set. |
7022 * data: Pointer to the data to be added. | 7201 * data: Pointer to the data to be added. |
7023 */ | 7202 */ |
7024 void API dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data) | 7203 void API dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data) |
7025 { | 7204 { |
7026 ContainerInfo *cinfo = (ContainerInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 7205 ContainerInfo *cinfo = (ContainerInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
7027 ULONG *flags; | 7206 ULONG *flags; |
7028 LV_ITEM lvi; | 7207 LV_ITEM lvi; |
7029 char textbuffer[100], *destptr = textbuffer; | 7208 char textbuffer[100], *destptr = textbuffer; |
7030 int item = (int)dw_window_get_data(handle, "_dw_insertitem"); | 7209 int item = (int)dw_window_get_data(handle, "_dw_insertitem"); |
7031 | 7210 |
7032 if(!cinfo || !cinfo->flags || !data) | 7211 if(!cinfo || !cinfo->flags || !data) |
7033 return; | 7212 return; |
7034 | 7213 |
7035 flags = cinfo->flags; | 7214 flags = cinfo->flags; |
7036 | 7215 |
7037 lvi.mask = LVIF_DI_SETITEM | LVIF_TEXT; | 7216 lvi.mask = LVIF_DI_SETITEM | LVIF_TEXT; |
7038 lvi.iItem = row + item; | 7217 lvi.iItem = row + item; |
7039 lvi.iSubItem = column; | 7218 lvi.iSubItem = column; |
7040 | 7219 |
7041 if(flags[column] & DW_CFA_BITMAPORICON) | 7220 if(flags[column] & DW_CFA_BITMAPORICON) |
7042 { | 7221 { |
7043 HICON hicon = *((HICON *)data); | 7222 HICON hicon = *((HICON *)data); |
7044 | 7223 |
7045 lvi.mask = LVIF_DI_SETITEM | LVIF_IMAGE; | 7224 lvi.mask = LVIF_DI_SETITEM | LVIF_IMAGE; |
7046 lvi.pszText = NULL; | 7225 lvi.pszText = NULL; |
7047 lvi.cchTextMax = 0; | 7226 lvi.cchTextMax = 0; |
7048 | 7227 |
7049 lvi.iImage = _lookup_icon(handle, hicon, 0); | 7228 lvi.iImage = _lookup_icon(handle, hicon, 0); |
7050 } | 7229 } |
7051 else if(flags[column] & DW_CFA_STRING) | 7230 else if(flags[column] & DW_CFA_STRING) |
7052 { | 7231 { |
7053 char *tmp = *((char **)data); | 7232 char *tmp = *((char **)data); |
7054 | 7233 |
7055 if(!tmp) | 7234 if(!tmp) |
7056 tmp = ""; | 7235 tmp = ""; |
7057 | 7236 |
7058 lvi.pszText = tmp; | 7237 lvi.pszText = tmp; |
7059 lvi.cchTextMax = strlen(tmp); | 7238 lvi.cchTextMax = strlen(tmp); |
7060 destptr = tmp; | 7239 destptr = tmp; |
7061 } | 7240 } |
7062 else if(flags[column] & DW_CFA_ULONG) | 7241 else if(flags[column] & DW_CFA_ULONG) |
7063 { | 7242 { |
7064 ULONG tmp = *((ULONG *)data); | 7243 ULONG tmp = *((ULONG *)data); |
7065 | 7244 |
7066 sprintf(textbuffer, "%lu", tmp); | 7245 sprintf(textbuffer, "%lu", tmp); |
7067 | 7246 |
7068 lvi.pszText = textbuffer; | 7247 lvi.pszText = textbuffer; |
7069 lvi.cchTextMax = strlen(textbuffer); | 7248 lvi.cchTextMax = strlen(textbuffer); |
7070 } | 7249 } |
7071 else if(flags[column] & DW_CFA_DATE) | 7250 else if(flags[column] & DW_CFA_DATE) |
7072 { | 7251 { |
7073 struct tm curtm; | 7252 struct tm curtm; |
7074 CDATE cdate = *((CDATE *)data); | 7253 CDATE cdate = *((CDATE *)data); |
7075 | 7254 |
7076 curtm.tm_mday = cdate.day; | 7255 curtm.tm_mday = cdate.day; |
7077 curtm.tm_mon = cdate.month - 1; | 7256 curtm.tm_mon = cdate.month - 1; |
7078 curtm.tm_year = cdate.year - 1900; | 7257 curtm.tm_year = cdate.year - 1900; |
7079 | 7258 |
7080 strftime(textbuffer, 100, "%x", &curtm); | 7259 strftime(textbuffer, 100, "%x", &curtm); |
7081 | 7260 |
7082 lvi.pszText = textbuffer; | 7261 lvi.pszText = textbuffer; |
7083 lvi.cchTextMax = strlen(textbuffer); | 7262 lvi.cchTextMax = strlen(textbuffer); |
7084 } | 7263 } |
7085 else if(flags[column] & DW_CFA_TIME) | 7264 else if(flags[column] & DW_CFA_TIME) |
7086 { | 7265 { |
7087 struct tm curtm; | 7266 struct tm curtm; |
7088 CTIME ctime = *((CTIME *)data); | 7267 CTIME ctime = *((CTIME *)data); |
7089 | 7268 |
7090 curtm.tm_hour = ctime.hours; | 7269 curtm.tm_hour = ctime.hours; |
7091 curtm.tm_min = ctime.minutes; | 7270 curtm.tm_min = ctime.minutes; |
7092 curtm.tm_sec = ctime.seconds; | 7271 curtm.tm_sec = ctime.seconds; |
7093 | 7272 |
7094 strftime(textbuffer, 100, "%X", &curtm); | 7273 strftime(textbuffer, 100, "%X", &curtm); |
7095 | 7274 |
7096 lvi.pszText = textbuffer; | 7275 lvi.pszText = textbuffer; |
7097 lvi.cchTextMax = strlen(textbuffer); | 7276 lvi.cchTextMax = strlen(textbuffer); |
7098 } | 7277 } |
7099 | 7278 |
7100 ListView_SetItem(handle, &lvi); | 7279 ListView_SetItem(handle, &lvi); |
7101 } | 7280 } |
7102 | 7281 |
7103 /* | 7282 /* |
7104 * Changes an existing item in specified row and column to the given data. | 7283 * Changes an existing item in specified row and column to the given data. |
7105 * Parameters: | 7284 * Parameters: |
7108 * row: Zero based row of data being set. | 7287 * row: Zero based row of data being set. |
7109 * data: Pointer to the data to be added. | 7288 * data: Pointer to the data to be added. |
7110 */ | 7289 */ |
7111 void API dw_container_change_item(HWND handle, int column, int row, void *data) | 7290 void API dw_container_change_item(HWND handle, int column, int row, void *data) |
7112 { | 7291 { |
7113 dw_container_set_item(handle, NULL, column, row, data); | 7292 dw_container_set_item(handle, NULL, column, row, data); |
7114 } | 7293 } |
7115 | 7294 |
7116 /* | 7295 /* |
7117 * Changes an existing item in specified row and column to the given data. | 7296 * Changes an existing item in specified row and column to the given data. |
7118 * Parameters: | 7297 * Parameters: |
7121 * row: Zero based row of data being set. | 7300 * row: Zero based row of data being set. |
7122 * data: Pointer to the data to be added. | 7301 * data: Pointer to the data to be added. |
7123 */ | 7302 */ |
7124 void API dw_filesystem_change_item(HWND handle, int column, int row, void *data) | 7303 void API dw_filesystem_change_item(HWND handle, int column, int row, void *data) |
7125 { | 7304 { |
7126 dw_filesystem_set_item(handle, NULL, column, row, data); | 7305 dw_filesystem_set_item(handle, NULL, column, row, data); |
7127 } | 7306 } |
7128 | 7307 |
7129 /* | 7308 /* |
7130 * Changes an item in specified row and column to the given data. | 7309 * Changes an item in specified row and column to the given data. |
7131 * Parameters: | 7310 * Parameters: |
7135 * row: Zero based row of data being set. | 7314 * row: Zero based row of data being set. |
7136 * data: Pointer to the data to be added. | 7315 * data: Pointer to the data to be added. |
7137 */ | 7316 */ |
7138 void API dw_filesystem_change_file(HWND handle, int row, char *filename, unsigned long icon) | 7317 void API dw_filesystem_change_file(HWND handle, int row, char *filename, unsigned long icon) |
7139 { | 7318 { |
7140 dw_filesystem_set_file(handle, NULL, row, filename, icon); | 7319 dw_filesystem_set_file(handle, NULL, row, filename, icon); |
7141 } | 7320 } |
7142 | 7321 |
7143 /* | 7322 /* |
7144 * Gets column type for a container column | 7323 * Gets column type for a container column |
7145 * Parameters: | 7324 * Parameters: |
7146 * handle: Handle to the container window (widget). | 7325 * handle: Handle to the container window (widget). |
7147 * column: Zero based column. | 7326 * column: Zero based column. |
7148 */ | 7327 */ |
7149 int API dw_container_get_column_type(HWND handle, int column) | 7328 int API dw_container_get_column_type(HWND handle, int column) |
7150 { | 7329 { |
7151 ContainerInfo *cinfo = (ContainerInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 7330 ContainerInfo *cinfo = (ContainerInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
7152 ULONG *flags; | 7331 ULONG *flags; |
7153 int rc; | 7332 int rc; |
7154 | 7333 |
7155 if(!cinfo || !cinfo->flags) | 7334 if(!cinfo || !cinfo->flags) |
7156 return 0; | 7335 return 0; |
7157 | 7336 |
7158 flags = cinfo->flags; | 7337 flags = cinfo->flags; |
7159 | 7338 |
7160 if(flags[column] & DW_CFA_BITMAPORICON) | 7339 if(flags[column] & DW_CFA_BITMAPORICON) |
7161 rc = DW_CFA_BITMAPORICON; | 7340 rc = DW_CFA_BITMAPORICON; |
7162 else if(flags[column] & DW_CFA_STRING) | 7341 else if(flags[column] & DW_CFA_STRING) |
7163 rc = DW_CFA_STRING; | 7342 rc = DW_CFA_STRING; |
7164 else if(flags[column] & DW_CFA_ULONG) | 7343 else if(flags[column] & DW_CFA_ULONG) |
7165 rc = DW_CFA_ULONG; | 7344 rc = DW_CFA_ULONG; |
7166 else if(flags[column] & DW_CFA_DATE) | 7345 else if(flags[column] & DW_CFA_DATE) |
7167 rc = DW_CFA_DATE; | 7346 rc = DW_CFA_DATE; |
7168 else if(flags[column] & DW_CFA_TIME) | 7347 else if(flags[column] & DW_CFA_TIME) |
7169 rc = DW_CFA_TIME; | 7348 rc = DW_CFA_TIME; |
7170 else | 7349 else |
7171 rc = 0; | 7350 rc = 0; |
7172 return rc; | 7351 return rc; |
7173 } | 7352 } |
7174 | 7353 |
7175 /* | 7354 /* |
7176 * Gets column type for a filesystem container column | 7355 * Gets column type for a filesystem container column |
7177 * Parameters: | 7356 * Parameters: |
7178 * handle: Handle to the container window (widget). | 7357 * handle: Handle to the container window (widget). |
7179 * column: Zero based column. | 7358 * column: Zero based column. |
7180 */ | 7359 */ |
7181 int API dw_filesystem_get_column_type(HWND handle, int column) | 7360 int API dw_filesystem_get_column_type(HWND handle, int column) |
7182 { | 7361 { |
7183 return dw_container_get_column_type( handle, column + 1 ); | 7362 return dw_container_get_column_type( handle, column + 1 ); |
7184 } | 7363 } |
7185 | 7364 |
7186 /* | 7365 /* |
7187 * Sets the width of a column in the container. | 7366 * Sets the width of a column in the container. |
7188 * Parameters: | 7367 * Parameters: |
7190 * column: Zero based column of width being set. | 7369 * column: Zero based column of width being set. |
7191 * width: Width of column in pixels. | 7370 * width: Width of column in pixels. |
7192 */ | 7371 */ |
7193 void API dw_container_set_column_width(HWND handle, int column, int width) | 7372 void API dw_container_set_column_width(HWND handle, int column, int width) |
7194 { | 7373 { |
7195 ListView_SetColumnWidth(handle, column, width); | 7374 ListView_SetColumnWidth(handle, column, width); |
7196 } | 7375 } |
7197 | 7376 |
7198 /* | 7377 /* |
7199 * Sets the title of a row in the container. | 7378 * Sets the title of a row in the container. |
7200 * Parameters: | 7379 * Parameters: |
7202 * row: Zero based row of data being set. | 7381 * row: Zero based row of data being set. |
7203 * title: String title of the item. | 7382 * title: String title of the item. |
7204 */ | 7383 */ |
7205 void API dw_container_set_row_title(void *pointer, int row, char *title) | 7384 void API dw_container_set_row_title(void *pointer, int row, char *title) |
7206 { | 7385 { |
7207 LV_ITEM lvi; | 7386 LV_ITEM lvi; |
7208 HWND container = (HWND)pointer; | 7387 HWND container = (HWND)pointer; |
7209 int item = (int)dw_window_get_data(container, "_dw_insertitem"); | 7388 int item = (int)dw_window_get_data(container, "_dw_insertitem"); |
7210 | 7389 |
7211 lvi.iItem = row + item; | 7390 lvi.iItem = row + item; |
7212 lvi.iSubItem = 0; | 7391 lvi.iSubItem = 0; |
7213 lvi.mask = LVIF_PARAM; | 7392 lvi.mask = LVIF_PARAM; |
7214 lvi.lParam = (LPARAM)title; | 7393 lvi.lParam = (LPARAM)title; |
7215 | 7394 |
7216 if(!ListView_SetItem(container, &lvi) && lvi.lParam) | 7395 if(!ListView_SetItem(container, &lvi) && lvi.lParam) |
7217 lvi.lParam = 0; | 7396 lvi.lParam = 0; |
7218 | 7397 |
7219 } | 7398 } |
7220 | 7399 |
7221 /* | 7400 /* |
7222 * Sets the title of a row in the container. | 7401 * Sets the title of a row in the container. |
7225 * pointer: Pointer to the allocated memory in dw_container_alloc(). | 7404 * pointer: Pointer to the allocated memory in dw_container_alloc(). |
7226 * rowcount: The number of rows to be inserted. | 7405 * rowcount: The number of rows to be inserted. |
7227 */ | 7406 */ |
7228 void API dw_container_insert(HWND handle, void *pointer, int rowcount) | 7407 void API dw_container_insert(HWND handle, void *pointer, int rowcount) |
7229 { | 7408 { |
7230 ShowWindow(handle, SW_SHOW); | 7409 ShowWindow(handle, SW_SHOW); |
7231 } | 7410 } |
7232 | 7411 |
7233 /* | 7412 /* |
7234 * Removes all rows from a container. | 7413 * Removes all rows from a container. |
7235 * Parameters: | 7414 * Parameters: |
7236 * handle: Handle to the window (widget) to be cleared. | 7415 * handle: Handle to the window (widget) to be cleared. |
7237 * redraw: TRUE to cause the container to redraw immediately. | 7416 * redraw: TRUE to cause the container to redraw immediately. |
7238 */ | 7417 */ |
7239 void API dw_container_clear(HWND handle, int redraw) | 7418 void API dw_container_clear(HWND handle, int redraw) |
7240 { | 7419 { |
7241 ListView_DeleteAllItems(handle); | 7420 ListView_DeleteAllItems(handle); |
7242 } | 7421 } |
7243 | 7422 |
7244 /* | 7423 /* |
7245 * Removes the first x rows from a container. | 7424 * Removes the first x rows from a container. |
7246 * Parameters: | 7425 * Parameters: |
7247 * handle: Handle to the window (widget) to be deleted from. | 7426 * handle: Handle to the window (widget) to be deleted from. |
7248 * rowcount: The number of rows to be deleted. | 7427 * rowcount: The number of rows to be deleted. |
7249 */ | 7428 */ |
7250 void API dw_container_delete(HWND handle, int rowcount) | 7429 void API dw_container_delete(HWND handle, int rowcount) |
7251 { | 7430 { |
7252 int z, _index = (int)dw_window_get_data(handle, "_dw_index"); | 7431 int z, _index = (int)dw_window_get_data(handle, "_dw_index"); |
7253 | 7432 |
7254 for(z=0;z<rowcount;z++) | 7433 for(z=0;z<rowcount;z++) |
7255 { | 7434 { |
7256 ListView_DeleteItem(handle, 0); | 7435 ListView_DeleteItem(handle, 0); |
7257 } | 7436 } |
7258 if(rowcount > _index) | 7437 if(rowcount > _index) |
7259 dw_window_set_data(handle, "_dw_index", 0); | 7438 dw_window_set_data(handle, "_dw_index", 0); |
7260 else | 7439 else |
7261 dw_window_set_data(handle, "_dw_index", (void *)(_index - rowcount)); | 7440 dw_window_set_data(handle, "_dw_index", (void *)(_index - rowcount)); |
7262 } | 7441 } |
7263 | 7442 |
7264 /* | 7443 /* |
7265 * Scrolls container up or down. | 7444 * Scrolls container up or down. |
7266 * Parameters: | 7445 * Parameters: |
7269 * DW_SCROLL_BOTTOM. (rows is ignored for last two) | 7448 * DW_SCROLL_BOTTOM. (rows is ignored for last two) |
7270 * rows: The number of rows to be scrolled. | 7449 * rows: The number of rows to be scrolled. |
7271 */ | 7450 */ |
7272 void API dw_container_scroll(HWND handle, int direction, long rows) | 7451 void API dw_container_scroll(HWND handle, int direction, long rows) |
7273 { | 7452 { |
7274 switch(direction) | 7453 switch(direction) |
7275 { | 7454 { |
7276 case DW_SCROLL_TOP: | 7455 case DW_SCROLL_TOP: |
7277 ListView_Scroll(handle, 0, -10000000); | 7456 ListView_Scroll(handle, 0, -10000000); |
7278 break; | 7457 break; |
7279 case DW_SCROLL_BOTTOM: | 7458 case DW_SCROLL_BOTTOM: |
7280 ListView_Scroll(handle, 0, 10000000); | 7459 ListView_Scroll(handle, 0, 10000000); |
7281 break; | 7460 break; |
7282 } | 7461 } |
7283 } | 7462 } |
7284 | 7463 |
7285 /* | 7464 /* |
7286 * Starts a new query of a container. | 7465 * Starts a new query of a container. |
7287 * Parameters: | 7466 * Parameters: |
7290 * return items that are currently selected. Otherwise | 7469 * return items that are currently selected. Otherwise |
7291 * it will return all records in the container. | 7470 * it will return all records in the container. |
7292 */ | 7471 */ |
7293 char * API dw_container_query_start(HWND handle, unsigned long flags) | 7472 char * API dw_container_query_start(HWND handle, unsigned long flags) |
7294 { | 7473 { |
7295 LV_ITEM lvi; | 7474 LV_ITEM lvi; |
7296 int _index = ListView_GetNextItem(handle, -1, flags); | 7475 int _index = ListView_GetNextItem(handle, -1, flags); |
7297 | 7476 |
7298 if(_index == -1) | 7477 if(_index == -1) |
7299 return NULL; | 7478 return NULL; |
7300 | 7479 |
7301 memset(&lvi, 0, sizeof(LV_ITEM)); | 7480 memset(&lvi, 0, sizeof(LV_ITEM)); |
7302 | 7481 |
7303 lvi.iItem = _index; | 7482 lvi.iItem = _index; |
7304 lvi.mask = LVIF_PARAM; | 7483 lvi.mask = LVIF_PARAM; |
7305 | 7484 |
7306 ListView_GetItem(handle, &lvi); | 7485 ListView_GetItem(handle, &lvi); |
7307 | 7486 |
7308 dw_window_set_data(handle, "_dw_index", (void *)_index); | 7487 dw_window_set_data(handle, "_dw_index", (void *)_index); |
7309 return (char *)lvi.lParam; | 7488 return (char *)lvi.lParam; |
7310 } | 7489 } |
7311 | 7490 |
7312 /* | 7491 /* |
7313 * Continues an existing query of a container. | 7492 * Continues an existing query of a container. |
7314 * Parameters: | 7493 * Parameters: |
7317 * return items that are currently selected. Otherwise | 7496 * return items that are currently selected. Otherwise |
7318 * it will return all records in the container. | 7497 * it will return all records in the container. |
7319 */ | 7498 */ |
7320 char * API dw_container_query_next(HWND handle, unsigned long flags) | 7499 char * API dw_container_query_next(HWND handle, unsigned long flags) |
7321 { | 7500 { |
7322 LV_ITEM lvi; | 7501 LV_ITEM lvi; |
7323 int _index = (int)dw_window_get_data(handle, "_dw_index"); | 7502 int _index = (int)dw_window_get_data(handle, "_dw_index"); |
7324 | 7503 |
7325 _index = ListView_GetNextItem(handle, _index, flags); | 7504 _index = ListView_GetNextItem(handle, _index, flags); |
7326 | 7505 |
7327 if(_index == -1) | 7506 if(_index == -1) |
7328 return NULL; | 7507 return NULL; |
7329 | 7508 |
7330 memset(&lvi, 0, sizeof(LV_ITEM)); | 7509 memset(&lvi, 0, sizeof(LV_ITEM)); |
7331 | 7510 |
7332 lvi.iItem = _index; | 7511 lvi.iItem = _index; |
7333 lvi.mask = LVIF_PARAM; | 7512 lvi.mask = LVIF_PARAM; |
7334 | 7513 |
7335 ListView_GetItem(handle, &lvi); | 7514 ListView_GetItem(handle, &lvi); |
7336 | 7515 |
7337 dw_window_set_data(handle, "_dw_index", (void *)_index); | 7516 dw_window_set_data(handle, "_dw_index", (void *)_index); |
7338 return (char *)lvi.lParam; | 7517 return (char *)lvi.lParam; |
7339 } | 7518 } |
7340 | 7519 |
7341 /* | 7520 /* |
7342 * Cursors the item with the text speficied, and scrolls to that item. | 7521 * Cursors the item with the text speficied, and scrolls to that item. |
7343 * Parameters: | 7522 * Parameters: |
7344 * handle: Handle to the window (widget) to be queried. | 7523 * handle: Handle to the window (widget) to be queried. |
7345 * text: Text usually returned by dw_container_query(). | 7524 * text: Text usually returned by dw_container_query(). |
7346 */ | 7525 */ |
7347 void API dw_container_cursor(HWND handle, char *text) | 7526 void API dw_container_cursor(HWND handle, char *text) |
7348 { | 7527 { |
7349 int index = ListView_GetNextItem(handle, -1, LVNI_ALL); | 7528 int index = ListView_GetNextItem(handle, -1, LVNI_ALL); |
7350 | 7529 |
7351 while(index != -1) | 7530 while(index != -1) |
7352 { | 7531 { |
7353 LV_ITEM lvi; | 7532 LV_ITEM lvi; |
7354 | 7533 |
7355 memset(&lvi, 0, sizeof(LV_ITEM)); | 7534 memset(&lvi, 0, sizeof(LV_ITEM)); |
7356 | 7535 |
7357 lvi.iItem = index; | 7536 lvi.iItem = index; |
7358 lvi.mask = LVIF_PARAM; | 7537 lvi.mask = LVIF_PARAM; |
7359 | 7538 |
7360 ListView_GetItem(handle, &lvi); | 7539 ListView_GetItem(handle, &lvi); |
7361 | 7540 |
7362 if((char *)lvi.lParam == text) | 7541 if((char *)lvi.lParam == text) |
7363 { | 7542 { |
7364 | 7543 |
7365 ListView_SetItemState(handle, index, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); | 7544 ListView_SetItemState(handle, index, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); |
7366 ListView_EnsureVisible(handle, index, TRUE); | 7545 ListView_EnsureVisible(handle, index, TRUE); |
7367 return; | 7546 return; |
7368 } | 7547 } |
7369 | 7548 |
7370 index = ListView_GetNextItem(handle, index, LVNI_ALL); | 7549 index = ListView_GetNextItem(handle, index, LVNI_ALL); |
7371 } | 7550 } |
7372 } | 7551 } |
7373 | 7552 |
7374 /* | 7553 /* |
7375 * Deletes the item with the text speficied. | 7554 * Deletes the item with the text speficied. |
7376 * Parameters: | 7555 * Parameters: |
7377 * handle: Handle to the window (widget). | 7556 * handle: Handle to the window (widget). |
7378 * text: Text usually returned by dw_container_query(). | 7557 * text: Text usually returned by dw_container_query(). |
7379 */ | 7558 */ |
7380 void API dw_container_delete_row(HWND handle, char *text) | 7559 void API dw_container_delete_row(HWND handle, char *text) |
7381 { | 7560 { |
7382 int index = ListView_GetNextItem(handle, -1, LVNI_ALL); | 7561 int index = ListView_GetNextItem(handle, -1, LVNI_ALL); |
7383 | 7562 |
7384 while(index != -1) | 7563 while(index != -1) |
7385 { | 7564 { |
7386 LV_ITEM lvi; | 7565 LV_ITEM lvi; |
7387 | 7566 |
7388 memset(&lvi, 0, sizeof(LV_ITEM)); | 7567 memset(&lvi, 0, sizeof(LV_ITEM)); |
7389 | 7568 |
7390 lvi.iItem = index; | 7569 lvi.iItem = index; |
7391 lvi.mask = LVIF_PARAM; | 7570 lvi.mask = LVIF_PARAM; |
7392 | 7571 |
7393 ListView_GetItem(handle, &lvi); | 7572 ListView_GetItem(handle, &lvi); |
7394 | 7573 |
7395 if((char *)lvi.lParam == text) | 7574 if((char *)lvi.lParam == text) |
7396 { | 7575 { |
7397 int _index = (int)dw_window_get_data(handle, "_dw_index"); | 7576 int _index = (int)dw_window_get_data(handle, "_dw_index"); |
7398 | 7577 |
7399 if(index < _index) | 7578 if(index < _index) |
7400 dw_window_set_data(handle, "_dw_index", (void *)(_index - 1)); | 7579 dw_window_set_data(handle, "_dw_index", (void *)(_index - 1)); |
7401 | 7580 |
7402 ListView_DeleteItem(handle, index); | 7581 ListView_DeleteItem(handle, index); |
7403 return; | 7582 return; |
7404 } | 7583 } |
7405 | 7584 |
7406 index = ListView_GetNextItem(handle, index, LVNI_ALL); | 7585 index = ListView_GetNextItem(handle, index, LVNI_ALL); |
7407 } | 7586 } |
7408 } | 7587 } |
7409 | 7588 |
7410 /* | 7589 /* |
7411 * Optimizes the column widths so that all data is visible. | 7590 * Optimizes the column widths so that all data is visible. |
7412 * Parameters: | 7591 * Parameters: |
7413 * handle: Handle to the window (widget) to be optimized. | 7592 * handle: Handle to the window (widget) to be optimized. |
7414 */ | 7593 */ |
7415 void API dw_container_optimize(HWND handle) | 7594 void API dw_container_optimize(HWND handle) |
7416 { | 7595 { |
7417 ContainerInfo *cinfo = (ContainerInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 7596 ContainerInfo *cinfo = (ContainerInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
7418 if(cinfo && cinfo->columns == 1) | 7597 if(cinfo && cinfo->columns == 1) |
7419 { | 7598 { |
7420 ListView_SetColumnWidth(handle, 0, LVSCW_AUTOSIZE); | 7599 ListView_SetColumnWidth(handle, 0, LVSCW_AUTOSIZE); |
7421 } | 7600 } |
7422 else if(cinfo && cinfo->columns > 1) | 7601 else if(cinfo && cinfo->columns > 1) |
7423 { | 7602 { |
7424 int z, index; | 7603 int z, index; |
7425 ULONG *flags = cinfo->flags, *columns = calloc(sizeof(ULONG), cinfo->columns); | 7604 ULONG *flags = cinfo->flags, *columns = calloc(sizeof(ULONG), cinfo->columns); |
7426 char *text = malloc(1024); | 7605 char *text = malloc(1024); |
7427 | 7606 |
7428 /* Initialize with sizes of column labels */ | 7607 /* Initialize with sizes of column labels */ |
7429 for(z=0;z<cinfo->columns;z++) | 7608 for(z=0;z<cinfo->columns;z++) |
7430 { | 7609 { |
7431 if(flags[z] & DW_CFA_BITMAPORICON) | 7610 if(flags[z] & DW_CFA_BITMAPORICON) |
7432 columns[z] = 5; | 7611 columns[z] = 5; |
7433 else | 7612 else |
7434 { | 7613 { |
7435 LVCOLUMN lvc; | 7614 LVCOLUMN lvc; |
7436 | 7615 |
7437 lvc.mask = LVCF_TEXT; | 7616 lvc.mask = LVCF_TEXT; |
7438 lvc.cchTextMax = 1023; | 7617 lvc.cchTextMax = 1023; |
7439 lvc.pszText = text; | 7618 lvc.pszText = text; |
7440 | 7619 |
7441 if(ListView_GetColumn(handle, z, &lvc)) | 7620 if(ListView_GetColumn(handle, z, &lvc)) |
7442 columns[z] = ListView_GetStringWidth(handle, lvc.pszText); | 7621 columns[z] = ListView_GetStringWidth(handle, lvc.pszText); |
7443 | 7622 |
7444 if(flags[z] & DW_CFA_RESERVED) | 7623 if(flags[z] & DW_CFA_RESERVED) |
7445 columns[z] += 20; | 7624 columns[z] += 20; |
7446 } | 7625 } |
7447 } | 7626 } |
7448 | 7627 |
7449 index = ListView_GetNextItem(handle, -1, LVNI_ALL); | 7628 index = ListView_GetNextItem(handle, -1, LVNI_ALL); |
7450 | 7629 |
7451 /* Query all the item texts */ | 7630 /* Query all the item texts */ |
7452 while(index != -1) | 7631 while(index != -1) |
7453 { | 7632 { |
7454 for(z=0;z<cinfo->columns;z++) | 7633 for(z=0;z<cinfo->columns;z++) |
7455 { | 7634 { |
7456 LV_ITEM lvi; | 7635 LV_ITEM lvi; |
7457 | 7636 |
7458 memset(&lvi, 0, sizeof(LV_ITEM)); | 7637 memset(&lvi, 0, sizeof(LV_ITEM)); |
7459 | 7638 |
7460 lvi.iItem = index; | 7639 lvi.iItem = index; |
7461 lvi.iSubItem = z; | 7640 lvi.iSubItem = z; |
7462 lvi.mask = LVIF_TEXT; | 7641 lvi.mask = LVIF_TEXT; |
7463 lvi.cchTextMax = 1023; | 7642 lvi.cchTextMax = 1023; |
7464 lvi.pszText = text; | 7643 lvi.pszText = text; |
7465 | 7644 |
7466 if(ListView_GetItem(handle, &lvi)) | 7645 if(ListView_GetItem(handle, &lvi)) |
7467 { | 7646 { |
7468 int width = ListView_GetStringWidth(handle, lvi.pszText); | 7647 int width = ListView_GetStringWidth(handle, lvi.pszText); |
7469 if(width > columns[z]) | 7648 if(width > columns[z]) |
7470 { | 7649 { |
7471 if(z == 0) | 7650 if(z == 0) |
7472 columns[z] = width + 20; | 7651 columns[z] = width + 20; |
7473 else | 7652 else |
7474 columns[z] = width; | 7653 columns[z] = width; |
7475 } | 7654 } |
7476 } | 7655 } |
7477 } | 7656 } |
7478 | 7657 |
7479 index = ListView_GetNextItem(handle, index, LVNI_ALL); | 7658 index = ListView_GetNextItem(handle, index, LVNI_ALL); |
7480 } | 7659 } |
7481 | 7660 |
7482 /* Set the new sizes */ | 7661 /* Set the new sizes */ |
7483 for(z=0;z<cinfo->columns;z++) | 7662 for(z=0;z<cinfo->columns;z++) |
7484 ListView_SetColumnWidth(handle, z, columns[z] + 16); | 7663 ListView_SetColumnWidth(handle, z, columns[z] + 16); |
7485 | 7664 |
7486 free(columns); | 7665 free(columns); |
7487 free(text); | 7666 free(text); |
7488 } | 7667 } |
7489 } | 7668 } |
7490 | 7669 |
7491 /* | 7670 /* |
7492 * Inserts an icon into the taskbar. | 7671 * Inserts an icon into the taskbar. |
7493 * Parameters: | 7672 * Parameters: |
7495 * icon: Icon handle to display in the taskbar. | 7674 * icon: Icon handle to display in the taskbar. |
7496 * bubbletext: Text to show when the mouse is above the icon. | 7675 * bubbletext: Text to show when the mouse is above the icon. |
7497 */ | 7676 */ |
7498 void API dw_taskbar_insert(HWND handle, unsigned long icon, char *bubbletext) | 7677 void API dw_taskbar_insert(HWND handle, unsigned long icon, char *bubbletext) |
7499 { | 7678 { |
7500 NOTIFYICONDATA tnid; | 7679 NOTIFYICONDATA tnid; |
7501 | 7680 |
7502 tnid.cbSize = sizeof(NOTIFYICONDATA); | 7681 tnid.cbSize = sizeof(NOTIFYICONDATA); |
7503 tnid.hWnd = handle; | 7682 tnid.hWnd = handle; |
7504 tnid.uID = icon; | 7683 tnid.uID = icon; |
7505 tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; | 7684 tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; |
7506 tnid.uCallbackMessage = WM_USER+2; | 7685 tnid.uCallbackMessage = WM_USER+2; |
7507 tnid.hIcon = (HICON)icon; | 7686 tnid.hIcon = (HICON)icon; |
7508 if(bubbletext) | 7687 if(bubbletext) |
7509 strncpy(tnid.szTip, bubbletext, sizeof(tnid.szTip)); | 7688 strncpy(tnid.szTip, bubbletext, sizeof(tnid.szTip)); |
7510 else | 7689 else |
7511 tnid.szTip[0] = 0; | 7690 tnid.szTip[0] = 0; |
7512 | 7691 |
7513 Shell_NotifyIcon(NIM_ADD, &tnid); | 7692 Shell_NotifyIcon(NIM_ADD, &tnid); |
7514 } | 7693 } |
7515 | 7694 |
7516 /* | 7695 /* |
7517 * Deletes an icon from the taskbar. | 7696 * Deletes an icon from the taskbar. |
7518 * Parameters: | 7697 * Parameters: |
7519 * handle: Window handle that was used with dw_taskbar_insert(). | 7698 * handle: Window handle that was used with dw_taskbar_insert(). |
7520 * icon: Icon handle that was used with dw_taskbar_insert(). | 7699 * icon: Icon handle that was used with dw_taskbar_insert(). |
7521 */ | 7700 */ |
7522 void API dw_taskbar_delete(HWND handle, unsigned long icon) | 7701 void API dw_taskbar_delete(HWND handle, unsigned long icon) |
7523 { | 7702 { |
7524 NOTIFYICONDATA tnid; | 7703 NOTIFYICONDATA tnid; |
7525 | 7704 |
7526 tnid.cbSize = sizeof(NOTIFYICONDATA); | 7705 tnid.cbSize = sizeof(NOTIFYICONDATA); |
7527 tnid.hWnd = handle; | 7706 tnid.hWnd = handle; |
7528 tnid.uID = icon; | 7707 tnid.uID = icon; |
7529 | 7708 |
7530 Shell_NotifyIcon(NIM_DELETE, &tnid); | 7709 Shell_NotifyIcon(NIM_DELETE, &tnid); |
7531 } | 7710 } |
7532 | 7711 |
7533 /* | 7712 /* |
7534 * Creates a rendering context widget (window) to be packed. | 7713 * Creates a rendering context widget (window) to be packed. |
7535 * Parameters: | 7714 * Parameters: |
7537 * Returns: | 7716 * Returns: |
7538 * A handle to the widget or NULL on failure. | 7717 * A handle to the widget or NULL on failure. |
7539 */ | 7718 */ |
7540 HWND API dw_render_new(unsigned long id) | 7719 HWND API dw_render_new(unsigned long id) |
7541 { | 7720 { |
7542 Box *newbox = calloc(sizeof(Box), 1); | 7721 Box *newbox = calloc(sizeof(Box), 1); |
7543 HWND tmp = CreateWindow(ObjectClassName, | 7722 HWND tmp = CreateWindow(ObjectClassName, |
7544 "", | 7723 "", |
7545 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, | 7724 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, |
7546 0,0,2000,1000, | 7725 0,0,2000,1000, |
7547 DW_HWND_OBJECT, | 7726 DW_HWND_OBJECT, |
7548 (HMENU)id, | 7727 (HMENU)id, |
7549 DWInstance, | 7728 DWInstance, |
7550 NULL); | 7729 NULL); |
7551 newbox->pad = 0; | 7730 newbox->pad = 0; |
7552 newbox->type = 0; | 7731 newbox->type = 0; |
7553 newbox->count = 0; | 7732 newbox->count = 0; |
7554 newbox->grouphwnd = (HWND)NULL; | 7733 newbox->grouphwnd = (HWND)NULL; |
7555 newbox->cinfo.pOldProc = SubclassWindow(tmp, _rendwndproc); | 7734 newbox->cinfo.pOldProc = SubclassWindow(tmp, _rendwndproc); |
7556 newbox->cinfo.fore = newbox->cinfo.back = -1; | 7735 newbox->cinfo.fore = newbox->cinfo.back = -1; |
7557 | 7736 |
7558 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)newbox); | 7737 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)newbox); |
7559 return tmp; | 7738 return tmp; |
7560 } | 7739 } |
7561 | 7740 |
7562 /* Sets the current foreground drawing color. | 7741 /* Sets the current foreground drawing color. |
7563 * Parameters: | 7742 * Parameters: |
7564 * red: red value. | 7743 * red: red value. |
7565 * green: green value. | 7744 * green: green value. |
7566 * blue: blue value. | 7745 * blue: blue value. |
7567 */ | 7746 */ |
7568 void API dw_color_foreground_set(unsigned long value) | 7747 void API dw_color_foreground_set(unsigned long value) |
7569 { | 7748 { |
7570 int threadid = dw_thread_id(); | 7749 int threadid = dw_thread_id(); |
7571 | 7750 |
7572 if(threadid < 0 || threadid >= THREAD_LIMIT) | 7751 if(threadid < 0 || threadid >= THREAD_LIMIT) |
7573 threadid = 0; | 7752 threadid = 0; |
7574 | 7753 |
7575 value = _internal_color(value); | 7754 value = _internal_color(value); |
7576 | 7755 |
7577 DeleteObject(_hPen[threadid]); | 7756 DeleteObject(_hPen[threadid]); |
7578 DeleteObject(_hBrush[threadid]); | 7757 DeleteObject(_hBrush[threadid]); |
7579 _foreground[threadid] = RGB(DW_RED_VALUE(value), DW_GREEN_VALUE(value), DW_BLUE_VALUE(value)); | 7758 _foreground[threadid] = RGB(DW_RED_VALUE(value), DW_GREEN_VALUE(value), DW_BLUE_VALUE(value)); |
7580 _hPen[threadid] = CreatePen(PS_SOLID, 1, _foreground[threadid]); | 7759 _hPen[threadid] = CreatePen(PS_SOLID, 1, _foreground[threadid]); |
7581 _hBrush[threadid] = CreateSolidBrush(_foreground[threadid]); | 7760 _hBrush[threadid] = CreateSolidBrush(_foreground[threadid]); |
7582 } | 7761 } |
7583 | 7762 |
7584 /* Sets the current background drawing color. | 7763 /* Sets the current background drawing color. |
7585 * Parameters: | 7764 * Parameters: |
7586 * red: red value. | 7765 * red: red value. |
7587 * green: green value. | 7766 * green: green value. |
7588 * blue: blue value. | 7767 * blue: blue value. |
7589 */ | 7768 */ |
7590 void API dw_color_background_set(unsigned long value) | 7769 void API dw_color_background_set(unsigned long value) |
7591 { | 7770 { |
7592 int threadid = dw_thread_id(); | 7771 int threadid = dw_thread_id(); |
7593 | 7772 |
7594 if(threadid < 0 || threadid >= THREAD_LIMIT) | 7773 if(threadid < 0 || threadid >= THREAD_LIMIT) |
7595 threadid = 0; | 7774 threadid = 0; |
7596 | 7775 |
7597 value = _internal_color(value); | 7776 value = _internal_color(value); |
7598 | 7777 |
7599 if(value == DW_RGB_TRANSPARENT) | 7778 if(value == DW_RGB_TRANSPARENT) |
7600 _background[threadid] = DW_RGB_TRANSPARENT; | 7779 _background[threadid] = DW_RGB_TRANSPARENT; |
7601 else | 7780 else |
7602 _background[threadid] = RGB(DW_RED_VALUE(value), DW_GREEN_VALUE(value), DW_BLUE_VALUE(value)); | 7781 _background[threadid] = RGB(DW_RED_VALUE(value), DW_GREEN_VALUE(value), DW_BLUE_VALUE(value)); |
7603 } | 7782 } |
7604 | 7783 |
7605 /* Allows the user to choose a color using the system's color chooser dialog. | 7784 /* Allows the user to choose a color using the system's color chooser dialog. |
7606 * Parameters: | 7785 * Parameters: |
7607 * value: current color | 7786 * value: current color |
7608 * Returns: | 7787 * Returns: |
7609 * The selected color or the current color if cancelled. | 7788 * The selected color or the current color if cancelled. |
7610 */ | 7789 */ |
7611 unsigned long API dw_color_choose(unsigned long value) | 7790 unsigned long API dw_color_choose(unsigned long value) |
7612 { | 7791 { |
7613 CHOOSECOLOR cc; | 7792 CHOOSECOLOR cc; |
7614 unsigned long newcolor; | 7793 unsigned long newcolor; |
7615 COLORREF acrCustClr[16] = {0}; | 7794 COLORREF acrCustClr[16] = {0}; |
7616 | 7795 |
7617 value = _internal_color(value); | 7796 value = _internal_color(value); |
7618 if(value == DW_RGB_TRANSPARENT) | 7797 if(value == DW_RGB_TRANSPARENT) |
7619 newcolor = DW_RGB_TRANSPARENT; | 7798 newcolor = DW_RGB_TRANSPARENT; |
7620 else | 7799 else |
7621 newcolor = RGB(DW_RED_VALUE(value), DW_GREEN_VALUE(value), DW_BLUE_VALUE(value)); | 7800 newcolor = RGB(DW_RED_VALUE(value), DW_GREEN_VALUE(value), DW_BLUE_VALUE(value)); |
7622 ZeroMemory(&cc, sizeof(CHOOSECOLOR)); | 7801 ZeroMemory(&cc, sizeof(CHOOSECOLOR)); |
7623 cc.lStructSize = sizeof(CHOOSECOLOR); | 7802 cc.lStructSize = sizeof(CHOOSECOLOR); |
7624 cc.rgbResult = newcolor; | 7803 cc.rgbResult = newcolor; |
7625 cc.hwndOwner = HWND_DESKTOP; | 7804 cc.hwndOwner = HWND_DESKTOP; |
7626 cc.lpCustColors = (LPDWORD)acrCustClr; | 7805 cc.lpCustColors = (LPDWORD)acrCustClr; |
7627 cc.Flags = CC_FULLOPEN | CC_RGBINIT; | 7806 cc.Flags = CC_FULLOPEN | CC_RGBINIT; |
7628 if (ChooseColor(&cc) == TRUE) | 7807 if (ChooseColor(&cc) == TRUE) |
7629 newcolor = DW_RGB(DW_RED_VALUE(cc.rgbResult), DW_GREEN_VALUE(cc.rgbResult), DW_BLUE_VALUE(cc.rgbResult)); | 7808 newcolor = DW_RGB(DW_RED_VALUE(cc.rgbResult), DW_GREEN_VALUE(cc.rgbResult), DW_BLUE_VALUE(cc.rgbResult)); |
7630 return newcolor; | 7809 return newcolor; |
7631 } | 7810 } |
7632 | 7811 |
7633 /* Draw a point on a window (preferably a render window). | 7812 /* Draw a point on a window (preferably a render window). |
7634 * Parameters: | 7813 * Parameters: |
7635 * handle: Handle to the window. | 7814 * handle: Handle to the window. |
7637 * x: X coordinate. | 7816 * x: X coordinate. |
7638 * y: Y coordinate. | 7817 * y: Y coordinate. |
7639 */ | 7818 */ |
7640 void API dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y) | 7819 void API dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y) |
7641 { | 7820 { |
7642 HDC hdcPaint; | 7821 HDC hdcPaint; |
7643 int threadid = dw_thread_id(); | 7822 int threadid = dw_thread_id(); |
7644 | 7823 |
7645 if(threadid < 0 || threadid >= THREAD_LIMIT) | 7824 if(threadid < 0 || threadid >= THREAD_LIMIT) |
7646 threadid = 0; | 7825 threadid = 0; |
7647 | 7826 |
7648 if(handle) | 7827 if(handle) |
7649 hdcPaint = GetDC(handle); | 7828 hdcPaint = GetDC(handle); |
7650 else if(pixmap) | 7829 else if(pixmap) |
7651 hdcPaint = pixmap->hdc; | 7830 hdcPaint = pixmap->hdc; |
7652 else | 7831 else |
7653 return; | 7832 return; |
7654 | 7833 |
7655 SetPixel(hdcPaint, x, y, _foreground[threadid]); | 7834 SetPixel(hdcPaint, x, y, _foreground[threadid]); |
7656 if(!pixmap) | 7835 if(!pixmap) |
7657 ReleaseDC(handle, hdcPaint); | 7836 ReleaseDC(handle, hdcPaint); |
7658 } | 7837 } |
7659 | 7838 |
7660 /* Draw a line on a window (preferably a render window). | 7839 /* Draw a line on a window (preferably a render window). |
7661 * Parameters: | 7840 * Parameters: |
7662 * handle: Handle to the window. | 7841 * handle: Handle to the window. |
7666 * x2: Second X coordinate. | 7845 * x2: Second X coordinate. |
7667 * y2: Second Y coordinate. | 7846 * y2: Second Y coordinate. |
7668 */ | 7847 */ |
7669 void API dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2) | 7848 void API dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2) |
7670 { | 7849 { |
7671 HDC hdcPaint; | 7850 HDC hdcPaint; |
7672 HPEN oldPen; | 7851 HPEN oldPen; |
7673 int threadid = dw_thread_id(); | 7852 int threadid = dw_thread_id(); |
7674 | 7853 |
7675 if(threadid < 0 || threadid >= THREAD_LIMIT) | 7854 if(threadid < 0 || threadid >= THREAD_LIMIT) |
7676 threadid = 0; | 7855 threadid = 0; |
7677 | 7856 |
7678 if(handle) | 7857 if(handle) |
7679 hdcPaint = GetDC(handle); | 7858 hdcPaint = GetDC(handle); |
7680 else if(pixmap) | 7859 else if(pixmap) |
7681 hdcPaint = pixmap->hdc; | 7860 hdcPaint = pixmap->hdc; |
7682 else | 7861 else |
7683 return; | 7862 return; |
7684 | 7863 |
7685 oldPen = SelectObject(hdcPaint, _hPen[threadid]); | 7864 oldPen = SelectObject(hdcPaint, _hPen[threadid]); |
7686 MoveToEx(hdcPaint, x1, y1, NULL); | 7865 MoveToEx(hdcPaint, x1, y1, NULL); |
7687 LineTo(hdcPaint, x2, y2); | 7866 LineTo(hdcPaint, x2, y2); |
7688 SelectObject(hdcPaint, oldPen); | 7867 SelectObject(hdcPaint, oldPen); |
7689 /* For some reason Win98 (at least) fails | 7868 /* For some reason Win98 (at least) fails |
7690 * to draw the last pixel. So I do it myself. | 7869 * to draw the last pixel. So I do it myself. |
7691 */ | 7870 */ |
7692 SetPixel(hdcPaint, x2, y2, _foreground[threadid]); | 7871 SetPixel(hdcPaint, x2, y2, _foreground[threadid]); |
7693 if(!pixmap) | 7872 if(!pixmap) |
7694 ReleaseDC(handle, hdcPaint); | 7873 ReleaseDC(handle, hdcPaint); |
7695 } | 7874 } |
7696 | 7875 |
7697 /* Draw a rectangle on a window (preferably a render window). | 7876 /* Draw a rectangle on a window (preferably a render window). |
7698 * Parameters: | 7877 * Parameters: |
7699 * handle: Handle to the window. | 7878 * handle: Handle to the window. |
7703 * width: Width of rectangle. | 7882 * width: Width of rectangle. |
7704 * height: Height of rectangle. | 7883 * height: Height of rectangle. |
7705 */ | 7884 */ |
7706 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int fill, int x, int y, int width, int height) | 7885 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int fill, int x, int y, int width, int height) |
7707 { | 7886 { |
7708 HDC hdcPaint; | 7887 HDC hdcPaint; |
7709 RECT Rect; | 7888 RECT Rect; |
7710 int threadid = dw_thread_id(); | 7889 int threadid = dw_thread_id(); |
7711 | 7890 |
7712 if(threadid < 0 || threadid >= THREAD_LIMIT) | 7891 if(threadid < 0 || threadid >= THREAD_LIMIT) |
7713 threadid = 0; | 7892 threadid = 0; |
7714 | 7893 |
7715 if(handle) | 7894 if(handle) |
7716 hdcPaint = GetDC(handle); | 7895 hdcPaint = GetDC(handle); |
7717 else if(pixmap) | 7896 else if(pixmap) |
7718 hdcPaint = pixmap->hdc; | 7897 hdcPaint = pixmap->hdc; |
7719 else | 7898 else |
7720 return; | 7899 return; |
7721 | 7900 |
7722 SetRect(&Rect, x, y, x + width , y + height ); | 7901 SetRect(&Rect, x, y, x + width , y + height ); |
7723 if(fill) | 7902 if(fill) |
7724 FillRect(hdcPaint, &Rect, _hBrush[threadid]); | 7903 FillRect(hdcPaint, &Rect, _hBrush[threadid]); |
7725 else | 7904 else |
7726 FrameRect(hdcPaint, &Rect, _hBrush[threadid]); | 7905 FrameRect(hdcPaint, &Rect, _hBrush[threadid]); |
7727 if(!pixmap) | 7906 if(!pixmap) |
7728 ReleaseDC(handle, hdcPaint); | 7907 ReleaseDC(handle, hdcPaint); |
7729 } | 7908 } |
7730 | 7909 |
7731 /* Draw text on a window (preferably a render window). | 7910 /* Draw text on a window (preferably a render window). |
7732 * Parameters: | 7911 * Parameters: |
7733 * handle: Handle to the window. | 7912 * handle: Handle to the window. |
7736 * y: Y coordinate. | 7915 * y: Y coordinate. |
7737 * text: Text to be displayed. | 7916 * text: Text to be displayed. |
7738 */ | 7917 */ |
7739 void API dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text) | 7918 void API dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text) |
7740 { | 7919 { |
7741 HDC hdc; | 7920 HDC hdc; |
7742 int mustdelete = 0; | 7921 int mustdelete = 0; |
7743 HFONT hFont = 0, oldFont = 0; | 7922 HFONT hFont = 0, oldFont = 0; |
7744 int threadid = dw_thread_id(); | 7923 int threadid = dw_thread_id(); |
7745 ColorInfo *cinfo; | 7924 ColorInfo *cinfo; |
7746 | 7925 |
7747 if(threadid < 0 || threadid >= THREAD_LIMIT) | 7926 if(threadid < 0 || threadid >= THREAD_LIMIT) |
7748 threadid = 0; | 7927 threadid = 0; |
7749 | 7928 |
7750 if(handle) | 7929 if(handle) |
7751 hdc = GetDC(handle); | 7930 hdc = GetDC(handle); |
7752 else if(pixmap) | 7931 else if(pixmap) |
7753 hdc = pixmap->hdc; | 7932 hdc = pixmap->hdc; |
7754 else | 7933 else |
7755 return; | 7934 return; |
7756 | 7935 |
7757 if(handle) | 7936 if(handle) |
7758 cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 7937 cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
7759 else | 7938 else |
7760 cinfo = (ColorInfo *)GetWindowLongPtr(pixmap->handle, GWLP_USERDATA); | 7939 cinfo = (ColorInfo *)GetWindowLongPtr(pixmap->handle, GWLP_USERDATA); |
7761 | 7940 |
7762 if(cinfo) | 7941 if(cinfo) |
7763 { | 7942 { |
7764 hFont = _acquire_font(handle, cinfo->fontname); | 7943 hFont = _acquire_font(handle, cinfo->fontname); |
7765 mustdelete = 1; | 7944 mustdelete = 1; |
7766 } | 7945 } |
7767 | 7946 |
7768 if(hFont) | 7947 if(hFont) |
7769 oldFont = SelectObject(hdc, hFont); | 7948 oldFont = SelectObject(hdc, hFont); |
7770 SetTextColor(hdc, _foreground[threadid]); | 7949 SetTextColor(hdc, _foreground[threadid]); |
7771 if(_background[threadid] == DW_RGB_TRANSPARENT) | 7950 if(_background[threadid] == DW_RGB_TRANSPARENT) |
7772 SetBkMode(hdc, TRANSPARENT); | 7951 SetBkMode(hdc, TRANSPARENT); |
7773 else | 7952 else |
7774 { | 7953 { |
7775 SetBkMode(hdc, OPAQUE); | 7954 SetBkMode(hdc, OPAQUE); |
7776 SetBkColor(hdc, _background[threadid]); | 7955 SetBkColor(hdc, _background[threadid]); |
7777 } | 7956 } |
7778 TextOut(hdc, x, y, text, strlen(text)); | 7957 TextOut(hdc, x, y, text, strlen(text)); |
7779 if(oldFont) | 7958 if(oldFont) |
7780 SelectObject(hdc, oldFont); | 7959 SelectObject(hdc, oldFont); |
7781 if(mustdelete) | 7960 if(mustdelete) |
7782 DeleteObject(hFont); | 7961 DeleteObject(hFont); |
7783 if(!pixmap) | 7962 if(!pixmap) |
7784 ReleaseDC(handle, hdc); | 7963 ReleaseDC(handle, hdc); |
7785 } | 7964 } |
7786 | 7965 |
7787 /* Query the width and height of a text string. | 7966 /* Query the width and height of a text string. |
7788 * Parameters: | 7967 * Parameters: |
7789 * handle: Handle to the window. | 7968 * handle: Handle to the window. |
7792 * width: Pointer to a variable to be filled in with the width. | 7971 * width: Pointer to a variable to be filled in with the width. |
7793 * height Pointer to a variable to be filled in with the height. | 7972 * height Pointer to a variable to be filled in with the height. |
7794 */ | 7973 */ |
7795 void API dw_font_text_extents_get(HWND handle, HPIXMAP pixmap, char *text, int *width, int *height) | 7974 void API dw_font_text_extents_get(HWND handle, HPIXMAP pixmap, char *text, int *width, int *height) |
7796 { | 7975 { |
7797 HDC hdc; | 7976 HDC hdc; |
7798 int mustdelete = 0; | 7977 int mustdelete = 0; |
7799 HFONT hFont = NULL, oldFont; | 7978 HFONT hFont = NULL, oldFont; |
7800 SIZE sz; | 7979 SIZE sz; |
7801 | 7980 |
7802 if(handle) | 7981 if(handle) |
7803 hdc = GetDC(handle); | 7982 hdc = GetDC(handle); |
7804 else if(pixmap) | 7983 else if(pixmap) |
7805 hdc = pixmap->hdc; | 7984 hdc = pixmap->hdc; |
7806 else | 7985 else |
7807 return; | 7986 return; |
7808 | 7987 |
7809 { | 7988 { |
7810 ColorInfo *cinfo; | 7989 ColorInfo *cinfo; |
7811 | 7990 |
7812 if(handle) | 7991 if(handle) |
7813 cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 7992 cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
7814 else | 7993 else |
7815 cinfo = (ColorInfo *)GetWindowLongPtr(pixmap->handle, GWLP_USERDATA); | 7994 cinfo = (ColorInfo *)GetWindowLongPtr(pixmap->handle, GWLP_USERDATA); |
7816 | 7995 |
7817 if(cinfo) | 7996 if(cinfo) |
7818 { | 7997 { |
7819 hFont = _acquire_font(handle, cinfo->fontname); | 7998 hFont = _acquire_font(handle, cinfo->fontname); |
7820 mustdelete = 1; | 7999 mustdelete = 1; |
7821 } | 8000 } |
7822 } | 8001 } |
7823 oldFont = SelectObject(hdc, hFont); | 8002 oldFont = SelectObject(hdc, hFont); |
7824 | 8003 |
7825 GetTextExtentPoint32(hdc, text, strlen(text), &sz); | 8004 GetTextExtentPoint32(hdc, text, strlen(text), &sz); |
7826 | 8005 |
7827 if(width) | 8006 if(width) |
7828 *width = sz.cx; | 8007 *width = sz.cx; |
7829 | 8008 |
7830 if(height) | 8009 if(height) |
7831 *height = sz.cy; | 8010 *height = sz.cy; |
7832 | 8011 |
7833 SelectObject(hdc, oldFont); | 8012 SelectObject(hdc, oldFont); |
7834 if(mustdelete) | 8013 if(mustdelete) |
7835 DeleteObject(hFont); | 8014 DeleteObject(hFont); |
7836 if(!pixmap) | 8015 if(!pixmap) |
7837 ReleaseDC(handle, hdc); | 8016 ReleaseDC(handle, hdc); |
7838 } | 8017 } |
7839 | 8018 |
7840 /* Call this after drawing to the screen to make sure | 8019 /* Call this after drawing to the screen to make sure |
7841 * anything you have drawn is visible. | 8020 * anything you have drawn is visible. |
7842 */ | 8021 */ |
7854 * Returns: | 8033 * Returns: |
7855 * A handle to a pixmap or NULL on failure. | 8034 * A handle to a pixmap or NULL on failure. |
7856 */ | 8035 */ |
7857 HPIXMAP API dw_pixmap_new(HWND handle, unsigned long width, unsigned long height, int depth) | 8036 HPIXMAP API dw_pixmap_new(HWND handle, unsigned long width, unsigned long height, int depth) |
7858 { | 8037 { |
7859 HPIXMAP pixmap; | 8038 HPIXMAP pixmap; |
7860 HDC hdc; | 8039 HDC hdc; |
7861 | 8040 |
7862 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 8041 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
7863 return NULL; | 8042 return NULL; |
7864 | 8043 |
7865 hdc = GetDC(handle); | 8044 hdc = GetDC(handle); |
7866 | 8045 |
7867 pixmap->width = width; pixmap->height = height; | 8046 pixmap->width = width; pixmap->height = height; |
7868 | 8047 |
7869 pixmap->handle = handle; | 8048 pixmap->handle = handle; |
7870 pixmap->hbm = CreateCompatibleBitmap(hdc, width, height); | 8049 pixmap->hbm = CreateCompatibleBitmap(hdc, width, height); |
7871 pixmap->hdc = CreateCompatibleDC(hdc); | 8050 pixmap->hdc = CreateCompatibleDC(hdc); |
7872 | 8051 |
7873 SelectObject(pixmap->hdc, pixmap->hbm); | 8052 SelectObject(pixmap->hdc, pixmap->hbm); |
7874 | 8053 |
7875 ReleaseDC(handle, hdc); | 8054 ReleaseDC(handle, hdc); |
7876 | 8055 |
7877 return pixmap; | 8056 return pixmap; |
7878 } | 8057 } |
7879 | 8058 |
7880 /* | 8059 /* |
7881 * Creates a pixmap from a file. | 8060 * Creates a pixmap from a file. |
7882 * Parameters: | 8061 * Parameters: |
7887 * Returns: | 8066 * Returns: |
7888 * A handle to a pixmap or NULL on failure. | 8067 * A handle to a pixmap or NULL on failure. |
7889 */ | 8068 */ |
7890 HPIXMAP API dw_pixmap_new_from_file(HWND handle, char *filename) | 8069 HPIXMAP API dw_pixmap_new_from_file(HWND handle, char *filename) |
7891 { | 8070 { |
7892 HPIXMAP pixmap; | 8071 HPIXMAP pixmap; |
7893 BITMAP bm; | 8072 BITMAP bm; |
7894 HDC hdc; | 8073 HDC hdc; |
7895 char *file = malloc(strlen(filename) + 5); | 8074 char *file = malloc(strlen(filename) + 5); |
7896 | 8075 |
7897 if (!file || !(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 8076 if (!file || !(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
7898 { | 8077 { |
7899 if(file) | 8078 if(file) |
7900 free(file); | 8079 free(file); |
7901 return NULL; | 8080 return NULL; |
7902 } | 8081 } |
7903 | 8082 |
7904 strcpy(file, filename); | 8083 strcpy(file, filename); |
7905 | 8084 |
7906 /* check if we can read from this file (it exists and read permission) */ | 8085 /* check if we can read from this file (it exists and read permission) */ |
7907 if(access(file, 04) != 0) | 8086 if(access(file, 04) != 0) |
7908 { | 8087 { |
7909 /* Try with .bmp extention */ | 8088 /* Try with .bmp extention */ |
7910 strcat(file, ".bmp"); | 8089 strcat(file, ".bmp"); |
7911 if(access(file, 04) != 0) | 8090 if(access(file, 04) != 0) |
7912 { | 8091 { |
7913 free(pixmap); | 8092 free(pixmap); |
7914 free(file); | 8093 free(file); |
7915 return NULL; | 8094 return NULL; |
7916 } | 8095 } |
7917 } | 8096 } |
7918 | 8097 |
7919 hdc = GetDC(handle); | 8098 hdc = GetDC(handle); |
7920 | 8099 |
7921 pixmap->handle = handle; | 8100 pixmap->handle = handle; |
7922 pixmap->hbm = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); | 8101 pixmap->hbm = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); |
7923 | 8102 |
7924 if(!pixmap->hbm) | 8103 if(!pixmap->hbm) |
7925 { | 8104 { |
7926 free(file); | 8105 free(file); |
7927 free(pixmap); | 8106 free(pixmap); |
7928 ReleaseDC(handle, hdc); | 8107 ReleaseDC(handle, hdc); |
7929 return NULL; | 8108 return NULL; |
7930 } | 8109 } |
7931 | 8110 |
7932 pixmap->hdc = CreateCompatibleDC(hdc); | 8111 pixmap->hdc = CreateCompatibleDC(hdc); |
7933 | 8112 |
7934 GetObject(pixmap->hbm, sizeof(bm), &bm); | 8113 GetObject(pixmap->hbm, sizeof(bm), &bm); |
7935 | 8114 |
7936 pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight; | 8115 pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight; |
7937 | 8116 |
7938 SelectObject(pixmap->hdc, pixmap->hbm); | 8117 SelectObject(pixmap->hdc, pixmap->hbm); |
7939 | 8118 |
7940 ReleaseDC(handle, hdc); | 8119 ReleaseDC(handle, hdc); |
7941 | 8120 |
7942 free(file); | 8121 free(file); |
7943 | 8122 |
7944 return pixmap; | 8123 return pixmap; |
7945 } | 8124 } |
7946 | 8125 |
7947 /* | 8126 /* |
7948 * Creates a pixmap from memory. | 8127 * Creates a pixmap from memory. |
7949 * Parameters: | 8128 * Parameters: |
8018 * Returns: | 8197 * Returns: |
8019 * A handle to a pixmap or NULL on failure. | 8198 * A handle to a pixmap or NULL on failure. |
8020 */ | 8199 */ |
8021 HPIXMAP API dw_pixmap_grab(HWND handle, ULONG id) | 8200 HPIXMAP API dw_pixmap_grab(HWND handle, ULONG id) |
8022 { | 8201 { |
8023 HPIXMAP pixmap; | 8202 HPIXMAP pixmap; |
8024 BITMAP bm; | 8203 BITMAP bm; |
8025 HDC hdc; | 8204 HDC hdc; |
8026 | 8205 |
8027 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 8206 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
8028 return NULL; | 8207 return NULL; |
8029 | 8208 |
8030 hdc = GetDC(handle); | 8209 hdc = GetDC(handle); |
8031 | 8210 |
8032 | 8211 |
8033 pixmap->hbm = LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); | 8212 pixmap->hbm = LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); |
8034 pixmap->hdc = CreateCompatibleDC(hdc); | 8213 pixmap->hdc = CreateCompatibleDC(hdc); |
8035 | 8214 |
8036 GetObject(pixmap->hbm, sizeof(BITMAP), (void *)&bm); | 8215 GetObject(pixmap->hbm, sizeof(BITMAP), (void *)&bm); |
8037 | 8216 |
8038 pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight; | 8217 pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight; |
8039 | 8218 |
8040 SelectObject(pixmap->hdc, pixmap->hbm); | 8219 SelectObject(pixmap->hdc, pixmap->hbm); |
8041 | 8220 |
8042 ReleaseDC(handle, hdc); | 8221 ReleaseDC(handle, hdc); |
8043 | 8222 |
8044 return pixmap; | 8223 return pixmap; |
8045 } | 8224 } |
8046 | 8225 |
8047 /* | 8226 /* |
8048 * Destroys an allocated pixmap. | 8227 * Destroys an allocated pixmap. |
8049 * Parameters: | 8228 * Parameters: |
8050 * pixmap: Handle to a pixmap returned by | 8229 * pixmap: Handle to a pixmap returned by |
8051 * dw_pixmap_new.. | 8230 * dw_pixmap_new.. |
8052 */ | 8231 */ |
8053 void API dw_pixmap_destroy(HPIXMAP pixmap) | 8232 void API dw_pixmap_destroy(HPIXMAP pixmap) |
8054 { | 8233 { |
8055 if(pixmap) | 8234 if(pixmap) |
8056 { | 8235 { |
8057 DeleteDC(pixmap->hdc); | 8236 DeleteDC(pixmap->hdc); |
8058 DeleteObject(pixmap->hbm); | 8237 DeleteObject(pixmap->hbm); |
8059 free(pixmap); | 8238 free(pixmap); |
8060 } | 8239 } |
8061 } | 8240 } |
8062 | 8241 |
8063 /* | 8242 /* |
8064 * Copies from one item to another. | 8243 * Copies from one item to another. |
8065 * Parameters: | 8244 * Parameters: |
8074 * xsrc: X coordinate of source. | 8253 * xsrc: X coordinate of source. |
8075 * ysrc: Y coordinate of source. | 8254 * ysrc: Y coordinate of source. |
8076 */ | 8255 */ |
8077 void API dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc) | 8256 void API dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc) |
8078 { | 8257 { |
8079 HDC hdcdest; | 8258 HDC hdcdest; |
8080 HDC hdcsrc; | 8259 HDC hdcsrc; |
8081 | 8260 |
8082 if(dest) | 8261 if(dest) |
8083 hdcdest = GetDC(dest); | 8262 hdcdest = GetDC(dest); |
8084 else if(destp) | 8263 else if(destp) |
8085 hdcdest = destp->hdc; | 8264 hdcdest = destp->hdc; |
8086 else | 8265 else |
8087 return; | 8266 return; |
8088 | 8267 |
8089 if(src) | 8268 if(src) |
8090 hdcsrc = GetDC(src); | 8269 hdcsrc = GetDC(src); |
8091 else if(srcp) | 8270 else if(srcp) |
8092 hdcsrc = srcp->hdc; | 8271 hdcsrc = srcp->hdc; |
8093 else | 8272 else |
8094 return; | 8273 return; |
8095 | 8274 |
8096 BitBlt(hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, SRCCOPY); | 8275 BitBlt(hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, SRCCOPY); |
8097 | 8276 |
8098 if(!destp) | 8277 if(!destp) |
8099 ReleaseDC(dest, hdcdest); | 8278 ReleaseDC(dest, hdcdest); |
8100 if(!srcp) | 8279 if(!srcp) |
8101 ReleaseDC(src, hdcsrc); | 8280 ReleaseDC(src, hdcsrc); |
8102 } | 8281 } |
8103 | 8282 |
8104 /* Run Beep() in a separate thread so it doesn't block */ | 8283 /* Run Beep() in a separate thread so it doesn't block */ |
8105 void _beepthread(void *data) | 8284 void _beepthread(void *data) |
8106 { | 8285 { |
8107 int *info = (int *)data; | 8286 int *info = (int *)data; |
8108 | 8287 |
8109 if(data) | 8288 if(data) |
8110 { | 8289 { |
8111 Beep(info[0], info[1]); | 8290 Beep(info[0], info[1]); |
8112 free(data); | 8291 free(data); |
8113 } | 8292 } |
8114 } | 8293 } |
8115 | 8294 |
8116 /* | 8295 /* |
8117 * Emits a beep. | 8296 * Emits a beep. |
8118 * Parameters: | 8297 * Parameters: |
8119 * freq: Frequency. | 8298 * freq: Frequency. |
8120 * dur: Duration. | 8299 * dur: Duration. |
8121 */ | 8300 */ |
8122 void API dw_beep(int freq, int dur) | 8301 void API dw_beep(int freq, int dur) |
8123 { | 8302 { |
8124 int *info = malloc(sizeof(int) * 2); | 8303 int *info = malloc(sizeof(int) * 2); |
8125 | 8304 |
8126 if(info) | 8305 if(info) |
8127 { | 8306 { |
8128 info[0] = freq; | 8307 info[0] = freq; |
8129 info[1] = dur; | 8308 info[1] = dur; |
8130 | 8309 |
8131 _beginthread(_beepthread, 100, (void *)info); | 8310 _beginthread(_beepthread, 100, (void *)info); |
8132 } | 8311 } |
8133 } | 8312 } |
8134 | 8313 |
8135 /* Open a shared library and return a handle. | 8314 /* Open a shared library and return a handle. |
8136 * Parameters: | 8315 * Parameters: |
8137 * name: Base name of the shared library. | 8316 * name: Base name of the shared library. |
8138 * handle: Pointer to a module handle, | 8317 * handle: Pointer to a module handle, |
8139 * will be filled in with the handle. | 8318 * will be filled in with the handle. |
8140 */ | 8319 */ |
8141 int API dw_module_load(char *name, HMOD *handle) | 8320 int API dw_module_load(char *name, HMOD *handle) |
8142 { | 8321 { |
8143 if(!handle) | 8322 if(!handle) |
8144 return -1; | 8323 return -1; |
8145 | 8324 |
8146 *handle = LoadLibrary(name); | 8325 *handle = LoadLibrary(name); |
8147 return (NULL == *handle); | 8326 return (NULL == *handle); |
8148 } | 8327 } |
8149 | 8328 |
8150 /* Queries the address of a symbol within open handle. | 8329 /* Queries the address of a symbol within open handle. |
8151 * Parameters: | 8330 * Parameters: |
8152 * handle: Module handle returned by dw_module_load() | 8331 * handle: Module handle returned by dw_module_load() |
8154 * func: A pointer to a function pointer, to obtain | 8333 * func: A pointer to a function pointer, to obtain |
8155 * the address. | 8334 * the address. |
8156 */ | 8335 */ |
8157 int API dw_module_symbol(HMOD handle, char *name, void**func) | 8336 int API dw_module_symbol(HMOD handle, char *name, void**func) |
8158 { | 8337 { |
8159 if(!func || !name) | 8338 if(!func || !name) |
8160 return -1; | 8339 return -1; |
8161 | 8340 |
8162 if(0 == strlen(name)) | 8341 if(0 == strlen(name)) |
8163 return -1; | 8342 return -1; |
8164 | 8343 |
8165 *func = (void*)GetProcAddress(handle, name); | 8344 *func = (void*)GetProcAddress(handle, name); |
8166 return (NULL == *func); | 8345 return (NULL == *func); |
8167 } | 8346 } |
8168 | 8347 |
8169 /* Frees the shared library previously opened. | 8348 /* Frees the shared library previously opened. |
8170 * Parameters: | 8349 * Parameters: |
8171 * handle: Module handle returned by dw_module_load() | 8350 * handle: Module handle returned by dw_module_load() |
8172 */ | 8351 */ |
8173 int API dw_module_close(HMOD handle) | 8352 int API dw_module_close(HMOD handle) |
8174 { | 8353 { |
8175 return FreeLibrary(handle); | 8354 return FreeLibrary(handle); |
8176 } | 8355 } |
8177 | 8356 |
8178 /* | 8357 /* |
8179 * Returns the handle to an unnamed mutex semaphore. | 8358 * Returns the handle to an unnamed mutex semaphore. |
8180 */ | 8359 */ |
8181 HMTX API dw_mutex_new(void) | 8360 HMTX API dw_mutex_new(void) |
8182 { | 8361 { |
8183 return (HMTX)CreateMutex(NULL, FALSE, NULL); | 8362 return (HMTX)CreateMutex(NULL, FALSE, NULL); |
8184 } | 8363 } |
8185 | 8364 |
8186 /* | 8365 /* |
8187 * Closes a semaphore created by dw_mutex_new(). | 8366 * Closes a semaphore created by dw_mutex_new(). |
8188 * Parameters: | 8367 * Parameters: |
8189 * mutex: The handle to the mutex returned by dw_mutex_new(). | 8368 * mutex: The handle to the mutex returned by dw_mutex_new(). |
8190 */ | 8369 */ |
8191 void API dw_mutex_close(HMTX mutex) | 8370 void API dw_mutex_close(HMTX mutex) |
8192 { | 8371 { |
8193 CloseHandle((HANDLE)mutex); | 8372 CloseHandle((HANDLE)mutex); |
8194 } | 8373 } |
8195 | 8374 |
8196 /* | 8375 /* |
8197 * Tries to gain access to the semaphore, if it can't it blocks. | 8376 * Tries to gain access to the semaphore, if it can't it blocks. |
8198 * Parameters: | 8377 * Parameters: |
8199 * mutex: The handle to the mutex returned by dw_mutex_new(). | 8378 * mutex: The handle to the mutex returned by dw_mutex_new(). |
8200 */ | 8379 */ |
8201 void API dw_mutex_lock(HMTX mutex) | 8380 void API dw_mutex_lock(HMTX mutex) |
8202 { | 8381 { |
8203 if(_dwtid == dw_thread_id()) | 8382 if(_dwtid == dw_thread_id()) |
8204 { | 8383 { |
8205 int rc = WaitForSingleObject((HANDLE)mutex, 0); | 8384 int rc = WaitForSingleObject((HANDLE)mutex, 0); |
8206 | 8385 |
8207 while(rc == WAIT_TIMEOUT) | 8386 while(rc == WAIT_TIMEOUT) |
8208 { | 8387 { |
8209 dw_main_sleep(1); | 8388 dw_main_sleep(1); |
8210 rc = WaitForSingleObject((HANDLE)mutex, 0); | 8389 rc = WaitForSingleObject((HANDLE)mutex, 0); |
8211 } | 8390 } |
8212 } | 8391 } |
8213 else | 8392 else |
8214 WaitForSingleObject((HANDLE)mutex, INFINITE); | 8393 WaitForSingleObject((HANDLE)mutex, INFINITE); |
8215 } | 8394 } |
8216 | 8395 |
8217 /* | 8396 /* |
8218 * Reliquishes the access to the semaphore. | 8397 * Reliquishes the access to the semaphore. |
8219 * Parameters: | 8398 * Parameters: |
8220 * mutex: The handle to the mutex returned by dw_mutex_new(). | 8399 * mutex: The handle to the mutex returned by dw_mutex_new(). |
8221 */ | 8400 */ |
8222 void API dw_mutex_unlock(HMTX mutex) | 8401 void API dw_mutex_unlock(HMTX mutex) |
8223 { | 8402 { |
8224 ReleaseMutex((HANDLE)mutex); | 8403 ReleaseMutex((HANDLE)mutex); |
8225 } | 8404 } |
8226 | 8405 |
8227 /* | 8406 /* |
8228 * Returns the handle to an unnamed event semaphore. | 8407 * Returns the handle to an unnamed event semaphore. |
8229 */ | 8408 */ |
8237 * Parameters: | 8416 * Parameters: |
8238 * eve: The handle to the event returned by dw_event_new(). | 8417 * eve: The handle to the event returned by dw_event_new(). |
8239 */ | 8418 */ |
8240 int API dw_event_reset(HEV eve) | 8419 int API dw_event_reset(HEV eve) |
8241 { | 8420 { |
8242 return ResetEvent(eve); | 8421 return ResetEvent(eve); |
8243 } | 8422 } |
8244 | 8423 |
8245 /* | 8424 /* |
8246 * Posts a semaphore created by dw_event_new(). Causing all threads | 8425 * Posts a semaphore created by dw_event_new(). Causing all threads |
8247 * waiting on this event in dw_event_wait to continue. | 8426 * waiting on this event in dw_event_wait to continue. |
8248 * Parameters: | 8427 * Parameters: |
8249 * eve: The handle to the event returned by dw_event_new(). | 8428 * eve: The handle to the event returned by dw_event_new(). |
8250 */ | 8429 */ |
8251 int API dw_event_post(HEV eve) | 8430 int API dw_event_post(HEV eve) |
8252 { | 8431 { |
8253 return SetEvent(eve); | 8432 return SetEvent(eve); |
8254 } | 8433 } |
8255 | 8434 |
8256 /* | 8435 /* |
8257 * Waits on a semaphore created by dw_event_new(), until the | 8436 * Waits on a semaphore created by dw_event_new(), until the |
8258 * event gets posted or until the timeout expires. | 8437 * event gets posted or until the timeout expires. |
8259 * Parameters: | 8438 * Parameters: |
8260 * eve: The handle to the event returned by dw_event_new(). | 8439 * eve: The handle to the event returned by dw_event_new(). |
8261 */ | 8440 */ |
8262 int API dw_event_wait(HEV eve, unsigned long timeout) | 8441 int API dw_event_wait(HEV eve, unsigned long timeout) |
8263 { | 8442 { |
8264 int rc; | 8443 int rc; |
8265 | 8444 |
8266 rc = WaitForSingleObject(eve, timeout); | 8445 rc = WaitForSingleObject(eve, timeout); |
8267 if(rc == WAIT_OBJECT_0) | 8446 if(rc == WAIT_OBJECT_0) |
8268 return 1; | 8447 return 1; |
8269 if(rc == WAIT_ABANDONED) | 8448 if(rc == WAIT_ABANDONED) |
8270 return -1; | 8449 return -1; |
8271 return 0; | 8450 return 0; |
8272 } | 8451 } |
8273 | 8452 |
8274 /* | 8453 /* |
8275 * Closes a semaphore created by dw_event_new(). | 8454 * Closes a semaphore created by dw_event_new(). |
8276 * Parameters: | 8455 * Parameters: |
8277 * eve: The handle to the event returned by dw_event_new(). | 8456 * eve: The handle to the event returned by dw_event_new(). |
8278 */ | 8457 */ |
8279 int API dw_event_close(HEV *eve) | 8458 int API dw_event_close(HEV *eve) |
8280 { | 8459 { |
8281 if(eve) | 8460 if(eve) |
8282 return CloseHandle(*eve); | 8461 return CloseHandle(*eve); |
8283 return 0; | 8462 return 0; |
8284 } | 8463 } |
8285 | 8464 |
8286 /* Create a named event semaphore which can be | 8465 /* Create a named event semaphore which can be |
8287 * opened from other processes. | 8466 * opened from other processes. |
8288 * Parameters: | 8467 * Parameters: |
8290 * name: Name given to semaphore which can be opened | 8469 * name: Name given to semaphore which can be opened |
8291 * by other processes. | 8470 * by other processes. |
8292 */ | 8471 */ |
8293 HEV API dw_named_event_new(char *name) | 8472 HEV API dw_named_event_new(char *name) |
8294 { | 8473 { |
8295 SECURITY_ATTRIBUTES sa; | 8474 SECURITY_ATTRIBUTES sa; |
8296 | 8475 |
8297 sa.nLength = sizeof( SECURITY_ATTRIBUTES); | 8476 sa.nLength = sizeof( SECURITY_ATTRIBUTES); |
8298 sa.lpSecurityDescriptor = &_dwsd; | 8477 sa.lpSecurityDescriptor = &_dwsd; |
8299 sa.bInheritHandle = FALSE; | 8478 sa.bInheritHandle = FALSE; |
8300 | 8479 |
8301 return CreateEvent(&sa, TRUE, FALSE, name); | 8480 return CreateEvent(&sa, TRUE, FALSE, name); |
8302 } | 8481 } |
8303 | 8482 |
8304 /* Destroy this semaphore. | 8483 /* Destroy this semaphore. |
8305 * Parameters: | 8484 * Parameters: |
8306 * eve: Handle to the semaphore obtained by | 8485 * eve: Handle to the semaphore obtained by |
8307 * a create call. | 8486 * a create call. |
8308 */ | 8487 */ |
8309 HEV API dw_named_event_get(char *name) | 8488 HEV API dw_named_event_get(char *name) |
8310 { | 8489 { |
8311 return OpenEvent(EVENT_ALL_ACCESS, FALSE, name); | 8490 return OpenEvent(EVENT_ALL_ACCESS, FALSE, name); |
8312 } | 8491 } |
8313 | 8492 |
8314 /* Resets the event semaphore so threads who call wait | 8493 /* Resets the event semaphore so threads who call wait |
8315 * on this semaphore will block. | 8494 * on this semaphore will block. |
8316 * Parameters: | 8495 * Parameters: |
8317 * eve: Handle to the semaphore obtained by | 8496 * eve: Handle to the semaphore obtained by |
8318 * an open or create call. | 8497 * an open or create call. |
8319 */ | 8498 */ |
8320 int API dw_named_event_reset(HEV eve) | 8499 int API dw_named_event_reset(HEV eve) |
8321 { | 8500 { |
8322 int rc; | 8501 int rc; |
8323 | 8502 |
8324 rc = ResetEvent(eve); | 8503 rc = ResetEvent(eve); |
8325 if(!rc) | 8504 if(!rc) |
8326 return 1; | 8505 return 1; |
8327 | 8506 |
8328 return 0; | 8507 return 0; |
8329 } | 8508 } |
8330 | 8509 |
8331 /* Sets the posted state of an event semaphore, any threads | 8510 /* Sets the posted state of an event semaphore, any threads |
8332 * waiting on the semaphore will no longer block. | 8511 * waiting on the semaphore will no longer block. |
8333 * Parameters: | 8512 * Parameters: |
8334 * eve: Handle to the semaphore obtained by | 8513 * eve: Handle to the semaphore obtained by |
8335 * an open or create call. | 8514 * an open or create call. |
8336 */ | 8515 */ |
8337 int API dw_named_event_post(HEV eve) | 8516 int API dw_named_event_post(HEV eve) |
8338 { | 8517 { |
8339 int rc; | 8518 int rc; |
8340 | 8519 |
8341 rc = SetEvent(eve); | 8520 rc = SetEvent(eve); |
8342 if(!rc) | 8521 if(!rc) |
8343 return 1; | 8522 return 1; |
8344 | 8523 |
8345 return 0; | 8524 return 0; |
8346 } | 8525 } |
8347 | 8526 |
8348 /* Waits on the specified semaphore until it becomes | 8527 /* Waits on the specified semaphore until it becomes |
8349 * posted, or returns immediately if it already is posted. | 8528 * posted, or returns immediately if it already is posted. |
8350 * Parameters: | 8529 * Parameters: |
8353 * timeout: Number of milliseconds before timing out | 8532 * timeout: Number of milliseconds before timing out |
8354 * or -1 if indefinite. | 8533 * or -1 if indefinite. |
8355 */ | 8534 */ |
8356 int API dw_named_event_wait(HEV eve, unsigned long timeout) | 8535 int API dw_named_event_wait(HEV eve, unsigned long timeout) |
8357 { | 8536 { |
8358 int rc; | 8537 int rc; |
8359 | 8538 |
8360 rc = WaitForSingleObject(eve, timeout); | 8539 rc = WaitForSingleObject(eve, timeout); |
8361 switch (rc) | 8540 switch (rc) |
8362 { | 8541 { |
8363 case WAIT_FAILED: | 8542 case WAIT_FAILED: |
8364 rc = DW_ERROR_TIMEOUT; | 8543 rc = DW_ERROR_TIMEOUT; |
8365 break; | 8544 break; |
8366 | 8545 |
8367 case WAIT_ABANDONED: | 8546 case WAIT_ABANDONED: |
8368 rc = DW_ERROR_INTERRUPT; | 8547 rc = DW_ERROR_INTERRUPT; |
8369 break; | 8548 break; |
8370 | 8549 |
8371 case WAIT_OBJECT_0: | 8550 case WAIT_OBJECT_0: |
8372 rc = 0; | 8551 rc = 0; |
8373 break; | 8552 break; |
8374 } | 8553 } |
8375 | 8554 |
8376 return rc; | 8555 return rc; |
8377 } | 8556 } |
8378 | 8557 |
8379 /* Release this semaphore, if there are no more open | 8558 /* Release this semaphore, if there are no more open |
8380 * handles on this semaphore the semaphore will be destroyed. | 8559 * handles on this semaphore the semaphore will be destroyed. |
8381 * Parameters: | 8560 * Parameters: |
8382 * eve: Handle to the semaphore obtained by | 8561 * eve: Handle to the semaphore obtained by |
8383 * an open or create call. | 8562 * an open or create call. |
8384 */ | 8563 */ |
8385 int API dw_named_event_close(HEV eve) | 8564 int API dw_named_event_close(HEV eve) |
8386 { | 8565 { |
8387 int rc; | 8566 int rc; |
8388 | 8567 |
8389 rc = CloseHandle(eve); | 8568 rc = CloseHandle(eve); |
8390 if(!rc) | 8569 if(!rc) |
8391 return 1; | 8570 return 1; |
8392 | 8571 |
8393 return 0; | 8572 return 0; |
8394 } | 8573 } |
8395 | 8574 |
8396 /* | 8575 /* |
8397 * Allocates a shared memory region with a name. | 8576 * Allocates a shared memory region with a name. |
8398 * Parameters: | 8577 * Parameters: |
8401 * size: Size in bytes of the shared memory region to allocate. | 8580 * size: Size in bytes of the shared memory region to allocate. |
8402 * name: A string pointer to a unique memory name. | 8581 * name: A string pointer to a unique memory name. |
8403 */ | 8582 */ |
8404 HSHM API dw_named_memory_new(void **dest, int size, char *name) | 8583 HSHM API dw_named_memory_new(void **dest, int size, char *name) |
8405 { | 8584 { |
8406 SECURITY_ATTRIBUTES sa; | 8585 SECURITY_ATTRIBUTES sa; |
8407 HSHM handle; | 8586 HSHM handle; |
8408 | 8587 |
8409 sa.nLength = sizeof(SECURITY_ATTRIBUTES); | 8588 sa.nLength = sizeof(SECURITY_ATTRIBUTES); |
8410 sa.lpSecurityDescriptor = &_dwsd; | 8589 sa.lpSecurityDescriptor = &_dwsd; |
8411 sa.bInheritHandle = FALSE; | 8590 sa.bInheritHandle = FALSE; |
8412 | 8591 |
8413 handle = CreateFileMapping((HANDLE)0xFFFFFFFF, &sa, PAGE_READWRITE, 0, size, name); | 8592 handle = CreateFileMapping((HANDLE)0xFFFFFFFF, &sa, PAGE_READWRITE, 0, size, name); |
8414 | 8593 |
8415 if(!handle) | 8594 if(!handle) |
8416 return 0; | 8595 return 0; |
8417 | 8596 |
8418 *dest = MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, 0); | 8597 *dest = MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, 0); |
8419 | 8598 |
8420 if(!*dest) | 8599 if(!*dest) |
8421 { | 8600 { |
8422 CloseHandle(handle); | 8601 CloseHandle(handle); |
8423 return 0; | 8602 return 0; |
8424 } | 8603 } |
8425 | 8604 |
8426 return handle; | 8605 return handle; |
8427 } | 8606 } |
8428 | 8607 |
8429 /* | 8608 /* |
8430 * Aquires shared memory region with a name. | 8609 * Aquires shared memory region with a name. |
8431 * Parameters: | 8610 * Parameters: |
8433 * size: Size in bytes of the shared memory region to requested. | 8612 * size: Size in bytes of the shared memory region to requested. |
8434 * name: A string pointer to a unique memory name. | 8613 * name: A string pointer to a unique memory name. |
8435 */ | 8614 */ |
8436 HSHM API dw_named_memory_get(void **dest, int size, char *name) | 8615 HSHM API dw_named_memory_get(void **dest, int size, char *name) |
8437 { | 8616 { |
8438 HSHM handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, name); | 8617 HSHM handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, name); |
8439 | 8618 |
8440 if(!handle) | 8619 if(!handle) |
8441 return 0; | 8620 return 0; |
8442 | 8621 |
8443 *dest = MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, 0); | 8622 *dest = MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, 0); |
8444 | 8623 |
8445 if(!*dest) | 8624 if(!*dest) |
8446 { | 8625 { |
8447 CloseHandle(handle); | 8626 CloseHandle(handle); |
8448 return 0; | 8627 return 0; |
8449 } | 8628 } |
8450 | 8629 |
8451 return handle; | 8630 return handle; |
8452 } | 8631 } |
8453 | 8632 |
8454 /* | 8633 /* |
8455 * Frees a shared memory region previously allocated. | 8634 * Frees a shared memory region previously allocated. |
8456 * Parameters: | 8635 * Parameters: |
8457 * handle: Handle obtained from DB_named_memory_allocate. | 8636 * handle: Handle obtained from DB_named_memory_allocate. |
8458 * ptr: The memory address aquired with DB_named_memory_allocate. | 8637 * ptr: The memory address aquired with DB_named_memory_allocate. |
8459 */ | 8638 */ |
8460 int API dw_named_memory_free(HSHM handle, void *ptr) | 8639 int API dw_named_memory_free(HSHM handle, void *ptr) |
8461 { | 8640 { |
8462 UnmapViewOfFile(ptr); | 8641 UnmapViewOfFile(ptr); |
8463 CloseHandle(handle); | 8642 CloseHandle(handle); |
8464 return 0; | 8643 return 0; |
8465 } | 8644 } |
8466 | 8645 |
8467 /* | 8646 /* |
8468 * Creates a new thread with a starting point of func. | 8647 * Creates a new thread with a starting point of func. |
8469 * Parameters: | 8648 * Parameters: |
8472 * stack: Stack size of new thread (OS/2 and Windows only). | 8651 * stack: Stack size of new thread (OS/2 and Windows only). |
8473 */ | 8652 */ |
8474 DWTID API dw_thread_new(void *func, void *data, int stack) | 8653 DWTID API dw_thread_new(void *func, void *data, int stack) |
8475 { | 8654 { |
8476 #if defined(__CYGWIN__) | 8655 #if defined(__CYGWIN__) |
8477 return 0; | 8656 return 0; |
8478 #else | 8657 #else |
8479 return (DWTID)_beginthread((void(*)(void *))func, stack, data); | 8658 return (DWTID)_beginthread((void(*)(void *))func, stack, data); |
8480 #endif | 8659 #endif |
8481 } | 8660 } |
8482 | 8661 |
8483 /* | 8662 /* |
8484 * Ends execution of current thread immediately. | 8663 * Ends execution of current thread immediately. |
8485 */ | 8664 */ |
8486 void API dw_thread_end(void) | 8665 void API dw_thread_end(void) |
8487 { | 8666 { |
8488 #if !defined(__CYGWIN__) | 8667 #if !defined(__CYGWIN__) |
8489 _endthread(); | 8668 _endthread(); |
8490 #endif | 8669 #endif |
8491 } | 8670 } |
8492 | 8671 |
8493 /* | 8672 /* |
8494 * Returns the current thread's ID. | 8673 * Returns the current thread's ID. |
8495 */ | 8674 */ |
8496 DWTID API dw_thread_id(void) | 8675 DWTID API dw_thread_id(void) |
8497 { | 8676 { |
8498 #if defined(__CYGWIN__) | 8677 #if defined(__CYGWIN__) |
8499 return 0; | 8678 return 0; |
8500 #else | 8679 #else |
8501 return (DWTID)GetCurrentThreadId(); | 8680 return (DWTID)GetCurrentThreadId(); |
8502 #endif | 8681 #endif |
8503 } | 8682 } |
8504 | 8683 |
8505 /* | 8684 /* |
8506 * Cleanly terminates a DW session, should be signal handler safe. | 8685 * Cleanly terminates a DW session, should be signal handler safe. |
8507 * Parameters: | 8686 * Parameters: |
8508 * exitcode: Exit code reported to the operating system. | 8687 * exitcode: Exit code reported to the operating system. |
8509 */ | 8688 */ |
8510 void API dw_exit(int exitcode) | 8689 void API dw_exit(int exitcode) |
8511 { | 8690 { |
8512 OleUninitialize(); | 8691 OleUninitialize(); |
8513 exit(exitcode); | 8692 exit(exitcode); |
8514 } | 8693 } |
8515 | 8694 |
8516 /* | 8695 /* |
8517 * Creates a splitbar window (widget) with given parameters. | 8696 * Creates a splitbar window (widget) with given parameters. |
8518 * Parameters: | 8697 * Parameters: |
8522 * Returns: | 8701 * Returns: |
8523 * A handle to a splitbar window or NULL on failure. | 8702 * A handle to a splitbar window or NULL on failure. |
8524 */ | 8703 */ |
8525 HWND API dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long id) | 8704 HWND API dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long id) |
8526 { | 8705 { |
8527 HWND tmp = CreateWindow(SplitbarClassName, | 8706 HWND tmp = CreateWindow(SplitbarClassName, |
8528 "", | 8707 "", |
8529 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, | 8708 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, |
8530 0,0,2000,1000, | 8709 0,0,2000,1000, |
8531 DW_HWND_OBJECT, | 8710 DW_HWND_OBJECT, |
8532 (HMENU)id, | 8711 (HMENU)id, |
8533 DWInstance, | 8712 DWInstance, |
8534 NULL); | 8713 NULL); |
8535 | 8714 |
8536 if(tmp) | 8715 if(tmp) |
8537 { | 8716 { |
8538 HWND tmpbox = dw_box_new(DW_VERT, 0); | 8717 HWND tmpbox = dw_box_new(DW_VERT, 0); |
8539 float *percent = (float *)malloc(sizeof(float)); | 8718 float *percent = (float *)malloc(sizeof(float)); |
8540 | 8719 |
8541 dw_box_pack_start(tmpbox, topleft, 1, 1, TRUE, TRUE, 0); | 8720 dw_box_pack_start(tmpbox, topleft, 1, 1, TRUE, TRUE, 0); |
8542 SetParent(tmpbox, tmp); | 8721 SetParent(tmpbox, tmp); |
8543 dw_window_set_data(tmp, "_dw_topleft", (void *)tmpbox); | 8722 dw_window_set_data(tmp, "_dw_topleft", (void *)tmpbox); |
8544 | 8723 |
8545 tmpbox = dw_box_new(DW_VERT, 0); | 8724 tmpbox = dw_box_new(DW_VERT, 0); |
8546 dw_box_pack_start(tmpbox, bottomright, 1, 1, TRUE, TRUE, 0); | 8725 dw_box_pack_start(tmpbox, bottomright, 1, 1, TRUE, TRUE, 0); |
8547 SetParent(tmpbox, tmp); | 8726 SetParent(tmpbox, tmp); |
8548 dw_window_set_data(tmp, "_dw_bottomright", (void *)tmpbox); | 8727 dw_window_set_data(tmp, "_dw_bottomright", (void *)tmpbox); |
8549 *percent = 50.0; | 8728 *percent = 50.0; |
8550 dw_window_set_data(tmp, "_dw_percent", (void *)percent); | 8729 dw_window_set_data(tmp, "_dw_percent", (void *)percent); |
8551 dw_window_set_data(tmp, "_dw_type", (void *)type); | 8730 dw_window_set_data(tmp, "_dw_type", (void *)type); |
8552 } | 8731 } |
8553 return tmp; | 8732 return tmp; |
8554 } | 8733 } |
8555 | 8734 |
8556 /* | 8735 /* |
8557 * Sets the position of a splitbar (pecentage). | 8736 * Sets the position of a splitbar (pecentage). |
8558 * Parameters: | 8737 * Parameters: |
8559 * handle: The handle to the splitbar returned by dw_splitbar_new(). | 8738 * handle: The handle to the splitbar returned by dw_splitbar_new(). |
8560 */ | 8739 */ |
8561 void API dw_splitbar_set(HWND handle, float percent) | 8740 void API dw_splitbar_set(HWND handle, float percent) |
8562 { | 8741 { |
8563 float *mypercent = (float *)dw_window_get_data(handle, "_dw_percent"); | 8742 float *mypercent = (float *)dw_window_get_data(handle, "_dw_percent"); |
8564 int type = (int)dw_window_get_data(handle, "_dw_type"); | 8743 int type = (int)dw_window_get_data(handle, "_dw_type"); |
8565 unsigned long width, height; | 8744 unsigned long width, height; |
8566 | 8745 |
8567 if(mypercent) | 8746 if(mypercent) |
8568 *mypercent = percent; | 8747 *mypercent = percent; |
8569 | 8748 |
8570 dw_window_get_pos_size(handle, NULL, NULL, &width, &height); | 8749 dw_window_get_pos_size(handle, NULL, NULL, &width, &height); |
8571 | 8750 |
8572 _handle_splitbar_resize(handle, percent, type, width, height); | 8751 _handle_splitbar_resize(handle, percent, type, width, height); |
8573 } | 8752 } |
8574 | 8753 |
8575 /* | 8754 /* |
8576 * Gets the position of a splitbar (pecentage). | 8755 * Gets the position of a splitbar (pecentage). |
8577 * Parameters: | 8756 * Parameters: |
8578 * handle: The handle to the splitbar returned by dw_splitbar_new(). | 8757 * handle: The handle to the splitbar returned by dw_splitbar_new(). |
8579 */ | 8758 */ |
8580 float API dw_splitbar_get(HWND handle) | 8759 float API dw_splitbar_get(HWND handle) |
8581 { | 8760 { |
8582 float *percent = (float *)dw_window_get_data(handle, "_dw_percent"); | 8761 float *percent = (float *)dw_window_get_data(handle, "_dw_percent"); |
8583 | 8762 |
8584 if(percent) | 8763 if(percent) |
8585 return *percent; | 8764 return *percent; |
8586 return 0.0; | 8765 return 0.0; |
8587 } | 8766 } |
8588 | 8767 |
8589 /* | 8768 /* |
8590 * Creates a calendar window (widget) with given parameters. | 8769 * Creates a calendar window (widget) with given parameters. |
8591 * Parameters: | 8770 * Parameters: |
8596 * Returns: | 8775 * Returns: |
8597 * A handle to a calendar window or NULL on failure. | 8776 * A handle to a calendar window or NULL on failure. |
8598 */ | 8777 */ |
8599 HWND API dw_calendar_new(unsigned long id) | 8778 HWND API dw_calendar_new(unsigned long id) |
8600 { | 8779 { |
8601 RECT rc; | 8780 RECT rc; |
8602 MONTHDAYSTATE mds[3]; | 8781 MONTHDAYSTATE mds[3]; |
8603 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, | 8782 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, |
8604 MONTHCAL_CLASS, | 8783 MONTHCAL_CLASS, |
8605 "", | 8784 "", |
8606 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | MCS_DAYSTATE, | 8785 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | MCS_DAYSTATE, |
8607 0,0,2000,1000, // resize it later | 8786 0,0,2000,1000, // resize it later |
8608 DW_HWND_OBJECT, | 8787 DW_HWND_OBJECT, |
8609 (HMENU)id, | 8788 (HMENU)id, |
8610 DWInstance, | 8789 DWInstance, |
8611 NULL); | 8790 NULL); |
8612 if ( tmp ) | 8791 if ( tmp ) |
8613 { | 8792 { |
8614 // Get the size required to show an entire month. | 8793 // Get the size required to show an entire month. |
8615 MonthCal_GetMinReqRect(tmp, &rc); | 8794 MonthCal_GetMinReqRect(tmp, &rc); |
8616 // Resize the control now that the size values have been obtained. | 8795 // Resize the control now that the size values have been obtained. |
8617 SetWindowPos(tmp, NULL, 0, 0, | 8796 SetWindowPos(tmp, NULL, 0, 0, |
8618 rc.right, rc.bottom, | 8797 rc.right, rc.bottom, |
8619 SWP_NOZORDER | SWP_NOMOVE); | 8798 SWP_NOZORDER | SWP_NOMOVE); |
8620 mds[0] = mds[1] = mds[2] = (MONTHDAYSTATE)0; | 8799 mds[0] = mds[1] = mds[2] = (MONTHDAYSTATE)0; |
8621 MonthCal_SetDayState(tmp,3,mds); | 8800 MonthCal_SetDayState(tmp,3,mds); |
8622 return tmp; | 8801 return tmp; |
8623 } | 8802 } |
8624 else | 8803 else |
8625 return NULL; | 8804 return NULL; |
8626 } | 8805 } |
8627 | 8806 |
8628 /* | 8807 /* |
8629 * Sets the current date of a calendar | 8808 * Sets the current date of a calendar |
8630 * Parameters: | 8809 * Parameters: |
8633 * month: The month to set the date to | 8812 * month: The month to set the date to |
8634 * day: The day to set the date to | 8813 * day: The day to set the date to |
8635 */ | 8814 */ |
8636 void API dw_calendar_set_date(HWND handle, unsigned int year, unsigned int month, unsigned int day) | 8815 void API dw_calendar_set_date(HWND handle, unsigned int year, unsigned int month, unsigned int day) |
8637 { | 8816 { |
8638 MONTHDAYSTATE mds[3]; | 8817 MONTHDAYSTATE mds[3]; |
8639 SYSTEMTIME date; | 8818 SYSTEMTIME date; |
8640 date.wYear = year; | 8819 date.wYear = year; |
8641 date.wMonth = month; | 8820 date.wMonth = month; |
8642 date.wDay = day; | 8821 date.wDay = day; |
8643 if ( MonthCal_SetCurSel( handle, &date ) ) | 8822 if ( MonthCal_SetCurSel( handle, &date ) ) |
8644 { | 8823 { |
8645 } | 8824 } |
8646 else | 8825 else |
8647 { | 8826 { |
8648 } | 8827 } |
8649 mds[0] = mds[1] = mds[2] = (MONTHDAYSTATE)0; | 8828 mds[0] = mds[1] = mds[2] = (MONTHDAYSTATE)0; |
8650 MonthCal_SetDayState(handle,3,mds); | 8829 MonthCal_SetDayState(handle,3,mds); |
8651 } | 8830 } |
8652 | 8831 |
8653 /* | 8832 /* |
8654 * Gets the date from the calendar | 8833 * Gets the date from the calendar |
8655 * Parameters: | 8834 * Parameters: |
8658 * month: Pointer to the month to get the date to | 8837 * month: Pointer to the month to get the date to |
8659 * day: Pointer to the day to get the date to | 8838 * day: Pointer to the day to get the date to |
8660 */ | 8839 */ |
8661 void API dw_calendar_get_date(HWND handle, unsigned int *year, unsigned int *month, unsigned int *day) | 8840 void API dw_calendar_get_date(HWND handle, unsigned int *year, unsigned int *month, unsigned int *day) |
8662 { | 8841 { |
8663 SYSTEMTIME date; | 8842 SYSTEMTIME date; |
8664 if ( MonthCal_GetCurSel( handle, &date ) ) | 8843 if ( MonthCal_GetCurSel( handle, &date ) ) |
8665 { | 8844 { |
8666 *year = date.wYear; | 8845 *year = date.wYear; |
8667 *month = date.wMonth; | 8846 *month = date.wMonth; |
8668 *day = date.wDay; | 8847 *day = date.wDay; |
8669 } | 8848 } |
8670 else | 8849 else |
8671 { | 8850 { |
8672 *year = *month = *day = 0; | 8851 *year = *month = *day = 0; |
8673 } | 8852 } |
8674 } | 8853 } |
8675 | 8854 |
8676 /* | 8855 /* |
8677 * Pack windows (widgets) into a box from the end (or bottom). | 8856 * Pack windows (widgets) into a box from the end (or bottom). |
8678 * Parameters: | 8857 * Parameters: |
8684 * vsize: TRUE if the window (widget) should expand vertically to fill space given. | 8863 * vsize: TRUE if the window (widget) should expand vertically to fill space given. |
8685 * pad: Number of pixels of padding around the item. | 8864 * pad: Number of pixels of padding around the item. |
8686 */ | 8865 */ |
8687 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | 8866 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) |
8688 { | 8867 { |
8689 Box *thisbox; | 8868 Box *thisbox; |
8690 | 8869 |
8691 /* | 8870 /* |
8692 * If you try and pack an item into itself VERY bad things can happen; like at least an | 8871 * If you try and pack an item into itself VERY bad things can happen; like at least an |
8693 * infinite loop on GTK! Lets be safe! | 8872 * infinite loop on GTK! Lets be safe! |
8694 */ | 8873 */ |
8695 if(box == item) | 8874 if(box == item) |
8696 { | 8875 { |
8697 dw_messagebox("dw_box_pack_end()", DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!"); | 8876 dw_messagebox("dw_box_pack_end()", DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!"); |
8698 return; | 8877 return; |
8699 } | 8878 } |
8700 | 8879 |
8701 thisbox = (Box *)GetWindowLongPtr(box, GWLP_USERDATA); | 8880 thisbox = (Box *)GetWindowLongPtr(box, GWLP_USERDATA); |
8702 if(thisbox) | 8881 if(thisbox) |
8703 { | 8882 { |
8704 int z; | 8883 int z; |
8705 Item *tmpitem, *thisitem = thisbox->items; | 8884 Item *tmpitem, *thisitem = thisbox->items; |
8706 char tmpbuf[100]; | 8885 char tmpbuf[100]; |
8707 | 8886 |
8708 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); | 8887 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); |
8709 | 8888 |
8710 for(z=0;z<thisbox->count;z++) | 8889 for(z=0;z<thisbox->count;z++) |
8711 { | 8890 { |
8712 tmpitem[z+1] = thisitem[z]; | 8891 tmpitem[z+1] = thisitem[z]; |
8713 } | 8892 } |
8714 | 8893 |
8715 GetClassName(item, tmpbuf, 99); | 8894 GetClassName(item, tmpbuf, 99); |
8716 | 8895 |
8717 if(vsize && !height) | 8896 if(vsize && !height) |
8718 height = 1; | 8897 height = 1; |
8719 if(hsize && !width) | 8898 if(hsize && !width) |
8720 width = 1; | 8899 width = 1; |
8721 | 8900 |
8722 if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1)==0) | 8901 if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1)==0) |
8723 tmpitem[0].type = TYPEBOX; | 8902 tmpitem[0].type = TYPEBOX; |
8724 else if(strnicmp(tmpbuf, "SysMonthCal32", 13)==0) | 8903 else if(strnicmp(tmpbuf, "SysMonthCal32", 13)==0) |
8725 { | 8904 { |
8726 RECT rc; | 8905 RECT rc; |
8727 MonthCal_GetMinReqRect(item, &rc); | 8906 MonthCal_GetMinReqRect(item, &rc); |
8728 width = 1 + rc.right - rc.left; | 8907 width = 1 + rc.right - rc.left; |
8729 height = 1 + rc.bottom - rc.top; | 8908 height = 1 + rc.bottom - rc.top; |
8730 tmpitem[thisbox->count].type = TYPEITEM; | 8909 tmpitem[thisbox->count].type = TYPEITEM; |
8731 } | 8910 } |
8732 else | 8911 else |
8733 { | 8912 { |
8734 if ( width == 0 && hsize == FALSE ) | 8913 if ( width == 0 && hsize == FALSE ) |
8735 dw_messagebox("dw_box_pack_end()", DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); | 8914 dw_messagebox("dw_box_pack_end()", DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); |
8736 if ( height == 0 && vsize == FALSE ) | 8915 if ( height == 0 && vsize == FALSE ) |
8737 dw_messagebox("dw_box_pack_end()", DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item); | 8916 dw_messagebox("dw_box_pack_end()", DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item); |
8738 | 8917 |
8739 tmpitem[0].type = TYPEITEM; | 8918 tmpitem[0].type = TYPEITEM; |
8740 } | 8919 } |
8741 | 8920 |
8742 tmpitem[0].hwnd = item; | 8921 tmpitem[0].hwnd = item; |
8743 tmpitem[0].origwidth = tmpitem[0].width = width; | 8922 tmpitem[0].origwidth = tmpitem[0].width = width; |
8744 tmpitem[0].origheight = tmpitem[0].height = height; | 8923 tmpitem[0].origheight = tmpitem[0].height = height; |
8745 tmpitem[0].pad = pad; | 8924 tmpitem[0].pad = pad; |
8746 if(hsize) | 8925 if(hsize) |
8747 tmpitem[0].hsize = SIZEEXPAND; | 8926 tmpitem[0].hsize = SIZEEXPAND; |
8748 else | 8927 else |
8749 tmpitem[0].hsize = SIZESTATIC; | 8928 tmpitem[0].hsize = SIZESTATIC; |
8750 | 8929 |
8751 if(vsize) | 8930 if(vsize) |
8752 tmpitem[0].vsize = SIZEEXPAND; | 8931 tmpitem[0].vsize = SIZEEXPAND; |
8753 else | 8932 else |
8754 tmpitem[0].vsize = SIZESTATIC; | 8933 tmpitem[0].vsize = SIZESTATIC; |
8755 | 8934 |
8756 thisbox->items = tmpitem; | 8935 thisbox->items = tmpitem; |
8757 | 8936 |
8758 if(thisbox->count) | 8937 if(thisbox->count) |
8759 free(thisitem); | 8938 free(thisitem); |
8760 | 8939 |
8761 thisbox->count++; | 8940 thisbox->count++; |
8762 | 8941 |
8763 SetParent(item, box); | 8942 SetParent(item, box); |
8764 if(strncmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1)==0) | 8943 if(strncmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1)==0) |
8765 { | 8944 { |
8766 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(item, GWLP_USERDATA); | 8945 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(item, GWLP_USERDATA); |
8767 | 8946 |
8768 if(cinfo) | 8947 if(cinfo) |
8769 { | 8948 { |
8770 SetParent(cinfo->buddy, box); | 8949 SetParent(cinfo->buddy, box); |
8771 ShowWindow(cinfo->buddy, SW_SHOW); | 8950 ShowWindow(cinfo->buddy, SW_SHOW); |
8772 SendMessage(item, UDM_SETBUDDY, (WPARAM)cinfo->buddy, 0); | 8951 SendMessage(item, UDM_SETBUDDY, (WPARAM)cinfo->buddy, 0); |
8773 } | 8952 } |
8774 } | 8953 } |
8775 } | 8954 } |
8776 } | 8955 } |
8777 | 8956 |
8778 /* | 8957 /* |
8779 * Sets the default focus item for a window/dialog. | 8958 * Sets the default focus item for a window/dialog. |
8780 * Parameters: | 8959 * Parameters: |
8781 * window: Toplevel window or dialog. | 8960 * window: Toplevel window or dialog. |
8782 * defaultitem: Handle to the dialog item to be default. | 8961 * defaultitem: Handle to the dialog item to be default. |
8783 */ | 8962 */ |
8784 void API dw_window_default(HWND window, HWND defaultitem) | 8963 void API dw_window_default(HWND window, HWND defaultitem) |
8785 { | 8964 { |
8786 Box *thisbox = (Box *)GetWindowLongPtr(window, GWLP_USERDATA); | 8965 Box *thisbox = (Box *)GetWindowLongPtr(window, GWLP_USERDATA); |
8787 | 8966 |
8788 if(thisbox) | 8967 if(thisbox) |
8789 thisbox->defaultitem = defaultitem; | 8968 thisbox->defaultitem = defaultitem; |
8790 } | 8969 } |
8791 | 8970 |
8792 /* | 8971 /* |
8793 * Sets window to click the default dialog item when an ENTER is pressed. | 8972 * Sets window to click the default dialog item when an ENTER is pressed. |
8794 * Parameters: | 8973 * Parameters: |
8795 * window: Window (widget) to look for the ENTER press. | 8974 * window: Window (widget) to look for the ENTER press. |
8796 * next: Window (widget) to move to next (or click) | 8975 * next: Window (widget) to move to next (or click) |
8797 */ | 8976 */ |
8798 void API dw_window_click_default(HWND window, HWND next) | 8977 void API dw_window_click_default(HWND window, HWND next) |
8799 { | 8978 { |
8800 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(window, GWLP_USERDATA); | 8979 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(window, GWLP_USERDATA); |
8801 | 8980 |
8802 if(cinfo) | 8981 if (cinfo) |
8803 cinfo->clickdefault = next; | 8982 cinfo->clickdefault = next; |
8804 } | 8983 } |
8805 | 8984 |
8806 /* | 8985 /* |
8807 * Gets the contents of the default clipboard as text. | 8986 * Gets the contents of the default clipboard as text. |
8808 * Parameters: | 8987 * Parameters: |
8889 * Parameters: | 9068 * Parameters: |
8890 * env: Pointer to a DWEnv struct. | 9069 * env: Pointer to a DWEnv struct. |
8891 */ | 9070 */ |
8892 void API dw_environment_query(DWEnv *env) | 9071 void API dw_environment_query(DWEnv *env) |
8893 { | 9072 { |
8894 if(!env) | 9073 if(!env) |
8895 return; | 9074 return; |
8896 | 9075 |
8897 /* Get the Windows version. */ | 9076 /* Get the Windows version. */ |
8898 | 9077 |
8899 env->MajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); | 9078 env->MajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); |
8900 env->MinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); | 9079 env->MinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); |
8901 | 9080 |
8902 /* Get the build number for Windows NT/Windows 2000. */ | 9081 /* Get the build number for Windows NT/Windows 2000. */ |
8903 | 9082 |
8904 env->MinorBuild = 0; | 9083 env->MinorBuild = 0; |
8905 | 9084 |
8906 if (dwVersion < 0x80000000) | 9085 if (dwVersion < 0x80000000) |
8907 { | 9086 { |
8908 if(env->MajorVersion == 5 && env->MinorVersion == 1) | 9087 if(env->MajorVersion == 5 && env->MinorVersion == 1) |
8909 strcpy(env->osName, "Windows XP"); | 9088 strcpy(env->osName, "Windows XP"); |
8910 else if(env->MajorVersion == 5 && env->MinorVersion == 0) | 9089 else if(env->MajorVersion == 5 && env->MinorVersion == 0) |
8911 strcpy(env->osName, "Windows 2000"); | 9090 strcpy(env->osName, "Windows 2000"); |
8912 else | 9091 else |
8913 strcpy(env->osName, "Windows NT"); | 9092 strcpy(env->osName, "Windows NT"); |
8914 | 9093 |
8915 env->MajorBuild = (DWORD)(HIWORD(dwVersion)); | 9094 env->MajorBuild = (DWORD)(HIWORD(dwVersion)); |
8916 } | 9095 } |
8917 else | 9096 else |
8918 { | 9097 { |
8919 strcpy(env->osName, "Windows 95/98/ME"); | 9098 strcpy(env->osName, "Windows 95/98/ME"); |
8920 env->MajorBuild = 0; | 9099 env->MajorBuild = 0; |
8921 } | 9100 } |
8922 | 9101 |
8923 strcpy(env->buildDate, __DATE__); | 9102 strcpy(env->buildDate, __DATE__); |
8924 strcpy(env->buildTime, __TIME__); | 9103 strcpy(env->buildTime, __TIME__); |
8925 env->DWMajorVersion = DW_MAJOR_VERSION; | 9104 env->DWMajorVersion = DW_MAJOR_VERSION; |
8926 env->DWMinorVersion = DW_MINOR_VERSION; | 9105 env->DWMinorVersion = DW_MINOR_VERSION; |
8927 env->DWSubVersion = DW_SUB_VERSION; | 9106 env->DWSubVersion = DW_SUB_VERSION; |
8928 } | 9107 } |
8929 | 9108 |
8930 /* | 9109 /* |
8931 * Opens a file dialog and queries user selection. | 9110 * Opens a file dialog and queries user selection. |
8932 * Parameters: | 9111 * Parameters: |
8939 * the file path on success. | 9118 * the file path on success. |
8940 * | 9119 * |
8941 */ | 9120 */ |
8942 char * API dw_file_browse(char *title, char *defpath, char *ext, int flags) | 9121 char * API dw_file_browse(char *title, char *defpath, char *ext, int flags) |
8943 { | 9122 { |
8944 OPENFILENAME of; | 9123 OPENFILENAME of; |
8945 char filenamebuf[1001] = ""; | 9124 char filenamebuf[1001] = ""; |
8946 int rc; | 9125 int rc; |
8947 | 9126 |
8948 BROWSEINFO bi; | 9127 BROWSEINFO bi; |
8949 TCHAR szDir[MAX_PATH]; | 9128 TCHAR szDir[MAX_PATH]; |
8950 LPITEMIDLIST pidl; | 9129 LPITEMIDLIST pidl; |
8951 LPMALLOC pMalloc; | 9130 LPMALLOC pMalloc; |
8952 | 9131 |
8953 if(flags==DW_DIRECTORY_OPEN) | 9132 if(flags==DW_DIRECTORY_OPEN) |
8954 { | 9133 { |
8955 if (SUCCEEDED(SHGetMalloc(&pMalloc))) | 9134 if (SUCCEEDED(SHGetMalloc(&pMalloc))) |
8956 { | 9135 { |
8957 ZeroMemory(&bi,sizeof(bi)); | 9136 ZeroMemory(&bi,sizeof(bi)); |
8958 bi.hwndOwner = NULL; | 9137 bi.hwndOwner = NULL; |
8959 bi.pszDisplayName = 0; | 9138 bi.pszDisplayName = 0; |
8960 bi.pidlRoot = 0; | 9139 bi.pidlRoot = 0; |
8961 bi.lpszTitle = title; | 9140 bi.lpszTitle = title; |
8962 bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT; | 9141 bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT; |
8963 bi.lpfn = NULL; /*BrowseCallbackProc*/ | 9142 bi.lpfn = NULL; /*BrowseCallbackProc*/ |
8964 | 9143 |
8965 pidl = SHBrowseForFolder(&bi); | 9144 pidl = SHBrowseForFolder(&bi); |
8966 if (pidl) | 9145 if (pidl) |
8967 { | 9146 { |
8968 if (SHGetPathFromIDList(pidl,szDir)) | 9147 if (SHGetPathFromIDList(pidl,szDir)) |
8969 { | 9148 { |
8970 strcpy(filenamebuf,szDir); | 9149 strcpy(filenamebuf,szDir); |
8971 } | 9150 } |
8972 | 9151 |
8973 // In C++: pMalloc->Free(pidl); pMalloc->Release(); | 9152 // In C++: pMalloc->Free(pidl); pMalloc->Release(); |
8974 pMalloc->lpVtbl->Free(pMalloc,pidl); | 9153 pMalloc->lpVtbl->Free(pMalloc,pidl); |
8975 pMalloc->lpVtbl->Release(pMalloc); | 9154 pMalloc->lpVtbl->Release(pMalloc); |
8976 return strdup(filenamebuf); | 9155 return strdup(filenamebuf); |
8977 } | 9156 } |
8978 } | 9157 } |
8979 } | 9158 } |
8980 else | 9159 else |
8981 { | 9160 { |
8982 if(ext) | 9161 if(ext) |
8983 { | 9162 { |
8984 strcpy(filenamebuf, "*."); | 9163 strcpy(filenamebuf, "*."); |
8985 strcat(filenamebuf, ext); | 9164 strcat(filenamebuf, ext); |
8986 } | 9165 } |
8987 | 9166 |
8988 memset(&of, 0, sizeof(OPENFILENAME)); | 9167 memset(&of, 0, sizeof(OPENFILENAME)); |
8989 | 9168 |
8990 of.lStructSize = sizeof(OPENFILENAME); | 9169 of.lStructSize = sizeof(OPENFILENAME); |
8991 of.hwndOwner = HWND_DESKTOP; | 9170 of.hwndOwner = HWND_DESKTOP; |
8992 of.hInstance = DWInstance; | 9171 of.hInstance = DWInstance; |
8993 of.lpstrInitialDir = defpath; | 9172 of.lpstrInitialDir = defpath; |
8994 of.lpstrTitle = title; | 9173 of.lpstrTitle = title; |
8995 of.lpstrFile = filenamebuf; | 9174 of.lpstrFile = filenamebuf; |
8996 of.nMaxFile = 1000; | 9175 of.nMaxFile = 1000; |
8997 of.lpstrDefExt = ext; | 9176 of.lpstrDefExt = ext; |
8998 of.Flags = 0; | 9177 of.Flags = 0; |
8999 | 9178 |
9000 if(flags & DW_FILE_SAVE) | 9179 if(flags & DW_FILE_SAVE) |
9001 rc = GetSaveFileName(&of); | 9180 rc = GetSaveFileName(&of); |
9002 else | 9181 else |
9003 rc = GetOpenFileName(&of); | 9182 rc = GetOpenFileName(&of); |
9004 | 9183 |
9005 if(rc) | 9184 if(rc) |
9006 return strdup(of.lpstrFile); | 9185 return strdup(of.lpstrFile); |
9007 } | 9186 } |
9008 return NULL; | 9187 return NULL; |
9009 } | 9188 } |
9010 | 9189 |
9011 /* | 9190 /* |
9012 * Execute and external program in a seperate session. | 9191 * Execute and external program in a seperate session. |
9013 * Parameters: | 9192 * Parameters: |
9017 * Returns: | 9196 * Returns: |
9018 * -1 on error. | 9197 * -1 on error. |
9019 */ | 9198 */ |
9020 int API dw_exec(char *program, int type, char **params) | 9199 int API dw_exec(char *program, int type, char **params) |
9021 { | 9200 { |
9022 char **newparams; | 9201 char **newparams; |
9023 int retcode, count = 0, z; | 9202 int retcode, count = 0, z; |
9024 | 9203 |
9025 while(params[count]) | 9204 while(params[count]) |
9026 { | 9205 { |
9027 count++; | 9206 count++; |
9028 } | 9207 } |
9029 | 9208 |
9030 newparams = (char **)malloc(sizeof(char *) * (count+1)); | 9209 newparams = (char **)malloc(sizeof(char *) * (count+1)); |
9031 | 9210 |
9032 for(z=0;z<count;z++) | 9211 for(z=0;z<count;z++) |
9033 { | 9212 { |
9034 newparams[z] = malloc(strlen(params[z])+3); | 9213 newparams[z] = malloc(strlen(params[z])+3); |
9035 strcpy(newparams[z], "\""); | 9214 strcpy(newparams[z], "\""); |
9036 strcat(newparams[z], params[z]); | 9215 strcat(newparams[z], params[z]); |
9037 strcat(newparams[z], "\""); | 9216 strcat(newparams[z], "\""); |
9038 } | 9217 } |
9039 newparams[count] = NULL; | 9218 newparams[count] = NULL; |
9040 | 9219 |
9041 retcode = spawnvp(P_NOWAIT, program, newparams); | 9220 retcode = spawnvp(P_NOWAIT, program, newparams); |
9042 | 9221 |
9043 for(z=0;z<count;z++) | 9222 for(z=0;z<count;z++) |
9044 { | 9223 { |
9045 free(newparams[z]); | 9224 free(newparams[z]); |
9046 } | 9225 } |
9047 free(newparams); | 9226 free(newparams); |
9048 | 9227 |
9049 return retcode; | 9228 return retcode; |
9050 } | 9229 } |
9051 | 9230 |
9052 /* | 9231 /* |
9053 * Loads a web browser pointed at the given URL. | 9232 * Loads a web browser pointed at the given URL. |
9054 * Parameters: | 9233 * Parameters: |
9055 * url: Uniform resource locator. | 9234 * url: Uniform resource locator. |
9056 */ | 9235 */ |
9057 int API dw_browse(char *url) | 9236 int API dw_browse(char *url) |
9058 { | 9237 { |
9059 char *browseurl = url; | 9238 char *browseurl = url; |
9060 int retcode; | 9239 int retcode; |
9061 | 9240 |
9062 if(strlen(url) > 7 && strncmp(url, "file://", 7) == 0) | 9241 if(strlen(url) > 7 && strncmp(url, "file://", 7) == 0) |
9063 { | 9242 { |
9064 int len, z; | 9243 int len, z; |
9065 | 9244 |
9066 browseurl = &url[7]; | 9245 browseurl = &url[7]; |
9067 len = strlen(browseurl); | 9246 len = strlen(browseurl); |
9068 | 9247 |
9069 for(z=0;z<len;z++) | 9248 for(z=0;z<len;z++) |
9070 { | 9249 { |
9071 if(browseurl[z] == '|') | 9250 if(browseurl[z] == '|') |
9072 browseurl[z] = ':'; | 9251 browseurl[z] = ':'; |
9073 if(browseurl[z] == '/') | 9252 if(browseurl[z] == '/') |
9074 browseurl[z] = '\\'; | 9253 browseurl[z] = '\\'; |
9075 } | 9254 } |
9076 } | 9255 } |
9077 | 9256 |
9078 retcode = (int)ShellExecute(NULL, "open", browseurl, NULL, NULL, SW_SHOWNORMAL); | 9257 retcode = (int)ShellExecute(NULL, "open", browseurl, NULL, NULL, SW_SHOWNORMAL); |
9079 if(retcode<33 && retcode != 2) | 9258 if(retcode<33 && retcode != 2) |
9080 return -1; | 9259 return -1; |
9081 return 1; | 9260 return 1; |
9082 } | 9261 } |
9083 | 9262 |
9084 /* | 9263 /* |
9085 * Returns a pointer to a static buffer which containes the | 9264 * Returns a pointer to a static buffer which containes the |
9086 * current user directory. Or the root directory (C:\ on | 9265 * current user directory. Or the root directory (C:\ on |
9087 * OS/2 and Windows). | 9266 * OS/2 and Windows). |
9088 */ | 9267 */ |
9089 char * API dw_user_dir(void) | 9268 char * API dw_user_dir(void) |
9090 { | 9269 { |
9091 static char _user_dir[1024] = ""; | 9270 static char _user_dir[1024] = ""; |
9092 | 9271 |
9093 if(!_user_dir[0]) | 9272 if(!_user_dir[0]) |
9094 { | 9273 { |
9095 /* Figure out how to do this the "Windows way" */ | 9274 /* Figure out how to do this the "Windows way" */ |
9096 char *home = getenv("HOME"); | 9275 char *home = getenv("HOME"); |
9097 | 9276 |
9098 if(home) | 9277 if(home) |
9099 strcpy(_user_dir, home); | 9278 strcpy(_user_dir, home); |
9100 else | 9279 else |
9101 strcpy(_user_dir, "C:\\"); | 9280 strcpy(_user_dir, "C:\\"); |
9102 } | 9281 } |
9103 return _user_dir; | 9282 return _user_dir; |
9104 } | 9283 } |
9105 | 9284 |
9106 /* | 9285 /* |
9107 * Call a function from the window (widget)'s context. | 9286 * Call a function from the window (widget)'s context. |
9108 * Parameters: | 9287 * Parameters: |
9110 * function: Function pointer to be called. | 9289 * function: Function pointer to be called. |
9111 * data: Pointer to the data to be passed to the function. | 9290 * data: Pointer to the data to be passed to the function. |
9112 */ | 9291 */ |
9113 void API dw_window_function(HWND handle, void *function, void *data) | 9292 void API dw_window_function(HWND handle, void *function, void *data) |
9114 { | 9293 { |
9115 SendMessage(handle, WM_USER, (WPARAM)function, (LPARAM)data); | 9294 SendMessage(handle, WM_USER, (WPARAM)function, (LPARAM)data); |
9116 } | 9295 } |
9117 | 9296 |
9118 /* Functions for managing the user data lists that are associated with | 9297 /* Functions for managing the user data lists that are associated with |
9119 * a given window handle. Used in dw_window_set_data() and | 9298 * a given window handle. Used in dw_window_set_data() and |
9120 * dw_window_get_data(). | 9299 * dw_window_get_data(). |
9121 */ | 9300 */ |
9122 UserData *_find_userdata(UserData **root, char *varname) | 9301 UserData *_find_userdata(UserData **root, char *varname) |
9123 { | 9302 { |
9124 UserData *tmp = *root; | 9303 UserData *tmp = *root; |
9125 | 9304 |
9126 while(tmp) | 9305 while(tmp) |
9127 { | 9306 { |
9128 if(stricmp(tmp->varname, varname) == 0) | 9307 if(stricmp(tmp->varname, varname) == 0) |
9129 return tmp; | 9308 return tmp; |
9130 tmp = tmp->next; | 9309 tmp = tmp->next; |
9131 } | 9310 } |
9132 return NULL; | 9311 return NULL; |
9133 } | 9312 } |
9134 | 9313 |
9135 int _new_userdata(UserData **root, char *varname, void *data) | 9314 int _new_userdata(UserData **root, char *varname, void *data) |
9136 { | 9315 { |
9137 UserData *new = _find_userdata(root, varname); | 9316 UserData *new = _find_userdata(root, varname); |
9138 | 9317 |
9139 if(new) | 9318 if(new) |
9140 { | 9319 { |
9141 new->data = data; | 9320 new->data = data; |
9142 return TRUE; | 9321 return TRUE; |
9143 } | 9322 } |
9144 else | 9323 else |
9145 { | 9324 { |
9146 new = malloc(sizeof(UserData)); | 9325 new = malloc(sizeof(UserData)); |
9147 if(new) | 9326 if(new) |
9148 { | 9327 { |
9149 new->varname = strdup(varname); | 9328 new->varname = strdup(varname); |
9150 new->data = data; | 9329 new->data = data; |
9151 | 9330 |
9152 new->next = NULL; | 9331 new->next = NULL; |
9153 | 9332 |
9154 if (!*root) | 9333 if (!*root) |
9155 *root = new; | 9334 *root = new; |
9156 else | 9335 else |
9157 { | 9336 { |
9158 UserData *prev = NULL, *tmp = *root; | 9337 UserData *prev = NULL, *tmp = *root; |
9159 while(tmp) | 9338 while(tmp) |
9160 { | 9339 { |
9161 prev = tmp; | 9340 prev = tmp; |
9162 tmp = tmp->next; | 9341 tmp = tmp->next; |
9163 } | 9342 } |
9164 if(prev) | 9343 if(prev) |
9165 prev->next = new; | 9344 prev->next = new; |
9166 else | 9345 else |
9167 *root = new; | 9346 *root = new; |
9168 } | 9347 } |
9169 return TRUE; | 9348 return TRUE; |
9170 } | 9349 } |
9171 } | 9350 } |
9172 return FALSE; | 9351 return FALSE; |
9173 } | 9352 } |
9174 | 9353 |
9175 int _remove_userdata(UserData **root, char *varname, int all) | 9354 int _remove_userdata(UserData **root, char *varname, int all) |
9176 { | 9355 { |
9177 UserData *prev = NULL, *tmp = *root; | 9356 UserData *prev = NULL, *tmp = *root; |
9178 | 9357 |
9179 while(tmp) | 9358 while(tmp) |
9180 { | 9359 { |
9181 if(all || stricmp(tmp->varname, varname) == 0) | 9360 if(all || stricmp(tmp->varname, varname) == 0) |
9182 { | 9361 { |
9183 if(!prev) | 9362 if(!prev) |
9184 { | 9363 { |
9185 *root = tmp->next; | 9364 *root = tmp->next; |
9186 free(tmp->varname); | 9365 free(tmp->varname); |
9187 free(tmp); | 9366 free(tmp); |
9188 if(!all) | 9367 if(!all) |
9189 return 0; | 9368 return 0; |
9190 tmp = *root; | 9369 tmp = *root; |
9191 } | 9370 } |
9192 else | 9371 else |
9193 { | 9372 { |
9194 /* If all is true we should | 9373 /* If all is true we should |
9195 * never get here. | 9374 * never get here. |
9196 */ | 9375 */ |
9197 prev->next = tmp->next; | 9376 prev->next = tmp->next; |
9198 free(tmp->varname); | 9377 free(tmp->varname); |
9199 free(tmp); | 9378 free(tmp); |
9200 return 0; | 9379 return 0; |
9201 } | 9380 } |
9202 } | 9381 } |
9203 else | 9382 else |
9204 { | 9383 { |
9205 prev = tmp; | 9384 prev = tmp; |
9206 tmp = tmp->next; | 9385 tmp = tmp->next; |
9207 } | 9386 } |
9208 } | 9387 } |
9209 return 0; | 9388 return 0; |
9210 } | 9389 } |
9211 | 9390 |
9212 /* | 9391 /* |
9213 * Add a named user data item to a window handle. | 9392 * Add a named user data item to a window handle. |
9214 * Parameters: | 9393 * Parameters: |
9216 * dataname: A string pointer identifying which signal to be hooked. | 9395 * dataname: A string pointer identifying which signal to be hooked. |
9217 * data: User data to be passed to the handler function. | 9396 * data: User data to be passed to the handler function. |
9218 */ | 9397 */ |
9219 void API dw_window_set_data(HWND window, char *dataname, void *data) | 9398 void API dw_window_set_data(HWND window, char *dataname, void *data) |
9220 { | 9399 { |
9221 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(window, GWLP_USERDATA); | 9400 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(window, GWLP_USERDATA); |
9222 | 9401 |
9223 if(!cinfo) | 9402 if(!cinfo) |
9224 { | 9403 { |
9225 if(!dataname) | 9404 if(!dataname) |
9226 return; | 9405 return; |
9227 | 9406 |
9228 cinfo = calloc(1, sizeof(ColorInfo)); | 9407 cinfo = calloc(1, sizeof(ColorInfo)); |
9229 cinfo->fore = cinfo->back = -1; | 9408 cinfo->fore = cinfo->back = -1; |
9230 SetWindowLongPtr(window, GWLP_USERDATA, (LONG_PTR)cinfo); | 9409 SetWindowLongPtr(window, GWLP_USERDATA, (LONG_PTR)cinfo); |
9231 } | 9410 } |
9232 | 9411 |
9233 if(cinfo) | 9412 if(cinfo) |
9234 { | 9413 { |
9235 if(data) | 9414 if(data) |
9236 _new_userdata(&(cinfo->root), dataname, data); | 9415 _new_userdata(&(cinfo->root), dataname, data); |
9237 else | 9416 else |
9238 { | 9417 { |
9239 if(dataname) | 9418 if(dataname) |
9240 _remove_userdata(&(cinfo->root), dataname, FALSE); | 9419 _remove_userdata(&(cinfo->root), dataname, FALSE); |
9241 else | 9420 else |
9242 _remove_userdata(&(cinfo->root), NULL, TRUE); | 9421 _remove_userdata(&(cinfo->root), NULL, TRUE); |
9243 } | 9422 } |
9244 } | 9423 } |
9245 } | 9424 } |
9246 | 9425 |
9247 /* | 9426 /* |
9248 * Gets a named user data item to a window handle. | 9427 * Gets a named user data item to a window handle. |
9249 * Parameters: | 9428 * Parameters: |
9251 * dataname: A string pointer identifying which signal to be hooked. | 9430 * dataname: A string pointer identifying which signal to be hooked. |
9252 * data: User data to be passed to the handler function. | 9431 * data: User data to be passed to the handler function. |
9253 */ | 9432 */ |
9254 void * API dw_window_get_data(HWND window, char *dataname) | 9433 void * API dw_window_get_data(HWND window, char *dataname) |
9255 { | 9434 { |
9256 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(window, GWLP_USERDATA); | 9435 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(window, GWLP_USERDATA); |
9257 | 9436 |
9258 if(cinfo && cinfo->root && dataname) | 9437 if(cinfo && cinfo->root && dataname) |
9259 { | 9438 { |
9260 UserData *ud = _find_userdata(&(cinfo->root), dataname); | 9439 UserData *ud = _find_userdata(&(cinfo->root), dataname); |
9261 if(ud) | 9440 if(ud) |
9262 return ud->data; | 9441 return ud->data; |
9263 } | 9442 } |
9264 return NULL; | 9443 return NULL; |
9265 } | 9444 } |
9266 | 9445 |
9267 /* | 9446 /* |
9268 * Add a callback to a timer event. | 9447 * Add a callback to a timer event. |
9269 * Parameters: | 9448 * Parameters: |
9273 * Returns: | 9452 * Returns: |
9274 * Timer ID for use with dw_timer_disconnect(), 0 on error. | 9453 * Timer ID for use with dw_timer_disconnect(), 0 on error. |
9275 */ | 9454 */ |
9276 int API dw_timer_connect(int interval, void *sigfunc, void *data) | 9455 int API dw_timer_connect(int interval, void *sigfunc, void *data) |
9277 { | 9456 { |
9278 if(sigfunc) | 9457 if(sigfunc) |
9279 { | 9458 { |
9280 int timerid = SetTimer(NULL, 0, interval, _TimerProc); | 9459 int timerid = SetTimer(NULL, 0, interval, _TimerProc); |
9281 | 9460 |
9282 if(timerid) | 9461 if(timerid) |
9283 { | 9462 { |
9284 _new_signal(WM_TIMER, NULL, timerid, sigfunc, data); | 9463 _new_signal(WM_TIMER, NULL, timerid, sigfunc, data); |
9285 return timerid; | 9464 return timerid; |
9286 } | 9465 } |
9287 } | 9466 } |
9288 return 0; | 9467 return 0; |
9289 } | 9468 } |
9290 | 9469 |
9291 /* | 9470 /* |
9292 * Removes timer callback. | 9471 * Removes timer callback. |
9293 * Parameters: | 9472 * Parameters: |
9294 * id: Timer ID returned by dw_timer_connect(). | 9473 * id: Timer ID returned by dw_timer_connect(). |
9295 */ | 9474 */ |
9296 void API dw_timer_disconnect(int id) | 9475 void API dw_timer_disconnect(int id) |
9297 { | 9476 { |
9298 SignalHandler *prev = NULL, *tmp = Root; | 9477 SignalHandler *prev = NULL, *tmp = Root; |
9299 | 9478 |
9300 /* 0 is an invalid timer ID */ | 9479 /* 0 is an invalid timer ID */ |
9301 if(!id) | 9480 if(!id) |
9302 return; | 9481 return; |
9303 | 9482 |
9304 KillTimer(NULL, id); | 9483 KillTimer(NULL, id); |
9305 | 9484 |
9306 while(tmp) | 9485 while(tmp) |
9307 { | 9486 { |
9308 if(tmp->id == id) | 9487 if(tmp->id == id) |
9309 { | 9488 { |
9310 if(prev) | 9489 if(prev) |
9311 { | 9490 { |
9312 prev->next = tmp->next; | 9491 prev->next = tmp->next; |
9313 free(tmp); | 9492 free(tmp); |
9314 tmp = prev->next; | 9493 tmp = prev->next; |
9315 } | 9494 } |
9316 else | 9495 else |
9317 { | 9496 { |
9318 Root = tmp->next; | 9497 Root = tmp->next; |
9319 free(tmp); | 9498 free(tmp); |
9320 tmp = Root; | 9499 tmp = Root; |
9321 } | 9500 } |
9322 } | 9501 } |
9323 else | 9502 else |
9324 { | 9503 { |
9325 prev = tmp; | 9504 prev = tmp; |
9326 tmp = tmp->next; | 9505 tmp = tmp->next; |
9327 } | 9506 } |
9328 } | 9507 } |
9329 } | 9508 } |
9330 | 9509 |
9331 /* | 9510 /* |
9332 * Add a callback to a window event. | 9511 * Add a callback to a window event. |
9333 * Parameters: | 9512 * Parameters: |
9336 * sigfunc: The pointer to the function to be used as the callback. | 9515 * sigfunc: The pointer to the function to be used as the callback. |
9337 * data: User data to be passed to the handler function. | 9516 * data: User data to be passed to the handler function. |
9338 */ | 9517 */ |
9339 void API dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data) | 9518 void API dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data) |
9340 { | 9519 { |
9341 ULONG message = 0, id = 0; | 9520 ULONG message = 0, id = 0; |
9342 | 9521 |
9343 if(window && signame && sigfunc) | 9522 if (window && signame && sigfunc) |
9344 { | 9523 { |
9345 if(stricmp(signame, DW_SIGNAL_SET_FOCUS) == 0) | 9524 if (stricmp(signame, DW_SIGNAL_SET_FOCUS) == 0) |
9346 window = _normalize_handle(window); | 9525 window = _normalize_handle(window); |
9347 | 9526 |
9348 if((message = _findsigmessage(signame)) != 0) | 9527 if ((message = _findsigmessage(signame)) != 0) |
9349 { | 9528 { |
9350 /* Handle special case of the menu item */ | 9529 /* Handle special case of the menu item */ |
9351 if(message == WM_COMMAND && window < (HWND)65536) | 9530 if (message == WM_COMMAND && window < (HWND)65536) |
9352 { | 9531 { |
9353 char buffer[15]; | 9532 char buffer[15]; |
9354 HWND owner; | 9533 HWND owner; |
9355 | 9534 |
9356 sprintf(buffer, "_dw_id%d", (int)window); | 9535 sprintf(buffer, "_dw_id%d", (int)window); |
9357 owner = (HWND)dw_window_get_data(DW_HWND_OBJECT, buffer); | 9536 owner = (HWND)dw_window_get_data(DW_HWND_OBJECT, buffer); |
9358 | 9537 |
9359 if(owner) | 9538 if (owner) |
9360 { | 9539 { |
9361 id = (ULONG)window; | 9540 id = (ULONG)window; |
9362 window = owner; | 9541 window = owner; |
9363 dw_window_set_data(DW_HWND_OBJECT, buffer, 0); | 9542 dw_window_set_data(DW_HWND_OBJECT, buffer, 0); |
9364 } | 9543 } |
9365 else | 9544 else |
9366 { | 9545 { |
9367 /* If it is a popup menu clear all entries */ | 9546 /* If it is a popup menu clear all entries */ |
9368 dw_signal_disconnect_by_window(window); | 9547 dw_signal_disconnect_by_window(window); |
9369 } | 9548 } |
9370 } | 9549 } |
9371 _new_signal(message, window, id, sigfunc, data); | 9550 _new_signal(message, window, id, sigfunc, data); |
9372 } | 9551 } |
9373 } | 9552 } |
9374 } | 9553 } |
9375 | 9554 |
9376 /* | 9555 /* |
9377 * Removes callbacks for a given window with given name. | 9556 * Removes callbacks for a given window with given name. |
9378 * Parameters: | 9557 * Parameters: |
9379 * window: Window handle of callback to be removed. | 9558 * window: Window handle of callback to be removed. |
9380 */ | 9559 */ |
9381 void API dw_signal_disconnect_by_name(HWND window, char *signame) | 9560 void API dw_signal_disconnect_by_name(HWND window, char *signame) |
9382 { | 9561 { |
9383 SignalHandler *prev = NULL, *tmp = Root; | 9562 SignalHandler *prev = NULL, *tmp = Root; |
9384 ULONG message; | 9563 ULONG message; |
9385 | 9564 |
9386 if(!window || !signame || (message = _findsigmessage(signame)) == 0) | 9565 if(!window || !signame || (message = _findsigmessage(signame)) == 0) |
9387 return; | 9566 return; |
9388 | 9567 |
9389 while(tmp) | 9568 while(tmp) |
9390 { | 9569 { |
9391 if(tmp->window == window && tmp->message == message) | 9570 if(tmp->window == window && tmp->message == message) |
9392 { | 9571 { |
9393 if(prev) | 9572 if(prev) |
9394 { | 9573 { |
9395 prev->next = tmp->next; | 9574 prev->next = tmp->next; |
9396 free(tmp); | 9575 free(tmp); |
9397 tmp = prev->next; | 9576 tmp = prev->next; |
9398 } | 9577 } |
9399 else | 9578 else |
9400 { | 9579 { |
9401 Root = tmp->next; | 9580 Root = tmp->next; |
9402 free(tmp); | 9581 free(tmp); |
9403 tmp = Root; | 9582 tmp = Root; |
9404 } | 9583 } |
9405 } | 9584 } |
9406 else | 9585 else |
9407 { | 9586 { |
9408 prev = tmp; | 9587 prev = tmp; |
9409 tmp = tmp->next; | 9588 tmp = tmp->next; |
9410 } | 9589 } |
9411 } | 9590 } |
9412 } | 9591 } |
9413 | 9592 |
9414 /* | 9593 /* |
9415 * Removes all callbacks for a given window. | 9594 * Removes all callbacks for a given window. |
9416 * Parameters: | 9595 * Parameters: |
9417 * window: Window handle of callback to be removed. | 9596 * window: Window handle of callback to be removed. |
9418 */ | 9597 */ |
9419 void API dw_signal_disconnect_by_window(HWND window) | 9598 void API dw_signal_disconnect_by_window(HWND window) |
9420 { | 9599 { |
9421 SignalHandler *prev = NULL, *tmp = Root; | 9600 SignalHandler *prev = NULL, *tmp = Root; |
9422 | 9601 |
9423 while(tmp) | 9602 while(tmp) |
9424 { | 9603 { |
9425 if(tmp->window == window) | 9604 if(tmp->window == window) |
9426 { | 9605 { |
9427 if(prev) | 9606 if(prev) |
9428 { | 9607 { |
9429 prev->next = tmp->next; | 9608 prev->next = tmp->next; |
9430 free(tmp); | 9609 free(tmp); |
9431 tmp = prev->next; | 9610 tmp = prev->next; |
9432 } | 9611 } |
9433 else | 9612 else |
9434 { | 9613 { |
9435 Root = tmp->next; | 9614 Root = tmp->next; |
9436 free(tmp); | 9615 free(tmp); |
9437 tmp = Root; | 9616 tmp = Root; |
9438 } | 9617 } |
9439 } | 9618 } |
9440 else | 9619 else |
9441 { | 9620 { |
9442 prev = tmp; | 9621 prev = tmp; |
9443 tmp = tmp->next; | 9622 tmp = tmp->next; |
9444 } | 9623 } |
9445 } | 9624 } |
9446 } | 9625 } |
9447 | 9626 |
9448 /* | 9627 /* |
9449 * Removes all callbacks for a given window with specified data. | 9628 * Removes all callbacks for a given window with specified data. |
9450 * Parameters: | 9629 * Parameters: |
9451 * window: Window handle of callback to be removed. | 9630 * window: Window handle of callback to be removed. |
9452 * data: Pointer to the data to be compared against. | 9631 * data: Pointer to the data to be compared against. |
9453 */ | 9632 */ |
9454 void API dw_signal_disconnect_by_data(HWND window, void *data) | 9633 void API dw_signal_disconnect_by_data(HWND window, void *data) |
9455 { | 9634 { |
9456 SignalHandler *prev = NULL, *tmp = Root; | 9635 SignalHandler *prev = NULL, *tmp = Root; |
9457 | 9636 |
9458 while(tmp) | 9637 while(tmp) |
9459 { | 9638 { |
9460 if(tmp->window == window && tmp->data == data) | 9639 if(tmp->window == window && tmp->data == data) |
9461 { | 9640 { |
9462 if(prev) | 9641 if(prev) |
9463 { | 9642 { |
9464 prev->next = tmp->next; | 9643 prev->next = tmp->next; |
9465 free(tmp); | 9644 free(tmp); |
9466 tmp = prev->next; | 9645 tmp = prev->next; |
9467 } | 9646 } |
9468 else | 9647 else |
9469 { | 9648 { |
9470 Root = tmp->next; | 9649 Root = tmp->next; |
9471 free(tmp); | 9650 free(tmp); |
9472 tmp = Root; | 9651 tmp = Root; |
9473 } | 9652 } |
9474 } | 9653 } |
9475 else | 9654 else |
9476 { | 9655 { |
9477 prev = tmp; | 9656 prev = tmp; |
9478 tmp = tmp->next; | 9657 tmp = tmp->next; |
9479 } | 9658 } |
9480 } | 9659 } |
9481 } | 9660 } |
9482 |