Re: i want to add different visibility to controls on notebook page



On Mon, 2004-11-01 at 09:58, Vinod Joseph wrote:
Hi David

My controls are outside the notebook widget..

Design as shown in attached text file

But i am not able to correctly disable or unrealize widgets for a
particular page in notebook....

Use the notebook's "switch-page" signal and gtk_widget_set_sensitive()
or g_object_set().

// EXAMPLE

typedef struct _TheButtons {
        GtkWidget* button_next;
        GtkWidget* button back;
} TheButtons;


void create_notebook()
{

TheButtons* buttons = g_malloc0(sizeof(TheButtons));

// create the notebook 
// create the buttons namely back and next in this example

buttons->button_next = back;
buttons->button_back = next;

g_signal_connect(G_OBJECT(notebook), "switch-page",
                        G_CALLBACK(notebook_page_switched),
                        buttons);

g_signal_connect_swapped(G_OBJECT(notebook), "destroy",
                        g_free,
                        buttons);

}

void
notebook_page_switched(GtkNotebook *notebook,
                       GtkNotebookPage *page,
                       guint page_num,
                       gpointer user_data)
{
  TheButtons* buttons;
  buttons = (TheButtons*) user_data;
  gboolean issensitive;

  if( page_num == 0){
    g_object_set(G_OBJECT(buttons->button_back),
      "sensitive", FALSE, NULL);
  }else{
    g_object_get(G_OBJECT(buttons->button_back),
      "sensitive",&issensitive, NULL);
    if( !issensitive ){
      g_object_set(G_OBJECT(buttons->button_back),
        "sensitive", TRUE, NULL);
    }
  }
  if( page_num == 
    (gtk_notebook_get_num_pages(notebook) - 1) ){
    g_object_set(G_OBJECT(buttons->button_next),
      "sensitive", FALSE, NULL);

  }else{
    g_object_get(G_OBJECT(buttons->button_next),
      "sensitive",&issensitive, NULL);
    if( !issensitive ){
      g_object_set(G_OBJECT(buttons->button_next),
        "sensitive", TRUE, NULL);
    }
  }
}


It's quick written from memory so it can contain errors.
-- 
Iago Rubio



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