1 /*
2 * A subclass of GtkAction that wraps a GtkComboBoxEntry.
3 * Features:
4 * Setting GtkEntryBox width in characters.
5 * Passing a function for formatting cells.
6 * Displaying a warning if text isn't in list.
7 * Setting names for GtkComboBoxEntry and GtkEntry (actionName_combobox, actionName_entry)
8 * to allow setting resources.
9 *
10 * Author(s):
11 * Tavmjong Bah
12 * Jon A. Cruz <jon@joncruz.org>
13 *
14 * Copyright (C) 2010 Authors
15 *
16 * Released under GNU GPL, read the file 'COPYING' for more information
17 */
19 #ifndef SEEN_INK_COMBOBOXENTRY_ACTION
20 #define SEEN_INK_COMBOBOXENTRY_ACTION
22 #include <glib.h>
23 #include <glib-object.h>
25 #include <gtk/gtkaction.h>
26 #include <gtk/gtktreemodel.h>
29 #define INK_COMBOBOXENTRY_TYPE_ACTION (ink_comboboxentry_action_get_type())
30 #define INK_COMBOBOXENTRY_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INK_COMBOBOXENTRY_TYPE_ACTION, Ink_ComboBoxEntry_Action))
31 #define INK_COMBOBOXENTRY_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INK_COMBOBOXENTRY_TYPE_ACTION, Ink_ComboBoxEntry_ActionClass))
32 #define INK_COMBOBOXENTRY_IS_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INK_COMBOBOXENTRY_TYPE_ACTION))
33 #define INK_COMBOBOXENTRY_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INK_COMBOBOXENTRY_TYPE_ACTION, Ink_ComboBoxEntry_ActionClass))
35 typedef struct _Ink_ComboBoxEntry_ActionClass Ink_ComboBoxEntry_ActionClass;
36 typedef struct _Ink_ComboBoxEntry_Action Ink_ComboBoxEntry_Action;
38 struct _Ink_ComboBoxEntry_ActionClass {
39 GtkActionClass parent_class;
41 void (*changed) (Ink_ComboBoxEntry_Action* action);
42 void (*activated) (Ink_ComboBoxEntry_Action* action);
43 };
45 struct _Ink_ComboBoxEntry_Action {
46 GtkAction parent_instance;
48 GtkTreeModel *model;
49 GtkComboBoxEntry *combobox;
50 GtkEntry *entry;
51 GtkEntryCompletion *entry_completion;
52 #if !GTK_CHECK_VERSION(2,16,0)
53 GtkWidget *indicator;
54 #endif
56 gpointer cell_data_func; // drop-down menu format
58 gint active; // Index of active menu item (-1 if not in list).
59 gchar *text; // Text of active menu item or entry box.
60 gint entry_width;// Width of GtkEntry in characters.
61 gint extra_width;// Extra Width of GtkComboBox.. to widen drop-down list in list mode.
62 gboolean popup; // Do we pop-up an entry-completion dialog?
63 gchar *warning; // Text for warning that entry isn't in list.
64 gchar *altx_name; // Target for Alt-X keyboard shortcut.
65 };
68 GType ink_comboboxentry_action_get_type (void);
70 /**
71 * Creates a GtkAction subclass that wraps a GtkComboBoxEntry object.
72 */
73 Ink_ComboBoxEntry_Action *ink_comboboxentry_action_new ( const gchar *name,
74 const gchar *label,
75 const gchar *tooltip,
76 const gchar *stock_id,
77 GtkTreeModel *model,
78 gint entry_width = -1,
79 gint extra_width = -1,
80 gpointer cell_data_func = NULL );
82 GtkTreeModel *ink_comboboxentry_action_get_model( Ink_ComboBoxEntry_Action* action );
83 GtkComboBoxEntry *ink_comboboxentry_action_get_comboboxentry( Ink_ComboBoxEntry_Action* action );
85 gchar* ink_comboboxentry_action_get_active_text( Ink_ComboBoxEntry_Action* action );
86 gboolean ink_comboboxentry_action_set_active_text( Ink_ComboBoxEntry_Action* action, const gchar* text );
88 void ink_comboboxentry_action_set_entry_width( Ink_ComboBoxEntry_Action* action, gint entry_width );
89 void ink_comboboxentry_action_set_extra_width( Ink_ComboBoxEntry_Action* action, gint extra_width );
91 void ink_comboboxentry_action_popup_enable( Ink_ComboBoxEntry_Action* action );
92 void ink_comboboxentry_action_popup_disable( Ink_ComboBoxEntry_Action* action );
94 void ink_comboboxentry_action_set_warning( Ink_ComboBoxEntry_Action* action, const gchar* warning );
96 void ink_comboboxentry_action_set_altx_name( Ink_ComboBoxEntry_Action* action, const gchar* altx_name );
98 #endif /* SEEN_INK_COMBOBOXENTRY_ACTION */