Mercurial > dwindows
comparison os2/dw.c @ 2853:c250764b2f32
OS/2: Add return values to dw_window_set_bitmap(_from_data).
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 15 Nov 2022 01:07:55 +0000 |
parents | ee1cfa7d645e |
children | 761b7a12b079 |
comparison
equal
deleted
inserted
replaced
2852:5018df4f952e | 2853:c250764b2f32 |
---|---|
7441 DosFreeMem(BitmapFileBegin); | 7441 DosFreeMem(BitmapFileBegin); |
7442 return 1; | 7442 return 1; |
7443 } | 7443 } |
7444 | 7444 |
7445 /* Internal function to change the button bitmap */ | 7445 /* Internal function to change the button bitmap */ |
7446 void _dw_window_set_bitmap(HWND handle, HBITMAP hbm, HDC hdc, HPS hps, unsigned long width, unsigned long height, int depth, HPOINTER icon) | 7446 int _dw_window_set_bitmap(HWND handle, HBITMAP hbm, HDC hdc, HPS hps, unsigned long width, unsigned long height, int depth, HPOINTER icon) |
7447 { | 7447 { |
7448 char tmpbuf[100] = {0}; | 7448 char tmpbuf[100] = {0}; |
7449 | 7449 |
7450 WinQueryClassName(handle, 99, (PCH)tmpbuf); | 7450 WinQueryClassName(handle, 99, (PCH)tmpbuf); |
7451 | 7451 |
7484 dw_window_set_data(handle, "_dw_bitmapbutton", DW_POINTER(1)); | 7484 dw_window_set_data(handle, "_dw_bitmapbutton", DW_POINTER(1)); |
7485 /* Make sure we invalidate the button so it redraws */ | 7485 /* Make sure we invalidate the button so it redraws */ |
7486 WinQueryWindowRect(handle, &rect); | 7486 WinQueryWindowRect(handle, &rect); |
7487 WinInvalidateRect(handle, &rect, TRUE); | 7487 WinInvalidateRect(handle, &rect, TRUE); |
7488 } | 7488 } |
7489 else | |
7490 return DW_ERROR_UNKNOWN; | |
7489 | 7491 |
7490 /* If we changed the bitmap... */ | 7492 /* If we changed the bitmap... */ |
7491 { | 7493 { |
7492 Item *item = _dw_box_item(handle); | 7494 Item *item = _dw_box_item(handle); |
7493 | 7495 |
7497 _dw_control_size(handle, item->origwidth == DW_SIZE_AUTO ? &item->width : NULL, item->origheight == DW_SIZE_AUTO ? &item->height : NULL); | 7499 _dw_control_size(handle, item->origwidth == DW_SIZE_AUTO ? &item->width : NULL, item->origheight == DW_SIZE_AUTO ? &item->height : NULL); |
7498 /* Queue a redraw on the top-level window */ | 7500 /* Queue a redraw on the top-level window */ |
7499 _dw_redraw(_dw_toplevel_window(handle), TRUE); | 7501 _dw_redraw(_dw_toplevel_window(handle), TRUE); |
7500 } | 7502 } |
7501 } | 7503 } |
7504 return DW_ERROR_NONE; | |
7502 } | 7505 } |
7503 | 7506 |
7504 /* | 7507 /* |
7505 * Sets the bitmap used for a given static window. | 7508 * Sets the bitmap used for a given static window. |
7506 * Parameters: | 7509 * Parameters: |
7508 * id: An ID to be used to specify the icon, | 7511 * id: An ID to be used to specify the icon, |
7509 * (pass 0 if you use the filename param) | 7512 * (pass 0 if you use the filename param) |
7510 * filename: a path to a file (Bitmap on OS/2 or | 7513 * filename: a path to a file (Bitmap on OS/2 or |
7511 * Windows and a pixmap on Unix, pass | 7514 * Windows and a pixmap on Unix, pass |
7512 * NULL if you use the id param) | 7515 * NULL if you use the id param) |
7513 */ | 7516 * Returns: |
7514 void API dw_window_set_bitmap(HWND handle, unsigned long id, const char *filename) | 7517 * DW_ERROR_NONE on success. |
7518 * DW_ERROR_UNKNOWN if the parameters were invalid. | |
7519 * DW_ERROR_GENERAL if the bitmap was unable to be loaded. | |
7520 */ | |
7521 int API dw_window_set_bitmap(HWND handle, unsigned long id, const char *filename) | |
7515 { | 7522 { |
7516 HBITMAP hbm = 0; | 7523 HBITMAP hbm = 0; |
7517 HPS hps = 0; | 7524 HPS hps = 0; |
7518 HDC hdc = 0; | 7525 HDC hdc = 0; |
7519 HPOINTER icon = 0; | 7526 HPOINTER icon = 0; |
7522 | 7529 |
7523 /* Destroy any old bitmap data */ | 7530 /* Destroy any old bitmap data */ |
7524 _dw_free_bitmap(handle); | 7531 _dw_free_bitmap(handle); |
7525 | 7532 |
7526 /* If id is non-zero use the resource */ | 7533 /* If id is non-zero use the resource */ |
7527 if ( id ) | 7534 if(id) |
7528 { | 7535 { |
7529 hps = WinGetPS( handle ); | 7536 hps = WinGetPS(handle); |
7530 hbm = GpiLoadBitmap( hps, NULLHANDLE, id, 0, 0 ); | 7537 hbm = GpiLoadBitmap(hps, NULLHANDLE, id, 0, 0); |
7531 WinReleasePS(hps); | 7538 WinReleasePS(hps); |
7532 } | 7539 } |
7533 else if ( filename ) | 7540 else if(filename) |
7534 { | 7541 { |
7535 char *file = alloca(strlen(filename) + 6); | 7542 char *file = alloca(strlen(filename) + 6); |
7536 | 7543 |
7537 if(!file) | 7544 if(!file) |
7538 return; | 7545 return DW_ERROR_GENERAL; |
7539 | 7546 |
7540 strcpy(file, filename); | 7547 strcpy(file, filename); |
7541 | 7548 |
7542 /* check if we can read from this file (it exists and read permission) */ | 7549 /* check if we can read from this file (it exists and read permission) */ |
7543 if(access(file, 04) != 0) | 7550 if(access(file, 04) != 0) |
7561 } | 7568 } |
7562 } | 7569 } |
7563 } | 7570 } |
7564 else | 7571 else |
7565 { | 7572 { |
7566 int len = strlen( file ); | 7573 int len = strlen(file); |
7567 if(len > 4) | 7574 if(len > 4) |
7568 { | 7575 { |
7569 if(stricmp(file + len - 4, ".ico") == 0) | 7576 if(stricmp(file + len - 4, ".ico") == 0) |
7570 icon = WinLoadFileIcon((PSZ)file, FALSE); | 7577 icon = WinLoadFileIcon((PSZ)file, FALSE); |
7571 else | 7578 else |
7572 _dw_load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth, DW_CLR_DEFAULT); | 7579 _dw_load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth, DW_CLR_DEFAULT); |
7573 } | 7580 } |
7574 } | 7581 } |
7575 | 7582 |
7576 if(!hdc && !icon) | 7583 if(!hdc && !icon) |
7577 return; | 7584 return DW_ERROR_GENERAL; |
7578 | 7585 |
7579 dw_window_set_data(handle, "_dw_hps", (void *)hps); | 7586 dw_window_set_data(handle, "_dw_hps", (void *)hps); |
7580 dw_window_set_data(handle, "_dw_hdc", (void *)hdc); | 7587 dw_window_set_data(handle, "_dw_hdc", (void *)hdc); |
7581 dw_window_set_data(handle, "_dw_width", (void *)width); | 7588 dw_window_set_data(handle, "_dw_width", (void *)width); |
7582 dw_window_set_data(handle, "_dw_height", (void *)height); | 7589 dw_window_set_data(handle, "_dw_height", (void *)height); |
7583 } | 7590 } |
7584 else | 7591 else |
7585 return; | 7592 return DW_ERROR_UNKNOWN; |
7586 | 7593 |
7587 dw_window_set_data(handle, "_dw_bitmap", (void *)hbm); | 7594 dw_window_set_data(handle, "_dw_bitmap", (void *)hbm); |
7588 | 7595 |
7589 _dw_window_set_bitmap(handle, hbm, hdc, hps, width, height, depth, icon); | 7596 return _dw_window_set_bitmap(handle, hbm, hdc, hps, width, height, depth, icon); |
7590 } | 7597 } |
7591 | 7598 |
7592 /* | 7599 /* |
7593 * Sets the bitmap used for a given static window. | 7600 * Sets the bitmap used for a given static window. |
7594 * Parameters: | 7601 * Parameters: |
7596 * id: An ID to be used to specify the icon, | 7603 * id: An ID to be used to specify the icon, |
7597 * (pass 0 if you use the filename param) | 7604 * (pass 0 if you use the filename param) |
7598 * filename: a path to a file (Bitmap on OS/2 or | 7605 * filename: a path to a file (Bitmap on OS/2 or |
7599 * Windows and a pixmap on Unix, pass | 7606 * Windows and a pixmap on Unix, pass |
7600 * NULL if you use the id param) | 7607 * NULL if you use the id param) |
7601 */ | 7608 * Returns: |
7602 void API dw_window_set_bitmap_from_data(HWND handle, unsigned long id, const char *data, int len) | 7609 * DW_ERROR_NONE on success. |
7610 * DW_ERROR_UNKNOWN if the parameters were invalid. | |
7611 * DW_ERROR_GENERAL if the bitmap was unable to be loaded. | |
7612 */ | |
7613 int API dw_window_set_bitmap_from_data(HWND handle, unsigned long id, const char *data, int len) | |
7603 { | 7614 { |
7604 HBITMAP hbm; | 7615 HBITMAP hbm; |
7605 HPS hps; | 7616 HPS hps; |
7606 HDC hdc; | 7617 HDC hdc; |
7607 unsigned long width, height; | 7618 unsigned long width, height; |
7610 int depth; | 7621 int depth; |
7611 | 7622 |
7612 /* Destroy any old bitmap data */ | 7623 /* Destroy any old bitmap data */ |
7613 _dw_free_bitmap(handle); | 7624 _dw_free_bitmap(handle); |
7614 | 7625 |
7615 if ( data ) | 7626 if(data) |
7616 { | 7627 { |
7617 file = tmpnam( NULL ); | 7628 file = tmpnam(NULL); |
7618 if ( file != NULL ) | 7629 if(file != NULL) |
7619 { | 7630 { |
7620 fp = fopen( file, "wb" ); | 7631 fp = fopen(file, "wb"); |
7621 if ( fp != NULL ) | 7632 if(fp != NULL) |
7622 { | 7633 { |
7623 fwrite( data, 1, len, fp ); | 7634 fwrite(data, 1, len, fp); |
7624 fclose( fp ); | 7635 fclose(fp); |
7625 if(!_dw_load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth, DW_CLR_DEFAULT)) | 7636 if(!_dw_load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height, &depth, DW_CLR_DEFAULT)) |
7626 { | 7637 { |
7627 /* can't use ICO ? */ | 7638 /* can't use ICO ? */ |
7628 unlink( file ); | 7639 unlink(file); |
7629 return; | 7640 return DW_ERROR_GENERAL; |
7630 } | 7641 } |
7631 } | 7642 } |
7632 else | 7643 else |
7633 { | 7644 { |
7634 unlink( file ); | 7645 unlink(file); |
7635 return; | 7646 return DW_ERROR_GENERAL; |
7636 } | 7647 } |
7637 unlink( file ); | 7648 unlink(file); |
7638 } | 7649 } |
7639 | 7650 |
7640 dw_window_set_data(handle, "_dw_hps", (void *)hps); | 7651 dw_window_set_data(handle, "_dw_hps", (void *)hps); |
7641 dw_window_set_data(handle, "_dw_hdc", (void *)hdc); | 7652 dw_window_set_data(handle, "_dw_hdc", (void *)hdc); |
7642 dw_window_set_data(handle, "_dw_width", (void *)width); | 7653 dw_window_set_data(handle, "_dw_width", (void *)width); |
7643 dw_window_set_data(handle, "_dw_height", (void *)height); | 7654 dw_window_set_data(handle, "_dw_height", (void *)height); |
7644 } | 7655 } |
7645 /* If id is non-zero use the resource */ | 7656 /* If id is non-zero use the resource */ |
7646 else if ( id ) | 7657 else if(id) |
7647 { | 7658 { |
7648 hps = WinGetPS( handle ); | 7659 hps = WinGetPS(handle); |
7649 hbm = GpiLoadBitmap( hps, NULLHANDLE, id, 0, 0 ); | 7660 hbm = GpiLoadBitmap( hps, NULLHANDLE, id, 0, 0 ); |
7650 WinReleasePS(hps); | 7661 WinReleasePS(hps); |
7651 } | 7662 } |
7652 else | 7663 else |
7653 return; | 7664 return DW_ERROR_UNKNOWN; |
7654 | 7665 |
7655 dw_window_set_data(handle, "_dw_bitmap", (void *)hbm); | 7666 dw_window_set_data(handle, "_dw_bitmap", (void *)hbm); |
7656 | 7667 |
7657 _dw_window_set_bitmap(handle, hbm, hdc, hps, width, height, depth, 0); | 7668 return _dw_window_set_bitmap(handle, hbm, hdc, hps, width, height, depth, 0); |
7658 } | 7669 } |
7659 | 7670 |
7660 /* | 7671 /* |
7661 * Sets the text used for a given window. | 7672 * Sets the text used for a given window. |
7662 * Parameters: | 7673 * Parameters: |