ink-comboboxentry-action.cpp revision 48fddc20b8d56a28c51e00fcb722b16001728ec4
/*
* A subclass of GtkAction that wraps a GtkComboBoxEntry.
* Features:
* Setting GtkEntryBox width in characters.
* Passing a function for formatting cells.
* Displaying a warning if text isn't in list.
*
* Author(s):
* Tavmjong Bah
*
* Copyright (C) 2010 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
/*
* We must provide for both a toolbar item and a menu item.
* As we don't know which widgets are used (or even constructed),
* we must keep track of things like active entry ourselves.
*/
#include <iostream>
#include <string.h>
#include <gtk/gtktoolitem.h>
#include <gtk/gtkcomboboxentry.h>
#include <gtk/gtkentrycompletion.h>
#include "ink-comboboxentry-action.h"
// Must handle both tool and menu items!
// Internal
// Callbacks
static gboolean match_selected_cb( GtkEntryCompletion* widget, GtkTreeModel* model, GtkTreeIter* iter, gpointer data );
enum {
PROP_MODEL = 1,
};
enum {
CHANGED = 0,
};
{
// Free any allocated resources.
}
static void ink_comboboxentry_action_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
switch(property_id) {
case PROP_MODEL:
break;
case PROP_COMBOBOX:
break;
case PROP_ENTRY:
break;
case PROP_WIDTH:
break;
case PROP_CELL_DATA_FUNC:
break;
case PROP_POPUP:
break;
default:
}
}
static void ink_comboboxentry_action_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
switch(property_id) {
case PROP_MODEL:
break;
case PROP_COMBOBOX:
break;
case PROP_ENTRY:
break;
case PROP_WIDTH:
break;
case PROP_CELL_DATA_FUNC:
break;
case PROP_POPUP:
break;
default:
}
}
static void
{
/* Override any proxy properties. */
// if (GTK_IS_MENU_ITEM (proxy)) {
// }
}
{
g_param_spec_object ("model",
"Tree Model",
"Tree Model",
g_param_spec_object ("combobox",
"GtkComboBoxEntry",
"GtkComboBoxEntry",
g_param_spec_object ("entry",
"GtkEntry",
"GtkEntry",
g_param_spec_int ("width",
"EntryBox width",
"EntryBox width (characters)",
-1.0, 100, -1.0,
g_param_spec_pointer ("cell_data_func",
"Cell Data Func",
"Cell Deta Function",
g_param_spec_boolean ("popup",
"Entry Popup",
"Entry Popup",
false,
// We need to know when GtkComboBoxEvent or Menu ready for reading
G_TYPE_NONE, 0);
// Probably not needed... originally to keep track of key-presses.
G_TYPE_NONE, 0);
}
{
}
{
static GType ink_comboboxentry_action_type = 0;
if (!ink_comboboxentry_action_type) {
static const GTypeInfo ink_comboboxentry_action_info = {
sizeof(Ink_ComboBoxEntry_ActionClass),
NULL, /* base_init */
NULL, /* base_finalize */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof(Ink_ComboBoxEntry_Action),
0, /* n_preallocs */
NULL /* value_table */
};
"Ink_ComboBoxEntry_Action",
(GTypeFlags)0 );
}
return ink_comboboxentry_action_type;
}
void *cell_data_func )
{
"name", name,
"label", label,
"tooltip", tooltip,
"stock-id", stock_id,
"model", model,
"width", width,
"cell_data_func", cell_data_func,
NULL);
}
// Create a widget for a toolbar.
{
GtkWidget* comboBoxEntry = gtk_combo_box_entry_new_with_model( ink_comboboxentry_action->model, 0 );
// Optionally add formatting...
}
// Get reference to GtkEntry and fiddle a bit with it.
// Change width
if( ink_comboboxentry_action->width > 0 ) {
}
// Add pop-up entry completion if required
if( ink_comboboxentry_action->popup ) {
}
// Add altx_name if required
if( ink_comboboxentry_action->altx_name ) {
g_object_set_data( G_OBJECT( child ), ink_comboboxentry_action->altx_name, ink_comboboxentry_action->entry );
}
// Add signal for GtkEntry to check if finished typing.
}
} else {
}
return item;
}
// Create a drop-down menu.
{
g_warning( "ink_comboboxentry_action: create_menu_item not implemented" );
// One can easily modify ege-select-one-action routine to implement this.
return item;
}
}
}
return text;
}
gboolean ink_comboboxentry_action_set_active_text( Ink_ComboBoxEntry_Action* ink_comboboxentry_action, const gchar* text ) {
// Get active row or -1 if none
ink_comboboxentry_action->active = get_active_row_from_text( ink_comboboxentry_action, ink_comboboxentry_action->text );
// Set active row, check that combobox has been created.
if( ink_comboboxentry_action->combobox ) {
gtk_combo_box_set_active( GTK_COMBO_BOX( ink_comboboxentry_action->combobox ), ink_comboboxentry_action->active );
}
// Fiddle with entry
if( ink_comboboxentry_action->entry ) {
// Explicitly set text in GtkEntry box (won't be set if text not in list).
// Show or hide warning
// Can't add tooltip until icon set
#endif // GTK_CHECK_VERSION(2,16,0)
} else {
NULL );
#endif // GTK_CHECK_VERSION(2,16,0)
}
}
// Return if active text in list
return found;
}
// Widget may not have been created....
}
}
// Widget may not have been created....
// Check we don't already have a GtkEntryCompletion
if( action->entry_completion ) return;
g_signal_connect (G_OBJECT (action->entry_completion), "match-selected", G_CALLBACK (match_selected_cb), action );
}
}
if( action->entry_completion ) {
}
}
void ink_comboboxentry_action_set_warning( Ink_ComboBoxEntry_Action* action, const gchar* warning ) {
// Widget may not have been created....
#endif // GTK_CHECK_VERSION(2,16,0)
}
}
void ink_comboboxentry_action_set_altx_name( Ink_ComboBoxEntry_Action* action, const gchar* altx_name ) {
// Widget may not have been created....
}
}
// Internal ---------------------------------------------------
// Return row of active text or -1 if not found.
// Check if text in list
while ( valid ) {
// Get text from list entry
// Check for match
found = true;
break;
}
++row;
}
return row;
}
// Callbacks ---------------------------------------------------
// Two things can happen to get here:
// An item is selected in the drop-down menu.
// Text is typed.
// We only react here if an item is selected.
// Get action
// Check if item selected:
if( newActive >= 0 ) {
// Now let the world know
}
}
}
// Get text from entry box.. check if it matches a menu entry.
// Get action
// Get text
// Get row
// Set active row
gtk_combo_box_set_active( GTK_COMBO_BOX( ink_comboboxentry_action->combobox), ink_comboboxentry_action->active );
// Now let the world know
}
static gboolean match_selected_cb( GtkEntryCompletion* /*widget*/, GtkTreeModel* model, GtkTreeIter* iter, gpointer data )
{
// Get action
if( entry) {
// Set text in GtkEntry
// Set text in GtkAction
// Get row
// Set active row
gtk_combo_box_set_active( GTK_COMBO_BOX( ink_comboboxentry_action->combobox), ink_comboboxentry_action->active );
// Now let the world know
return true;
}
return false;
}