Mercurial > dwindows
changeset 1824:213420512084
Changes on OS/2 to allow dw_window_set_bitmap() to work on bitmap
buttons... also rewrote and optimized some of the code.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 26 Oct 2012 08:37:45 +0000 |
parents | 9c77567c5b2d |
children | df7f3967c21e |
files | os2/dw.c |
diffstat | 1 files changed, 134 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- a/os2/dw.c Fri Oct 26 05:25:54 2012 +0000 +++ b/os2/dw.c Fri Oct 26 08:37:45 2012 +0000 @@ -6655,6 +6655,29 @@ return tmp; } +/* Internal function to create a disabled version of a pixmap */ +HPIXMAP _create_disabled(HWND handle, HPIXMAP pixmap) +{ + /* Create a disabled style pixmap */ + HPIXMAP disabled = dw_pixmap_new(handle, pixmap->width, pixmap->height, dw_color_depth_get()); + LONG fore = _foreground; + int z, j, lim; + + dw_pixmap_bitblt(0, disabled, 0, 0, pixmap->width, pixmap->height, 0, pixmap, 0, 0); + + dw_color_foreground_set(DW_CLR_PALEGRAY); + lim = pixmap->width/2; + for(j=0;j<pixmap->height;j++) + { + int mod = j%2; + + for(z=0;z<lim;z++) + dw_draw_point(0, disabled, (z*2)+mod, j); + } + _foreground = fore; + return disabled; +} + /* * Create a new bitmap button window (widget) to be packed from a file. * Parameters: @@ -6684,8 +6707,7 @@ if(file && (pixmap = calloc(1,sizeof(struct _hpixmap)))) { - int z, j, lim, len; - LONG fore; + int z, len; strcpy(file, filename); @@ -6727,21 +6749,7 @@ } else { - /* Create a disabled style pixmap */ - disabled = dw_pixmap_new(tmp, pixmap->width, pixmap->height, dw_color_depth_get()); - dw_pixmap_bitblt(0, disabled, 0, 0, pixmap->width, pixmap->height, 0, pixmap, 0, 0); - - fore = _foreground; - dw_color_foreground_set(DW_CLR_PALEGRAY); - lim = pixmap->width/2; - for(j=0;j<pixmap->height;j++) - { - int mod = j%2; - - for(z=0;z<lim;z++) - dw_draw_point(0, disabled, (z*2)+mod, j); - } - _foreground = fore; + disabled = _create_disabled(tmp, pixmap); } } @@ -6792,8 +6800,6 @@ if((pixmap = calloc(1, sizeof(struct _hpixmap))) != NULL) { - int z, j, lim; - LONG fore; file = tmpnam( NULL ); if ( file != NULL ) { @@ -6822,21 +6828,7 @@ } else { - /* Create a disabled style pixmap */ - disabled = dw_pixmap_new(tmp, pixmap->width, pixmap->height, dw_color_depth_get()); - dw_pixmap_bitblt(0, disabled, 0, 0, pixmap->width, pixmap->height, 0, pixmap, 0, 0); - - fore = _foreground; - dw_color_foreground_set(DW_CLR_PALEGRAY); - lim = pixmap->width/2; - for(j=0;j<pixmap->height;j++) - { - int mod = j%2; - - for(z=0;z<lim;z++) - dw_draw_point(0, disabled, (z*2)+mod, j); - } - _foreground = fore; + disabled = _create_disabled(tmp, pixmap); } } @@ -7276,6 +7268,72 @@ return 1; } +/* Internal function to change the button bitmap */ +void _dw_window_set_bitmap(HWND handle, HBITMAP hbm, HDC hdc, HPS hps, unsigned long width, unsigned long height, int depth, HPOINTER icon) +{ + char tmpbuf[100] = {0}; + + WinQueryClassName(handle, 99, (PCH)tmpbuf); + + /* Button */ + if(strncmp(tmpbuf, "#3", 3)==0) + { + WNDPARAMS wp = {0}; + BTNCDATA bcd = {0}; + RECTL rect; + + wp.fsStatus = WPM_CTLDATA; + wp.pCtlData = &bcd; + wp.cbCtlData = bcd.cb = sizeof(BTNCDATA); + + /* Clear any existing icon */ + WinSendMsg(handle, WM_SETWINDOWPARAMS, (MPARAM)&wp, NULL); + + if(icon) + { + dw_window_set_data(handle, "_dw_button_icon", DW_POINTER(icon)); + } + else + { + HPIXMAP pixmap = (HPIXMAP)dw_window_get_data(handle, "_dw_hpixmap"); + HPIXMAP disabled = (HPIXMAP)dw_window_get_data(handle, "_dw_hpixmap_disabled"); + + if(pixmap) + dw_pixmap_destroy(pixmap); + if(disabled) + dw_pixmap_destroy(disabled); + + pixmap = calloc(1,sizeof(struct _hpixmap)); + pixmap->hbm = hbm; + pixmap->hdc = hdc; + pixmap->hps = hps; + pixmap->width = width; + pixmap->height = height; + disabled = _create_disabled(handle, pixmap); + + dw_window_set_data(handle, "_dw_hpixmap", DW_POINTER(pixmap)); + dw_window_set_data(handle, "_dw_hpixmap_disabled", DW_POINTER(disabled)); + } + dw_window_set_data(handle, "_dw_bitmapbutton", DW_POINTER(1)); + /* Make sure we invalidate the button so it redraws */ + WinQueryWindowRect(handle, &rect); + WinInvalidateRect(handle, &rect, TRUE); + } + + /* If we changed the bitmap... */ + { + Item *item = _box_item(handle); + + /* Check to see if any of the sizes need to be recalculated */ + if(item && (item->origwidth == -1 || item->origheight == -1)) + { + _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); + /* Queue a redraw on the top-level window */ + _dw_redraw(_toplevel_window(handle), TRUE); + } + } +} + /* * Sets the bitmap used for a given static window. * Parameters: @@ -7288,8 +7346,12 @@ */ void API dw_window_set_bitmap(HWND handle, unsigned long id, char *filename) { - HBITMAP hbm; - HPS hps; + HBITMAP hbm = 0; + HPS hps = 0; + HDC hdc = 0; + HPOINTER icon = 0; + unsigned long width = 0, height = 0; + int depth = 0; /* Destroy any old bitmap data */ _free_bitmap(handle); @@ -7299,13 +7361,11 @@ { hps = WinGetPS( handle ); hbm = GpiLoadBitmap( hps, NULLHANDLE, id, 0, 0 ); + WinReleasePS(hps); } else if ( filename ) { - HDC hdc = 0; - unsigned long width, height; char *file = alloca(strlen(filename) + 6); - int depth; if(!file) return; @@ -7315,22 +7375,38 @@ /* check if we can read from this file (it exists and read permission) */ if(access(file, 04) != 0) { - int z; - - /* Try with supported extensions */ - for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) - { - strcpy(file, filename); - strcat(file, image_exts[z]); - if(access(file, 04) == 0 && - _load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth)) - break; - } + /* Try with .ico extension first...*/ + strcat(file, ".ico"); + if(access(file, 04) == 0) + icon = WinLoadFileIcon((PSZ)file, FALSE); + else + { + int z; + + /* Try with supported extensions */ + for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) + { + strcpy(file, filename); + strcat(file, image_exts[z]); + if(access(file, 04) == 0 && + _load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth)) + break; + } + } } else - _load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth); - - if(!hdc) + { + int len = strlen( file ); + if(len > 4) + { + if(stricmp(file + len - 4, ".ico") == 0) + icon = WinLoadFileIcon((PSZ)file, FALSE); + else + _load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth); + } + } + + if(!hdc && !icon) return; dw_window_set_data(handle, "_dw_hps", (void *)hps); @@ -7341,22 +7417,9 @@ else return; - if ( id ) - WinReleasePS(hps); dw_window_set_data(handle, "_dw_bitmap", (void *)hbm); - - /* If we changed the bitmap... */ - { - Item *item = _box_item(handle); - - /* Check to see if any of the sizes need to be recalculated */ - if(item && (item->origwidth == -1 || item->origheight == -1)) - { - _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); - /* Queue a redraw on the top-level window */ - _dw_redraw(_toplevel_window(handle), TRUE); - } - } + + _dw_window_set_bitmap(handle, hbm, hdc, hps, width, height, depth, icon); } /* @@ -7417,13 +7480,14 @@ { hps = WinGetPS( handle ); hbm = GpiLoadBitmap( hps, NULLHANDLE, id, 0, 0 ); + WinReleasePS(hps); } else return; - if ( id ) - WinReleasePS(hps); dw_window_set_data(handle, "_dw_bitmap", (void *)hbm); + + _dw_window_set_bitmap(handle, hbm, hdc, hps, width, height, depth, 0); } /*