Re: Combobox focus event
- From: tr <tr kyborg dk>
- To: cecashon aol com, gtk-app-devel-list gnome org
- Subject: Re: Combobox focus event
- Date: Fri, 7 Apr 2017 15:13:15 +0200
Hi Eric,
Thanks a lot, looks good. I will try it.
If I want the same feature with other widgets, then I can find the
structs in the sources from GTK ?
Thomas
On 04/06/2017 10:43 PM, cecashon aol com wrote:
Hi Thomas,
You can try getting the private toggle button in the combo box. This
isn't a solution using the given GTK api but if you want to inspect
the how to get the "focus-in-event" to work with a combo box, this
might be helpful. You are working in C right?
Eric
/*
gcc -Wall combo_focus1.c -o combo_focus1 `pkg-config gtk+-3.0
--cflags --libs`
Tested on Ubuntu16.04, GTK3.18.
*/
#include<gtk/gtk.h>
//From gtkcombobox.c
struct _GtkComboBoxPrivate
{
GtkTreeModel *model;
GtkCellArea *area;
gint col_column;
gint row_column;
gint wrap_width;
gint active; /* Only temporary */
GtkTreeRowReference *active_row;
GtkWidget *tree_view;
GtkWidget *cell_view;
GtkWidget *box;
GtkWidget *button;
GtkWidget *arrow;
GtkWidget *popup_widget;
GtkWidget *popup_window;
GtkWidget *scrolled_window;
//GtkCssGadget *gadget;
gulong inserted_id;
gulong deleted_id;
gulong reordered_id;
gulong changed_id;
guint popup_idle_id;
guint activate_button;
guint32 activate_time;
guint scroll_timer;
guint resize_idle_id;
/* For "has-entry" specific behavior we track
* an automated cell renderer and text column
*/
gint text_column;
GtkCellRenderer *text_renderer;
gint id_column;
guint popup_in_progress : 1;
guint popup_shown : 1;
guint add_tearoffs : 1;
guint has_frame : 1;
guint is_cell_renderer : 1;
guint editing_canceled : 1;
guint auto_scroll : 1;
guint button_sensitivity : 2;
guint has_entry : 1;
guint popup_fixed_width : 1;
GtkTreeViewRowSeparatorFunc row_separator_func;
gpointer row_separator_data;
GDestroyNotify row_separator_destroy;
GdkDevice *grab_pointer;
gchar *tearoff_title;
};
static gboolean focus_button(GtkWidget *widget, GdkEvent *event,
gpointer user_data);
static gboolean focus_combo(GtkWidget *widget, GdkEvent *event,
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), "Rooster Icon");
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 *button=gtk_button_new_with_label("Button");
gtk_widget_set_hexpand(button, TRUE);
gtk_widget_set_vexpand(button, TRUE);
g_signal_connect(button, "focus-in-event",
G_CALLBACK(focus_button), 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);
GtkComboBoxPrivate *priv=G_TYPE_INSTANCE_GET_PRIVATE((combo),
GTK_TYPE_COMBO_BOX, GtkComboBoxPrivate);
g_signal_connect(priv->button, "focus-in-event",
G_CALLBACK(focus_combo), NULL);
GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), button, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), combo, 0, 1, 1, 1);
gtk_container_add(GTK_CONTAINER(window), grid);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
static gboolean focus_button(GtkWidget *widget, GdkEvent *event,
gpointer user_data)
{
g_print("Button Focus\n");
return FALSE;
}
static gboolean focus_combo(GtkWidget *widget, GdkEvent *event,
gpointer user_data)
{
g_print("Combo Focus\n");
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]