# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1351240665 0 # Node ID 213420512084d8831cac6a0f7c250e1b0d306364 # Parent 9c77567c5b2d48197bb7a4b348919bce90c12435 Changes on OS/2 to allow dw_window_set_bitmap() to work on bitmap buttons... also rewrote and optimized some of the code. diff -r 9c77567c5b2d -r 213420512084 os2/dw.c --- 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;jheight;j++) + { + int mod = j%2; + + for(z=0;zwidth, 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;jheight;j++) - { - int mod = j%2; - - for(z=0;zwidth, 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;jheight;j++) - { - int mod = j%2; - - for(z=0;zhbm = 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); } /*