comparison gtk/dw.c @ 1088:97c221691665

Merge all 3 box packing functions into one internal function on GTK2.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 28 Jun 2011 20:17:22 +0000
parents 7821a35e1e11
children 99899e6b51c2
comparison
equal deleted inserted replaced
1087:173e49c2270f 1088:97c221691665
9157 gtk_container_child_set(cont, widget, "top-attach", (oldpos + 1), "bottom-attach", (oldpos+2), NULL); 9157 gtk_container_child_set(cont, widget, "top-attach", (oldpos + 1), "bottom-attach", (oldpos+2), NULL);
9158 } 9158 }
9159 } 9159 }
9160 } 9160 }
9161 9161
9162 /* Internal box packing function called by the other 3 functions */
9163 void _dw_box_pack(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad, char *funcname)
9164 {
9165 int warn = FALSE, _locked_by_me = FALSE;
9166 GtkWidget *tmp, *tmpitem, *image = NULL;
9167
9168 if(!box)
9169 return;
9170
9171 /*
9172 * If you try and pack an item into itself VERY bad things can happen; like at least an
9173 * infinite loop on GTK! Lets be safe!
9174 */
9175 if(box == item)
9176 {
9177 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!");
9178 return;
9179 }
9180
9181 DW_MUTEX_LOCK;
9182
9183 if((tmp = g_object_get_data(G_OBJECT(box), "_dw_boxhandle")))
9184 box = tmp;
9185
9186 if(!item)
9187 {
9188 item = gtk_label_new("");
9189 gtk_widget_show_all(item);
9190 }
9191 else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap")))
9192 {
9193 GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image));
9194
9195 if(pixbuf)
9196 {
9197 int pwidth = gdk_pixbuf_get_width(pixbuf);
9198 int pheight = gdk_pixbuf_get_height(pixbuf);
9199
9200 if(pwidth > width || pheight > height)
9201 {
9202 pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR);
9203 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
9204 }
9205 }
9206 }
9207
9208 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle");
9209
9210 if(GTK_IS_TABLE(box))
9211 {
9212 int boxcount = (int)g_object_get_data(G_OBJECT(box), "_dw_boxcount");
9213 int boxtype = (int)g_object_get_data(G_OBJECT(box), "_dw_boxtype");
9214 int x, y;
9215
9216 /* If the item being packed is a box, then we use it's padding
9217 * instead of the padding specified on the pack line, this is
9218 * due to a bug in the OS/2 and Win32 renderer and a limitation
9219 * of the GtkTable class.
9220 */
9221 if(GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem)))
9222 {
9223 GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_eventbox");
9224
9225 /* NOTE: I left in the ability to pack boxes with a size,
9226 * this eliminates that by forcing the size to 0.
9227 */
9228 height = width = 0;
9229
9230 if(eventbox)
9231 {
9232 int boxpad = (int)g_object_get_data(G_OBJECT(item), "_dw_boxpad");
9233 gtk_container_add(GTK_CONTAINER(eventbox), item);
9234 gtk_container_set_border_width(GTK_CONTAINER(eventbox), boxpad);
9235 item = eventbox;
9236 }
9237 }
9238 else
9239 {
9240 /* Only show warning if item is not a box */
9241 warn = TRUE;
9242 }
9243
9244 /* Do some sanity bounds checking */
9245 if(index < 0)
9246 index = 0;
9247 if(index > boxcount)
9248 index = boxcount;
9249
9250 if(boxtype == DW_VERT)
9251 {
9252 x = 0;
9253 y = index;
9254 gtk_table_resize(GTK_TABLE(box), boxcount + 1, 1);
9255 }
9256 else
9257 {
9258 x = index;
9259 y = 0;
9260 gtk_table_resize(GTK_TABLE(box), 1, boxcount + 1);
9261 }
9262
9263 gtk_object_set_data(GTK_OBJECT(item), "_dw_table", box);
9264 if(index < boxcount)
9265 gtk_container_forall(GTK_CONTAINER(box),_rearrange_table, GINT_TO_POINTER(boxtype == DW_VERT ? index : -(index+1)));
9266 gtk_table_attach(GTK_TABLE(box), item, x, x + 1, y, y + 1, hsize ? DW_EXPAND : 0, vsize ? DW_EXPAND : 0, pad, pad);
9267 gtk_object_set_data(GTK_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount + 1));
9268 gtk_widget_set_usize(item, width, height);
9269 if(GTK_IS_RADIO_BUTTON(item))
9270 {
9271 GSList *group;
9272 GtkWidget *groupstart = (GtkWidget *)g_object_get_data(G_OBJECT(box), "_dw_group");
9273
9274 if(groupstart)
9275 {
9276 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(groupstart));
9277 gtk_radio_button_set_group(GTK_RADIO_BUTTON(item), group);
9278 }
9279 else
9280 g_object_set_data(G_OBJECT(box), "_dw_group", (gpointer)item);
9281 }
9282 }
9283 else
9284 {
9285 GtkWidget *vbox = g_object_get_data(G_OBJECT(box), "_dw_vbox");
9286
9287 if(!vbox)
9288 {
9289 vbox = gtk_vbox_new(FALSE, 0);
9290 g_object_set_data(G_OBJECT(box), "_dw_vbox", vbox);
9291 gtk_container_add(GTK_CONTAINER(box), vbox);
9292 gtk_widget_show(vbox);
9293 }
9294
9295 gtk_container_set_border_width(GTK_CONTAINER(box), pad);
9296
9297 if(GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem)))
9298 {
9299 GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_eventbox");
9300
9301 /* NOTE: I left in the ability to pack boxes with a size,
9302 * this eliminates that by forcing the size to 0.
9303 */
9304 height = width = 0;
9305
9306 if(eventbox)
9307 {
9308 int boxpad = (int)g_object_get_data(G_OBJECT(item), "_dw_boxpad");
9309 gtk_container_add(GTK_CONTAINER(eventbox), item);
9310 gtk_container_set_border_width(GTK_CONTAINER(eventbox), boxpad);
9311 item = eventbox;
9312 }
9313 }
9314 else
9315 {
9316 /* Only show warning if item is not a box */
9317 warn = TRUE;
9318 }
9319
9320 gtk_box_pack_end(GTK_BOX(vbox), item, TRUE, TRUE, 0);
9321
9322 gtk_widget_set_usize(item, width, height);
9323 g_object_set_data(G_OBJECT(box), "_dw_user", vbox);
9324 }
9325 DW_MUTEX_UNLOCK;
9326
9327 if(warn)
9328 {
9329 if ( width == 0 && hsize == FALSE )
9330 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item);
9331 if ( height == 0 && vsize == FALSE )
9332 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item);
9333 }
9334 }
9335
9162 /* 9336 /*
9163 * Pack windows (widgets) into a box at an arbitrary location. 9337 * Pack windows (widgets) into a box at an arbitrary location.
9164 * Parameters: 9338 * Parameters:
9165 * box: Window handle of the box to be packed into. 9339 * box: Window handle of the box to be packed into.
9166 * item: Window handle of the item to be back. 9340 * item: Window handle of the item to be back.
9169 * height: Height in pixels of the item or -1 to be self determined. 9343 * height: Height in pixels of the item or -1 to be self determined.
9170 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. 9344 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
9171 * vsize: TRUE if the window (widget) should expand vertically to fill space given. 9345 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
9172 * pad: Number of pixels of padding around the item. 9346 * pad: Number of pixels of padding around the item.
9173 */ 9347 */
9174 void dw_box_pack_at_index(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad) 9348 void API dw_box_pack_at_index(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad)
9175 { 9349 {
9176 int warn = FALSE, _locked_by_me = FALSE; 9350 _dw_box_pack(box, item, index, width, height, hsize, vsize, pad, "dw_box_pack_at_index()");
9177 GtkWidget *tmp, *tmpitem, *image = NULL; 9351 }
9178 char *funcname = "dw_box_pack_at_index()"; 9352
9179 9353 /*
9180 if(!box) 9354 * Pack windows (widgets) into a box from the start (or top).
9181 return;
9182
9183 /*
9184 * If you try and pack an item into itself VERY bad things can happen; like at least an
9185 * infinite loop on GTK! Lets be safe!
9186 */
9187 if(box == item)
9188 {
9189 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!");
9190 return;
9191 }
9192
9193 DW_MUTEX_LOCK;
9194
9195 if((tmp = g_object_get_data(G_OBJECT(box), "_dw_boxhandle")))
9196 box = tmp;
9197
9198 if(!item)
9199 {
9200 item = gtk_label_new("");
9201 gtk_widget_show_all(item);
9202 }
9203 else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap")))
9204 {
9205 GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image));
9206
9207 if(pixbuf)
9208 {
9209 int pwidth = gdk_pixbuf_get_width(pixbuf);
9210 int pheight = gdk_pixbuf_get_height(pixbuf);
9211
9212 if(pwidth > width || pheight > height)
9213 {
9214 pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR);
9215 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
9216 }
9217 }
9218 }
9219
9220 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle");
9221
9222 if(GTK_IS_TABLE(box))
9223 {
9224 int boxcount = (int)g_object_get_data(G_OBJECT(box), "_dw_boxcount");
9225 int boxtype = (int)g_object_get_data(G_OBJECT(box), "_dw_boxtype");
9226 int x, y;
9227
9228 /* If the item being packed is a box, then we use it's padding
9229 * instead of the padding specified on the pack line, this is
9230 * due to a bug in the OS/2 and Win32 renderer and a limitation
9231 * of the GtkTable class.
9232 */
9233 if(GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem)))
9234 {
9235 GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_eventbox");
9236
9237 /* NOTE: I left in the ability to pack boxes with a size,
9238 * this eliminates that by forcing the size to 0.
9239 */
9240 height = width = 0;
9241
9242 if(eventbox)
9243 {
9244 int boxpad = (int)g_object_get_data(G_OBJECT(item), "_dw_boxpad");
9245 gtk_container_add(GTK_CONTAINER(eventbox), item);
9246 gtk_container_set_border_width(GTK_CONTAINER(eventbox), boxpad);
9247 item = eventbox;
9248 }
9249 }
9250 else
9251 {
9252 /* Only show warning if item is not a box */
9253 warn = TRUE;
9254 }
9255
9256 /* Do some sanity bounds checking */
9257 if(index < 0)
9258 index = 0;
9259 if(index > boxcount)
9260 index = boxcount;
9261
9262 if(boxtype == DW_VERT)
9263 {
9264 x = 0;
9265 y = index;
9266 gtk_table_resize(GTK_TABLE(box), boxcount + 1, 1);
9267 }
9268 else
9269 {
9270 x = index;
9271 y = 0;
9272 gtk_table_resize(GTK_TABLE(box), 1, boxcount + 1);
9273 }
9274
9275 gtk_object_set_data(GTK_OBJECT(item), "_dw_table", box);
9276 gtk_container_forall(GTK_CONTAINER(box),_rearrange_table, GINT_TO_POINTER(boxtype == DW_VERT ? index : -(index+1)));
9277 gtk_table_attach(GTK_TABLE(box), item, x, x + 1, y, y + 1, hsize ? DW_EXPAND : 0, vsize ? DW_EXPAND : 0, pad, pad);
9278 gtk_object_set_data(GTK_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount + 1));
9279 gtk_widget_set_usize(item, width, height);
9280 if(GTK_IS_RADIO_BUTTON(item))
9281 {
9282 GSList *group;
9283 GtkWidget *groupstart = (GtkWidget *)g_object_get_data(G_OBJECT(box), "_dw_group");
9284
9285 if(groupstart)
9286 {
9287 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(groupstart));
9288 gtk_radio_button_set_group(GTK_RADIO_BUTTON(item), group);
9289 }
9290 else
9291 g_object_set_data(G_OBJECT(box), "_dw_group", (gpointer)item);
9292 }
9293 }
9294 else
9295 {
9296 GtkWidget *vbox = g_object_get_data(G_OBJECT(box), "_dw_vbox");
9297
9298 if(!vbox)
9299 {
9300 vbox = gtk_vbox_new(FALSE, 0);
9301 g_object_set_data(G_OBJECT(box), "_dw_vbox", vbox);
9302 gtk_container_add(GTK_CONTAINER(box), vbox);
9303 gtk_widget_show(vbox);
9304 }
9305
9306 gtk_container_set_border_width(GTK_CONTAINER(box), pad);
9307
9308 if(GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem)))
9309 {
9310 GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_eventbox");
9311
9312 /* NOTE: I left in the ability to pack boxes with a size,
9313 * this eliminates that by forcing the size to 0.
9314 */
9315 height = width = 0;
9316
9317 if(eventbox)
9318 {
9319 int boxpad = (int)g_object_get_data(G_OBJECT(item), "_dw_boxpad");
9320 gtk_container_add(GTK_CONTAINER(eventbox), item);
9321 gtk_container_set_border_width(GTK_CONTAINER(eventbox), boxpad);
9322 item = eventbox;
9323 }
9324 }
9325 else
9326 {
9327 /* Only show warning if item is not a box */
9328 warn = TRUE;
9329 }
9330
9331 gtk_box_pack_end(GTK_BOX(vbox), item, TRUE, TRUE, 0);
9332
9333 gtk_widget_set_usize(item, width, height);
9334 g_object_set_data(G_OBJECT(box), "_dw_user", vbox);
9335 }
9336 DW_MUTEX_UNLOCK;
9337
9338 if(warn)
9339 {
9340 if ( width == 0 && hsize == FALSE )
9341 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item);
9342 if ( height == 0 && vsize == FALSE )
9343 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item);
9344 }
9345 }
9346
9347 /*
9348 * Pack windows (widgets) into a box from the end (or bottom).
9349 * Parameters: 9355 * Parameters:
9350 * box: Window handle of the box to be packed into. 9356 * box: Window handle of the box to be packed into.
9351 * item: Window handle of the item to be back. 9357 * item: Window handle of the item to be back.
9352 * width: Width in pixels of the item or -1 to be self determined. 9358 * width: Width in pixels of the item or -1 to be self determined.
9353 * height: Height in pixels of the item or -1 to be self determined. 9359 * height: Height in pixels of the item or -1 to be self determined.
9354 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. 9360 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
9355 * vsize: TRUE if the window (widget) should expand vertically to fill space given. 9361 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
9356 * pad: Number of pixels of padding around the item. 9362 * pad: Number of pixels of padding around the item.
9357 */ 9363 */
9358 void dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) 9364 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
9359 { 9365 {
9360 int warn = FALSE, _locked_by_me = FALSE; 9366 /* 65536 is the table limit on GTK...
9361 GtkWidget *tmp, *tmpitem; 9367 * seems like a high enough value we will never hit it here either.
9362 char *funcname = "dw_box_pack_end()"; 9368 */
9363 9369 _dw_box_pack(box, item, 65536, width, height, hsize, vsize, pad, "dw_box_pack_start()");
9364 if(!box) 9370 }
9365 return; 9371
9366 9372 /*
9367 /* 9373 * Pack windows (widgets) into a box from the end (or bottom).
9368 * If you try and pack an item into itself VERY bad things can happen; like at least an 9374 * Parameters:
9369 * infinite loop on GTK! Lets be safe! 9375 * box: Window handle of the box to be packed into.
9370 */ 9376 * item: Window handle of the item to be back.
9371 if(box == item) 9377 * width: Width in pixels of the item or -1 to be self determined.
9372 { 9378 * height: Height in pixels of the item or -1 to be self determined.
9373 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!"); 9379 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
9374 return; 9380 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
9375 } 9381 * pad: Number of pixels of padding around the item.
9376 9382 */
9377 DW_MUTEX_LOCK; 9383 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
9378 9384 {
9379 if((tmp = gtk_object_get_data(GTK_OBJECT(box), "_dw_boxhandle"))) 9385 _dw_box_pack(box, item, 0, width, height, hsize, vsize, pad, "dw_box_pack_end()");
9380 box = tmp;
9381
9382 if(!item)
9383 {
9384 item = gtk_label_new("");
9385 gtk_widget_show_all(item);
9386 }
9387
9388 tmpitem = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(item), "_dw_boxhandle");
9389
9390 if(GTK_IS_TABLE(box))
9391 {
9392 int boxcount = (int)gtk_object_get_data(GTK_OBJECT(box), "_dw_boxcount");
9393 int boxtype = (int)gtk_object_get_data(GTK_OBJECT(box), "_dw_boxtype");
9394
9395 /* If the item being packed is a box, then we use it's padding
9396 * instead of the padding specified on the pack line, this is
9397 * due to a bug in the OS/2 and Win32 renderer and a limitation
9398 * of the GtkTable class.
9399 */
9400 if(GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem)))
9401 {
9402 GtkWidget *eventbox = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(item), "_dw_eventbox");
9403
9404 /* NOTE: I left in the ability to pack boxes with a size,
9405 * this eliminates that by forcing the size to 0.
9406 */
9407 height = width = 0;
9408
9409 if(eventbox)
9410 {
9411 int boxpad = (int)gtk_object_get_data(GTK_OBJECT(item), "_dw_boxpad");
9412 gtk_container_add(GTK_CONTAINER(eventbox), item);
9413 gtk_container_border_width(GTK_CONTAINER(eventbox), boxpad);
9414 item = eventbox;
9415 }
9416 }
9417 else
9418 {
9419 /* Only show warning if item is not a box */
9420 warn = TRUE;
9421 }
9422
9423 if(boxtype == DW_VERT)
9424 gtk_table_resize(GTK_TABLE(box), boxcount + 1, 1);
9425 else
9426 gtk_table_resize(GTK_TABLE(box), 1, boxcount + 1);
9427
9428 gtk_object_set_data(GTK_OBJECT(item), "_dw_table", box);
9429 gtk_table_attach(GTK_TABLE(box), item, 0, 1, 0, 1, hsize ? DW_EXPAND : 0, vsize ? DW_EXPAND : 0, pad, pad);
9430 gtk_object_set_data(GTK_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount + 1));
9431 gtk_widget_set_usize(item, width, height);
9432 if(GTK_IS_RADIO_BUTTON(item))
9433 {
9434 GSList *group;
9435 GtkWidget *groupstart = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(box), "_dw_group");
9436
9437 if(groupstart)
9438 {
9439 group = gtk_radio_button_group(GTK_RADIO_BUTTON(groupstart));
9440 gtk_radio_button_set_group(GTK_RADIO_BUTTON(item), group);
9441 }
9442 else
9443 gtk_object_set_data(GTK_OBJECT(box), "_dw_group", (gpointer)item);
9444 }
9445 }
9446 else
9447 {
9448 GtkWidget *vbox = g_object_get_data(G_OBJECT(box), "_dw_vbox");
9449
9450 if(!vbox)
9451 {
9452 vbox = gtk_vbox_new(FALSE, 0);
9453 g_object_set_data(G_OBJECT(box), "_dw_vbox", vbox);
9454 gtk_container_add(GTK_CONTAINER(box), vbox);
9455 gtk_widget_show(vbox);
9456 }
9457
9458 gtk_container_set_border_width(GTK_CONTAINER(box), pad);
9459
9460 if(GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem)))
9461 {
9462 GtkWidget *eventbox = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(item), "_dw_eventbox");
9463
9464 /* NOTE: I left in the ability to pack boxes with a size,
9465 * this eliminates that by forcing the size to 0.
9466 */
9467 height = width = 0;
9468
9469 if(eventbox)
9470 {
9471 int boxpad = (int)gtk_object_get_data(GTK_OBJECT(item), "_dw_boxpad");
9472 gtk_container_add(GTK_CONTAINER(eventbox), item);
9473 gtk_container_border_width(GTK_CONTAINER(eventbox), boxpad);
9474 item = eventbox;
9475 }
9476 }
9477 else
9478 {
9479 /* Only show warning if item is not a box */
9480 warn = TRUE;
9481 }
9482
9483 gtk_box_pack_end(GTK_BOX(vbox), item, TRUE, TRUE, 0);
9484
9485 gtk_widget_set_usize(item, width, height);
9486 gtk_object_set_user_data(GTK_OBJECT(box), vbox);
9487 }
9488 DW_MUTEX_UNLOCK;
9489
9490 if(warn)
9491 {
9492 if ( width == 0 && hsize == FALSE )
9493 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item);
9494 if ( height == 0 && vsize == FALSE )
9495 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item);
9496 }
9497 } 9386 }
9498 9387
9499 /* 9388 /*
9500 * Sets the size of a given window (widget). 9389 * Sets the size of a given window (widget).
9501 * Parameters: 9390 * Parameters:
10811 gtk_calendar_get_date(GTK_CALENDAR(handle),year,month,day); 10700 gtk_calendar_get_date(GTK_CALENDAR(handle),year,month,day);
10812 *month = *month + 1; 10701 *month = *month + 1;
10813 } 10702 }
10814 DW_MUTEX_UNLOCK; 10703 DW_MUTEX_UNLOCK;
10815 return; 10704 return;
10816 }
10817
10818 /*
10819 * Pack windows (widgets) into a box from the start (or top).
10820 * Parameters:
10821 * box: Window handle of the box to be packed into.
10822 * item: Window handle of the item to be back.
10823 * width: Width in pixels of the item or -1 to be self determined.
10824 * height: Height in pixels of the item or -1 to be self determined.
10825 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
10826 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
10827 * pad: Number of pixels of padding around the item.
10828 */
10829 void dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
10830 {
10831 int warn = FALSE, _locked_by_me = FALSE;
10832 GtkWidget *tmp, *tmpitem;
10833 char *funcname = "dw_box_pack_start()";
10834
10835 if ( !box )
10836 return;
10837
10838 /*
10839 * If you try and pack an item into itself VERY bad things can happen; like at least an
10840 * infinite loop on GTK! Lets be safe!
10841 */
10842 if ( box == item )
10843 {
10844 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!" );
10845 return;
10846 }
10847
10848 DW_MUTEX_LOCK;
10849
10850 if ((tmp = gtk_object_get_data(GTK_OBJECT(box), "_dw_boxhandle")))
10851 box = tmp;
10852
10853 if (!item)
10854 {
10855 item = gtk_label_new("");
10856 gtk_widget_show_all(item);
10857 }
10858
10859 tmpitem = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(item), "_dw_boxhandle");
10860
10861 if (GTK_IS_TABLE(box))
10862 {
10863 int boxcount = (int)gtk_object_get_data(GTK_OBJECT(box), "_dw_boxcount");
10864 int boxtype = (int)gtk_object_get_data(GTK_OBJECT(box), "_dw_boxtype");
10865 int x, y;
10866
10867 /* If the item being packed is a box, then we use it's padding
10868 * instead of the padding specified on the pack line, this is
10869 * due to a bug in the OS/2 and Win32 renderer and a limitation
10870 * of the GtkTable class.
10871 */
10872 if (GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem)))
10873 {
10874 GtkWidget *eventbox = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(item), "_dw_eventbox");
10875
10876 /* NOTE: I left in the ability to pack boxes with a size,
10877 * this eliminates that by forcing the size to 0.
10878 */
10879 height = width = 0;
10880
10881 if (eventbox)
10882 {
10883 int boxpad = (int)gtk_object_get_data(GTK_OBJECT(item), "_dw_boxpad");
10884 gtk_container_add(GTK_CONTAINER(eventbox), item);
10885 gtk_container_border_width(GTK_CONTAINER(eventbox), boxpad);
10886 item = eventbox;
10887 }
10888 }
10889 else
10890 {
10891 /* Only show warning if item is not a box */
10892 warn = TRUE;
10893 }
10894
10895 if (boxtype == DW_VERT)
10896 {
10897 x = 0;
10898 y = boxcount;
10899 gtk_table_resize(GTK_TABLE(box), boxcount + 1, 1);
10900 }
10901 else
10902 {
10903 x = boxcount;
10904 y = 0;
10905 gtk_table_resize(GTK_TABLE(box), 1, boxcount + 1);
10906 }
10907
10908 gtk_object_set_data(GTK_OBJECT(item), "_dw_table", box);
10909 gtk_table_attach(GTK_TABLE(box), item, x, x + 1, y, y + 1, hsize ? DW_EXPAND : 0, vsize ? DW_EXPAND : 0, pad, pad);
10910 gtk_object_set_data(GTK_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount + 1));
10911 gtk_widget_set_usize(item, width, height);
10912 if (GTK_IS_RADIO_BUTTON(item))
10913 {
10914 GSList *group;
10915 GtkWidget *groupstart = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(box), "_dw_group");
10916
10917 if (groupstart)
10918 {
10919 group = gtk_radio_button_group(GTK_RADIO_BUTTON(groupstart));
10920 gtk_radio_button_set_group(GTK_RADIO_BUTTON(item), group);
10921 }
10922 else
10923 {
10924 gtk_object_set_data(GTK_OBJECT(box), "_dw_group", (gpointer)item);
10925 }
10926 }
10927 }
10928 else
10929 {
10930 GtkWidget *vbox = g_object_get_data(G_OBJECT(box), "_dw_vbox");
10931
10932 if(!vbox)
10933 {
10934 vbox = gtk_vbox_new(FALSE, 0);
10935 g_object_set_data(G_OBJECT(box), "_dw_vbox", vbox);
10936 gtk_container_add(GTK_CONTAINER(box), vbox);
10937 gtk_widget_show(vbox);
10938 }
10939
10940 gtk_container_set_border_width(GTK_CONTAINER(box), pad);
10941
10942 if (GTK_IS_TABLE(item) || (tmpitem && GTK_IS_TABLE(tmpitem)))
10943 {
10944 GtkWidget *eventbox = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(item), "_dw_eventbox");
10945
10946 /* NOTE: I left in the ability to pack boxes with a size,
10947 * this eliminates that by forcing the size to 0.
10948 */
10949 height = width = 0;
10950
10951 if (eventbox)
10952 {
10953 int boxpad = (int)gtk_object_get_data(GTK_OBJECT(item), "_dw_boxpad");
10954 gtk_container_add(GTK_CONTAINER(eventbox), item);
10955 gtk_container_border_width(GTK_CONTAINER(eventbox), boxpad);
10956 item = eventbox;
10957 }
10958 }
10959 else
10960 {
10961 /* Only show warning if item is not a box */
10962 warn = TRUE;
10963 }
10964
10965 gtk_box_pack_end(GTK_BOX(vbox), item, TRUE, TRUE, 0);
10966
10967 gtk_widget_set_usize(item, width, height);
10968 gtk_object_set_user_data(GTK_OBJECT(box), vbox);
10969 }
10970 DW_MUTEX_UNLOCK;
10971
10972 if (warn)
10973 {
10974 if ( width == 0 && hsize == FALSE )
10975 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item);
10976 if ( height == 0 && vsize == FALSE )
10977 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item);
10978 }
10979 } 10705 }
10980 10706
10981 /* 10707 /*
10982 * Sets the default focus item for a window/dialog. 10708 * Sets the default focus item for a window/dialog.
10983 * Parameters: 10709 * Parameters: