Mercurial > dwindows
comparison os2/dw.c @ 1697:f5b187156cc0
Added image extension list for OS/2 for use when using GBM.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 03 May 2012 04:04:30 +0000 |
parents | c01961b48c40 |
children | e31c7e389b2f |
comparison
equal
deleted
inserted
replaced
1696:c01961b48c40 | 1697:f5b187156cc0 |
---|---|
80 int (API_FUNC _gbm_io_open)(const char *fn, int mode) = 0; | 80 int (API_FUNC _gbm_io_open)(const char *fn, int mode) = 0; |
81 int (API_FUNC _gbm_io_close)(int fd) = 0; | 81 int (API_FUNC _gbm_io_close)(int fd) = 0; |
82 int (API_FUNC _gbm_read_header)(const char *fn, int fd, int ft, GBM *gbm, const char *info) = 0; | 82 int (API_FUNC _gbm_read_header)(const char *fn, int fd, int ft, GBM *gbm, const char *info) = 0; |
83 int (API_FUNC _gbm_read_palette)(int fd, int ft, GBM *gbm, GBMRGB *gbmrgb) = 0; | 83 int (API_FUNC _gbm_read_palette)(int fd, int ft, GBM *gbm, GBMRGB *gbmrgb) = 0; |
84 int (API_FUNC _gbm_read_data)(int fd, int ft, GBM *gbm, unsigned char *data) = 0; | 84 int (API_FUNC _gbm_read_data)(int fd, int ft, GBM *gbm, unsigned char *data) = 0; |
85 | |
86 /* | |
87 * List those icons that have transparency first | |
88 * GDI+ List of supported formats: BMP, ICON, GIF, JPEG, Exif, PNG, TIFF, WMF, and EMF. | |
89 * Not sure if we should include all these or not... maybe we should add TIFF and GIF? | |
90 */ | |
91 #define NUM_EXTS 8 | |
92 char *image_exts[NUM_EXTS] = | |
93 { | |
94 ".bmp", | |
95 ".png", | |
96 ".jpg", | |
97 ".jpeg", | |
98 ".tga", | |
99 ".tif", | |
100 ".tiff", | |
101 ".xpm" | |
102 }; | |
103 | |
85 | 104 |
86 char ClassName[] = "dynamicwindows"; | 105 char ClassName[] = "dynamicwindows"; |
87 char SplitbarClassName[] = "dwsplitbar"; | 106 char SplitbarClassName[] = "dwsplitbar"; |
88 char ScrollClassName[] = "dwscroll"; | 107 char ScrollClassName[] = "dwscroll"; |
89 char CalendarClassName[] = "dwcalendar"; | 108 char CalendarClassName[] = "dwcalendar"; |
4780 /* Bitmap/Static */ | 4799 /* Bitmap/Static */ |
4781 else if(strncmp(tmpbuf, "#5", 3)==0) | 4800 else if(strncmp(tmpbuf, "#5", 3)==0) |
4782 { | 4801 { |
4783 HBITMAP hbm = (HBITMAP)WinSendMsg(handle, SM_QUERYHANDLE, MPVOID, MPVOID); | 4802 HBITMAP hbm = (HBITMAP)WinSendMsg(handle, SM_QUERYHANDLE, MPVOID, MPVOID); |
4784 | 4803 |
4804 /* If we got a bitmap handle */ | |
4785 if(hbm) | 4805 if(hbm) |
4786 { | 4806 { |
4787 BITMAPINFOHEADER2 bmp; | 4807 BITMAPINFOHEADER2 bmp; |
4788 bmp.cbFix = sizeof(BITMAPINFOHEADER2); | 4808 bmp.cbFix = sizeof(BITMAPINFOHEADER2); |
4789 /* Get the parameters of the bitmap */ | 4809 /* Get the parameters of the bitmap */ |
6333 NULLHANDLE, | 6353 NULLHANDLE, |
6334 HWND_TOP, | 6354 HWND_TOP, |
6335 id, | 6355 id, |
6336 NULL, | 6356 NULL, |
6337 NULL); | 6357 NULL); |
6338 char *file = alloca(strlen(filename) + 5); | 6358 char *file = alloca(strlen(filename) + 6); |
6339 HPIXMAP pixmap = NULL, disabled = NULL; | 6359 HPIXMAP pixmap = NULL, disabled = NULL; |
6340 HPOINTER icon = 0; | 6360 HPOINTER icon = 0; |
6341 | 6361 |
6342 if(file && (pixmap = calloc(1,sizeof(struct _hpixmap)))) | 6362 if(file && (pixmap = calloc(1,sizeof(struct _hpixmap)))) |
6343 { | 6363 { |
6364 strcat(file, ".ico"); | 6384 strcat(file, ".ico"); |
6365 if(access(file, 04) == 0) | 6385 if(access(file, 04) == 0) |
6366 icon = WinLoadFileIcon((PSZ)file, FALSE); | 6386 icon = WinLoadFileIcon((PSZ)file, FALSE); |
6367 else | 6387 else |
6368 { | 6388 { |
6369 strcpy(file, filename); | 6389 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) |
6370 strcat(file, ".bmp"); | 6390 { |
6371 if(access(file, 04) == 0) | 6391 strcpy(file, filename); |
6372 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height); | 6392 strcat(file, image_exts[z]); |
6393 if(access(file, 04) == 0 && | |
6394 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height)) | |
6395 break; | |
6396 } | |
6373 } | 6397 } |
6374 } | 6398 } |
6375 | 6399 |
6376 if(icon) | 6400 if(icon) |
6377 { | 6401 { |
6453 fp = fopen( file, "wb" ); | 6477 fp = fopen( file, "wb" ); |
6454 if ( fp != NULL ) | 6478 if ( fp != NULL ) |
6455 { | 6479 { |
6456 fwrite( data, 1, len, fp ); | 6480 fwrite( data, 1, len, fp ); |
6457 fclose( fp ); | 6481 fclose( fp ); |
6458 if ( len > 1 && data[0] == 'B' && data[1] == 'M' ) /* first 2 chars of data is BM, then its a BMP */ | 6482 if(!_load_bitmap_file( file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height)); |
6459 { | |
6460 _load_bitmap_file( file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height ); | |
6461 } | |
6462 else /* otherwise its assumed to be an ico */ | |
6463 { | 6483 { |
6464 icon = WinLoadFileIcon((PSZ)file, FALSE); | 6484 icon = WinLoadFileIcon((PSZ)file, FALSE); |
6465 } | 6485 } |
6466 } | 6486 } |
6467 else | 6487 else |
6926 } | 6946 } |
6927 else if ( filename ) | 6947 else if ( filename ) |
6928 { | 6948 { |
6929 HDC hdc; | 6949 HDC hdc; |
6930 unsigned long width, height; | 6950 unsigned long width, height; |
6931 char *file = alloca(strlen(filename) + 5); | 6951 char *file = alloca(strlen(filename) + 6); |
6932 | 6952 |
6933 if(!file) | 6953 if(!file) |
6934 return; | 6954 return; |
6935 | 6955 |
6936 strcpy(file, filename); | 6956 strcpy(file, filename); |
6937 | 6957 |
6938 /* check if we can read from this file (it exists and read permission) */ | 6958 /* check if we can read from this file (it exists and read permission) */ |
6939 if(access(file, 04) != 0) | 6959 if(access(file, 04) != 0) |
6940 { | 6960 { |
6941 /* Try with .bmp extention */ | 6961 int z; |
6942 strcat(file, ".bmp"); | 6962 |
6943 if(access(file, 04) != 0) | 6963 /* Try with supported extensions */ |
6944 return; | 6964 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) |
6965 { | |
6966 strcpy(file, filename); | |
6967 strcat(file, image_exts[z]); | |
6968 if(access(file, 04) == 0) | |
6969 break; | |
6970 } | |
6945 } | 6971 } |
6946 | 6972 |
6947 if(!_load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height)) | 6973 if(!_load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height)) |
6948 return; | 6974 return; |
6949 | 6975 |
7011 fp = fopen( file, "wb" ); | 7037 fp = fopen( file, "wb" ); |
7012 if ( fp != NULL ) | 7038 if ( fp != NULL ) |
7013 { | 7039 { |
7014 fwrite( data, 1, len, fp ); | 7040 fwrite( data, 1, len, fp ); |
7015 fclose( fp ); | 7041 fclose( fp ); |
7016 if ( len > 1 && data[0] == 'B' && data[1] == 'M' ) /* first 2 chars of data is BM, then its a BMP */ | 7042 if(!_load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height)) |
7017 _load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height); | |
7018 else /* otherwise its assumed to be an ico */ | |
7019 { | 7043 { |
7020 /* con't use ICO ? */ | 7044 /* can't use ICO ? */ |
7021 unlink( file ); | 7045 unlink( file ); |
7022 return; | 7046 return; |
7023 } | 7047 } |
7024 } | 7048 } |
7025 else | 7049 else |
10378 strcpy(file, filename); | 10402 strcpy(file, filename); |
10379 | 10403 |
10380 /* check if we can read from this file (it exists and read permission) */ | 10404 /* check if we can read from this file (it exists and read permission) */ |
10381 if ( access(file, 04) != 0 ) | 10405 if ( access(file, 04) != 0 ) |
10382 { | 10406 { |
10383 /* Try with .bmp extention */ | 10407 int z; |
10384 strcat(file, ".bmp"); | 10408 |
10385 if ( access(file, 04) != 0 ) | 10409 /* Try with supported extensions */ |
10386 { | 10410 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) |
10387 free(pixmap); | 10411 { |
10388 return NULL; | 10412 strcpy(file, filename); |
10389 } | 10413 strcat(file, image_exts[z]); |
10414 if(access(file, 04) == 0) | |
10415 break; | |
10416 } | |
10390 } | 10417 } |
10391 | 10418 |
10392 /* Try to load the bitmap from file */ | 10419 /* Try to load the bitmap from file */ |
10393 if ( !_load_bitmap_file(file, handle, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height) ) | 10420 if ( !_load_bitmap_file(file, handle, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height) ) |
10394 { | 10421 { |
10428 fp = fopen( file, "wb" ); | 10455 fp = fopen( file, "wb" ); |
10429 if ( fp != NULL ) | 10456 if ( fp != NULL ) |
10430 { | 10457 { |
10431 fwrite( data, 1, len, fp ); | 10458 fwrite( data, 1, len, fp ); |
10432 fclose( fp ); | 10459 fclose( fp ); |
10433 if ( len > 1 && data[0] == 'B' && data[1] == 'M' ) /* first 2 chars of data is BM, then its a BMP */ | 10460 if(!_load_bitmap_file(file, handle, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height)) |
10434 { | 10461 { |
10435 /* Try to load the bitmap from file */ | 10462 /* can't use ICO ? */ |
10436 if ( !_load_bitmap_file(file, handle, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height) ) | |
10437 { | |
10438 free(pixmap); | |
10439 return NULL; | |
10440 } | |
10441 } | |
10442 else /* otherwise its assumed to be an ico */ | |
10443 { | |
10444 /* con't use ICO ? */ | |
10445 unlink( file ); | 10463 unlink( file ); |
10446 return NULL; | 10464 return NULL; |
10447 } | 10465 } |
10448 } | 10466 } |
10449 else | 10467 else |
11349 * None. | 11367 * None. |
11350 * Returns: | 11368 * Returns: |
11351 * Pointer to an allocated string of text or NULL if clipboard empty or contents could not | 11369 * Pointer to an allocated string of text or NULL if clipboard empty or contents could not |
11352 * be converted to text. | 11370 * be converted to text. |
11353 */ | 11371 */ |
11354 char *dw_clipboard_get_text() | 11372 char * API dw_clipboard_get_text(void) |
11355 { | 11373 { |
11356 APIRET rc; | 11374 APIRET rc; |
11357 char *retbuf = NULL; | 11375 char *retbuf = NULL; |
11358 ULONG fmtInfo; | 11376 ULONG fmtInfo; |
11359 | 11377 |
11372 /* | 11390 /* |
11373 * Sets the contents of the default clipboard to the supplied text. | 11391 * Sets the contents of the default clipboard to the supplied text. |
11374 * Parameters: | 11392 * Parameters: |
11375 * Text. | 11393 * Text. |
11376 */ | 11394 */ |
11377 void dw_clipboard_set_text( char *str, int len ) | 11395 void API dw_clipboard_set_text( char *str, int len ) |
11378 { | 11396 { |
11379 APIRET rc; | 11397 APIRET rc; |
11380 static PVOID shared; | 11398 static PVOID shared; |
11381 | 11399 |
11382 WinOpenClipbrd(dwhab); /* Open clipboard */ | 11400 WinOpenClipbrd(dwhab); /* Open clipboard */ |