Re: Combobox focus event
- From: Thomas Rønshof <tr kyborg dk>
- To: cecashon aol com, ntd entidi it, gtk-app-devel-list gnome org
- Subject: Re: Combobox focus event
- Date: Sat, 8 Apr 2017 07:47:51 +0200
Thanks :-))
I'l try that.
Thomas
On 07-04-2017 23:10, cecashon aol com wrote:
Hi Nicola,
The "set-focus-child" on the container fires for the "focus-in-event"
and "focus-out-event". I forgot about those container functions
though. You can get the toggle button pointer from the container and
set up your "focus-in-event". That way there is no ugly business of
using a private structure.
Eric
/*
gcc -Wall combo_focus2.c -o combo_focus2 `pkg-config gtk+-3.0
--cflags --libs`
Tested on Ubuntu16.04, GTK3.18.
https://bugzilla.gnome.org/show_bug.cgi?id=599076
Bugzilla Bug 599076 - GtkComboBox missing focus events
*/
#include<gtk/gtk.h>
static void find_toggle_button(GtkWidget *widget, GtkWidget
**toggle_button);
static gboolean focus_button1(GtkWidget *widget, GdkEvent *event,
gpointer user_data);
static gboolean focus_combo(GtkWidget *widget, GdkEvent *event,
gpointer user_data);
static gboolean focus_button2(GtkWidget *widget, GdkEvent *event,
gpointer user_data);
static void focus_combo_container(GtkContainer *container, GtkWidget
*widget, gpointer user_data);
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), "Combo Focus");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
gtk_window_set_default_size(GTK_WINDOW(window), 200, 100);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
GtkWidget *button1=gtk_button_new_with_label("Button1");
gtk_widget_set_hexpand(button1, TRUE);
gtk_widget_set_vexpand(button1, TRUE);
g_signal_connect(button1, "focus-in-event",
G_CALLBACK(focus_button1), NULL);
GtkWidget *combo=gtk_combo_box_text_new();
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo), 0, "1",
"Turtle");
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo), 1, "2", "Koala");
gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo), 2, "3",
"Cheetah");
gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
gtk_widget_set_hexpand(combo, TRUE);
GtkWidget *toggle_button=NULL;
gtk_container_forall(GTK_CONTAINER(combo),
(GtkCallback)find_toggle_button, &toggle_button);
g_signal_connect(toggle_button, "focus-in-event",
G_CALLBACK(focus_combo), NULL);
g_signal_connect(combo, "set-focus-child",
G_CALLBACK(focus_combo_container), NULL);
GtkWidget *button2=gtk_button_new_with_label("Button2");
gtk_widget_set_hexpand(button2, TRUE);
gtk_widget_set_vexpand(button2, TRUE);
g_signal_connect(button2, "focus-in-event",
G_CALLBACK(focus_button2), NULL);
GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), button1, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), combo, 0, 1, 1, 1);
gtk_grid_attach(GTK_GRID(grid), button2, 0, 2, 1, 1);
gtk_container_add(GTK_CONTAINER(window), grid);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
static void find_toggle_button(GtkWidget *widget, GtkWidget
**toggle_button)
{
if(g_strcmp0(gtk_widget_get_name(widget), "GtkToggleButton")==0)
{
g_print("Found Toggle Button in Combo\n");
*toggle_button=widget;
}
}
static gboolean focus_button1(GtkWidget *widget, GdkEvent *event,
gpointer user_data)
{
g_print("Button1 Focus\n");
return FALSE;
}
static gboolean focus_combo(GtkWidget *widget, GdkEvent *event,
gpointer user_data)
{
g_print("Combo Focus In\n");
return FALSE;
}
static gboolean focus_button2(GtkWidget *widget, GdkEvent *event,
gpointer user_data)
{
g_print("Button2 Focus\n");
return FALSE;
}
static void focus_combo_container(GtkContainer *container, GtkWidget
*widget, gpointer user_data)
{
g_print("Combo Container Focus\n");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]