2008-07-01 22:57:50 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
2004-07-22 05:06:39 +00:00
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.Free
|
2004-07-22 05:06:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
|
|
|
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
|
|
* files for a list of changes. These files are distributed with
|
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2022-10-08 00:59:10 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
2004-07-22 05:06:39 +00:00
|
|
|
static void
|
|
|
|
combo_changed_cb (GtkWidget *combo,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *label = GTK_WIDGET (data);
|
2020-07-24 13:54:49 +00:00
|
|
|
int active;
|
2004-07-22 05:06:39 +00:00
|
|
|
|
|
|
|
active = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
|
|
|
|
gtk_label_set_ellipsize (GTK_LABEL (label), (PangoEllipsizeMode)active);
|
2009-12-02 08:48:42 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 21:37:41 +00:00
|
|
|
static void
|
|
|
|
overlay_draw (GtkDrawingArea *da,
|
|
|
|
cairo_t *cr,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
gpointer data)
|
2009-12-02 08:48:42 +00:00
|
|
|
{
|
2016-11-18 21:37:41 +00:00
|
|
|
GtkWidget *widget = GTK_WIDGET (da);
|
2009-12-02 08:48:42 +00:00
|
|
|
PangoLayout *layout;
|
|
|
|
const double dashes[] = { 6, 18 };
|
2010-09-08 20:17:48 +00:00
|
|
|
GtkAllocation label_allocation;
|
2010-04-18 02:50:12 +00:00
|
|
|
GtkRequisition minimum_size, natural_size;
|
2009-12-02 08:48:42 +00:00
|
|
|
GtkWidget *label = data;
|
2020-05-17 21:08:01 +00:00
|
|
|
double x, y;
|
2009-12-02 08:48:42 +00:00
|
|
|
|
|
|
|
cairo_translate (cr, -0.5, -0.5);
|
|
|
|
cairo_set_line_width (cr, 1);
|
|
|
|
|
2010-04-11 02:03:20 +00:00
|
|
|
cairo_set_source_rgb (cr, 1, 1, 1);
|
2016-11-18 21:37:41 +00:00
|
|
|
cairo_rectangle (cr, 0, 0, width, height);
|
|
|
|
cairo_fill (cr);
|
2010-04-11 02:03:20 +00:00
|
|
|
|
|
|
|
gtk_widget_translate_coordinates (label, widget, 0, 0, &x, &y);
|
|
|
|
layout = gtk_widget_create_pango_layout (widget, "");
|
|
|
|
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_size (label, &minimum_size, &natural_size);
|
2010-04-18 02:50:12 +00:00
|
|
|
|
2010-04-11 02:03:20 +00:00
|
|
|
pango_layout_set_markup (layout,
|
|
|
|
"<span color='#c33'>\342\227\217 requisition</span>\n"
|
|
|
|
"<span color='#3c3'>\342\227\217 natural size</span>\n"
|
|
|
|
"<span color='#33c'>\342\227\217 allocation</span>", -1);
|
|
|
|
|
|
|
|
pango_cairo_show_layout (cr, layout);
|
|
|
|
g_object_unref (layout);
|
|
|
|
|
2010-08-15 22:34:34 +00:00
|
|
|
gtk_widget_get_allocation (label, &label_allocation);
|
|
|
|
|
2009-12-02 08:48:42 +00:00
|
|
|
cairo_rectangle (cr,
|
2010-08-15 22:34:34 +00:00
|
|
|
x + 0.5 * (label_allocation.width - minimum_size.width),
|
|
|
|
y + 0.5 * (label_allocation.height - minimum_size.height),
|
2010-04-18 02:50:12 +00:00
|
|
|
minimum_size.width, minimum_size.height);
|
2009-12-02 08:48:42 +00:00
|
|
|
cairo_set_source_rgb (cr, 0.8, 0.2, 0.2);
|
|
|
|
cairo_set_dash (cr, NULL, 0, 0);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
|
2010-08-15 22:34:34 +00:00
|
|
|
cairo_rectangle (cr, x, y, label_allocation.width, label_allocation.height);
|
2009-12-02 08:48:42 +00:00
|
|
|
cairo_set_source_rgb (cr, 0.2, 0.2, 0.8);
|
|
|
|
cairo_set_dash (cr, dashes, 2, 0.5);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
|
|
|
|
cairo_rectangle (cr,
|
2010-08-15 22:34:34 +00:00
|
|
|
x + 0.5 * (label_allocation.width - natural_size.width),
|
|
|
|
y + 0.5 * (label_allocation.height - natural_size.height),
|
2009-12-02 08:48:42 +00:00
|
|
|
natural_size.width, natural_size.height);
|
|
|
|
cairo_set_source_rgb (cr, 0.2, 0.8, 0.2);
|
|
|
|
cairo_set_dash (cr, dashes, 2, 12.5);
|
|
|
|
cairo_stroke (cr);
|
2004-07-22 05:06:39 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
static void
|
|
|
|
quit_cb (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean *done = data;
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
|
|
|
}
|
|
|
|
|
2004-07-22 05:06:39 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2009-12-02 08:48:42 +00:00
|
|
|
GtkWidget *window, *vbox, *label;
|
2016-11-18 21:37:41 +00:00
|
|
|
GtkWidget *combo, *scale, *overlay, *da;
|
2020-02-10 03:24:47 +00:00
|
|
|
gboolean done = FALSE;
|
2004-07-22 05:06:39 +00:00
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2004-07-22 05:06:39 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2009-12-02 08:48:42 +00:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
|
2020-02-10 03:24:47 +00:00
|
|
|
g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
|
2009-12-02 08:48:42 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), vbox);
|
2009-12-02 08:48:42 +00:00
|
|
|
|
2010-10-02 16:19:46 +00:00
|
|
|
combo = gtk_combo_box_text_new ();
|
2010-10-30 00:01:27 +00:00
|
|
|
scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
|
|
|
|
0, 360, 1);
|
2009-12-02 08:48:42 +00:00
|
|
|
label = gtk_label_new ("This label may be ellipsized\nto make it fit.");
|
|
|
|
|
2010-10-02 16:19:46 +00:00
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "NONE");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "START");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "MIDDLE");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "END");
|
2004-07-22 05:06:39 +00:00
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
|
2009-12-02 08:48:42 +00:00
|
|
|
|
2014-05-24 00:42:47 +00:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
|
2009-12-02 08:48:42 +00:00
|
|
|
|
2016-11-18 21:37:41 +00:00
|
|
|
da = gtk_drawing_area_new ();
|
|
|
|
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (da), overlay_draw, label, NULL);
|
|
|
|
|
|
|
|
overlay = gtk_overlay_new ();
|
2020-05-03 14:32:24 +00:00
|
|
|
gtk_overlay_set_child (GTK_OVERLAY (overlay), da);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_vexpand (overlay, TRUE);
|
2016-11-18 21:37:41 +00:00
|
|
|
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), label);
|
2009-12-02 08:48:42 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), combo);
|
|
|
|
gtk_box_append (GTK_BOX (vbox), scale);
|
|
|
|
gtk_box_append (GTK_BOX (vbox), overlay);
|
2009-12-02 08:48:42 +00:00
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (label), "combo", combo);
|
|
|
|
|
2004-07-22 05:06:39 +00:00
|
|
|
g_signal_connect (combo, "changed", G_CALLBACK (combo_changed_cb), label);
|
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2004-07-22 05:06:39 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2004-07-22 05:06:39 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|