Mercurial > dwindows
comparison gtk/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 | 7821a35e1e11 |
comparison
equal
deleted
inserted
replaced
1079:5d3acda4acd4 | 1080:27e9a063fbb5 |
---|---|
9125 } | 9125 } |
9126 | 9126 |
9127 #define DW_EXPAND (GTK_EXPAND | GTK_SHRINK | GTK_FILL) | 9127 #define DW_EXPAND (GTK_EXPAND | GTK_SHRINK | GTK_FILL) |
9128 | 9128 |
9129 /* | 9129 /* |
9130 * Pack windows (widgets) into a box at an arbitrary location. | |
9131 * Parameters: | |
9132 * box: Window handle of the box to be packed into. | |
9133 * item: Window handle of the item to be back. | |
9134 * index: 0 based index of packed items. | |
9135 * width: Width in pixels of the item or -1 to be self determined. | |
9136 * height: Height in pixels of the item or -1 to be self determined. | |
9137 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. | |
9138 * vsize: TRUE if the window (widget) should expand vertically to fill space given. | |
9139 * pad: Number of pixels of padding around the item. | |
9140 */ | |
9141 void dw_box_pack_at_index(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad) | |
9142 { | |
9143 int warn = FALSE, _locked_by_me = FALSE; | |
9144 GtkWidget *tmp, *tmpitem, *image = NULL; | |
9145 char *funcname = "dw_box_pack_at_index()"; | |
9146 | |
9147 if(!box) | |
9148 return; | |
9149 | |
9150 /* | |
9151 * If you try and pack an item into itself VERY bad things can happen; like at least an | |
9152 * infinite loop on GTK! Lets be safe! | |
9153 */ | |
9154 if(box == item) | |
9155 { | |
9156 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!"); | |
9157 return; | |
9158 } | |
9159 | |
9160 DW_MUTEX_LOCK; | |
9161 | |
9162 if((tmp = g_object_get_data(G_OBJECT(box), "_dw_boxhandle"))) | |
9163 box = tmp; | |
9164 | |
9165 if(!item) | |
9166 { | |
9167 item = gtk_label_new(""); | |
9168 gtk_widget_show_all(item); | |
9169 } | |
9170 else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap"))) | |
9171 { | |
9172 GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image)); | |
9173 | |
9174 if(pixbuf) | |
9175 { | |
9176 int pwidth = gdk_pixbuf_get_width(pixbuf); | |
9177 int pheight = gdk_pixbuf_get_height(pixbuf); | |
9178 | |
9179 if(pwidth > width || pheight > height) | |
9180 { | |
9181 pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR); | |
9182 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); | |
9183 } | |
9184 } | |
9185 } | |
9186 | |
9187 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle"); | |
9188 | |
9189 if(GTK_IS_TABLE(box)) | |
9190 { | |
9191 int boxcount = (int)g_object_get_data(G_OBJECT(box), "_dw_boxcount"); | |
9192 int boxtype = (int)g_object_get_data(G_OBJECT(box), "_dw_boxtype"); | |
9193 int x, y; | |
9194 | |
9195 /* If the item being packed is a box, then we use it's padding | |
9196 * instead of the padding specified on the pack line, this is | |
9197 * due to a bug in the OS/2 and Win32 renderer and a limitation | |
9198 * of the GtkTable class. | |
9199 */ | |
9200 if(GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem))) | |
9201 { | |
9202 GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_eventbox"); | |
9203 | |
9204 /* NOTE: I left in the ability to pack boxes with a size, | |
9205 * this eliminates that by forcing the size to 0. | |
9206 */ | |
9207 height = width = 0; | |
9208 | |
9209 if(eventbox) | |
9210 { | |
9211 int boxpad = (int)g_object_get_data(G_OBJECT(item), "_dw_boxpad"); | |
9212 gtk_container_add(GTK_CONTAINER(eventbox), item); | |
9213 gtk_container_set_border_width(GTK_CONTAINER(eventbox), boxpad); | |
9214 item = eventbox; | |
9215 } | |
9216 } | |
9217 else | |
9218 { | |
9219 /* Only show warning if item is not a box */ | |
9220 warn = TRUE; | |
9221 } | |
9222 | |
9223 /* Do some sanity bounds checking */ | |
9224 if(index < 0) | |
9225 index = 0; | |
9226 if(index > boxcount) | |
9227 index = boxcount; | |
9228 | |
9229 if(boxtype == DW_VERT) | |
9230 { | |
9231 x = 0; | |
9232 y = index; | |
9233 gtk_table_resize(GTK_TABLE(box), boxcount + 1, 1); | |
9234 } | |
9235 else | |
9236 { | |
9237 x = index; | |
9238 y = 0; | |
9239 gtk_table_resize(GTK_TABLE(box), 1, boxcount + 1); | |
9240 } | |
9241 | |
9242 gtk_table_attach(GTK_TABLE(box), item, x, x + 1, y, y + 1, hsize ? DW_EXPAND : 0, vsize ? DW_EXPAND : 0, pad, pad); | |
9243 g_object_set_data(G_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount + 1)); | |
9244 gtk_widget_set_usize(item, width, height); | |
9245 if(GTK_IS_RADIO_BUTTON(item)) | |
9246 { | |
9247 GSList *group; | |
9248 GtkWidget *groupstart = (GtkWidget *)g_object_get_data(G_OBJECT(box), "_dw_group"); | |
9249 | |
9250 if(groupstart) | |
9251 { | |
9252 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(groupstart)); | |
9253 gtk_radio_button_set_group(GTK_RADIO_BUTTON(item), group); | |
9254 } | |
9255 else | |
9256 g_object_set_data(G_OBJECT(box), "_dw_group", (gpointer)item); | |
9257 } | |
9258 } | |
9259 else | |
9260 { | |
9261 GtkWidget *vbox = g_object_get_data(G_OBJECT(box), "_dw_vbox"); | |
9262 | |
9263 if(!vbox) | |
9264 { | |
9265 vbox = gtk_vbox_new(FALSE, 0); | |
9266 g_object_set_data(G_OBJECT(box), "_dw_vbox", vbox); | |
9267 gtk_container_add(GTK_CONTAINER(box), vbox); | |
9268 gtk_widget_show(vbox); | |
9269 } | |
9270 | |
9271 gtk_container_set_border_width(GTK_CONTAINER(box), pad); | |
9272 | |
9273 if(GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem))) | |
9274 { | |
9275 GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_eventbox"); | |
9276 | |
9277 /* NOTE: I left in the ability to pack boxes with a size, | |
9278 * this eliminates that by forcing the size to 0. | |
9279 */ | |
9280 height = width = 0; | |
9281 | |
9282 if(eventbox) | |
9283 { | |
9284 int boxpad = (int)g_object_get_data(G_OBJECT(item), "_dw_boxpad"); | |
9285 gtk_container_add(GTK_CONTAINER(eventbox), item); | |
9286 gtk_container_set_border_width(GTK_CONTAINER(eventbox), boxpad); | |
9287 item = eventbox; | |
9288 } | |
9289 } | |
9290 else | |
9291 { | |
9292 /* Only show warning if item is not a box */ | |
9293 warn = TRUE; | |
9294 } | |
9295 | |
9296 gtk_box_pack_end(GTK_BOX(vbox), item, TRUE, TRUE, 0); | |
9297 | |
9298 gtk_widget_set_usize(item, width, height); | |
9299 g_object_set_data(G_OBJECT(box), "_dw_user", vbox); | |
9300 } | |
9301 DW_MUTEX_UNLOCK; | |
9302 | |
9303 if(warn) | |
9304 { | |
9305 if ( width == 0 && hsize == FALSE ) | |
9306 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); | |
9307 if ( height == 0 && vsize == FALSE ) | |
9308 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item); | |
9309 } | |
9310 } | |
9311 | |
9312 /* | |
9130 * Pack windows (widgets) into a box from the end (or bottom). | 9313 * Pack windows (widgets) into a box from the end (or bottom). |
9131 * Parameters: | 9314 * Parameters: |
9132 * box: Window handle of the box to be packed into. | 9315 * box: Window handle of the box to be packed into. |
9133 * item: Window handle of the item to be back. | 9316 * item: Window handle of the item to be back. |
9134 * width: Width in pixels of the item or -1 to be self determined. | 9317 * width: Width in pixels of the item or -1 to be self determined. |
9139 */ | 9322 */ |
9140 void dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | 9323 void dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) |
9141 { | 9324 { |
9142 int warn = FALSE, _locked_by_me = FALSE; | 9325 int warn = FALSE, _locked_by_me = FALSE; |
9143 GtkWidget *tmp, *tmpitem; | 9326 GtkWidget *tmp, *tmpitem; |
9327 char *funcname = "dw_box_pack_end()"; | |
9144 | 9328 |
9145 if(!box) | 9329 if(!box) |
9146 return; | 9330 return; |
9147 | 9331 |
9148 /* | 9332 /* |
9149 * If you try and pack an item into itself VERY bad things can happen; like at least an | 9333 * If you try and pack an item into itself VERY bad things can happen; like at least an |
9150 * infinite loop on GTK! Lets be safe! | 9334 * infinite loop on GTK! Lets be safe! |
9151 */ | 9335 */ |
9152 if(box == item) | 9336 if(box == item) |
9153 { | 9337 { |
9154 dw_messagebox("dw_box_pack_end()", DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!"); | 9338 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!"); |
9155 return; | 9339 return; |
9156 } | 9340 } |
9157 | 9341 |
9158 DW_MUTEX_LOCK; | 9342 DW_MUTEX_LOCK; |
9159 | 9343 |
9268 DW_MUTEX_UNLOCK; | 9452 DW_MUTEX_UNLOCK; |
9269 | 9453 |
9270 if(warn) | 9454 if(warn) |
9271 { | 9455 { |
9272 if ( width == 0 && hsize == FALSE ) | 9456 if ( width == 0 && hsize == FALSE ) |
9273 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); | 9457 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); |
9274 if ( height == 0 && vsize == FALSE ) | 9458 if ( height == 0 && vsize == FALSE ) |
9275 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); | 9459 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item); |
9276 } | 9460 } |
9277 } | 9461 } |
9278 | 9462 |
9279 /* | 9463 /* |
9280 * Sets the size of a given window (widget). | 9464 * Sets the size of a given window (widget). |
10608 */ | 10792 */ |
10609 void dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | 10793 void dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) |
10610 { | 10794 { |
10611 int warn = FALSE, _locked_by_me = FALSE; | 10795 int warn = FALSE, _locked_by_me = FALSE; |
10612 GtkWidget *tmp, *tmpitem; | 10796 GtkWidget *tmp, *tmpitem; |
10797 char *funcname = "dw_box_pack_start()"; | |
10613 | 10798 |
10614 if ( !box ) | 10799 if ( !box ) |
10615 return; | 10800 return; |
10616 | 10801 |
10617 /* | 10802 /* |
10618 * If you try and pack an item into itself VERY bad things can happen; like at least an | 10803 * If you try and pack an item into itself VERY bad things can happen; like at least an |
10619 * infinite loop on GTK! Lets be safe! | 10804 * infinite loop on GTK! Lets be safe! |
10620 */ | 10805 */ |
10621 if ( box == item ) | 10806 if ( box == item ) |
10622 { | 10807 { |
10623 dw_messagebox( "dw_box_pack_start()", DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!" ); | 10808 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!" ); |
10624 return; | 10809 return; |
10625 } | 10810 } |
10626 | 10811 |
10627 DW_MUTEX_LOCK; | 10812 DW_MUTEX_LOCK; |
10628 | 10813 |
10748 DW_MUTEX_UNLOCK; | 10933 DW_MUTEX_UNLOCK; |
10749 | 10934 |
10750 if (warn) | 10935 if (warn) |
10751 { | 10936 { |
10752 if ( width == 0 && hsize == FALSE ) | 10937 if ( width == 0 && hsize == FALSE ) |
10753 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); | 10938 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); |
10754 if ( height == 0 && vsize == FALSE ) | 10939 if ( height == 0 && vsize == FALSE ) |
10755 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); | 10940 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item); |
10756 } | 10941 } |
10757 } | 10942 } |
10758 | 10943 |
10759 /* | 10944 /* |
10760 * Sets the default focus item for a window/dialog. | 10945 * Sets the default focus item for a window/dialog. |