comparison os2/dw.c @ 1703:043db6b221c2

Cleanups on the icon creation code on OS/2. Make sure any temporary resources are destroyed.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 03 May 2012 18:44:08 +0000
parents 1b10b4534bc4
children e2c5715d057d
comparison
equal deleted inserted replaced
1702:1b10b4534bc4 1703:043db6b221c2
8905 { 8905 {
8906 return WinLoadPointer(HWND_DESKTOP,module,id); 8906 return WinLoadPointer(HWND_DESKTOP,module,id);
8907 } 8907 }
8908 8908
8909 /* Internal function to create an icon from an existing pixmap */ 8909 /* Internal function to create an icon from an existing pixmap */
8910 HICN _create_icon(char *file, HPIXMAP src) 8910 HICN _create_icon(HPIXMAP src)
8911 { 8911 {
8912 HPIXMAP pntr = dw_pixmap_new(hwndApp, WinQuerySysValue(HWND_DESKTOP, SV_CXICON), WinQuerySysValue(HWND_DESKTOP, SV_CYICON), src->depth); 8912 HPIXMAP pntr = dw_pixmap_new(hwndApp, WinQuerySysValue(HWND_DESKTOP, SV_CXICON), WinQuerySysValue(HWND_DESKTOP, SV_CYICON), src->depth);
8913 HPIXMAP mask = dw_pixmap_new(hwndApp, pntr->width, pntr->height*2, 1); 8913 HPIXMAP mask = dw_pixmap_new(hwndApp, pntr->width, pntr->height*2, 1);
8914 HPIXMAP minipntr = dw_pixmap_new(hwndApp, pntr->width/2, pntr->height/2, src->depth); 8914 HPIXMAP minipntr = dw_pixmap_new(hwndApp, pntr->width/2, pntr->height/2, src->depth);
8915 HPIXMAP minimask = dw_pixmap_new(hwndApp, minipntr->width, minipntr->height*2, 1); 8915 HPIXMAP minimask = dw_pixmap_new(hwndApp, minipntr->width, minipntr->height*2, 1);
8952 */ 8952 */
8953 HICN API dw_icon_load_from_file(char *filename) 8953 HICN API dw_icon_load_from_file(char *filename)
8954 { 8954 {
8955 char *file = alloca(strlen(filename) + 6); 8955 char *file = alloca(strlen(filename) + 6);
8956 HPIXMAP src = alloca(sizeof(struct _hpixmap)); 8956 HPIXMAP src = alloca(sizeof(struct _hpixmap));
8957 HICN icon = 0;
8957 8958
8958 if(!file || !src) 8959 if(!file || !src)
8959 return 0; 8960 return 0;
8960 8961
8961 strcpy(file, filename); 8962 strcpy(file, filename);
8975 { 8976 {
8976 strcpy(file, filename); 8977 strcpy(file, filename);
8977 strcat(file, image_exts[z]); 8978 strcat(file, image_exts[z]);
8978 if(access(file, 04) == 0 && 8979 if(access(file, 04) == 0 &&
8979 _load_bitmap_file(file, hwndApp, &src->hbm, &src->hdc, &src->hps, &src->width, &src->height, &src->depth)) 8980 _load_bitmap_file(file, hwndApp, &src->hbm, &src->hdc, &src->hps, &src->width, &src->height, &src->depth))
8980 return _create_icon(file, src); 8981 {
8982 icon = _create_icon(src);
8983 break;
8984 }
8981 } 8985 }
8982 return 0;
8983 } 8986 }
8984 else if(_load_bitmap_file(file, hwndApp, &src->hbm, &src->hdc, &src->hps, &src->width, &src->height, &src->depth)) 8987 else if(_load_bitmap_file(file, hwndApp, &src->hbm, &src->hdc, &src->hps, &src->width, &src->height, &src->depth))
8985 return _create_icon(file, src); 8988 icon = _create_icon(src);
8989 /* Free temporary resources if in use */
8990 if(icon)
8991 {
8992 GpiSetBitmap(src->hps, NULLHANDLE);
8993 GpiDeleteBitmap(src->hbm);
8994 GpiAssociate(src->hps, NULLHANDLE);
8995 GpiDestroyPS(src->hps);
8996 DevCloseDC(src->hdc);
8997 }
8986 /* Otherwise fall back to the classic method */ 8998 /* Otherwise fall back to the classic method */
8987 return WinLoadFileIcon((PSZ)file, FALSE); 8999 return icon ? icon : WinLoadFileIcon((PSZ)file, FALSE);
8988 } 9000 }
8989 9001
8990 /* 9002 /*
8991 * Obtains an icon from data 9003 * Obtains an icon from data
8992 * Parameters: 9004 * Parameters: