Mercurial > dwindows
comparison os2/dw.c @ 1828:e0df1916b054
Added code to query the control background color on OS/2 when
loading images so if they contain an alpha channel they get
loaded with the correct background color. If no color is set
use DW_CLR_PALEGRAY for now since that is the default.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 30 Oct 2012 13:47:59 +0000 |
parents | 04c74cd0fb35 |
children | dc343df88ad8 |
comparison
equal
deleted
inserted
replaced
1827:04c74cd0fb35 | 1828:e0df1916b054 |
---|---|
63 MRESULT EXPENTRY _run_event(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); | 63 MRESULT EXPENTRY _run_event(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); |
64 MRESULT EXPENTRY _wndproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); | 64 MRESULT EXPENTRY _wndproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); |
65 MRESULT EXPENTRY _scrollwndproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); | 65 MRESULT EXPENTRY _scrollwndproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); |
66 void _do_resize(Box *thisbox, int x, int y); | 66 void _do_resize(Box *thisbox, int x, int y); |
67 void _handle_splitbar_resize(HWND hwnd, float percent, int type, int x, int y); | 67 void _handle_splitbar_resize(HWND hwnd, float percent, int type, int x, int y); |
68 int _load_bitmap_file(char *file, HWND handle, HBITMAP *hbm, HDC *hdc, HPS *hps, unsigned long *width, unsigned long *height, int *depth); | 68 int _load_bitmap_file(char *file, HWND handle, HBITMAP *hbm, HDC *hdc, HPS *hps, unsigned long *width, unsigned long *height, int *depth, unsigned long backrgb); |
69 void _free_menu_data(HWND menu); | 69 void _free_menu_data(HWND menu); |
70 BOOL (API_FUNC _WinQueryDesktopWorkArea)(HWND hwndDesktop, PWRECT pwrcWorkArea) = 0; | 70 BOOL (API_FUNC _WinQueryDesktopWorkArea)(HWND hwndDesktop, PWRECT pwrcWorkArea) = 0; |
71 /* PMPrintf support for dw_debug() */ | 71 /* PMPrintf support for dw_debug() */ |
72 ULONG (API_FUNC _PmPrintfString)(char *String) = 0; | 72 ULONG (API_FUNC _PmPrintfString)(char *String) = 0; |
73 /* GBM (Generalize Bitmap Module) support for file loading */ | 73 /* GBM (Generalize Bitmap Module) support for file loading */ |
6726 if(len > 4) | 6726 if(len > 4) |
6727 { | 6727 { |
6728 if(stricmp(file + len - 4, ".ico") == 0) | 6728 if(stricmp(file + len - 4, ".ico") == 0) |
6729 icon = WinLoadFileIcon((PSZ)file, FALSE); | 6729 icon = WinLoadFileIcon((PSZ)file, FALSE); |
6730 else | 6730 else |
6731 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height, &pixmap->depth); | 6731 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height, &pixmap->depth, DW_CLR_DEFAULT); |
6732 } | 6732 } |
6733 } | 6733 } |
6734 else | 6734 else |
6735 { | 6735 { |
6736 /* Try with .ico extension first...*/ | 6736 /* Try with .ico extension first...*/ |
6742 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) | 6742 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) |
6743 { | 6743 { |
6744 strcpy(file, filename); | 6744 strcpy(file, filename); |
6745 strcat(file, image_exts[z]); | 6745 strcat(file, image_exts[z]); |
6746 if(access(file, 04) == 0 && | 6746 if(access(file, 04) == 0 && |
6747 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height, &pixmap->depth)) | 6747 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height, &pixmap->depth, DW_CLR_DEFAULT)) |
6748 break; | 6748 break; |
6749 } | 6749 } |
6750 } | 6750 } |
6751 } | 6751 } |
6752 | 6752 |
6814 fp = fopen( file, "wb" ); | 6814 fp = fopen( file, "wb" ); |
6815 if ( fp != NULL ) | 6815 if ( fp != NULL ) |
6816 { | 6816 { |
6817 fwrite( data, 1, len, fp ); | 6817 fwrite( data, 1, len, fp ); |
6818 fclose( fp ); | 6818 fclose( fp ); |
6819 if(!_load_bitmap_file( file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height, &pixmap->depth)) | 6819 if(!_load_bitmap_file( file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height, &pixmap->depth, DW_CLR_DEFAULT)) |
6820 { | 6820 { |
6821 icon = WinLoadFileIcon((PSZ)file, FALSE); | 6821 icon = WinLoadFileIcon((PSZ)file, FALSE); |
6822 } | 6822 } |
6823 } | 6823 } |
6824 else | 6824 else |
7071 #define GBM_O_RDONLY 0x00000004 | 7071 #define GBM_O_RDONLY 0x00000004 |
7072 | 7072 |
7073 /* Internal function to load a bitmap from a file and return handles | 7073 /* Internal function to load a bitmap from a file and return handles |
7074 * to the bitmap, presentation space etc. | 7074 * to the bitmap, presentation space etc. |
7075 */ | 7075 */ |
7076 int _load_bitmap_file(char *file, HWND handle, HBITMAP *hbm, HDC *hdc, HPS *hps, unsigned long *width, unsigned long *height, int *depth) | 7076 int _load_bitmap_file(char *file, HWND handle, HBITMAP *hbm, HDC *hdc, HPS *hps, unsigned long *width, unsigned long *height, int *depth, unsigned long backrgb) |
7077 { | 7077 { |
7078 PBITMAPINFOHEADER2 pBitmapInfoHeader; | 7078 PBITMAPINFOHEADER2 pBitmapInfoHeader; |
7079 /* pointer to the first byte of bitmap data */ | 7079 /* pointer to the first byte of bitmap data */ |
7080 PBYTE BitmapFileBegin, BitmapBits; | 7080 PBYTE BitmapFileBegin, BitmapBits; |
7081 ULONG ulFlags; | 7081 ULONG ulFlags; |
7103 /* guess the source file type from the source filename */ | 7103 /* guess the source file type from the source filename */ |
7104 _gbm_query_n_filetypes(&ft); | 7104 _gbm_query_n_filetypes(&ft); |
7105 | 7105 |
7106 for(z=0;z<ft;z++) | 7106 for(z=0;z<ft;z++) |
7107 { | 7107 { |
7108 /* Using CLR_PALEGRAY as a default alpha background... we can | |
7109 * change this to use WinQuerySysColor() later, but pale gray is | |
7110 * already hardcoded elsewhere so just continue using it here. | |
7111 */ | |
7112 char options[101] = "back_rgb=52020_52020_52020"; | |
7113 | |
7114 /* Ask the control if it has another color set */ | |
7115 if(backrgb == DW_CLR_DEFAULT && handle) | |
7116 { | |
7117 RGB rgb = {0}; | |
7118 | |
7119 if(WinQueryPresParam(handle, PP_BACKGROUNDCOLOR, PP_BACKGROUNDCOLORINDEX, NULL, sizeof(rgb), &rgb, QPF_NOINHERIT | QPF_PURERGBCOLOR | QPF_ID2COLORINDEX)) | |
7120 snprintf(options, 100, "back_rgb=%d_%d_%d", rgb.bRed * 255, rgb.bGreen * 255, rgb.bBlue * 255); | |
7121 } | |
7122 else if(backrgb & DW_RGB_COLOR) | |
7123 { | |
7124 snprintf(options, 100, "back_rgb=%d_%d_%d", (int)DW_RED_VALUE(backrgb) * 255, (int)DW_GREEN_VALUE(backrgb) * 255, (int)DW_BLUE_VALUE(backrgb) * 255); | |
7125 } | |
7126 | |
7108 /* Read the file header */ | 7127 /* Read the file header */ |
7109 if((err = _gbm_read_header(file, fd, z, &gbm, "")) == 0) | 7128 if((err = _gbm_read_header(file, fd, z, &gbm, options)) == 0) |
7110 break; | 7129 break; |
7111 } | 7130 } |
7112 | 7131 |
7113 /* If we failed to load the header */ | 7132 /* If we failed to load the header */ |
7114 if(err) | 7133 if(err) |
7388 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) | 7407 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) |
7389 { | 7408 { |
7390 strcpy(file, filename); | 7409 strcpy(file, filename); |
7391 strcat(file, image_exts[z]); | 7410 strcat(file, image_exts[z]); |
7392 if(access(file, 04) == 0 && | 7411 if(access(file, 04) == 0 && |
7393 _load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth)) | 7412 _load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth, DW_CLR_DEFAULT)) |
7394 break; | 7413 break; |
7395 } | 7414 } |
7396 } | 7415 } |
7397 } | 7416 } |
7398 else | 7417 else |
7401 if(len > 4) | 7420 if(len > 4) |
7402 { | 7421 { |
7403 if(stricmp(file + len - 4, ".ico") == 0) | 7422 if(stricmp(file + len - 4, ".ico") == 0) |
7404 icon = WinLoadFileIcon((PSZ)file, FALSE); | 7423 icon = WinLoadFileIcon((PSZ)file, FALSE); |
7405 else | 7424 else |
7406 _load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth); | 7425 _load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth, DW_CLR_DEFAULT); |
7407 } | 7426 } |
7408 } | 7427 } |
7409 | 7428 |
7410 if(!hdc && !icon) | 7429 if(!hdc && !icon) |
7411 return; | 7430 return; |
7454 fp = fopen( file, "wb" ); | 7473 fp = fopen( file, "wb" ); |
7455 if ( fp != NULL ) | 7474 if ( fp != NULL ) |
7456 { | 7475 { |
7457 fwrite( data, 1, len, fp ); | 7476 fwrite( data, 1, len, fp ); |
7458 fclose( fp ); | 7477 fclose( fp ); |
7459 if(!_load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth)) | 7478 if(!_load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth, DW_CLR_DEFAULT)) |
7460 { | 7479 { |
7461 /* can't use ICO ? */ | 7480 /* can't use ICO ? */ |
7462 unlink( file ); | 7481 unlink( file ); |
7463 return; | 7482 return; |
7464 } | 7483 } |
9420 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) | 9439 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) |
9421 { | 9440 { |
9422 strcpy(file, filename); | 9441 strcpy(file, filename); |
9423 strcat(file, image_exts[z]); | 9442 strcat(file, image_exts[z]); |
9424 if(access(file, 04) == 0 && | 9443 if(access(file, 04) == 0 && |
9425 _load_bitmap_file(file, hwndApp, &src->hbm, &src->hdc, &src->hps, &src->width, &src->height, &src->depth)) | 9444 _load_bitmap_file(file, hwndApp, &src->hbm, &src->hdc, &src->hps, &src->width, &src->height, &src->depth, DW_CLR_DEFAULT)) |
9426 { | 9445 { |
9427 icon = _create_icon(src); | 9446 icon = _create_icon(src); |
9428 break; | 9447 break; |
9429 } | 9448 } |
9430 } | 9449 } |
9431 } | 9450 } |
9432 else if(_load_bitmap_file(file, hwndApp, &src->hbm, &src->hdc, &src->hps, &src->width, &src->height, &src->depth)) | 9451 else if(_load_bitmap_file(file, hwndApp, &src->hbm, &src->hdc, &src->hps, &src->width, &src->height, &src->depth, DW_CLR_DEFAULT)) |
9433 icon = _create_icon(src); | 9452 icon = _create_icon(src); |
9434 /* Free temporary resources if in use */ | 9453 /* Free temporary resources if in use */ |
9435 if(icon) | 9454 if(icon) |
9436 { | 9455 { |
9437 GpiSetBitmap(src->hps, NULLHANDLE); | 9456 GpiSetBitmap(src->hps, NULLHANDLE); |
10947 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) | 10966 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) |
10948 { | 10967 { |
10949 strcpy(file, filename); | 10968 strcpy(file, filename); |
10950 strcat(file, image_exts[z]); | 10969 strcat(file, image_exts[z]); |
10951 if(access(file, 04) == 0 && | 10970 if(access(file, 04) == 0 && |
10952 _load_bitmap_file(file, handle, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height, &pixmap->depth)) | 10971 _load_bitmap_file(file, handle, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height, &pixmap->depth, DW_CLR_DEFAULT)) |
10953 break; | 10972 break; |
10954 } | 10973 } |
10955 } | 10974 } |
10956 | 10975 |
10957 /* Try to load the bitmap from file */ | 10976 /* Try to load the bitmap from file */ |
10993 fp = fopen( file, "wb" ); | 11012 fp = fopen( file, "wb" ); |
10994 if ( fp != NULL ) | 11013 if ( fp != NULL ) |
10995 { | 11014 { |
10996 fwrite( data, 1, len, fp ); | 11015 fwrite( data, 1, len, fp ); |
10997 fclose( fp ); | 11016 fclose( fp ); |
10998 if(!_load_bitmap_file(file, handle, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height, &pixmap->depth)) | 11017 if(!_load_bitmap_file(file, handle, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height, &pixmap->depth, DW_CLR_DEFAULT)) |
10999 { | 11018 { |
11000 /* can't use ICO ? */ | 11019 /* can't use ICO ? */ |
11001 unlink( file ); | 11020 unlink( file ); |
11002 return NULL; | 11021 return NULL; |
11003 } | 11022 } |