comparison gtk4/dw.c @ 2276:d7f0254f7d1e

GTK4: Attempt fixing box and item padding using gtk_widget_set_margin_*().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 02 Feb 2021 03:52:56 +0000
parents 51cb73faab6e
children ba81894924cb
comparison
equal deleted inserted replaced
2275:51cb73faab6e 2276:d7f0254f7d1e
1017 { 1017 {
1018 int (*genericfunc)(HWND, void *) = work.func; 1018 int (*genericfunc)(HWND, void *) = work.func;
1019 1019
1020 genericfunc(work.window, work.data); 1020 genericfunc(work.window, work.data);
1021 } 1021 }
1022 }
1023
1024 /* Internal function to add padding to boxes or other widgets */
1025 static void _dw_widget_set_pad(GtkWidget *widget, int pad)
1026 {
1027 /* Set pad for each margin direction on the widget */
1028 gtk_widget_set_margin_start(widget, pad);
1029 gtk_widget_set_margin_end(widget, pad);
1030 gtk_widget_set_margin_top(widget, pad);
1031 gtk_widget_set_margin_bottom(widget, pad);
1022 } 1032 }
1023 1033
1024 static void _dw_app_activate(GApplication *app, gpointer user_data) 1034 static void _dw_app_activate(GApplication *app, gpointer user_data)
1025 { 1035 {
1026 /* Not sure why this signal is required, but GLib gives warnings 1036 /* Not sure why this signal is required, but GLib gives warnings
2009 { 2019 {
2010 GtkWidget *tmp; 2020 GtkWidget *tmp;
2011 2021
2012 tmp = gtk_grid_new(); 2022 tmp = gtk_grid_new();
2013 g_object_set_data(G_OBJECT(tmp), "_dw_boxtype", GINT_TO_POINTER(type)); 2023 g_object_set_data(G_OBJECT(tmp), "_dw_boxtype", GINT_TO_POINTER(type));
2014 g_object_set_data(G_OBJECT(tmp), "_dw_boxpad", GINT_TO_POINTER(pad)); 2024 _dw_widget_set_pad(tmp, pad);
2015 gtk_widget_show(tmp); 2025 gtk_widget_show(tmp);
2016 return tmp; 2026 return tmp;
2017 } 2027 }
2018 2028
2019 /* 2029 /*
2030 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(tmp), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); 2040 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(tmp), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
2031 2041
2032 box = gtk_grid_new(); 2042 box = gtk_grid_new();
2033 2043
2034 g_object_set_data(G_OBJECT(box), "_dw_boxtype", GINT_TO_POINTER(type)); 2044 g_object_set_data(G_OBJECT(box), "_dw_boxtype", GINT_TO_POINTER(type));
2035 g_object_set_data(G_OBJECT(box), "_dw_boxpad", GINT_TO_POINTER(pad));
2036 g_object_set_data(G_OBJECT(tmp), "_dw_boxhandle", (gpointer)box); 2045 g_object_set_data(G_OBJECT(tmp), "_dw_boxhandle", (gpointer)box);
2037 2046 _dw_widget_set_pad(box, pad);
2047
2038 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(tmp), box); 2048 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(tmp), box);
2039 g_object_set_data(G_OBJECT(tmp), "_dw_user", box); 2049 g_object_set_data(G_OBJECT(tmp), "_dw_user", box);
2040 gtk_widget_show(box); 2050 gtk_widget_show(box);
2041 gtk_widget_show(tmp); 2051 gtk_widget_show(tmp);
2042 2052
2102 { 2112 {
2103 GtkWidget *tmp, *frame; 2113 GtkWidget *tmp, *frame;
2104 2114
2105 frame = gtk_frame_new(NULL); 2115 frame = gtk_frame_new(NULL);
2106 gtk_frame_set_label(GTK_FRAME(frame), title && *title ? title : NULL); 2116 gtk_frame_set_label(GTK_FRAME(frame), title && *title ? title : NULL);
2107 2117
2108 tmp = gtk_grid_new(); 2118 tmp = gtk_grid_new();
2109 /* TODO: Fix this! gtk_container_set_border_width(GTK_CONTAINER(tmp), pad); */
2110 g_object_set_data(G_OBJECT(tmp), "_dw_boxtype", GINT_TO_POINTER(type)); 2119 g_object_set_data(G_OBJECT(tmp), "_dw_boxtype", GINT_TO_POINTER(type));
2111 g_object_set_data(G_OBJECT(tmp), "_dw_boxpad", GINT_TO_POINTER(pad));
2112 g_object_set_data(G_OBJECT(frame), "_dw_boxhandle", (gpointer)tmp); 2120 g_object_set_data(G_OBJECT(frame), "_dw_boxhandle", (gpointer)tmp);
2121 _dw_widget_set_pad(tmp, pad);
2113 gtk_frame_set_child(GTK_FRAME(frame), tmp); 2122 gtk_frame_set_child(GTK_FRAME(frame), tmp);
2114 gtk_widget_show(tmp); 2123 gtk_widget_show(tmp);
2115 gtk_widget_show(frame); 2124 gtk_widget_show(frame);
2116 if(_DWDefaultFont) 2125 if(_DWDefaultFont)
2117 dw_window_set_font(frame, _DWDefaultFont); 2126 dw_window_set_font(frame, _DWDefaultFont);
7236 { 7245 {
7237 /* NOTE: I left in the ability to pack boxes with a size, 7246 /* NOTE: I left in the ability to pack boxes with a size,
7238 * this eliminates that by forcing the size to 0. 7247 * this eliminates that by forcing the size to 0.
7239 */ 7248 */
7240 height = width = 0; 7249 height = width = 0;
7241 /* TODO: Might need to add "_dw_boxpad" to item here */
7242 } 7250 }
7243 7251
7244 /* Do some sanity bounds checking */ 7252 /* Do some sanity bounds checking */
7245 if(index < 0) 7253 if(index < 0)
7246 index = 0; 7254 index = 0;
7251 /* Set the expand attribute on the widgets now instead of the container */ 7259 /* Set the expand attribute on the widgets now instead of the container */
7252 gtk_widget_set_vexpand(item, vsize); 7260 gtk_widget_set_vexpand(item, vsize);
7253 gtk_widget_set_valign(item, vsize ? GTK_ALIGN_FILL : GTK_ALIGN_START); 7261 gtk_widget_set_valign(item, vsize ? GTK_ALIGN_FILL : GTK_ALIGN_START);
7254 gtk_widget_set_hexpand(item, hsize); 7262 gtk_widget_set_hexpand(item, hsize);
7255 gtk_widget_set_halign(item, hsize ? GTK_ALIGN_FILL : GTK_ALIGN_START); 7263 gtk_widget_set_halign(item, hsize ? GTK_ALIGN_FILL : GTK_ALIGN_START);
7256 /* TODO: Use the margin property as padding 7264 /* Set pad for each margin direction on the widget */
7257 g_object_set(G_OBJECT(item), "margin", pad, NULL);*/ 7265 _dw_widget_set_pad(item, pad);
7258 /* Add to the grid using insert... 7266 /* Add to the grid using insert...
7259 * rows for vertical boxes and columns for horizontal. 7267 * rows for vertical boxes and columns for horizontal.
7260 */ 7268 */
7261 if(boxtype == DW_VERT) 7269 if(boxtype == DW_VERT)
7262 { 7270 {
7908 */ 7916 */
7909 void dw_notebook_pack(HWND handle, unsigned long pageid, HWND page) 7917 void dw_notebook_pack(HWND handle, unsigned long pageid, HWND page)
7910 { 7918 {
7911 GtkWidget *label, *child, *oldlabel, **pagearray; 7919 GtkWidget *label, *child, *oldlabel, **pagearray;
7912 const gchar *text = NULL; 7920 const gchar *text = NULL;
7913 int num, z, realpage = -1, pad; 7921 int num, z, realpage = -1;
7914 char ptext[101] = {0}; 7922 char ptext[101] = {0};
7915 7923
7916 snprintf(ptext, 100, "_dw_page%d", (int)pageid); 7924 snprintf(ptext, 100, "_dw_page%d", (int)pageid);
7917 num = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(handle), ptext)); 7925 num = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(handle), ptext));
7918 g_object_set_data(G_OBJECT(handle), ptext, NULL); 7926 g_object_set_data(G_OBJECT(handle), ptext, NULL);
7940 } 7948 }
7941 7949
7942 pagearray[pageid] = page; 7950 pagearray[pageid] = page;
7943 7951
7944 label = gtk_label_new(text ? text : ""); 7952 label = gtk_label_new(text ? text : "");
7945
7946 if(GTK_IS_GRID(page))
7947 {
7948 pad = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(page), "_dw_boxpad"));
7949 /* TODO: Add padding to page with no GtkContainer in GTK4 */
7950 pad = pad;
7951 }
7952 7953
7953 if(realpage != -1) 7954 if(realpage != -1)
7954 gtk_notebook_insert_page(GTK_NOTEBOOK(handle), page, label, realpage); 7955 gtk_notebook_insert_page(GTK_NOTEBOOK(handle), page, label, realpage);
7955 else if(num & ~(0xFF)) 7956 else if(num & ~(0xFF))
7956 gtk_notebook_insert_page(GTK_NOTEBOOK(handle), page, label, 0); 7957 gtk_notebook_insert_page(GTK_NOTEBOOK(handle), page, label, 0);