~canonical-dx-team/ubuntu/maverick/gtk+2.0/menuproxy

« back to all changes in this revision

Viewing changes to gtk/gtkcomboboxentry.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-05-04 12:24:25 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20070504122425-0m8midgzrp40y8w2
Tags: 2.10.12-1ubuntu1
* Sync with Debian
* New upstream version:
  Fixed bugs:
  - 379414 file chooser warnings when changing path in the entry
  - 418585 GtkFileChooserDefault sizing code is not DPI independent
  - 419568 Crash in search if start with special letter
  - 435062 build dies with icon cache validation
  - 379399 Segfault to call gtk_print_operation_run twice.
  - 387889 cups backend has problems when there are too many printers
  - 418531 invalid read to gtkicontheme.c gtk_icon_theme_lookup_icon...
  - 423916 crash in color scheme code
  - 424042 Segmentation fault while quickly pressing Alt+arrows
  - 415260 Protect against negative indices when setting values in G...
  - 419171 XGetVisualInfo() may not set nxvisuals
  - 128852 Gdk cursors don't look good on win32
  - 344657 Ctrl-H doesn't toggle "Show Hidden Files" setting
  - 345345 PrintOperation::paginate is not emitted for class handler
  - 347567 GtkPrintOperation::end-print is not emitted if it's cance...
  - 369112 gtk_ui_manager_add_ui should accept unnamed separator
  - 392015 Selected menu item invisible on Windows Vista
  - 399253 MS-Windows Theme Bottom Tab placement rendering glitches
  - 399425 gtk_input_dialog_fill_axes() adds child to gtkscrolledwin...
  - 403251 [patch] little memory leak in GtkPrintJob
  - 403267 [patch] memory leak in GtkPageSetupUnixDialog
  - 403470 MS-Windows Theme tab placement other than on top leaks a ...
  - 404506 Windows system fonts that have multi-byte font names cann...
  - 405089 Incorrect window placement for GtkEventBox private window
  - 405515 Minor leak in gtkfilesystemmodel.c
  - 405539 gdk_pixbuf_save() for PNG saver can return FALSE without ...
  - 415681 gdk_window_clear_area includes an extra line and column o...
  - 418219 GtkRecentChooser should apply filter before sorting and c...
  - 418403 Scroll to printer after selecting it from settings
  - 421985 _gtk_print_operation_platform_backend_launch_preview
  - 421990 gtk_print_job_get_surface
  - 421993 gtk_print_operation_init
  - 423064 Conditional jump or move depends on uninitialised value(s...
  - 423722 Fix printing header in gtk-demo
  - 424168 gtk_print_operation_run on async preview
  - 425655 Don't install gtk+-unix-print-2.0.pc on non-UNIX platforms
  - 425786 GDK segfaults if XineramaQueryScreens fails
  - 428665 Lpr Backend gets stuck in infinite loop during gtk_enumer...
  - 429902 GtkPrintOperation leaks cairo contextes
  - 431997 First delay of GdkPixbufAnimationIter is wrong
  - 433242 Inconsistent scroll arrow position calculations
  - 433972 Placing gtk.Expander inside a gtk.TextView() changes gtk....
  - 434261 _gtk_toolbar_elide_underscores incorrectly handles some s...
  - 383354 ctrl-L should make 'Location' entry disappear
  - 418673 gtk_recent_manager_add_item
  - 429732 gtk_accel_group_finalize accesses invalid memory
  - 435028 WM_CLIENT_LEADER is wrong on the leader_window
  - 431067 Background of the header window is not updated
  - 338843 add recent files support inside the ui manager
  - 148535 add drop shadow to menus, tooltips, etc. under Windows XP
* debian/control.in:
  - Conflicts on ubuntulooks (<= 0.9.11-1)
* debian/patches/15_default-fallback-icon-theme.patch:
  - patch from Debian, fallback on gnome icon theme

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* gtkcomboboxentry.c
 
2
 * Copyright (C) 2002, 2003  Kristian Rietveld <kris@gtk.org>
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Library General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Library General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Library General Public
 
15
 * License along with this library; if not, write to the
 
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
 */
 
19
 
 
20
#include <config.h>
 
21
#include "gtkcomboboxentry.h"
 
22
#include "gtkcelllayout.h"
 
23
 
 
24
#include "gtkentry.h"
 
25
#include "gtkcellrenderertext.h"
 
26
 
 
27
#include "gtkprivate.h"
 
28
#include "gtkintl.h"
 
29
#include "gtkalias.h"
 
30
 
 
31
#define GTK_COMBO_BOX_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_COMBO_BOX_ENTRY, GtkComboBoxEntryPrivate))
 
32
 
 
33
struct _GtkComboBoxEntryPrivate
 
34
{
 
35
  GtkWidget *entry;
 
36
 
 
37
  GtkCellRenderer *text_renderer;
 
38
  gint text_column;
 
39
};
 
40
 
 
41
static void gtk_combo_box_entry_set_property     (GObject               *object,
 
42
                                                  guint                  prop_id,
 
43
                                                  const GValue          *value,
 
44
                                                  GParamSpec            *pspec);
 
45
static void gtk_combo_box_entry_get_property     (GObject               *object,
 
46
                                                  guint                  prop_id,
 
47
                                                  GValue                *value,
 
48
                                                  GParamSpec            *pspec);
 
49
 
 
50
static gchar *gtk_combo_box_entry_get_active_text (GtkComboBox *combo_box);
 
51
static void gtk_combo_box_entry_active_changed   (GtkComboBox           *combo_box,
 
52
                                                  gpointer               user_data);
 
53
static void gtk_combo_box_entry_contents_changed (GtkEntry              *entry,
 
54
                                                  gpointer               user_data);
 
55
static gboolean gtk_combo_box_entry_mnemonic_activate (GtkWidget        *entry,
 
56
                                                       gboolean          group_cycling);
 
57
static void gtk_combo_box_entry_grab_focus       (GtkWidget *widget);
 
58
static void has_frame_changed                    (GtkComboBoxEntry      *entry_box,
 
59
                                                  GParamSpec            *pspec,
 
60
                                                  gpointer               data);
 
61
 
 
62
enum
 
63
{
 
64
  PROP_0,
 
65
  PROP_TEXT_COLUMN
 
66
};
 
67
 
 
68
G_DEFINE_TYPE (GtkComboBoxEntry, gtk_combo_box_entry, GTK_TYPE_COMBO_BOX)
 
69
 
 
70
static void
 
71
gtk_combo_box_entry_class_init (GtkComboBoxEntryClass *klass)
 
72
{
 
73
  GObjectClass *object_class;
 
74
  GtkWidgetClass *widget_class;
 
75
  GtkComboBoxClass *combo_class;
 
76
  
 
77
  object_class = (GObjectClass *)klass;
 
78
  object_class->set_property = gtk_combo_box_entry_set_property;
 
79
  object_class->get_property = gtk_combo_box_entry_get_property;
 
80
 
 
81
  widget_class = (GtkWidgetClass *)klass;
 
82
  widget_class->mnemonic_activate = gtk_combo_box_entry_mnemonic_activate;
 
83
  widget_class->grab_focus = gtk_combo_box_entry_grab_focus;
 
84
 
 
85
  combo_class = (GtkComboBoxClass *)klass;
 
86
  combo_class->get_active_text = gtk_combo_box_entry_get_active_text;
 
87
  
 
88
  g_object_class_install_property (object_class,
 
89
                                   PROP_TEXT_COLUMN,
 
90
                                   g_param_spec_int ("text-column",
 
91
                                                     P_("Text Column"),
 
92
                                                     P_("A column in the data source model to get the strings from"),
 
93
                                                     -1,
 
94
                                                     G_MAXINT,
 
95
                                                     -1,
 
96
                                                     GTK_PARAM_READWRITE));
 
97
 
 
98
  g_type_class_add_private ((GObjectClass *) klass,
 
99
                            sizeof (GtkComboBoxEntryPrivate));
 
100
}
 
101
 
 
102
static void
 
103
gtk_combo_box_entry_init (GtkComboBoxEntry *entry_box)
 
104
{
 
105
  entry_box->priv = GTK_COMBO_BOX_ENTRY_GET_PRIVATE (entry_box);
 
106
  entry_box->priv->text_column = -1;
 
107
 
 
108
  entry_box->priv->entry = gtk_entry_new ();
 
109
  /* this flag is a hack to tell the entry to fill its allocation.
 
110
   */
 
111
  GTK_ENTRY (entry_box->priv->entry)->is_cell_renderer = TRUE;
 
112
  gtk_container_add (GTK_CONTAINER (entry_box), entry_box->priv->entry);
 
113
  gtk_widget_show (entry_box->priv->entry);
 
114
 
 
115
  entry_box->priv->text_renderer = gtk_cell_renderer_text_new ();
 
116
  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (entry_box),
 
117
                              entry_box->priv->text_renderer, TRUE);
 
118
 
 
119
  gtk_combo_box_set_active (GTK_COMBO_BOX (entry_box), -1);
 
120
 
 
121
  g_signal_connect (entry_box->priv->entry, "changed",
 
122
                    G_CALLBACK (gtk_combo_box_entry_contents_changed),
 
123
                    entry_box);
 
124
  g_signal_connect (entry_box, "changed",
 
125
                    G_CALLBACK (gtk_combo_box_entry_active_changed), NULL);
 
126
  has_frame_changed (entry_box, NULL, NULL);
 
127
  g_signal_connect (entry_box, "notify::has-frame", G_CALLBACK (has_frame_changed), NULL);
 
128
}
 
129
 
 
130
static void
 
131
gtk_combo_box_entry_set_property (GObject      *object,
 
132
                                  guint         prop_id,
 
133
                                  const GValue *value,
 
134
                                  GParamSpec   *pspec)
 
135
{
 
136
  GtkComboBoxEntry *entry_box = GTK_COMBO_BOX_ENTRY (object);
 
137
 
 
138
  switch (prop_id)
 
139
    {
 
140
      case PROP_TEXT_COLUMN:
 
141
        gtk_combo_box_entry_set_text_column (entry_box,
 
142
                                             g_value_get_int (value));
 
143
        break;
 
144
 
 
145
      default:
 
146
        break;
 
147
    }
 
148
}
 
149
 
 
150
static void
 
151
gtk_combo_box_entry_get_property (GObject    *object,
 
152
                                  guint       prop_id,
 
153
                                  GValue     *value,
 
154
                                  GParamSpec *pspec)
 
155
{
 
156
  GtkComboBoxEntry *entry_box = GTK_COMBO_BOX_ENTRY (object);
 
157
 
 
158
  switch (prop_id)
 
159
    {
 
160
      case PROP_TEXT_COLUMN:
 
161
        g_value_set_int (value, entry_box->priv->text_column);
 
162
        break;
 
163
 
 
164
      default:
 
165
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
166
        break;
 
167
    }
 
168
}
 
169
 
 
170
static void
 
171
gtk_combo_box_entry_active_changed (GtkComboBox *combo_box,
 
172
                                    gpointer     user_data)
 
173
{
 
174
  GtkComboBoxEntry *entry_box = GTK_COMBO_BOX_ENTRY (combo_box);
 
175
  GtkTreeModel *model;
 
176
  GtkTreeIter iter;
 
177
  gchar *str = NULL;
 
178
 
 
179
  if (gtk_combo_box_get_active_iter (combo_box, &iter))
 
180
    {
 
181
      g_signal_handlers_block_by_func (entry_box->priv->entry,
 
182
                                       gtk_combo_box_entry_contents_changed,
 
183
                                       combo_box);
 
184
 
 
185
      model = gtk_combo_box_get_model (combo_box);
 
186
 
 
187
      gtk_tree_model_get (model, &iter, 
 
188
                          entry_box->priv->text_column, &str, 
 
189
                          -1);
 
190
      gtk_entry_set_text (GTK_ENTRY (entry_box->priv->entry), str);
 
191
      g_free (str);
 
192
 
 
193
      g_signal_handlers_unblock_by_func (entry_box->priv->entry,
 
194
                                         gtk_combo_box_entry_contents_changed,
 
195
                                         combo_box);
 
196
    }
 
197
}
 
198
 
 
199
static void 
 
200
has_frame_changed (GtkComboBoxEntry *entry_box,
 
201
                   GParamSpec       *pspec,
 
202
                   gpointer          data)
 
203
{
 
204
  gboolean has_frame;
 
205
  
 
206
  g_object_get (entry_box, "has-frame", &has_frame, NULL);
 
207
 
 
208
  gtk_entry_set_has_frame (GTK_ENTRY (entry_box->priv->entry), has_frame);
 
209
}
 
210
 
 
211
static void
 
212
gtk_combo_box_entry_contents_changed (GtkEntry *entry,
 
213
                                      gpointer  user_data)
 
214
{
 
215
  GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
 
216
 
 
217
  g_signal_handlers_block_by_func (combo_box,
 
218
                                   gtk_combo_box_entry_active_changed,
 
219
                                   NULL);
 
220
  gtk_combo_box_set_active (combo_box, -1);
 
221
  g_signal_handlers_unblock_by_func (combo_box,
 
222
                                     gtk_combo_box_entry_active_changed,
 
223
                                     NULL);
 
224
}
 
225
 
 
226
/* public API */
 
227
 
 
228
/**
 
229
 * gtk_combo_box_entry_new:
 
230
 *
 
231
 * Creates a new #GtkComboBoxEntry which has a #GtkEntry as child. After
 
232
 * construction, you should set a model using gtk_combo_box_set_model() and a
 
233
 * text_column * using gtk_combo_box_entry_set_text_column().
 
234
 *
 
235
 * Return value: A new #GtkComboBoxEntry.
 
236
 *
 
237
 * Since: 2.4
 
238
 */
 
239
GtkWidget *
 
240
gtk_combo_box_entry_new (void)
 
241
{
 
242
  return g_object_new (gtk_combo_box_entry_get_type (), NULL);
 
243
}
 
244
 
 
245
/**
 
246
 * gtk_combo_box_entry_new_with_model:
 
247
 * @model: A #GtkTreeModel.
 
248
 * @text_column: A column in @model to get the strings from.
 
249
 *
 
250
 * Creates a new #GtkComboBoxEntry which has a #GtkEntry as child and a list
 
251
 * of strings as popup. You can get the #GtkEntry from a #GtkComboBoxEntry
 
252
 * using GTK_ENTRY (GTK_BIN (combo_box_entry)->child). To add and remove
 
253
 * strings from the list, just modify @model using its data manipulation
 
254
 * API.
 
255
 *
 
256
 * Return value: A new #GtkComboBoxEntry.
 
257
 *
 
258
 * Since: 2.4
 
259
 */
 
260
GtkWidget *
 
261
gtk_combo_box_entry_new_with_model (GtkTreeModel *model,
 
262
                                    gint          text_column)
 
263
{
 
264
  GtkWidget *ret;
 
265
 
 
266
  g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
 
267
  g_return_val_if_fail (text_column >= 0, NULL);
 
268
  g_return_val_if_fail (text_column < gtk_tree_model_get_n_columns (model), NULL);
 
269
 
 
270
  ret = g_object_new (gtk_combo_box_entry_get_type (),
 
271
                      "model", model,
 
272
                      "text-column", text_column,
 
273
                      NULL);
 
274
 
 
275
  return ret;
 
276
}
 
277
 
 
278
/**
 
279
 * gtk_combo_box_entry_set_text_column:
 
280
 * @entry_box: A #GtkComboBoxEntry.
 
281
 * @text_column: A column in @model to get the strings from.
 
282
 *
 
283
 * Sets the model column which @entry_box should use to get strings from
 
284
 * to be @text_column.
 
285
 *
 
286
 * Since: 2.4
 
287
 */
 
288
void
 
289
gtk_combo_box_entry_set_text_column (GtkComboBoxEntry *entry_box,
 
290
                                     gint              text_column)
 
291
{
 
292
  g_return_if_fail (text_column >= 0);
 
293
  g_return_if_fail (text_column < gtk_tree_model_get_n_columns (gtk_combo_box_get_model (GTK_COMBO_BOX (entry_box))));
 
294
  g_return_if_fail (entry_box->priv->text_column == -1);
 
295
 
 
296
  entry_box->priv->text_column = text_column;
 
297
 
 
298
  gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (entry_box),
 
299
                                  entry_box->priv->text_renderer,
 
300
                                  "text", text_column,
 
301
                                  NULL);
 
302
}
 
303
 
 
304
/**
 
305
 * gtk_combo_box_entry_get_text_column:
 
306
 * @entry_box: A #GtkComboBoxEntry.
 
307
 *
 
308
 * Returns the column which @entry_box is using to get the strings from.
 
309
 *
 
310
 * Return value: A column in the data source model of @entry_box.
 
311
 *
 
312
 * Since: 2.4
 
313
 */
 
314
gint
 
315
gtk_combo_box_entry_get_text_column (GtkComboBoxEntry *entry_box)
 
316
{
 
317
  g_return_val_if_fail (GTK_IS_COMBO_BOX_ENTRY (entry_box), 0);
 
318
 
 
319
  return entry_box->priv->text_column;
 
320
}
 
321
 
 
322
static gboolean
 
323
gtk_combo_box_entry_mnemonic_activate (GtkWidget *widget,
 
324
                                       gboolean   group_cycling)
 
325
{
 
326
  GtkComboBoxEntry *entry_box = GTK_COMBO_BOX_ENTRY (widget);
 
327
 
 
328
  gtk_widget_grab_focus (entry_box->priv->entry);
 
329
 
 
330
  return TRUE;
 
331
}
 
332
 
 
333
static void
 
334
gtk_combo_box_entry_grab_focus (GtkWidget *widget)
 
335
{
 
336
  GtkComboBoxEntry *entry_box = GTK_COMBO_BOX_ENTRY (widget);
 
337
 
 
338
  gtk_widget_grab_focus (entry_box->priv->entry);
 
339
}
 
340
 
 
341
 
 
342
 
 
343
/* convenience API for simple text combos */
 
344
 
 
345
/**
 
346
 * gtk_combo_box_entry_new_text:
 
347
 *
 
348
 * Convenience function which constructs a new editable text combo box, which 
 
349
 * is a #GtkComboBoxEntry just displaying strings. If you use this function to
 
350
 * create a text combo box, you should only manipulate its data source with
 
351
 * the following convenience functions: gtk_combo_box_append_text(),
 
352
 * gtk_combo_box_insert_text(), gtk_combo_box_prepend_text() and
 
353
 * gtk_combo_box_remove_text().
 
354
 *
 
355
 * Return value: A new text #GtkComboBoxEntry.
 
356
 *
 
357
 * Since: 2.4
 
358
 */
 
359
GtkWidget *
 
360
gtk_combo_box_entry_new_text (void)
 
361
{
 
362
  GtkWidget *entry_box;
 
363
  GtkListStore *store;
 
364
 
 
365
  store = gtk_list_store_new (1, G_TYPE_STRING);
 
366
  entry_box = gtk_combo_box_entry_new_with_model (GTK_TREE_MODEL (store), 0);
 
367
  g_object_unref (store);
 
368
 
 
369
  return entry_box;
 
370
}
 
371
 
 
372
static gchar *
 
373
gtk_combo_box_entry_get_active_text (GtkComboBox *combo_box)
 
374
{
 
375
  GtkComboBoxEntry *combo = GTK_COMBO_BOX_ENTRY (combo_box);
 
376
 
 
377
  if (combo->priv->entry)
 
378
    return g_strdup (gtk_entry_get_text (GTK_ENTRY (combo->priv->entry)));
 
379
 
 
380
  return NULL;
 
381
}
 
382
 
 
383
#define __GTK_COMBO_BOX_ENTRY_C__
 
384
#include "gtkaliasdef.c"