Mercurial > dwindows
comparison gtk3/dw.c @ 2854:8a5131cbbe93
GTK2/3/4: Add return values to dw_window_set_bitmap(_from_data).
Also similar to the other platforms, no longer install XPMs to gtk/.
GTK4 is currently untested, if it doesn't work, may be a follow-up.
Also fix a GCC fortify warning with strncpy().
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 15 Nov 2022 02:29:56 +0000 |
parents | ee1cfa7d645e |
children | 86286f528adf |
comparison
equal
deleted
inserted
replaced
2853:c250764b2f32 | 2854:8a5131cbbe93 |
---|---|
4260 tmp = gtk_button_new(); | 4260 tmp = gtk_button_new(); |
4261 /* Now on to the image stuff */ | 4261 /* Now on to the image stuff */ |
4262 bitmap = dw_bitmap_new(id); | 4262 bitmap = dw_bitmap_new(id); |
4263 if(bitmap) | 4263 if(bitmap) |
4264 { | 4264 { |
4265 dw_window_set_bitmap( bitmap, 0, filename ); | 4265 dw_window_set_bitmap(bitmap, 0, filename); |
4266 gtk_container_add (GTK_CONTAINER(tmp), bitmap); | 4266 gtk_container_add(GTK_CONTAINER(tmp), bitmap); |
4267 g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", bitmap); | 4267 g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", bitmap); |
4268 } | 4268 } |
4269 gtk_widget_show(tmp); | 4269 gtk_widget_show(tmp); |
4270 if(text) | 4270 if(text) |
4271 { | 4271 { |
4296 bitmap = dw_bitmap_new(id); | 4296 bitmap = dw_bitmap_new(id); |
4297 | 4297 |
4298 if(bitmap) | 4298 if(bitmap) |
4299 { | 4299 { |
4300 dw_window_set_bitmap_from_data(bitmap, 0, data, len); | 4300 dw_window_set_bitmap_from_data(bitmap, 0, data, len); |
4301 gtk_container_add (GTK_CONTAINER(tmp), bitmap); | 4301 gtk_container_add(GTK_CONTAINER(tmp), bitmap); |
4302 g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", bitmap); | 4302 g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", bitmap); |
4303 } | 4303 } |
4304 gtk_widget_show(tmp); | 4304 gtk_widget_show(tmp); |
4305 if(text) | 4305 if(text) |
4306 { | 4306 { |
4547 * id: An ID to be used to specify the icon, | 4547 * id: An ID to be used to specify the icon, |
4548 * (pass 0 if you use the filename param) | 4548 * (pass 0 if you use the filename param) |
4549 * filename: a path to a file (Bitmap on OS/2 or | 4549 * filename: a path to a file (Bitmap on OS/2 or |
4550 * Windows and a pixmap on Unix, pass | 4550 * Windows and a pixmap on Unix, pass |
4551 * NULL if you use the id param) | 4551 * NULL if you use the id param) |
4552 */ | 4552 * Returns: |
4553 void dw_window_set_bitmap(HWND handle, unsigned long id, const char *filename) | 4553 * DW_ERROR_NONE on success. |
4554 * DW_ERROR_UNKNOWN if the parameters were invalid. | |
4555 * DW_ERROR_GENERAL if the bitmap was unable to be loaded. | |
4556 */ | |
4557 int dw_window_set_bitmap(HWND handle, unsigned long id, const char *filename) | |
4554 { | 4558 { |
4555 GdkPixbuf *tmp = NULL; | 4559 GdkPixbuf *tmp = NULL; |
4556 int found_ext = 0; | 4560 int i, found_ext = 0; |
4557 int i; | 4561 int _dw_locked_by_me = FALSE; |
4558 int _dw_locked_by_me = FALSE; | 4562 int retval = DW_ERROR_UNKNOWN; |
4559 | 4563 |
4560 if(!id && !filename) | 4564 if(!id && !filename) |
4561 return; | 4565 return retval; |
4562 | 4566 |
4563 DW_MUTEX_LOCK; | 4567 DW_MUTEX_LOCK; |
4564 if(id) | 4568 if(id) |
4565 tmp = _dw_find_pixbuf((HICN)id, NULL, NULL); | 4569 tmp = _dw_find_pixbuf((HICN)id, NULL, NULL); |
4566 else | 4570 else |
4567 { | 4571 { |
4568 char *file = alloca(strlen(filename) + 6); | 4572 char *file = alloca(strlen(filename) + 6); |
4569 | 4573 |
4570 if (!file) | 4574 if(!file) |
4571 { | 4575 { |
4572 DW_MUTEX_UNLOCK; | 4576 DW_MUTEX_UNLOCK; |
4573 return; | 4577 return DW_ERROR_GENERAL; |
4574 } | 4578 } |
4575 | 4579 |
4576 strcpy(file, filename); | 4580 strcpy(file, filename); |
4577 | 4581 |
4578 /* check if we can read from this file (it exists and read permission) */ | 4582 /* check if we can read from this file (it exists and read permission) */ |
4579 if ( access(file, 04 ) != 0 ) | 4583 if(access(file, 04) != 0) |
4580 { | 4584 { |
4581 /* Try with various extentions */ | 4585 /* Try with various extentions */ |
4582 for ( i = 0; i < NUM_EXTS; i++ ) | 4586 for(i = 0; i < NUM_EXTS; i++) |
4583 { | 4587 { |
4584 strcpy( file, filename ); | 4588 strcpy(file, filename); |
4585 strcat( file, _dw_image_exts[i] ); | 4589 strcat(file, _dw_image_exts[i]); |
4586 if ( access( file, 04 ) == 0 ) | 4590 if(access( file, 04 ) == 0) |
4587 { | 4591 { |
4588 found_ext = 1; | 4592 found_ext = 1; |
4589 break; | 4593 break; |
4590 } | 4594 } |
4591 } | 4595 } |
4592 if ( found_ext == 0 ) | 4596 if(found_ext == 0) |
4593 { | 4597 { |
4594 DW_MUTEX_UNLOCK; | 4598 DW_MUTEX_UNLOCK; |
4595 return; | 4599 return DW_ERROR_GENERAL; |
4596 } | 4600 } |
4597 } | 4601 } |
4598 tmp = gdk_pixbuf_new_from_file(file, NULL ); | 4602 tmp = gdk_pixbuf_new_from_file(file, NULL); |
4599 } | 4603 } |
4600 | 4604 |
4601 if (tmp) | 4605 if(tmp) |
4602 { | 4606 { |
4603 if ( GTK_IS_BUTTON(handle) ) | 4607 if(GTK_IS_BUTTON(handle)) |
4604 { | 4608 { |
4605 GtkWidget *pixmap = (GtkWidget *)g_object_get_data( G_OBJECT(handle), "_dw_bitmap" ); | 4609 GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap"); |
4606 if(pixmap) | 4610 if(pixmap) |
4607 { | 4611 { |
4608 gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), tmp); | 4612 gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), tmp); |
4613 retval = DW_ERROR_NONE; | |
4609 } | 4614 } |
4610 } | 4615 } |
4611 else | 4616 else if(GTK_IS_IMAGE(handle)) |
4612 { | 4617 { |
4613 gtk_image_set_from_pixbuf(GTK_IMAGE(handle), tmp); | 4618 gtk_image_set_from_pixbuf(GTK_IMAGE(handle), tmp); |
4614 } | 4619 retval = DW_ERROR_NONE; |
4615 } | 4620 } |
4616 DW_MUTEX_UNLOCK; | 4621 } |
4622 DW_MUTEX_UNLOCK; | |
4623 return retval; | |
4617 } | 4624 } |
4618 | 4625 |
4619 /* | 4626 /* |
4620 * Sets the bitmap used for a given static window. | 4627 * Sets the bitmap used for a given static window. |
4621 * Parameters: | 4628 * Parameters: |
4624 * (pass 0 if you use the filename param) | 4631 * (pass 0 if you use the filename param) |
4625 * data: the image data | 4632 * data: the image data |
4626 * Bitmap on Windows and a pixmap on Unix, pass | 4633 * Bitmap on Windows and a pixmap on Unix, pass |
4627 * NULL if you use the id param) | 4634 * NULL if you use the id param) |
4628 * len: length of data | 4635 * len: length of data |
4629 */ | 4636 * Returns: |
4630 void dw_window_set_bitmap_from_data(HWND handle, unsigned long id, const char *data, int len) | 4637 * DW_ERROR_NONE on success. |
4638 * DW_ERROR_UNKNOWN if the parameters were invalid. | |
4639 * DW_ERROR_GENERAL if the bitmap was unable to be loaded. | |
4640 */ | |
4641 int dw_window_set_bitmap_from_data(HWND handle, unsigned long id, const char *data, int len) | |
4631 { | 4642 { |
4632 GdkPixbuf *tmp = NULL; | 4643 GdkPixbuf *tmp = NULL; |
4633 int _dw_locked_by_me = FALSE; | 4644 int _dw_locked_by_me = FALSE; |
4645 int retval = DW_ERROR_UNKNOWN; | |
4634 | 4646 |
4635 if(!id && !data) | 4647 if(!id && !data) |
4636 return; | 4648 return retval; |
4637 | 4649 |
4638 DW_MUTEX_LOCK; | 4650 DW_MUTEX_LOCK; |
4639 if(data) | 4651 if(data) |
4640 { | 4652 { |
4641 /* | 4653 /* |
4652 } | 4664 } |
4653 /* Bail if we couldn't write full file */ | 4665 /* Bail if we couldn't write full file */ |
4654 if(fd == -1 || written != len) | 4666 if(fd == -1 || written != len) |
4655 { | 4667 { |
4656 DW_MUTEX_UNLOCK; | 4668 DW_MUTEX_UNLOCK; |
4657 return; | 4669 return DW_ERROR_GENERAL; |
4658 } | 4670 } |
4659 | 4671 |
4660 tmp = gdk_pixbuf_new_from_file(template, NULL); | 4672 tmp = gdk_pixbuf_new_from_file(template, NULL); |
4661 /* remove our temporary file */ | 4673 /* remove our temporary file */ |
4662 unlink(template); | 4674 unlink(template); |
4669 if(GTK_IS_BUTTON(handle)) | 4681 if(GTK_IS_BUTTON(handle)) |
4670 { | 4682 { |
4671 GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap"); | 4683 GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap"); |
4672 | 4684 |
4673 if(pixmap) | 4685 if(pixmap) |
4686 { | |
4674 gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), tmp); | 4687 gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), tmp); |
4675 } | 4688 retval = DW_ERROR_NONE; |
4676 else | 4689 } |
4690 } | |
4691 else if(GTK_IS_IMAGE(handle)) | |
4692 { | |
4677 gtk_image_set_from_pixbuf(GTK_IMAGE(handle), tmp); | 4693 gtk_image_set_from_pixbuf(GTK_IMAGE(handle), tmp); |
4678 } | 4694 retval = DW_ERROR_NONE; |
4679 DW_MUTEX_UNLOCK; | 4695 } |
4696 } | |
4697 DW_MUTEX_UNLOCK; | |
4698 return retval; | |
4680 } | 4699 } |
4681 | 4700 |
4682 /* | 4701 /* |
4683 * Sets the text used for a given window. | 4702 * Sets the text used for a given window. |
4684 * Parameters: | 4703 * Parameters: |