forked from AuroraMiddleware/gtk
Merge branch 'tests-cleanup' into 'master'
Tests cleanup See merge request GNOME/gtk!1904
This commit is contained in:
commit
acae90cc6e
@ -17,7 +17,6 @@ gtk_tests = [
|
|||||||
['testappchooserbutton'],
|
['testappchooserbutton'],
|
||||||
['testassistant'],
|
['testassistant'],
|
||||||
['testbaseline'],
|
['testbaseline'],
|
||||||
['testbuttons'],
|
|
||||||
['testcalendar'],
|
['testcalendar'],
|
||||||
['testclipboard2'],
|
['testclipboard2'],
|
||||||
['testcombo'],
|
['testcombo'],
|
||||||
@ -26,9 +25,7 @@ gtk_tests = [
|
|||||||
['testdialog'],
|
['testdialog'],
|
||||||
['testdnd'],
|
['testdnd'],
|
||||||
['testdnd2'],
|
['testdnd2'],
|
||||||
['testdnd3'],
|
|
||||||
['testellipsise'],
|
['testellipsise'],
|
||||||
['testemblems'],
|
|
||||||
['testentrycompletion'],
|
['testentrycompletion'],
|
||||||
['testentryicons'],
|
['testentryicons'],
|
||||||
['testfilechooser'],
|
['testfilechooser'],
|
||||||
@ -37,13 +34,11 @@ gtk_tests = [
|
|||||||
['testfontoptions'],
|
['testfontoptions'],
|
||||||
['testframe'],
|
['testframe'],
|
||||||
['testfullscreen'],
|
['testfullscreen'],
|
||||||
['testgiconpixbuf'],
|
|
||||||
['testglarea'],
|
['testglarea'],
|
||||||
['testglblending', ['gtkgears.c']],
|
['testglblending', ['gtkgears.c']],
|
||||||
['testgrid'],
|
['testgrid'],
|
||||||
['testgtk'],
|
['testgtk'],
|
||||||
['testheaderbar'],
|
['testheaderbar'],
|
||||||
['testheaderbar2'],
|
|
||||||
['testheightforwidth'],
|
['testheightforwidth'],
|
||||||
['testhover'],
|
['testhover'],
|
||||||
['testiconview'],
|
['testiconview'],
|
||||||
@ -60,7 +55,6 @@ gtk_tests = [
|
|||||||
['testmountoperation'],
|
['testmountoperation'],
|
||||||
['testnotebookdnd'],
|
['testnotebookdnd'],
|
||||||
['testnouiprint'],
|
['testnouiprint'],
|
||||||
['testorientable'],
|
|
||||||
['testoverlay'],
|
['testoverlay'],
|
||||||
['testoverlaystyleclass'],
|
['testoverlaystyleclass'],
|
||||||
['testprint', ['testprintfileoperation.c']],
|
['testprint', ['testprintfileoperation.c']],
|
||||||
@ -99,8 +93,6 @@ gtk_tests = [
|
|||||||
['testrevealer'],
|
['testrevealer'],
|
||||||
['testrevealer2'],
|
['testrevealer2'],
|
||||||
['testtreelistmodel'],
|
['testtreelistmodel'],
|
||||||
['testsplitheaders'],
|
|
||||||
['teststackedheaders'],
|
|
||||||
['testwindowsize'],
|
['testwindowsize'],
|
||||||
['testpopover'],
|
['testpopover'],
|
||||||
['listmodel'],
|
['listmodel'],
|
||||||
|
@ -1,123 +0,0 @@
|
|||||||
/* testbuttons.c
|
|
||||||
* Copyright (C) 2009 Red Hat, Inc.
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Library General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Library General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
|
||||||
|
|
||||||
/* various combinations of use_underline */
|
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
|
||||||
{
|
|
||||||
GtkWidget *window, *box, *button, *hbox;
|
|
||||||
gchar *text;
|
|
||||||
const char *icon_name;
|
|
||||||
gboolean use_underline;
|
|
||||||
GtkWidget *label;
|
|
||||||
|
|
||||||
gtk_init ();
|
|
||||||
|
|
||||||
window = gtk_window_new ();
|
|
||||||
|
|
||||||
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
||||||
|
|
||||||
gtk_window_set_child (GTK_WINDOW (window), box);
|
|
||||||
|
|
||||||
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
||||||
gtk_box_append (GTK_BOX (box), hbox);
|
|
||||||
button = g_object_new (GTK_TYPE_BUTTON,
|
|
||||||
"label", "document-save",
|
|
||||||
NULL);
|
|
||||||
gtk_box_append (GTK_BOX (hbox), button);
|
|
||||||
|
|
||||||
g_object_get (button,
|
|
||||||
"label", &text,
|
|
||||||
"use-underline", &use_underline,
|
|
||||||
"icon-name", &icon_name,
|
|
||||||
NULL);
|
|
||||||
text = g_strdup_printf ("label: \"%s\" icon-name: \"%s\" use-underline: %s\n", text, icon_name, use_underline ? "TRUE" : "FALSE");
|
|
||||||
label = gtk_label_new (text);
|
|
||||||
g_free (text);
|
|
||||||
gtk_box_append (GTK_BOX (hbox), label);
|
|
||||||
|
|
||||||
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
||||||
gtk_box_append (GTK_BOX (box), hbox);
|
|
||||||
button = gtk_button_new_with_label ("_Save");
|
|
||||||
gtk_box_append (GTK_BOX (hbox), button);
|
|
||||||
|
|
||||||
g_object_get (button,
|
|
||||||
"label", &text,
|
|
||||||
"use-underline", &use_underline,
|
|
||||||
"icon-name", &icon_name,
|
|
||||||
NULL);
|
|
||||||
text = g_strdup_printf ("label: \"%s\" icon-name: \"%s\" use-underline: %s\n", text, icon_name, use_underline ? "TRUE" : "FALSE");
|
|
||||||
label = gtk_label_new (text);
|
|
||||||
g_free (text);
|
|
||||||
gtk_box_append (GTK_BOX (hbox), label);
|
|
||||||
|
|
||||||
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
||||||
gtk_box_append (GTK_BOX (box), hbox);
|
|
||||||
button = gtk_button_new_with_mnemonic ("_Save");
|
|
||||||
gtk_box_append (GTK_BOX (hbox), button);
|
|
||||||
|
|
||||||
g_object_get (button,
|
|
||||||
"label", &text,
|
|
||||||
"use-underline", &use_underline,
|
|
||||||
"icon-name", &icon_name,
|
|
||||||
NULL);
|
|
||||||
text = g_strdup_printf ("label: \"%s\" icon-name: \"%s\" use-underline: %s\n", text, icon_name, use_underline ? "TRUE" : "FALSE");
|
|
||||||
label = gtk_label_new (text);
|
|
||||||
g_free (text);
|
|
||||||
gtk_box_append (GTK_BOX (hbox), label);
|
|
||||||
|
|
||||||
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
||||||
gtk_box_append (GTK_BOX (box), hbox);
|
|
||||||
button = gtk_button_new_from_icon_name ("help-about");
|
|
||||||
gtk_box_append (GTK_BOX (hbox), button);
|
|
||||||
|
|
||||||
g_object_get (button,
|
|
||||||
"label", &text,
|
|
||||||
"use-underline", &use_underline,
|
|
||||||
"icon-name", &icon_name,
|
|
||||||
NULL);
|
|
||||||
text = g_strdup_printf ("label: \"%s\" icon-name: \"%s\" use-underline: %s\n", text, icon_name, use_underline ? "TRUE" : "FALSE");
|
|
||||||
label = gtk_label_new (text);
|
|
||||||
g_free (text);
|
|
||||||
gtk_box_append (GTK_BOX (hbox), label);
|
|
||||||
|
|
||||||
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
||||||
gtk_box_append (GTK_BOX (box), hbox);
|
|
||||||
button = gtk_button_new ();
|
|
||||||
gtk_button_set_icon_name (GTK_BUTTON (button), "help-about");
|
|
||||||
gtk_button_set_use_underline (GTK_BUTTON (button), TRUE);
|
|
||||||
gtk_box_append (GTK_BOX (hbox), button);
|
|
||||||
g_object_get (button,
|
|
||||||
"label", &text,
|
|
||||||
"use-underline", &use_underline,
|
|
||||||
"icon-name", &icon_name,
|
|
||||||
NULL);
|
|
||||||
text = g_strdup_printf ("label: \"%s\" icon-name: \"%s\" use-underline: %s\n", text, icon_name, use_underline ? "TRUE" : "FALSE");
|
|
||||||
label = gtk_label_new (text);
|
|
||||||
g_free (text);
|
|
||||||
gtk_box_append (GTK_BOX (hbox), label);
|
|
||||||
|
|
||||||
gtk_widget_show (window);
|
|
||||||
|
|
||||||
while (TRUE)
|
|
||||||
g_main_context_iteration (NULL, TRUE);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
326
tests/testdnd3.c
326
tests/testdnd3.c
@ -1,326 +0,0 @@
|
|||||||
#include <gtk/gtk.h>
|
|
||||||
|
|
||||||
static GdkContentProvider *
|
|
||||||
prepare (GtkDragSource *source, double x, double y)
|
|
||||||
{
|
|
||||||
GtkWidget *canvas;
|
|
||||||
GtkWidget *item;
|
|
||||||
|
|
||||||
canvas = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (source));
|
|
||||||
item = gtk_widget_pick (canvas, x, y, GTK_PICK_DEFAULT);
|
|
||||||
|
|
||||||
if (!GTK_IS_LABEL (item))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
g_object_set_data (G_OBJECT (canvas), "dragged-item", item);
|
|
||||||
|
|
||||||
return gdk_content_provider_new_typed (GTK_TYPE_WIDGET, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
drag_begin (GtkDragSource *source, GdkDrag *drag)
|
|
||||||
{
|
|
||||||
GtkWidget *canvas;
|
|
||||||
GtkWidget *item;
|
|
||||||
|
|
||||||
canvas = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (source));
|
|
||||||
item = g_object_get_data (G_OBJECT (canvas), "dragged-item");
|
|
||||||
|
|
||||||
gtk_widget_set_opacity (item, 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
drag_end (GtkDragSource *source, GdkDrag *drag)
|
|
||||||
{
|
|
||||||
GtkWidget *canvas;
|
|
||||||
GtkWidget *item;
|
|
||||||
|
|
||||||
canvas = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (source));
|
|
||||||
item = g_object_get_data (G_OBJECT (canvas), "dragged-item");
|
|
||||||
g_object_set_data (G_OBJECT (canvas), "dragged-item", NULL);
|
|
||||||
|
|
||||||
gtk_widget_set_opacity (item, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
drag_cancel (GtkDragSource *source,
|
|
||||||
GdkDrag *drag,
|
|
||||||
GdkDragCancelReason reason)
|
|
||||||
{
|
|
||||||
drag_end (source, drag);
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
double x, y;
|
|
||||||
double angle;
|
|
||||||
double delta;
|
|
||||||
} TransformData;
|
|
||||||
|
|
||||||
static void
|
|
||||||
apply_transform (GtkWidget *item)
|
|
||||||
{
|
|
||||||
GtkWidget *canvas = gtk_widget_get_parent (item);
|
|
||||||
TransformData *data;
|
|
||||||
GskTransform *transform;
|
|
||||||
|
|
||||||
data = g_object_get_data (G_OBJECT (item), "transform-data");
|
|
||||||
transform = gsk_transform_rotate (gsk_transform_translate (NULL, &(graphene_point_t){data->x, data->y}),
|
|
||||||
data->angle + data->delta);
|
|
||||||
gtk_fixed_set_child_transform (GTK_FIXED (canvas), item, transform);
|
|
||||||
gsk_transform_unref (transform);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
drag_drop (GtkDropTarget *target,
|
|
||||||
const GValue *value,
|
|
||||||
double x,
|
|
||||||
double y)
|
|
||||||
{
|
|
||||||
GtkWidget *item;
|
|
||||||
TransformData *transform_data;
|
|
||||||
GtkWidget *canvas;
|
|
||||||
GtkWidget *last_child;
|
|
||||||
|
|
||||||
item = g_value_get_object (value);
|
|
||||||
transform_data = g_object_get_data (G_OBJECT (item), "transform-data");
|
|
||||||
|
|
||||||
transform_data->x = x;
|
|
||||||
transform_data->y = y;
|
|
||||||
|
|
||||||
canvas = gtk_widget_get_parent (item);
|
|
||||||
last_child = gtk_widget_get_last_child (canvas);
|
|
||||||
if (item != last_child)
|
|
||||||
gtk_widget_insert_after (item, canvas, last_child);
|
|
||||||
|
|
||||||
apply_transform (item);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GtkWidget *
|
|
||||||
canvas_new (void)
|
|
||||||
{
|
|
||||||
GtkWidget *canvas;
|
|
||||||
GtkDragSource *source;
|
|
||||||
GtkDropTarget *dest;
|
|
||||||
|
|
||||||
canvas = gtk_fixed_new ();
|
|
||||||
gtk_widget_set_hexpand (canvas, TRUE);
|
|
||||||
gtk_widget_set_vexpand (canvas, TRUE);
|
|
||||||
gtk_widget_add_css_class (canvas, "frame");
|
|
||||||
|
|
||||||
source = gtk_drag_source_new ();
|
|
||||||
gtk_drag_source_set_actions (source, GDK_ACTION_MOVE);
|
|
||||||
g_signal_connect (source, "prepare", G_CALLBACK (prepare), NULL);
|
|
||||||
g_signal_connect (source, "drag-begin", G_CALLBACK (drag_begin), NULL);
|
|
||||||
g_signal_connect (source, "drag-end", G_CALLBACK (drag_end), NULL);
|
|
||||||
g_signal_connect (source, "drag-cancel", G_CALLBACK (drag_cancel), NULL);
|
|
||||||
gtk_widget_add_controller (canvas, GTK_EVENT_CONTROLLER (source));
|
|
||||||
|
|
||||||
dest = gtk_drop_target_new (GTK_TYPE_WIDGET, GDK_ACTION_MOVE);
|
|
||||||
g_signal_connect (dest, "drop", G_CALLBACK (drag_drop), NULL);
|
|
||||||
gtk_widget_add_controller (canvas, GTK_EVENT_CONTROLLER (dest));
|
|
||||||
|
|
||||||
return canvas;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
set_color (GtkWidget *item,
|
|
||||||
GdkRGBA *color)
|
|
||||||
{
|
|
||||||
char *css;
|
|
||||||
char *str;
|
|
||||||
GtkStyleContext *context;
|
|
||||||
GtkCssProvider *provider;
|
|
||||||
|
|
||||||
str = gdk_rgba_to_string (color);
|
|
||||||
css = g_strdup_printf ("* { background: %s; padding: 10px; }", str);
|
|
||||||
|
|
||||||
context = gtk_widget_get_style_context (item);
|
|
||||||
provider = g_object_get_data (G_OBJECT (context), "style-provider");
|
|
||||||
if (provider)
|
|
||||||
gtk_style_context_remove_provider (context, GTK_STYLE_PROVIDER (provider));
|
|
||||||
|
|
||||||
provider = gtk_css_provider_new ();
|
|
||||||
gtk_css_provider_load_from_data (provider, css, -1);
|
|
||||||
gtk_style_context_add_provider (gtk_widget_get_style_context (item), GTK_STYLE_PROVIDER (provider), 800);
|
|
||||||
g_object_set_data_full (G_OBJECT (context), "style-provider", provider, g_object_unref);
|
|
||||||
|
|
||||||
g_free (str);
|
|
||||||
g_free (css);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
item_drag_drop (GtkDropTarget *dest,
|
|
||||||
const GValue *value,
|
|
||||||
double x,
|
|
||||||
double y)
|
|
||||||
{
|
|
||||||
GtkWidget *item = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (dest));
|
|
||||||
|
|
||||||
set_color (item, g_value_get_boxed (value));
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
angle_changed (GtkGestureRotate *gesture,
|
|
||||||
double angle,
|
|
||||||
double delta)
|
|
||||||
{
|
|
||||||
GtkWidget *item = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
|
|
||||||
TransformData *data = g_object_get_data (G_OBJECT (item), "transform-data");
|
|
||||||
|
|
||||||
data->delta = angle / M_PI * 180.0;
|
|
||||||
|
|
||||||
apply_transform (item);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
rotate_done (GtkGesture *gesture)
|
|
||||||
{
|
|
||||||
GtkWidget *item = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
|
|
||||||
TransformData *data = g_object_get_data (G_OBJECT (item), "transform-data");
|
|
||||||
|
|
||||||
data->angle = data->angle + data->delta;
|
|
||||||
data->delta = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
click_done (GtkGesture *gesture)
|
|
||||||
{
|
|
||||||
GtkWidget *item = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
|
|
||||||
GtkWidget *canvas = gtk_widget_get_parent (item);
|
|
||||||
GtkWidget *last_child;
|
|
||||||
|
|
||||||
last_child = gtk_widget_get_last_child (canvas);
|
|
||||||
if (item != last_child)
|
|
||||||
gtk_widget_insert_after (item, canvas, last_child);
|
|
||||||
}
|
|
||||||
|
|
||||||
static GtkWidget *
|
|
||||||
canvas_item_new (int i,
|
|
||||||
double x,
|
|
||||||
double y,
|
|
||||||
double angle)
|
|
||||||
{
|
|
||||||
GtkWidget *widget;
|
|
||||||
char *label;
|
|
||||||
char *id;
|
|
||||||
TransformData *transform_data;
|
|
||||||
GdkRGBA rgba;
|
|
||||||
GtkDropTarget *dest;
|
|
||||||
GtkGesture *gesture;
|
|
||||||
|
|
||||||
label = g_strdup_printf ("Item %d", i);
|
|
||||||
id = g_strdup_printf ("item%d", i);
|
|
||||||
|
|
||||||
gdk_rgba_parse (&rgba, "yellow");
|
|
||||||
|
|
||||||
widget = gtk_label_new (label);
|
|
||||||
gtk_widget_add_css_class (widget, "frame");
|
|
||||||
gtk_widget_set_name (widget, id);
|
|
||||||
|
|
||||||
set_color (widget, &rgba);
|
|
||||||
transform_data = g_new0 (TransformData, 1);
|
|
||||||
transform_data->x = x;
|
|
||||||
transform_data->y = y;
|
|
||||||
transform_data->angle = angle;
|
|
||||||
g_object_set_data_full (G_OBJECT (widget), "transform-data", transform_data, g_free);
|
|
||||||
|
|
||||||
g_free (label);
|
|
||||||
g_free (id);
|
|
||||||
|
|
||||||
dest = gtk_drop_target_new (GDK_TYPE_RGBA, GDK_ACTION_COPY);
|
|
||||||
g_signal_connect (dest, "drop", G_CALLBACK (item_drag_drop), NULL);
|
|
||||||
gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (dest));
|
|
||||||
|
|
||||||
gesture = gtk_gesture_rotate_new ();
|
|
||||||
g_signal_connect (gesture, "angle-changed", G_CALLBACK (angle_changed), NULL);
|
|
||||||
g_signal_connect (gesture, "end", G_CALLBACK (rotate_done), NULL);
|
|
||||||
gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (gesture));
|
|
||||||
|
|
||||||
gesture = gtk_gesture_click_new ();
|
|
||||||
g_signal_connect (gesture, "released", G_CALLBACK (click_done), NULL);
|
|
||||||
gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (gesture));
|
|
||||||
|
|
||||||
return widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
|
||||||
{
|
|
||||||
GtkWidget *window;
|
|
||||||
GtkWidget *sw;
|
|
||||||
GtkWidget *canvas;
|
|
||||||
GtkWidget *widget;
|
|
||||||
GtkWidget *box, *box2, *box3;
|
|
||||||
const char *colors[] = {
|
|
||||||
"red", "green", "blue", "magenta", "orange", "gray", "black", "yellow",
|
|
||||||
"white", "gray", "brown", "pink", "cyan", "bisque", "gold", "maroon",
|
|
||||||
"navy", "orchid", "olive", "peru", "salmon", "silver", "wheat",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
int i;
|
|
||||||
int x, y;
|
|
||||||
|
|
||||||
gtk_init ();
|
|
||||||
|
|
||||||
widget = gtk_color_button_new ();
|
|
||||||
g_object_unref (g_object_ref_sink (widget));
|
|
||||||
|
|
||||||
window = gtk_window_new ();
|
|
||||||
gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
|
|
||||||
|
|
||||||
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
||||||
gtk_window_set_child (GTK_WINDOW (window), box);
|
|
||||||
|
|
||||||
box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
||||||
gtk_box_append (GTK_BOX (box), box2);
|
|
||||||
|
|
||||||
canvas = canvas_new ();
|
|
||||||
gtk_box_append (GTK_BOX (box2), canvas);
|
|
||||||
|
|
||||||
x = y = 40;
|
|
||||||
for (i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
GtkWidget *item;
|
|
||||||
|
|
||||||
item = canvas_item_new (i, x, y, 0);
|
|
||||||
gtk_box_append (GTK_BOX (canvas), item);
|
|
||||||
apply_transform (item);
|
|
||||||
|
|
||||||
x += 150;
|
|
||||||
y += 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
sw = gtk_scrolled_window_new (NULL, NULL);
|
|
||||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
|
||||||
GTK_POLICY_AUTOMATIC,
|
|
||||||
GTK_POLICY_NEVER);
|
|
||||||
gtk_box_append (GTK_BOX (box), sw);
|
|
||||||
|
|
||||||
box3 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
||||||
gtk_widget_add_css_class (box3, "linked");
|
|
||||||
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), box3);
|
|
||||||
|
|
||||||
for (i = 0; colors[i]; i++)
|
|
||||||
{
|
|
||||||
GdkRGBA rgba;
|
|
||||||
GtkWidget *swatch;
|
|
||||||
|
|
||||||
gdk_rgba_parse (&rgba, colors[i]);
|
|
||||||
|
|
||||||
swatch = g_object_new (g_type_from_name ("GtkColorSwatch"),
|
|
||||||
"rgba", &rgba,
|
|
||||||
"selectable", FALSE,
|
|
||||||
NULL);
|
|
||||||
gtk_box_append (GTK_BOX (box3), swatch);
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_widget_show (window);
|
|
||||||
|
|
||||||
while (TRUE)
|
|
||||||
g_main_context_iteration (NULL, TRUE);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
#include <gtk/gtk.h>
|
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
|
||||||
{
|
|
||||||
GtkWidget *window;
|
|
||||||
GtkWidget *button;
|
|
||||||
GtkWidget *grid;
|
|
||||||
GIcon *icon;
|
|
||||||
GIcon *icon2;
|
|
||||||
|
|
||||||
gtk_init ();
|
|
||||||
|
|
||||||
window = gtk_window_new ();
|
|
||||||
|
|
||||||
grid = gtk_grid_new ();
|
|
||||||
gtk_grid_set_row_spacing (GTK_GRID (grid), 12);
|
|
||||||
gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
|
|
||||||
gtk_window_set_child (GTK_WINDOW (window), grid);
|
|
||||||
|
|
||||||
icon = g_themed_icon_new ("folder");
|
|
||||||
button = gtk_image_new_from_gicon (icon);
|
|
||||||
gtk_grid_attach (GTK_GRID (grid), button, 1, 1, 1, 1);
|
|
||||||
|
|
||||||
icon2 = g_themed_icon_new ("folder-symbolic");
|
|
||||||
button = gtk_image_new_from_gicon (icon2);
|
|
||||||
gtk_grid_attach (GTK_GRID (grid), button, 2, 1, 1, 1);
|
|
||||||
|
|
||||||
icon = g_emblemed_icon_new (icon, g_emblem_new (g_themed_icon_new ("emblem-new")));
|
|
||||||
button = gtk_image_new_from_gicon (icon);
|
|
||||||
gtk_grid_attach (GTK_GRID (grid), button, 1, 2, 1, 1);
|
|
||||||
|
|
||||||
icon2 = g_emblemed_icon_new (icon2, g_emblem_new (g_themed_icon_new ("emblem-new")));
|
|
||||||
button = gtk_image_new_from_gicon (icon2);
|
|
||||||
gtk_grid_attach (GTK_GRID (grid), button, 2, 2, 1, 1);
|
|
||||||
|
|
||||||
gtk_widget_show (window);
|
|
||||||
|
|
||||||
while (TRUE)
|
|
||||||
g_main_context_iteration (NULL, TRUE);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,91 +0,0 @@
|
|||||||
/* testgiconpixbuf.c
|
|
||||||
* Copyright (C) 2010 Red Hat, Inc.
|
|
||||||
* Authors: Cosimo Cecchi
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Library General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Library General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
|
||||||
#include <glib/gstdio.h>
|
|
||||||
|
|
||||||
static void
|
|
||||||
quit_cb (GtkWidget *widget,
|
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
gboolean *done = data;
|
|
||||||
|
|
||||||
*done = TRUE;
|
|
||||||
|
|
||||||
g_main_context_wakeup (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
main (int argc,
|
|
||||||
char **argv)
|
|
||||||
{
|
|
||||||
GdkPixbuf *pixbuf, *otherpix;
|
|
||||||
GtkWidget *image, *image2, *hbox, *vbox, *label, *toplevel;
|
|
||||||
GIcon *emblemed;
|
|
||||||
GEmblem *emblem;
|
|
||||||
gchar *str;
|
|
||||||
gboolean done = FALSE;
|
|
||||||
|
|
||||||
#ifdef GTK_SRCDIR
|
|
||||||
g_chdir (GTK_SRCDIR);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
gtk_init ();
|
|
||||||
|
|
||||||
pixbuf = gdk_pixbuf_new_from_file ("apple-red.png", NULL);
|
|
||||||
toplevel = gtk_window_new ();
|
|
||||||
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
|
|
||||||
gtk_window_set_child (GTK_WINDOW (toplevel), hbox);
|
|
||||||
|
|
||||||
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
|
||||||
gtk_box_append (GTK_BOX (hbox), vbox);
|
|
||||||
|
|
||||||
image = gtk_image_new_from_gicon (G_ICON (pixbuf));
|
|
||||||
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
|
|
||||||
gtk_box_append (GTK_BOX (vbox), image);
|
|
||||||
|
|
||||||
label = gtk_label_new (NULL);
|
|
||||||
str = g_strdup_printf ("Normal icon, hash %u", g_icon_hash (G_ICON (pixbuf)));
|
|
||||||
gtk_label_set_label (GTK_LABEL (label), str);
|
|
||||||
gtk_box_append (GTK_BOX (vbox), label);
|
|
||||||
|
|
||||||
otherpix = gdk_pixbuf_new_from_file ("gnome-textfile.png", NULL);
|
|
||||||
emblem = g_emblem_new (G_ICON (otherpix));
|
|
||||||
emblemed = g_emblemed_icon_new (G_ICON (pixbuf), emblem);
|
|
||||||
|
|
||||||
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
|
||||||
gtk_box_append (GTK_BOX (hbox), vbox);
|
|
||||||
|
|
||||||
image2 = gtk_image_new_from_gicon (emblemed);
|
|
||||||
gtk_image_set_icon_size (GTK_IMAGE (image2), GTK_ICON_SIZE_LARGE);
|
|
||||||
gtk_box_append (GTK_BOX (vbox), image2);
|
|
||||||
|
|
||||||
label = gtk_label_new (NULL);
|
|
||||||
str = g_strdup_printf ("Emblemed icon, hash %u", g_icon_hash (emblemed));
|
|
||||||
gtk_label_set_label (GTK_LABEL (label), str);
|
|
||||||
gtk_box_append (GTK_BOX (vbox), label);
|
|
||||||
|
|
||||||
gtk_widget_show (toplevel);
|
|
||||||
|
|
||||||
g_signal_connect (toplevel, "destroy", G_CALLBACK (quit_cb), &done);
|
|
||||||
|
|
||||||
while (!done)
|
|
||||||
g_main_context_iteration (NULL, TRUE);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,5 +1,368 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
static void
|
||||||
|
unset_title (GtkWidget *window)
|
||||||
|
{
|
||||||
|
GtkWidget *box;
|
||||||
|
|
||||||
|
g_assert (GTK_IS_WINDOW (window));
|
||||||
|
|
||||||
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
||||||
|
gtk_widget_hide (box);
|
||||||
|
|
||||||
|
gtk_window_set_titlebar (GTK_WINDOW (window), box);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
load_css (GtkWidget *widget,
|
||||||
|
const char *css)
|
||||||
|
{
|
||||||
|
GtkCssProvider *provider;
|
||||||
|
GtkStyleContext *context;
|
||||||
|
|
||||||
|
context = gtk_widget_get_style_context (widget);
|
||||||
|
|
||||||
|
provider = gtk_css_provider_new ();
|
||||||
|
gtk_css_provider_load_from_data (provider, css, -1);
|
||||||
|
gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), 800);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
create_regular (GtkApplication *app)
|
||||||
|
{
|
||||||
|
GtkWidget *window, *label;
|
||||||
|
|
||||||
|
window = gtk_application_window_new (app);
|
||||||
|
gtk_window_set_title (GTK_WINDOW (window), "Regular window");
|
||||||
|
|
||||||
|
label = gtk_label_new ("This window has no titlebar set");
|
||||||
|
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
||||||
|
gtk_window_set_child (GTK_WINDOW (window), label);
|
||||||
|
|
||||||
|
gtk_widget_show (window);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
create_headerbar_as_titlebar (GtkApplication *app)
|
||||||
|
{
|
||||||
|
GtkWidget *window, *header, *label;
|
||||||
|
|
||||||
|
window = gtk_application_window_new (app);
|
||||||
|
gtk_window_set_title (GTK_WINDOW (window), "Headerbar as titlebar");
|
||||||
|
|
||||||
|
header = gtk_header_bar_new ();
|
||||||
|
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), TRUE);
|
||||||
|
gtk_window_set_titlebar (GTK_WINDOW (window), header);
|
||||||
|
|
||||||
|
label = gtk_label_new ("This window has a headerbar set as a titlebar");
|
||||||
|
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
||||||
|
gtk_window_set_child (GTK_WINDOW (window), label);
|
||||||
|
|
||||||
|
gtk_widget_show (window);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
create_headerbar_inside_window (GtkApplication *app)
|
||||||
|
{
|
||||||
|
GtkWidget *window, *box, *header, *label;
|
||||||
|
|
||||||
|
window = gtk_application_window_new (app);
|
||||||
|
gtk_window_set_title (GTK_WINDOW (window), "Headerbar inside window");
|
||||||
|
unset_title (window);
|
||||||
|
|
||||||
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||||
|
gtk_window_set_child (GTK_WINDOW (window), box);
|
||||||
|
|
||||||
|
header = gtk_header_bar_new ();
|
||||||
|
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), TRUE);
|
||||||
|
gtk_box_append (GTK_BOX (box), header);
|
||||||
|
|
||||||
|
label = gtk_label_new ("This window has a headerbar inside the window and no titlebar");
|
||||||
|
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
||||||
|
gtk_widget_set_vexpand (label, TRUE);
|
||||||
|
gtk_box_append (GTK_BOX (box), label);
|
||||||
|
|
||||||
|
gtk_widget_show (window);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
create_headerbar_overlay (GtkApplication *app)
|
||||||
|
{
|
||||||
|
GtkWidget *window, *overlay, *sw, *box, *header, *label;
|
||||||
|
|
||||||
|
window = gtk_application_window_new (app);
|
||||||
|
gtk_window_set_title (GTK_WINDOW (window), "Headerbar overlaying content");
|
||||||
|
unset_title (window);
|
||||||
|
|
||||||
|
overlay = gtk_overlay_new ();
|
||||||
|
gtk_window_set_child (GTK_WINDOW (window), overlay);
|
||||||
|
|
||||||
|
header = gtk_header_bar_new ();
|
||||||
|
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), TRUE);
|
||||||
|
gtk_widget_set_valign (header, GTK_ALIGN_START);
|
||||||
|
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), header);
|
||||||
|
load_css (header, "headerbar { background: alpha(shade(@theme_bg_color, .9), .8); }");
|
||||||
|
|
||||||
|
sw = gtk_scrolled_window_new (NULL, NULL);
|
||||||
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
||||||
|
gtk_widget_set_size_request (sw, 300, 250);
|
||||||
|
gtk_overlay_set_child (GTK_OVERLAY (overlay), sw);
|
||||||
|
|
||||||
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
||||||
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), box);
|
||||||
|
gtk_widget_set_size_request (sw, 300, 250);
|
||||||
|
|
||||||
|
label = gtk_label_new ("Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
|
||||||
|
"Nulla innn urna ac dui malesuada ornare. Nullam dictum "
|
||||||
|
"tempor mi et tincidunt. Aliquam metus nulla, auctor "
|
||||||
|
"vitae pulvinar nec, egestas at mi. Class aptent taciti "
|
||||||
|
"sociosqu ad litora torquent per conubia nostra, per "
|
||||||
|
"inceptos himenaeos. Aliquam sagittis, tellus congue "
|
||||||
|
"cursus congue, diam massa mollis enim, sit amet gravida "
|
||||||
|
"magna turpis egestas sapien. Aenean vel molestie nunc. "
|
||||||
|
"In hac habitasse platea dictumst. Suspendisse lacinia"
|
||||||
|
"mi eu ipsum vestibulum in venenatis enim commodo. "
|
||||||
|
"Vivamus non malesuada ligula.");
|
||||||
|
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
||||||
|
gtk_box_append (GTK_BOX (box), label);
|
||||||
|
|
||||||
|
label = gtk_label_new ("This window has a headerbar inside an overlay, so the text is visible underneath it");
|
||||||
|
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
||||||
|
gtk_widget_set_vexpand (label, TRUE);
|
||||||
|
gtk_box_append (GTK_BOX (box), label);
|
||||||
|
|
||||||
|
gtk_widget_show (window);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
create_hiding_headerbar (GtkApplication *app)
|
||||||
|
{
|
||||||
|
GtkWidget *window, *box, *revealer, *header, *label, *hbox, *toggle;
|
||||||
|
|
||||||
|
window = gtk_application_window_new (app);
|
||||||
|
gtk_window_set_title (GTK_WINDOW (window), "Hiding headerbar");
|
||||||
|
unset_title (window);
|
||||||
|
|
||||||
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||||
|
gtk_window_set_child (GTK_WINDOW (window), box);
|
||||||
|
|
||||||
|
revealer = gtk_revealer_new ();
|
||||||
|
gtk_box_append (GTK_BOX (box), revealer);
|
||||||
|
|
||||||
|
header = gtk_header_bar_new ();
|
||||||
|
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), TRUE);
|
||||||
|
gtk_revealer_set_child (GTK_REVEALER (revealer), header);
|
||||||
|
|
||||||
|
label = gtk_label_new ("This window's headerbar can be shown and hidden with animation");
|
||||||
|
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
||||||
|
gtk_widget_set_vexpand (label, TRUE);
|
||||||
|
gtk_box_append (GTK_BOX (box), label);
|
||||||
|
|
||||||
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
|
||||||
|
gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
|
||||||
|
gtk_widget_set_margin_top (hbox, 12);
|
||||||
|
gtk_widget_set_margin_bottom (hbox, 12);
|
||||||
|
gtk_widget_set_margin_start (hbox, 12);
|
||||||
|
gtk_widget_set_margin_end (hbox, 12);
|
||||||
|
gtk_box_append (GTK_BOX (box), hbox);
|
||||||
|
|
||||||
|
toggle = gtk_switch_new ();
|
||||||
|
gtk_switch_set_active (GTK_SWITCH (toggle), TRUE);
|
||||||
|
gtk_box_append (GTK_BOX (hbox), toggle);
|
||||||
|
g_object_bind_property (toggle, "active",
|
||||||
|
revealer, "reveal-child",
|
||||||
|
G_BINDING_SYNC_CREATE);
|
||||||
|
|
||||||
|
label = gtk_label_new ("Show headerbar");
|
||||||
|
gtk_box_append (GTK_BOX (hbox), label);
|
||||||
|
|
||||||
|
gtk_widget_show (window);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
create_fake_headerbar (GtkApplication *app)
|
||||||
|
{
|
||||||
|
GtkWidget *window, *handle, *box, *center_box, *controls, *label;
|
||||||
|
|
||||||
|
window = gtk_application_window_new (app);
|
||||||
|
gtk_window_set_title (GTK_WINDOW (window), "Fake headerbar");
|
||||||
|
unset_title (window);
|
||||||
|
|
||||||
|
handle = gtk_window_handle_new ();
|
||||||
|
gtk_window_set_child (GTK_WINDOW (window), handle);
|
||||||
|
|
||||||
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||||
|
gtk_window_handle_set_child (GTK_WINDOW_HANDLE (handle), box);
|
||||||
|
|
||||||
|
center_box = gtk_center_box_new ();
|
||||||
|
gtk_box_append (GTK_BOX (box), center_box);
|
||||||
|
|
||||||
|
label = gtk_label_new ("Fake headerbar");
|
||||||
|
gtk_center_box_set_center_widget (GTK_CENTER_BOX (center_box), label);
|
||||||
|
|
||||||
|
controls = gtk_window_controls_new (GTK_PACK_START);
|
||||||
|
gtk_center_box_set_start_widget (GTK_CENTER_BOX (center_box), controls);
|
||||||
|
|
||||||
|
controls = gtk_window_controls_new (GTK_PACK_END);
|
||||||
|
gtk_center_box_set_end_widget (GTK_CENTER_BOX (center_box), controls);
|
||||||
|
|
||||||
|
label = gtk_label_new ("This window's titlebar is just a centerbox with a label and window controls.\nThe whole window is draggable.");
|
||||||
|
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
||||||
|
gtk_widget_set_vexpand (label, TRUE);
|
||||||
|
gtk_box_append (GTK_BOX (box), label);
|
||||||
|
|
||||||
|
gtk_widget_show (window);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* split headerbar */
|
||||||
|
|
||||||
|
static void
|
||||||
|
split_decorations (GtkSettings *settings,
|
||||||
|
GParamSpec *pspec,
|
||||||
|
GtkBuilder *builder)
|
||||||
|
{
|
||||||
|
GtkWidget *sheader, *mheader;
|
||||||
|
gchar *layout, *p1, *p2;
|
||||||
|
gchar **p;
|
||||||
|
|
||||||
|
sheader = (GtkWidget *)gtk_builder_get_object (builder, "sidebar-header");
|
||||||
|
mheader = (GtkWidget *)gtk_builder_get_object (builder, "main-header");
|
||||||
|
|
||||||
|
g_object_get (settings, "gtk-decoration-layout", &layout, NULL);
|
||||||
|
|
||||||
|
p = g_strsplit (layout, ":", -1);
|
||||||
|
|
||||||
|
p1 = g_strconcat ("", p[0], ":", NULL);
|
||||||
|
|
||||||
|
if (g_strv_length (p) >= 2)
|
||||||
|
p2 = g_strconcat (":", p[1], NULL);
|
||||||
|
else
|
||||||
|
p2 = g_strdup ("");
|
||||||
|
|
||||||
|
gtk_header_bar_set_decoration_layout (GTK_HEADER_BAR (sheader), p1);
|
||||||
|
gtk_header_bar_set_decoration_layout (GTK_HEADER_BAR (mheader), p2);
|
||||||
|
|
||||||
|
g_free (p1);
|
||||||
|
g_free (p2);
|
||||||
|
g_strfreev (p);
|
||||||
|
g_free (layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
create_split_headerbar (GtkApplication *app)
|
||||||
|
{
|
||||||
|
GtkBuilder *builder;
|
||||||
|
GtkSettings *settings;
|
||||||
|
GtkWidget *win;
|
||||||
|
GtkWidget *entry;
|
||||||
|
GtkWidget *check;
|
||||||
|
GtkWidget *header;
|
||||||
|
const char *ui = "tests/testsplitheaders.ui";
|
||||||
|
|
||||||
|
if (!g_file_test (ui, G_FILE_TEST_EXISTS))
|
||||||
|
{
|
||||||
|
g_warning ("Can't find %s", ui);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = gtk_builder_new_from_file (ui);
|
||||||
|
|
||||||
|
win = (GtkWidget *)gtk_builder_get_object (builder, "window");
|
||||||
|
gtk_window_set_application (GTK_WINDOW (win), app);
|
||||||
|
|
||||||
|
settings = gtk_widget_get_settings (win);
|
||||||
|
|
||||||
|
g_signal_connect (settings, "notify::gtk-decoration-layout",
|
||||||
|
G_CALLBACK (split_decorations), builder);
|
||||||
|
split_decorations (settings, NULL, builder);
|
||||||
|
|
||||||
|
entry = (GtkWidget *)gtk_builder_get_object (builder, "layout-entry");
|
||||||
|
g_object_bind_property (settings, "gtk-decoration-layout",
|
||||||
|
entry, "text",
|
||||||
|
G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);
|
||||||
|
check = (GtkWidget *)gtk_builder_get_object (builder, "decorations");
|
||||||
|
header = (GtkWidget *)gtk_builder_get_object (builder, "sidebar-header");
|
||||||
|
g_object_bind_property (check, "active",
|
||||||
|
header, "show-title-buttons",
|
||||||
|
G_BINDING_DEFAULT);
|
||||||
|
header = (GtkWidget *)gtk_builder_get_object (builder, "main-header");
|
||||||
|
g_object_bind_property (check, "active",
|
||||||
|
header, "show-title-buttons",
|
||||||
|
G_BINDING_DEFAULT);
|
||||||
|
gtk_window_present (GTK_WINDOW (win));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* stacked headers */
|
||||||
|
|
||||||
|
static void
|
||||||
|
back_to_main (GtkButton *button,
|
||||||
|
GtkWidget *win)
|
||||||
|
{
|
||||||
|
GtkWidget *header_stack;
|
||||||
|
GtkWidget *page_stack;
|
||||||
|
|
||||||
|
header_stack = GTK_WIDGET (g_object_get_data (G_OBJECT (win), "header-stack"));
|
||||||
|
page_stack = GTK_WIDGET (g_object_get_data (G_OBJECT (win), "page-stack"));
|
||||||
|
|
||||||
|
gtk_stack_set_visible_child_name (GTK_STACK (header_stack), "main");
|
||||||
|
gtk_stack_set_visible_child_name (GTK_STACK (page_stack), "page1");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
go_to_secondary (GtkButton *button,
|
||||||
|
GtkWidget *win)
|
||||||
|
{
|
||||||
|
GtkWidget *header_stack;
|
||||||
|
GtkWidget *page_stack;
|
||||||
|
|
||||||
|
header_stack = GTK_WIDGET (g_object_get_data (G_OBJECT (win), "header-stack"));
|
||||||
|
page_stack = GTK_WIDGET (g_object_get_data (G_OBJECT (win), "page-stack"));
|
||||||
|
|
||||||
|
gtk_stack_set_visible_child_name (GTK_STACK (header_stack), "secondary");
|
||||||
|
gtk_stack_set_visible_child_name (GTK_STACK (page_stack), "secondary");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
create_stacked_headerbar (GtkApplication *app)
|
||||||
|
{
|
||||||
|
GtkBuilder *builder;
|
||||||
|
GtkWidget *win;
|
||||||
|
GtkWidget *new_btn;
|
||||||
|
GtkWidget *back_btn;
|
||||||
|
GtkWidget *header_stack;
|
||||||
|
GtkWidget *page_stack;
|
||||||
|
const char *ui = "tests/teststackedheaders.ui";
|
||||||
|
|
||||||
|
if (!g_file_test (ui, G_FILE_TEST_EXISTS))
|
||||||
|
{
|
||||||
|
g_warning ("Can't find %s", ui);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = gtk_builder_new ();
|
||||||
|
gtk_builder_add_from_file (builder, ui, NULL);
|
||||||
|
|
||||||
|
win = (GtkWidget *)gtk_builder_get_object (builder, "window");
|
||||||
|
gtk_window_set_application (GTK_WINDOW (win), app);
|
||||||
|
|
||||||
|
header_stack = (GtkWidget *)gtk_builder_get_object (builder, "header_stack");
|
||||||
|
page_stack = (GtkWidget *)gtk_builder_get_object (builder, "page_stack");
|
||||||
|
|
||||||
|
g_object_set_data (G_OBJECT (win), "header-stack", header_stack);
|
||||||
|
g_object_set_data (G_OBJECT (win), "page-stack", page_stack);
|
||||||
|
|
||||||
|
new_btn = (GtkWidget *)gtk_builder_get_object (builder, "new_btn");
|
||||||
|
back_btn = (GtkWidget *)gtk_builder_get_object (builder, "back_btn");
|
||||||
|
|
||||||
|
g_signal_connect (new_btn, "clicked", G_CALLBACK (go_to_secondary), win);
|
||||||
|
g_signal_connect (back_btn, "clicked", G_CALLBACK (back_to_main), win);
|
||||||
|
|
||||||
|
gtk_window_present (GTK_WINDOW (win));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* technorama */
|
||||||
|
|
||||||
static const gchar css[] =
|
static const gchar css[] =
|
||||||
".main.background { "
|
".main.background { "
|
||||||
" background-image: linear-gradient(to bottom, red, blue);"
|
" background-image: linear-gradient(to bottom, red, blue);"
|
||||||
@ -34,8 +397,6 @@ on_bookmark_clicked (GtkButton *button, gpointer data)
|
|||||||
gtk_widget_show (chooser);
|
gtk_widget_show (chooser);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GtkWidget *header;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
toggle_fullscreen (GtkButton *button, gpointer data)
|
toggle_fullscreen (GtkButton *button, gpointer data)
|
||||||
{
|
{
|
||||||
@ -54,19 +415,6 @@ toggle_fullscreen (GtkButton *button, gpointer data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean done = FALSE;
|
|
||||||
|
|
||||||
static void
|
|
||||||
quit_cb (GtkWidget *widget,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
gboolean *is_done = user_data;
|
|
||||||
|
|
||||||
*is_done = TRUE;
|
|
||||||
|
|
||||||
g_main_context_wakeup (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
change_header (GtkButton *button, gpointer data)
|
change_header (GtkButton *button, gpointer data)
|
||||||
{
|
{
|
||||||
@ -74,6 +422,7 @@ change_header (GtkButton *button, gpointer data)
|
|||||||
GtkWidget *label;
|
GtkWidget *label;
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
GtkWidget *image;
|
GtkWidget *image;
|
||||||
|
GtkWidget *header;
|
||||||
|
|
||||||
if (button && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
|
if (button && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
|
||||||
{
|
{
|
||||||
@ -99,7 +448,7 @@ change_header (GtkButton *button, gpointer data)
|
|||||||
widget = gtk_button_new_with_label ("_Close");
|
widget = gtk_button_new_with_label ("_Close");
|
||||||
gtk_button_set_use_underline (GTK_BUTTON (widget), TRUE);
|
gtk_button_set_use_underline (GTK_BUTTON (widget), TRUE);
|
||||||
gtk_widget_add_css_class (widget, "suggested-action");
|
gtk_widget_add_css_class (widget, "suggested-action");
|
||||||
g_signal_connect (widget, "clicked", G_CALLBACK (quit_cb), &done);
|
g_signal_connect_swapped (widget, "clicked", G_CALLBACK (gtk_window_destroy), window);
|
||||||
|
|
||||||
gtk_header_bar_pack_end (GTK_HEADER_BAR (header), widget);
|
gtk_header_bar_pack_end (GTK_HEADER_BAR (header), widget);
|
||||||
|
|
||||||
@ -114,8 +463,8 @@ change_header (GtkButton *button, gpointer data)
|
|||||||
gtk_window_set_titlebar (GTK_WINDOW (window), header);
|
gtk_window_set_titlebar (GTK_WINDOW (window), header);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static void
|
||||||
main (int argc, char *argv[])
|
create_technorama (GtkApplication *app)
|
||||||
{
|
{
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
GtkWidget *box;
|
GtkWidget *box;
|
||||||
@ -124,9 +473,9 @@ main (int argc, char *argv[])
|
|||||||
GtkWidget *content;
|
GtkWidget *content;
|
||||||
GtkCssProvider *provider;
|
GtkCssProvider *provider;
|
||||||
|
|
||||||
gtk_init ();
|
|
||||||
|
|
||||||
window = gtk_window_new ();
|
window = gtk_window_new ();
|
||||||
|
gtk_window_set_application (GTK_WINDOW (window), app);
|
||||||
|
|
||||||
gtk_widget_add_css_class (window, "main");
|
gtk_widget_add_css_class (window, "main");
|
||||||
|
|
||||||
provider = gtk_css_provider_new ();
|
provider = gtk_css_provider_new ();
|
||||||
@ -157,11 +506,70 @@ main (int argc, char *argv[])
|
|||||||
g_signal_connect (button, "clicked", G_CALLBACK (toggle_fullscreen), window);
|
g_signal_connect (button, "clicked", G_CALLBACK (toggle_fullscreen), window);
|
||||||
gtk_box_append (GTK_BOX (box), footer);
|
gtk_box_append (GTK_BOX (box), footer);
|
||||||
gtk_widget_show (window);
|
gtk_widget_show (window);
|
||||||
|
}
|
||||||
|
|
||||||
while (!done)
|
struct {
|
||||||
g_main_context_iteration (NULL, TRUE);
|
const gchar *name;
|
||||||
|
void (*cb) (GtkApplication *app);
|
||||||
|
} buttons[] =
|
||||||
|
{
|
||||||
|
{ "Regular window", create_regular },
|
||||||
|
{ "Headerbar as titlebar", create_headerbar_as_titlebar },
|
||||||
|
{ "Headerbar inside window", create_headerbar_inside_window },
|
||||||
|
{ "Headerbar overlaying content", create_headerbar_overlay },
|
||||||
|
{ "Hiding headerbar", create_hiding_headerbar },
|
||||||
|
{ "Fake headerbar", create_fake_headerbar },
|
||||||
|
{ "Split headerbar", create_split_headerbar },
|
||||||
|
{ "Stacked headerbar", create_stacked_headerbar },
|
||||||
|
{ "Technorama", create_technorama },
|
||||||
|
};
|
||||||
|
int n_buttons = sizeof (buttons) / sizeof (buttons[0]);
|
||||||
|
|
||||||
gtk_window_destroy (GTK_WINDOW (window));
|
static void
|
||||||
|
app_activate_cb (GtkApplication *app)
|
||||||
|
{
|
||||||
|
GtkWidget *window, *box;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
window = gtk_application_window_new (app);
|
||||||
|
gtk_window_set_title (GTK_WINDOW (window), "Headerbar test");
|
||||||
|
|
||||||
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||||
|
gtk_widget_set_halign (box, GTK_ALIGN_CENTER);
|
||||||
|
gtk_widget_set_valign (box, GTK_ALIGN_CENTER);
|
||||||
|
gtk_widget_add_css_class (box, "linked");
|
||||||
|
gtk_window_set_child (GTK_WINDOW (window), box);
|
||||||
|
|
||||||
|
for (i = 0; i < n_buttons; i++)
|
||||||
|
{
|
||||||
|
GtkWidget *btn;
|
||||||
|
|
||||||
|
btn = gtk_button_new_with_label (buttons[i].name);
|
||||||
|
g_signal_connect_object (btn,
|
||||||
|
"clicked",
|
||||||
|
G_CALLBACK (buttons[i].cb),
|
||||||
|
app,
|
||||||
|
G_CONNECT_SWAPPED);
|
||||||
|
gtk_box_append (GTK_BOX (box), btn);
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_widget_show (window);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc,
|
||||||
|
char **argv)
|
||||||
|
{
|
||||||
|
GtkApplication *app;
|
||||||
|
|
||||||
|
app = gtk_application_new ("org.gtk.Test.headerbar2", 0);
|
||||||
|
|
||||||
|
g_signal_connect (app,
|
||||||
|
"activate",
|
||||||
|
G_CALLBACK (app_activate_cb),
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
g_application_run (G_APPLICATION (app), argc, argv);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,278 +0,0 @@
|
|||||||
#include <gtk/gtk.h>
|
|
||||||
|
|
||||||
static void
|
|
||||||
unset_title (GtkWidget *window)
|
|
||||||
{
|
|
||||||
GtkWidget *box;
|
|
||||||
|
|
||||||
g_assert (GTK_IS_WINDOW (window));
|
|
||||||
|
|
||||||
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
||||||
gtk_widget_hide (box);
|
|
||||||
|
|
||||||
gtk_window_set_titlebar (GTK_WINDOW (window), box);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
load_css (GtkWidget *widget,
|
|
||||||
const char *css)
|
|
||||||
{
|
|
||||||
GtkCssProvider *provider;
|
|
||||||
GtkStyleContext *context;
|
|
||||||
|
|
||||||
context = gtk_widget_get_style_context (widget);
|
|
||||||
|
|
||||||
provider = gtk_css_provider_new ();
|
|
||||||
gtk_css_provider_load_from_data (provider, css, -1);
|
|
||||||
gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), 800);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
create_regular (GtkApplication *app)
|
|
||||||
{
|
|
||||||
GtkWidget *window, *label;
|
|
||||||
|
|
||||||
window = gtk_application_window_new (app);
|
|
||||||
gtk_window_set_title (GTK_WINDOW (window), "Regular window");
|
|
||||||
|
|
||||||
label = gtk_label_new ("This window has no titlebar set");
|
|
||||||
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
|
||||||
gtk_window_set_child (GTK_WINDOW (window), label);
|
|
||||||
|
|
||||||
gtk_widget_show (window);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
create_headerbar_as_titlebar (GtkApplication *app)
|
|
||||||
{
|
|
||||||
GtkWidget *window, *header, *label;
|
|
||||||
|
|
||||||
window = gtk_application_window_new (app);
|
|
||||||
gtk_window_set_title (GTK_WINDOW (window), "Headerbar as titlebar");
|
|
||||||
|
|
||||||
header = gtk_header_bar_new ();
|
|
||||||
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), TRUE);
|
|
||||||
gtk_window_set_titlebar (GTK_WINDOW (window), header);
|
|
||||||
|
|
||||||
label = gtk_label_new ("This window has a headerbar set as a titlebar");
|
|
||||||
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
|
||||||
gtk_window_set_child (GTK_WINDOW (window), label);
|
|
||||||
|
|
||||||
gtk_widget_show (window);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
create_headerbar_inside_window (GtkApplication *app)
|
|
||||||
{
|
|
||||||
GtkWidget *window, *box, *header, *label;
|
|
||||||
|
|
||||||
window = gtk_application_window_new (app);
|
|
||||||
gtk_window_set_title (GTK_WINDOW (window), "Headerbar inside window");
|
|
||||||
unset_title (window);
|
|
||||||
|
|
||||||
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
||||||
gtk_window_set_child (GTK_WINDOW (window), box);
|
|
||||||
|
|
||||||
header = gtk_header_bar_new ();
|
|
||||||
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), TRUE);
|
|
||||||
gtk_box_append (GTK_BOX (box), header);
|
|
||||||
|
|
||||||
label = gtk_label_new ("This window has a headerbar inside the window and no titlebar");
|
|
||||||
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
|
||||||
gtk_widget_set_vexpand (label, TRUE);
|
|
||||||
gtk_box_append (GTK_BOX (box), label);
|
|
||||||
|
|
||||||
gtk_widget_show (window);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
create_headerbar_overlay (GtkApplication *app)
|
|
||||||
{
|
|
||||||
GtkWidget *window, *overlay, *sw, *box, *header, *label;
|
|
||||||
|
|
||||||
window = gtk_application_window_new (app);
|
|
||||||
gtk_window_set_title (GTK_WINDOW (window), "Headerbar overlaying content");
|
|
||||||
unset_title (window);
|
|
||||||
|
|
||||||
overlay = gtk_overlay_new ();
|
|
||||||
gtk_window_set_child (GTK_WINDOW (window), overlay);
|
|
||||||
|
|
||||||
header = gtk_header_bar_new ();
|
|
||||||
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), TRUE);
|
|
||||||
gtk_widget_set_valign (header, GTK_ALIGN_START);
|
|
||||||
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), header);
|
|
||||||
load_css (header, "headerbar { background: alpha(shade(@theme_bg_color, .9), .8); }");
|
|
||||||
|
|
||||||
sw = gtk_scrolled_window_new (NULL, NULL);
|
|
||||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
|
||||||
gtk_widget_set_size_request (sw, 300, 250);
|
|
||||||
gtk_overlay_set_child (GTK_OVERLAY (overlay), sw);
|
|
||||||
|
|
||||||
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
|
||||||
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), box);
|
|
||||||
gtk_widget_set_size_request (sw, 300, 250);
|
|
||||||
|
|
||||||
label = gtk_label_new ("Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
|
|
||||||
"Nulla innn urna ac dui malesuada ornare. Nullam dictum "
|
|
||||||
"tempor mi et tincidunt. Aliquam metus nulla, auctor "
|
|
||||||
"vitae pulvinar nec, egestas at mi. Class aptent taciti "
|
|
||||||
"sociosqu ad litora torquent per conubia nostra, per "
|
|
||||||
"inceptos himenaeos. Aliquam sagittis, tellus congue "
|
|
||||||
"cursus congue, diam massa mollis enim, sit amet gravida "
|
|
||||||
"magna turpis egestas sapien. Aenean vel molestie nunc. "
|
|
||||||
"In hac habitasse platea dictumst. Suspendisse lacinia"
|
|
||||||
"mi eu ipsum vestibulum in venenatis enim commodo. "
|
|
||||||
"Vivamus non malesuada ligula.");
|
|
||||||
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
|
||||||
gtk_box_append (GTK_BOX (box), label);
|
|
||||||
|
|
||||||
label = gtk_label_new ("This window has a headerbar inside an overlay, so the text is visible underneath it");
|
|
||||||
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
|
||||||
gtk_widget_set_vexpand (label, TRUE);
|
|
||||||
gtk_box_append (GTK_BOX (box), label);
|
|
||||||
|
|
||||||
gtk_widget_show (window);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
create_hiding_headerbar (GtkApplication *app)
|
|
||||||
{
|
|
||||||
GtkWidget *window, *box, *revealer, *header, *label, *hbox, *toggle;
|
|
||||||
|
|
||||||
window = gtk_application_window_new (app);
|
|
||||||
gtk_window_set_title (GTK_WINDOW (window), "Hiding headerbar");
|
|
||||||
unset_title (window);
|
|
||||||
|
|
||||||
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
||||||
gtk_window_set_child (GTK_WINDOW (window), box);
|
|
||||||
|
|
||||||
revealer = gtk_revealer_new ();
|
|
||||||
gtk_box_append (GTK_BOX (box), revealer);
|
|
||||||
|
|
||||||
header = gtk_header_bar_new ();
|
|
||||||
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), TRUE);
|
|
||||||
gtk_revealer_set_child (GTK_REVEALER (revealer), header);
|
|
||||||
|
|
||||||
label = gtk_label_new ("This window's headerbar can be shown and hidden with animation");
|
|
||||||
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
|
||||||
gtk_widget_set_vexpand (label, TRUE);
|
|
||||||
gtk_box_append (GTK_BOX (box), label);
|
|
||||||
|
|
||||||
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
|
|
||||||
gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
|
|
||||||
gtk_widget_set_margin_top (hbox, 12);
|
|
||||||
gtk_widget_set_margin_bottom (hbox, 12);
|
|
||||||
gtk_widget_set_margin_start (hbox, 12);
|
|
||||||
gtk_widget_set_margin_end (hbox, 12);
|
|
||||||
gtk_box_append (GTK_BOX (box), hbox);
|
|
||||||
|
|
||||||
toggle = gtk_switch_new ();
|
|
||||||
gtk_switch_set_active (GTK_SWITCH (toggle), TRUE);
|
|
||||||
gtk_box_append (GTK_BOX (hbox), toggle);
|
|
||||||
g_object_bind_property (toggle, "active",
|
|
||||||
revealer, "reveal-child",
|
|
||||||
G_BINDING_SYNC_CREATE);
|
|
||||||
|
|
||||||
label = gtk_label_new ("Show headerbar");
|
|
||||||
gtk_box_append (GTK_BOX (hbox), label);
|
|
||||||
|
|
||||||
gtk_widget_show (window);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
create_fake_headerbar (GtkApplication *app)
|
|
||||||
{
|
|
||||||
GtkWidget *window, *handle, *box, *center_box, *controls, *label;
|
|
||||||
|
|
||||||
window = gtk_application_window_new (app);
|
|
||||||
gtk_window_set_title (GTK_WINDOW (window), "Fake headerbar");
|
|
||||||
unset_title (window);
|
|
||||||
|
|
||||||
handle = gtk_window_handle_new ();
|
|
||||||
gtk_window_set_child (GTK_WINDOW (window), handle);
|
|
||||||
|
|
||||||
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
||||||
gtk_window_handle_set_child (GTK_WINDOW_HANDLE (handle), box);
|
|
||||||
|
|
||||||
center_box = gtk_center_box_new ();
|
|
||||||
gtk_box_append (GTK_BOX (box), center_box);
|
|
||||||
|
|
||||||
label = gtk_label_new ("Fake headerbar");
|
|
||||||
gtk_center_box_set_center_widget (GTK_CENTER_BOX (center_box), label);
|
|
||||||
|
|
||||||
controls = gtk_window_controls_new (GTK_PACK_START);
|
|
||||||
gtk_center_box_set_start_widget (GTK_CENTER_BOX (center_box), controls);
|
|
||||||
|
|
||||||
controls = gtk_window_controls_new (GTK_PACK_END);
|
|
||||||
gtk_center_box_set_end_widget (GTK_CENTER_BOX (center_box), controls);
|
|
||||||
|
|
||||||
label = gtk_label_new ("This window's titlebar is just a centerbox with a label and window controls.\nThe whole window is draggable.");
|
|
||||||
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
|
||||||
gtk_widget_set_vexpand (label, TRUE);
|
|
||||||
gtk_box_append (GTK_BOX (box), label);
|
|
||||||
|
|
||||||
gtk_widget_show (window);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct {
|
|
||||||
const gchar *name;
|
|
||||||
void (*cb) (GtkApplication *app);
|
|
||||||
} buttons[] =
|
|
||||||
{
|
|
||||||
{ "Regular window", create_regular },
|
|
||||||
{ "Headerbar as titlebar", create_headerbar_as_titlebar },
|
|
||||||
{ "Headerbar inside window", create_headerbar_inside_window },
|
|
||||||
{ "Headerbar overlaying content", create_headerbar_overlay },
|
|
||||||
{ "Hiding headerbar", create_hiding_headerbar },
|
|
||||||
{ "Fake headerbar", create_fake_headerbar },
|
|
||||||
};
|
|
||||||
int n_buttons = sizeof (buttons) / sizeof (buttons[0]);
|
|
||||||
|
|
||||||
static void
|
|
||||||
app_activate_cb (GtkApplication *app)
|
|
||||||
{
|
|
||||||
GtkWidget *window, *box;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
window = gtk_application_window_new (app);
|
|
||||||
gtk_window_set_title (GTK_WINDOW (window), "Headerbar test");
|
|
||||||
|
|
||||||
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
||||||
gtk_widget_set_halign (box, GTK_ALIGN_CENTER);
|
|
||||||
gtk_widget_set_valign (box, GTK_ALIGN_CENTER);
|
|
||||||
gtk_widget_add_css_class (box, "linked");
|
|
||||||
gtk_window_set_child (GTK_WINDOW (window), box);
|
|
||||||
|
|
||||||
for (i = 0; i < n_buttons; i++)
|
|
||||||
{
|
|
||||||
GtkWidget *btn;
|
|
||||||
|
|
||||||
btn = gtk_button_new_with_label (buttons[i].name);
|
|
||||||
g_signal_connect_object (btn,
|
|
||||||
"clicked",
|
|
||||||
G_CALLBACK (buttons[i].cb),
|
|
||||||
app,
|
|
||||||
G_CONNECT_SWAPPED);
|
|
||||||
gtk_box_append (GTK_BOX (box), btn);
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_widget_show (window);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
main (int argc,
|
|
||||||
char **argv)
|
|
||||||
{
|
|
||||||
GtkApplication *app;
|
|
||||||
|
|
||||||
app = gtk_application_new ("org.gtk.Test.headerbar2", 0);
|
|
||||||
|
|
||||||
g_signal_connect (app,
|
|
||||||
"activate",
|
|
||||||
G_CALLBACK (app_activate_cb),
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
g_application_run (G_APPLICATION (app), argc, argv);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,98 +0,0 @@
|
|||||||
/* testorientable.c
|
|
||||||
* Copyright (C) 2004 Red Hat, Inc.
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Library General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Library General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
|
||||||
|
|
||||||
static void
|
|
||||||
orient_toggled (GtkToggleButton *button, gpointer user_data)
|
|
||||||
{
|
|
||||||
GList *orientables = (GList *) user_data, *ptr;
|
|
||||||
gboolean state = gtk_toggle_button_get_active (button);
|
|
||||||
GtkOrientation orientation;
|
|
||||||
|
|
||||||
if (state)
|
|
||||||
{
|
|
||||||
orientation = GTK_ORIENTATION_VERTICAL;
|
|
||||||
gtk_button_set_label (GTK_BUTTON (button), "Vertical");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
orientation = GTK_ORIENTATION_HORIZONTAL;
|
|
||||||
gtk_button_set_label (GTK_BUTTON (button), "Horizontal");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ptr = orientables; ptr; ptr = ptr->next)
|
|
||||||
{
|
|
||||||
GtkOrientable *orientable = GTK_ORIENTABLE (ptr->data);
|
|
||||||
|
|
||||||
gtk_orientable_set_orientation (orientable, orientation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
quit_cb (GtkWidget *widget,
|
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
gboolean *done = data;
|
|
||||||
|
|
||||||
*done = TRUE;
|
|
||||||
|
|
||||||
g_main_context_wakeup (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
main (int argc, char **argv)
|
|
||||||
{
|
|
||||||
GtkWidget *window;
|
|
||||||
GtkWidget *vbox;
|
|
||||||
GtkWidget *box, *button;
|
|
||||||
GList *orientables = NULL;
|
|
||||||
gboolean done = FALSE;
|
|
||||||
|
|
||||||
gtk_init ();
|
|
||||||
|
|
||||||
window = gtk_window_new ();
|
|
||||||
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
|
||||||
|
|
||||||
button = gtk_toggle_button_new_with_label ("Horizontal");
|
|
||||||
gtk_box_append (GTK_BOX (vbox), button);
|
|
||||||
|
|
||||||
/* GtkBox */
|
|
||||||
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
|
||||||
orientables = g_list_prepend (orientables, box);
|
|
||||||
gtk_box_append (GTK_BOX (vbox), box);
|
|
||||||
gtk_box_append (GTK_BOX (box),
|
|
||||||
gtk_button_new_with_label ("GtkBox 1"));
|
|
||||||
gtk_box_append (GTK_BOX (box),
|
|
||||||
gtk_button_new_with_label ("GtkBox 2"));
|
|
||||||
gtk_box_append (GTK_BOX (box),
|
|
||||||
gtk_button_new_with_label ("GtkBox 3"));
|
|
||||||
|
|
||||||
g_signal_connect (button, "toggled",
|
|
||||||
G_CALLBACK (orient_toggled), orientables);
|
|
||||||
|
|
||||||
gtk_window_set_child (GTK_WINDOW (window), vbox);
|
|
||||||
gtk_widget_show (window);
|
|
||||||
|
|
||||||
g_signal_connect (window, "destroy",
|
|
||||||
G_CALLBACK (quit_cb), &done);
|
|
||||||
|
|
||||||
while (!done)
|
|
||||||
g_main_context_iteration (NULL, TRUE);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,80 +0,0 @@
|
|||||||
#include <gtk/gtk.h>
|
|
||||||
#include <glib/gstdio.h>
|
|
||||||
|
|
||||||
static void
|
|
||||||
split_decorations (GtkSettings *settings,
|
|
||||||
GParamSpec *pspec,
|
|
||||||
GtkBuilder *builder)
|
|
||||||
{
|
|
||||||
GtkWidget *sheader, *mheader;
|
|
||||||
gchar *layout, *p1, *p2;
|
|
||||||
gchar **p;
|
|
||||||
|
|
||||||
sheader = (GtkWidget *)gtk_builder_get_object (builder, "sidebar-header");
|
|
||||||
mheader = (GtkWidget *)gtk_builder_get_object (builder, "main-header");
|
|
||||||
|
|
||||||
g_object_get (settings, "gtk-decoration-layout", &layout, NULL);
|
|
||||||
|
|
||||||
p = g_strsplit (layout, ":", -1);
|
|
||||||
|
|
||||||
p1 = g_strconcat ("", p[0], ":", NULL);
|
|
||||||
|
|
||||||
if (g_strv_length (p) >= 2)
|
|
||||||
p2 = g_strconcat (":", p[1], NULL);
|
|
||||||
else
|
|
||||||
p2 = g_strdup ("");
|
|
||||||
|
|
||||||
gtk_header_bar_set_decoration_layout (GTK_HEADER_BAR (sheader), p1);
|
|
||||||
gtk_header_bar_set_decoration_layout (GTK_HEADER_BAR (mheader), p2);
|
|
||||||
|
|
||||||
g_free (p1);
|
|
||||||
g_free (p2);
|
|
||||||
g_strfreev (p);
|
|
||||||
g_free (layout);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
main (int argc, char *argv[])
|
|
||||||
{
|
|
||||||
GtkBuilder *builder;
|
|
||||||
GtkSettings *settings;
|
|
||||||
GtkWidget *win;
|
|
||||||
GtkWidget *entry;
|
|
||||||
GtkWidget *check;
|
|
||||||
GtkWidget *header;
|
|
||||||
|
|
||||||
#ifdef GTK_SRCDIR
|
|
||||||
g_chdir (GTK_SRCDIR);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
gtk_init ();
|
|
||||||
|
|
||||||
builder = gtk_builder_new_from_file ("testsplitheaders.ui");
|
|
||||||
|
|
||||||
win = (GtkWidget *)gtk_builder_get_object (builder, "window");
|
|
||||||
settings = gtk_widget_get_settings (win);
|
|
||||||
|
|
||||||
g_signal_connect (settings, "notify::gtk-decoration-layout",
|
|
||||||
G_CALLBACK (split_decorations), builder);
|
|
||||||
split_decorations (settings, NULL, builder);
|
|
||||||
|
|
||||||
entry = (GtkWidget *)gtk_builder_get_object (builder, "layout-entry");
|
|
||||||
g_object_bind_property (settings, "gtk-decoration-layout",
|
|
||||||
entry, "text",
|
|
||||||
G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);
|
|
||||||
check = (GtkWidget *)gtk_builder_get_object (builder, "decorations");
|
|
||||||
header = (GtkWidget *)gtk_builder_get_object (builder, "sidebar-header");
|
|
||||||
g_object_bind_property (check, "active",
|
|
||||||
header, "show-title-buttons",
|
|
||||||
G_BINDING_DEFAULT);
|
|
||||||
header = (GtkWidget *)gtk_builder_get_object (builder, "main-header");
|
|
||||||
g_object_bind_property (check, "active",
|
|
||||||
header, "show-title-buttons",
|
|
||||||
G_BINDING_DEFAULT);
|
|
||||||
gtk_window_present (GTK_WINDOW (win));
|
|
||||||
|
|
||||||
while (TRUE)
|
|
||||||
g_main_context_iteration (NULL, TRUE);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
#include <gtk/gtk.h>
|
|
||||||
#include <glib/gstdio.h>
|
|
||||||
|
|
||||||
static GtkWidget *header_stack;
|
|
||||||
static GtkWidget *page_stack;
|
|
||||||
|
|
||||||
static void
|
|
||||||
back_to_main (GtkButton *button)
|
|
||||||
{
|
|
||||||
gtk_stack_set_visible_child_name (GTK_STACK (header_stack), "main");
|
|
||||||
gtk_stack_set_visible_child_name (GTK_STACK (page_stack), "page1");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
go_to_secondary (GtkButton *button)
|
|
||||||
{
|
|
||||||
gtk_stack_set_visible_child_name (GTK_STACK (header_stack), "secondary");
|
|
||||||
gtk_stack_set_visible_child_name (GTK_STACK (page_stack), "secondary");
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
main (int argc, char *argv[])
|
|
||||||
{
|
|
||||||
GtkBuilder *builder;
|
|
||||||
GtkWidget *win;
|
|
||||||
GtkWidget *new_btn;
|
|
||||||
GtkWidget *back_btn;
|
|
||||||
|
|
||||||
#ifdef GTK_SRCDIR
|
|
||||||
g_chdir (GTK_SRCDIR);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
gtk_init ();
|
|
||||||
|
|
||||||
builder = gtk_builder_new ();
|
|
||||||
gtk_builder_add_from_file (builder, "teststackedheaders.ui", NULL);
|
|
||||||
|
|
||||||
win = (GtkWidget *)gtk_builder_get_object (builder, "window");
|
|
||||||
header_stack = (GtkWidget *)gtk_builder_get_object (builder, "header_stack");
|
|
||||||
page_stack = (GtkWidget *)gtk_builder_get_object (builder, "page_stack");
|
|
||||||
new_btn = (GtkWidget *)gtk_builder_get_object (builder, "new_btn");
|
|
||||||
back_btn = (GtkWidget *)gtk_builder_get_object (builder, "back_btn");
|
|
||||||
|
|
||||||
g_signal_connect (new_btn, "clicked", G_CALLBACK (go_to_secondary), NULL);
|
|
||||||
g_signal_connect (back_btn, "clicked", G_CALLBACK (back_to_main), NULL);
|
|
||||||
|
|
||||||
g_assert (header_stack);
|
|
||||||
|
|
||||||
gtk_window_present (GTK_WINDOW (win));
|
|
||||||
|
|
||||||
while (TRUE)
|
|
||||||
g_main_context_iteration (NULL, TRUE);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user