comparison gtk3/dw.c @ 1080:27e9a063fbb5

Committing initial version of dw_box_pack_at_index() for GTK2 and GTK3... This doesn't work yet in most cases (unless packing at the ends) due to how the table resizes... Fixes coming soon but I didn't want to break building in the meantime.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 28 Jun 2011 05:34:14 +0000
parents dbaf1b11c301
children f9232a52367a
comparison
equal deleted inserted replaced
1079:5d3acda4acd4 1080:27e9a063fbb5
8009 } 8009 }
8010 8010
8011 #define DW_EXPAND (GTK_EXPAND | GTK_SHRINK | GTK_FILL) 8011 #define DW_EXPAND (GTK_EXPAND | GTK_SHRINK | GTK_FILL)
8012 8012
8013 /* 8013 /*
8014 * Pack windows (widgets) into a box at an arbitrary location.
8015 * Parameters:
8016 * box: Window handle of the box to be packed into.
8017 * item: Window handle of the item to be back.
8018 * index: 0 based index of packed items.
8019 * width: Width in pixels of the item or -1 to be self determined.
8020 * height: Height in pixels of the item or -1 to be self determined.
8021 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
8022 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
8023 * pad: Number of pixels of padding around the item.
8024 */
8025 void dw_box_pack_at_index(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad)
8026 {
8027 int warn = FALSE, _locked_by_me = FALSE;
8028 GtkWidget *tmp, *tmpitem, *image = NULL;
8029 char *funcname = "dw_box_pack_at_index()";
8030
8031 if(!box)
8032 return;
8033
8034 /*
8035 * If you try and pack an item into itself VERY bad things can happen; like at least an
8036 * infinite loop on GTK! Lets be safe!
8037 */
8038 if(box == item)
8039 {
8040 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!");
8041 return;
8042 }
8043
8044 DW_MUTEX_LOCK;
8045
8046 if((tmp = g_object_get_data(G_OBJECT(box), "_dw_boxhandle")))
8047 box = tmp;
8048
8049 if(!item)
8050 {
8051 item = gtk_label_new("");
8052 gtk_widget_show_all(item);
8053 }
8054 else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap")))
8055 {
8056 GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image));
8057
8058 if(pixbuf)
8059 {
8060 int pwidth = gdk_pixbuf_get_width(pixbuf);
8061 int pheight = gdk_pixbuf_get_height(pixbuf);
8062
8063 if(pwidth > width || pheight > height)
8064 {
8065 pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR);
8066 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
8067 }
8068 }
8069 }
8070
8071 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle");
8072
8073 if(GTK_IS_TABLE(box))
8074 {
8075 int boxcount = (int)g_object_get_data(G_OBJECT(box), "_dw_boxcount");
8076 int boxtype = (int)g_object_get_data(G_OBJECT(box), "_dw_boxtype");
8077 int x, y;
8078
8079 /* If the item being packed is a box, then we use it's padding
8080 * instead of the padding specified on the pack line, this is
8081 * due to a bug in the OS/2 and Win32 renderer and a limitation
8082 * of the GtkTable class.
8083 */
8084 if(GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem)))
8085 {
8086 GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_eventbox");
8087
8088 /* NOTE: I left in the ability to pack boxes with a size,
8089 * this eliminates that by forcing the size to 0.
8090 */
8091 height = width = 0;
8092
8093 if(eventbox)
8094 {
8095 int boxpad = (int)g_object_get_data(G_OBJECT(item), "_dw_boxpad");
8096 gtk_container_add(GTK_CONTAINER(eventbox), item);
8097 gtk_container_set_border_width(GTK_CONTAINER(eventbox), boxpad);
8098 item = eventbox;
8099 }
8100 }
8101 else
8102 {
8103 /* Only show warning if item is not a box */
8104 warn = TRUE;
8105 }
8106
8107 /* Do some sanity bounds checking */
8108 if(index < 0)
8109 index = 0;
8110 if(index > boxcount)
8111 index = boxcount;
8112
8113 if(boxtype == DW_VERT)
8114 {
8115 x = 0;
8116 y = index;
8117 gtk_table_resize(GTK_TABLE(box), boxcount + 1, 1);
8118 }
8119 else
8120 {
8121 x = index;
8122 y = 0;
8123 gtk_table_resize(GTK_TABLE(box), 1, boxcount + 1);
8124 }
8125
8126 gtk_table_attach(GTK_TABLE(box), item, x, x + 1, y, y + 1, hsize ? DW_EXPAND : 0, vsize ? DW_EXPAND : 0, pad, pad);
8127 g_object_set_data(G_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount + 1));
8128 if(GTK_IS_SCROLLED_WINDOW(item))
8129 {
8130 gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(item), width);
8131 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(item), height);
8132 }
8133 else
8134 gtk_widget_set_size_request(item, width, height);
8135 if(GTK_IS_RADIO_BUTTON(item))
8136 {
8137 GSList *group;
8138 GtkWidget *groupstart = (GtkWidget *)g_object_get_data(G_OBJECT(box), "_dw_group");
8139
8140 if(groupstart)
8141 {
8142 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(groupstart));
8143 gtk_radio_button_set_group(GTK_RADIO_BUTTON(item), group);
8144 }
8145 else
8146 g_object_set_data(G_OBJECT(box), "_dw_group", (gpointer)item);
8147 }
8148 }
8149 else
8150 {
8151 GtkWidget *vbox = g_object_get_data(G_OBJECT(box), "_dw_vbox");
8152
8153 if(!vbox)
8154 {
8155 vbox = gtk_vbox_new(FALSE, 0);
8156 g_object_set_data(G_OBJECT(box), "_dw_vbox", vbox);
8157 gtk_container_add(GTK_CONTAINER(box), vbox);
8158 gtk_widget_show(vbox);
8159 }
8160
8161 gtk_container_set_border_width(GTK_CONTAINER(box), pad);
8162
8163 if(GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem)))
8164 {
8165 GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_eventbox");
8166
8167 /* NOTE: I left in the ability to pack boxes with a size,
8168 * this eliminates that by forcing the size to 0.
8169 */
8170 height = width = 0;
8171
8172 if(eventbox)
8173 {
8174 int boxpad = (int)g_object_get_data(G_OBJECT(item), "_dw_boxpad");
8175 gtk_container_add(GTK_CONTAINER(eventbox), item);
8176 gtk_container_set_border_width(GTK_CONTAINER(eventbox), boxpad);
8177 item = eventbox;
8178 }
8179 }
8180 else
8181 {
8182 /* Only show warning if item is not a box */
8183 warn = TRUE;
8184 }
8185
8186 gtk_box_pack_end(GTK_BOX(vbox), item, TRUE, TRUE, 0);
8187
8188 gtk_widget_set_size_request(item, width, height);
8189 g_object_set_data(G_OBJECT(box), "_dw_user", vbox);
8190 }
8191 DW_MUTEX_UNLOCK;
8192
8193 if(warn)
8194 {
8195 if ( width == 0 && hsize == FALSE )
8196 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item);
8197 if ( height == 0 && vsize == FALSE )
8198 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item);
8199 }
8200 }
8201
8202 /*
8014 * Pack windows (widgets) into a box from the end (or bottom). 8203 * Pack windows (widgets) into a box from the end (or bottom).
8015 * Parameters: 8204 * Parameters:
8016 * box: Window handle of the box to be packed into. 8205 * box: Window handle of the box to be packed into.
8017 * item: Window handle of the item to be back. 8206 * item: Window handle of the item to be back.
8018 * width: Width in pixels of the item or -1 to be self determined. 8207 * width: Width in pixels of the item or -1 to be self determined.
8023 */ 8212 */
8024 void dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) 8213 void dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
8025 { 8214 {
8026 int warn = FALSE, _locked_by_me = FALSE; 8215 int warn = FALSE, _locked_by_me = FALSE;
8027 GtkWidget *tmp, *tmpitem, *image = NULL; 8216 GtkWidget *tmp, *tmpitem, *image = NULL;
8217 char *funcname = "dw_box_pack_end()";
8028 8218
8029 if(!box) 8219 if(!box)
8030 return; 8220 return;
8031 8221
8032 /* 8222 /*
8033 * If you try and pack an item into itself VERY bad things can happen; like at least an 8223 * If you try and pack an item into itself VERY bad things can happen; like at least an
8034 * infinite loop on GTK! Lets be safe! 8224 * infinite loop on GTK! Lets be safe!
8035 */ 8225 */
8036 if(box == item) 8226 if(box == item)
8037 { 8227 {
8038 dw_messagebox("dw_box_pack_end()", DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!"); 8228 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!");
8039 return; 8229 return;
8040 } 8230 }
8041 8231
8042 DW_MUTEX_LOCK; 8232 DW_MUTEX_LOCK;
8043 8233
8174 DW_MUTEX_UNLOCK; 8364 DW_MUTEX_UNLOCK;
8175 8365
8176 if(warn) 8366 if(warn)
8177 { 8367 {
8178 if ( width == 0 && hsize == FALSE ) 8368 if ( width == 0 && hsize == FALSE )
8179 dw_messagebox("dw_box_pack_end()", DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); 8369 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item);
8180 if ( height == 0 && vsize == FALSE ) 8370 if ( height == 0 && vsize == FALSE )
8181 dw_messagebox("dw_box_pack_end()", DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item); 8371 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item);
8182 } 8372 }
8183 } 8373 }
8184 8374
8185 /* 8375 /*
8186 * Sets the size of a given window (widget). 8376 * Sets the size of a given window (widget).
9408 */ 9598 */
9409 void dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) 9599 void dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
9410 { 9600 {
9411 int warn = FALSE, _locked_by_me = FALSE; 9601 int warn = FALSE, _locked_by_me = FALSE;
9412 GtkWidget *tmp, *tmpitem, *image = NULL; 9602 GtkWidget *tmp, *tmpitem, *image = NULL;
9603 char *funcname = "dw_box_pack_start()";
9413 9604
9414 if ( !box ) 9605 if ( !box )
9415 return; 9606 return;
9416 9607
9417 /* 9608 /*
9418 * If you try and pack an item into itself VERY bad things can happen; like at least an 9609 * If you try and pack an item into itself VERY bad things can happen; like at least an
9419 * infinite loop on GTK! Lets be safe! 9610 * infinite loop on GTK! Lets be safe!
9420 */ 9611 */
9421 if ( box == item ) 9612 if ( box == item )
9422 { 9613 {
9423 dw_messagebox( "dw_box_pack_start()", DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!" ); 9614 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!" );
9424 return; 9615 return;
9425 } 9616 }
9426 9617
9427 DW_MUTEX_LOCK; 9618 DW_MUTEX_LOCK;
9428 9619
9570 DW_MUTEX_UNLOCK; 9761 DW_MUTEX_UNLOCK;
9571 9762
9572 if (warn) 9763 if (warn)
9573 { 9764 {
9574 if ( width == 0 && hsize == FALSE ) 9765 if ( width == 0 && hsize == FALSE )
9575 dw_messagebox("dw_box_pack_start()", DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); 9766 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item);
9576 if ( height == 0 && vsize == FALSE ) 9767 if ( height == 0 && vsize == FALSE )
9577 dw_messagebox("dw_box_pack_start()", DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item); 9768 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item);
9578 } 9769 }
9579 } 9770 }
9580 9771
9581 /* 9772 /*
9582 * Sets the default focus item for a window/dialog. 9773 * Sets the default focus item for a window/dialog.