comparison win/dw.c @ 1422:131bedf41332

Initial support for automatic redrawing on Windows and ranged/bitmap auto-calculation support. Also some code optimization and cleanup on the Mac gleaned from the Windows changes.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 03 Dec 2011 02:08:40 +0000
parents ddf9cfb4a074
children 1628bf383893
comparison
equal deleted inserted replaced
1421:63d253a2cdd9 1422:131bedf41332
179 void _handle_splitbar_resize(HWND hwnd, float percent, int type, int x, int y); 179 void _handle_splitbar_resize(HWND hwnd, float percent, int type, int x, int y);
180 int _lookup_icon(HWND handle, HICON hicon, int type); 180 int _lookup_icon(HWND handle, HICON hicon, int type);
181 HFONT _acquire_font(HWND handle, char *fontname); 181 HFONT _acquire_font(HWND handle, char *fontname);
182 void _click_default(HWND handle); 182 void _click_default(HWND handle);
183 void _do_resize(Box *thisbox, int x, int y); 183 void _do_resize(Box *thisbox, int x, int y);
184
185 /* Internal function to queue a window redraw */
186 void _dw_redraw(HWND window, int skip)
187 {
188 static HWND lastwindow = 0;
189
190 if(skip && !window)
191 return;
192
193 if(lastwindow != window && lastwindow)
194 {
195 dw_window_redraw(lastwindow);
196 }
197 lastwindow = window;
198 }
184 199
185 typedef struct _sighandler 200 typedef struct _sighandler
186 { 201 {
187 struct _sighandler *next; 202 struct _sighandler *next;
188 ULONG message; 203 ULONG message;
1050 HWND box, lastbox = GetParent(handle); 1065 HWND box, lastbox = GetParent(handle);
1051 1066
1052 /* Find the toplevel window */ 1067 /* Find the toplevel window */
1053 while((box = GetParent(lastbox))) 1068 while((box = GetParent(lastbox)))
1054 { 1069 {
1070 if(box == DW_HWND_OBJECT)
1071 return 0;
1055 lastbox = box; 1072 lastbox = box;
1056 } 1073 }
1057 if(lastbox) 1074 if(lastbox)
1058 return lastbox; 1075 return lastbox;
1059 return handle; 1076 return handle;
2386 2403
2387 } 2404 }
2388 break; 2405 break;
2389 } 2406 }
2390 if(result != -1) 2407 if(result != -1)
2408 {
2409 /* Make sure any queued redraws are handled */
2410 _dw_redraw(0, FALSE);
2411 /* Then finally return */
2391 return result; 2412 return result;
2392 else 2413 }
2393 { 2414 return DefWindowProc(hWnd, msg, mp1, mp2);
2394 return DefWindowProc(hWnd, msg, mp1, mp2);
2395 }
2396 } 2415 }
2397 2416
2398 VOID CALLBACK _TimerProc(HWND hwnd, UINT msg, UINT_PTR idEvent, DWORD dwTime) 2417 VOID CALLBACK _TimerProc(HWND hwnd, UINT msg, UINT_PTR idEvent, DWORD dwTime)
2399 { 2418 {
2400 _wndproc(hwnd, msg, (WPARAM)idEvent, 0); 2419 _wndproc(hwnd, msg, (WPARAM)idEvent, 0);
4337 * 4356 *
4338 * Scrolled(Container,Tree,MLE)/Render/Unspecified: 1x1 4357 * Scrolled(Container,Tree,MLE)/Render/Unspecified: 1x1
4339 * Entryfield/Combobox/Spinbutton: 150x(maxfontheight) 4358 * Entryfield/Combobox/Spinbutton: 150x(maxfontheight)
4340 * Spinbutton: 50x(maxfontheight) 4359 * Spinbutton: 50x(maxfontheight)
4341 * Text/Status: (textwidth)x(textheight) 4360 * Text/Status: (textwidth)x(textheight)
4361 * Ranged: 100x14 or 14x100 for vertical.
4362 * Buttons/Bitmaps: Size of text or image and border.
4342 */ 4363 */
4343 void _control_size(HWND handle, int *width, int *height) 4364 void _control_size(HWND handle, int *width, int *height)
4344 { 4365 {
4345 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0; 4366 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0;
4346 char tmpbuf[100], *buf = dw_window_get_text(handle); 4367 char tmpbuf[100], *buf = dw_window_get_text(handle);
4347 static char testtext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 4368 static char testtext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
4369 HBITMAP hbm = 0;
4348 4370
4349 GetClassName(handle, tmpbuf, 99); 4371 GetClassName(handle, tmpbuf, 99);
4350 4372
4351 /* If we have a string... 4373 /* If we have a string...
4352 * calculate the size with the current font. 4374 * calculate the size with the current font.
4353 */ 4375 */
4354 if(buf) 4376 if(buf)
4355 { 4377 {
4356 if(*buf) 4378 if(*buf)
4357 dw_font_text_extents_get(handle, NULL, buf, &thiswidth, &thisheight); 4379 dw_font_text_extents_get(handle, NULL, buf, &thiswidth, &thisheight);
4358 dw_free(buf); 4380 dw_free(buf);
4359 } 4381 }
4360 4382
4383 /* Attempt to get bitmap from classes that can have them */
4384 if(strnicmp(tmpbuf, STATICCLASSNAME, strlen(STATICCLASSNAME)+1) == 0)
4385 hbm = (HBITMAP)SendMessage(handle, STM_GETIMAGE, IMAGE_BITMAP, 0);
4386 if(strnicmp(tmpbuf, BUTTONCLASSNAME, strlen(BUTTONCLASSNAME)+1) == 0)
4387 hbm = (HBITMAP)SendMessage(handle, BM_GETIMAGE, IMAGE_BITMAP, 0);
4388
4389 /* If we got an image... set the sizes appropriately */
4390 if(hbm)
4391 {
4392 BITMAP bmi;
4393
4394 GetObject(hbm, sizeof(BITMAP), &bmi);
4395 thiswidth = bmi.bmWidth;
4396 thisheight = bmi.bmHeight;
4397 }
4398
4361 /* Combobox */ 4399 /* Combobox */
4362 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1) == 0) 4400 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1) == 0)
4363 { 4401 {
4364 dw_font_text_extents_get(handle, NULL, testtext, NULL, &thisheight); 4402 dw_font_text_extents_get(handle, NULL, testtext, NULL, &thisheight);
4365 thiswidth = 150; 4403 thiswidth = 150;
4366 extraheight = 4; 4404 extraheight = 4;
4367 if(thisheight < 18) 4405 if(thisheight < 18)
4368 thisheight = 18; 4406 thisheight = 18;
4369 } 4407 }
4408 /* Ranged: Percent, Slider, Scrollbar */
4409 else if(strnicmp(tmpbuf, PROGRESS_CLASS, strlen(PROGRESS_CLASS)+1) == 0 ||
4410 strnicmp(tmpbuf, TRACKBAR_CLASS, strlen(TRACKBAR_CLASS)+1) == 0 ||
4411 strnicmp(tmpbuf, SCROLLBARCLASSNAME, strlen(SCROLLBARCLASSNAME)+1) == 0)
4412 {
4413 if(strnicmp(tmpbuf, SCROLLBARCLASSNAME, strlen(SCROLLBARCLASSNAME)+1) == 0 &&
4414 GetWindowLong(handle, GWL_STYLE) & SBS_VERT)
4415 {
4416 /* Vertical */
4417 thiswidth = 14;
4418 thisheight = 100;
4419 }
4420 else
4421 {
4422 /* Horizontal */
4423 thiswidth = 100;
4424 thisheight = 14;
4425 }
4426 }
4427 /* Spinbuttons */
4370 else if(strnicmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1) == 0) 4428 else if(strnicmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1) == 0)
4371 { 4429 {
4372 dw_font_text_extents_get(handle, NULL, testtext, NULL, &thisheight); 4430 dw_font_text_extents_get(handle, NULL, testtext, NULL, &thisheight);
4373 thiswidth = 50; 4431 thiswidth = 50;
4374 } 4432 }
4433 /* Entryfields */
4375 else if(strnicmp(tmpbuf, EDITCLASSNAME, strlen(EDITCLASSNAME)+1) == 0 && 4434 else if(strnicmp(tmpbuf, EDITCLASSNAME, strlen(EDITCLASSNAME)+1) == 0 &&
4376 !(GetWindowLong(handle, GWL_STYLE) & ES_MULTILINE)) 4435 !(GetWindowLong(handle, GWL_STYLE) & ES_MULTILINE))
4377 { 4436 {
4378 dw_font_text_extents_get(handle, NULL, testtext, NULL, &thisheight); 4437 dw_font_text_extents_get(handle, NULL, testtext, NULL, &thisheight);
4379 thiswidth = 150; 4438 thiswidth = 150;
4381 } 4440 }
4382 else if(strnicmp(tmpbuf, BUTTONCLASSNAME, strlen(BUTTONCLASSNAME)+1) == 0) 4441 else if(strnicmp(tmpbuf, BUTTONCLASSNAME, strlen(BUTTONCLASSNAME)+1) == 0)
4383 { 4442 {
4384 ULONG style = GetWindowLong(handle, GWL_STYLE); 4443 ULONG style = GetWindowLong(handle, GWL_STYLE);
4385 4444
4386 if(style & BS_AUTOCHECKBOX || style & BS_AUTORADIOBUTTON) 4445 /* Bitmap buttons */
4446 if(hbm)
4447 {
4448 extrawidth = 2;
4449 extraheight = 2;
4450 }
4451 /* Checkbox or radio button */
4452 else if(style & BS_AUTOCHECKBOX || style & BS_AUTORADIOBUTTON)
4387 { 4453 {
4388 extrawidth = 24; 4454 extrawidth = 24;
4389 extraheight = 4; 4455 extraheight = 4;
4390 } 4456 }
4457 /* Text buttons */
4391 else 4458 else
4392 { 4459 {
4393 extrawidth = 8; 4460 extrawidth = 8;
4394 extraheight = 4; 4461 extraheight = 4;
4395 } 4462 }
4397 else if(strnicmp(tmpbuf, StatusbarClassName, strlen(StatusbarClassName)+1) == 0) 4464 else if(strnicmp(tmpbuf, StatusbarClassName, strlen(StatusbarClassName)+1) == 0)
4398 { 4465 {
4399 extrawidth = 4; 4466 extrawidth = 4;
4400 extraheight = 2; 4467 extraheight = 2;
4401 } 4468 }
4402
4403 4469
4404 /* Set the requested sizes */ 4470 /* Set the requested sizes */
4405 if(width) 4471 if(width)
4406 *width = thiswidth + extrawidth; 4472 *width = thiswidth + extrawidth;
4407 if(height) 4473 if(height)
4466 if(oldfont) 4532 if(oldfont)
4467 DeleteObject(oldfont); 4533 DeleteObject(oldfont);
4468 4534
4469 /* Check to see if any of the sizes need to be recalculated */ 4535 /* Check to see if any of the sizes need to be recalculated */
4470 if(item && (item->origwidth == -1 || item->origheight == -1)) 4536 if(item && (item->origwidth == -1 || item->origheight == -1))
4537 {
4471 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); 4538 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL);
4539 /* Queue a redraw on the top-level window */
4540 _dw_redraw(_toplevel_window(handle), TRUE);
4541 }
4472 return DW_ERROR_NONE; 4542 return DW_ERROR_NONE;
4473 } 4543 }
4474 return DW_ERROR_UNKNOWN; 4544 return DW_ERROR_UNKNOWN;
4475 } 4545 }
4476 4546
6212 6282
6213 if(hbitmap && oldbitmap) 6283 if(hbitmap && oldbitmap)
6214 DeleteObject(oldbitmap); 6284 DeleteObject(oldbitmap);
6215 else if(icon && oldicon) 6285 else if(icon && oldicon)
6216 DeleteObject(oldicon); 6286 DeleteObject(oldicon);
6287
6288 /* If we changed the bitmap... */
6289 {
6290 Item *item = _box_item(handle);
6291
6292 /* Check to see if any of the sizes need to be recalculated */
6293 if(item && (item->origwidth == -1 || item->origheight == -1))
6294 {
6295 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL);
6296 /* Queue a redraw on the top-level window */
6297 _dw_redraw(_toplevel_window(handle), TRUE);
6298 }
6299 }
6217 } 6300 }
6218 6301
6219 /* 6302 /*
6220 * Sets the bitmap used for a given static window from data. 6303 * Sets the bitmap used for a given static window from data.
6221 * Parameters: 6304 * Parameters:
6334 { 6417 {
6335 Item *item = _box_item(handle); 6418 Item *item = _box_item(handle);
6336 6419
6337 /* Check to see if any of the sizes need to be recalculated */ 6420 /* Check to see if any of the sizes need to be recalculated */
6338 if(item && (item->origwidth == -1 || item->origheight == -1)) 6421 if(item && (item->origwidth == -1 || item->origheight == -1))
6422 {
6339 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); 6423 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL);
6424 /* Queue a redraw on the top-level window */
6425 _dw_redraw(_toplevel_window(handle), TRUE);
6426 }
6340 } 6427 }
6341 } 6428 }
6342 6429
6343 /* 6430 /*
6344 * Sets the text used for a given window's floating bubble help. 6431 * Sets the text used for a given window's floating bubble help.
6564 SetParent(cinfo->buddy, box); 6651 SetParent(cinfo->buddy, box);
6565 ShowWindow(cinfo->buddy, SW_SHOW); 6652 ShowWindow(cinfo->buddy, SW_SHOW);
6566 SendMessage(item, UDM_SETBUDDY, (WPARAM)cinfo->buddy, 0); 6653 SendMessage(item, UDM_SETBUDDY, (WPARAM)cinfo->buddy, 0);
6567 } 6654 }
6568 } 6655 }
6656 /* Queue a redraw on the top-level window */
6657 _dw_redraw(_toplevel_window(item), TRUE);
6569 } 6658 }
6570 } 6659 }
6571 6660
6572 /* 6661 /*
6573 * Pack windows (widgets) into a box at an arbitrary location. 6662 * Pack windows (widgets) into a box at an arbitrary location.