comparison gtk4/dw.c @ 2319:36522ed00ef8

GTK4: Some general code cleanup and an attempt to get dw_window_set_icon() working for resource icons, the docs say I need hi color layout...
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 16 Feb 2021 09:01:07 +0000
parents 5951752fa7af
children 829228de003f
comparison
equal deleted inserted replaced
2318:5951752fa7af 2319:36522ed00ef8
389 #define _DW_TREE_TYPE_CONTAINER 1 389 #define _DW_TREE_TYPE_CONTAINER 1
390 #define _DW_TREE_TYPE_TREE 2 390 #define _DW_TREE_TYPE_TREE 2
391 #define _DW_TREE_TYPE_LISTBOX 3 391 #define _DW_TREE_TYPE_LISTBOX 3
392 #define _DW_TREE_TYPE_COMBOBOX 4 392 #define _DW_TREE_TYPE_COMBOBOX 4
393 393
394 #define _DW_RESOURCE_PATH "/org/dbsoft/dwindows/resources/"
395
394 /* Signal forwarder prototypes */ 396 /* Signal forwarder prototypes */
395 static gint _dw_button_press_event(GtkGestureSingle *gesture, int n_press, double x, double y, gpointer data); 397 static gint _dw_button_press_event(GtkGestureSingle *gesture, int n_press, double x, double y, gpointer data);
396 static gint _dw_button_release_event(GtkGestureSingle *gesture, int n_press, double x, double y, gpointer data); 398 static gint _dw_button_release_event(GtkGestureSingle *gesture, int n_press, double x, double y, gpointer data);
397 static gint _dw_motion_notify_event(GtkEventControllerMotion *controller, double x, double y, gpointer data); 399 static gint _dw_motion_notify_event(GtkEventControllerMotion *controller, double x, double y, gpointer data);
398 static gboolean _dw_delete_event(GtkWidget *window, gpointer data); 400 static gboolean _dw_delete_event(GtkWidget *window, gpointer data);
1250 } 1252 }
1251 1253
1252 static GdkPixbuf *_dw_pixbuf_from_resource(unsigned int rid) 1254 static GdkPixbuf *_dw_pixbuf_from_resource(unsigned int rid)
1253 { 1255 {
1254 char resource_path[201] = {0}; 1256 char resource_path[201] = {0};
1255 snprintf(resource_path, 200, "/org/dbsoft/dwindows/resources/%u.png", rid); 1257
1258 snprintf(resource_path, 200, "%s%u.png", _DW_RESOURCE_PATH, rid);
1256 return gdk_pixbuf_new_from_resource(resource_path, NULL); 1259 return gdk_pixbuf_new_from_resource(resource_path, NULL);
1257 } 1260 }
1258 1261
1259 static GdkPixbuf *_dw_find_pixbuf(HICN icon, unsigned long *userwidth, unsigned long *userheight) 1262 static GdkPixbuf *_dw_find_pixbuf(HICN icon, unsigned long *userwidth, unsigned long *userheight)
1260 { 1263 {
3532 gtk_tree_view_set_expander_column(GTK_TREE_VIEW(tree), col); 3535 gtk_tree_view_set_expander_column(GTK_TREE_VIEW(tree), col);
3533 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree), FALSE); 3536 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree), FALSE);
3534 3537
3535 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)); 3538 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
3536 if(multi) 3539 if(multi)
3537 {
3538 gtk_tree_selection_set_mode(sel, GTK_SELECTION_MULTIPLE); 3540 gtk_tree_selection_set_mode(sel, GTK_SELECTION_MULTIPLE);
3539 }
3540 else 3541 else
3541 {
3542 gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE); 3542 gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
3543 }
3544 gtk_widget_show(tree); 3543 gtk_widget_show(tree);
3545 if(_DWDefaultFont) 3544 if(_DWDefaultFont)
3546 dw_window_set_font(tmp, _DWDefaultFont); 3545 dw_window_set_font(tmp, _DWDefaultFont);
3547 } 3546 }
3548 DW_FUNCTION_RETURN_THIS(tmp); 3547 DW_FUNCTION_RETURN_THIS(tmp);
3552 * Sets the icon used for a given window. 3551 * Sets the icon used for a given window.
3553 * Parameters: 3552 * Parameters:
3554 * handle: Handle to the window. 3553 * handle: Handle to the window.
3555 * id: An ID to be used to specify the icon. 3554 * id: An ID to be used to specify the icon.
3556 */ 3555 */
3557 void dw_window_set_icon(HWND handle, HICN icon) 3556 DW_FUNCTION_DEFINITION(dw_window_set_icon, void, HWND handle, HICN icon)
3558 { 3557 DW_FUNCTION_ADD_PARAM2(handle, icon)
3559 /* TODO: figure out how to do this for GTK4 */ 3558 DW_FUNCTION_NO_RETURN(dw_window_set_icon)
3560 #if GTK3 3559 DW_FUNCTION_RESTORE_PARAM2(handle, HWND, icon, HICN)
3561 GdkPixbuf *icon_pixbuf; 3560 {
3562 3561 if(handle && GTK_IS_WINDOW(handle))
3563 icon_pixbuf = _dw_find_pixbuf(icon, NULL, NULL); 3562 {
3564 3563 int rid = GPOINTER_TO_INT(icon);
3565 if(icon_pixbuf) 3564
3566 { 3565 if(rid < 65536)
3567 gtk_window_set_icon_name( 3566 {
3568 } 3567 GdkDisplay *display = gdk_display_get_default();
3569 #endif 3568 GtkIconTheme *theme = gtk_icon_theme_get_for_display(display);
3569
3570 if(theme)
3571 {
3572 char resource_path[201] = {0};
3573 char window_icon[25] = {0};
3574
3575 snprintf(resource_path, 200, "%s%u.png", _DW_RESOURCE_PATH, rid);
3576 gtk_icon_theme_add_resource_path(theme, _DW_RESOURCE_PATH);
3577 snprintf(window_icon, 24, "%u", rid);
3578 gtk_window_set_icon_name(GTK_WINDOW(handle), window_icon);
3579 }
3580 }
3581 }
3582 DW_FUNCTION_RETURN_NOTHING;
3570 } 3583 }
3571 3584
3572 /* 3585 /*
3573 * Sets the bitmap used for a given static window. 3586 * Sets the bitmap used for a given static window.
3574 * Parameters: 3587 * Parameters:
8471 * y: Y location from the bottom left. 8484 * y: Y location from the bottom left.
8472 */ 8485 */
8473 void dw_window_set_pos(HWND handle, long x, long y) 8486 void dw_window_set_pos(HWND handle, long x, long y)
8474 { 8487 {
8475 /* TODO: Figure out how to do this in GTK4 with no GdkWindow */ 8488 /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
8476 if(!handle)
8477 return;
8478 } 8489 }
8479 8490
8480 /* 8491 /*
8481 * Sets the position and size of a given window (widget). 8492 * Sets the position and size of a given window (widget).
8482 * Parameters: 8493 * Parameters:
8561 } 8572 }
8562 if(GTK_IS_LABEL(handle2)) 8573 if(GTK_IS_LABEL(handle2))
8563 { 8574 {
8564 gfloat x=DW_LEFT, y=DW_CENTER; 8575 gfloat x=DW_LEFT, y=DW_CENTER;
8565 /* horizontal... */ 8576 /* horizontal... */
8566 if ( style & DW_DT_CENTER ) 8577 if(style & DW_DT_CENTER)
8567 x = DW_CENTER; 8578 x = DW_CENTER;
8568 if ( style & DW_DT_RIGHT ) 8579 if(style & DW_DT_RIGHT)
8569 x = DW_RIGHT; 8580 x = DW_RIGHT;
8570 if ( style & DW_DT_LEFT ) 8581 if(style & DW_DT_LEFT)
8571 x = DW_LEFT; 8582 x = DW_LEFT;
8572 /* vertical... */ 8583 /* vertical... */
8573 if ( style & DW_DT_VCENTER ) 8584 if(style & DW_DT_VCENTER)
8574 y = DW_CENTER; 8585 y = DW_CENTER;
8575 if ( style & DW_DT_TOP ) 8586 if(style & DW_DT_TOP)
8576 y = DW_TOP; 8587 y = DW_TOP;
8577 if ( style & DW_DT_BOTTOM ) 8588 if(style & DW_DT_BOTTOM)
8578 y = DW_BOTTOM; 8589 y = DW_BOTTOM;
8579 gtk_label_set_xalign(GTK_LABEL(handle2), x); 8590 gtk_label_set_xalign(GTK_LABEL(handle2), x);
8580 gtk_label_set_yalign(GTK_LABEL(handle2), y); 8591 gtk_label_set_yalign(GTK_LABEL(handle2), y);
8581 if(style & DW_DT_WORDBREAK) 8592 if(style & DW_DT_WORDBREAK)
8582 gtk_label_set_wrap(GTK_LABEL(handle), TRUE); 8593 gtk_label_set_wrap(GTK_LABEL(handle), TRUE);