gtkcombobox.c 185 KB
Newer Older
1 2 3
/* gtkcombobox.c
 * Copyright (C) 2002, 2003  Kristian Rietveld <kris@gtk.org>
 *
4 5 6 7
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * 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 11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * 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
Javier Jardón's avatar
Javier Jardón committed
15
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 17
 */

18
#include "config.h"
19

Kristian Rietveld's avatar
Kristian Rietveld committed
20
#include "gtkcombobox.h"
21 22

#include "gtkadjustment.h"
23 24
#include "gtkcellareabox.h"
#include "gtktreemenu.h"
25 26
#include "gtkarrow.h"
#include "gtkbindings.h"
Kristian Rietveld's avatar
Kristian Rietveld committed
27
#include "gtkcelllayout.h"
28
#include "gtkcellrenderertext.h"
Kristian Rietveld's avatar
Kristian Rietveld committed
29
#include "gtkcellview.h"
30
#include "gtkeventbox.h"
Kristian Rietveld's avatar
Kristian Rietveld committed
31
#include "gtkframe.h"
Matthias Clasen's avatar
Matthias Clasen committed
32
#include "gtkbox.h"
33 34
#include "gtkliststore.h"
#include "gtkmain.h"
35
#include "gtkmenuprivate.h"
36
#include "gtkmenushellprivate.h"
37
#include "gtkscrolledwindow.h"
38
#include "gtkseparatormenuitem.h"
39
#include "deprecated/gtktearoffmenuitem.h"
Kristian Rietveld's avatar
Kristian Rietveld committed
40
#include "gtktogglebutton.h"
41
#include "gtktreeselection.h"
Matthias Clasen's avatar
Matthias Clasen committed
42
#include "gtkseparator.h"
43
#include "gtkwidgetpath.h"
44
#include "gtkwidgetprivate.h"
Kristian Rietveld's avatar
Kristian Rietveld committed
45
#include "gtkwindow.h"
46
#include "gtktypebuiltins.h"
47
#include "gtkprivate.h"
48 49 50

#include <gobject/gvaluecollector.h>

Kristian Rietveld's avatar
Kristian Rietveld committed
51
#include <string.h>
52 53 54 55 56
#include <stdarg.h>

#include "gtkmarshalers.h"
#include "gtkintl.h"

57
#include "gtkentryprivate.h"
58
#include "gtktreeprivate.h"
59
#include "a11y/gtkcomboboxaccessible.h"
60

61 62 63 64 65

/**
 * SECTION:gtkcombobox
 * @Short_description: A widget used to choose from a list of items
 * @Title: GtkComboBox
66
 * @See_also: #GtkComboBoxText, #GtkTreeModel, #GtkCellRenderer
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
 *
 * A GtkComboBox is a widget that allows the user to choose from a list of
 * valid choices. The GtkComboBox displays the selected choice. When
 * activated, the GtkComboBox displays a popup which allows the user to
 * make a new choice. The style in which the selected value is displayed,
 * and the style of the popup is determined by the current theme. It may
 * be similar to a Windows-style combo box.
 *
 * The GtkComboBox uses the model-view pattern; the list of valid choices
 * is specified in the form of a tree model, and the display of the choices
 * can be adapted to the data in the model by using cell renderers, as you
 * would in a tree view. This is possible since GtkComboBox implements the
 * #GtkCellLayout interface. The tree model holding the valid choices is
 * not restricted to a flat list, it can be a real tree, and the popup will
 * reflect the tree structure.
 *
83 84 85 86
 * To allow the user to enter values not in the model, the 'has-entry'
 * property allows the GtkComboBox to contain a #GtkEntry. This entry
 * can be accessed by calling gtk_bin_get_child() on the combo box.
 *
87 88
 * For a simple list of textual choices, the model-view API of GtkComboBox
 * can be a bit overwhelming. In this case, #GtkComboBoxText offers a
89 90
 * simple alternative. Both GtkComboBox and #GtkComboBoxText can contain
 * an entry.
91 92 93
 */


94
/* WELCOME, to THE house of evil code */
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
struct _GtkComboBoxPrivate
{
  GtkTreeModel *model;

  GtkCellArea *area;

  gint col_column;
  gint row_column;

  gint wrap_width;
  GtkShadowType shadow_type;

  gint active; /* Only temporary */
  GtkTreeRowReference *active_row;

  GtkWidget *tree_view;

  GtkWidget *cell_view;
  GtkWidget *cell_view_frame;

  GtkWidget *button;
  GtkWidget *box;
  GtkWidget *arrow;
  GtkWidget *separator;

  GtkWidget *popup_widget;
  GtkWidget *popup_window;
  GtkWidget *scrolled_window;

  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
135 136
   * an automated cell renderer and text column
   */
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
  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 focus_on_click : 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;
  GdkDevice *grab_keyboard;

  gchar *tearoff_title;
};

164 165 166 167 168 169 170 171 172 173 174 175 176 177
/* While debugging this evil code, I have learned that
 * there are actually 4 modes to this widget, which can
 * be characterized as follows
 * 
 * 1) menu mode, no child added
 *
 * tree_view -> NULL
 * cell_view -> GtkCellView, regular child
 * cell_view_frame -> NULL
 * button -> GtkToggleButton set_parent to combo
 * arrow -> GtkArrow set_parent to button
 * separator -> GtkVSepator set_parent to button
 * popup_widget -> GtkMenu
 * popup_window -> NULL
178
 * scrolled_window -> NULL
179 180 181 182 183 184 185 186 187 188 189
 *
 * 2) menu mode, child added
 * 
 * tree_view -> NULL
 * cell_view -> NULL 
 * cell_view_frame -> NULL
 * button -> GtkToggleButton set_parent to combo
 * arrow -> GtkArrow, child of button
 * separator -> NULL
 * popup_widget -> GtkMenu
 * popup_window -> NULL
190
 * scrolled_window -> NULL
191 192 193
 *
 * 3) list mode, no child added
 * 
194
 * tree_view -> GtkTreeView, child of scrolled_window
195 196 197 198 199 200 201
 * cell_view -> GtkCellView, regular child
 * cell_view_frame -> GtkFrame, set parent to combo
 * button -> GtkToggleButton, set_parent to combo
 * arrow -> GtkArrow, child of button
 * separator -> NULL
 * popup_widget -> tree_view
 * popup_window -> GtkWindow
202
 * scrolled_window -> GtkScrolledWindow, child of popup_window
203 204 205
 *
 * 4) list mode, child added
 *
206
 * tree_view -> GtkTreeView, child of scrolled_window
207 208 209 210 211 212 213
 * cell_view -> NULL
 * cell_view_frame -> NULL
 * button -> GtkToggleButton, set_parent to combo
 * arrow -> GtkArrow, child of button
 * separator -> NULL
 * popup_widget -> tree_view
 * popup_window -> GtkWindow
214
 * scrolled_window -> GtkScrolledWindow, child of popup_window
215 216 217
 * 
 */

218 219 220 221 222
enum {
  CHANGED,
  MOVE_ACTIVE,
  POPUP,
  POPDOWN,
223
  FORMAT_ENTRY_TEXT,
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
  LAST_SIGNAL
};

enum {
  PROP_0,
  PROP_MODEL,
  PROP_WRAP_WIDTH,
  PROP_ROW_SPAN_COLUMN,
  PROP_COLUMN_SPAN_COLUMN,
  PROP_ACTIVE,
  PROP_ADD_TEAROFFS,
  PROP_TEAROFF_TITLE,
  PROP_HAS_FRAME,
  PROP_FOCUS_ON_CLICK,
  PROP_POPUP_SHOWN,
  PROP_BUTTON_SENSITIVITY,
  PROP_EDITING_CANCELED,
  PROP_HAS_ENTRY,
  PROP_ENTRY_TEXT_COLUMN,
  PROP_POPUP_FIXED_WIDTH,
  PROP_ID_COLUMN,
  PROP_ACTIVE_ID,
  PROP_CELL_AREA
};

static guint combo_box_signals[LAST_SIGNAL] = {0,};

#define SCROLL_TIME  100

/* common */

static void     gtk_combo_box_cell_layout_init     (GtkCellLayoutIface *iface);
static void     gtk_combo_box_cell_editable_init   (GtkCellEditableIface *iface);
257
static GObject *gtk_combo_box_constructor          (GType                  type,
258 259
                                                    guint                  n_construct_properties,
                                                    GObjectConstructParam *construct_properties);
260
static void     gtk_combo_box_dispose              (GObject          *object);
261
static void     gtk_combo_box_finalize             (GObject          *object);
262 263
static void     gtk_combo_box_destroy              (GtkWidget        *widget);

264 265 266 267 268 269 270 271 272
static void     gtk_combo_box_set_property         (GObject         *object,
                                                    guint            prop_id,
                                                    const GValue    *value,
                                                    GParamSpec      *spec);
static void     gtk_combo_box_get_property         (GObject         *object,
                                                    guint            prop_id,
                                                    GValue          *value,
                                                    GParamSpec      *spec);

273 274
static void     gtk_combo_box_state_flags_changed  (GtkWidget       *widget,
                                                    GtkStateFlags    previous);
275 276 277 278 279 280 281
static void     gtk_combo_box_grab_focus           (GtkWidget       *widget);
static void     gtk_combo_box_style_updated        (GtkWidget       *widget);
static void     gtk_combo_box_button_toggled       (GtkWidget       *widget,
                                                    gpointer         data);
static void     gtk_combo_box_button_state_flags_changed (GtkWidget     *widget,
                                                          GtkStateFlags  previous,
                                                          gpointer       data);
282 283
static void     gtk_combo_box_add                  (GtkContainer    *container,
                                                    GtkWidget       *widget);
284 285
static void     gtk_combo_box_remove               (GtkContainer    *container,
                                                    GtkWidget       *widget);
286 287 288 289 290 291 292 293

static void     gtk_combo_box_menu_show            (GtkWidget        *menu,
                                                    gpointer          user_data);
static void     gtk_combo_box_menu_hide            (GtkWidget        *menu,
                                                    gpointer          user_data);

static void     gtk_combo_box_set_popup_widget     (GtkComboBox      *combo_box,
                                                    GtkWidget        *popup);
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
static void     gtk_combo_box_menu_position_below  (GtkMenu          *menu,
                                                    gint             *x,
                                                    gint             *y,
                                                    gint             *push_in,
                                                    gpointer          user_data);
static void     gtk_combo_box_menu_position_over   (GtkMenu          *menu,
                                                    gint             *x,
                                                    gint             *y,
                                                    gint             *push_in,
                                                    gpointer          user_data);
static void     gtk_combo_box_menu_position        (GtkMenu          *menu,
                                                    gint             *x,
                                                    gint             *y,
                                                    gint             *push_in,
                                                    gpointer          user_data);
309

310 311
static void     gtk_combo_box_unset_model          (GtkComboBox      *combo_box);

312 313 314 315 316 317 318 319 320 321
static void     gtk_combo_box_size_allocate        (GtkWidget        *widget,
                                                    GtkAllocation    *allocation);
static void     gtk_combo_box_forall               (GtkContainer     *container,
                                                    gboolean          include_internals,
                                                    GtkCallback       callback,
                                                    gpointer          callback_data);
static gboolean gtk_combo_box_draw                 (GtkWidget        *widget,
                                                    cairo_t          *cr);
static gboolean gtk_combo_box_scroll_event         (GtkWidget        *widget,
                                                    GdkEventScroll   *event);
322
static void     gtk_combo_box_set_active_internal  (GtkComboBox      *combo_box,
323
                                                    GtkTreePath      *path);
324

325
static void     gtk_combo_box_check_appearance     (GtkComboBox      *combo_box);
326 327 328 329
static void     gtk_combo_box_real_move_active     (GtkComboBox      *combo_box,
                                                    GtkScrollType     scroll);
static void     gtk_combo_box_real_popup           (GtkComboBox      *combo_box);
static gboolean gtk_combo_box_real_popdown         (GtkComboBox      *combo_box);
330

331 332
/* listening to the model */
static void     gtk_combo_box_model_row_inserted   (GtkTreeModel     *model,
333 334 335
                                                    GtkTreePath      *path,
                                                    GtkTreeIter      *iter,
                                                    gpointer          user_data);
336
static void     gtk_combo_box_model_row_deleted    (GtkTreeModel     *model,
337 338
                                                    GtkTreePath      *path,
                                                    gpointer          user_data);
339
static void     gtk_combo_box_model_rows_reordered (GtkTreeModel     *model,
340 341 342 343
                                                    GtkTreePath      *path,
                                                    GtkTreeIter      *iter,
                                                    gint             *new_order,
                                                    gpointer          user_data);
344
static void     gtk_combo_box_model_row_changed    (GtkTreeModel     *model,
345 346 347
                                                    GtkTreePath      *path,
                                                    GtkTreeIter      *iter,
                                                    gpointer          data);
348
static void     gtk_combo_box_model_row_expanded   (GtkTreeModel     *model,
349 350 351
                                                    GtkTreePath      *path,
                                                    GtkTreeIter      *iter,
                                                    gpointer          data);
352

353
/* list */
354 355 356 357 358
static void     gtk_combo_box_list_position        (GtkComboBox      *combo_box,
                                                    gint             *x,
                                                    gint             *y,
                                                    gint             *width,
                                                    gint             *height);
359 360 361 362 363 364 365 366 367
static void     gtk_combo_box_list_setup           (GtkComboBox      *combo_box);
static void     gtk_combo_box_list_destroy         (GtkComboBox      *combo_box);

static gboolean gtk_combo_box_list_button_released (GtkWidget        *widget,
                                                    GdkEventButton   *event,
                                                    gpointer          data);
static gboolean gtk_combo_box_list_key_press       (GtkWidget        *widget,
                                                    GdkEventKey      *event,
                                                    gpointer          data);
368 369 370 371
static gboolean gtk_combo_box_list_enter_notify    (GtkWidget        *widget,
                                                    GdkEventCrossing *event,
                                                    gpointer          data);
static void     gtk_combo_box_list_auto_scroll     (GtkComboBox   *combo,
372 373
                                                    gint           x,
                                                    gint           y);
374
static gboolean gtk_combo_box_list_scroll_timeout  (GtkComboBox   *combo);
375 376 377 378
static gboolean gtk_combo_box_list_button_pressed  (GtkWidget        *widget,
                                                    GdkEventButton   *event,
                                                    gpointer          data);

379
static gboolean gtk_combo_box_list_select_func     (GtkTreeSelection *selection,
380 381 382 383
                                                    GtkTreeModel     *model,
                                                    GtkTreePath      *path,
                                                    gboolean          path_currently_selected,
                                                    gpointer          data);
384

385 386 387 388
static void     gtk_combo_box_list_row_changed     (GtkTreeModel     *model,
                                                    GtkTreePath      *path,
                                                    GtkTreeIter      *iter,
                                                    gpointer          data);
389
static void     gtk_combo_box_list_popup_resize    (GtkComboBox      *combo_box);
390 391 392

/* menu */
static void     gtk_combo_box_menu_setup           (GtkComboBox      *combo_box,
393
                                                    gboolean          add_children);
394
static void     gtk_combo_box_update_title         (GtkComboBox      *combo_box);
395 396 397
static void     gtk_combo_box_menu_destroy         (GtkComboBox      *combo_box);


398 399 400
static gboolean gtk_combo_box_menu_button_press    (GtkWidget        *widget,
                                                    GdkEventButton   *event,
                                                    gpointer          user_data);
401
static void     gtk_combo_box_menu_activate        (GtkWidget        *menu,
402 403
                                                    const gchar      *path,
                                                    GtkComboBox      *combo_box);
404
static void     gtk_combo_box_update_sensitivity   (GtkComboBox      *combo_box);
405
static gboolean gtk_combo_box_menu_key_press       (GtkWidget        *widget,
406 407
                                                    GdkEventKey      *event,
                                                    gpointer          data);
408
static void     gtk_combo_box_menu_popup           (GtkComboBox      *combo_box,
409 410
                                                    guint             button,
                                                    guint32           activate_time);
411

412
/* cell layout */
413
static GtkCellArea *gtk_combo_box_cell_layout_get_area       (GtkCellLayout    *cell_layout);
414

415
static gboolean gtk_combo_box_mnemonic_activate              (GtkWidget    *widget,
416
                                                              gboolean      group_cycling);
417

418
static void     gtk_combo_box_child_show                     (GtkWidget       *widget,
419
                                                              GtkComboBox     *combo_box);
420
static void     gtk_combo_box_child_hide                     (GtkWidget       *widget,
421
                                                              GtkComboBox     *combo_box);
422

423 424
/* GtkComboBox:has-entry callbacks */
static void     gtk_combo_box_entry_contents_changed         (GtkEntry        *entry,
425
                                                              gpointer         user_data);
426
static void     gtk_combo_box_entry_active_changed           (GtkComboBox     *combo_box,
427
                                                              gpointer         user_data);
428 429
static gchar   *gtk_combo_box_format_entry_text              (GtkComboBox     *combo_box,
							      const gchar     *path);
430 431 432 433

/* GtkBuildable method implementation */
static GtkBuildableIface *parent_buildable_iface;

434 435
static void     gtk_combo_box_buildable_init                 (GtkBuildableIface *iface);
static gboolean gtk_combo_box_buildable_custom_tag_start     (GtkBuildable  *buildable,
436 437 438 439 440
                                                              GtkBuilder    *builder,
                                                              GObject       *child,
                                                              const gchar   *tagname,
                                                              GMarkupParser *parser,
                                                              gpointer      *data);
441
static void     gtk_combo_box_buildable_custom_tag_end       (GtkBuildable  *buildable,
442 443 444 445
                                                              GtkBuilder    *builder,
                                                              GObject       *child,
                                                              const gchar   *tagname,
                                                              gpointer      *data);
446
static GObject *gtk_combo_box_buildable_get_internal_child   (GtkBuildable *buildable,
447 448
                                                              GtkBuilder   *builder,
                                                              const gchar  *childname);
449

450 451

/* GtkCellEditable method implementations */
452
static void     gtk_combo_box_start_editing                  (GtkCellEditable *cell_editable,
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
                                                              GdkEvent        *event);

static void     gtk_combo_box_get_preferred_width            (GtkWidget    *widget,
                                                              gint         *minimum_size,
                                                              gint         *natural_size);
static void     gtk_combo_box_get_preferred_height           (GtkWidget    *widget,
                                                              gint         *minimum_size,
                                                              gint         *natural_size);
static void     gtk_combo_box_get_preferred_width_for_height (GtkWidget    *widget,
                                                              gint          avail_size,
                                                              gint         *minimum_size,
                                                              gint         *natural_size);
static void     gtk_combo_box_get_preferred_height_for_width (GtkWidget    *widget,
                                                              gint          avail_size,
                                                              gint         *minimum_size,
                                                              gint         *natural_size);
469 470 471 472
static GtkWidgetPath *gtk_combo_box_get_path_for_child       (GtkContainer *container,
                                                              GtkWidget    *child);
static void     gtk_combo_box_direction_changed              (GtkWidget    *widget,
                                                              GtkTextDirection  previous_direction);
473

474
G_DEFINE_TYPE_WITH_CODE (GtkComboBox, gtk_combo_box, GTK_TYPE_BIN,
475 476 477 478 479 480
                         G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
                                                gtk_combo_box_cell_layout_init)
                         G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
                                                gtk_combo_box_cell_editable_init)
                         G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
                                                gtk_combo_box_buildable_init))
481

482

483 484 485 486 487 488 489 490
/* common */
static void
gtk_combo_box_class_init (GtkComboBoxClass *klass)
{
  GObjectClass *object_class;
  GtkContainerClass *container_class;
  GtkWidgetClass *widget_class;
  GtkBindingSet *binding_set;
491

492 493 494 495
  container_class = (GtkContainerClass *)klass;
  container_class->forall = gtk_combo_box_forall;
  container_class->add = gtk_combo_box_add;
  container_class->remove = gtk_combo_box_remove;
496
  container_class->get_path_for_child = gtk_combo_box_get_path_for_child;
497

498 499
  gtk_container_class_handle_border_width (container_class);

500 501 502 503 504 505 506
  widget_class = (GtkWidgetClass *)klass;
  widget_class->size_allocate = gtk_combo_box_size_allocate;
  widget_class->draw = gtk_combo_box_draw;
  widget_class->scroll_event = gtk_combo_box_scroll_event;
  widget_class->mnemonic_activate = gtk_combo_box_mnemonic_activate;
  widget_class->grab_focus = gtk_combo_box_grab_focus;
  widget_class->style_updated = gtk_combo_box_style_updated;
507
  widget_class->state_flags_changed = gtk_combo_box_state_flags_changed;
508 509 510 511 512
  widget_class->get_preferred_width = gtk_combo_box_get_preferred_width;
  widget_class->get_preferred_height = gtk_combo_box_get_preferred_height;
  widget_class->get_preferred_height_for_width = gtk_combo_box_get_preferred_height_for_width;
  widget_class->get_preferred_width_for_height = gtk_combo_box_get_preferred_width_for_height;
  widget_class->destroy = gtk_combo_box_destroy;
513
  widget_class->direction_changed = gtk_combo_box_direction_changed;
514

515 516 517 518 519 520
  object_class = (GObjectClass *)klass;
  object_class->constructor = gtk_combo_box_constructor;
  object_class->dispose = gtk_combo_box_dispose;
  object_class->finalize = gtk_combo_box_finalize;
  object_class->set_property = gtk_combo_box_set_property;
  object_class->get_property = gtk_combo_box_get_property;
521

522 523
  klass->format_entry_text = gtk_combo_box_format_entry_text;

524 525 526
  /* signals */
  /**
   * GtkComboBox::changed:
Matthias Clasen's avatar
Matthias Clasen committed
527 528
   * @widget: the object which received the signal
   * 
529
   * The changed signal is emitted when the active
Matthias Clasen's avatar
Matthias Clasen committed
530
   * item is changed. The can be due to the user selecting
531
   * a different item from the list, or due to a
Matthias Clasen's avatar
Matthias Clasen committed
532
   * call to gtk_combo_box_set_active_iter().
533 534
   * It will also be emitted while typing into the entry of a combo box
   * with an entry.
Matthias Clasen's avatar
Matthias Clasen committed
535 536 537
   *
   * Since: 2.4
   */
538
  combo_box_signals[CHANGED] =
539
    g_signal_new (I_("changed"),
540 541 542 543 544 545
                  G_OBJECT_CLASS_TYPE (klass),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (GtkComboBoxClass, changed),
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE, 0);
546 547 548 549 550
  /**
   * GtkComboBox::move-active:
   * @widget: the object that received the signal
   * @scroll_type: a #GtkScrollType
   *
551
   * The ::move-active signal is a
552 553 554 555 556
   * <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted to move the active selection.
   *
   * Since: 2.12
   */
557
  combo_box_signals[MOVE_ACTIVE] =
558 559 560 561 562 563 564 565
    g_signal_new_class_handler (I_("move-active"),
                                G_OBJECT_CLASS_TYPE (klass),
                                G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                                G_CALLBACK (gtk_combo_box_real_move_active),
                                NULL, NULL,
                                g_cclosure_marshal_VOID__ENUM,
                                G_TYPE_NONE, 1,
                                GTK_TYPE_SCROLL_TYPE);
566

567 568 569 570
  /**
   * GtkComboBox::popup:
   * @widget: the object that received the signal
   *
571
   * The ::popup signal is a
572 573 574 575 576 577 578
   * <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted to popup the combo box list.
   *
   * The default binding for this signal is Alt+Down.
   *
   * Since: 2.12
   */
579
  combo_box_signals[POPUP] =
580 581 582 583 584 585 586
    g_signal_new_class_handler (I_("popup"),
                                G_OBJECT_CLASS_TYPE (klass),
                                G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                                G_CALLBACK (gtk_combo_box_real_popup),
                                NULL, NULL,
                                g_cclosure_marshal_VOID__VOID,
                                G_TYPE_NONE, 0);
587 588 589 590
  /**
   * GtkComboBox::popdown:
   * @button: the object which received the signal
   *
591 592
   * The ::popdown signal is a
   * <link linkend="keybinding-signals">keybinding signal</link>
593 594 595 596 597 598
   * which gets emitted to popdown the combo box list.
   *
   * The default bindings for this signal are Alt+Up and Escape.
   *
   * Since: 2.12
   */
599
  combo_box_signals[POPDOWN] =
600 601 602 603 604 605 606
    g_signal_new_class_handler (I_("popdown"),
                                G_OBJECT_CLASS_TYPE (klass),
                                G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                                G_CALLBACK (gtk_combo_box_real_popdown),
                                NULL, NULL,
                                _gtk_marshal_BOOLEAN__VOID,
                                G_TYPE_BOOLEAN, 0);
607

608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
  /**
   * GtkComboBox::format-entry-text:
   * @combo: the object which received the signal
   * @path: the GtkTreePath string from the combo box's current model to format text for
   *
   * For combo boxes that are created with an entry (See GtkComboBox:has-entry).
   *
   * A signal which allows you to change how the text displayed in a combo box's
   * entry is displayed.
   *
   * Connect a signal handler which returns an allocated string representing
   * @path. That string will then be used to set the text in the combo box's entry.
   * The default signal handler uses the text from the GtkComboBox::entry-text-column 
   * model column.
   *
   * Here's an example signal handler which fetches data from the model and
   * displays it in the entry.
   * |[
   * static gchar*
   * format_entry_text_callback (GtkComboBox *combo,
   *                             const gchar *path,
   *                             gpointer     user_data)
   * {
   *   GtkTreeIter iter;
   *   GtkTreeModel model;
   *   gdouble      value;
   *   
   *   model = gtk_combo_box_get_model (combo);
   *
   *   gtk_tree_model_get_iter_from_string (model, &iter, path);
   *   gtk_tree_model_get (model, &iter, 
   *                       THE_DOUBLE_VALUE_COLUMN, &value,
   *                       -1);
   *
   *   return g_strdup_printf ("&percnt;g", value);
   * }
   * ]|
   *
   * Return value: (transfer full): a newly allocated string representing @path 
   * for the current GtkComboBox model.
   *
   * Since: 3.4
   */
  combo_box_signals[FORMAT_ENTRY_TEXT] =
    g_signal_new (I_("format-entry-text"),
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (GtkComboBoxClass, format_entry_text),
                  _gtk_single_string_accumulator, NULL,
                  _gtk_marshal_STRING__STRING,
                  G_TYPE_STRING, 1, G_TYPE_STRING);

660 661 662
  /* key bindings */
  binding_set = gtk_binding_set_by_class (widget_class);

663
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Down, GDK_MOD1_MASK,
664
                                "popup", 0);
665
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Down, GDK_MOD1_MASK,
666
                                "popup", 0);
667

668
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, GDK_MOD1_MASK,
669
                                "popdown", 0);
670
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Up, GDK_MOD1_MASK,
671
                                "popdown", 0);
672
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0,
673
                                "popdown", 0);
674

675
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, 0,
676 677
                                "move-active", 1,
                                GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_UP);
678
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Up, 0,
679 680
                                "move-active", 1,
                                GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_UP);
681
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Page_Up, 0,
682 683
                                "move-active", 1,
                                GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_UP);
684
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Page_Up, 0,
685 686
                                "move-active", 1,
                                GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_UP);
687
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Home, 0,
688 689
                                "move-active", 1,
                                GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_START);
690
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Home, 0,
691 692
                                "move-active", 1,
                                GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_START);
693

694
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Down, 0,
695 696
                                "move-active", 1,
                                GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_DOWN);
697
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Down, 0,
698 699
                                "move-active", 1,
                                GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_DOWN);
700
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Page_Down, 0,
701 702
                                "move-active", 1,
                                GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_DOWN);
703
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Page_Down, 0,
704 705
                                "move-active", 1,
                                GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_DOWN);
706
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_End, 0,
707 708
                                "move-active", 1,
                                GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_END);
709
  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_End, 0,
710 711
                                "move-active", 1,
                                GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_END);
712

713
  /* properties */
714 715 716 717
  g_object_class_override_property (object_class,
                                    PROP_EDITING_CANCELED,
                                    "editing-canceled");

Matthias Clasen's avatar
Matthias Clasen committed
718 719 720 721
  /**
   * GtkComboBox:model:
   *
   * The model from which the combo box takes the values shown
722
   * in the list.
Matthias Clasen's avatar
Matthias Clasen committed
723 724 725
   *
   * Since: 2.4
   */
726 727 728
  g_object_class_install_property (object_class,
                                   PROP_MODEL,
                                   g_param_spec_object ("model",
729 730
                                                        P_("ComboBox model"),
                                                        P_("The model for the combo box"),
731
                                                        GTK_TYPE_TREE_MODEL,
732
                                                        GTK_PARAM_READWRITE));
733

Matthias Clasen's avatar
Matthias Clasen committed
734 735 736 737 738 739 740 741 742
  /**
   * GtkComboBox:wrap-width:
   *
   * If wrap-width is set to a positive value, the list will be
   * displayed in multiple columns, the number of columns is
   * determined by wrap-width.
   *
   * Since: 2.4
   */
743 744
  g_object_class_install_property (object_class,
                                   PROP_WRAP_WIDTH,
745
                                   g_param_spec_int ("wrap-width",
746
                                                     P_("Wrap width"),
747
                                                     P_("Wrap width for laying out the items in a grid"),
748 749 750
                                                     0,
                                                     G_MAXINT,
                                                     0,
751
                                                     GTK_PARAM_READWRITE));
752

Matthias Clasen's avatar
Matthias Clasen committed
753 754 755 756

  /**
   * GtkComboBox:row-span-column:
   *
757 758
   * If this is set to a non-negative value, it must be the index of a column
   * of type %G_TYPE_INT in the model.
Matthias Clasen's avatar
Matthias Clasen committed
759
   *
760 761
   * The values of that column are used to determine how many rows a value in
   * the list will span. Therefore, the values in the model column pointed to
Matthias Clasen's avatar
Matthias Clasen committed
762
   * by this property must be greater than zero and not larger than wrap-width.
Matthias Clasen's avatar
Matthias Clasen committed
763 764 765
   *
   * Since: 2.4
   */
766 767
  g_object_class_install_property (object_class,
                                   PROP_ROW_SPAN_COLUMN,
768
                                   g_param_spec_int ("row-span-column",
769 770
                                                     P_("Row span column"),
                                                     P_("TreeModel column containing the row span values"),
771
                                                     -1,
772
                                                     G_MAXINT,
773
                                                     -1,
774
                                                     GTK_PARAM_READWRITE));
775

Matthias Clasen's avatar
Matthias Clasen committed
776 777 778 779

  /**
   * GtkComboBox:column-span-column:
   *
780 781
   * If this is set to a non-negative value, it must be the index of a column
   * of type %G_TYPE_INT in the model.
Matthias Clasen's avatar
Matthias Clasen committed
782
   *
783 784
   * The values of that column are used to determine how many columns a value
   * in the list will span.
Matthias Clasen's avatar
Matthias Clasen committed
785 786 787
   *
   * Since: 2.4
   */
788 789
  g_object_class_install_property (object_class,
                                   PROP_COLUMN_SPAN_COLUMN,
790
                                   g_param_spec_int ("column-span-column",
791 792
                                                     P_("Column span column"),
                                                     P_("TreeModel column containing the column span values"),
793
                                                     -1,
794
                                                     G_MAXINT,
795
                                                     -1,
796
                                                     GTK_PARAM_READWRITE));
797

798

Matthias Clasen's avatar
Matthias Clasen committed
799 800 801 802 803
  /**
   * GtkComboBox:active:
   *
   * The item which is currently active. If the model is a non-flat treemodel,
   * and the active item is not an immediate child of the root of the tree,
804
   * this property has the value
805
   * <literal>gtk_tree_path_get_indices (path)[0]</literal>,
Matthias Clasen's avatar
Matthias Clasen committed
806 807 808 809
   * where <literal>path</literal> is the #GtkTreePath of the active item.
   *
   * Since: 2.4
   */
810 811 812
  g_object_class_install_property (object_class,
                                   PROP_ACTIVE,
                                   g_param_spec_int ("active",
813 814
                                                     P_("Active item"),
                                                     P_("The item which is currently active"),
815
                                                     -1,
816
                                                     G_MAXINT,
817
                                                     -1,
818
                                                     GTK_PARAM_READWRITE));
819

820 821 822
  /**
   * GtkComboBox:add-tearoffs:
   *
823 824
   * The add-tearoffs property controls whether generated menus
   * have tearoff menu items.
825 826 827 828 829 830 831
   *
   * Note that this only affects menu style combo boxes.
   *
   * Since: 2.6
   */
  g_object_class_install_property (object_class,
                                   PROP_ADD_TEAROFFS,
832 833 834 835 836 837
                                   g_param_spec_boolean ("add-tearoffs",
                                                         P_("Add tearoffs to menus"),
                                                         P_("Whether dropdowns should have a tearoff menu item"),
                                                         FALSE,
                                                         GTK_PARAM_READWRITE));

838 839 840
  /**
   * GtkComboBox:has-frame:
   *
Matthias Clasen's avatar
Matthias Clasen committed
841
   * The has-frame property controls whether a frame
842 843 844 845 846 847
   * is drawn around the entry.
   *
   * Since: 2.6
   */
  g_object_class_install_property (object_class,
                                   PROP_HAS_FRAME,
848 849 850 851 852 853
                                   g_param_spec_boolean ("has-frame",
                                                         P_("Has Frame"),
                                                         P_("Whether the combo box draws a frame around the child"),
                                                         TRUE,
                                                         GTK_PARAM_READWRITE));

Matthias Clasen's avatar
Matthias Clasen committed
854 855
  g_object_class_install_property (object_class,
                                   PROP_FOCUS_ON_CLICK,
856
                                   g_param_spec_boolean ("focus-on-click",
857 858 859 860
                                                         P_("Focus on click"),
                                                         P_("Whether the combo box grabs focus when it is clicked with the mouse"),
                                                         TRUE,
                                                         GTK_PARAM_READWRITE));
Matthias Clasen's avatar
Matthias Clasen committed
861

862 863 864
  /**
   * GtkComboBox:tearoff-title:
   *
865
   * A title that may be displayed by the window manager
866 867 868 869 870 871 872 873 874
   * when the popup is torn-off.
   *
   * Since: 2.10
   */
  g_object_class_install_property (object_class,
                                   PROP_TEAROFF_TITLE,
                                   g_param_spec_string ("tearoff-title",
                                                        P_("Tearoff Title"),
                                                        P_("A title that may be displayed by the window manager when the popup is torn-off"),
875
                                                        NULL,
876 877 878
                                                        GTK_PARAM_READWRITE));


879 880 881
  /**
   * GtkComboBox:popup-shown:
   *
882
   * Whether the combo boxes dropdown is popped up.
883 884 885 886 887 888 889 890 891 892 893 894
   * Note that this property is mainly useful, because
   * it allows you to connect to notify::popup-shown.
   *
   * Since: 2.10
   */
  g_object_class_install_property (object_class,
                                   PROP_POPUP_SHOWN,
                                   g_param_spec_boolean ("popup-shown",
                                                         P_("Popup shown"),
                                                         P_("Whether the combo's dropdown is shown"),
                                                         FALSE,
                                                         GTK_PARAM_READABLE));
895

896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913

   /**
    * GtkComboBox:button-sensitivity:
    *
    * Whether the dropdown button is sensitive when
    * the model is empty.
    *
    * Since: 2.14
    */
   g_object_class_install_property (object_class,
                                    PROP_BUTTON_SENSITIVITY,
                                    g_param_spec_enum ("button-sensitivity",
                                                       P_("Button Sensitivity"),
                                                       P_("Whether the dropdown button is sensitive when the model is empty"),
                                                       GTK_TYPE_SENSITIVITY_TYPE,
                                                       GTK_SENSITIVITY_AUTO,
                                                       GTK_PARAM_READWRITE));

914 915 916 917 918
   /**
    * GtkComboBox:has-entry:
    *
    * Whether the combo box has an entry.
    *
919
    * Since: 2.24
920 921 922 923
    */
   g_object_class_install_property (object_class,
                                    PROP_HAS_ENTRY,
                                    g_param_spec_boolean ("has-entry",
924 925 926 927
                                                          P_("Has Entry"),
                                                          P_("Whether combo box has an entry"),
                                                          FALSE,
                                                          GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
928 929 930 931 932 933 934

   /**
    * GtkComboBox:entry-text-column:
    *
    * The column in the combo box's model to associate with strings from the entry
    * if the combo was created with #GtkComboBox:has-entry = %TRUE.
    *
935
    * Since: 2.24
936 937 938 939
    */
   g_object_class_install_property (object_class,
                                    PROP_ENTRY_TEXT_COLUMN,
                                    g_param_spec_int ("entry-text-column",
940 941 942 943 944 945
                                                      P_("Entry Text Column"),
                                                      P_("The column in the combo box's model to associate "
                                                         "with strings from the entry if the combo was "
                                                         "created with #GtkComboBox:has-entry = %TRUE"),
                                                      -1, G_MAXINT, -1,
                                                      GTK_PARAM_READWRITE));
946

947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978
   /**
    * GtkComboBox:id-column:
    *
    * The column in the combo box's model that provides string
    * IDs for the values in the model, if != -1.
    *
    * Since: 3.0
    */
   g_object_class_install_property (object_class,
                                    PROP_ID_COLUMN,
                                    g_param_spec_int ("id-column",
                                                      P_("ID Column"),
                                                      P_("The column in the combo box's model that provides "
                                                      "string IDs for the values in the model"),
                                                      -1, G_MAXINT, -1,
                                                      GTK_PARAM_READWRITE));

   /**
    * GtkComboBox:active-id:
    *
    * The value of the ID column of the active row.
    *
    * Since: 3.0
    */
   g_object_class_install_property (object_class,
                                    PROP_ACTIVE_ID,
                                    g_param_spec_string ("active-id",
                                                         P_("Active id"),
                                                         P_("The value of the id column "
                                                         "for the active row"),
                                                         NULL, GTK_PARAM_READWRITE));

979 980 981 982 983 984 985 986 987 988 989
   /**
    * GtkComboBox:popup-fixed-width:
    *
    * Whether the popup's width should be a fixed width matching the
    * allocated width of the combo box.
    *
    * Since: 3.0
    */
   g_object_class_install_property (object_class,
                                    PROP_POPUP_FIXED_WIDTH,
                                    g_param_spec_boolean ("popup-fixed-width",
990 991 992 993 994 995
                                                          P_("Popup Fixed Width"),
                                                          P_("Whether the popup's width should be a "
                                                             "fixed width matching the allocated width "
                                                             "of the combo box"),
                                                          TRUE,
                                                          GTK_PARAM_READWRITE));
996

997 998 999 1000 1001
   /**
    * GtkComboBox:cell-area:
    *
    * The #GtkCellArea used to layout cell renderers for this combo box.
    *
1002 1003 1004
    * If no area is specified when creating the combo box with gtk_combo_box_new_with_area() 
    * a horizontally oriented #GtkCellAreaBox will be used.
    *
1005 1006 1007 1008 1009
    * Since: 3.0
    */
   g_object_class_install_property (object_class,
                                    PROP_CELL_AREA,
                                    g_param_spec_object ("cell-area",
1010 1011 1012 1013
                                                         P_("Cell Area"),
                                                         P_("The GtkCellArea used to layout cells"),
                                                         GTK_TYPE_CELL_AREA,
                                                         GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
1014

1015
  gtk_widget_class_install_style_property (widget_class,
1016 1017
                                           g_param_spec_boolean ("appears-as-list",
                                                                 P_("Appears as list"),
1018
                                                                 P_("Whether dropdowns should look like lists rather than menus"),
1019
                                                                 FALSE,
1020
                                                                 GTK_PARAM_READABLE));
1021

1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032
  /**
   * GtkComboBox:arrow-size:
   *
   * Sets the minimum size of the arrow in the combo box.  Note
   * that the arrow size is coupled to the font size, so in case
   * a larger font is used, the arrow will be larger than set
   * by arrow size.
   *
   * Since: 2.12
   */
  gtk_widget_class_install_style_property (widget_class,
1033 1034 1035 1036 1037 1038 1039
                                           g_param_spec_int ("arrow-size",
                                                             P_("Arrow Size"),
                                                             P_("The minimum size of the arrow in the combo box"),
                                                             0,
                                                             G_MAXINT,
                                                             15,
                                                             GTK_PARAM_READABLE));
1040

1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057
  /**
   * GtkComboBox:arrow-scaling:
   *
   * Sets the amount of space used up by the combobox arrow,
   * proportional to the font size.
   *
   * Since: 3.2
   */
  gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_float ("arrow-scaling",
                                                               P_("Arrow Scaling"),
                                                               P_("The amount of space used by the arrow"),
                                                             0,
                                                             2.0,
                                                             1.0,
                                                             GTK_PARAM_READABLE));

1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
  /**
   * GtkComboBox:shadow-type:
   *
   * Which kind of shadow to draw around the combo box.
   *
   * Since: 2.12
   */
  gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_enum ("shadow-type",
                                                              P_("Shadow type"),
                                                              P_("Which kind of shadow to draw around the combo box"),
                                                              GTK_TYPE_SHADOW_TYPE,
                                                              GTK_SHADOW_NONE,
                                                              GTK_PARAM_READABLE));

1073
  g_type_class_add_private (object_class, sizeof (GtkComboBoxPrivate));
1074 1075

  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_COMBO_BOX_ACCESSIBLE);
1076 1077
}

1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
static void
gtk_combo_box_buildable_init (GtkBuildableIface *iface)
{
  parent_buildable_iface = g_type_interface_peek_parent (iface);
  iface->add_child = _gtk_cell_layout_buildable_add_child;
  iface->custom_tag_start = gtk_combo_box_buildable_custom_tag_start;
  iface->custom_tag_end = gtk_combo_box_buildable_custom_tag_end;
  iface->get_internal_child = gtk_combo_box_buildable_get_internal_child;
}

static void
gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface)
{
  iface->get_area = gtk_combo_box_cell_layout_get_area;
}

static void
gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface)
{
  iface->start_editing = gtk_combo_box_start_editing;
}

1100 1101 1102
static void
gtk_combo_box_init (GtkComboBox *combo_box)
{
1103 1104 1105 1106 1107 1108
  GtkComboBoxPrivate *priv;

  combo_box->priv = G_TYPE_INSTANCE_GET_PRIVATE (combo_box,
                                                 GTK_TYPE_COMBO_BOX,
                                                 GtkComboBoxPrivate);
  priv = combo_box->priv;
1109

1110
  priv->wrap_width = 0;
1111

1112
  priv->active = -1;
1113 1114 1115
  priv->active_row = NULL;
  priv->col_column = -1;
  priv->row_column = -1;
1116

1117 1118 1119 1120 1121 1122 1123
  priv->popup_shown = FALSE;
  priv->add_tearoffs = FALSE;
  priv->has_frame = TRUE;
  priv->is_cell_renderer = FALSE;
  priv->editing_canceled = FALSE;
  priv->auto_scroll = FALSE;
  priv->focus_on_click = TRUE;
1124
  priv->button_sensitivity = GTK_SENSITIVITY_AUTO;
1125
  priv->has_entry = FALSE;
1126
  priv->popup_fixed_width = TRUE;
1127 1128 1129

  priv->text_column = -1;
  priv->text_renderer = NULL;
1130
  priv->id_column = -1;
1131 1132
}

1133 1134 1135 1136 1137
static void
gtk_combo_box_set_property (GObject      *object,
                            guint         prop_id,
                            const GValue *value,
                            GParamSpec   *pspec)
1138
{
1139
  GtkComboBox *combo_box = GTK_COMBO_BOX (object);
1140
  GtkComboBoxPrivate *priv = combo_box->priv;
1141
  GtkCellArea *area;
1142

1143
  switch (prop_id)
1144
    {
1145 1146 1147
    case PROP_MODEL:
      gtk_combo_box_set_model (combo_box, g_value_get_object (value));
      break;
1148

1149 1150 1151
    case PROP_WRAP_WIDTH:
      gtk_combo_box_set_wrap_width (combo_box, g_value_get_int (value));
      break;
1152

1153 1154 1155
    case PROP_ROW_SPAN_COLUMN:
      gtk_combo_box_set_row_span_column (combo_box, g_value_get_int (value));
      break;
1156

1157 1158 1159
    case PROP_COLUMN_SPAN_COLUMN:
      gtk_combo_box_set_column_span_column (combo_box, g_value_get_int (value));
      break;
1160

1161 1162 1163
    case PROP_ACTIVE:
      gtk_combo_box_set_active (combo_box, g_value_get_int (value));
      break;
1164

1165 1166 1167
    case PROP_ADD_TEAROFFS:
      gtk_combo_box_set_add_tearoffs (combo_box, g_value_get_boolean (value));
      break;
1168

1169
    case PROP_HAS_FRAME:
1170
      priv->has_frame = g_value_get_boolean (value);
1171

1172
      if (priv->has_entry)
1173 1174
        {
          GtkWidget *child;
1175

1176
          child = gtk_bin_get_child (GTK_BIN (combo_box));
1177

1178
          gtk_entry_set_has_frame (GTK_ENTRY (child), priv->has_frame);
1179
        }
1180

1181
      break;
1182

1183 1184 1185 1186
    case PROP_FOCUS_ON_CLICK:
      gtk_combo_box_set_focus_on_click (combo_box,
                                        g_value_get_boolean (value));
      break;
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203

    case PROP_TEAROFF_TITLE:
      gtk_combo_box_set_title (combo_box, g_value_get_string (value));
      break;

    case PROP_POPUP_SHOWN:
      if (g_value_get_boolean (value))
        gtk_combo_box_popup (combo_box);
      else
        gtk_combo_box_popdown (combo_box);
      break;

    case PROP_BUTTON_SENSITIVITY:
      gtk_combo_box_set_button_sensitivity (combo_box,
                                            g_value_get_enum (value));
      break;

1204 1205
    case PROP_POPUP_FIXED_WIDTH:
      gtk_combo_box_set_popup_fixed_width (combo_box,
1206
                                           g_value_get_boolean (value));
1207 1208
      break;

1209
    case PROP_EDITING_CANCELED:
1210
      priv->editing_canceled = g_value_get_boolean (value);
1211 1212
      break;

1213
    case PROP_HAS_ENTRY:
1214
      priv->has_entry = g_value_get_boolean (value);
1215 1216 1217 1218 1219 1220
      break;

    case PROP_ENTRY_TEXT_COLUMN:
      gtk_combo_box_set_entry_text_column (combo_box, g_value_get_int (value));
      break;

1221 1222 1223 1224 1225 1226 1227 1228
    case PROP_ID_COLUMN:
      gtk_combo_box_set_id_column (combo_box, g_value_get_int (value));
      break;

    case PROP_ACTIVE_ID:
      gtk_combo_box_set_active_id (combo_box, g_value_get_string (value));
      break;

1229 1230 1231 1232
    case PROP_CELL_AREA:
      /* Construct-only, can only be assigned once */
      area = g_value_get_object (value);
      if (area)
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242
        {
          if (priv->area != NULL)
            {
              g_warning ("cell-area has already been set, ignoring construct property");
              g_object_ref_sink (area);
              g_object_unref (area);
            }
          else
            priv->area = g_object_ref_sink (area);
        }
1243 1244
      break;

1245 1246 1247
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
1248 1249 1250 1251 1252 1253 1254 1255 1256 1257
    }
}

static void
gtk_combo_box_get_property (GObject    *object,
                            guint       prop_id,
                            GValue     *value,
                            GParamSpec *pspec)
{
  GtkComboBox *combo_box = GTK_COMBO_BOX (object);
1258
  GtkComboBoxPrivate *priv = combo_box->priv;
1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281

  switch (prop_id)
    {
      case PROP_MODEL:
        g_value_set_object (value, combo_box->priv->model);
        break;

      case PROP_WRAP_WIDTH:
        g_value_set_int (value, combo_box->priv->wrap_width);
        break;

      case PROP_ROW_SPAN_COLUMN:
        g_value_set_int (value, combo_box->priv->row_column);
        break;

      case PROP_COLUMN_SPAN_COLUMN:
        g_value_set_int (value, combo_box->priv->col_column);
        break;

      case PROP_ACTIVE:
        g_value_set_int (value, gtk_combo_box_get_active (combo_box));
        break;

1282 1283 1284 1285
      case PROP_ADD_TEAROFFS:
        g_value_set_boolean (value, gtk_combo_box_get_add_tearoffs (combo_box));
        break;

1286 1287 1288 1289
      case PROP_HAS_FRAME:
        g_value_set_boolean (value, combo_box->priv->has_frame);
        break;

Matthias Clasen's avatar
Matthias Clasen committed
1290 1291 1292 1293
      case PROP_FOCUS_ON_CLICK:
        g_value_set_boolean (value, combo_box->priv->focus_on_click);
        break;

1294 1295 1296 1297
      case PROP_TEAROFF_TITLE:
        g_value_set_string (value, gtk_combo_box_get_title (combo_box));
        break;

1298 1299 1300 1301
      case PROP_POPUP_SHOWN:
        g_value_set_boolean (value, combo_box->priv->popup_shown);
        break;

1302 1303 1304 1305
      case PROP_BUTTON_SENSITIVITY:
        g_value_set_enum (value, combo_box->priv->button_sensitivity);
        break;

1306 1307 1308 1309
      case PROP_POPUP_FIXED_WIDTH:
        g_value_set_boolean (value, combo_box->priv->popup_fixed_width);
        break;

1310 1311 1312 1313
      case PROP_EDITING_CANCELED:
        g_value_set_boolean (value, priv->editing_canceled);
        break;

1314
      case PROP_HAS_ENTRY:
1315 1316
        g_value_set_boolean (value, priv->has_entry);
        break;
1317 1318

      case PROP_ENTRY_TEXT_COLUMN:
1319 1320
        g_value_set_int (value, priv->text_column);
        break;
1321

1322 1323 1324 1325 1326 1327 1328 1329
      case PROP_ID_COLUMN:
        g_value_set_int (value, priv->id_column);
        break;

      case PROP_ACTIVE_ID:
        g_value_set_string (value, gtk_combo_box_get_active_id (combo_box));
        break;

1330
      case PROP_CELL_AREA:
1331 1332
        g_value_set_object (value, priv->area);
        break;
1333

1334 1335 1336 1337 1338 1339
      default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        break;
    }
}

1340
static void
1341 1342
gtk_combo_box_state_flags_changed (GtkWidget     *widget,
                                   GtkStateFlags  previous)
1343 1344
{
  GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
1345
  GtkComboBoxPrivate *priv = combo_box->priv;
1346

1347
  if (gtk_widget_get_realized (widget))
1348
    {
1349 1350 1351 1352
      if (priv->tree_view && priv->cell_view)
        {
          GtkStyleContext *context;
          GtkStateFlags state;
1353
          GdkRGBA color;
1354

1355 1356
          context  = gtk_widget_get_style_context (widget);
          state = gtk_widget_get_state_flags (widget);
1357
          gtk_style_context_get_background_color (context, state, &color);
1358

1359
          gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view), &color);
1360
        }
1361 1362
    }

1363 1364
  gtk_widget_queue_draw (widget);
}
1365

1366 1367 1368 1369 1370 1371 1372 1373 1374
static void
gtk_combo_box_button_state_flags_changed (GtkWidget     *widget,
                                          GtkStateFlags  previous,
                                          gpointer       data)
{
  GtkComboBox *combo_box = GTK_COMBO_BOX (data);
  GtkComboBoxPrivate *priv = combo_box->priv;

  if (gtk_widget_get_realized (widget))
1375
    {
1376 1377 1378 1379
      if (!priv->tree_view && priv->cell_view)
        gtk_widget_set_state_flags (priv->cell_view,
                                    gtk_widget_get_state_flags (widget),
                                    TRUE);
1380 1381
    }

1382
  gtk_widget_queue_draw (widget);
1383
}
1384

1385 1386 1387 1388 1389 1390
static void
gtk_combo_box_invalidate_order_foreach (GtkWidget *widget)
{
  _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_POSITION | GTK_CSS_CHANGE_SIBLING_POSITION);
}

1391 1392 1393 1394
static void
gtk_combo_box_invalidate_order (GtkComboBox *combo_box)
{
  gtk_container_forall (GTK_CONTAINER (combo_box),
1395
                        (GtkCallback) gtk_combo_box_invalidate_order_foreach,
1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417
                        NULL);
}

static void
gtk_combo_box_direction_changed (GtkWidget        *widget,
                                 GtkTextDirection  previous_direction)
{
  gtk_combo_box_invalidate_order (GTK_COMBO_BOX (widget));
}

static GtkWidgetPath *
gtk_combo_box_get_path_for_child (GtkContainer *container,
                                  GtkWidget    *child)
{
  GtkComboBoxPrivate *priv = GTK_COMBO_BOX (container)->priv;
  GtkWidgetPath *path;
  GtkWidget *widget;
  gboolean found = FALSE;
  GList *visible_children, *l;
  GtkWidgetPath *sibling_path;
  int pos;

1418
  path = _gtk_widget_create_path (GTK_WIDGET (container));
1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472

  if (gtk_widget_get_visible (child))
    {
      visible_children = NULL;

      if (priv->button && gtk_widget_get_visible (priv->button))
        visible_children = g_list_prepend (visible_children, priv->button);

      if (priv->cell_view_frame && gtk_widget_get_visible (priv->cell_view_frame))
        visible_children = g_list_prepend (visible_children, priv->cell_view_frame);

      widget = gtk_bin_get_child (GTK_BIN (container));
      if (widget && gtk_widget_get_visible (widget))
        visible_children = g_list_prepend (visible_children, widget);

      if (gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL)
        visible_children = g_list_reverse (visible_children);

      pos = 0;

      for (l = visible_children; l; l = l->next)
        {
          widget = l->data;

          if (widget == child)
            {
              found = TRUE;
              break;
            }

          pos++;
        }
    }

  if (found)
    {
      sibling_path = gtk_widget_path_new ();

      for (l = visible_children; l; l = l->next)
        gtk_widget_path_append_for_widget (sibling_path, l->data);

      gtk_widget_path_append_with_siblings (path, sibling_path, pos);

      g_list_free (visible_children);
      gtk_widget_path_unref (sibling_path);
    }
  else
    {
      gtk_widget_path_append_for_widget (path, child);
    }

  return path;
}

1473 1474
static void
gtk_combo_box_check_appearance (GtkComboBox *combo_box)
1475
{
1476 1477 1478 1479 1480
  GtkComboBoxPrivate *priv = combo_box->priv;
  gboolean appears_as_list;

  /* if wrap_width > 0, then we are in grid-mode and forced to use
   * unix style
1481
   */
1482 1483 1484 1485
  if (priv->wrap_width)
    appears_as_list = FALSE;
  else
    gtk_widget_style_get (GTK_WIDGET (combo_box),
1486 1487
                          "appears-as-list", &appears_as_list,
                          NULL);
1488 1489 1490 1491 1492
  
  if (appears_as_list)
    {
      /* Destroy all the menu mode widgets, if they exist. */
      if (GTK_IS_MENU (priv->popup_widget))
1493
        gtk_combo_box_menu_destroy (combo_box);
1494 1495 1496

      /* Create the list mode widgets, if they don't already exist. */
      if (!GTK_IS_TREE_VIEW (priv->tree_view))
1497
        gtk_combo_box_list_setup (combo_box);
1498 1499 1500 1501 1502
    }
  else
    {
      /* Destroy all the list mode widgets, if they exist. */
      if (GTK_IS_TREE_VIEW (priv->tree_view))
1503
        gtk_combo_box_list_destroy (combo_box);
1504 1505 1506

      /* Create the menu mode widgets, if they don't already exist. */
      if (!GTK_IS_MENU (priv->popup_widget))