[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gEDA-dev: Re: Tabbed pages in gschem (and implications)



Peter Clifton wrote:
> Call for ideas / comments:......................
> 
> 
> A neat feature which was suggested to me was to implement "tabbed"
> viewing of pages - possibly to replace the page manager in gschem.
> 
> Simple, I thought,... until I dig a little more into the GtkNotebook
> widget which implements tabbed windows.
> 
> Each tab has to have its own contents... (In the case of gschem, this
> would be a GtkTable for packing, two scrollbars and the drawing area).
>
I think there is another way. Use an empty child for each notebook tab, 
so the notebook is only as tall as the tabs. Stack the drawing area
widgets under it with a GtkVBox.

GtkVBox
   |->GtkNotebook (empty pages - only the tabs are shown)
   |->GtkTable (drawing area below - the same for all pages)

Then, catch the relevant signal to update the drawing area when a new
notebook tab is selected.

Sample code is attached. Compile with
gcc -o tabbed tabbed.c `pkg-config --cflags --libs gtk+-2.0`

Regards

Cesar


#include <gtk/gtk.h>

int
main (int argc, char *argv[])
{
  GtkWidget *window1;
  gtk_set_locale ();
  gtk_init (&argc, &argv);


  GtkWidget *vbox1;
  GtkWidget *notebook1;
  GtkWidget *empty_notebook_page;
  GtkWidget *label1;
  GtkWidget *label2;
  GtkWidget *label3;
  GtkWidget *table1;
  GtkWidget *drawingarea1;
  GtkWidget *vscrollbar1;
  GtkWidget *hscrollbar1;

  window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window1), "window1");

  vbox1 = gtk_vbox_new (FALSE, 0);
  gtk_widget_show (vbox1);
  gtk_container_add (GTK_CONTAINER (window1), vbox1);

  notebook1 = gtk_notebook_new ();
  gtk_widget_show (notebook1);
  gtk_box_pack_start (GTK_BOX (vbox1), notebook1, FALSE, TRUE, 0);

  empty_notebook_page = gtk_vbox_new (FALSE, 0);
  gtk_widget_show (empty_notebook_page);
  gtk_container_add (GTK_CONTAINER (notebook1), empty_notebook_page);

  label1 = gtk_label_new ("label1");
  gtk_widget_show (label1);
  gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook1), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 0), label1);

  empty_notebook_page = gtk_vbox_new (FALSE, 0);
  gtk_widget_show (empty_notebook_page);
  gtk_container_add (GTK_CONTAINER (notebook1), empty_notebook_page);

  label2 = gtk_label_new ("label2");
  gtk_widget_show (label2);
  gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook1), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 1), label2);

  empty_notebook_page = gtk_vbox_new (FALSE, 0);
  gtk_widget_show (empty_notebook_page);
  gtk_container_add (GTK_CONTAINER (notebook1), empty_notebook_page);

  label3 = gtk_label_new ("label3");
  gtk_widget_show (label3);
  gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook1), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 2), label3);

  table1 = gtk_table_new (2, 2, FALSE);
  gtk_widget_show (table1);
  gtk_box_pack_start (GTK_BOX (vbox1), table1, TRUE, TRUE, 0);

  drawingarea1 = gtk_drawing_area_new ();
  gtk_widget_show (drawingarea1);
  gtk_table_attach (GTK_TABLE (table1), drawingarea1, 0, 1, 0, 1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);

  vscrollbar1 = gtk_vscrollbar_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 0, 0, 0, 0)));
  gtk_widget_show (vscrollbar1);
  gtk_table_attach (GTK_TABLE (table1), vscrollbar1, 1, 2, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (GTK_FILL), 0, 0);

  hscrollbar1 = gtk_hscrollbar_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 0, 0, 0, 0)));
  gtk_widget_show (hscrollbar1);
  gtk_table_attach (GTK_TABLE (table1), hscrollbar1, 0, 1, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (GTK_FILL), 0, 0);


  gtk_widget_show (window1);
  g_signal_connect ((gpointer) window1, "destroy", G_CALLBACK(gtk_main_quit),
                    NULL);

  gtk_main ();
  return 0;    
}



_______________________________________________
geda-dev mailing list
geda-dev@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-dev