"Fossies" - the Fresh Open Source Software Archive

Member "gtkdatabox-1.0.0/examples/enable_disable.c" (31 Mar 2021, 5779 Bytes) of package /linux/privat/gtkdatabox-1.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "enable_disable.c": 0.9.3.1_vs_1.0.0.

    1 /* $Id: enable_disable.c 4 2008-06-22 09:19:11Z rbock $ */
    2 /* GtkDatabox - An extension to the gtk+ library
    3  * Copyright (C) 1998 - 2008  Dr. Roland Bock
    4  *
    5  * This program is free software; you can redistribute it and/or
    6  * modify it under the terms of the GNU Lesser General Public License
    7  * as published by the Free Software Foundation; either version 2.1
    8  * of the License, or (at your option) any later version.
    9  * 
   10  * This program is distributed in the hope that it will be useful,
   11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  * GNU Lesser General Public License for more details.
   14  * 
   15  * You should have received a copy of the GNU General Public License
   16  * along with this program; if not, write to the Free Software
   17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   18  */
   19 #include <stdio.h>
   20 
   21 #include <gtk/gtk.h>
   22 #include <gtkdatabox.h>
   23 #include <gtkdatabox_bars.h>
   24 #include <math.h>
   25 
   26 #define POINTS 50
   27 
   28 /*----------------------------------------------------------------
   29  *  databox show_hide
   30  *----------------------------------------------------------------*/
   31 
   32 typedef void (*set_function) (GtkDatabox * box, gboolean enable);
   33 typedef gboolean (*get_function) (GtkDatabox * box);
   34 
   35 typedef struct
   36 {
   37    char *title;
   38    set_function set;
   39    get_function get;
   40    GtkDatabox *box;
   41    GtkEntry *entry;
   42 }
   43 EnableSet;
   44 
   45 EnableSet enableSets[] = {
   46    {"Selection Enabled",
   47     gtk_databox_set_enable_selection,
   48     gtk_databox_get_enable_selection,
   49     NULL,
   50     NULL},
   51    {"Zoom Enabled",
   52     gtk_databox_set_enable_zoom,
   53     gtk_databox_get_enable_zoom,
   54     NULL,
   55     NULL},
   56 };
   57 
   58 gint noEnableSets = sizeof (enableSets) / sizeof (EnableSet);
   59 
   60 static gboolean
   61 update_enable (EnableSet * enableSet)
   62 {
   63    gboolean status = !(enableSet->get (enableSet->box));
   64 
   65    enableSet->set (enableSet->box, status);
   66    gtk_entry_set_text (GTK_ENTRY (enableSet->entry),
   67                (status) ? "TRUE" : "FALSE");
   68 
   69    return FALSE;
   70 }
   71 
   72 static void
   73 create_show_hide (void)
   74 {
   75    GtkWidget *window = NULL;
   76    GtkWidget *box1;
   77    GtkWidget *box2;
   78    GtkWidget *close_button;
   79    GtkWidget *enable_box;
   80    GtkWidget *box;
   81    GtkWidget *table;
   82    GtkWidget *label;
   83    GtkWidget *separator;
   84    GtkDataboxGraph *graph;
   85    gfloat *X;
   86    gfloat *Y;
   87    GdkRGBA color;
   88    gint i;
   89 
   90    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   91    gtk_widget_set_size_request (window, 600, 600);
   92 
   93    g_signal_connect (G_OBJECT (window), "destroy",
   94              G_CALLBACK (gtk_main_quit), NULL);
   95 
   96    gtk_window_set_title (GTK_WINDOW (window),
   97              "GtkDatabox: Enable/Disable Features");
   98    gtk_container_set_border_width (GTK_CONTAINER (window), 0);
   99 
  100    box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
  101    gtk_container_add (GTK_CONTAINER (window), box1);
  102 
  103    label =
  104       gtk_label_new
  105       ("Click on the buttons to enable/disable features.\n\nFor basic understanding: See basics :-)\n\n");
  106    gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
  107    separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
  108    gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, FALSE, 0);
  109 
  110    enable_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
  111    gtk_box_pack_start (GTK_BOX (box1), enable_box, FALSE, FALSE, 0);
  112    separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
  113    gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, FALSE, 0);
  114 
  115    /* Create a GtkDatabox widget along with scrollbars and rulers */
  116    gtk_databox_create_box_with_scrollbars_and_rulers (&box, &table,
  117                               TRUE, TRUE, TRUE, TRUE);
  118 
  119    gtk_box_pack_start (GTK_BOX (box1), table, TRUE, TRUE, 0);
  120 
  121    X = g_new0 (gfloat, POINTS);
  122    Y = g_new0 (gfloat, POINTS);
  123 
  124    for (i = 0; i < POINTS; i++)
  125    {
  126       X[i] = i;
  127       Y[i] = 100. * sin (i * 2 * G_PI / POINTS);
  128    }
  129    color.red = 0;
  130    color.green = 0;
  131    color.blue = 1;
  132    color.alpha = 1;
  133 
  134    graph = gtk_databox_bars_new (POINTS, X, Y, &color, 1);
  135    gtk_databox_graph_add (GTK_DATABOX (box), graph);
  136 
  137    gtk_databox_auto_rescale (GTK_DATABOX (box), 0.05);
  138 
  139    separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
  140    gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
  141 
  142    box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
  143    gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
  144    gtk_box_pack_end (GTK_BOX (box1), box2, FALSE, TRUE, 0);
  145    close_button = gtk_button_new_with_label ("close");
  146    g_signal_connect_swapped (G_OBJECT (close_button), "clicked",
  147                  G_CALLBACK (gtk_main_quit), G_OBJECT (box));
  148    gtk_box_pack_start (GTK_BOX (box2), close_button, TRUE, TRUE, 0);
  149    gtk_widget_set_can_default(close_button, TRUE);
  150    for (i = 0; i < noEnableSets; ++i)
  151    {
  152       GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
  153       GtkWidget *label = gtk_label_new (enableSets[i].title);
  154       GtkWidget *entry = gtk_entry_new ();
  155       GtkWidget *button = gtk_button_new_with_label ("Change");
  156 
  157       gtk_box_pack_start (GTK_BOX (enable_box), vbox, TRUE, TRUE, 0);
  158       gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
  159       gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0);
  160       gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
  161 
  162       gtk_editable_set_editable (GTK_EDITABLE (entry), FALSE);
  163       g_signal_connect_swapped (button, "clicked",
  164                 G_CALLBACK (update_enable),
  165                 (gpointer) & (enableSets[i]));
  166       enableSets[i].box = GTK_DATABOX (box);
  167       enableSets[i].entry = GTK_ENTRY (entry);
  168 
  169       update_enable (&enableSets[i]);
  170       update_enable (&enableSets[i]);
  171 
  172    }
  173 
  174    gtk_widget_grab_default (close_button);
  175    gtk_widget_show_all (window);
  176 
  177 }
  178 
  179 gint
  180 main (gint argc, char *argv[])
  181 {
  182    gtk_init (&argc, &argv);
  183 
  184    create_show_hide ();
  185    gtk_main ();
  186 
  187    return 0;
  188 }