Re: Font selection panel




Hi Igor,

You can try setting the focus and then catching the "focus-out-event" to change the sensitivity of the apply button.

Maybe that function isn't deprecated in GTK2 but I don't really know.

Eric


//gcc -Wall focus1.c -o focus1 `pkg-config --cflags --libs gtk+-2.0`

#include <gtk/gtk.h>

static gboolean focus_out(GtkWidget *widget, GdkEvent *event, gpointer user_data)
  {
    g_print("Focus Out\n");
    gtk_widget_set_sensitive(GTK_WIDGET(user_data), TRUE);
    return FALSE;
  }
static void button1_clicked(GtkWidget *widget, gpointer user_data)
  {
    g_print("Button1 Clicked\n");
  }
static void button2_clicked(GtkWidget *widget, gpointer user_data)
  {
    g_print("Button2 Clicked\n");
  }
int main (int argc, char *argv[])
  {
    gtk_init(&argc, &argv);

    GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "File Selection");
    gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_container_set_border_width(GTK_CONTAINER(window), 20);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    GtkWidget *font=gtk_font_selection_new();

    GtkWidget *button1=gtk_button_new_with_label("Apply");
    gtk_widget_set_sensitive(button1, FALSE);
    g_signal_connect(button1, "clicked", G_CALLBACK(button1_clicked), NULL);

    GtkWidget *button2=gtk_button_new_with_label("OK");
    g_signal_connect(button2, "clicked", G_CALLBACK(button2_clicked), NULL);
    g_signal_connect(button2, "focus-out-event", G_CALLBACK(focus_out), button1);

    GtkWidget *table1=gtk_table_new(2, 2, FALSE);
    gtk_table_attach(GTK_TABLE(table1), font, 0, 2, 0, 1, GTK_EXPAND, GTK_EXPAND, 0, 0);
    gtk_table_attach(GTK_TABLE(table1), button1, 0, 1, 1, 2, GTK_EXPAND, GTK_SHRINK, 0, 0);
    gtk_table_attach(GTK_TABLE(table1), button2, 1, 2, 1, 2, GTK_EXPAND, GTK_SHRINK, 0, 0);

    gtk_container_add(GTK_CONTAINER(window), table1);

    gtk_widget_show_all(window);

    gtk_widget_set_can_focus(button2, TRUE);
    gtk_widget_grab_focus(button2);
   
    gtk_main();

    return 0;
  }





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