comparison gtk3/dw.c @ 1451:95ca625b8ffc

Removed GtkVbox and associated code from top-level windows on GTK. Replaced it with a with a GtkTable based vertical box. More than one item can be packed into the top-level window on GTK.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 14 Dec 2011 05:11:57 +0000
parents fbaec6e5df63
children dbe16031ffb4
comparison
equal deleted inserted replaced
1450:145edf67013e 1451:95ca625b8ffc
2889 2889
2890 gtk_mdi_put(GTK_MDI(hwndOwner), tmp, 100, 75, label); 2890 gtk_mdi_put(GTK_MDI(hwndOwner), tmp, 100, 75, label);
2891 } 2891 }
2892 else 2892 else
2893 { 2893 {
2894 GtkWidget *box = dw_box_new(DW_VERT, 0);
2895
2894 last_window = tmp = gtk_window_new(GTK_WINDOW_TOPLEVEL); 2896 last_window = tmp = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2895 2897
2896 gtk_window_set_title(GTK_WINDOW(tmp), title); 2898 gtk_window_set_title(GTK_WINDOW(tmp), title);
2897 if(!(flStyle & DW_FCF_SIZEBORDER)) 2899 if(!(flStyle & DW_FCF_SIZEBORDER))
2898 gtk_window_set_resizable(GTK_WINDOW(tmp), FALSE); 2900 gtk_window_set_resizable(GTK_WINDOW(tmp), FALSE);
2930 if(hwndOwner) 2932 if(hwndOwner)
2931 gdk_window_reparent(gtk_widget_get_window(GTK_WIDGET(tmp)), gtk_widget_get_window(GTK_WIDGET(hwndOwner)), 0, 0); 2933 gdk_window_reparent(gtk_widget_get_window(GTK_WIDGET(tmp)), gtk_widget_get_window(GTK_WIDGET(hwndOwner)), 0, 0);
2932 2934
2933 if(flStyle & DW_FCF_SIZEBORDER) 2935 if(flStyle & DW_FCF_SIZEBORDER)
2934 g_object_set_data(G_OBJECT(tmp), "_dw_size", GINT_TO_POINTER(1)); 2936 g_object_set_data(G_OBJECT(tmp), "_dw_size", GINT_TO_POINTER(1));
2937
2938 gtk_container_add(GTK_CONTAINER(tmp), box);
2939 g_object_set_data(G_OBJECT(tmp), "_dw_boxhandle", (gpointer)box);
2935 } 2940 }
2936 g_object_set_data(G_OBJECT(tmp), "_dw_style", GINT_TO_POINTER(flStyle)); 2941 g_object_set_data(G_OBJECT(tmp), "_dw_style", GINT_TO_POINTER(flStyle));
2937 DW_MUTEX_UNLOCK; 2942 DW_MUTEX_UNLOCK;
2938 return tmp; 2943 return tmp;
2939 } 2944 }
3167 * If there is no box already packed into the "location", the menu will not appear 3172 * If there is no box already packed into the "location", the menu will not appear
3168 * so tell the user. 3173 * so tell the user.
3169 */ 3174 */
3170 HMENUI dw_menubar_new(HWND location) 3175 HMENUI dw_menubar_new(HWND location)
3171 { 3176 {
3177 int _locked_by_me = FALSE;
3178 GtkAccelGroup *accel_group;
3172 GtkWidget *box; 3179 GtkWidget *box;
3173 int _locked_by_me = FALSE; 3180 HMENUI tmp = 0;
3174 GtkAccelGroup *accel_group; 3181
3175 HMENUI tmp; 3182 DW_MUTEX_LOCK;
3176 3183 if(GTK_IS_WINDOW(location) &&
3177 DW_MUTEX_LOCK; 3184 (box = (GtkWidget *)g_object_get_data(G_OBJECT(location), "_dw_boxhandle")))
3178 tmp = gtk_menu_bar_new(); 3185 {
3179 box = (GtkWidget *)g_object_get_data(G_OBJECT(location), "_dw_user"); 3186 /* If there is an existing menu bar, remove it */
3180 gtk_widget_show(tmp); 3187 GtkWidget *oldmenu = (GtkWidget *)g_object_get_data(G_OBJECT(location), "_dw_menubar");
3181 accel_group = gtk_accel_group_new(); 3188 if(oldmenu)
3182 g_object_set_data(G_OBJECT(tmp), "_dw_accel", (gpointer)accel_group); 3189 gtk_widget_destroy(oldmenu);
3183 3190 /* Create a new menu bar */
3184 if (box) 3191 tmp = gtk_menu_bar_new();
3185 gtk_box_pack_end(GTK_BOX(box), tmp, FALSE, FALSE, 0); 3192 gtk_widget_show(tmp);
3186 else 3193 accel_group = gtk_accel_group_new();
3187 fprintf(stderr,"dw_menubar_new(): Coding error: You MUST pack a box into the window in which this menubar is to be added BEFORE calling this function.\n"); 3194 g_object_set_data(G_OBJECT(tmp), "_dw_accel", (gpointer)accel_group);
3188 3195 g_object_set_data(G_OBJECT(location), "_dw_menubar", (gpointer)tmp);
3196 dw_box_pack_end(box, (HWND)tmp, -1, -1, TRUE, FALSE, 0);
3197 }
3189 DW_MUTEX_UNLOCK; 3198 DW_MUTEX_UNLOCK;
3190 return tmp; 3199 return tmp;
3191 } 3200 }
3192 3201
3193 /* 3202 /*
8275 return; 8284 return;
8276 } 8285 }
8277 8286
8278 DW_MUTEX_LOCK; 8287 DW_MUTEX_LOCK;
8279 8288
8289 /* If this is a special box, like: Window, Groupbox, Scrollbox...
8290 * get the internal box handle.
8291 */
8280 if((tmp = g_object_get_data(G_OBJECT(box), "_dw_boxhandle"))) 8292 if((tmp = g_object_get_data(G_OBJECT(box), "_dw_boxhandle")))
8281 box = tmp; 8293 box = tmp;
8282 8294
8295 /* Can't pack nothing with GTK, so create an empty label */
8283 if(!item) 8296 if(!item)
8284 { 8297 {
8285 item = gtk_label_new(""); 8298 item = gtk_label_new("");
8286 gtk_widget_show_all(item); 8299 gtk_widget_show_all(item);
8287 } 8300 }
8301 /* Due to GTK3 minimum size limitations, if we are packing a widget
8302 * with an image, we need to scale the image down to fit the packed size.
8303 */
8288 else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap"))) 8304 else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap")))
8289 { 8305 {
8290 GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image)); 8306 GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image));
8291 8307
8292 if(pixbuf) 8308 if(pixbuf)
8303 pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR); 8319 pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR);
8304 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); 8320 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
8305 } 8321 }
8306 } 8322 }
8307 8323
8324 /* Check if the item to be packed is a special box */
8308 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle"); 8325 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle");
8309 8326
8327 /* Make sure our target box is valid */
8310 if(GTK_IS_GRID(box)) 8328 if(GTK_IS_GRID(box))
8311 { 8329 {
8312 int boxcount = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(box), "_dw_boxcount")); 8330 int boxcount = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(box), "_dw_boxcount"));
8313 int boxtype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(box), "_dw_boxtype")); 8331 int boxtype = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(box), "_dw_boxtype"));
8314 8332
8402 gtk_radio_button_set_group(GTK_RADIO_BUTTON(item), group); 8420 gtk_radio_button_set_group(GTK_RADIO_BUTTON(item), group);
8403 } 8421 }
8404 else 8422 else
8405 g_object_set_data(G_OBJECT(box), "_dw_group", (gpointer)item); 8423 g_object_set_data(G_OBJECT(box), "_dw_group", (gpointer)item);
8406 } 8424 }
8407 }
8408 else
8409 {
8410 GtkWidget *vbox = g_object_get_data(G_OBJECT(box), "_dw_vbox");
8411
8412 if(!vbox)
8413 {
8414 vbox = gtk_vbox_new(FALSE, 0);
8415 g_object_set_data(G_OBJECT(box), "_dw_vbox", vbox);
8416 gtk_container_add(GTK_CONTAINER(box), vbox);
8417 gtk_widget_show(vbox);
8418 }
8419
8420 gtk_container_set_border_width(GTK_CONTAINER(box), pad);
8421
8422 if(GTK_IS_GRID(item) || (tmpitem && GTK_IS_GRID(tmpitem)))
8423 {
8424 GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_eventbox");
8425
8426 /* NOTE: I left in the ability to pack boxes with a size,
8427 * this eliminates that by forcing the size to 0.
8428 */
8429 height = width = 0;
8430
8431 if(eventbox)
8432 {
8433 int boxpad = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(item), "_dw_boxpad"));
8434 gtk_container_add(GTK_CONTAINER(eventbox), item);
8435 gtk_container_set_border_width(GTK_CONTAINER(eventbox), boxpad);
8436 item = eventbox;
8437 }
8438 }
8439 else
8440 {
8441 /* Only show warning if item is not a box */
8442 warn = TRUE;
8443 }
8444
8445 gtk_box_pack_end(GTK_BOX(vbox), item, TRUE, TRUE, 0);
8446
8447 gtk_widget_set_size_request(item, width, height);
8448 g_object_set_data(G_OBJECT(box), "_dw_user", vbox);
8449 } 8425 }
8450 DW_MUTEX_UNLOCK; 8426 DW_MUTEX_UNLOCK;
8451 8427
8452 if(warn) 8428 if(warn)
8453 { 8429 {