Mercurial > dwindows
comparison win/dw.c @ 1792:b0bdec1b820c
Similar fixes to the Mac one on OS/2 and Windows....
Plus a performance optimization on all three platforms.
Don't redraw the window if the calculated control size did not change.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 05 Aug 2012 13:47:57 +0000 |
parents | 209c57a14b09 |
children | 9304241b7b33 |
comparison
equal
deleted
inserted
replaced
1791:ed8851658015 | 1792:b0bdec1b820c |
---|---|
4570 * Buttons/Bitmaps: Size of text or image and border. | 4570 * Buttons/Bitmaps: Size of text or image and border. |
4571 */ | 4571 */ |
4572 void _control_size(HWND handle, int *width, int *height) | 4572 void _control_size(HWND handle, int *width, int *height) |
4573 { | 4573 { |
4574 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0; | 4574 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0; |
4575 char *buf = dw_window_get_text(handle); | |
4576 TCHAR tmpbuf[100] = {0}; | 4575 TCHAR tmpbuf[100] = {0}; |
4577 static char testtext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | 4576 static char testtext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
4578 HBITMAP hbm = 0; | 4577 HBITMAP hbm = 0; |
4579 HICON hic = 0; | 4578 HICON hic = 0; |
4580 ICONINFO ii = {0}; | 4579 ICONINFO ii = {0}; |
4581 | 4580 |
4582 GetClassName(handle, tmpbuf, 99); | 4581 GetClassName(handle, tmpbuf, 99); |
4583 | 4582 |
4584 /* If we have a string... | |
4585 * calculate the size with the current font. | |
4586 */ | |
4587 if(buf) | |
4588 { | |
4589 if(*buf) | |
4590 dw_font_text_extents_get(handle, NULL, buf, &thiswidth, &thisheight); | |
4591 dw_free(buf); | |
4592 } | |
4593 | |
4594 /* Attempt to get icon from classes that can have them */ | 4583 /* Attempt to get icon from classes that can have them */ |
4595 if(_tcsnicmp(tmpbuf, STATICCLASSNAME, _tcslen(STATICCLASSNAME)+1) == 0) | 4584 if(_tcsnicmp(tmpbuf, STATICCLASSNAME, _tcslen(STATICCLASSNAME)+1) == 0) |
4596 hic = (HICON)SendMessage(handle, STM_GETIMAGE, IMAGE_ICON, 0); | 4585 hic = (HICON)SendMessage(handle, STM_GETIMAGE, IMAGE_ICON, 0); |
4597 else if(_tcsnicmp(tmpbuf, BUTTONCLASSNAME, _tcslen(BUTTONCLASSNAME)+1) == 0) | 4586 else if(_tcsnicmp(tmpbuf, BUTTONCLASSNAME, _tcslen(BUTTONCLASSNAME)+1) == 0) |
4598 hic = (HICON)SendMessage(handle, BM_GETIMAGE, IMAGE_ICON, 0); | 4587 hic = (HICON)SendMessage(handle, BM_GETIMAGE, IMAGE_ICON, 0); |
4620 BITMAP bmi = { 0 }; | 4609 BITMAP bmi = { 0 }; |
4621 | 4610 |
4622 GetObject(hbm, sizeof(BITMAP), &bmi); | 4611 GetObject(hbm, sizeof(BITMAP), &bmi); |
4623 thiswidth = bmi.bmWidth; | 4612 thiswidth = bmi.bmWidth; |
4624 thisheight = bmi.bmHeight; | 4613 thisheight = bmi.bmHeight; |
4614 } | |
4615 else | |
4616 { | |
4617 char *buf = dw_window_get_text(handle); | |
4618 | |
4619 /* If we have a string... | |
4620 * calculate the size with the current font. | |
4621 */ | |
4622 if(buf) | |
4623 { | |
4624 if(*buf) | |
4625 dw_font_text_extents_get(handle, NULL, buf, &thiswidth, &thisheight); | |
4626 else if(_tcsnicmp(tmpbuf, STATICCLASSNAME, _tcslen(STATICCLASSNAME)+1) == 0 || | |
4627 _tcsnicmp(tmpbuf, StatusbarClassName, _tcslen(StatusbarClassName)+1) == 0) | |
4628 dw_font_text_extents_get(handle, NULL, testtext, NULL, &thisheight); | |
4629 dw_free(buf); | |
4630 } | |
4625 } | 4631 } |
4626 | 4632 |
4627 /* Combobox */ | 4633 /* Combobox */ |
4628 if(_tcsnicmp(tmpbuf, COMBOBOXCLASSNAME, _tcslen(COMBOBOXCLASSNAME)+1) == 0) | 4634 if(_tcsnicmp(tmpbuf, COMBOBOXCLASSNAME, _tcslen(COMBOBOXCLASSNAME)+1) == 0) |
4629 { | 4635 { |
6915 Item *item = _box_item(handle); | 6921 Item *item = _box_item(handle); |
6916 | 6922 |
6917 /* Check to see if any of the sizes need to be recalculated */ | 6923 /* Check to see if any of the sizes need to be recalculated */ |
6918 if(item && (item->origwidth == -1 || item->origheight == -1)) | 6924 if(item && (item->origwidth == -1 || item->origheight == -1)) |
6919 { | 6925 { |
6920 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); | 6926 int newwidth, newheight; |
6921 /* Queue a redraw on the top-level window */ | 6927 |
6922 _dw_redraw(_toplevel_window(handle), TRUE); | 6928 _control_size(handle, &newwidth, &newheight); |
6929 | |
6930 /* Only update the item and redraw the window if it changed */ | |
6931 if((item->origwidth == -1 && item->width != newwidth) || | |
6932 (item->origheight == -1 && item->height != newheight)) | |
6933 { | |
6934 if(item->origwidth == -1) | |
6935 item->width = newwidth; | |
6936 if(item->origheight == -1) | |
6937 item->height = newheight; | |
6938 /* Queue a redraw on the top-level window */ | |
6939 _dw_redraw(_toplevel_window(handle), TRUE); | |
6940 } | |
6923 } | 6941 } |
6924 } | 6942 } |
6925 } | 6943 } |
6926 | 6944 |
6927 /* | 6945 /* |