/* extendedlayoutexample.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, see . */ #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 */ static TestInterface interfaces[] = { { "Ellipsizing Labels", "Demonstrates how labels will request a natural size in a horizontal space", "" " " " " " " " 450" " 50" " " " " " horizontal" " 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", "" " " " " " " " 300" " " " " " horizontal" " True" " True" " " " " " vertical" " True" " " " " " True" " A short static label." " " " " " " " " " " " 0" " " " " " " " " " Long label" " True" " " " " " 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" " " " " " " " " " " " " " " " 1" " " " " " " " " " True" " True" " True" " " " " " True" " A really really long label inside a button to demonstrate height for width working inside buttons" " True" " 25" " " " " " " " " " " " " " " " 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" " " " " " horizontal" " True" " True" " " " " " vertical" " True" " " " " " horizontal" " True" " " " " " True" " True" " True" " " " " " True" " A button that wraps." " True" " 10" " " " " " " " " " " " " " " " 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" " " " " " " " " " 0" " " " " " " " " " A button that expands in the vbox" " True" " True" " True" " " " " " 1" " " " " " " " " " False" " False" " " " " " " " " " True" " This label is\n" "set to shrink inside\n" "the paned window." " center" " " " " " " " " " " " " " True" " True" " " " " " " " " " " "", 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" " " " " " horizontal" " True" " True" " " " " " vertical" " True" " " " " " horizontal" " True" " 6" " " " " " True" " The first 2 labels require 10 characters." " True" " 10" " " " " " " " " " " " " " 0" " " " " " " " " " True" " This label has a maximum natural width of 20 characters. The second two labels expand." " True" " 10" " 20" " " " " " " " " " " " " " 1" " " " " " " " " " True" " This label 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 }, { "Wrapping Expander", "This test demonstrates how the expander label can fill to its natural width " "and also trade height for width.", "" "" " " " " " " " 500" " " " " " horizontal" " True" " True" " " " " " True" " True" " " " " " True" " More wrapping text to fill the largish content area in the expander " " True" " 10" " " " " " " " " " " " " " " " " " True" " Here is some expander text that wraps" " True" " 10" " " " " " " " " " " " " " " " " " False" " False" " " " " " " " " " True" " static\n" "text\n" "here" " " " " " " " " " " " True" " True" " " " " " " " " " " "", NULL }, { "Wrapping Frame Label", "This test demonstrates how the frame label can fill to its natural width " "and also trade height for width.", "" "" " " " " " " " 400" " 150" " " " " " True" " 0" " " " " " True" " 12" " some content" " " " " " " " " " True" " A frame label that's a little long and wraps" " True" " True" " " " " " " " " " " "", NULL }, { "Combo Boxes and Menus", "This test shows wrapping and ellipsizing text in combo boxes (and consequently in menu items).", "" "" " " " " " " " 600" " " " " " horizontal" " True" " True" " " " " " vertical" " True" " 5" " " " " " horizontal" " True" " 5" " " " " " True" " this combo box" " " " " " " " " " " " " " 0" " " " " " " " " " True" " contains some wrapping locations" " end" " 10" " " " " " " " " " " " " " 1" " " " " " " " " " True" " liststore1" " 0" " " " " " " " 1" " " " " " " " " " purple" " 600" " word" " 100" " " " " " 0" " " " " " " " " " 2" " " " " " " " " " 0" " " " " " " " " " True" " 0" " " " " " True" " This test shows combo boxes\n" "requesting and allocating space\n" "for its backing content using\n" "height-for-width geometry\n" "management.\n" "\n" "Note this test also demonstrates\n" "height-for-width menu items." " center" " " " " " " " " " " " " " " " " " 1" " " " " " " " " " horizontal" " True" " 5" " " " " " True" " this combo box" " " " " " " " " " " " " " 0" " " " " " " " " " True" " contains some ellipsizing locations" " end" " 10" " " " " " " " " " " " " " 1" " " " " " " " " " True" " liststore1" " 0" " " " " " " " 1" " " " " " " " " " end" " orange" " 600" " 10" " " " " " 0" " " " " " " " " " 2" " " " " " " " " " 2" " " " " " " " " " True" " False" " " " " " " " " " True" " Some static\n" "text here\n" "that shrinks." " center" " " " " " " " " " " " False" " True" " " " " " " " " " " " " " " " " " " " " " " " " " " " " " Montreal, Quebec Canada" " edit-undo" " " " " " Sao Paulo, SP Brazil" " edit-redo" " " " " " Buenos Aires, Argentina" " process-stop" " " " " " Los Angelos, California USA" " media-record" " " " " " Rio de Janeiro, RJ Brazil" " dialog-error" " " " " " Seoul, South Korea" " dialog-information" " " " " " " "", NULL }, }; static void test_clicked (GtkWidget *button, TestInterface *interface) { if (!interface->window) { GtkBuilder *builder = gtk_builder_new (); GError *error = NULL; gtk_builder_add_from_string (builder, interface->interface, -1, &error); if (error) { g_printerr ("GtkBuilder for interface \"%s\" returned error \"%s\"\n", interface->name, error->message); g_error_free (error); g_object_unref (builder); return; } interface->window = (GtkWidget *)gtk_builder_get_object (builder, "window"); gtk_window_set_hide_on_close (GTK_WINDOW (interface->window), TRUE); g_object_unref (builder); } gtk_widget_show (interface->window); } static GtkWidget * create_window (void) { GtkWidget *window, *vbox, *button; gint i; window = gtk_window_new (); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_widget_set_margin_start (vbox, 8); gtk_widget_set_margin_end (vbox, 8); gtk_widget_set_margin_top (vbox, 8); gtk_widget_set_margin_bottom (vbox, 8); 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 (button, "clicked", G_CALLBACK (test_clicked), &interfaces[i]); gtk_container_add (GTK_CONTAINER (vbox), button); } return window; } 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; gboolean done = FALSE; gtk_init (); window = create_window (); g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done); gtk_widget_show (window); while (!done) g_main_context_iteration (NULL, TRUE); return 0; }