2000-10-18 15:50:13 +00:00
|
|
|
/* Paned Widgets
|
|
|
|
*
|
2015-06-20 01:59:15 +00:00
|
|
|
* The GtkPaned Widget divides its content area into two panes
|
|
|
|
* with a divider in between that the user can adjust. A separate
|
|
|
|
* child is placed into each pane. GtkPaned widgets can be split
|
|
|
|
* horizontally or vertially.
|
2000-10-18 15:50:13 +00:00
|
|
|
*
|
|
|
|
* There are a number of options that can be set for each pane.
|
2015-06-20 01:59:15 +00:00
|
|
|
* This test contains both a horizontal and a vertical GtkPaned
|
|
|
|
* widget, and allows you to adjust the options for each side of
|
|
|
|
* each widget.
|
2000-10-18 15:50:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
void
|
2001-05-18 16:28:30 +00:00
|
|
|
toggle_resize (GtkWidget *widget,
|
2011-08-31 15:10:19 +00:00
|
|
|
GtkWidget *child)
|
2000-10-18 15:50:13 +00:00
|
|
|
{
|
2010-08-15 22:36:48 +00:00
|
|
|
GtkWidget *parent;
|
|
|
|
GtkPaned *paned;
|
|
|
|
gboolean is_child1;
|
2000-10-18 15:50:13 +00:00
|
|
|
gboolean resize, shrink;
|
|
|
|
|
2010-08-15 22:36:48 +00:00
|
|
|
parent = gtk_widget_get_parent (child);
|
|
|
|
paned = GTK_PANED (parent);
|
|
|
|
|
|
|
|
is_child1 = (child == gtk_paned_get_child1 (paned));
|
|
|
|
|
2010-07-06 04:32:48 +00:00
|
|
|
gtk_container_child_get (GTK_CONTAINER (paned), child,
|
|
|
|
"resize", &resize,
|
|
|
|
"shrink", &shrink,
|
|
|
|
NULL);
|
2000-10-18 15:50:13 +00:00
|
|
|
|
2007-09-06 10:46:54 +00:00
|
|
|
g_object_ref (child);
|
2010-08-15 22:36:48 +00:00
|
|
|
gtk_container_remove (GTK_CONTAINER (parent), child);
|
2000-10-18 15:50:13 +00:00
|
|
|
if (is_child1)
|
|
|
|
gtk_paned_pack1 (paned, child, !resize, shrink);
|
|
|
|
else
|
|
|
|
gtk_paned_pack2 (paned, child, !resize, shrink);
|
2007-09-06 10:46:54 +00:00
|
|
|
g_object_unref (child);
|
2000-10-18 15:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-05-18 16:28:30 +00:00
|
|
|
toggle_shrink (GtkWidget *widget,
|
2011-08-31 15:10:19 +00:00
|
|
|
GtkWidget *child)
|
2000-10-18 15:50:13 +00:00
|
|
|
{
|
2010-08-15 22:36:48 +00:00
|
|
|
GtkWidget *parent;
|
|
|
|
GtkPaned *paned;
|
|
|
|
gboolean is_child1;
|
2000-10-18 15:50:13 +00:00
|
|
|
gboolean resize, shrink;
|
|
|
|
|
2010-08-15 22:36:48 +00:00
|
|
|
parent = gtk_widget_get_parent (child);
|
|
|
|
paned = GTK_PANED (parent);
|
|
|
|
|
|
|
|
is_child1 = (child == gtk_paned_get_child1 (paned));
|
|
|
|
|
2010-07-06 04:32:48 +00:00
|
|
|
gtk_container_child_get (GTK_CONTAINER (paned), child,
|
|
|
|
"resize", &resize,
|
|
|
|
"shrink", &shrink,
|
|
|
|
NULL);
|
2000-10-18 15:50:13 +00:00
|
|
|
|
2007-09-06 10:46:54 +00:00
|
|
|
g_object_ref (child);
|
2010-08-15 22:36:48 +00:00
|
|
|
gtk_container_remove (GTK_CONTAINER (parent), child);
|
2000-10-18 15:50:13 +00:00
|
|
|
if (is_child1)
|
|
|
|
gtk_paned_pack1 (paned, child, resize, !shrink);
|
|
|
|
else
|
|
|
|
gtk_paned_pack2 (paned, child, resize, !shrink);
|
2007-09-06 10:46:54 +00:00
|
|
|
g_object_unref (child);
|
2000-10-18 15:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
2011-08-31 15:10:19 +00:00
|
|
|
create_pane_options (GtkPaned *paned,
|
|
|
|
const gchar *frame_label,
|
|
|
|
const gchar *label1,
|
|
|
|
const gchar *label2)
|
2000-10-18 15:50:13 +00:00
|
|
|
{
|
2010-07-06 04:32:48 +00:00
|
|
|
GtkWidget *child1, *child2;
|
2000-10-18 15:50:13 +00:00
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *check_button;
|
2010-07-06 04:32:48 +00:00
|
|
|
|
|
|
|
child1 = gtk_paned_get_child1 (paned);
|
|
|
|
child2 = gtk_paned_get_child2 (paned);
|
|
|
|
|
2000-10-18 15:50:13 +00:00
|
|
|
frame = gtk_frame_new (frame_label);
|
2016-10-26 19:11:18 +00:00
|
|
|
g_object_set (frame, "margin", 4, NULL);
|
2011-08-31 15:10:19 +00:00
|
|
|
|
|
|
|
table = gtk_grid_new ();
|
2000-10-18 15:50:13 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), table);
|
2011-08-31 15:10:19 +00:00
|
|
|
|
2000-10-18 15:50:13 +00:00
|
|
|
label = gtk_label_new (label1);
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
|
|
|
|
|
2001-03-22 06:45:57 +00:00
|
|
|
check_button = gtk_check_button_new_with_mnemonic ("_Resize");
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), check_button, 0, 1, 1, 1);
|
2001-10-20 23:39:32 +00:00
|
|
|
g_signal_connect (check_button, "toggled",
|
2011-08-31 15:10:19 +00:00
|
|
|
G_CALLBACK (toggle_resize), child1);
|
2010-07-06 04:32:48 +00:00
|
|
|
|
2001-03-22 06:45:57 +00:00
|
|
|
check_button = gtk_check_button_new_with_mnemonic ("_Shrink");
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), check_button, 0, 2, 1, 1);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), TRUE);
|
2001-10-20 23:39:32 +00:00
|
|
|
g_signal_connect (check_button, "toggled",
|
2011-08-31 15:10:19 +00:00
|
|
|
G_CALLBACK (toggle_shrink), child1);
|
2010-07-06 04:32:48 +00:00
|
|
|
|
2000-10-18 15:50:13 +00:00
|
|
|
label = gtk_label_new (label2);
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), label, 1, 0, 1, 1);
|
|
|
|
|
2001-03-22 06:45:57 +00:00
|
|
|
check_button = gtk_check_button_new_with_mnemonic ("_Resize");
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), check_button, 1, 1, 1, 1);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), TRUE);
|
2001-10-20 23:39:32 +00:00
|
|
|
g_signal_connect (check_button, "toggled",
|
2011-08-31 15:10:19 +00:00
|
|
|
G_CALLBACK (toggle_resize), child2);
|
2010-07-06 04:32:48 +00:00
|
|
|
|
2001-03-22 06:45:57 +00:00
|
|
|
check_button = gtk_check_button_new_with_mnemonic ("_Shrink");
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), check_button, 1, 2, 1, 1);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), TRUE);
|
2001-10-20 23:39:32 +00:00
|
|
|
g_signal_connect (check_button, "toggled",
|
2011-08-31 15:10:19 +00:00
|
|
|
G_CALLBACK (toggle_shrink), child2);
|
2000-10-18 15:50:13 +00:00
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2000-11-18 23:59:30 +00:00
|
|
|
GtkWidget *
|
2003-11-08 22:08:05 +00:00
|
|
|
do_panes (GtkWidget *do_widget)
|
2000-10-18 15:50:13 +00:00
|
|
|
{
|
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *hpaned;
|
|
|
|
GtkWidget *vpaned;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
{
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2003-11-08 22:08:05 +00:00
|
|
|
gtk_window_set_screen (GTK_WINDOW (window),
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_widget_get_screen (do_widget));
|
2000-10-18 15:50:13 +00:00
|
|
|
|
2001-10-20 23:39:32 +00:00
|
|
|
g_signal_connect (window, "destroy",
|
2011-08-31 15:10:19 +00:00
|
|
|
G_CALLBACK (gtk_widget_destroyed), &window);
|
2000-10-18 15:50:13 +00:00
|
|
|
|
2015-06-20 01:59:15 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Paned Widgets");
|
2000-10-18 15:50:13 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2000-10-18 15:50:13 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), vbox);
|
2010-10-31 17:07:20 +00:00
|
|
|
|
2010-10-29 23:47:13 +00:00
|
|
|
vpaned = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
|
2016-10-26 19:11:18 +00:00
|
|
|
g_object_set (vpaned, "margin", 5, NULL);
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), vpaned);
|
2000-10-18 15:50:13 +00:00
|
|
|
|
2010-10-29 23:47:13 +00:00
|
|
|
hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
|
2000-10-18 15:50:13 +00:00
|
|
|
gtk_paned_add1 (GTK_PANED (vpaned), hpaned);
|
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN);
|
fix a typo.
2001-08-07 Havoc Pennington <hp@pobox.com>
* gtk/gtkfilesel.c (open_ref_dir): fix a typo.
* gtk/gtkplug.c (gtk_plug_init): remove setting of auto_shrink;
some fixage is needed here, but nothing simple. Owen understands
it. ;-)
* gtk/gtkwindow.h, gtk/gtkwindow.c: Rework code and API for window
sizing and positioning. Also, fix bug in compute_geometry_hints
(width/height confusion for setting min size).
(gtk_window_move): new function
(gtk_window_resize): new function
(gtk_window_get_size): new function
(gtk_window_get_position): new function
(gtk_window_parse_geometry): new function
* gtk/gtkwidget.c (gtk_widget_set_size_request): new function
(gtk_widget_get_size_request): new function
(gtk_widget_get_usize): delete, that was a short-lived function
;-)
(gtk_widget_set_usize): deprecate
(gtk_widget_set_uposition): deprecate, make it a trivial
gtk_window_move() wrapper
(gtk_widget_class_init): remove x/y/width/height properties,
add width_request height_request
* demos/*: update to avoid deprecated functions
* gtk/gtklayout.c: add x/y child properties
* gtk/gtkfixed.c: add x/y child properties, and get rid of
uses of "gint16"
* tests/testgtk.c (create_window_sizing): lots of tweaks to window
sizing test
* gdk/x11/gdkevents-x11.c (gdk_event_translate): Ensure that
configure events on toplevel windows are always in root window
coordinates, following ICCCM spec that all synthetic events
are in root window coords already, while real events are
in parent window coords. Previously the code assumed that
coords of 0,0 were parent window coords, which was
really broken.
* gtk/gtkcontainer.c (gtk_container_get_focus_chain): fix
warning
* gdk/gdkwindow.h (GdkWindowHints): add GDK_HINT_USER_POS
and GDK_HINT_USER_SIZE so we can set USSize and USPosition
hints in gtk_window_parse_geometry()
* gdk/x11/gdkwindow-x11.c (gdk_window_set_geometry_hints): support
new USER_POS USER_SIZE hints
2001-08-10 03:46:08 +00:00
|
|
|
gtk_widget_set_size_request (frame, 60, 60);
|
2000-10-18 15:50:13 +00:00
|
|
|
gtk_paned_add1 (GTK_PANED (hpaned), frame);
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2001-03-22 06:45:57 +00:00
|
|
|
button = gtk_button_new_with_mnemonic ("_Hi there");
|
2000-10-18 15:50:13 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER(frame), button);
|
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN);
|
2001-08-17 14:11:36 +00:00
|
|
|
gtk_widget_set_size_request (frame, 80, 60);
|
2000-10-18 15:50:13 +00:00
|
|
|
gtk_paned_add2 (GTK_PANED (hpaned), frame);
|
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN);
|
2001-08-17 14:11:36 +00:00
|
|
|
gtk_widget_set_size_request (frame, 60, 80);
|
2000-10-18 15:50:13 +00:00
|
|
|
gtk_paned_add2 (GTK_PANED (vpaned), frame);
|
|
|
|
|
|
|
|
/* Now create toggle buttons to control sizing */
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox),
|
2011-08-31 15:10:19 +00:00
|
|
|
create_pane_options (GTK_PANED (hpaned),
|
|
|
|
"Horizontal",
|
|
|
|
"Left",
|
2017-04-21 20:34:36 +00:00
|
|
|
"Right"));
|
2000-10-18 15:50:13 +00:00
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox),
|
2011-08-31 15:10:19 +00:00
|
|
|
create_pane_options (GTK_PANED (vpaned),
|
|
|
|
"Vertical",
|
|
|
|
"Top",
|
2017-04-21 20:34:36 +00:00
|
|
|
"Bottom"));
|
2000-10-18 15:50:13 +00:00
|
|
|
}
|
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (!gtk_widget_get_visible (window))
|
2015-06-28 13:23:28 +00:00
|
|
|
gtk_widget_show (window);
|
2000-10-18 15:50:13 +00:00
|
|
|
else
|
2015-06-28 13:23:28 +00:00
|
|
|
gtk_widget_destroy (window);
|
2000-11-18 23:59:30 +00:00
|
|
|
|
|
|
|
return window;
|
2000-10-18 15:50:13 +00:00
|
|
|
}
|