Re: resizing notebook to match current page



I was playing around with the GtkNotebook
and I noticed that the size of the notebook matches
the size of the biggest page widget...
I would like the notebook to adapt its size to the size
of the current page, not the biggest page,
because that distorts my smaller pages...
What's an easy way to do that?
I tried hiding page widgets, but then the label dissapears too.

I have done this some time ago, and others (LaborFaroise)
in this list, as well. This is how you do it:

Basically you create all the pages at once and then
hide and show its contents using the switch callback, so
at a given moment only one page has its contents shown. 
This way, the automatic resize policy will show the notebook
with the size of the current page size. The major tricks 
of the trade are:

-the switch signal is quite tricky,
-the automatic resize policy, 
-you don't hide the pages but its contents,
 (so the page label is always visible)

see below (and let me know if you need
to clarify something else),

Carlos

-----------------main code-------------------
gtk_window_set_policy (GTK_WINDOW (dialog), FALSE, FALSE, TRUE);

notebook = gtk_notebook_new ();
gtk_container_add (GTK_CONTAINER (dialog), notebook);
gtk_widget_show (notebook);

static_create (window);
frame0 = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (dialog), "frame0");
gtk_widget_show(frame0);
gtk_notebook_set_page (GTK_NOTEBOOK (notebook), 0);

gtk_signal_connect_while_alive (GTK_OBJECT (notebook), "switch_page",
GTK_SIGNAL_FUNC (static_switch), window, GTK_OBJECT (dialog));
--------------------------------------

-----------------------switch callback-------------
static void static_switch (GtkNotebook *notebook, GtkNotebookPage *page, guint tag, gpointer data)
{
app_window *window = APP_CAST_WINDOW data;
GtkWidget *frame0, *frame1, *frame2, *dialog = window->dialog0;
GtkWidget* vbox = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), tag);
GtkWidget *entry;

frame2 = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (dialog), "frame2");
frame1 = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (dialog), "frame1");
frame0 = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (dialog), "frame0");

gtk_widget_hide (frame2);
gtk_widget_hide (frame1);
gtk_widget_hide (frame0);

entry = gtk_object_get_data (GTK_OBJECT (vbox), "value");
gtk_entry_set_text (GTK_ENTRY (entry), "");

switch (tag)
  {
  case 2:
  entry = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (vbox), "name4");
  gtk_entry_set_text (GTK_ENTRY (entry), "");

  case 1:
  entry = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (vbox), "name3");
  gtk_entry_set_text (GTK_ENTRY (entry), "");

  case 0:
  entry = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (vbox), "name2");
  gtk_entry_set_text (GTK_ENTRY (entry), "");
  entry = (GtkWidget *) gtk_object_get_data (GTK_OBJECT (vbox), "name1");
  gtk_entry_set_text (GTK_ENTRY (entry), "");
  break;
  }

switch (tag)
  {
  case 2:
  gtk_widget_show (frame2);
  break;

  case 1:
  gtk_widget_show (frame1);
  break;

  case 0:
  gtk_widget_show (frame0);
  break;
  }
}
----------------------static_create---------

Here you create all the notebook pages, this function
runs only once. After that, you just hide and show
pages, and the automatic resize policy will change
the notebook size. Note that you don't hide vbox0
but frame0, so the tag label is always visible.

/* length page */
vbox0 = gtk_vbox_new (FALSE, 0);
gtk_widget_show (vbox0);

label = gtk_label_new ("Length");
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox0, label);

frame = gtk_frame_new ("Do Something");
gtk_object_set_data (GTK_OBJECT (dialog), "frame0", frame);
gtk_box_pack_start (GTK_BOX (vbox0), frame, TRUE, TRUE, 0);

etc... etc...




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