summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2010-04-27 18:24:44 +0000
committertavmjong-free <tavmjong@free.fr>2010-04-27 18:24:44 +0000
commit409de448cfb250865b4958d1dd2c6e409e990443 (patch)
treed2e5e3bb9a8016f1265ad206d9ac01c766efa732 /src
parentsome copyediting of labels (diff)
downloadinkscape-409de448cfb250865b4958d1dd2c6e409e990443.tar.gz
inkscape-409de448cfb250865b4958d1dd2c6e409e990443.zip
inkscape-comboboxentry-action:
Add option to add extra width to GtkComboBox. Add names to widgets so styles can be set with RC files. toolbox.cpp: Add extra width to font-family GtkComboBox. Change style of font-family drop-down from menu to list. (bzr r9384)
Diffstat (limited to 'src')
-rw-r--r--src/ink-comboboxentry-action.cpp84
-rw-r--r--src/ink-comboboxentry-action.h21
-rw-r--r--src/widgets/toolbox.cpp25
3 files changed, 102 insertions, 28 deletions
diff --git a/src/ink-comboboxentry-action.cpp b/src/ink-comboboxentry-action.cpp
index de0af347c..cfaf09901 100644
--- a/src/ink-comboboxentry-action.cpp
+++ b/src/ink-comboboxentry-action.cpp
@@ -4,6 +4,8 @@
* Setting GtkEntryBox width in characters.
* Passing a function for formatting cells.
* Displaying a warning if text isn't in list.
+ * Setting names for GtkComboBoxEntry and GtkEntry (actionName_combobox, actionName_entry)
+ * to allow setting resources.
*
* Author(s):
* Tavmjong Bah
@@ -46,7 +48,8 @@ enum {
PROP_MODEL = 1,
PROP_COMBOBOX,
PROP_ENTRY,
- PROP_WIDTH,
+ PROP_ENTRY_WIDTH,
+ PROP_EXTRA_WIDTH,
PROP_CELL_DATA_FUNC,
PROP_POPUP
};
@@ -87,8 +90,12 @@ static void ink_comboboxentry_action_set_property (GObject *object, guint proper
action->entry = GTK_ENTRY( g_value_get_object( value ));
break;
- case PROP_WIDTH:
- action->width = g_value_get_int( value );
+ case PROP_ENTRY_WIDTH:
+ action->entry_width = g_value_get_int( value );
+ break;
+
+ case PROP_EXTRA_WIDTH:
+ action->extra_width = g_value_get_int( value );
break;
case PROP_CELL_DATA_FUNC:
@@ -123,8 +130,12 @@ static void ink_comboboxentry_action_get_property (GObject *object, guint proper
g_value_set_object (value, action->entry);
break;
- case PROP_WIDTH:
- g_value_set_int (value, action->width);
+ case PROP_ENTRY_WIDTH:
+ g_value_set_int (value, action->entry_width);
+ break;
+
+ case PROP_EXTRA_WIDTH:
+ g_value_set_int (value, action->extra_width);
break;
case PROP_CELL_DATA_FUNC:
@@ -197,8 +208,8 @@ static void ink_comboboxentry_action_class_init (Ink_ComboBoxEntry_ActionClass *
(GParamFlags)G_PARAM_READABLE));
g_object_class_install_property (
gobject_class,
- PROP_WIDTH,
- g_param_spec_int ("width",
+ PROP_ENTRY_WIDTH,
+ g_param_spec_int ("entry_width",
"EntryBox width",
"EntryBox width (characters)",
-1.0, 100, -1.0,
@@ -206,6 +217,15 @@ static void ink_comboboxentry_action_class_init (Ink_ComboBoxEntry_ActionClass *
g_object_class_install_property (
gobject_class,
+ PROP_EXTRA_WIDTH,
+ g_param_spec_int ("extra_width",
+ "Extra width",
+ "Extra width (px)",
+ -1.0, 500, -1.0,
+ (GParamFlags)G_PARAM_READWRITE));
+
+ g_object_class_install_property (
+ gobject_class,
PROP_CELL_DATA_FUNC,
g_param_spec_pointer ("cell_data_func",
"Cell Data Func",
@@ -287,7 +307,8 @@ Ink_ComboBoxEntry_Action *ink_comboboxentry_action_new (const gchar *name,
const gchar *tooltip,
const gchar *stock_id,
GtkTreeModel *model,
- gint width,
+ gint entry_width,
+ gint extra_width,
void *cell_data_func )
{
g_return_val_if_fail (name != NULL, NULL);
@@ -298,7 +319,8 @@ Ink_ComboBoxEntry_Action *ink_comboboxentry_action_new (const gchar *name,
"tooltip", tooltip,
"stock-id", stock_id,
"model", model,
- "width", width,
+ "entry_width", entry_width,
+ "extra_width", extra_width,
"cell_data_func", cell_data_func,
NULL);
}
@@ -312,9 +334,17 @@ GtkWidget* create_tool_item( GtkAction* action )
Ink_ComboBoxEntry_Action* ink_comboboxentry_action = INK_COMBOBOXENTRY_ACTION( action );
+ gchar *action_name = g_strdup( gtk_action_get_name( action ) );
+ gchar *combobox_name = g_strjoin( NULL, action_name, "_combobox", NULL );
+ gchar *entry_name = g_strjoin( NULL, action_name, "_entry", NULL );
+ g_free( action_name );
+
item = GTK_WIDGET( gtk_tool_item_new() );
GtkWidget* comboBoxEntry = gtk_combo_box_entry_new_with_model( ink_comboboxentry_action->model, 0 );
+ // Name it so we can muck with it using an RC file
+ gtk_widget_set_name( comboBoxEntry, combobox_name );
+ g_free( combobox_name );
{
GtkWidget *align = gtk_alignment_new(0, 0.5, 0, 0);
@@ -346,14 +376,28 @@ GtkWidget* create_tool_item( GtkAction* action )
NULL, NULL );
}
+ // Optionally widen the combobox width... which widens the drop-down list in list mode.
+ if( ink_comboboxentry_action->extra_width > 0 ) {
+ GtkRequisition req;
+ gtk_widget_size_request( GTK_WIDGET( ink_comboboxentry_action->combobox ), &req );
+ gtk_widget_set_size_request( GTK_WIDGET( ink_comboboxentry_action->combobox ),
+ req.width + ink_comboboxentry_action->extra_width, -1 );
+ }
+
// Get reference to GtkEntry and fiddle a bit with it.
GtkWidget *child = gtk_bin_get_child( GTK_BIN(comboBoxEntry) );
+
+ // Name it so we can muck with it using an RC file
+ gtk_widget_set_name( child, entry_name );
+ g_free( entry_name );
+
if( child && GTK_IS_ENTRY( child ) ) {
+
ink_comboboxentry_action->entry = GTK_ENTRY(child);
// Change width
- if( ink_comboboxentry_action->width > 0 ) {
- gtk_entry_set_width_chars (GTK_ENTRY (child), ink_comboboxentry_action->width );
+ if( ink_comboboxentry_action->entry_width > 0 ) {
+ gtk_entry_set_width_chars (GTK_ENTRY (child), ink_comboboxentry_action->entry_width );
}
// Add pop-up entry completion if required
@@ -465,13 +509,25 @@ gboolean ink_comboboxentry_action_set_active_text( Ink_ComboBoxEntry_Action* ink
return found;
}
-void ink_comboboxentry_action_set_width( Ink_ComboBoxEntry_Action* action, gint width ) {
+void ink_comboboxentry_action_set_entry_width( Ink_ComboBoxEntry_Action* action, gint entry_width ) {
- action->width = width;
+ action->entry_width = entry_width;
// Widget may not have been created....
if( action->entry ) {
- gtk_entry_set_width_chars( GTK_ENTRY(action->entry), width );
+ gtk_entry_set_width_chars( GTK_ENTRY(action->entry), entry_width );
+ }
+}
+
+void ink_comboboxentry_action_set_extra_width( Ink_ComboBoxEntry_Action* action, gint extra_width ) {
+
+ action->extra_width = extra_width;
+
+ // Widget may not have been created....
+ if( action->combobox ) {
+ GtkRequisition req;
+ gtk_widget_size_request( GTK_WIDGET( action->combobox ), &req );
+ gtk_widget_set_size_request( GTK_WIDGET( action->combobox ), req.width + action->extra_width, -1 );
}
}
diff --git a/src/ink-comboboxentry-action.h b/src/ink-comboboxentry-action.h
index 031803d8a..e080e6cdf 100644
--- a/src/ink-comboboxentry-action.h
+++ b/src/ink-comboboxentry-action.h
@@ -4,6 +4,8 @@
* Setting GtkEntryBox width in characters.
* Passing a function for formatting cells.
* Displaying a warning if text isn't in list.
+ * Setting names for GtkComboBoxEntry and GtkEntry (actionName_combobox, actionName_entry)
+ * to allow setting resources.
*
* Author(s):
* Tavmjong Bah
@@ -55,7 +57,8 @@ struct _Ink_ComboBoxEntry_Action {
gint active; // Index of active menu item (-1 if not in list).
gchar *text; // Text of active menu item or entry box.
- gint width; // Width of GtkComboBoxEntry in characters.
+ gint entry_width;// Width of GtkEntry in characters.
+ gint extra_width;// Extra Width of GtkComboBox.. to widen drop-down list in list mode.
gboolean popup; // Do we pop-up an entry-completion dialog?
gchar *warning; // Text for warning that entry isn't in list.
gchar *altx_name; // Target for Alt-X keyboard shortcut.
@@ -68,12 +71,13 @@ GType ink_comboboxentry_action_get_type (void);
* Creates a GtkAction subclass that wraps a GtkComboBoxEntry object.
*/
Ink_ComboBoxEntry_Action *ink_comboboxentry_action_new ( const gchar *name,
- const gchar *label,
- const gchar *tooltip,
- const gchar *stock_id,
- GtkTreeModel *model,
- gint width = -1,
- gpointer cell_data_func = NULL );
+ const gchar *label,
+ const gchar *tooltip,
+ const gchar *stock_id,
+ GtkTreeModel *model,
+ gint entry_width = -1,
+ gint extra_width = -1,
+ gpointer cell_data_func = NULL );
GtkTreeModel *ink_comboboxentry_action_get_model( Ink_ComboBoxEntry_Action* action );
GtkComboBoxEntry *ink_comboboxentry_action_get_comboboxentry( Ink_ComboBoxEntry_Action* action );
@@ -81,7 +85,8 @@ GtkComboBoxEntry *ink_comboboxentry_action_get_comboboxentry( Ink_ComboBoxEntry_
gchar* ink_comboboxentry_action_get_active_text( Ink_ComboBoxEntry_Action* action );
gboolean ink_comboboxentry_action_set_active_text( Ink_ComboBoxEntry_Action* action, const gchar* text );
-void ink_comboboxentry_action_set_width( Ink_ComboBoxEntry_Action* action, gint width );
+void ink_comboboxentry_action_set_entry_width( Ink_ComboBoxEntry_Action* action, gint entry_width );
+void ink_comboboxentry_action_set_extra_width( Ink_ComboBoxEntry_Action* action, gint extra_width );
void ink_comboboxentry_action_popup_enable( Ink_ComboBoxEntry_Action* action );
void ink_comboboxentry_action_popup_disable( Ink_ComboBoxEntry_Action* action );
diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp
index 978f19c4c..2cd96491e 100644
--- a/src/widgets/toolbox.cpp
+++ b/src/widgets/toolbox.cpp
@@ -6239,15 +6239,19 @@ static void cell_data_func(GtkCellLayout * /*cell_layout*/,
Glib::ustring sample = prefs->getString("/tools/text/font_sample");
gchar *const sample_escaped = g_markup_escape_text(sample.data(), -1);
- std::stringstream markup;
- markup << family_escaped << " <span foreground='gray' font_family='"
- << family_escaped << "'>" << sample_escaped << "</span>";
- g_object_set (G_OBJECT (cell), "markup", markup.str().c_str(), NULL);
+ std::stringstream markup;
+ markup << family_escaped << " <span foreground='gray' font_family='"
+ << family_escaped << "'>" << sample_escaped << "</span>";
+ g_object_set (G_OBJECT (cell), "markup", markup.str().c_str(), NULL);
g_free(sample_escaped);
} else {
g_object_set (G_OBJECT (cell), "markup", family_escaped, NULL);
}
+ // This doesn't work for two reasons... it set both selected and not selected backgrounds
+ // to white.. which means that white foreground text is invisible. It also only effects
+ // the text region, leaving the padding untouched.
+ // g_object_set (G_OBJECT (cell), "cell-background", "white", "cell-background-set", true, NULL);
g_free(family);
g_free(family_escaped);
@@ -7171,10 +7175,11 @@ static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions
Ink_ComboBoxEntry_Action* act = ink_comboboxentry_action_new( "TextFontFamilyAction",
_("Font Family"),
- _("Select Font Family"),
+ _("Select Font Family (Alt-X to access)"),
NULL,
GTK_TREE_MODEL(model),
- -1, // Set width
+ -1, // Entry width
+ 50, // Extra list width
(gpointer)cell_data_func ); // Cell layout
ink_comboboxentry_action_popup_enable( act ); // Enable entry completion
gchar *const warning = _("Font not found on system");
@@ -7183,6 +7188,14 @@ static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions
g_signal_connect( G_OBJECT(act), "changed", G_CALLBACK(sp_text_fontfamily_value_changed), holder );
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
g_object_set_data( holder, "TextFontFamilyAction", act );
+
+ // Change style of drop-down from menu to list
+ gtk_rc_parse_string (
+ "style \"dropdown-as-list-style\"\n"
+ "{\n"
+ " GtkComboBox::appears-as-list = 1\n"
+ "}\n"
+ "widget \"*.TextFontFamilyAction_combobox\" style \"dropdown-as-list-style\"");
}
/* Font size */