Mercurial > dwindows
comparison os2/dw.c @ 1700:4487f6bc9e8b
Initial attempt at creating icons from other formats on OS/2.
Doesn't work yet, and won't initally support transparency.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 03 May 2012 12:18:25 +0000 |
parents | df7ca5c4fa5b |
children | 1b10b4534bc4 |
comparison
equal
deleted
inserted
replaced
1699:df7ca5c4fa5b | 1700:4487f6bc9e8b |
---|---|
58 MRESULT EXPENTRY _run_event(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); | 58 MRESULT EXPENTRY _run_event(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); |
59 MRESULT EXPENTRY _wndproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); | 59 MRESULT EXPENTRY _wndproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); |
60 MRESULT EXPENTRY _scrollwndproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); | 60 MRESULT EXPENTRY _scrollwndproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); |
61 void _do_resize(Box *thisbox, int x, int y); | 61 void _do_resize(Box *thisbox, int x, int y); |
62 void _handle_splitbar_resize(HWND hwnd, float percent, int type, int x, int y); | 62 void _handle_splitbar_resize(HWND hwnd, float percent, int type, int x, int y); |
63 int _load_bitmap_file(char *file, HWND handle, HBITMAP *hbm, HDC *hdc, HPS *hps, unsigned long *width, unsigned long *height); | 63 int _load_bitmap_file(char *file, HWND handle, HBITMAP *hbm, HDC *hdc, HPS *hps, unsigned long *width, unsigned long *height, int *depth); |
64 void _free_menu_data(HWND menu); | 64 void _free_menu_data(HWND menu); |
65 BOOL (API_FUNC _WinQueryDesktopWorkArea)(HWND hwndDesktop, PWRECT pwrcWorkArea) = 0; | 65 BOOL (API_FUNC _WinQueryDesktopWorkArea)(HWND hwndDesktop, PWRECT pwrcWorkArea) = 0; |
66 /* PMPrintf support for dw_debug() */ | 66 /* PMPrintf support for dw_debug() */ |
67 ULONG (API_FUNC _PmPrintfString)(char *String) = 0; | 67 ULONG (API_FUNC _PmPrintfString)(char *String) = 0; |
68 /* GBM (Generalize Bitmap Module) support for file loading */ | 68 /* GBM (Generalize Bitmap Module) support for file loading */ |
5070 if(dw_window_get_data(handle, "_dw_bitmapbutton")) | 5070 if(dw_window_get_data(handle, "_dw_bitmapbutton")) |
5071 { | 5071 { |
5072 HPOINTER hpr = (HPOINTER)dw_window_get_data(handle, "_dw_button_icon"); | 5072 HPOINTER hpr = (HPOINTER)dw_window_get_data(handle, "_dw_button_icon"); |
5073 HBITMAP hbm = 0; | 5073 HBITMAP hbm = 0; |
5074 int iconwidth = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_button_icon_width")); | 5074 int iconwidth = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_button_icon_width")); |
5075 HPIXMAP pixmap = (HPIXMAP)dw_window_get_data(handle, "_dw_hpixmap"); | |
5075 | 5076 |
5076 /* Handle case of icon resource */ | 5077 /* Handle case of icon resource */ |
5077 if(hpr) | 5078 if(hpr) |
5078 { | 5079 { |
5079 if(iconwidth) | 5080 if(iconwidth) |
5084 | 5085 |
5085 /* Get the internal HBITMAP handles */ | 5086 /* Get the internal HBITMAP handles */ |
5086 if(WinQueryPointerInfo(hpr, &pi)) | 5087 if(WinQueryPointerInfo(hpr, &pi)) |
5087 hbm = pi.hbmColor ? pi.hbmColor : pi.hbmPointer; | 5088 hbm = pi.hbmColor ? pi.hbmColor : pi.hbmPointer; |
5088 } | 5089 } |
5090 } | |
5091 /* Handle case of pixmap resource */ | |
5092 else if(pixmap) | |
5093 { | |
5094 thiswidth = pixmap->width; | |
5095 thisheight = pixmap->height; | |
5089 } | 5096 } |
5090 | 5097 |
5091 /* If we didn't load it from the icon... */ | 5098 /* If we didn't load it from the icon... */ |
5092 if(!hbm && !iconwidth) | 5099 if(!hbm && !iconwidth) |
5093 { | 5100 { |
6372 if(len > 4) | 6379 if(len > 4) |
6373 { | 6380 { |
6374 if(stricmp(file + len - 4, ".ico") == 0) | 6381 if(stricmp(file + len - 4, ".ico") == 0) |
6375 icon = WinLoadFileIcon((PSZ)file, FALSE); | 6382 icon = WinLoadFileIcon((PSZ)file, FALSE); |
6376 else | 6383 else |
6377 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height); | 6384 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height, &pixmap->depth); |
6378 } | 6385 } |
6379 } | 6386 } |
6380 else | 6387 else |
6381 { | 6388 { |
6382 /* Try with .ico extension first...*/ | 6389 /* Try with .ico extension first...*/ |
6388 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) | 6395 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) |
6389 { | 6396 { |
6390 strcpy(file, filename); | 6397 strcpy(file, filename); |
6391 strcat(file, image_exts[z]); | 6398 strcat(file, image_exts[z]); |
6392 if(access(file, 04) == 0 && | 6399 if(access(file, 04) == 0 && |
6393 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height)) | 6400 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height, &pixmap->depth)) |
6394 break; | 6401 break; |
6395 } | 6402 } |
6396 } | 6403 } |
6397 } | 6404 } |
6398 | 6405 |
6476 fp = fopen( file, "wb" ); | 6483 fp = fopen( file, "wb" ); |
6477 if ( fp != NULL ) | 6484 if ( fp != NULL ) |
6478 { | 6485 { |
6479 fwrite( data, 1, len, fp ); | 6486 fwrite( data, 1, len, fp ); |
6480 fclose( fp ); | 6487 fclose( fp ); |
6481 if(!_load_bitmap_file( file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height)); | 6488 if(!_load_bitmap_file( file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height, &pixmap->depth)); |
6482 { | 6489 { |
6483 icon = WinLoadFileIcon((PSZ)file, FALSE); | 6490 icon = WinLoadFileIcon((PSZ)file, FALSE); |
6484 } | 6491 } |
6485 } | 6492 } |
6486 else | 6493 else |
6740 } | 6747 } |
6741 | 6748 |
6742 /* Internal function to load a bitmap from a file and return handles | 6749 /* Internal function to load a bitmap from a file and return handles |
6743 * to the bitmap, presentation space etc. | 6750 * to the bitmap, presentation space etc. |
6744 */ | 6751 */ |
6745 int _load_bitmap_file(char *file, HWND handle, HBITMAP *hbm, HDC *hdc, HPS *hps, unsigned long *width, unsigned long *height) | 6752 int _load_bitmap_file(char *file, HWND handle, HBITMAP *hbm, HDC *hdc, HPS *hps, unsigned long *width, unsigned long *height, int *depth) |
6746 { | 6753 { |
6747 PBITMAPINFOHEADER2 pBitmapInfoHeader; | 6754 PBITMAPINFOHEADER2 pBitmapInfoHeader; |
6748 /* pointer to the first byte of bitmap data */ | 6755 /* pointer to the first byte of bitmap data */ |
6749 PBYTE BitmapFileBegin, BitmapBits; | 6756 PBYTE BitmapFileBegin, BitmapBits; |
6750 ULONG ulFlags; | 6757 ULONG ulFlags; |
6802 gbmrgb = NULL; | 6809 gbmrgb = NULL; |
6803 | 6810 |
6804 /* Save the dimension for return */ | 6811 /* Save the dimension for return */ |
6805 *width = gbm.w; | 6812 *width = gbm.w; |
6806 *height = gbm.h; | 6813 *height = gbm.h; |
6814 *depth = gbm.bpp; | |
6807 byteswidth = (((gbm.w*gbm.bpp + 31)/32)*4); | 6815 byteswidth = (((gbm.w*gbm.bpp + 31)/32)*4); |
6808 | 6816 |
6809 /* Allocate a buffer to store the image */ | 6817 /* Allocate a buffer to store the image */ |
6810 DosAllocMem((PPVOID)&BitmapFileBegin, (ULONG)byteswidth * gbm.h, | 6818 DosAllocMem((PPVOID)&BitmapFileBegin, (ULONG)byteswidth * gbm.h, |
6811 PAG_READ | PAG_WRITE | PAG_COMMIT); | 6819 PAG_READ | PAG_WRITE | PAG_COMMIT); |
6893 /* and query number of lines */ | 6901 /* and query number of lines */ |
6894 if(pBitmapInfoHeader->cbFix == sizeof(BITMAPINFOHEADER)) | 6902 if(pBitmapInfoHeader->cbFix == sizeof(BITMAPINFOHEADER)) |
6895 { | 6903 { |
6896 *height = (ULONG)((PBITMAPINFOHEADER)pBitmapInfoHeader)->cy; | 6904 *height = (ULONG)((PBITMAPINFOHEADER)pBitmapInfoHeader)->cy; |
6897 *width = (ULONG)((PBITMAPINFOHEADER)pBitmapInfoHeader)->cx; | 6905 *width = (ULONG)((PBITMAPINFOHEADER)pBitmapInfoHeader)->cx; |
6906 *depth = (int)((PBITMAPINFOHEADER)pBitmapInfoHeader)->cBitCount; | |
6898 } | 6907 } |
6899 else | 6908 else |
6900 { | 6909 { |
6901 *height = pBitmapInfoHeader->cy; | 6910 *height = pBitmapInfoHeader->cy; |
6902 *width = pBitmapInfoHeader->cx; | 6911 *width = pBitmapInfoHeader->cx; |
6912 *depth = pBitmapInfoHeader->cBitCount; | |
6903 } | 6913 } |
6904 | 6914 |
6905 /* Put the bitmap bits into the destination */ | 6915 /* Put the bitmap bits into the destination */ |
6906 BitmapBits = BitmapFileBegin + pBitmapFileHeader->offBits; | 6916 BitmapBits = BitmapFileBegin + pBitmapFileHeader->offBits; |
6907 | 6917 |
6964 else if ( filename ) | 6974 else if ( filename ) |
6965 { | 6975 { |
6966 HDC hdc = 0; | 6976 HDC hdc = 0; |
6967 unsigned long width, height; | 6977 unsigned long width, height; |
6968 char *file = alloca(strlen(filename) + 6); | 6978 char *file = alloca(strlen(filename) + 6); |
6979 int depth; | |
6969 | 6980 |
6970 if(!file) | 6981 if(!file) |
6971 return; | 6982 return; |
6972 | 6983 |
6973 strcpy(file, filename); | 6984 strcpy(file, filename); |
6981 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) | 6992 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) |
6982 { | 6993 { |
6983 strcpy(file, filename); | 6994 strcpy(file, filename); |
6984 strcat(file, image_exts[z]); | 6995 strcat(file, image_exts[z]); |
6985 if(access(file, 04) == 0 && | 6996 if(access(file, 04) == 0 && |
6986 _load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height)) | 6997 _load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth)) |
6987 break; | 6998 break; |
6988 } | 6999 } |
6989 } | 7000 } |
6990 | 7001 |
6991 if(!hdc) | 7002 if(!hdc) |
7035 HPS hps; | 7046 HPS hps; |
7036 HDC hdc; | 7047 HDC hdc; |
7037 unsigned long width, height; | 7048 unsigned long width, height; |
7038 char *file; | 7049 char *file; |
7039 FILE *fp; | 7050 FILE *fp; |
7051 int depth; | |
7040 | 7052 |
7041 /* Destroy any old bitmap data */ | 7053 /* Destroy any old bitmap data */ |
7042 _free_bitmap(handle); | 7054 _free_bitmap(handle); |
7043 | 7055 |
7044 /* If id is non-zero use the resource */ | 7056 /* If id is non-zero use the resource */ |
7055 fp = fopen( file, "wb" ); | 7067 fp = fopen( file, "wb" ); |
7056 if ( fp != NULL ) | 7068 if ( fp != NULL ) |
7057 { | 7069 { |
7058 fwrite( data, 1, len, fp ); | 7070 fwrite( data, 1, len, fp ); |
7059 fclose( fp ); | 7071 fclose( fp ); |
7060 if(!_load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height)) | 7072 if(!_load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth)) |
7061 { | 7073 { |
7062 /* can't use ICO ? */ | 7074 /* can't use ICO ? */ |
7063 unlink( file ); | 7075 unlink( file ); |
7064 return; | 7076 return; |
7065 } | 7077 } |
8892 HICN API dw_icon_load(unsigned long module, unsigned long id) | 8904 HICN API dw_icon_load(unsigned long module, unsigned long id) |
8893 { | 8905 { |
8894 return WinLoadPointer(HWND_DESKTOP,module,id); | 8906 return WinLoadPointer(HWND_DESKTOP,module,id); |
8895 } | 8907 } |
8896 | 8908 |
8909 /* Internal function to create an icon from an existing pixmap */ | |
8910 HICN _create_icon(char *file, HPIXMAP src) | |
8911 { | |
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, 1); | |
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, 1); | |
8916 ULONG oldcol = _foreground; | |
8917 POINTERINFO pi = {0}; | |
8918 | |
8919 /* Create the color pointers, stretching it to the necessary size */ | |
8920 dw_pixmap_stretch_bitblt(0, pntr, 0, 0, pntr->width, pntr->height, 0, src, 0, 0, src->width, src->height); | |
8921 dw_pixmap_stretch_bitblt(0, minipntr, 0, 0, minipntr->width, minipntr->height, 0, src, 0, 0, src->width, src->height); | |
8922 | |
8923 /* Create the masks, all in black */ | |
8924 dw_color_foreground_set(DW_CLR_BLACK); | |
8925 dw_draw_rect(0, mask, DW_DRAW_FILL, 0, 0, mask->width, mask->height); | |
8926 dw_draw_rect(0, minimask, DW_DRAW_FILL, 0, 0, minimask->width, minimask->height); | |
8927 _foreground = oldcol; | |
8928 | |
8929 /* Assemble the Pointer Info structure */ | |
8930 pi.hbmPointer = mask->hbm; | |
8931 pi.hbmColor = pntr->hbm; | |
8932 pi.hbmMiniPointer = minimask->hbm; | |
8933 pi.hbmMiniColor = minipntr->hbm; | |
8934 | |
8935 /* Destroy the pixmaps but not the bitmaps */ | |
8936 mask->hbm = pntr->hbm = minimask->hbm = minipntr->hbm = 0; | |
8937 dw_pixmap_destroy(mask); | |
8938 dw_pixmap_destroy(pntr); | |
8939 dw_pixmap_destroy(minimask); | |
8940 dw_pixmap_destroy(minipntr); | |
8941 | |
8942 /* Generate the icon */ | |
8943 return WinCreatePointerIndirect(HWND_DESKTOP, &pi); | |
8944 } | |
8945 | |
8897 /* | 8946 /* |
8898 * Obtains an icon from a file. | 8947 * Obtains an icon from a file. |
8899 * Parameters: | 8948 * Parameters: |
8900 * filename: Name of the file, omit extention to have | 8949 * filename: Name of the file, omit extention to have |
8901 * DW pick the appropriate file extension. | 8950 * DW pick the appropriate file extension. |
8902 * (ICO on OS/2 or Windows, XPM on Unix) | 8951 * (ICO on OS/2 or Windows, XPM on Unix) |
8903 */ | 8952 */ |
8904 HICN API dw_icon_load_from_file(char *filename) | 8953 HICN API dw_icon_load_from_file(char *filename) |
8905 { | 8954 { |
8906 char *file = alloca(strlen(filename) + 5); | 8955 char *file = alloca(strlen(filename) + 6); |
8907 | 8956 HPIXMAP src = alloca(sizeof(struct _hpixmap)); |
8908 if(!file) | 8957 |
8958 if(!file || !src) | |
8909 return 0; | 8959 return 0; |
8910 | 8960 |
8911 strcpy(file, filename); | 8961 strcpy(file, filename); |
8912 | 8962 |
8913 /* check if we can read from this file (it exists and read permission) */ | 8963 /* check if we can read from this file (it exists and read permission) */ |
8914 if(access(file, 04) != 0) | 8964 if(access(file, 04) != 0) |
8915 { | 8965 { |
8916 /* Try with .bmp extention */ | 8966 int z; |
8917 strcat(file, ".ico"); | 8967 |
8918 if(access(file, 04) != 0) | 8968 /* Try with .ico extention */ |
8919 return 0; | 8969 strcat(file, ".ico"); |
8920 } | 8970 if(access(file, 04) == 0) |
8971 return WinLoadFileIcon((PSZ)file, FALSE); | |
8972 | |
8973 /* Try with supported extensions */ | |
8974 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) | |
8975 { | |
8976 strcpy(file, filename); | |
8977 strcat(file, image_exts[z]); | |
8978 if(access(file, 04) == 0 && | |
8979 _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 return 0; | |
8983 } | |
8984 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); | |
8986 /* Otherwise fall back to the classic method */ | |
8921 return WinLoadFileIcon((PSZ)file, FALSE); | 8987 return WinLoadFileIcon((PSZ)file, FALSE); |
8922 } | 8988 } |
8923 | 8989 |
8924 /* | 8990 /* |
8925 * Obtains an icon from data | 8991 * Obtains an icon from data |
8942 fp = fopen( file, "wb" ); | 9008 fp = fopen( file, "wb" ); |
8943 if ( fp != NULL ) | 9009 if ( fp != NULL ) |
8944 { | 9010 { |
8945 fwrite( data, 1, len, fp ); | 9011 fwrite( data, 1, len, fp ); |
8946 fclose( fp ); | 9012 fclose( fp ); |
8947 icon = WinLoadFileIcon( (PSZ)file, FALSE ); | 9013 icon = dw_icon_load_from_file(file); |
8948 } | |
8949 else | |
8950 { | |
8951 unlink( file ); | |
8952 return 0; | |
8953 } | 9014 } |
8954 unlink( file ); | 9015 unlink( file ); |
8955 } | 9016 } |
8956 return icon; | 9017 return icon; |
8957 } | 9018 } |
10384 bmih.cPlanes = (SHORT)cPlanes; | 10445 bmih.cPlanes = (SHORT)cPlanes; |
10385 bmih.cBitCount = (SHORT)depth; | 10446 bmih.cBitCount = (SHORT)depth; |
10386 | 10447 |
10387 pixmap->width = width; pixmap->height = height; | 10448 pixmap->width = width; pixmap->height = height; |
10388 pixmap->transcolor = DW_CLR_DEFAULT; | 10449 pixmap->transcolor = DW_CLR_DEFAULT; |
10450 pixmap->depth = depth; | |
10389 | 10451 |
10390 pixmap->hbm = GpiCreateBitmap(pixmap->hps, (PBITMAPINFOHEADER2)&bmih, 0L, NULL, NULL); | 10452 pixmap->hbm = GpiCreateBitmap(pixmap->hps, (PBITMAPINFOHEADER2)&bmih, 0L, NULL, NULL); |
10391 | 10453 |
10392 GpiSetBitmap(pixmap->hps, pixmap->hbm); | 10454 GpiSetBitmap(pixmap->hps, pixmap->hbm); |
10393 | 10455 |
10428 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) | 10490 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) |
10429 { | 10491 { |
10430 strcpy(file, filename); | 10492 strcpy(file, filename); |
10431 strcat(file, image_exts[z]); | 10493 strcat(file, image_exts[z]); |
10432 if(access(file, 04) == 0 && | 10494 if(access(file, 04) == 0 && |
10433 _load_bitmap_file(file, handle, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height)) | 10495 _load_bitmap_file(file, handle, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height, &pixmap->depth)) |
10434 break; | 10496 break; |
10435 } | 10497 } |
10436 } | 10498 } |
10437 | 10499 |
10438 /* Try to load the bitmap from file */ | 10500 /* Try to load the bitmap from file */ |
10474 fp = fopen( file, "wb" ); | 10536 fp = fopen( file, "wb" ); |
10475 if ( fp != NULL ) | 10537 if ( fp != NULL ) |
10476 { | 10538 { |
10477 fwrite( data, 1, len, fp ); | 10539 fwrite( data, 1, len, fp ); |
10478 fclose( fp ); | 10540 fclose( fp ); |
10479 if(!_load_bitmap_file(file, handle, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height)) | 10541 if(!_load_bitmap_file(file, handle, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height, &pixmap->depth)) |
10480 { | 10542 { |
10481 /* can't use ICO ? */ | 10543 /* can't use ICO ? */ |
10482 unlink( file ); | 10544 unlink( file ); |
10483 return NULL; | 10545 return NULL; |
10484 } | 10546 } |