Mercurial > dwindows
comparison os2/dw.c @ 1824:213420512084
Changes on OS/2 to allow dw_window_set_bitmap() to work on bitmap
buttons... also rewrote and optimized some of the code.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 26 Oct 2012 08:37:45 +0000 |
parents | 09a7202edb53 |
children | 04c74cd0fb35 |
comparison
equal
deleted
inserted
replaced
1823:9c77567c5b2d | 1824:213420512084 |
---|---|
6653 } | 6653 } |
6654 dw_window_set_data(tmp, "_dw_bitmapbutton", DW_INT_TO_POINTER(1)); | 6654 dw_window_set_data(tmp, "_dw_bitmapbutton", DW_INT_TO_POINTER(1)); |
6655 return tmp; | 6655 return tmp; |
6656 } | 6656 } |
6657 | 6657 |
6658 /* Internal function to create a disabled version of a pixmap */ | |
6659 HPIXMAP _create_disabled(HWND handle, HPIXMAP pixmap) | |
6660 { | |
6661 /* Create a disabled style pixmap */ | |
6662 HPIXMAP disabled = dw_pixmap_new(handle, pixmap->width, pixmap->height, dw_color_depth_get()); | |
6663 LONG fore = _foreground; | |
6664 int z, j, lim; | |
6665 | |
6666 dw_pixmap_bitblt(0, disabled, 0, 0, pixmap->width, pixmap->height, 0, pixmap, 0, 0); | |
6667 | |
6668 dw_color_foreground_set(DW_CLR_PALEGRAY); | |
6669 lim = pixmap->width/2; | |
6670 for(j=0;j<pixmap->height;j++) | |
6671 { | |
6672 int mod = j%2; | |
6673 | |
6674 for(z=0;z<lim;z++) | |
6675 dw_draw_point(0, disabled, (z*2)+mod, j); | |
6676 } | |
6677 _foreground = fore; | |
6678 return disabled; | |
6679 } | |
6680 | |
6658 /* | 6681 /* |
6659 * Create a new bitmap button window (widget) to be packed from a file. | 6682 * Create a new bitmap button window (widget) to be packed from a file. |
6660 * Parameters: | 6683 * Parameters: |
6661 * text: Bubble help text to be displayed. | 6684 * text: Bubble help text to be displayed. |
6662 * id: An ID to be used with dw_window_from_id() or 0L. | 6685 * id: An ID to be used with dw_window_from_id() or 0L. |
6682 HPIXMAP pixmap = NULL, disabled = NULL; | 6705 HPIXMAP pixmap = NULL, disabled = NULL; |
6683 HPOINTER icon = 0; | 6706 HPOINTER icon = 0; |
6684 | 6707 |
6685 if(file && (pixmap = calloc(1,sizeof(struct _hpixmap)))) | 6708 if(file && (pixmap = calloc(1,sizeof(struct _hpixmap)))) |
6686 { | 6709 { |
6687 int z, j, lim, len; | 6710 int z, len; |
6688 LONG fore; | |
6689 | 6711 |
6690 strcpy(file, filename); | 6712 strcpy(file, filename); |
6691 | 6713 |
6692 /* check if we can read from this file (it exists and read permission) */ | 6714 /* check if we can read from this file (it exists and read permission) */ |
6693 if(access(file, 04) == 0) | 6715 if(access(file, 04) == 0) |
6725 free(pixmap); | 6747 free(pixmap); |
6726 pixmap = NULL; | 6748 pixmap = NULL; |
6727 } | 6749 } |
6728 else | 6750 else |
6729 { | 6751 { |
6730 /* Create a disabled style pixmap */ | 6752 disabled = _create_disabled(tmp, pixmap); |
6731 disabled = dw_pixmap_new(tmp, pixmap->width, pixmap->height, dw_color_depth_get()); | |
6732 dw_pixmap_bitblt(0, disabled, 0, 0, pixmap->width, pixmap->height, 0, pixmap, 0, 0); | |
6733 | |
6734 fore = _foreground; | |
6735 dw_color_foreground_set(DW_CLR_PALEGRAY); | |
6736 lim = pixmap->width/2; | |
6737 for(j=0;j<pixmap->height;j++) | |
6738 { | |
6739 int mod = j%2; | |
6740 | |
6741 for(z=0;z<lim;z++) | |
6742 dw_draw_point(0, disabled, (z*2)+mod, j); | |
6743 } | |
6744 _foreground = fore; | |
6745 } | 6753 } |
6746 } | 6754 } |
6747 | 6755 |
6748 if(text) | 6756 if(text) |
6749 strncpy(blah->bubbletext, text, BUBBLE_HELP_MAX - 1); | 6757 strncpy(blah->bubbletext, text, BUBBLE_HELP_MAX - 1); |
6790 HPIXMAP pixmap = NULL, disabled = NULL; | 6798 HPIXMAP pixmap = NULL, disabled = NULL; |
6791 HPOINTER icon = 0; | 6799 HPOINTER icon = 0; |
6792 | 6800 |
6793 if((pixmap = calloc(1, sizeof(struct _hpixmap))) != NULL) | 6801 if((pixmap = calloc(1, sizeof(struct _hpixmap))) != NULL) |
6794 { | 6802 { |
6795 int z, j, lim; | |
6796 LONG fore; | |
6797 file = tmpnam( NULL ); | 6803 file = tmpnam( NULL ); |
6798 if ( file != NULL ) | 6804 if ( file != NULL ) |
6799 { | 6805 { |
6800 fp = fopen( file, "wb" ); | 6806 fp = fopen( file, "wb" ); |
6801 if ( fp != NULL ) | 6807 if ( fp != NULL ) |
6820 free(pixmap); | 6826 free(pixmap); |
6821 pixmap = NULL; | 6827 pixmap = NULL; |
6822 } | 6828 } |
6823 else | 6829 else |
6824 { | 6830 { |
6825 /* Create a disabled style pixmap */ | 6831 disabled = _create_disabled(tmp, pixmap); |
6826 disabled = dw_pixmap_new(tmp, pixmap->width, pixmap->height, dw_color_depth_get()); | |
6827 dw_pixmap_bitblt(0, disabled, 0, 0, pixmap->width, pixmap->height, 0, pixmap, 0, 0); | |
6828 | |
6829 fore = _foreground; | |
6830 dw_color_foreground_set(DW_CLR_PALEGRAY); | |
6831 lim = pixmap->width/2; | |
6832 for(j=0;j<pixmap->height;j++) | |
6833 { | |
6834 int mod = j%2; | |
6835 | |
6836 for(z=0;z<lim;z++) | |
6837 dw_draw_point(0, disabled, (z*2)+mod, j); | |
6838 } | |
6839 _foreground = fore; | |
6840 } | 6832 } |
6841 } | 6833 } |
6842 | 6834 |
6843 if(text) | 6835 if(text) |
6844 strncpy(blah->bubbletext, text, BUBBLE_HELP_MAX - 1); | 6836 strncpy(blah->bubbletext, text, BUBBLE_HELP_MAX - 1); |
7274 if(BitmapFileBegin) | 7266 if(BitmapFileBegin) |
7275 DosFreeMem(BitmapFileBegin); | 7267 DosFreeMem(BitmapFileBegin); |
7276 return 1; | 7268 return 1; |
7277 } | 7269 } |
7278 | 7270 |
7271 /* Internal function to change the button bitmap */ | |
7272 void _dw_window_set_bitmap(HWND handle, HBITMAP hbm, HDC hdc, HPS hps, unsigned long width, unsigned long height, int depth, HPOINTER icon) | |
7273 { | |
7274 char tmpbuf[100] = {0}; | |
7275 | |
7276 WinQueryClassName(handle, 99, (PCH)tmpbuf); | |
7277 | |
7278 /* Button */ | |
7279 if(strncmp(tmpbuf, "#3", 3)==0) | |
7280 { | |
7281 WNDPARAMS wp = {0}; | |
7282 BTNCDATA bcd = {0}; | |
7283 RECTL rect; | |
7284 | |
7285 wp.fsStatus = WPM_CTLDATA; | |
7286 wp.pCtlData = &bcd; | |
7287 wp.cbCtlData = bcd.cb = sizeof(BTNCDATA); | |
7288 | |
7289 /* Clear any existing icon */ | |
7290 WinSendMsg(handle, WM_SETWINDOWPARAMS, (MPARAM)&wp, NULL); | |
7291 | |
7292 if(icon) | |
7293 { | |
7294 dw_window_set_data(handle, "_dw_button_icon", DW_POINTER(icon)); | |
7295 } | |
7296 else | |
7297 { | |
7298 HPIXMAP pixmap = (HPIXMAP)dw_window_get_data(handle, "_dw_hpixmap"); | |
7299 HPIXMAP disabled = (HPIXMAP)dw_window_get_data(handle, "_dw_hpixmap_disabled"); | |
7300 | |
7301 if(pixmap) | |
7302 dw_pixmap_destroy(pixmap); | |
7303 if(disabled) | |
7304 dw_pixmap_destroy(disabled); | |
7305 | |
7306 pixmap = calloc(1,sizeof(struct _hpixmap)); | |
7307 pixmap->hbm = hbm; | |
7308 pixmap->hdc = hdc; | |
7309 pixmap->hps = hps; | |
7310 pixmap->width = width; | |
7311 pixmap->height = height; | |
7312 disabled = _create_disabled(handle, pixmap); | |
7313 | |
7314 dw_window_set_data(handle, "_dw_hpixmap", DW_POINTER(pixmap)); | |
7315 dw_window_set_data(handle, "_dw_hpixmap_disabled", DW_POINTER(disabled)); | |
7316 } | |
7317 dw_window_set_data(handle, "_dw_bitmapbutton", DW_POINTER(1)); | |
7318 /* Make sure we invalidate the button so it redraws */ | |
7319 WinQueryWindowRect(handle, &rect); | |
7320 WinInvalidateRect(handle, &rect, TRUE); | |
7321 } | |
7322 | |
7323 /* If we changed the bitmap... */ | |
7324 { | |
7325 Item *item = _box_item(handle); | |
7326 | |
7327 /* Check to see if any of the sizes need to be recalculated */ | |
7328 if(item && (item->origwidth == -1 || item->origheight == -1)) | |
7329 { | |
7330 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); | |
7331 /* Queue a redraw on the top-level window */ | |
7332 _dw_redraw(_toplevel_window(handle), TRUE); | |
7333 } | |
7334 } | |
7335 } | |
7336 | |
7279 /* | 7337 /* |
7280 * Sets the bitmap used for a given static window. | 7338 * Sets the bitmap used for a given static window. |
7281 * Parameters: | 7339 * Parameters: |
7282 * handle: Handle to the window. | 7340 * handle: Handle to the window. |
7283 * id: An ID to be used to specify the icon, | 7341 * id: An ID to be used to specify the icon, |
7286 * Windows and a pixmap on Unix, pass | 7344 * Windows and a pixmap on Unix, pass |
7287 * NULL if you use the id param) | 7345 * NULL if you use the id param) |
7288 */ | 7346 */ |
7289 void API dw_window_set_bitmap(HWND handle, unsigned long id, char *filename) | 7347 void API dw_window_set_bitmap(HWND handle, unsigned long id, char *filename) |
7290 { | 7348 { |
7291 HBITMAP hbm; | 7349 HBITMAP hbm = 0; |
7292 HPS hps; | 7350 HPS hps = 0; |
7351 HDC hdc = 0; | |
7352 HPOINTER icon = 0; | |
7353 unsigned long width = 0, height = 0; | |
7354 int depth = 0; | |
7293 | 7355 |
7294 /* Destroy any old bitmap data */ | 7356 /* Destroy any old bitmap data */ |
7295 _free_bitmap(handle); | 7357 _free_bitmap(handle); |
7296 | 7358 |
7297 /* If id is non-zero use the resource */ | 7359 /* If id is non-zero use the resource */ |
7298 if ( id ) | 7360 if ( id ) |
7299 { | 7361 { |
7300 hps = WinGetPS( handle ); | 7362 hps = WinGetPS( handle ); |
7301 hbm = GpiLoadBitmap( hps, NULLHANDLE, id, 0, 0 ); | 7363 hbm = GpiLoadBitmap( hps, NULLHANDLE, id, 0, 0 ); |
7364 WinReleasePS(hps); | |
7302 } | 7365 } |
7303 else if ( filename ) | 7366 else if ( filename ) |
7304 { | 7367 { |
7305 HDC hdc = 0; | |
7306 unsigned long width, height; | |
7307 char *file = alloca(strlen(filename) + 6); | 7368 char *file = alloca(strlen(filename) + 6); |
7308 int depth; | |
7309 | 7369 |
7310 if(!file) | 7370 if(!file) |
7311 return; | 7371 return; |
7312 | 7372 |
7313 strcpy(file, filename); | 7373 strcpy(file, filename); |
7314 | 7374 |
7315 /* check if we can read from this file (it exists and read permission) */ | 7375 /* check if we can read from this file (it exists and read permission) */ |
7316 if(access(file, 04) != 0) | 7376 if(access(file, 04) != 0) |
7317 { | 7377 { |
7318 int z; | 7378 /* Try with .ico extension first...*/ |
7319 | 7379 strcat(file, ".ico"); |
7320 /* Try with supported extensions */ | 7380 if(access(file, 04) == 0) |
7321 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) | 7381 icon = WinLoadFileIcon((PSZ)file, FALSE); |
7322 { | 7382 else |
7323 strcpy(file, filename); | 7383 { |
7324 strcat(file, image_exts[z]); | 7384 int z; |
7325 if(access(file, 04) == 0 && | 7385 |
7326 _load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth)) | 7386 /* Try with supported extensions */ |
7327 break; | 7387 for(z=0;z<(_gbm_init?NUM_EXTS:1);z++) |
7328 } | 7388 { |
7389 strcpy(file, filename); | |
7390 strcat(file, image_exts[z]); | |
7391 if(access(file, 04) == 0 && | |
7392 _load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth)) | |
7393 break; | |
7394 } | |
7395 } | |
7329 } | 7396 } |
7330 else | 7397 else |
7331 _load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth); | 7398 { |
7332 | 7399 int len = strlen( file ); |
7333 if(!hdc) | 7400 if(len > 4) |
7401 { | |
7402 if(stricmp(file + len - 4, ".ico") == 0) | |
7403 icon = WinLoadFileIcon((PSZ)file, FALSE); | |
7404 else | |
7405 _load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth); | |
7406 } | |
7407 } | |
7408 | |
7409 if(!hdc && !icon) | |
7334 return; | 7410 return; |
7335 | 7411 |
7336 dw_window_set_data(handle, "_dw_hps", (void *)hps); | 7412 dw_window_set_data(handle, "_dw_hps", (void *)hps); |
7337 dw_window_set_data(handle, "_dw_hdc", (void *)hdc); | 7413 dw_window_set_data(handle, "_dw_hdc", (void *)hdc); |
7338 dw_window_set_data(handle, "_dw_width", (void *)width); | 7414 dw_window_set_data(handle, "_dw_width", (void *)width); |
7339 dw_window_set_data(handle, "_dw_height", (void *)height); | 7415 dw_window_set_data(handle, "_dw_height", (void *)height); |
7340 } | 7416 } |
7341 else | 7417 else |
7342 return; | 7418 return; |
7343 | 7419 |
7344 if ( id ) | |
7345 WinReleasePS(hps); | |
7346 dw_window_set_data(handle, "_dw_bitmap", (void *)hbm); | 7420 dw_window_set_data(handle, "_dw_bitmap", (void *)hbm); |
7347 | 7421 |
7348 /* If we changed the bitmap... */ | 7422 _dw_window_set_bitmap(handle, hbm, hdc, hps, width, height, depth, icon); |
7349 { | |
7350 Item *item = _box_item(handle); | |
7351 | |
7352 /* Check to see if any of the sizes need to be recalculated */ | |
7353 if(item && (item->origwidth == -1 || item->origheight == -1)) | |
7354 { | |
7355 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); | |
7356 /* Queue a redraw on the top-level window */ | |
7357 _dw_redraw(_toplevel_window(handle), TRUE); | |
7358 } | |
7359 } | |
7360 } | 7423 } |
7361 | 7424 |
7362 /* | 7425 /* |
7363 * Sets the bitmap used for a given static window. | 7426 * Sets the bitmap used for a given static window. |
7364 * Parameters: | 7427 * Parameters: |
7415 /* If id is non-zero use the resource */ | 7478 /* If id is non-zero use the resource */ |
7416 else if ( id ) | 7479 else if ( id ) |
7417 { | 7480 { |
7418 hps = WinGetPS( handle ); | 7481 hps = WinGetPS( handle ); |
7419 hbm = GpiLoadBitmap( hps, NULLHANDLE, id, 0, 0 ); | 7482 hbm = GpiLoadBitmap( hps, NULLHANDLE, id, 0, 0 ); |
7483 WinReleasePS(hps); | |
7420 } | 7484 } |
7421 else | 7485 else |
7422 return; | 7486 return; |
7423 | 7487 |
7424 if ( id ) | |
7425 WinReleasePS(hps); | |
7426 dw_window_set_data(handle, "_dw_bitmap", (void *)hbm); | 7488 dw_window_set_data(handle, "_dw_bitmap", (void *)hbm); |
7489 | |
7490 _dw_window_set_bitmap(handle, hbm, hdc, hps, width, height, depth, 0); | |
7427 } | 7491 } |
7428 | 7492 |
7429 /* | 7493 /* |
7430 * Sets the text used for a given window. | 7494 * Sets the text used for a given window. |
7431 * Parameters: | 7495 * Parameters: |