comparison gtk3/dw.c @ 1087:173e49c2270f

Merge all 3 box packing functions into one internal function on GTK3.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 28 Jun 2011 20:04:27 +0000
parents f9232a52367a
children 0fc7387abfd1
comparison
equal deleted inserted replaced
1086:4254c9b6d50d 1087:173e49c2270f
8041 gtk_container_child_set(cont, widget, "top-attach", (oldpos + 1), "bottom-attach", (oldpos+2), NULL); 8041 gtk_container_child_set(cont, widget, "top-attach", (oldpos + 1), "bottom-attach", (oldpos+2), NULL);
8042 } 8042 }
8043 } 8043 }
8044 } 8044 }
8045 8045
8046 /* Internal box packing function called by the other 3 functions */
8047 void _dw_box_pack(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad, char *funcname)
8048 {
8049 int warn = FALSE, _locked_by_me = FALSE;
8050 GtkWidget *tmp, *tmpitem, *image = NULL;
8051
8052 if(!box)
8053 return;
8054
8055 /*
8056 * If you try and pack an item into itself VERY bad things can happen; like at least an
8057 * infinite loop on GTK! Lets be safe!
8058 */
8059 if(box == item)
8060 {
8061 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!");
8062 return;
8063 }
8064
8065 DW_MUTEX_LOCK;
8066
8067 if((tmp = g_object_get_data(G_OBJECT(box), "_dw_boxhandle")))
8068 box = tmp;
8069
8070 if(!item)
8071 {
8072 item = gtk_label_new("");
8073 gtk_widget_show_all(item);
8074 }
8075 else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap")))
8076 {
8077 GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image));
8078
8079 if(pixbuf)
8080 {
8081 int pwidth = gdk_pixbuf_get_width(pixbuf);
8082 int pheight = gdk_pixbuf_get_height(pixbuf);
8083
8084 if(pwidth > width || pheight > height)
8085 {
8086 pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR);
8087 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
8088 }
8089 }
8090 }
8091
8092 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle");
8093
8094 if(GTK_IS_TABLE(box))
8095 {
8096 int boxcount = (int)g_object_get_data(G_OBJECT(box), "_dw_boxcount");
8097 int boxtype = (int)g_object_get_data(G_OBJECT(box), "_dw_boxtype");
8098 int x, y;
8099
8100 /* If the item being packed is a box, then we use it's padding
8101 * instead of the padding specified on the pack line, this is
8102 * due to a bug in the OS/2 and Win32 renderer and a limitation
8103 * of the GtkTable class.
8104 */
8105 if(GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem)))
8106 {
8107 GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_eventbox");
8108
8109 /* NOTE: I left in the ability to pack boxes with a size,
8110 * this eliminates that by forcing the size to 0.
8111 */
8112 height = width = 0;
8113
8114 if(eventbox)
8115 {
8116 int boxpad = (int)g_object_get_data(G_OBJECT(item), "_dw_boxpad");
8117 gtk_container_add(GTK_CONTAINER(eventbox), item);
8118 gtk_container_set_border_width(GTK_CONTAINER(eventbox), boxpad);
8119 item = eventbox;
8120 }
8121 }
8122 else
8123 {
8124 /* Only show warning if item is not a box */
8125 warn = TRUE;
8126 }
8127
8128 /* Do some sanity bounds checking */
8129 if(index < 0)
8130 index = 0;
8131 if(index > boxcount)
8132 index = boxcount;
8133
8134 if(boxtype == DW_VERT)
8135 {
8136 x = 0;
8137 y = index;
8138 gtk_table_resize(GTK_TABLE(box), boxcount + 1, 1);
8139 }
8140 else
8141 {
8142 x = index;
8143 y = 0;
8144 gtk_table_resize(GTK_TABLE(box), 1, boxcount + 1);
8145 }
8146
8147 g_object_set_data(G_OBJECT(item), "_dw_table", box);
8148 if(index < boxcount)
8149 gtk_container_forall(GTK_CONTAINER(box),_rearrange_table, GINT_TO_POINTER(boxtype == DW_VERT ? index : -(index+1)));
8150 gtk_table_attach(GTK_TABLE(box), item, x, x + 1, y, y + 1, hsize ? DW_EXPAND : 0, vsize ? DW_EXPAND : 0, pad, pad);
8151 g_object_set_data(G_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount + 1));
8152 if(GTK_IS_SCROLLED_WINDOW(item))
8153 {
8154 gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(item), width);
8155 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(item), height);
8156 }
8157 else
8158 gtk_widget_set_size_request(item, width, height);
8159 if(GTK_IS_RADIO_BUTTON(item))
8160 {
8161 GSList *group;
8162 GtkWidget *groupstart = (GtkWidget *)g_object_get_data(G_OBJECT(box), "_dw_group");
8163
8164 if(groupstart)
8165 {
8166 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(groupstart));
8167 gtk_radio_button_set_group(GTK_RADIO_BUTTON(item), group);
8168 }
8169 else
8170 g_object_set_data(G_OBJECT(box), "_dw_group", (gpointer)item);
8171 }
8172 }
8173 else
8174 {
8175 GtkWidget *vbox = g_object_get_data(G_OBJECT(box), "_dw_vbox");
8176
8177 if(!vbox)
8178 {
8179 vbox = gtk_vbox_new(FALSE, 0);
8180 g_object_set_data(G_OBJECT(box), "_dw_vbox", vbox);
8181 gtk_container_add(GTK_CONTAINER(box), vbox);
8182 gtk_widget_show(vbox);
8183 }
8184
8185 gtk_container_set_border_width(GTK_CONTAINER(box), pad);
8186
8187 if(GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem)))
8188 {
8189 GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_eventbox");
8190
8191 /* NOTE: I left in the ability to pack boxes with a size,
8192 * this eliminates that by forcing the size to 0.
8193 */
8194 height = width = 0;
8195
8196 if(eventbox)
8197 {
8198 int boxpad = (int)g_object_get_data(G_OBJECT(item), "_dw_boxpad");
8199 gtk_container_add(GTK_CONTAINER(eventbox), item);
8200 gtk_container_set_border_width(GTK_CONTAINER(eventbox), boxpad);
8201 item = eventbox;
8202 }
8203 }
8204 else
8205 {
8206 /* Only show warning if item is not a box */
8207 warn = TRUE;
8208 }
8209
8210 gtk_box_pack_end(GTK_BOX(vbox), item, TRUE, TRUE, 0);
8211
8212 gtk_widget_set_size_request(item, width, height);
8213 g_object_set_data(G_OBJECT(box), "_dw_user", vbox);
8214 }
8215 DW_MUTEX_UNLOCK;
8216
8217 if(warn)
8218 {
8219 if ( width == 0 && hsize == FALSE )
8220 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item);
8221 if ( height == 0 && vsize == FALSE )
8222 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item);
8223 }
8224 }
8225
8046 /* 8226 /*
8047 * Pack windows (widgets) into a box at an arbitrary location. 8227 * Pack windows (widgets) into a box at an arbitrary location.
8048 * Parameters: 8228 * Parameters:
8049 * box: Window handle of the box to be packed into. 8229 * box: Window handle of the box to be packed into.
8050 * item: Window handle of the item to be back. 8230 * item: Window handle of the item to be back.
8053 * height: Height in pixels of the item or -1 to be self determined. 8233 * height: Height in pixels of the item or -1 to be self determined.
8054 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. 8234 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
8055 * vsize: TRUE if the window (widget) should expand vertically to fill space given. 8235 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
8056 * pad: Number of pixels of padding around the item. 8236 * pad: Number of pixels of padding around the item.
8057 */ 8237 */
8058 void dw_box_pack_at_index(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad) 8238 void API dw_box_pack_at_index(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad)
8059 { 8239 {
8060 int warn = FALSE, _locked_by_me = FALSE; 8240 _dw_box_pack(box, item, index, width, height, hsize, vsize, pad, "dw_box_pack_at_index()");
8061 GtkWidget *tmp, *tmpitem, *image = NULL; 8241 }
8062 char *funcname = "dw_box_pack_at_index()"; 8242
8063 8243 /*
8064 if(!box) 8244 * Pack windows (widgets) into a box from the start (or top).
8065 return;
8066
8067 /*
8068 * If you try and pack an item into itself VERY bad things can happen; like at least an
8069 * infinite loop on GTK! Lets be safe!
8070 */
8071 if(box == item)
8072 {
8073 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!");
8074 return;
8075 }
8076
8077 DW_MUTEX_LOCK;
8078
8079 if((tmp = g_object_get_data(G_OBJECT(box), "_dw_boxhandle")))
8080 box = tmp;
8081
8082 if(!item)
8083 {
8084 item = gtk_label_new("");
8085 gtk_widget_show_all(item);
8086 }
8087 else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap")))
8088 {
8089 GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image));
8090
8091 if(pixbuf)
8092 {
8093 int pwidth = gdk_pixbuf_get_width(pixbuf);
8094 int pheight = gdk_pixbuf_get_height(pixbuf);
8095
8096 if(pwidth > width || pheight > height)
8097 {
8098 pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR);
8099 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
8100 }
8101 }
8102 }
8103
8104 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle");
8105
8106 if(GTK_IS_TABLE(box))
8107 {
8108 int boxcount = (int)g_object_get_data(G_OBJECT(box), "_dw_boxcount");
8109 int boxtype = (int)g_object_get_data(G_OBJECT(box), "_dw_boxtype");
8110 int x, y;
8111
8112 /* If the item being packed is a box, then we use it's padding
8113 * instead of the padding specified on the pack line, this is
8114 * due to a bug in the OS/2 and Win32 renderer and a limitation
8115 * of the GtkTable class.
8116 */
8117 if(GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem)))
8118 {
8119 GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_eventbox");
8120
8121 /* NOTE: I left in the ability to pack boxes with a size,
8122 * this eliminates that by forcing the size to 0.
8123 */
8124 height = width = 0;
8125
8126 if(eventbox)
8127 {
8128 int boxpad = (int)g_object_get_data(G_OBJECT(item), "_dw_boxpad");
8129 gtk_container_add(GTK_CONTAINER(eventbox), item);
8130 gtk_container_set_border_width(GTK_CONTAINER(eventbox), boxpad);
8131 item = eventbox;
8132 }
8133 }
8134 else
8135 {
8136 /* Only show warning if item is not a box */
8137 warn = TRUE;
8138 }
8139
8140 /* Do some sanity bounds checking */
8141 if(index < 0)
8142 index = 0;
8143 if(index > boxcount)
8144 index = boxcount;
8145
8146 if(boxtype == DW_VERT)
8147 {
8148 x = 0;
8149 y = index;
8150 gtk_table_resize(GTK_TABLE(box), boxcount + 1, 1);
8151 }
8152 else
8153 {
8154 x = index;
8155 y = 0;
8156 gtk_table_resize(GTK_TABLE(box), 1, boxcount + 1);
8157 }
8158
8159 g_object_set_data(G_OBJECT(item), "_dw_table", box);
8160 gtk_container_forall(GTK_CONTAINER(box),_rearrange_table, GINT_TO_POINTER(boxtype == DW_VERT ? index : -(index+1)));
8161 gtk_table_attach(GTK_TABLE(box), item, x, x + 1, y, y + 1, hsize ? DW_EXPAND : 0, vsize ? DW_EXPAND : 0, pad, pad);
8162 g_object_set_data(G_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount + 1));
8163 if(GTK_IS_SCROLLED_WINDOW(item))
8164 {
8165 gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(item), width);
8166 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(item), height);
8167 }
8168 else
8169 gtk_widget_set_size_request(item, width, height);
8170 if(GTK_IS_RADIO_BUTTON(item))
8171 {
8172 GSList *group;
8173 GtkWidget *groupstart = (GtkWidget *)g_object_get_data(G_OBJECT(box), "_dw_group");
8174
8175 if(groupstart)
8176 {
8177 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(groupstart));
8178 gtk_radio_button_set_group(GTK_RADIO_BUTTON(item), group);
8179 }
8180 else
8181 g_object_set_data(G_OBJECT(box), "_dw_group", (gpointer)item);
8182 }
8183 }
8184 else
8185 {
8186 GtkWidget *vbox = g_object_get_data(G_OBJECT(box), "_dw_vbox");
8187
8188 if(!vbox)
8189 {
8190 vbox = gtk_vbox_new(FALSE, 0);
8191 g_object_set_data(G_OBJECT(box), "_dw_vbox", vbox);
8192 gtk_container_add(GTK_CONTAINER(box), vbox);
8193 gtk_widget_show(vbox);
8194 }
8195
8196 gtk_container_set_border_width(GTK_CONTAINER(box), pad);
8197
8198 if(GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem)))
8199 {
8200 GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_eventbox");
8201
8202 /* NOTE: I left in the ability to pack boxes with a size,
8203 * this eliminates that by forcing the size to 0.
8204 */
8205 height = width = 0;
8206
8207 if(eventbox)
8208 {
8209 int boxpad = (int)g_object_get_data(G_OBJECT(item), "_dw_boxpad");
8210 gtk_container_add(GTK_CONTAINER(eventbox), item);
8211 gtk_container_set_border_width(GTK_CONTAINER(eventbox), boxpad);
8212 item = eventbox;
8213 }
8214 }
8215 else
8216 {
8217 /* Only show warning if item is not a box */
8218 warn = TRUE;
8219 }
8220
8221 gtk_box_pack_end(GTK_BOX(vbox), item, TRUE, TRUE, 0);
8222
8223 gtk_widget_set_size_request(item, width, height);
8224 g_object_set_data(G_OBJECT(box), "_dw_user", vbox);
8225 }
8226 DW_MUTEX_UNLOCK;
8227
8228 if(warn)
8229 {
8230 if ( width == 0 && hsize == FALSE )
8231 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item);
8232 if ( height == 0 && vsize == FALSE )
8233 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item);
8234 }
8235 }
8236
8237 /*
8238 * Pack windows (widgets) into a box from the end (or bottom).
8239 * Parameters: 8245 * Parameters:
8240 * box: Window handle of the box to be packed into. 8246 * box: Window handle of the box to be packed into.
8241 * item: Window handle of the item to be back. 8247 * item: Window handle of the item to be back.
8242 * width: Width in pixels of the item or -1 to be self determined. 8248 * width: Width in pixels of the item or -1 to be self determined.
8243 * height: Height in pixels of the item or -1 to be self determined. 8249 * height: Height in pixels of the item or -1 to be self determined.
8244 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. 8250 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
8245 * vsize: TRUE if the window (widget) should expand vertically to fill space given. 8251 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
8246 * pad: Number of pixels of padding around the item. 8252 * pad: Number of pixels of padding around the item.
8247 */ 8253 */
8248 void dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) 8254 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
8249 { 8255 {
8250 int warn = FALSE, _locked_by_me = FALSE; 8256 /* 65536 is the table limit on GTK...
8251 GtkWidget *tmp, *tmpitem, *image = NULL; 8257 * seems like a high enough value we will never hit it here either.
8252 char *funcname = "dw_box_pack_end()"; 8258 */
8253 8259 _dw_box_pack(box, item, 65536, width, height, hsize, vsize, pad, "dw_box_pack_start()");
8254 if(!box) 8260 }
8255 return; 8261
8256 8262 /*
8257 /* 8263 * Pack windows (widgets) into a box from the end (or bottom).
8258 * If you try and pack an item into itself VERY bad things can happen; like at least an 8264 * Parameters:
8259 * infinite loop on GTK! Lets be safe! 8265 * box: Window handle of the box to be packed into.
8260 */ 8266 * item: Window handle of the item to be back.
8261 if(box == item) 8267 * width: Width in pixels of the item or -1 to be self determined.
8262 { 8268 * height: Height in pixels of the item or -1 to be self determined.
8263 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!"); 8269 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
8264 return; 8270 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
8265 } 8271 * pad: Number of pixels of padding around the item.
8266 8272 */
8267 DW_MUTEX_LOCK; 8273 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
8268 8274 {
8269 if((tmp = g_object_get_data(G_OBJECT(box), "_dw_boxhandle"))) 8275 _dw_box_pack(box, item, 0, width, height, hsize, vsize, pad, "dw_box_pack_end()");
8270 box = tmp;
8271
8272 if(!item)
8273 {
8274 item = gtk_label_new("");
8275 gtk_widget_show_all(item);
8276 }
8277 else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap")))
8278 {
8279 GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image));
8280
8281 if(pixbuf)
8282 {
8283 int pwidth = gdk_pixbuf_get_width(pixbuf);
8284 int pheight = gdk_pixbuf_get_height(pixbuf);
8285
8286 if(pwidth > width || pheight > height)
8287 {
8288 pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR);
8289 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
8290 }
8291 }
8292 }
8293
8294 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle");
8295
8296 if(GTK_IS_TABLE(box))
8297 {
8298 int boxcount = (int)g_object_get_data(G_OBJECT(box), "_dw_boxcount");
8299 int boxtype = (int)g_object_get_data(G_OBJECT(box), "_dw_boxtype");
8300
8301 /* If the item being packed is a box, then we use it's padding
8302 * instead of the padding specified on the pack line, this is
8303 * due to a bug in the OS/2 and Win32 renderer and a limitation
8304 * of the GtkTable class.
8305 */
8306 if(GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem)))
8307 {
8308 GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_eventbox");
8309
8310 /* NOTE: I left in the ability to pack boxes with a size,
8311 * this eliminates that by forcing the size to 0.
8312 */
8313 height = width = 0;
8314
8315 if(eventbox)
8316 {
8317 int boxpad = (int)g_object_get_data(G_OBJECT(item), "_dw_boxpad");
8318 gtk_container_add(GTK_CONTAINER(eventbox), item);
8319 gtk_container_set_border_width(GTK_CONTAINER(eventbox), boxpad);
8320 item = eventbox;
8321 }
8322 }
8323 else
8324 {
8325 /* Only show warning if item is not a box */
8326 warn = TRUE;
8327 }
8328
8329 if(boxtype == DW_VERT)
8330 gtk_table_resize(GTK_TABLE(box), boxcount + 1, 1);
8331 else
8332 gtk_table_resize(GTK_TABLE(box), 1, boxcount + 1);
8333
8334 g_object_set_data(G_OBJECT(item), "_dw_table", box);
8335 gtk_table_attach(GTK_TABLE(box), item, 0, 1, 0, 1, hsize ? DW_EXPAND : 0, vsize ? DW_EXPAND : 0, pad, pad);
8336 g_object_set_data(G_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount + 1));
8337 if(GTK_IS_SCROLLED_WINDOW(item))
8338 {
8339 gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(item), width);
8340 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(item), height);
8341 }
8342 else
8343 gtk_widget_set_size_request(item, width, height);
8344 if(GTK_IS_RADIO_BUTTON(item))
8345 {
8346 GSList *group;
8347 GtkWidget *groupstart = (GtkWidget *)g_object_get_data(G_OBJECT(box), "_dw_group");
8348
8349 if(groupstart)
8350 {
8351 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(groupstart));
8352 gtk_radio_button_set_group(GTK_RADIO_BUTTON(item), group);
8353 }
8354 else
8355 g_object_set_data(G_OBJECT(box), "_dw_group", (gpointer)item);
8356 }
8357 }
8358 else
8359 {
8360 GtkWidget *vbox = g_object_get_data(G_OBJECT(box), "_dw_vbox");
8361
8362 if(!vbox)
8363 {
8364 vbox = gtk_vbox_new(FALSE, 0);
8365 g_object_set_data(G_OBJECT(box), "_dw_vbox", vbox);
8366 gtk_container_add(GTK_CONTAINER(box), vbox);
8367 gtk_widget_show(vbox);
8368 }
8369
8370 gtk_container_set_border_width(GTK_CONTAINER(box), pad);
8371
8372 if(GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem)))
8373 {
8374 GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_eventbox");
8375
8376 /* NOTE: I left in the ability to pack boxes with a size,
8377 * this eliminates that by forcing the size to 0.
8378 */
8379 height = width = 0;
8380
8381 if(eventbox)
8382 {
8383 int boxpad = (int)g_object_get_data(G_OBJECT(item), "_dw_boxpad");
8384 gtk_container_add(GTK_CONTAINER(eventbox), item);
8385 gtk_container_set_border_width(GTK_CONTAINER(eventbox), boxpad);
8386 item = eventbox;
8387 }
8388 }
8389 else
8390 {
8391 /* Only show warning if item is not a box */
8392 warn = TRUE;
8393 }
8394
8395 gtk_box_pack_end(GTK_BOX(vbox), item, TRUE, TRUE, 0);
8396
8397 gtk_widget_set_size_request(item, width, height);
8398 g_object_set_data(G_OBJECT(box), "_dw_user", vbox);
8399 }
8400 DW_MUTEX_UNLOCK;
8401
8402 if(warn)
8403 {
8404 if ( width == 0 && hsize == FALSE )
8405 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item);
8406 if ( height == 0 && vsize == FALSE )
8407 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item);
8408 }
8409 } 8276 }
8410 8277
8411 /* 8278 /*
8412 * Sets the size of a given window (widget). 8279 * Sets the size of a given window (widget).
8413 * Parameters: 8280 * Parameters:
9620 DW_MUTEX_UNLOCK; 9487 DW_MUTEX_UNLOCK;
9621 return; 9488 return;
9622 } 9489 }
9623 9490
9624 /* 9491 /*
9625 * Pack windows (widgets) into a box from the start (or top).
9626 * Parameters:
9627 * box: Window handle of the box to be packed into.
9628 * item: Window handle of the item to be back.
9629 * width: Width in pixels of the item or -1 to be self determined.
9630 * height: Height in pixels of the item or -1 to be self determined.
9631 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
9632 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
9633 * pad: Number of pixels of padding around the item.
9634 */
9635 void dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
9636 {
9637 int warn = FALSE, _locked_by_me = FALSE;
9638 GtkWidget *tmp, *tmpitem, *image = NULL;
9639 char *funcname = "dw_box_pack_start()";
9640
9641 if ( !box )
9642 return;
9643
9644 /*
9645 * If you try and pack an item into itself VERY bad things can happen; like at least an
9646 * infinite loop on GTK! Lets be safe!
9647 */
9648 if ( box == item )
9649 {
9650 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!" );
9651 return;
9652 }
9653
9654 DW_MUTEX_LOCK;
9655
9656 if ((tmp = g_object_get_data(G_OBJECT(box), "_dw_boxhandle")))
9657 box = tmp;
9658
9659 if (!item)
9660 {
9661 item = gtk_label_new("");
9662 gtk_widget_show_all(item);
9663 }
9664 else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap")))
9665 {
9666 GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image));
9667
9668 if(pixbuf)
9669 {
9670 int pwidth = gdk_pixbuf_get_width(pixbuf);
9671 int pheight = gdk_pixbuf_get_height(pixbuf);
9672
9673 if(pwidth > width || pheight > height)
9674 {
9675 pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR);
9676 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
9677 }
9678 }
9679 }
9680
9681 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle");
9682
9683 if (GTK_IS_TABLE(box))
9684 {
9685 int boxcount = (int)g_object_get_data(G_OBJECT(box), "_dw_boxcount");
9686 int boxtype = (int)g_object_get_data(G_OBJECT(box), "_dw_boxtype");
9687 int x, y;
9688
9689 /* If the item being packed is a box, then we use it's padding
9690 * instead of the padding specified on the pack line, this is
9691 * due to a bug in the OS/2 and Win32 renderer and a limitation
9692 * of the GtkTable class.
9693 */
9694 if (GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem)))
9695 {
9696 GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_eventbox");
9697
9698 /* NOTE: I left in the ability to pack boxes with a size,
9699 * this eliminates that by forcing the size to 0.
9700 */
9701 height = width = 0;
9702
9703 if (eventbox)
9704 {
9705 int boxpad = (int)g_object_get_data(G_OBJECT(item), "_dw_boxpad");
9706 gtk_container_add(GTK_CONTAINER(eventbox), item);
9707 gtk_container_set_border_width(GTK_CONTAINER(eventbox), boxpad);
9708 item = eventbox;
9709 }
9710 }
9711 else
9712 {
9713 /* Only show warning if item is not a box */
9714 warn = TRUE;
9715 }
9716
9717 if (boxtype == DW_VERT)
9718 {
9719 x = 0;
9720 y = boxcount;
9721 gtk_table_resize(GTK_TABLE(box), boxcount + 1, 1);
9722 }
9723 else
9724 {
9725 x = boxcount;
9726 y = 0;
9727 gtk_table_resize(GTK_TABLE(box), 1, boxcount + 1);
9728 }
9729
9730 g_object_set_data(G_OBJECT(item), "_dw_table", box);
9731 gtk_table_attach(GTK_TABLE(box), item, x, x + 1, y, y + 1, hsize ? DW_EXPAND : 0, vsize ? DW_EXPAND : 0, pad, pad);
9732 g_object_set_data(G_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount + 1));
9733 if(GTK_IS_SCROLLED_WINDOW(item))
9734 {
9735 gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(item), width);
9736 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(item), height);
9737 }
9738 else
9739 gtk_widget_set_size_request(item, width, height);
9740 if (GTK_IS_RADIO_BUTTON(item))
9741 {
9742 GSList *group;
9743 GtkWidget *groupstart = (GtkWidget *)g_object_get_data(G_OBJECT(box), "_dw_group");
9744
9745 if (groupstart)
9746 {
9747 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(groupstart));
9748 gtk_radio_button_set_group(GTK_RADIO_BUTTON(item), group);
9749 }
9750 else
9751 {
9752 g_object_set_data(G_OBJECT(box), "_dw_group", (gpointer)item);
9753 }
9754 }
9755 }
9756 else
9757 {
9758 GtkWidget *vbox = g_object_get_data(G_OBJECT(box), "_dw_vbox");
9759
9760 if(!vbox)
9761 {
9762 vbox = gtk_vbox_new(FALSE, 0);
9763 g_object_set_data(G_OBJECT(box), "_dw_vbox", vbox);
9764 gtk_container_add(GTK_CONTAINER(box), vbox);
9765 gtk_widget_show(vbox);
9766 }
9767
9768 gtk_container_set_border_width(GTK_CONTAINER(box), pad);
9769
9770 if (GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem)))
9771 {
9772 GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_eventbox");
9773
9774 /* NOTE: I left in the ability to pack boxes with a size,
9775 * this eliminates that by forcing the size to 0.
9776 */
9777 height = width = 0;
9778
9779 if (eventbox)
9780 {
9781 int boxpad = (int)g_object_get_data(G_OBJECT(item), "_dw_boxpad");
9782 gtk_container_add(GTK_CONTAINER(eventbox), item);
9783 gtk_container_set_border_width(GTK_CONTAINER(eventbox), boxpad);
9784 item = eventbox;
9785 }
9786 }
9787 else
9788 {
9789 /* Only show warning if item is not a box */
9790 warn = TRUE;
9791 }
9792
9793 gtk_box_pack_end(GTK_BOX(vbox), item, TRUE, TRUE, 0);
9794
9795 gtk_widget_set_size_request(item, width, height);
9796 g_object_set_data(G_OBJECT(box), "_dw_user", vbox);
9797 }
9798 DW_MUTEX_UNLOCK;
9799
9800 if (warn)
9801 {
9802 if ( width == 0 && hsize == FALSE )
9803 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item);
9804 if ( height == 0 && vsize == FALSE )
9805 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item);
9806 }
9807 }
9808
9809 /*
9810 * Sets the default focus item for a window/dialog. 9492 * Sets the default focus item for a window/dialog.
9811 * Parameters: 9493 * Parameters:
9812 * window: Toplevel window or dialog. 9494 * window: Toplevel window or dialog.
9813 * defaultitem: Handle to the dialog item to be default. 9495 * defaultitem: Handle to the dialog item to be default.
9814 */ 9496 */