/* testextendedlayout2.c * Copyright (C) 2010 Openismus GmbH * * Author: * Tristan Van Berkom * * 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, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #include typedef struct { const gchar *name; const gchar *tooltip; const gchar *interface; GtkWidget *window; } TestInterface; /* These strings were generated with: * * IFS=""; while read line; do echo -n \"; echo -n $line | sed -e 's|\"|\\"|g'; echo \"; done < file.glade */ TestInterface interfaces[] = { { "Ellipsizing Labels", "Demonstrates how labels will request a natural size in a horizontal space", "" " " " " " " " 450" " 50" " " " " " True" " " " " " True" " Some labels do ellipsize" " end" " " " " " " " " " " " " " 0" " " " " " " " " " True" " but some" " end" " " " " " " " " " " " " " 1" " " " " " " " " " True" " do not at all" " " " " " " " " " " " " " " " 2" " " " " " " " " " " "", NULL }, { "Wrapping Label", "Demonstrates how a wrapping label can require a height contextual to its allocated width", "" " " " " " " " 12" " 300" " " " " " True" " True" " " " " " True" " " " " " True" " A short static label." " " " " " " " " " " " 0" " " " " " " " " " True" " This is a really long label for the purpose of testing line wrapping is working correctly in conjunction with height-for-width support in GTK+" " True" " 30" " " " " " " " " " " " False" " 1" " " " " " " " " " True" " True" " True" " " " " " True" " A really really long label inside a button to demonstrate height for width working inside buttons" " True" " 25" " " " " " " " " " " " " " " " False" " 2" " " " " " " " " " False" " False" " " " " " " " " " True" " This static label\n" "can shrink." " center" " " " " " " " " " " " " " True" " True" " " " " " " " " " " "", NULL }, { "Horizontal Box", "Demonstrates how a horizontal box can calculate the collective height for an allocated width", "" " " " " " " " 200" " 600" " " " " " True" " True" " " " " " True" " " " " " True" " " " " " True" " True" " True" " False" " " " " " True" " A button that wraps." " True" " 10" " " " " " " " " " " " " " " " False" " 0" " " " " " " " " " True" " Lets try setting up some long text to wrap up in this hbox and see if the height-for-width is gonna work !" " True" " 30" " " " " " " " " " " " 1" " " " " " " " " " False" " 0" " " " " " " " " " A button that expands in the vbox" " True" " True" " True" " False" " " " " " 1" " " " " " " " " " False" " False" " " " " " " " " " True" " This label is\n" "set to shrink inside\n" "the paned window." " center" " " " " " " " " " " " " " True" " True" " " " " " " " " " " "", NULL }, { "Vertical Labels", "Demonstrates how a horizontal box will consider width-for-height when allocating children " "even if the toplevel window is requested as height-for-width.", "" " " " " " " " 400" " 300" " " " " " True" " True" " " " " " True" " " " " " True" " Some long width-for-height text that wraps" " center" " True" " 10" " 90" " " " " " " " " " " " " " False" " 0" " " " " " " " " " True" " 0" " out" " " " " " True" " Neither of the panes are\n" "set to shrink." " center" " " " " " " " " " " " " " " " " " " " " " 1" " " " " " " " " " False" " False" " " " " " " " " " True" " " " " " True" " 0" " out" " " " " " True" " The interface is allocated as height\n" "for width, but the horizontal boxes\n" "allocate in width for height mode." " " " " " " " " " " " " " " " " " " " " " 0" " " " " " " " " " True" " Some long width-for-height text that wraps" " center" " True" " 10" " 270" " " " " " " " " " " " " " False" " 1" " " " " " " " " " False" " False" " " " " " " " " " " "", NULL }, { "Label Parameters", "This test demonstrates how \"width-chars\" and \"max-width-chars\" can be used " "to effect minimum and natural widths in wrapping labels.", "" " " " " " " " 900" " " " " " True" " True" " " " " " True" " " " " " True" " 6" " " " " " True" " These first 2 labels explicitly require only 10 charachters in width." " True" " 10" " " " " " " " " " " " " " False" " False" " 0" " " " " " " " " " True" " This label has a maximum natural width of 20 charachters. Otherwise it would unwrap much further." " True" " 10" " 20" " " " " " " " " " " " " " False" " False" " 1" " " " " " " " " " True" " This label is set to expand and requires a default minimum size." " True" " " " " " " " " " " " " " 2" " " " " " " " " " 0" " " " " " " " " " True" " This test demonstrates how the \"width-chars\" and \"max-width-chars\"\n" "properties can be used to specify the minimum requested wrap width\n" "and the maximum natural wrap width respectively." " end" " 30" " " " " " " " " " " " " " 1" " " " " " " " " " False" " False" " " " " " " " " " True" " Some static\n" "text that shrinks.\n" "\n" "You will need to stretch\n" "this window quite wide\n" "to see the effects." " center" " " " " " " " " " " " True" " True" " " " " " " " " " " "", NULL }, }; static void test_clicked (GtkWidget *button, TestInterface *interface) { if (!interface->window) { GtkBuilder *builder = gtk_builder_new (); gtk_builder_add_from_string (builder, interface->interface, -1, NULL); interface->window = (GtkWidget *)gtk_builder_get_object (builder, "window"); g_signal_connect (interface->window, "delete_event", G_CALLBACK (gtk_widget_hide_on_delete), NULL); } gtk_widget_show (interface->window); } static GtkWidget * create_window (void) { GtkWidget *window, *vbox, *button; gint i; window = gtk_window_new (GTK_WINDOW_TOPLEVEL); vbox = gtk_vbox_new (FALSE, 6); gtk_container_set_border_width (GTK_CONTAINER (window), 8); gtk_widget_show (vbox); gtk_container_add (GTK_CONTAINER (window), vbox); for (i = 0; i < G_N_ELEMENTS (interfaces); i++) { button = gtk_button_new_with_label (interfaces[i].name); gtk_widget_set_tooltip_text (button, interfaces[i].tooltip); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (test_clicked), &interfaces[i]); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); gtk_widget_show (button); } return window; } int main (int argc, char *argv[]) { GtkWidget *window; gtk_init (&argc, &argv); window = create_window (); g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), window); gtk_widget_show (window); gtk_main (); return 0; }