2003-09-26 21:57:06 +00:00
|
|
|
/* gtkcombobox.c
|
|
|
|
* Copyright (C) 2002, 2003 Kristian Rietveld <kris@gtk.org>
|
|
|
|
*
|
2003-10-24 18:36:55 +00:00
|
|
|
* 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.
|
2003-09-26 21:57:06 +00:00
|
|
|
*
|
2003-10-24 18:36:55 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2003-09-26 21:57:06 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2003-10-24 18:36:55 +00:00
|
|
|
* Library General Public License for more details.
|
2003-09-26 21:57:06 +00:00
|
|
|
*
|
2003-10-24 18:36:55 +00:00
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2003-09-26 21:57:06 +00:00
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2004-03-06 03:38:59 +00:00
|
|
|
#include <config.h>
|
2003-10-23 18:25:53 +00:00
|
|
|
#include "gtkcombobox.h"
|
2004-02-29 00:08:04 +00:00
|
|
|
|
|
|
|
#include "gtkarrow.h"
|
|
|
|
#include "gtkbindings.h"
|
2003-10-23 18:25:53 +00:00
|
|
|
#include "gtkcelllayout.h"
|
2004-02-29 00:08:04 +00:00
|
|
|
#include "gtkcellrenderertext.h"
|
2003-10-23 18:25:53 +00:00
|
|
|
#include "gtkcellview.h"
|
2004-02-29 00:08:04 +00:00
|
|
|
#include "gtkeventbox.h"
|
2003-10-23 18:25:53 +00:00
|
|
|
#include "gtkframe.h"
|
2004-04-14 20:26:26 +00:00
|
|
|
#include "gtkhbox.h"
|
2004-02-29 00:08:04 +00:00
|
|
|
#include "gtkliststore.h"
|
|
|
|
#include "gtkmain.h"
|
|
|
|
#include "gtkmenu.h"
|
2004-07-07 15:15:35 +00:00
|
|
|
#include "gtkseparatormenuitem.h"
|
2004-05-10 14:07:35 +00:00
|
|
|
#include "gtktearoffmenuitem.h"
|
2003-10-23 18:25:53 +00:00
|
|
|
#include "gtktogglebutton.h"
|
2004-02-29 00:08:04 +00:00
|
|
|
#include "gtktreeselection.h"
|
2003-10-23 18:25:53 +00:00
|
|
|
#include "gtkvseparator.h"
|
|
|
|
#include "gtkwindow.h"
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
|
|
|
|
#include <gobject/gvaluecollector.h>
|
|
|
|
|
2003-10-23 18:25:53 +00:00
|
|
|
#include <string.h>
|
2003-09-26 21:57:06 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "gtkmarshalers.h"
|
|
|
|
#include "gtkintl.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* WELCOME, to THE house of evil code */
|
|
|
|
|
|
|
|
typedef struct _ComboCellInfo ComboCellInfo;
|
|
|
|
struct _ComboCellInfo
|
|
|
|
{
|
|
|
|
GtkCellRenderer *cell;
|
|
|
|
GSList *attributes;
|
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
GtkCellLayoutDataFunc func;
|
|
|
|
gpointer func_data;
|
|
|
|
GDestroyNotify destroy;
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
guint expand : 1;
|
|
|
|
guint pack : 1;
|
|
|
|
};
|
|
|
|
|
2003-10-11 23:12:20 +00:00
|
|
|
#define GTK_COMBO_BOX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_COMBO_BOX, GtkComboBoxPrivate))
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
struct _GtkComboBoxPrivate
|
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
|
|
|
gint col_column;
|
|
|
|
gint row_column;
|
2004-07-07 15:15:35 +00:00
|
|
|
gint separator_column;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
gint wrap_width;
|
|
|
|
|
|
|
|
gint active_item;
|
|
|
|
|
|
|
|
GtkWidget *tree_view;
|
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
|
|
|
|
GtkWidget *cell_view;
|
|
|
|
GtkWidget *cell_view_frame;
|
|
|
|
|
|
|
|
GtkWidget *button;
|
2004-04-14 20:26:26 +00:00
|
|
|
GtkWidget *box;
|
2003-09-26 21:57:06 +00:00
|
|
|
GtkWidget *arrow;
|
|
|
|
GtkWidget *separator;
|
|
|
|
|
|
|
|
GtkWidget *popup_widget;
|
|
|
|
GtkWidget *popup_window;
|
|
|
|
GtkWidget *popup_frame;
|
|
|
|
|
|
|
|
guint inserted_id;
|
|
|
|
guint deleted_id;
|
2004-03-02 18:56:10 +00:00
|
|
|
guint reordered_id;
|
|
|
|
guint changed_id;
|
2004-07-16 20:27:40 +00:00
|
|
|
guint popup_idle_id;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
gint width;
|
|
|
|
GSList *cells;
|
|
|
|
|
|
|
|
guint popup_in_progress : 1;
|
2004-03-13 00:36:27 +00:00
|
|
|
guint destroying : 1;
|
2004-05-10 14:07:35 +00:00
|
|
|
guint add_tearoffs : 1;
|
2004-07-16 20:27:40 +00:00
|
|
|
guint has_frame : 1;
|
|
|
|
guint is_cell_renderer : 1;
|
|
|
|
guint editing_canceled : 1;
|
2003-09-26 21:57:06 +00:00
|
|
|
};
|
|
|
|
|
2004-02-24 23:12:57 +00:00
|
|
|
/* 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
|
|
|
|
* popup_frame -> NULL
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* popup_frame -> NULL
|
|
|
|
*
|
|
|
|
* 3) list mode, no child added
|
|
|
|
*
|
|
|
|
* tree_view -> GtkTreeView, child of popup_frame
|
|
|
|
* 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
|
|
|
|
* popup_frame -> GtkFrame, child of popup_window
|
|
|
|
*
|
|
|
|
* 4) list mode, child added
|
|
|
|
*
|
|
|
|
* tree_view -> GtkTreeView, child of popup_frame
|
|
|
|
* 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
|
|
|
|
* popup_frame -> GtkFrame, child of popup_window
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
enum {
|
|
|
|
CHANGED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_MODEL,
|
|
|
|
PROP_WRAP_WIDTH,
|
|
|
|
PROP_ROW_SPAN_COLUMN,
|
|
|
|
PROP_COLUMN_SPAN_COLUMN,
|
2004-07-07 15:15:35 +00:00
|
|
|
PROP_ROW_SEPARATOR_COLUMN,
|
2004-05-10 14:07:35 +00:00
|
|
|
PROP_ACTIVE,
|
2004-07-16 20:27:40 +00:00
|
|
|
PROP_ADD_TEAROFFS,
|
|
|
|
PROP_HAS_FRAME
|
2003-09-26 21:57:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static GtkBinClass *parent_class = NULL;
|
|
|
|
static guint combo_box_signals[LAST_SIGNAL] = {0,};
|
|
|
|
|
|
|
|
#define BONUS_PADDING 4
|
|
|
|
|
|
|
|
|
|
|
|
/* common */
|
|
|
|
static void gtk_combo_box_class_init (GtkComboBoxClass *klass);
|
2003-10-01 20:51:54 +00:00
|
|
|
static void gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface);
|
2004-07-16 20:27:40 +00:00
|
|
|
static void gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface);
|
2003-09-26 21:57:06 +00:00
|
|
|
static void gtk_combo_box_init (GtkComboBox *combo_box);
|
2004-02-24 00:07:15 +00:00
|
|
|
static void gtk_combo_box_finalize (GObject *object);
|
|
|
|
static void gtk_combo_box_destroy (GtkObject *object);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2004-03-04 20:43:41 +00:00
|
|
|
static void gtk_combo_box_state_changed (GtkWidget *widget,
|
|
|
|
GtkStateType previous);
|
2003-09-26 21:57:06 +00:00
|
|
|
static void gtk_combo_box_style_set (GtkWidget *widget,
|
2004-02-29 00:08:04 +00:00
|
|
|
GtkStyle *previous);
|
2003-09-26 21:57:06 +00:00
|
|
|
static void gtk_combo_box_button_toggled (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static void gtk_combo_box_add (GtkContainer *container,
|
|
|
|
GtkWidget *widget);
|
2004-03-13 00:36:27 +00:00
|
|
|
static void gtk_combo_box_remove (GtkContainer *container,
|
|
|
|
GtkWidget *widget);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
static ComboCellInfo *gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
|
|
|
|
GtkCellRenderer *cell);
|
|
|
|
|
|
|
|
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);
|
2004-03-03 22:30:36 +00:00
|
|
|
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);
|
2003-09-26 21:57:06 +00:00
|
|
|
static void gtk_combo_box_menu_position (GtkMenu *menu,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gint *push_in,
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
static gint gtk_combo_box_calc_requested_width (GtkComboBox *combo_box,
|
|
|
|
GtkTreePath *path);
|
Fixes based on comments from Owen Taylor, #125264.
Tue Nov 18 19:47:59 2003 Kristian Rietveld <kris@gtk.org>
Fixes based on comments from Owen Taylor, #125264.
* gtk/gtkcellview.[ch] (gtk_cell_view_finalize): remove unused
variable,
(gtk_cell_view_set_value), (gtk_cell_view_set_displayed_model): queue
a resize,
(gtk_cell_view_get_size_of_row): new function,
(gtk_cell_view_set_value), (gtk_cell_view_set_valuesv),
(gtk_cell_view_set_values), (gtk_cell_view_set_model),
(gtk_cell_view_set_displayed_row), (gtk_cell_view_get_displayed_row):
s/cellview/cell_view/ in the function definitions, so they match
with the header file.
* gtk/gtkcombobox.c (gtk_combo_box_remeasure): remove the resize
flag again (:, and use gtk_cell_view_get_size_of_row instead of
the measurer, remove _set_size_request call,
(gtk_combo_box_calc_requested_width): use gtk_cell_view_get_size_of_row
instead of the measurer,
(gtk_combo_box_style_set): queue a resize,
(gtk_combo_box_size_request): update of _remeasure call,
(gtk_combo_box_init), (gtk_combo_box_cell_layout_pack_start),
(gtk_combo_box_cell_layout_pack_end),
(gtk_combo_box_cell_layout_clear),
(gtk_combo_box_set_model): get rid of the measurer,
(gtk_combo_box_cell_layout_add_attribute),
(gtk_combo_box_cell_layout_set_cell_data_func),
(gtk_combo_box_cell_layout_clear_attributes): ditto and queue a
resize instead of calling _remeasure.
2003-11-18 19:02:30 +00:00
|
|
|
static void gtk_combo_box_remeasure (GtkComboBox *combo_box);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
static void gtk_combo_box_unset_model (GtkComboBox *combo_box);
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
static void gtk_combo_box_size_request (GtkWidget *widget,
|
|
|
|
GtkRequisition *requisition);
|
|
|
|
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_expose_event (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event);
|
2003-11-17 22:24:57 +00:00
|
|
|
static gboolean gtk_combo_box_scroll_event (GtkWidget *widget,
|
|
|
|
GdkEventScroll *event);
|
2004-03-03 22:30:36 +00:00
|
|
|
static void gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
|
|
|
|
gint index);
|
2004-03-04 23:35:31 +00:00
|
|
|
static gboolean gtk_combo_box_key_press (GtkWidget *widget,
|
|
|
|
GdkEventKey *event,
|
|
|
|
gpointer data);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
static void gtk_combo_box_check_appearance (GtkComboBox *combo_box);
|
|
|
|
|
2004-03-02 18:56:10 +00:00
|
|
|
/* listening to the model */
|
|
|
|
static void gtk_combo_box_model_row_inserted (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data);
|
|
|
|
static void gtk_combo_box_model_row_deleted (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
gpointer user_data);
|
|
|
|
static void gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gint *new_order,
|
|
|
|
gpointer user_data);
|
|
|
|
static void gtk_combo_box_model_row_changed (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data);
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
/* list */
|
2004-02-29 01:33:01 +00:00
|
|
|
static void gtk_combo_box_list_position (GtkComboBox *combo_box,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gint *width,
|
|
|
|
gint *height);
|
2003-09-26 21:57:06 +00:00
|
|
|
static void gtk_combo_box_list_setup (GtkComboBox *combo_box);
|
|
|
|
static void gtk_combo_box_list_destroy (GtkComboBox *combo_box);
|
|
|
|
|
2004-02-27 01:38:16 +00:00
|
|
|
static void gtk_combo_box_list_remove_grabs (GtkComboBox *combo_box);
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
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);
|
|
|
|
static gboolean gtk_combo_box_list_button_pressed (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static void gtk_combo_box_list_row_changed (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
/* menu */
|
|
|
|
static void gtk_combo_box_menu_setup (GtkComboBox *combo_box,
|
2004-03-08 18:39:44 +00:00
|
|
|
gboolean add_children);
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
static void gtk_combo_box_menu_fill (GtkComboBox *combo_box);
|
2003-09-26 21:57:06 +00:00
|
|
|
static void gtk_combo_box_menu_destroy (GtkComboBox *combo_box);
|
|
|
|
|
|
|
|
static void gtk_combo_box_item_get_size (GtkComboBox *combo_box,
|
|
|
|
gint index,
|
|
|
|
gint *cols,
|
|
|
|
gint *rows);
|
|
|
|
static void gtk_combo_box_relayout_item (GtkComboBox *combo_box,
|
|
|
|
gint index);
|
|
|
|
static void gtk_combo_box_relayout (GtkComboBox *combo_box);
|
|
|
|
|
|
|
|
static gboolean gtk_combo_box_menu_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer user_data);
|
|
|
|
static void gtk_combo_box_menu_item_activate (GtkWidget *item,
|
|
|
|
gpointer user_data);
|
|
|
|
static void gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data);
|
|
|
|
static void gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
gpointer user_data);
|
2004-03-02 18:56:10 +00:00
|
|
|
static void gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gint *new_order,
|
|
|
|
gpointer user_data);
|
2003-09-26 21:57:06 +00:00
|
|
|
static void gtk_combo_box_menu_row_changed (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data);
|
2004-03-04 23:35:31 +00:00
|
|
|
static gboolean gtk_combo_box_menu_key_press (GtkWidget *widget,
|
|
|
|
GdkEventKey *event,
|
|
|
|
gpointer data);
|
2004-04-14 20:26:26 +00:00
|
|
|
static void gtk_combo_box_menu_state_changed (GtkWidget *widget,
|
|
|
|
GtkStateType previous,
|
|
|
|
gpointer data);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
/* cell layout */
|
|
|
|
static void gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
gboolean expand);
|
|
|
|
static void gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
gboolean expand);
|
|
|
|
static void gtk_combo_box_cell_layout_clear (GtkCellLayout *layout);
|
|
|
|
static void gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
const gchar *attribute,
|
|
|
|
gint column);
|
|
|
|
static void gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkCellLayoutDataFunc func,
|
|
|
|
gpointer func_data,
|
|
|
|
GDestroyNotify destroy);
|
|
|
|
static void gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
|
|
|
|
GtkCellRenderer *cell);
|
2003-12-19 22:47:20 +00:00
|
|
|
static void gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
gint position);
|
2004-02-05 20:35:57 +00:00
|
|
|
static gboolean gtk_combo_box_mnemonic_activate (GtkWidget *widget,
|
|
|
|
gboolean group_cycling);
|
2003-10-01 20:51:54 +00:00
|
|
|
|
2004-03-14 16:02:33 +00:00
|
|
|
static void cell_view_sync_cells (GtkComboBox *combo_box,
|
|
|
|
GtkCellView *cell_view);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
/* GtkCellEditable method implementations */
|
|
|
|
static void gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
|
|
|
|
GdkEvent *event);
|
|
|
|
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
GType
|
|
|
|
gtk_combo_box_get_type (void)
|
|
|
|
{
|
|
|
|
static GType combo_box_type = 0;
|
|
|
|
|
|
|
|
if (!combo_box_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo combo_box_info =
|
|
|
|
{
|
|
|
|
sizeof (GtkComboBoxClass),
|
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
(GClassInitFunc) gtk_combo_box_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GtkComboBox),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gtk_combo_box_init
|
|
|
|
};
|
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
static const GInterfaceInfo cell_layout_info =
|
|
|
|
{
|
|
|
|
(GInterfaceInitFunc) gtk_combo_box_cell_layout_init,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
static const GInterfaceInfo cell_editable_info =
|
|
|
|
{
|
|
|
|
(GInterfaceInitFunc) gtk_combo_box_cell_editable_init,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
combo_box_type = g_type_register_static (GTK_TYPE_BIN,
|
|
|
|
"GtkComboBox",
|
|
|
|
&combo_box_info,
|
|
|
|
0);
|
2003-10-01 20:51:54 +00:00
|
|
|
|
|
|
|
g_type_add_interface_static (combo_box_type,
|
|
|
|
GTK_TYPE_CELL_LAYOUT,
|
|
|
|
&cell_layout_info);
|
2004-07-16 20:27:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
g_type_add_interface_static (combo_box_type,
|
|
|
|
GTK_TYPE_CELL_EDITABLE,
|
|
|
|
&cell_editable_info);
|
|
|
|
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return combo_box_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* common */
|
|
|
|
static void
|
|
|
|
gtk_combo_box_class_init (GtkComboBoxClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
|
|
|
GtkBindingSet *binding_set;
|
2004-02-24 00:07:15 +00:00
|
|
|
GtkObjectClass *gtk_object_class;
|
2003-09-26 21:57:06 +00:00
|
|
|
GtkContainerClass *container_class;
|
|
|
|
GtkWidgetClass *widget_class;
|
|
|
|
|
|
|
|
binding_set = gtk_binding_set_by_class (klass);
|
|
|
|
|
|
|
|
container_class = (GtkContainerClass *)klass;
|
|
|
|
container_class->forall = gtk_combo_box_forall;
|
|
|
|
container_class->add = gtk_combo_box_add;
|
2004-03-13 00:36:27 +00:00
|
|
|
container_class->remove = gtk_combo_box_remove;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
widget_class = (GtkWidgetClass *)klass;
|
|
|
|
widget_class->size_allocate = gtk_combo_box_size_allocate;
|
|
|
|
widget_class->size_request = gtk_combo_box_size_request;
|
|
|
|
widget_class->expose_event = gtk_combo_box_expose_event;
|
2003-11-17 22:24:57 +00:00
|
|
|
widget_class->scroll_event = gtk_combo_box_scroll_event;
|
2004-02-05 20:35:57 +00:00
|
|
|
widget_class->mnemonic_activate = gtk_combo_box_mnemonic_activate;
|
2004-02-28 22:28:37 +00:00
|
|
|
widget_class->style_set = gtk_combo_box_style_set;
|
2004-03-04 20:43:41 +00:00
|
|
|
widget_class->state_changed = gtk_combo_box_state_changed;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-02-24 00:07:15 +00:00
|
|
|
gtk_object_class = (GtkObjectClass *)klass;
|
|
|
|
gtk_object_class->destroy = gtk_combo_box_destroy;
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
object_class = (GObjectClass *)klass;
|
2004-02-05 23:45:21 +00:00
|
|
|
object_class->finalize = gtk_combo_box_finalize;
|
2003-09-26 21:57:06 +00:00
|
|
|
object_class->set_property = gtk_combo_box_set_property;
|
|
|
|
object_class->get_property = gtk_combo_box_get_property;
|
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
|
|
|
/* signals */
|
|
|
|
combo_box_signals[CHANGED] =
|
|
|
|
g_signal_new ("changed",
|
|
|
|
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);
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_MODEL,
|
|
|
|
g_param_spec_object ("model",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("ComboBox model"),
|
|
|
|
P_("The model for the combo box"),
|
2003-09-26 21:57:06 +00:00
|
|
|
GTK_TYPE_TREE_MODEL,
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
G_PARAM_READWRITE));
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_WRAP_WIDTH,
|
|
|
|
g_param_spec_int ("wrap_width",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("Wrap width"),
|
|
|
|
P_("Wrap width for layouting the items in a grid"),
|
2003-09-26 21:57:06 +00:00
|
|
|
0,
|
|
|
|
G_MAXINT,
|
|
|
|
0,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_ROW_SPAN_COLUMN,
|
|
|
|
g_param_spec_int ("row_span_column",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("Row span column"),
|
|
|
|
P_("TreeModel column containing the row span values"),
|
2004-07-07 15:15:35 +00:00
|
|
|
-1,
|
2003-09-26 21:57:06 +00:00
|
|
|
G_MAXINT,
|
2004-07-07 15:15:35 +00:00
|
|
|
-1,
|
2003-09-26 21:57:06 +00:00
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_COLUMN_SPAN_COLUMN,
|
|
|
|
g_param_spec_int ("column_span_column",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("Column span column"),
|
|
|
|
P_("TreeModel column containing the column span values"),
|
2004-07-07 15:15:35 +00:00
|
|
|
-1,
|
2003-09-26 21:57:06 +00:00
|
|
|
G_MAXINT,
|
2004-07-07 15:15:35 +00:00
|
|
|
-1,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_ROW_SEPARATOR_COLUMN,
|
|
|
|
g_param_spec_int ("row_separator_column",
|
|
|
|
P_("Row separator column"),
|
|
|
|
P_("Boolean TreeModel column specifying which rows are separators"),
|
|
|
|
-1,
|
|
|
|
G_MAXINT,
|
|
|
|
-1,
|
2003-09-26 21:57:06 +00:00
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_ACTIVE,
|
|
|
|
g_param_spec_int ("active",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("Active item"),
|
|
|
|
P_("The item which is currently active"),
|
2004-06-04 00:57:03 +00:00
|
|
|
-1,
|
2003-09-26 21:57:06 +00:00
|
|
|
G_MAXINT,
|
2004-06-04 00:57:03 +00:00
|
|
|
-1,
|
2003-09-26 21:57:06 +00:00
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2004-05-10 14:07:35 +00:00
|
|
|
/**
|
|
|
|
* GtkComboBox:add-tearoffs:
|
|
|
|
*
|
|
|
|
* The "add-tearoffs" property controls whether generated menus
|
|
|
|
* have tearoff menu items.
|
|
|
|
*
|
|
|
|
* Note that this only affects menu style combo boxes.
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_ADD_TEAROFFS,
|
|
|
|
g_param_spec_boolean ("add-tearoffs",
|
|
|
|
P_("Add tearoffs to menus"),
|
2004-07-16 20:27:40 +00:00
|
|
|
P_("Whether dropdowns should have a tearoff menu item"),
|
2004-05-10 14:07:35 +00:00
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
/**
|
|
|
|
* GtkComboBox:has-frame:
|
|
|
|
*
|
|
|
|
* The :has-frame property controls whether a frame
|
|
|
|
* is drawn around the entry.
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_HAS_FRAME,
|
|
|
|
g_param_spec_boolean ("has-frame",
|
|
|
|
P_("Has Frame"),
|
|
|
|
P_("Whether the combo box draws a frame around the child"),
|
|
|
|
TRUE,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_widget_class_install_style_property (widget_class,
|
2004-03-02 20:42:14 +00:00
|
|
|
g_param_spec_boolean ("appears-as-list",
|
|
|
|
P_("Appears as list"),
|
2004-07-16 20:27:40 +00:00
|
|
|
P_("Whether dropdowns should look like lists rather than menus"),
|
2003-09-26 21:57:06 +00:00
|
|
|
FALSE,
|
2004-04-14 21:34:29 +00:00
|
|
|
G_PARAM_READABLE));
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
g_type_class_add_private (object_class, sizeof (GtkComboBoxPrivate));
|
|
|
|
}
|
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface)
|
|
|
|
{
|
|
|
|
iface->pack_start = gtk_combo_box_cell_layout_pack_start;
|
|
|
|
iface->pack_end = gtk_combo_box_cell_layout_pack_end;
|
|
|
|
iface->clear = gtk_combo_box_cell_layout_clear;
|
|
|
|
iface->add_attribute = gtk_combo_box_cell_layout_add_attribute;
|
|
|
|
iface->set_cell_data_func = gtk_combo_box_cell_layout_set_cell_data_func;
|
|
|
|
iface->clear_attributes = gtk_combo_box_cell_layout_clear_attributes;
|
2003-12-19 22:47:20 +00:00
|
|
|
iface->reorder = gtk_combo_box_cell_layout_reorder;
|
2003-10-01 20:51:54 +00:00
|
|
|
}
|
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface)
|
|
|
|
{
|
|
|
|
iface->start_editing = gtk_combo_box_start_editing;
|
|
|
|
}
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_init (GtkComboBox *combo_box)
|
|
|
|
{
|
|
|
|
combo_box->priv = GTK_COMBO_BOX_GET_PRIVATE (combo_box);
|
|
|
|
|
|
|
|
combo_box->priv->cell_view = gtk_cell_view_new ();
|
2004-03-13 00:36:27 +00:00
|
|
|
gtk_widget_set_parent (combo_box->priv->cell_view, GTK_WIDGET (combo_box));
|
|
|
|
GTK_BIN (combo_box)->child = combo_box->priv->cell_view;
|
2003-09-30 19:11:55 +00:00
|
|
|
gtk_widget_show (combo_box->priv->cell_view);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
combo_box->priv->width = 0;
|
|
|
|
combo_box->priv->wrap_width = 0;
|
|
|
|
|
|
|
|
combo_box->priv->active_item = -1;
|
|
|
|
combo_box->priv->col_column = -1;
|
|
|
|
combo_box->priv->row_column = -1;
|
2004-07-07 15:15:35 +00:00
|
|
|
combo_box->priv->separator_column = -1;
|
2004-07-16 20:27:40 +00:00
|
|
|
|
|
|
|
combo_box->priv->add_tearoffs = FALSE;
|
|
|
|
combo_box->priv->has_frame = TRUE;
|
|
|
|
combo_box->priv->is_cell_renderer = FALSE;
|
|
|
|
combo_box->priv->editing_canceled = FALSE;
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_MODEL:
|
|
|
|
gtk_combo_box_set_model (combo_box, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_WRAP_WIDTH:
|
|
|
|
gtk_combo_box_set_wrap_width (combo_box, g_value_get_int (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ROW_SPAN_COLUMN:
|
|
|
|
gtk_combo_box_set_row_span_column (combo_box, g_value_get_int (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_COLUMN_SPAN_COLUMN:
|
|
|
|
gtk_combo_box_set_column_span_column (combo_box, g_value_get_int (value));
|
|
|
|
break;
|
|
|
|
|
2004-07-07 15:15:35 +00:00
|
|
|
case PROP_ROW_SEPARATOR_COLUMN:
|
|
|
|
gtk_combo_box_set_row_separator_column (combo_box, g_value_get_int (value));
|
|
|
|
break;
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
case PROP_ACTIVE:
|
|
|
|
gtk_combo_box_set_active (combo_box, g_value_get_int (value));
|
|
|
|
break;
|
|
|
|
|
2004-05-10 14:07:35 +00:00
|
|
|
case PROP_ADD_TEAROFFS:
|
|
|
|
gtk_combo_box_set_add_tearoffs (combo_box, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
case PROP_HAS_FRAME:
|
|
|
|
combo_box->priv->has_frame = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (object);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2004-07-07 15:15:35 +00:00
|
|
|
case PROP_ROW_SEPARATOR_COLUMN:
|
|
|
|
g_value_set_int (value, combo_box->priv->separator_column);
|
|
|
|
break;
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
case PROP_ACTIVE:
|
|
|
|
g_value_set_int (value, gtk_combo_box_get_active (combo_box));
|
|
|
|
break;
|
|
|
|
|
2004-05-10 14:07:35 +00:00
|
|
|
case PROP_ADD_TEAROFFS:
|
|
|
|
g_value_set_boolean (value, gtk_combo_box_get_add_tearoffs (combo_box));
|
|
|
|
break;
|
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
case PROP_HAS_FRAME:
|
|
|
|
g_value_set_boolean (value, combo_box->priv->has_frame);
|
|
|
|
break;
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-04 20:43:41 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_state_changed (GtkWidget *widget,
|
|
|
|
GtkStateType previous)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
|
|
|
|
|
|
|
|
if (GTK_WIDGET_REALIZED (widget))
|
|
|
|
{
|
|
|
|
if (combo_box->priv->tree_view && combo_box->priv->cell_view)
|
|
|
|
gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
|
|
|
|
&widget->style->base[GTK_WIDGET_STATE (widget)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_queue_draw (widget);
|
|
|
|
}
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
static void
|
2004-03-08 18:39:44 +00:00
|
|
|
gtk_combo_box_check_appearance (GtkComboBox *combo_box)
|
2003-09-26 21:57:06 +00:00
|
|
|
{
|
2004-03-07 01:37:06 +00:00
|
|
|
gboolean appears_as_list;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
/* if wrap_width > 0, then we are in grid-mode and forced to use
|
|
|
|
* unix style
|
|
|
|
*/
|
|
|
|
if (combo_box->priv->wrap_width)
|
2004-03-08 18:39:44 +00:00
|
|
|
appears_as_list = FALSE;
|
|
|
|
else
|
|
|
|
gtk_widget_style_get (GTK_WIDGET (combo_box),
|
|
|
|
"appears-as-list", &appears_as_list,
|
|
|
|
NULL);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-03-07 01:37:06 +00:00
|
|
|
if (appears_as_list)
|
2003-09-26 21:57:06 +00:00
|
|
|
{
|
2004-02-27 20:41:14 +00:00
|
|
|
/* Destroy all the menu mode widgets, if they exist. */
|
2003-09-26 21:57:06 +00:00
|
|
|
if (GTK_IS_MENU (combo_box->priv->popup_widget))
|
2004-02-27 20:41:14 +00:00
|
|
|
gtk_combo_box_menu_destroy (combo_box);
|
|
|
|
|
|
|
|
/* Create the list mode widgets, if they don't already exist. */
|
|
|
|
if (!GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
|
|
|
|
gtk_combo_box_list_setup (combo_box);
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-02-27 20:41:14 +00:00
|
|
|
/* Destroy all the list mode widgets, if they exist. */
|
2003-09-26 21:57:06 +00:00
|
|
|
if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
|
2004-02-27 20:41:14 +00:00
|
|
|
gtk_combo_box_list_destroy (combo_box);
|
|
|
|
|
|
|
|
/* Create the menu mode widgets, if they don't already exist. */
|
|
|
|
if (!GTK_IS_MENU (combo_box->priv->popup_widget))
|
|
|
|
gtk_combo_box_menu_setup (combo_box, TRUE);
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
2004-03-08 18:39:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_style_set (GtkWidget *widget,
|
|
|
|
GtkStyle *previous)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
|
|
|
|
|
|
|
|
gtk_combo_box_check_appearance (combo_box);
|
2004-03-04 20:43:41 +00:00
|
|
|
|
|
|
|
if (combo_box->priv->tree_view && combo_box->priv->cell_view)
|
|
|
|
gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
|
|
|
|
&widget->style->base[GTK_WIDGET_STATE (widget)]);
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_button_toggled (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (data);
|
|
|
|
|
|
|
|
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
|
|
|
|
{
|
|
|
|
if (!combo_box->priv->popup_in_progress)
|
|
|
|
gtk_combo_box_popup (combo_box);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gtk_combo_box_popdown (combo_box);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_add (GtkContainer *container,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (container);
|
|
|
|
|
|
|
|
if (combo_box->priv->cell_view && combo_box->priv->cell_view->parent)
|
2004-03-13 00:36:27 +00:00
|
|
|
{
|
|
|
|
gtk_widget_unparent (combo_box->priv->cell_view);
|
|
|
|
GTK_BIN (container)->child = NULL;
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (container));
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_set_parent (widget, GTK_WIDGET (container));
|
|
|
|
GTK_BIN (container)->child = widget;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
if (combo_box->priv->cell_view &&
|
|
|
|
widget != combo_box->priv->cell_view)
|
|
|
|
{
|
|
|
|
/* since the cell_view was unparented, it's gone now */
|
|
|
|
combo_box->priv->cell_view = NULL;
|
|
|
|
|
|
|
|
if (!combo_box->priv->tree_view && combo_box->priv->separator)
|
|
|
|
{
|
2004-04-14 20:26:26 +00:00
|
|
|
gtk_container_remove (GTK_CONTAINER (combo_box->priv->separator->parent),
|
|
|
|
combo_box->priv->separator);
|
2004-02-24 23:12:57 +00:00
|
|
|
combo_box->priv->separator = NULL;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (container));
|
|
|
|
}
|
|
|
|
else if (combo_box->priv->cell_view_frame)
|
|
|
|
{
|
|
|
|
gtk_widget_unparent (combo_box->priv->cell_view_frame);
|
|
|
|
combo_box->priv->cell_view_frame = NULL;
|
2004-07-16 20:27:40 +00:00
|
|
|
combo_box->priv->box = NULL;
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-13 00:36:27 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_remove (GtkContainer *container,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (container);
|
|
|
|
gboolean appears_as_list;
|
|
|
|
|
|
|
|
gtk_widget_unparent (widget);
|
|
|
|
GTK_BIN (container)->child = NULL;
|
|
|
|
|
|
|
|
if (combo_box->priv->destroying)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (container));
|
|
|
|
|
|
|
|
if (!combo_box->priv->tree_view)
|
|
|
|
appears_as_list = FALSE;
|
|
|
|
else
|
|
|
|
appears_as_list = TRUE;
|
|
|
|
|
|
|
|
if (appears_as_list)
|
|
|
|
gtk_combo_box_list_destroy (combo_box);
|
|
|
|
else if (GTK_IS_MENU (combo_box->priv->popup_widget))
|
|
|
|
{
|
|
|
|
gtk_combo_box_menu_destroy (combo_box);
|
|
|
|
gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
|
|
|
|
combo_box->priv->popup_widget = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!combo_box->priv->cell_view)
|
|
|
|
{
|
|
|
|
combo_box->priv->cell_view = gtk_cell_view_new ();
|
|
|
|
gtk_widget_set_parent (combo_box->priv->cell_view, GTK_WIDGET (container));
|
|
|
|
GTK_BIN (container)->child = combo_box->priv->cell_view;
|
|
|
|
|
|
|
|
gtk_widget_show (combo_box->priv->cell_view);
|
|
|
|
gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
|
|
|
|
combo_box->priv->model);
|
|
|
|
cell_view_sync_cells (combo_box, GTK_CELL_VIEW (combo_box->priv->cell_view));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (appears_as_list)
|
|
|
|
gtk_combo_box_list_setup (combo_box);
|
|
|
|
else
|
|
|
|
gtk_combo_box_menu_setup (combo_box, TRUE);
|
|
|
|
|
|
|
|
gtk_combo_box_set_active_internal (combo_box, combo_box->priv->active_item);
|
|
|
|
}
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
static ComboCellInfo *
|
|
|
|
gtk_combo_box_get_cell_info (GtkComboBox *combo_box,
|
|
|
|
GtkCellRenderer *cell)
|
|
|
|
{
|
|
|
|
GSList *i;
|
|
|
|
|
|
|
|
for (i = combo_box->priv->cells; i; i = i->next)
|
|
|
|
{
|
|
|
|
ComboCellInfo *info = (ComboCellInfo *)i->data;
|
|
|
|
|
2004-02-27 20:41:14 +00:00
|
|
|
if (info && info->cell == cell)
|
2003-09-26 21:57:06 +00:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_menu_show (GtkWidget *menu,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
|
|
|
2004-05-10 14:07:35 +00:00
|
|
|
combo_box->priv->popup_in_progress = TRUE;
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
|
|
|
|
TRUE);
|
2003-09-30 19:46:48 +00:00
|
|
|
combo_box->priv->popup_in_progress = FALSE;
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_menu_hide (GtkWidget *menu,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
|
|
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
|
2004-02-08 00:42:59 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_detacher (GtkWidget *widget,
|
|
|
|
GtkMenu *menu)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (widget));
|
|
|
|
|
|
|
|
combo_box = GTK_COMBO_BOX (widget);
|
|
|
|
g_return_if_fail (combo_box->priv->popup_widget == (GtkWidget*) menu);
|
|
|
|
|
2004-05-10 14:07:35 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (menu->toplevel,
|
2004-02-08 00:42:59 +00:00
|
|
|
gtk_combo_box_menu_show,
|
|
|
|
combo_box);
|
2004-05-10 14:07:35 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (menu->toplevel,
|
2004-02-08 00:42:59 +00:00
|
|
|
gtk_combo_box_menu_hide,
|
|
|
|
combo_box);
|
|
|
|
|
|
|
|
combo_box->priv->popup_widget = NULL;
|
|
|
|
}
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
|
|
|
|
GtkWidget *popup)
|
|
|
|
{
|
|
|
|
if (GTK_IS_MENU (combo_box->priv->popup_widget))
|
2004-02-08 00:42:59 +00:00
|
|
|
{
|
|
|
|
gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
|
|
|
|
combo_box->priv->popup_widget = NULL;
|
|
|
|
}
|
2003-09-26 21:57:06 +00:00
|
|
|
else if (combo_box->priv->popup_widget)
|
|
|
|
{
|
|
|
|
gtk_container_remove (GTK_CONTAINER (combo_box->priv->popup_frame),
|
|
|
|
combo_box->priv->popup_widget);
|
|
|
|
g_object_unref (G_OBJECT (combo_box->priv->popup_widget));
|
|
|
|
combo_box->priv->popup_widget = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GTK_IS_MENU (popup))
|
|
|
|
{
|
|
|
|
if (combo_box->priv->popup_window)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (combo_box->priv->popup_window);
|
2004-02-29 00:08:04 +00:00
|
|
|
combo_box->priv->popup_window = NULL;
|
|
|
|
combo_box->priv->popup_frame = NULL;
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
combo_box->priv->popup_widget = popup;
|
|
|
|
|
2004-05-10 14:07:35 +00:00
|
|
|
/*
|
|
|
|
* Note that we connect to show/hide on the toplevel, not the
|
|
|
|
* menu itself, since the menu is not shown/hidden when it is
|
|
|
|
* popped up while torn-off.
|
|
|
|
*/
|
|
|
|
g_signal_connect (GTK_MENU (popup)->toplevel, "show",
|
2003-09-26 21:57:06 +00:00
|
|
|
G_CALLBACK (gtk_combo_box_menu_show), combo_box);
|
2004-05-10 14:07:35 +00:00
|
|
|
g_signal_connect (GTK_MENU (popup)->toplevel, "hide",
|
2003-09-26 21:57:06 +00:00
|
|
|
G_CALLBACK (gtk_combo_box_menu_hide), combo_box);
|
|
|
|
|
2004-02-08 00:42:59 +00:00
|
|
|
gtk_menu_attach_to_widget (GTK_MENU (popup),
|
|
|
|
GTK_WIDGET (combo_box),
|
|
|
|
gtk_combo_box_detacher);
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!combo_box->priv->popup_window)
|
|
|
|
{
|
|
|
|
combo_box->priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
|
2004-02-29 00:08:04 +00:00
|
|
|
gtk_window_set_resizable (GTK_WINDOW (combo_box->priv->popup_window), FALSE);
|
2004-02-08 09:29:11 +00:00
|
|
|
gtk_window_set_screen (GTK_WINDOW (combo_box->priv->popup_window),
|
|
|
|
gtk_widget_get_screen (GTK_WIDGET (combo_box)));
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
combo_box->priv->popup_frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->popup_frame),
|
2004-03-02 18:53:55 +00:00
|
|
|
GTK_SHADOW_ETCHED_IN);
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (combo_box->priv->popup_window),
|
|
|
|
combo_box->priv->popup_frame);
|
2004-02-29 00:08:04 +00:00
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_widget_show (combo_box->priv->popup_frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (combo_box->priv->popup_frame),
|
|
|
|
popup);
|
|
|
|
gtk_widget_show (popup);
|
|
|
|
g_object_ref (G_OBJECT (popup));
|
|
|
|
combo_box->priv->popup_widget = popup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-03 22:30:36 +00:00
|
|
|
gtk_combo_box_menu_position_below (GtkMenu *menu,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gint *push_in,
|
|
|
|
gpointer user_data)
|
2003-09-26 21:57:06 +00:00
|
|
|
{
|
2004-05-10 18:17:47 +00:00
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
2003-09-26 21:57:06 +00:00
|
|
|
gint sx, sy;
|
|
|
|
GtkWidget *child;
|
|
|
|
GtkRequisition req;
|
2004-05-10 18:17:47 +00:00
|
|
|
GdkScreen *screen;
|
|
|
|
gint monitor_num;
|
|
|
|
GdkRectangle monitor;
|
2004-03-03 22:30:36 +00:00
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
/* FIXME: is using the size request here broken? */
|
2004-03-03 22:30:36 +00:00
|
|
|
child = GTK_BIN (combo_box)->child;
|
|
|
|
|
|
|
|
gdk_window_get_origin (child->window, &sx, &sy);
|
|
|
|
|
2004-05-10 18:17:47 +00:00
|
|
|
if (GTK_WIDGET_NO_WINDOW (child))
|
|
|
|
{
|
|
|
|
sx += child->allocation.x;
|
|
|
|
sy += child->allocation.y;
|
|
|
|
}
|
|
|
|
|
2004-03-03 22:30:36 +00:00
|
|
|
gtk_widget_size_request (GTK_WIDGET (menu), &req);
|
2004-05-10 18:17:47 +00:00
|
|
|
|
2004-03-10 00:20:19 +00:00
|
|
|
if (gtk_widget_get_direction (GTK_WIDGET (combo_box)) == GTK_TEXT_DIR_LTR)
|
2004-03-03 22:30:36 +00:00
|
|
|
*x = sx;
|
|
|
|
else
|
|
|
|
*x = sx + child->allocation.width - req.width;
|
2004-05-10 18:17:47 +00:00
|
|
|
*y = sy;
|
|
|
|
|
|
|
|
screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
|
|
|
|
monitor_num = gdk_screen_get_monitor_at_window (screen,
|
|
|
|
GTK_WIDGET (combo_box)->window);
|
|
|
|
gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
|
|
|
|
|
|
|
|
if (*x < monitor.x)
|
|
|
|
*x = monitor.x;
|
|
|
|
else if (*x + req.width > monitor.x + monitor.width)
|
|
|
|
*x = monitor.x + monitor.width - req.width;
|
|
|
|
|
2004-06-26 03:39:35 +00:00
|
|
|
if (monitor.y + monitor.height - *y - child->allocation.height >= req.height)
|
|
|
|
*y += child->allocation.height;
|
|
|
|
else if (*y - monitor.y >= req.height)
|
|
|
|
*y -= req.height;
|
|
|
|
else if (monitor.y + monitor.height - *y - child->allocation.height > *y - monitor.y)
|
2004-05-10 18:17:47 +00:00
|
|
|
*y += child->allocation.height;
|
|
|
|
else
|
|
|
|
*y -= req.height;
|
|
|
|
|
2004-06-26 03:39:35 +00:00
|
|
|
*push_in = FALSE;
|
2004-03-03 22:30:36 +00:00
|
|
|
}
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-03-03 22:30:36 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_menu_position_over (GtkMenu *menu,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gboolean *push_in,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box;
|
|
|
|
GtkWidget *active;
|
|
|
|
GtkWidget *child;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkRequisition requisition;
|
|
|
|
GList *children;
|
|
|
|
gint screen_width;
|
|
|
|
gint menu_xpos;
|
|
|
|
gint menu_ypos;
|
|
|
|
gint menu_width;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (user_data));
|
|
|
|
|
|
|
|
combo_box = GTK_COMBO_BOX (user_data);
|
|
|
|
widget = GTK_WIDGET (combo_box);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-03-03 22:30:36 +00:00
|
|
|
gtk_widget_get_child_requisition (GTK_WIDGET (menu), &requisition);
|
|
|
|
menu_width = requisition.width;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-03-03 22:30:36 +00:00
|
|
|
active = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
|
|
|
|
gdk_window_get_origin (widget->window, &menu_xpos, &menu_ypos);
|
|
|
|
|
|
|
|
menu_xpos += widget->allocation.x;
|
|
|
|
menu_ypos += widget->allocation.y + widget->allocation.height / 2 - 2;
|
|
|
|
|
|
|
|
if (active != NULL)
|
|
|
|
{
|
|
|
|
gtk_widget_get_child_requisition (active, &requisition);
|
|
|
|
menu_ypos -= requisition.height / 2;
|
|
|
|
}
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-03-03 22:30:36 +00:00
|
|
|
children = GTK_MENU_SHELL (combo_box->priv->popup_widget)->children;
|
|
|
|
while (children)
|
2003-09-26 21:57:06 +00:00
|
|
|
{
|
2004-03-03 22:30:36 +00:00
|
|
|
child = children->data;
|
|
|
|
|
|
|
|
if (active == child)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (GTK_WIDGET_VISIBLE (child))
|
|
|
|
{
|
|
|
|
gtk_widget_get_child_requisition (child, &requisition);
|
|
|
|
menu_ypos -= requisition.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
children = children->next;
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
2004-03-03 22:30:36 +00:00
|
|
|
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
|
|
|
menu_xpos = menu_xpos + widget->allocation.width - menu_width;
|
|
|
|
|
|
|
|
/* Clamp the position on screen */
|
|
|
|
screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget));
|
|
|
|
|
|
|
|
if (menu_xpos < 0)
|
|
|
|
menu_xpos = 0;
|
|
|
|
else if ((menu_xpos + menu_width) > screen_width)
|
|
|
|
menu_xpos -= ((menu_xpos + menu_width) - screen_width);
|
|
|
|
|
|
|
|
*x = menu_xpos;
|
|
|
|
*y = menu_ypos;
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
*push_in = TRUE;
|
|
|
|
}
|
|
|
|
|
2004-03-03 22:30:36 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_menu_position (GtkMenu *menu,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gint *push_in,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box;
|
2004-03-04 23:35:31 +00:00
|
|
|
GtkWidget *menu_item;
|
2004-03-03 22:30:36 +00:00
|
|
|
|
|
|
|
combo_box = GTK_COMBO_BOX (user_data);
|
|
|
|
|
|
|
|
if (combo_box->priv->wrap_width > 0 || combo_box->priv->cell_view == NULL)
|
|
|
|
gtk_combo_box_menu_position_below (menu, x, y, push_in, user_data);
|
|
|
|
else
|
2004-03-04 23:35:31 +00:00
|
|
|
{
|
|
|
|
menu_item = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
|
|
|
|
if (menu_item)
|
|
|
|
gtk_menu_shell_select_item (GTK_MENU_SHELL (combo_box->priv->popup_widget),
|
|
|
|
menu_item);
|
|
|
|
|
|
|
|
gtk_combo_box_menu_position_over (menu, x, y, push_in, user_data);
|
|
|
|
}
|
2004-03-03 22:30:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-02-29 01:33:01 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_list_position (GtkComboBox *combo_box,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gint *width,
|
|
|
|
gint *height)
|
|
|
|
{
|
|
|
|
GtkWidget *sample;
|
|
|
|
GdkScreen *screen;
|
|
|
|
gint monitor_num;
|
|
|
|
GdkRectangle monitor;
|
2004-03-02 18:53:55 +00:00
|
|
|
GtkRequisition popup_req;
|
2004-02-29 01:33:01 +00:00
|
|
|
|
|
|
|
sample = GTK_BIN (combo_box)->child;
|
|
|
|
|
|
|
|
*width = sample->allocation.width;
|
2004-03-02 18:53:55 +00:00
|
|
|
gtk_widget_size_request (combo_box->priv->popup_window, &popup_req);
|
|
|
|
*height = popup_req.height;
|
2004-02-29 01:33:01 +00:00
|
|
|
|
|
|
|
gdk_window_get_origin (sample->window, x, y);
|
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
if (combo_box->priv->cell_view_frame && combo_box->priv->has_frame)
|
2004-02-29 01:33:01 +00:00
|
|
|
{
|
|
|
|
*x -= GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
|
|
|
|
GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness;
|
|
|
|
*width += 2 * (GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
|
|
|
|
GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GTK_WIDGET_NO_WINDOW (sample))
|
|
|
|
{
|
|
|
|
*x += sample->allocation.x;
|
|
|
|
*y += sample->allocation.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
|
|
|
|
monitor_num = gdk_screen_get_monitor_at_window (screen,
|
|
|
|
GTK_WIDGET (combo_box)->window);
|
|
|
|
gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
|
|
|
|
|
|
|
|
if (*x < monitor.x)
|
|
|
|
*x = monitor.x;
|
|
|
|
else if (*x + *width > monitor.x + monitor.width)
|
|
|
|
*x = monitor.x + monitor.width - *width;
|
2004-03-02 18:53:55 +00:00
|
|
|
|
|
|
|
if (*y + sample->allocation.height + *height <= monitor.y + monitor.height)
|
|
|
|
*y += sample->allocation.height;
|
|
|
|
else
|
|
|
|
*y -= *height;
|
2004-02-29 01:33:01 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 03:31:17 +00:00
|
|
|
static gboolean
|
|
|
|
menu_row_is_sensitive (GtkComboBox *combo_box,
|
|
|
|
GtkWidget *item)
|
|
|
|
{
|
|
|
|
GtkWidget *cell_view;
|
|
|
|
GList *cells, *list;
|
|
|
|
gboolean sensitive;
|
2004-07-07 15:15:35 +00:00
|
|
|
|
2004-07-19 19:07:27 +00:00
|
|
|
if (!GTK_IS_CELL_VIEW (GTK_BIN (item)->child))
|
2004-07-07 15:15:35 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2004-05-27 03:31:17 +00:00
|
|
|
cell_view = gtk_bin_get_child (GTK_BIN (item));
|
|
|
|
|
|
|
|
gtk_cell_view_set_cell_data (GTK_CELL_VIEW (cell_view));
|
|
|
|
cells = gtk_cell_view_get_cell_renderers (GTK_CELL_VIEW (cell_view));
|
|
|
|
|
|
|
|
sensitive = FALSE;
|
|
|
|
list = cells;
|
|
|
|
while (list)
|
|
|
|
{
|
|
|
|
g_object_get (G_OBJECT (list->data), "sensitive", &sensitive, NULL);
|
|
|
|
|
|
|
|
if (sensitive)
|
|
|
|
break;
|
|
|
|
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
g_list_free (cells);
|
|
|
|
|
|
|
|
return sensitive;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
tree_column_row_is_sensitive (GtkComboBox *combo_box,
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
{
|
|
|
|
GList *cells, *list;
|
|
|
|
gboolean sensitive;
|
|
|
|
|
|
|
|
if (!combo_box->priv->column)
|
|
|
|
return TRUE;
|
|
|
|
|
2004-07-07 15:15:35 +00:00
|
|
|
if (combo_box->priv->separator_column != -1)
|
|
|
|
{
|
|
|
|
gboolean is_separator;
|
|
|
|
|
|
|
|
gtk_tree_model_get (combo_box->priv->model,
|
|
|
|
iter,
|
|
|
|
combo_box->priv->separator_column, &is_separator,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (is_separator)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-05-27 03:31:17 +00:00
|
|
|
gtk_tree_view_column_cell_set_cell_data (combo_box->priv->column,
|
|
|
|
combo_box->priv->model,
|
|
|
|
iter, FALSE, FALSE);
|
|
|
|
|
|
|
|
cells = gtk_tree_view_column_get_cell_renderers (combo_box->priv->column);
|
|
|
|
|
|
|
|
sensitive = FALSE;
|
|
|
|
list = cells;
|
|
|
|
while (list)
|
|
|
|
{
|
|
|
|
g_object_get (G_OBJECT (list->data), "sensitive", &sensitive, NULL);
|
|
|
|
|
|
|
|
if (sensitive)
|
|
|
|
break;
|
|
|
|
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
g_list_free (cells);
|
|
|
|
|
|
|
|
return sensitive;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
row_is_sensitive (GtkComboBox *combo_box,
|
|
|
|
gint index)
|
|
|
|
{
|
|
|
|
gboolean sensitive;
|
|
|
|
|
|
|
|
if (!combo_box->priv->model)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (GTK_IS_MENU (combo_box->priv->popup_widget))
|
|
|
|
{
|
|
|
|
GtkWidget *item;
|
|
|
|
GList *children, *child;
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (combo_box->priv->popup_widget));
|
|
|
|
child = children;
|
|
|
|
if (GTK_IS_TEAROFF_MENU_ITEM (child->data))
|
|
|
|
child = child->next;
|
|
|
|
child = g_list_nth (child, index);
|
|
|
|
item = GTK_WIDGET (child->data);
|
|
|
|
g_list_free (children);
|
|
|
|
|
|
|
|
sensitive = menu_row_is_sensitive (combo_box, item);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
path = gtk_tree_path_new_from_indices (index, -1);
|
|
|
|
if (gtk_tree_model_get_iter (combo_box->priv->model, &iter, path))
|
|
|
|
sensitive = tree_column_row_is_sensitive (combo_box, &iter);
|
|
|
|
else
|
|
|
|
sensitive = TRUE;
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return sensitive;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_menu_sensitivity (GtkComboBox *combo_box)
|
|
|
|
{
|
|
|
|
gint i, items;
|
|
|
|
GtkWidget *menu;
|
|
|
|
GList *children, *child;
|
|
|
|
|
|
|
|
if (!combo_box->priv->model)
|
|
|
|
return;
|
|
|
|
|
|
|
|
items = gtk_tree_model_iter_n_children (combo_box->priv->model, NULL);
|
|
|
|
menu = combo_box->priv->popup_widget;
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
|
|
child = children;
|
|
|
|
|
|
|
|
for (i = 0; i < items; i++, child = child->next)
|
|
|
|
{
|
|
|
|
GtkWidget *item = GTK_WIDGET (child->data);
|
|
|
|
gboolean sensitive;
|
|
|
|
|
2004-07-19 19:07:27 +00:00
|
|
|
if (!GTK_IS_CELL_VIEW (GTK_BIN (item)->child))
|
2004-07-07 15:15:35 +00:00
|
|
|
continue;
|
|
|
|
|
2004-05-27 03:31:17 +00:00
|
|
|
sensitive = menu_row_is_sensitive (combo_box, item);
|
|
|
|
gtk_widget_set_sensitive (item, sensitive);
|
|
|
|
}
|
|
|
|
g_list_free (children);
|
|
|
|
}
|
|
|
|
|
2004-02-15 23:05:48 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_popup:
|
|
|
|
* @combo_box: a #GtkComboBox
|
|
|
|
*
|
|
|
|
* Pops up the menu or dropdown list of @combo_box.
|
|
|
|
*
|
|
|
|
* This function is mostly intended for use by accessibility technologies;
|
|
|
|
* applications should have little use for it.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
|
|
|
void
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_combo_box_popup (GtkComboBox *combo_box)
|
|
|
|
{
|
2004-02-29 00:08:04 +00:00
|
|
|
gint x, y, width, height;
|
2004-03-04 23:35:31 +00:00
|
|
|
|
2004-02-15 23:05:48 +00:00
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
if (GTK_WIDGET_MAPPED (combo_box->priv->popup_widget))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (GTK_IS_MENU (combo_box->priv->popup_widget))
|
|
|
|
{
|
2004-05-27 03:31:17 +00:00
|
|
|
update_menu_sensitivity (combo_box);
|
2004-03-03 22:30:36 +00:00
|
|
|
gtk_menu_set_active (GTK_MENU (combo_box->priv->popup_widget),
|
|
|
|
combo_box->priv->active_item);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-05-10 15:44:48 +00:00
|
|
|
if (combo_box->priv->wrap_width == 0)
|
|
|
|
{
|
2004-05-11 19:15:56 +00:00
|
|
|
GtkRequisition requisition;
|
|
|
|
|
2004-05-10 15:44:48 +00:00
|
|
|
width = GTK_WIDGET (combo_box)->allocation.width;
|
2004-05-11 19:15:56 +00:00
|
|
|
gtk_widget_size_request (combo_box->priv->popup_widget, &requisition);
|
|
|
|
|
|
|
|
gtk_widget_set_size_request (combo_box->priv->popup_widget,
|
|
|
|
MAX (width, requisition.width), -1);
|
2004-05-10 15:44:48 +00:00
|
|
|
}
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_menu_popup (GTK_MENU (combo_box->priv->popup_widget),
|
2004-03-03 22:30:36 +00:00
|
|
|
NULL, NULL,
|
|
|
|
gtk_combo_box_menu_position, combo_box,
|
|
|
|
0, 0);
|
2003-09-26 21:57:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-03-02 18:53:55 +00:00
|
|
|
gtk_widget_show_all (combo_box->priv->popup_frame);
|
2004-02-29 01:33:01 +00:00
|
|
|
gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
|
2004-07-07 15:15:35 +00:00
|
|
|
|
2004-02-29 01:33:01 +00:00
|
|
|
gtk_widget_set_size_request (combo_box->priv->popup_window, width, -1);
|
2004-03-02 18:53:55 +00:00
|
|
|
gtk_window_move (GTK_WINDOW (combo_box->priv->popup_window), x, y);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
/* popup */
|
2004-03-02 18:53:55 +00:00
|
|
|
gtk_widget_show (combo_box->priv->popup_window);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
gtk_widget_grab_focus (combo_box->priv->popup_window);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
if (!GTK_WIDGET_HAS_FOCUS (combo_box->priv->tree_view))
|
|
|
|
{
|
|
|
|
gdk_keyboard_grab (combo_box->priv->popup_window->window,
|
|
|
|
FALSE, GDK_CURRENT_TIME);
|
|
|
|
gtk_widget_grab_focus (combo_box->priv->tree_view);
|
|
|
|
}
|
2004-02-26 22:40:12 +00:00
|
|
|
|
|
|
|
gtk_grab_add (combo_box->priv->popup_window);
|
|
|
|
gdk_pointer_grab (combo_box->priv->popup_window->window, TRUE,
|
|
|
|
GDK_BUTTON_PRESS_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK |
|
|
|
|
GDK_POINTER_MOTION_MASK,
|
|
|
|
NULL, NULL, GDK_CURRENT_TIME);
|
|
|
|
|
|
|
|
gtk_grab_add (combo_box->priv->tree_view);
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
2004-02-15 23:05:48 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_popdown:
|
|
|
|
* @combo_box: a #GtkComboBox
|
|
|
|
*
|
|
|
|
* Hides the menu or dropdown list of @combo_box.
|
|
|
|
*
|
|
|
|
* This function is mostly intended for use by accessibility technologies;
|
|
|
|
* applications should have little use for it.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
|
|
|
void
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_combo_box_popdown (GtkComboBox *combo_box)
|
|
|
|
{
|
2004-02-15 23:05:48 +00:00
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
|
|
|
2004-07-13 14:50:11 +00:00
|
|
|
if (!GTK_WIDGET_REALIZED (GTK_WIDGET (combo_box)))
|
2004-07-13 13:54:13 +00:00
|
|
|
return;
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
if (GTK_IS_MENU (combo_box->priv->popup_widget))
|
|
|
|
{
|
|
|
|
gtk_menu_popdown (GTK_MENU (combo_box->priv->popup_widget));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-26 22:40:12 +00:00
|
|
|
gtk_combo_box_list_remove_grabs (combo_box);
|
2004-07-07 15:15:35 +00:00
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_widget_hide_all (combo_box->priv->popup_window);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_combo_box_calc_requested_width (GtkComboBox *combo_box,
|
|
|
|
GtkTreePath *path)
|
|
|
|
{
|
|
|
|
gint padding;
|
|
|
|
GtkRequisition req;
|
|
|
|
|
Fixes based on comments from Owen Taylor, #125264.
Tue Nov 18 19:47:59 2003 Kristian Rietveld <kris@gtk.org>
Fixes based on comments from Owen Taylor, #125264.
* gtk/gtkcellview.[ch] (gtk_cell_view_finalize): remove unused
variable,
(gtk_cell_view_set_value), (gtk_cell_view_set_displayed_model): queue
a resize,
(gtk_cell_view_get_size_of_row): new function,
(gtk_cell_view_set_value), (gtk_cell_view_set_valuesv),
(gtk_cell_view_set_values), (gtk_cell_view_set_model),
(gtk_cell_view_set_displayed_row), (gtk_cell_view_get_displayed_row):
s/cellview/cell_view/ in the function definitions, so they match
with the header file.
* gtk/gtkcombobox.c (gtk_combo_box_remeasure): remove the resize
flag again (:, and use gtk_cell_view_get_size_of_row instead of
the measurer, remove _set_size_request call,
(gtk_combo_box_calc_requested_width): use gtk_cell_view_get_size_of_row
instead of the measurer,
(gtk_combo_box_style_set): queue a resize,
(gtk_combo_box_size_request): update of _remeasure call,
(gtk_combo_box_init), (gtk_combo_box_cell_layout_pack_start),
(gtk_combo_box_cell_layout_pack_end),
(gtk_combo_box_cell_layout_clear),
(gtk_combo_box_set_model): get rid of the measurer,
(gtk_combo_box_cell_layout_add_attribute),
(gtk_combo_box_cell_layout_set_cell_data_func),
(gtk_combo_box_cell_layout_clear_attributes): ditto and queue a
resize instead of calling _remeasure.
2003-11-18 19:02:30 +00:00
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
gtk_widget_style_get (combo_box->priv->cell_view,
|
|
|
|
"focus-line-width", &padding,
|
|
|
|
NULL);
|
|
|
|
else
|
|
|
|
padding = 0;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
/* add some pixels for good measure */
|
|
|
|
padding += BONUS_PADDING;
|
|
|
|
|
Fixes based on comments from Owen Taylor, #125264.
Tue Nov 18 19:47:59 2003 Kristian Rietveld <kris@gtk.org>
Fixes based on comments from Owen Taylor, #125264.
* gtk/gtkcellview.[ch] (gtk_cell_view_finalize): remove unused
variable,
(gtk_cell_view_set_value), (gtk_cell_view_set_displayed_model): queue
a resize,
(gtk_cell_view_get_size_of_row): new function,
(gtk_cell_view_set_value), (gtk_cell_view_set_valuesv),
(gtk_cell_view_set_values), (gtk_cell_view_set_model),
(gtk_cell_view_set_displayed_row), (gtk_cell_view_get_displayed_row):
s/cellview/cell_view/ in the function definitions, so they match
with the header file.
* gtk/gtkcombobox.c (gtk_combo_box_remeasure): remove the resize
flag again (:, and use gtk_cell_view_get_size_of_row instead of
the measurer, remove _set_size_request call,
(gtk_combo_box_calc_requested_width): use gtk_cell_view_get_size_of_row
instead of the measurer,
(gtk_combo_box_style_set): queue a resize,
(gtk_combo_box_size_request): update of _remeasure call,
(gtk_combo_box_init), (gtk_combo_box_cell_layout_pack_start),
(gtk_combo_box_cell_layout_pack_end),
(gtk_combo_box_cell_layout_clear),
(gtk_combo_box_set_model): get rid of the measurer,
(gtk_combo_box_cell_layout_add_attribute),
(gtk_combo_box_cell_layout_set_cell_data_func),
(gtk_combo_box_cell_layout_clear_attributes): ditto and queue a
resize instead of calling _remeasure.
2003-11-18 19:02:30 +00:00
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
gtk_cell_view_get_size_of_row (GTK_CELL_VIEW (combo_box->priv->cell_view),
|
|
|
|
path, &req);
|
|
|
|
else
|
|
|
|
req.width = 0;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
return req.width + padding;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
Fixes based on comments from Owen Taylor, #125264.
Tue Nov 18 19:47:59 2003 Kristian Rietveld <kris@gtk.org>
Fixes based on comments from Owen Taylor, #125264.
* gtk/gtkcellview.[ch] (gtk_cell_view_finalize): remove unused
variable,
(gtk_cell_view_set_value), (gtk_cell_view_set_displayed_model): queue
a resize,
(gtk_cell_view_get_size_of_row): new function,
(gtk_cell_view_set_value), (gtk_cell_view_set_valuesv),
(gtk_cell_view_set_values), (gtk_cell_view_set_model),
(gtk_cell_view_set_displayed_row), (gtk_cell_view_get_displayed_row):
s/cellview/cell_view/ in the function definitions, so they match
with the header file.
* gtk/gtkcombobox.c (gtk_combo_box_remeasure): remove the resize
flag again (:, and use gtk_cell_view_get_size_of_row instead of
the measurer, remove _set_size_request call,
(gtk_combo_box_calc_requested_width): use gtk_cell_view_get_size_of_row
instead of the measurer,
(gtk_combo_box_style_set): queue a resize,
(gtk_combo_box_size_request): update of _remeasure call,
(gtk_combo_box_init), (gtk_combo_box_cell_layout_pack_start),
(gtk_combo_box_cell_layout_pack_end),
(gtk_combo_box_cell_layout_clear),
(gtk_combo_box_set_model): get rid of the measurer,
(gtk_combo_box_cell_layout_add_attribute),
(gtk_combo_box_cell_layout_set_cell_data_func),
(gtk_combo_box_cell_layout_clear_attributes): ditto and queue a
resize instead of calling _remeasure.
2003-11-18 19:02:30 +00:00
|
|
|
gtk_combo_box_remeasure (GtkComboBox *combo_box)
|
2003-09-26 21:57:06 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *path;
|
|
|
|
gint padding = 0;
|
|
|
|
|
2004-06-08 03:14:58 +00:00
|
|
|
if (!combo_box->priv->model ||
|
|
|
|
!gtk_tree_model_get_iter_first (combo_box->priv->model, &iter))
|
2003-09-26 21:57:06 +00:00
|
|
|
return;
|
|
|
|
|
Fixes based on comments from Owen Taylor, #125264.
Tue Nov 18 19:47:59 2003 Kristian Rietveld <kris@gtk.org>
Fixes based on comments from Owen Taylor, #125264.
* gtk/gtkcellview.[ch] (gtk_cell_view_finalize): remove unused
variable,
(gtk_cell_view_set_value), (gtk_cell_view_set_displayed_model): queue
a resize,
(gtk_cell_view_get_size_of_row): new function,
(gtk_cell_view_set_value), (gtk_cell_view_set_valuesv),
(gtk_cell_view_set_values), (gtk_cell_view_set_model),
(gtk_cell_view_set_displayed_row), (gtk_cell_view_get_displayed_row):
s/cellview/cell_view/ in the function definitions, so they match
with the header file.
* gtk/gtkcombobox.c (gtk_combo_box_remeasure): remove the resize
flag again (:, and use gtk_cell_view_get_size_of_row instead of
the measurer, remove _set_size_request call,
(gtk_combo_box_calc_requested_width): use gtk_cell_view_get_size_of_row
instead of the measurer,
(gtk_combo_box_style_set): queue a resize,
(gtk_combo_box_size_request): update of _remeasure call,
(gtk_combo_box_init), (gtk_combo_box_cell_layout_pack_start),
(gtk_combo_box_cell_layout_pack_end),
(gtk_combo_box_cell_layout_clear),
(gtk_combo_box_set_model): get rid of the measurer,
(gtk_combo_box_cell_layout_add_attribute),
(gtk_combo_box_cell_layout_set_cell_data_func),
(gtk_combo_box_cell_layout_clear_attributes): ditto and queue a
resize instead of calling _remeasure.
2003-11-18 19:02:30 +00:00
|
|
|
combo_box->priv->width = 0;
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
path = gtk_tree_path_new_from_indices (0, -1);
|
|
|
|
|
Fixes based on comments from Owen Taylor, #125264.
Tue Nov 18 19:47:59 2003 Kristian Rietveld <kris@gtk.org>
Fixes based on comments from Owen Taylor, #125264.
* gtk/gtkcellview.[ch] (gtk_cell_view_finalize): remove unused
variable,
(gtk_cell_view_set_value), (gtk_cell_view_set_displayed_model): queue
a resize,
(gtk_cell_view_get_size_of_row): new function,
(gtk_cell_view_set_value), (gtk_cell_view_set_valuesv),
(gtk_cell_view_set_values), (gtk_cell_view_set_model),
(gtk_cell_view_set_displayed_row), (gtk_cell_view_get_displayed_row):
s/cellview/cell_view/ in the function definitions, so they match
with the header file.
* gtk/gtkcombobox.c (gtk_combo_box_remeasure): remove the resize
flag again (:, and use gtk_cell_view_get_size_of_row instead of
the measurer, remove _set_size_request call,
(gtk_combo_box_calc_requested_width): use gtk_cell_view_get_size_of_row
instead of the measurer,
(gtk_combo_box_style_set): queue a resize,
(gtk_combo_box_size_request): update of _remeasure call,
(gtk_combo_box_init), (gtk_combo_box_cell_layout_pack_start),
(gtk_combo_box_cell_layout_pack_end),
(gtk_combo_box_cell_layout_clear),
(gtk_combo_box_set_model): get rid of the measurer,
(gtk_combo_box_cell_layout_add_attribute),
(gtk_combo_box_cell_layout_set_cell_data_func),
(gtk_combo_box_cell_layout_clear_attributes): ditto and queue a
resize instead of calling _remeasure.
2003-11-18 19:02:30 +00:00
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
gtk_widget_style_get (combo_box->priv->cell_view,
|
|
|
|
"focus-line-width", &padding,
|
|
|
|
NULL);
|
|
|
|
else
|
|
|
|
padding = 0;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
/* add some pixels for good measure */
|
|
|
|
padding += BONUS_PADDING;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
GtkRequisition req;
|
|
|
|
|
Fixes based on comments from Owen Taylor, #125264.
Tue Nov 18 19:47:59 2003 Kristian Rietveld <kris@gtk.org>
Fixes based on comments from Owen Taylor, #125264.
* gtk/gtkcellview.[ch] (gtk_cell_view_finalize): remove unused
variable,
(gtk_cell_view_set_value), (gtk_cell_view_set_displayed_model): queue
a resize,
(gtk_cell_view_get_size_of_row): new function,
(gtk_cell_view_set_value), (gtk_cell_view_set_valuesv),
(gtk_cell_view_set_values), (gtk_cell_view_set_model),
(gtk_cell_view_set_displayed_row), (gtk_cell_view_get_displayed_row):
s/cellview/cell_view/ in the function definitions, so they match
with the header file.
* gtk/gtkcombobox.c (gtk_combo_box_remeasure): remove the resize
flag again (:, and use gtk_cell_view_get_size_of_row instead of
the measurer, remove _set_size_request call,
(gtk_combo_box_calc_requested_width): use gtk_cell_view_get_size_of_row
instead of the measurer,
(gtk_combo_box_style_set): queue a resize,
(gtk_combo_box_size_request): update of _remeasure call,
(gtk_combo_box_init), (gtk_combo_box_cell_layout_pack_start),
(gtk_combo_box_cell_layout_pack_end),
(gtk_combo_box_cell_layout_clear),
(gtk_combo_box_set_model): get rid of the measurer,
(gtk_combo_box_cell_layout_add_attribute),
(gtk_combo_box_cell_layout_set_cell_data_func),
(gtk_combo_box_cell_layout_clear_attributes): ditto and queue a
resize instead of calling _remeasure.
2003-11-18 19:02:30 +00:00
|
|
|
if (combo_box->priv->cell_view)
|
2004-02-28 22:28:37 +00:00
|
|
|
gtk_cell_view_get_size_of_row (GTK_CELL_VIEW (combo_box->priv->cell_view),
|
Fixes based on comments from Owen Taylor, #125264.
Tue Nov 18 19:47:59 2003 Kristian Rietveld <kris@gtk.org>
Fixes based on comments from Owen Taylor, #125264.
* gtk/gtkcellview.[ch] (gtk_cell_view_finalize): remove unused
variable,
(gtk_cell_view_set_value), (gtk_cell_view_set_displayed_model): queue
a resize,
(gtk_cell_view_get_size_of_row): new function,
(gtk_cell_view_set_value), (gtk_cell_view_set_valuesv),
(gtk_cell_view_set_values), (gtk_cell_view_set_model),
(gtk_cell_view_set_displayed_row), (gtk_cell_view_get_displayed_row):
s/cellview/cell_view/ in the function definitions, so they match
with the header file.
* gtk/gtkcombobox.c (gtk_combo_box_remeasure): remove the resize
flag again (:, and use gtk_cell_view_get_size_of_row instead of
the measurer, remove _set_size_request call,
(gtk_combo_box_calc_requested_width): use gtk_cell_view_get_size_of_row
instead of the measurer,
(gtk_combo_box_style_set): queue a resize,
(gtk_combo_box_size_request): update of _remeasure call,
(gtk_combo_box_init), (gtk_combo_box_cell_layout_pack_start),
(gtk_combo_box_cell_layout_pack_end),
(gtk_combo_box_cell_layout_clear),
(gtk_combo_box_set_model): get rid of the measurer,
(gtk_combo_box_cell_layout_add_attribute),
(gtk_combo_box_cell_layout_set_cell_data_func),
(gtk_combo_box_cell_layout_clear_attributes): ditto and queue a
resize instead of calling _remeasure.
2003-11-18 19:02:30 +00:00
|
|
|
path, &req);
|
|
|
|
else
|
|
|
|
req.width = 0;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
combo_box->priv->width = MAX (combo_box->priv->width,
|
|
|
|
req.width + padding);
|
|
|
|
|
|
|
|
gtk_tree_path_next (path);
|
|
|
|
}
|
|
|
|
while (gtk_tree_model_iter_next (combo_box->priv->model, &iter));
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_size_request (GtkWidget *widget,
|
|
|
|
GtkRequisition *requisition)
|
|
|
|
{
|
|
|
|
gint width, height;
|
2004-07-16 20:27:40 +00:00
|
|
|
gint focus_width, focus_pad;
|
2003-09-26 21:57:06 +00:00
|
|
|
GtkRequisition bin_req;
|
|
|
|
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
|
|
|
|
|
|
|
|
/* common */
|
|
|
|
gtk_widget_size_request (GTK_BIN (widget)->child, &bin_req);
|
Fixes based on comments from Owen Taylor, #125264.
Tue Nov 18 19:47:59 2003 Kristian Rietveld <kris@gtk.org>
Fixes based on comments from Owen Taylor, #125264.
* gtk/gtkcellview.[ch] (gtk_cell_view_finalize): remove unused
variable,
(gtk_cell_view_set_value), (gtk_cell_view_set_displayed_model): queue
a resize,
(gtk_cell_view_get_size_of_row): new function,
(gtk_cell_view_set_value), (gtk_cell_view_set_valuesv),
(gtk_cell_view_set_values), (gtk_cell_view_set_model),
(gtk_cell_view_set_displayed_row), (gtk_cell_view_get_displayed_row):
s/cellview/cell_view/ in the function definitions, so they match
with the header file.
* gtk/gtkcombobox.c (gtk_combo_box_remeasure): remove the resize
flag again (:, and use gtk_cell_view_get_size_of_row instead of
the measurer, remove _set_size_request call,
(gtk_combo_box_calc_requested_width): use gtk_cell_view_get_size_of_row
instead of the measurer,
(gtk_combo_box_style_set): queue a resize,
(gtk_combo_box_size_request): update of _remeasure call,
(gtk_combo_box_init), (gtk_combo_box_cell_layout_pack_start),
(gtk_combo_box_cell_layout_pack_end),
(gtk_combo_box_cell_layout_clear),
(gtk_combo_box_set_model): get rid of the measurer,
(gtk_combo_box_cell_layout_add_attribute),
(gtk_combo_box_cell_layout_set_cell_data_func),
(gtk_combo_box_cell_layout_clear_attributes): ditto and queue a
resize instead of calling _remeasure.
2003-11-18 19:02:30 +00:00
|
|
|
gtk_combo_box_remeasure (combo_box);
|
2003-11-17 12:10:06 +00:00
|
|
|
bin_req.width = MAX (bin_req.width, combo_box->priv->width);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
gtk_widget_style_get (GTK_WIDGET (widget),
|
|
|
|
"focus-line-width", &focus_width,
|
|
|
|
"focus-padding", &focus_pad,
|
|
|
|
NULL);
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
if (!combo_box->priv->tree_view)
|
|
|
|
{
|
|
|
|
/* menu mode */
|
|
|
|
|
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
{
|
2004-03-07 01:37:06 +00:00
|
|
|
GtkRequisition button_req, sep_req, arrow_req;
|
2003-09-26 21:57:06 +00:00
|
|
|
gint border_width, xthickness, ythickness;
|
|
|
|
|
2004-03-07 01:37:06 +00:00
|
|
|
gtk_widget_size_request (combo_box->priv->button, &button_req);
|
2004-07-16 20:27:40 +00:00
|
|
|
border_width = GTK_CONTAINER (combo_box)->border_width;
|
2003-09-26 21:57:06 +00:00
|
|
|
xthickness = combo_box->priv->button->style->xthickness;
|
|
|
|
ythickness = combo_box->priv->button->style->ythickness;
|
|
|
|
|
|
|
|
bin_req.width = MAX (bin_req.width, combo_box->priv->width);
|
|
|
|
|
|
|
|
gtk_widget_size_request (combo_box->priv->separator, &sep_req);
|
|
|
|
gtk_widget_size_request (combo_box->priv->arrow, &arrow_req);
|
|
|
|
|
|
|
|
height = MAX (sep_req.height, arrow_req.height);
|
|
|
|
height = MAX (height, bin_req.height);
|
|
|
|
|
|
|
|
width = bin_req.width + sep_req.width + arrow_req.width;
|
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
height += 2*(border_width + ythickness + focus_width + focus_pad);
|
|
|
|
width += 2*(border_width + xthickness + focus_width + focus_pad);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2003-10-10 17:18:34 +00:00
|
|
|
requisition->width = width;
|
|
|
|
requisition->height = height;
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkRequisition but_req;
|
|
|
|
|
|
|
|
gtk_widget_size_request (combo_box->priv->button, &but_req);
|
|
|
|
|
|
|
|
requisition->width = bin_req.width + but_req.width;
|
|
|
|
requisition->height = MAX (bin_req.height, but_req.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* list mode */
|
2004-03-07 01:37:06 +00:00
|
|
|
GtkRequisition button_req, frame_req;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
/* sample + frame */
|
|
|
|
*requisition = bin_req;
|
|
|
|
|
|
|
|
if (combo_box->priv->cell_view_frame)
|
|
|
|
{
|
2004-03-07 01:37:06 +00:00
|
|
|
gtk_widget_size_request (combo_box->priv->cell_view_frame, &frame_req);
|
2004-07-16 20:27:40 +00:00
|
|
|
if (combo_box->priv->has_frame)
|
|
|
|
{
|
|
|
|
requisition->width += 2 *
|
|
|
|
(GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
|
|
|
|
GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
|
|
|
|
requisition->height += 2 *
|
|
|
|
(GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
|
|
|
|
GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness);
|
|
|
|
}
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* the button */
|
|
|
|
gtk_widget_size_request (combo_box->priv->button, &button_req);
|
|
|
|
|
|
|
|
requisition->height = MAX (requisition->height, button_req.height);
|
|
|
|
requisition->width += button_req.width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
|
2004-07-16 20:27:40 +00:00
|
|
|
gint focus_width, focus_pad;
|
2003-09-26 21:57:06 +00:00
|
|
|
GtkAllocation child;
|
|
|
|
GtkRequisition req;
|
2003-12-12 20:08:58 +00:00
|
|
|
gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
widget->allocation = *allocation;
|
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
gtk_widget_style_get (GTK_WIDGET (widget),
|
|
|
|
"focus-line-width", &focus_width,
|
|
|
|
"focus-padding", &focus_pad,
|
|
|
|
NULL);
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
if (!combo_box->priv->tree_view)
|
|
|
|
{
|
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
{
|
|
|
|
gint border_width, xthickness, ythickness;
|
|
|
|
gint width;
|
|
|
|
|
|
|
|
/* menu mode */
|
|
|
|
gtk_widget_size_allocate (combo_box->priv->button, allocation);
|
|
|
|
|
|
|
|
/* set some things ready */
|
|
|
|
border_width = GTK_CONTAINER (combo_box->priv->button)->border_width;
|
|
|
|
xthickness = combo_box->priv->button->style->xthickness;
|
|
|
|
ythickness = combo_box->priv->button->style->ythickness;
|
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
child.x = allocation->x;
|
|
|
|
child.y = allocation->y;
|
|
|
|
width = allocation->width;
|
|
|
|
child.height = allocation->height;
|
|
|
|
|
|
|
|
if (!combo_box->priv->is_cell_renderer)
|
|
|
|
{
|
|
|
|
child.x += border_width + xthickness + focus_width + focus_pad;
|
|
|
|
child.y += border_width + ythickness + focus_width + focus_pad;
|
|
|
|
width -= 2 * (child.x - allocation->x);
|
|
|
|
child.height -= 2 * (child.y - allocation->y);
|
|
|
|
}
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
|
2004-03-08 18:39:44 +00:00
|
|
|
/* handle the children */
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_widget_size_request (combo_box->priv->arrow, &req);
|
|
|
|
child.width = req.width;
|
2003-12-12 20:08:58 +00:00
|
|
|
if (!is_rtl)
|
|
|
|
child.x += width - req.width;
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_widget_size_allocate (combo_box->priv->arrow, &child);
|
2003-12-12 20:08:58 +00:00
|
|
|
if (is_rtl)
|
|
|
|
child.x += req.width;
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_widget_size_request (combo_box->priv->separator, &req);
|
|
|
|
child.width = req.width;
|
2003-12-12 20:08:58 +00:00
|
|
|
if (!is_rtl)
|
|
|
|
child.x -= req.width;
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_widget_size_allocate (combo_box->priv->separator, &child);
|
|
|
|
|
2003-12-12 20:08:58 +00:00
|
|
|
if (is_rtl)
|
|
|
|
{
|
|
|
|
child.x += req.width;
|
|
|
|
child.width = allocation->x + allocation->width
|
2004-07-16 20:27:40 +00:00
|
|
|
- (border_width + xthickness + focus_width + focus_pad)
|
|
|
|
- child.x;
|
2003-12-12 20:08:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
child.width = child.x;
|
2004-07-16 20:27:40 +00:00
|
|
|
child.x = allocation->x
|
|
|
|
+ border_width + xthickness + focus_width + focus_pad;
|
2003-12-12 20:08:58 +00:00
|
|
|
child.width -= child.x;
|
|
|
|
}
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
gtk_widget_size_allocate (GTK_BIN (widget)->child, &child);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_size_request (combo_box->priv->button, &req);
|
2003-12-12 20:08:58 +00:00
|
|
|
if (is_rtl)
|
|
|
|
child.x = allocation->x;
|
|
|
|
else
|
|
|
|
child.x = allocation->x + allocation->width - req.width;
|
2003-09-26 21:57:06 +00:00
|
|
|
child.y = allocation->y;
|
|
|
|
child.width = req.width;
|
2003-10-11 13:39:35 +00:00
|
|
|
child.height = allocation->height;
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_widget_size_allocate (combo_box->priv->button, &child);
|
|
|
|
|
2003-12-12 20:08:58 +00:00
|
|
|
if (is_rtl)
|
|
|
|
child.x = allocation->x + req.width;
|
|
|
|
else
|
|
|
|
child.x = allocation->x;
|
2003-09-26 21:57:06 +00:00
|
|
|
child.y = allocation->y;
|
|
|
|
child.width = allocation->width - req.width;
|
|
|
|
gtk_widget_size_allocate (GTK_BIN (widget)->child, &child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* list mode */
|
|
|
|
|
|
|
|
/* button */
|
|
|
|
gtk_widget_size_request (combo_box->priv->button, &req);
|
2003-12-12 20:08:58 +00:00
|
|
|
if (is_rtl)
|
|
|
|
child.x = allocation->x;
|
|
|
|
else
|
2004-02-23 01:23:27 +00:00
|
|
|
child.x = allocation->x + allocation->width - req.width;
|
2003-09-26 21:57:06 +00:00
|
|
|
child.y = allocation->y;
|
|
|
|
child.width = req.width;
|
2003-10-10 17:18:34 +00:00
|
|
|
child.height = allocation->height;
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_widget_size_allocate (combo_box->priv->button, &child);
|
|
|
|
|
|
|
|
/* frame */
|
2003-12-12 20:08:58 +00:00
|
|
|
if (is_rtl)
|
|
|
|
child.x = allocation->x + req.width;
|
|
|
|
else
|
|
|
|
child.x = allocation->x;
|
2003-09-26 21:57:06 +00:00
|
|
|
child.y = allocation->y;
|
|
|
|
child.width = allocation->width - req.width;
|
2003-10-10 17:18:34 +00:00
|
|
|
child.height = allocation->height;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
if (combo_box->priv->cell_view_frame)
|
|
|
|
{
|
|
|
|
gtk_widget_size_allocate (combo_box->priv->cell_view_frame, &child);
|
|
|
|
|
|
|
|
/* the sample */
|
2004-07-16 20:27:40 +00:00
|
|
|
if (combo_box->priv->has_frame)
|
|
|
|
{
|
|
|
|
child.x +=
|
|
|
|
GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
|
|
|
|
GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness;
|
|
|
|
child.y +=
|
|
|
|
GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
|
|
|
|
GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness;
|
|
|
|
child.width -= 2 * (
|
|
|
|
GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
|
|
|
|
GTK_WIDGET (combo_box->priv->cell_view_frame)->style->xthickness);
|
|
|
|
child.height -= 2 * (
|
|
|
|
GTK_CONTAINER (combo_box->priv->cell_view_frame)->border_width +
|
|
|
|
GTK_WIDGET (combo_box->priv->cell_view_frame)->style->ythickness);
|
|
|
|
}
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
2004-07-16 20:27:40 +00:00
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_widget_size_allocate (GTK_BIN (combo_box)->child, &child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_unset_model (GtkComboBox *combo_box)
|
|
|
|
{
|
2004-03-08 18:39:44 +00:00
|
|
|
if (combo_box->priv->model)
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
{
|
|
|
|
g_signal_handler_disconnect (combo_box->priv->model,
|
2004-02-24 23:12:57 +00:00
|
|
|
combo_box->priv->inserted_id);
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
g_signal_handler_disconnect (combo_box->priv->model,
|
2004-02-24 23:12:57 +00:00
|
|
|
combo_box->priv->deleted_id);
|
2004-03-02 18:56:10 +00:00
|
|
|
g_signal_handler_disconnect (combo_box->priv->model,
|
|
|
|
combo_box->priv->reordered_id);
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
g_signal_handler_disconnect (combo_box->priv->model,
|
2004-02-24 23:12:57 +00:00
|
|
|
combo_box->priv->changed_id);
|
|
|
|
}
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
|
2004-02-24 23:12:57 +00:00
|
|
|
/* menu mode */
|
|
|
|
if (!combo_box->priv->tree_view)
|
|
|
|
{
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
if (combo_box->priv->popup_widget)
|
|
|
|
gtk_container_foreach (GTK_CONTAINER (combo_box->priv->popup_widget),
|
|
|
|
(GtkCallback)gtk_widget_destroy, NULL);
|
|
|
|
}
|
|
|
|
|
2004-04-12 20:06:52 +00:00
|
|
|
if (combo_box->priv->model)
|
|
|
|
{
|
|
|
|
g_object_unref (G_OBJECT (combo_box->priv->model));
|
|
|
|
combo_box->priv->model = NULL;
|
|
|
|
}
|
2004-07-03 03:37:44 +00:00
|
|
|
|
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL);
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
}
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_forall (GtkContainer *container,
|
|
|
|
gboolean include_internals,
|
|
|
|
GtkCallback callback,
|
|
|
|
gpointer callback_data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (container);
|
|
|
|
|
|
|
|
if (include_internals)
|
|
|
|
{
|
2004-02-24 23:12:57 +00:00
|
|
|
if (combo_box->priv->button)
|
|
|
|
(* callback) (combo_box->priv->button, callback_data);
|
|
|
|
if (combo_box->priv->cell_view_frame)
|
|
|
|
(* callback) (combo_box->priv->cell_view_frame, callback_data);
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GTK_BIN (container)->child)
|
|
|
|
(* callback) (GTK_BIN (container)->child, callback_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_combo_box_expose_event (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
|
|
|
|
|
|
|
|
if (!combo_box->priv->tree_view)
|
|
|
|
{
|
|
|
|
gtk_container_propagate_expose (GTK_CONTAINER (widget),
|
2004-07-16 20:27:40 +00:00
|
|
|
combo_box->priv->button, event);
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_container_propagate_expose (GTK_CONTAINER (widget),
|
|
|
|
combo_box->priv->button, event);
|
|
|
|
|
|
|
|
if (combo_box->priv->cell_view_frame)
|
|
|
|
gtk_container_propagate_expose (GTK_CONTAINER (widget),
|
|
|
|
combo_box->priv->cell_view_frame, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_container_propagate_expose (GTK_CONTAINER (widget),
|
|
|
|
GTK_BIN (widget)->child, event);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-19 22:26:42 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_combo_box_scroll_event (GtkWidget *widget,
|
|
|
|
GdkEventScroll *event)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
|
2004-07-07 15:15:35 +00:00
|
|
|
gint index, new_index, items;
|
2003-11-19 22:26:42 +00:00
|
|
|
|
|
|
|
index = gtk_combo_box_get_active (combo_box);
|
|
|
|
|
2004-07-16 21:13:21 +00:00
|
|
|
items = gtk_tree_model_iter_n_children (combo_box->priv->model, NULL);
|
|
|
|
|
|
|
|
if (event->direction == GDK_SCROLL_UP)
|
2003-11-19 22:26:42 +00:00
|
|
|
{
|
2004-07-16 21:13:21 +00:00
|
|
|
new_index = index - 1;
|
|
|
|
while (new_index >= 0 && !row_is_sensitive (combo_box, new_index))
|
|
|
|
new_index--;
|
|
|
|
if (new_index < 0)
|
|
|
|
new_index = index;
|
2003-11-19 22:26:42 +00:00
|
|
|
}
|
2004-07-16 21:13:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
new_index = index + 1;
|
|
|
|
while (new_index < items && !row_is_sensitive (combo_box, new_index))
|
|
|
|
new_index++;
|
|
|
|
if (new_index == items)
|
|
|
|
new_index = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_combo_box_set_active (combo_box, new_index);
|
2003-11-19 22:26:42 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
/*
|
|
|
|
* menu style
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
cell_view_sync_cells (GtkComboBox *combo_box,
|
|
|
|
GtkCellView *cell_view)
|
|
|
|
{
|
|
|
|
GSList *k;
|
|
|
|
|
|
|
|
for (k = combo_box->priv->cells; k; k = k->next)
|
|
|
|
{
|
|
|
|
GSList *j;
|
|
|
|
ComboCellInfo *info = (ComboCellInfo *)k->data;
|
|
|
|
|
|
|
|
if (info->pack == GTK_PACK_START)
|
2003-10-01 20:51:54 +00:00
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cell_view),
|
|
|
|
info->cell, info->expand);
|
2003-09-26 21:57:06 +00:00
|
|
|
else if (info->pack == GTK_PACK_END)
|
2003-10-01 20:51:54 +00:00
|
|
|
gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (cell_view),
|
|
|
|
info->cell, info->expand);
|
|
|
|
|
|
|
|
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (cell_view),
|
|
|
|
info->cell,
|
|
|
|
info->func, info->func_data, NULL);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
for (j = info->attributes; j; j = j->next->next)
|
|
|
|
{
|
2003-10-01 20:51:54 +00:00
|
|
|
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (cell_view),
|
|
|
|
info->cell,
|
|
|
|
j->data,
|
|
|
|
GPOINTER_TO_INT (j->next->data));
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_menu_setup (GtkComboBox *combo_box,
|
2004-03-08 18:39:44 +00:00
|
|
|
gboolean add_children)
|
2003-09-26 21:57:06 +00:00
|
|
|
{
|
2004-04-14 20:26:26 +00:00
|
|
|
GtkWidget *menu;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
{
|
|
|
|
combo_box->priv->button = gtk_toggle_button_new ();
|
|
|
|
g_signal_connect (combo_box->priv->button, "toggled",
|
|
|
|
G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
|
2004-07-16 20:27:40 +00:00
|
|
|
g_signal_connect_after (combo_box->priv->button,
|
|
|
|
"key_press_event",
|
2004-03-04 23:35:31 +00:00
|
|
|
G_CALLBACK (gtk_combo_box_key_press), combo_box);
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_widget_set_parent (combo_box->priv->button,
|
|
|
|
GTK_BIN (combo_box)->child->parent);
|
|
|
|
|
2004-04-14 20:26:26 +00:00
|
|
|
combo_box->priv->box = gtk_hbox_new (FALSE, 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
|
|
|
|
combo_box->priv->box);
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
combo_box->priv->separator = gtk_vseparator_new ();
|
2004-04-14 20:26:26 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (combo_box->priv->box),
|
|
|
|
combo_box->priv->separator);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
|
2004-04-14 20:26:26 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (combo_box->priv->box),
|
|
|
|
combo_box->priv->arrow);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
gtk_widget_show_all (combo_box->priv->button);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
combo_box->priv->button = gtk_toggle_button_new ();
|
|
|
|
g_signal_connect (combo_box->priv->button, "toggled",
|
|
|
|
G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
|
2004-03-04 23:35:31 +00:00
|
|
|
g_signal_connect_after (combo_box, "key_press_event",
|
|
|
|
G_CALLBACK (gtk_combo_box_key_press), combo_box);
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_widget_set_parent (combo_box->priv->button,
|
|
|
|
GTK_BIN (combo_box)->child->parent);
|
|
|
|
|
|
|
|
combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
|
|
|
|
gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
|
|
|
|
combo_box->priv->arrow);
|
|
|
|
gtk_widget_show_all (combo_box->priv->button);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_connect (combo_box->priv->button, "button_press_event",
|
|
|
|
G_CALLBACK (gtk_combo_box_menu_button_press),
|
|
|
|
combo_box);
|
2004-04-14 20:26:26 +00:00
|
|
|
g_signal_connect (combo_box->priv->button, "state_changed",
|
|
|
|
G_CALLBACK (gtk_combo_box_menu_state_changed),
|
|
|
|
combo_box);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
/* create our funky menu */
|
2004-04-14 20:26:26 +00:00
|
|
|
menu = gtk_menu_new ();
|
|
|
|
g_signal_connect (menu, "key_press_event",
|
2004-03-04 23:35:31 +00:00
|
|
|
G_CALLBACK (gtk_combo_box_menu_key_press), combo_box);
|
2004-04-14 20:26:26 +00:00
|
|
|
gtk_combo_box_set_popup_widget (combo_box, menu);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
/* add items */
|
2004-03-08 18:39:44 +00:00
|
|
|
if (add_children)
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
gtk_combo_box_menu_fill (combo_box);
|
2004-02-24 23:12:57 +00:00
|
|
|
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_menu_fill (GtkComboBox *combo_box)
|
|
|
|
{
|
|
|
|
gint i, items;
|
|
|
|
GtkWidget *menu;
|
|
|
|
GtkWidget *tmp;
|
|
|
|
|
|
|
|
if (!combo_box->priv->model)
|
2003-09-26 21:57:06 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
items = gtk_tree_model_iter_n_children (combo_box->priv->model, NULL);
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
menu = combo_box->priv->popup_widget;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-05-10 14:07:35 +00:00
|
|
|
if (combo_box->priv->add_tearoffs)
|
|
|
|
{
|
|
|
|
GtkWidget *tearoff = gtk_tearoff_menu_item_new ();
|
|
|
|
|
|
|
|
gtk_widget_show (tearoff);
|
|
|
|
|
|
|
|
if (combo_box->priv->wrap_width)
|
|
|
|
gtk_menu_attach (GTK_MENU (menu), tearoff,
|
|
|
|
0, combo_box->priv->wrap_width, 0, 1);
|
|
|
|
else
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), tearoff);
|
|
|
|
}
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
for (i = 0; i < items; i++)
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
2004-07-07 15:15:35 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean is_separator;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
path = gtk_tree_path_new_from_indices (i, -1);
|
|
|
|
|
2004-07-07 15:15:35 +00:00
|
|
|
if (combo_box->priv->separator_column != -1)
|
|
|
|
{
|
|
|
|
gtk_tree_model_get_iter (combo_box->priv->model, &iter, path);
|
|
|
|
gtk_tree_model_get (combo_box->priv->model, &iter,
|
|
|
|
combo_box->priv->separator_column, &is_separator, -1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
is_separator = FALSE;
|
|
|
|
|
|
|
|
if (is_separator)
|
|
|
|
tmp = gtk_separator_menu_item_new ();
|
|
|
|
else
|
|
|
|
{
|
2004-07-19 19:07:27 +00:00
|
|
|
GtkCellView *cell_view;
|
|
|
|
|
2004-07-22 03:00:48 +00:00
|
|
|
cell_view = GTK_CELL_VIEW (gtk_cell_view_new ());
|
2004-07-19 19:07:27 +00:00
|
|
|
gtk_cell_view_set_model (cell_view, combo_box->priv->model);
|
|
|
|
gtk_cell_view_set_displayed_row (cell_view, path);
|
|
|
|
gtk_widget_show (GTK_WIDGET (cell_view));
|
|
|
|
|
|
|
|
tmp = gtk_menu_item_new ();
|
|
|
|
gtk_container_add (GTK_CONTAINER (tmp), cell_view);
|
|
|
|
|
2004-07-07 15:15:35 +00:00
|
|
|
g_signal_connect (tmp, "activate",
|
|
|
|
G_CALLBACK (gtk_combo_box_menu_item_activate),
|
|
|
|
combo_box);
|
|
|
|
|
2004-07-19 19:07:27 +00:00
|
|
|
cell_view_sync_cells (combo_box, cell_view);
|
2004-07-07 15:15:35 +00:00
|
|
|
}
|
2003-09-26 21:57:06 +00:00
|
|
|
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), tmp);
|
2004-03-08 18:39:44 +00:00
|
|
|
|
|
|
|
if (combo_box->priv->wrap_width)
|
|
|
|
gtk_combo_box_relayout_item (combo_box, i);
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_widget_show (tmp);
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_menu_destroy (GtkComboBox *combo_box)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_matched (combo_box->priv->button,
|
|
|
|
G_SIGNAL_MATCH_DATA,
|
|
|
|
0, 0, NULL,
|
|
|
|
gtk_combo_box_menu_button_press, NULL);
|
2004-04-14 20:26:26 +00:00
|
|
|
g_signal_handlers_disconnect_matched (combo_box->priv->button,
|
|
|
|
G_SIGNAL_MATCH_DATA,
|
|
|
|
0, 0, NULL,
|
|
|
|
gtk_combo_box_menu_state_changed, NULL);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
/* unparent will remove our latest ref */
|
2004-04-14 20:26:26 +00:00
|
|
|
gtk_widget_unparent (combo_box->priv->button);
|
|
|
|
|
|
|
|
combo_box->priv->box = NULL;
|
|
|
|
combo_box->priv->button = NULL;
|
|
|
|
combo_box->priv->arrow = NULL;
|
|
|
|
combo_box->priv->separator = NULL;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-03-08 18:39:44 +00:00
|
|
|
/* changing the popup window will unref the menu and the children */
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* grid
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_item_get_size (GtkComboBox *combo_box,
|
2004-06-02 03:16:03 +00:00
|
|
|
gint index_,
|
2003-09-26 21:57:06 +00:00
|
|
|
gint *cols,
|
|
|
|
gint *rows)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
2004-06-02 03:16:03 +00:00
|
|
|
gtk_tree_model_iter_nth_child (combo_box->priv->model, &iter, NULL, index_);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
if (cols)
|
|
|
|
{
|
|
|
|
if (combo_box->priv->col_column == -1)
|
|
|
|
*cols = 1;
|
|
|
|
else
|
|
|
|
gtk_tree_model_get (combo_box->priv->model, &iter,
|
|
|
|
combo_box->priv->col_column, cols,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rows)
|
|
|
|
{
|
|
|
|
if (combo_box->priv->row_column == -1)
|
|
|
|
*rows = 1;
|
|
|
|
else
|
|
|
|
gtk_tree_model_get (combo_box->priv->model, &iter,
|
|
|
|
combo_box->priv->row_column, rows,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
menu_occupied (GtkMenu *menu,
|
|
|
|
guint left_attach,
|
|
|
|
guint right_attach,
|
|
|
|
guint top_attach,
|
|
|
|
guint bottom_attach)
|
|
|
|
{
|
|
|
|
GList *i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU (menu), TRUE);
|
|
|
|
g_return_val_if_fail (left_attach < right_attach, TRUE);
|
|
|
|
g_return_val_if_fail (top_attach < bottom_attach, TRUE);
|
|
|
|
|
|
|
|
for (i = GTK_MENU_SHELL (menu)->children; i; i = i->next)
|
|
|
|
{
|
|
|
|
guint l, r, b, t;
|
|
|
|
|
|
|
|
gtk_container_child_get (GTK_CONTAINER (menu), i->data,
|
|
|
|
"left_attach", &l,
|
|
|
|
"right_attach", &r,
|
|
|
|
"bottom_attach", &b,
|
|
|
|
"top_attach", &t,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* look if this item intersects with the given coordinates */
|
2004-05-10 14:07:35 +00:00
|
|
|
if (right_attach > l && left_attach < r && bottom_attach > t && top_attach < b)
|
|
|
|
return TRUE;
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_relayout_item (GtkComboBox *combo_box,
|
|
|
|
gint index)
|
|
|
|
{
|
|
|
|
gint current_col = 0, current_row = 0;
|
|
|
|
gint rows, cols;
|
|
|
|
GList *list;
|
|
|
|
GtkWidget *item;
|
|
|
|
GtkWidget *menu;
|
|
|
|
|
|
|
|
menu = combo_box->priv->popup_widget;
|
|
|
|
if (!GTK_IS_MENU_SHELL (menu))
|
|
|
|
return;
|
|
|
|
|
|
|
|
list = gtk_container_get_children (GTK_CONTAINER (menu));
|
2004-05-10 14:07:35 +00:00
|
|
|
if (combo_box->priv->add_tearoffs)
|
|
|
|
list = list->next;
|
2003-09-26 21:57:06 +00:00
|
|
|
item = g_list_nth_data (list, index);
|
2003-12-21 22:28:14 +00:00
|
|
|
g_list_free (list);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
gtk_combo_box_item_get_size (combo_box, index, &cols, &rows);
|
|
|
|
|
|
|
|
/* look for a good spot */
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (current_col + cols > combo_box->priv->wrap_width)
|
|
|
|
{
|
|
|
|
current_col = 0;
|
|
|
|
current_row++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!menu_occupied (GTK_MENU (menu),
|
|
|
|
current_col, current_col + cols,
|
|
|
|
current_row, current_row + rows))
|
|
|
|
break;
|
|
|
|
|
|
|
|
current_col++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set attach props */
|
|
|
|
gtk_menu_attach (GTK_MENU (menu), item,
|
|
|
|
current_col, current_col + cols,
|
|
|
|
current_row, current_row + rows);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_relayout (GtkComboBox *combo_box)
|
|
|
|
{
|
|
|
|
GList *list, *j;
|
|
|
|
GtkWidget *menu;
|
|
|
|
|
|
|
|
menu = combo_box->priv->popup_widget;
|
2004-04-14 13:53:57 +00:00
|
|
|
|
|
|
|
/* do nothing unless we are in menu style and realized */
|
|
|
|
if (combo_box->priv->tree_view || !GTK_IS_MENU_SHELL (menu))
|
|
|
|
return;
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
/* get rid of all children */
|
|
|
|
list = gtk_container_get_children (GTK_CONTAINER (menu));
|
2004-04-14 13:53:57 +00:00
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
for (j = g_list_last (list); j; j = j->prev)
|
|
|
|
gtk_container_remove (GTK_CONTAINER (menu), j->data);
|
2004-04-14 13:53:57 +00:00
|
|
|
|
2003-12-21 22:28:14 +00:00
|
|
|
g_list_free (list);
|
2004-04-14 13:53:57 +00:00
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
/* and relayout */
|
2004-03-08 18:39:44 +00:00
|
|
|
gtk_combo_box_menu_fill (combo_box);
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
static gboolean
|
|
|
|
gtk_combo_box_menu_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
|
|
|
|
|
|
if (! GTK_IS_MENU (combo_box->priv->popup_widget))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (event->type == GDK_BUTTON_PRESS && event->button == 1)
|
|
|
|
{
|
2003-09-30 19:46:48 +00:00
|
|
|
combo_box->priv->popup_in_progress = TRUE;
|
2004-05-27 03:31:17 +00:00
|
|
|
update_menu_sensitivity (combo_box);
|
2004-03-03 22:30:36 +00:00
|
|
|
gtk_menu_set_active (GTK_MENU (combo_box->priv->popup_widget),
|
|
|
|
combo_box->priv->active_item);
|
2004-03-04 23:35:31 +00:00
|
|
|
|
2004-05-10 15:44:48 +00:00
|
|
|
if (combo_box->priv->wrap_width == 0)
|
|
|
|
{
|
2004-05-11 19:15:56 +00:00
|
|
|
GtkRequisition requisition;
|
|
|
|
gint width;
|
|
|
|
|
2004-05-10 15:44:48 +00:00
|
|
|
width = GTK_WIDGET (combo_box)->allocation.width;
|
2004-05-11 19:15:56 +00:00
|
|
|
gtk_widget_size_request (combo_box->priv->popup_widget, &requisition);
|
|
|
|
|
|
|
|
gtk_widget_set_size_request (combo_box->priv->popup_widget,
|
|
|
|
MAX (width, requisition.width), -1);
|
2004-05-10 15:44:48 +00:00
|
|
|
}
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_menu_popup (GTK_MENU (combo_box->priv->popup_widget),
|
|
|
|
NULL, NULL,
|
|
|
|
gtk_combo_box_menu_position, combo_box,
|
|
|
|
event->button, event->time);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-04-14 20:26:26 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_menu_state_changed (GtkWidget *widget,
|
|
|
|
GtkStateType previous,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
|
|
|
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
{
|
|
|
|
gtk_widget_set_state (combo_box->priv->cell_view,
|
|
|
|
GTK_WIDGET_STATE (widget));
|
|
|
|
|
|
|
|
gtk_widget_queue_draw (combo_box->priv->cell_view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_menu_item_activate (GtkWidget *item,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gint index;
|
|
|
|
GtkWidget *menu;
|
2004-05-10 14:07:35 +00:00
|
|
|
GList *children;
|
2003-09-26 21:57:06 +00:00
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
|
|
|
|
|
|
menu = combo_box->priv->popup_widget;
|
|
|
|
g_return_if_fail (GTK_IS_MENU (menu));
|
|
|
|
|
2004-05-10 14:07:35 +00:00
|
|
|
children = GTK_MENU_SHELL (menu)->children;
|
|
|
|
if (combo_box->priv->add_tearoffs)
|
|
|
|
children = children->next;
|
|
|
|
|
|
|
|
index = g_list_index (children, item);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
gtk_combo_box_set_active (combo_box, index);
|
2004-07-16 20:27:40 +00:00
|
|
|
|
|
|
|
combo_box->priv->editing_canceled = FALSE;
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
2004-03-02 18:56:10 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_model_row_inserted (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
|
|
gint index = gtk_tree_path_get_indices (path)[0];
|
2004-03-02 20:42:14 +00:00
|
|
|
|
2004-03-02 18:56:10 +00:00
|
|
|
if (combo_box->priv->active_item >= index)
|
|
|
|
combo_box->priv->active_item++;
|
2004-03-08 18:39:44 +00:00
|
|
|
|
2004-03-02 18:56:10 +00:00
|
|
|
if (!combo_box->priv->tree_view)
|
|
|
|
gtk_combo_box_menu_row_inserted (model, path, iter, user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_model_row_deleted (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
|
|
gint index = gtk_tree_path_get_indices (path)[0];
|
|
|
|
|
2004-03-02 20:42:14 +00:00
|
|
|
if (!combo_box->priv->tree_view)
|
|
|
|
gtk_combo_box_menu_row_deleted (model, path, user_data);
|
|
|
|
|
2004-03-02 18:56:10 +00:00
|
|
|
if (index == combo_box->priv->active_item)
|
|
|
|
{
|
|
|
|
gint items = gtk_tree_model_iter_n_children (model, NULL);
|
|
|
|
|
|
|
|
if (items == 0)
|
2004-03-03 22:30:36 +00:00
|
|
|
gtk_combo_box_set_active_internal (combo_box, -1);
|
2004-03-02 20:42:14 +00:00
|
|
|
else if (index == items)
|
2004-03-03 22:30:36 +00:00
|
|
|
gtk_combo_box_set_active_internal (combo_box, index - 1);
|
2004-03-02 18:56:10 +00:00
|
|
|
else
|
2004-03-03 22:30:36 +00:00
|
|
|
gtk_combo_box_set_active_internal (combo_box, index);
|
2004-03-02 18:56:10 +00:00
|
|
|
}
|
|
|
|
else if (combo_box->priv->active_item > index)
|
|
|
|
combo_box->priv->active_item--;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_model_rows_reordered (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gint *new_order,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
|
|
gint items = gtk_tree_model_iter_n_children (model, NULL);
|
|
|
|
gint i;
|
|
|
|
|
2004-03-02 21:34:19 +00:00
|
|
|
for (i = 0; i < items; i++)
|
|
|
|
if (new_order[i] == combo_box->priv->active_item)
|
|
|
|
{
|
|
|
|
combo_box->priv->active_item = i;
|
|
|
|
break;
|
|
|
|
}
|
2004-03-02 18:56:10 +00:00
|
|
|
|
|
|
|
if (!combo_box->priv->tree_view)
|
|
|
|
gtk_combo_box_menu_rows_reordered (model, path, iter, new_order, user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_model_row_changed (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
|
|
gint index = gtk_tree_path_get_indices (path)[0];
|
|
|
|
|
|
|
|
if (index == combo_box->priv->active_item &&
|
|
|
|
combo_box->priv->cell_view)
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (combo_box->priv->cell_view));
|
|
|
|
|
|
|
|
if (combo_box->priv->tree_view)
|
|
|
|
gtk_combo_box_list_row_changed (model, path, iter, user_data);
|
|
|
|
else
|
|
|
|
gtk_combo_box_menu_row_changed (model, path, iter, user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkWidget *menu;
|
|
|
|
GtkWidget *item;
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
2004-07-19 19:07:27 +00:00
|
|
|
GtkCellView *cell_view;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
if (!combo_box->priv->popup_widget)
|
|
|
|
return;
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
menu = combo_box->priv->popup_widget;
|
|
|
|
g_return_if_fail (GTK_IS_MENU (menu));
|
|
|
|
|
2004-07-22 05:16:58 +00:00
|
|
|
cell_view = GTK_CELL_VIEW (gtk_cell_view_new ());
|
2004-07-19 19:07:27 +00:00
|
|
|
gtk_cell_view_set_model (cell_view, model);
|
|
|
|
gtk_cell_view_set_displayed_row (cell_view, path);
|
|
|
|
gtk_widget_show (GTK_WIDGET (cell_view));
|
|
|
|
|
|
|
|
item = gtk_menu_item_new ();
|
2004-07-22 05:16:58 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (item), GTK_WIDGET (cell_view));
|
2004-07-19 19:07:27 +00:00
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
G_CALLBACK (gtk_combo_box_menu_item_activate),
|
|
|
|
combo_box);
|
|
|
|
|
2004-07-19 19:07:27 +00:00
|
|
|
cell_view_sync_cells (combo_box, cell_view);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item,
|
|
|
|
gtk_tree_path_get_indices (path)[0]);
|
|
|
|
gtk_widget_show (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_menu_row_deleted (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2004-03-02 18:56:10 +00:00
|
|
|
gint index;
|
2003-09-26 21:57:06 +00:00
|
|
|
GtkWidget *menu;
|
|
|
|
GtkWidget *item;
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
|
|
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
if (!combo_box->priv->popup_widget)
|
|
|
|
return;
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
index = gtk_tree_path_get_indices (path)[0];
|
|
|
|
|
|
|
|
menu = combo_box->priv->popup_widget;
|
|
|
|
g_return_if_fail (GTK_IS_MENU (menu));
|
|
|
|
|
|
|
|
item = g_list_nth_data (GTK_MENU_SHELL (menu)->children, index);
|
|
|
|
g_return_if_fail (GTK_IS_MENU_ITEM (item));
|
|
|
|
|
|
|
|
gtk_container_remove (GTK_CONTAINER (menu), item);
|
|
|
|
}
|
|
|
|
|
2004-03-02 18:56:10 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_menu_rows_reordered (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gint *new_order,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
|
|
|
|
|
|
gtk_combo_box_relayout (combo_box);
|
|
|
|
}
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_menu_row_changed (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
|
|
gint width;
|
|
|
|
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
if (!combo_box->priv->popup_widget)
|
|
|
|
return;
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
if (combo_box->priv->wrap_width)
|
|
|
|
gtk_combo_box_relayout_item (combo_box,
|
|
|
|
gtk_tree_path_get_indices (path)[0]);
|
|
|
|
|
|
|
|
width = gtk_combo_box_calc_requested_width (combo_box, path);
|
|
|
|
|
|
|
|
if (width > combo_box->priv->width)
|
|
|
|
{
|
2004-02-24 23:12:57 +00:00
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
{
|
|
|
|
gtk_widget_set_size_request (combo_box->priv->cell_view, width, -1);
|
|
|
|
gtk_widget_queue_resize (combo_box->priv->cell_view);
|
|
|
|
}
|
2003-09-26 21:57:06 +00:00
|
|
|
combo_box->priv->width = width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* list style
|
|
|
|
*/
|
|
|
|
|
2004-07-07 15:15:35 +00:00
|
|
|
static gboolean
|
|
|
|
row_is_separator (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (data);
|
|
|
|
gboolean is_separator = FALSE;
|
|
|
|
|
|
|
|
if (combo_box->priv->separator_column != -1)
|
|
|
|
gtk_tree_model_get (combo_box->priv->model, iter,
|
|
|
|
combo_box->priv->separator_column, &is_separator, -1);
|
|
|
|
|
|
|
|
return is_separator;
|
|
|
|
}
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_list_setup (GtkComboBox *combo_box)
|
|
|
|
{
|
|
|
|
GSList *i;
|
|
|
|
GtkTreeSelection *sel;
|
|
|
|
|
|
|
|
combo_box->priv->button = gtk_toggle_button_new ();
|
|
|
|
gtk_widget_set_parent (combo_box->priv->button,
|
|
|
|
GTK_BIN (combo_box)->child->parent);
|
|
|
|
g_signal_connect (combo_box->priv->button, "button_press_event",
|
|
|
|
G_CALLBACK (gtk_combo_box_list_button_pressed), combo_box);
|
|
|
|
g_signal_connect (combo_box->priv->button, "toggled",
|
|
|
|
G_CALLBACK (gtk_combo_box_button_toggled), combo_box);
|
2004-03-04 23:35:31 +00:00
|
|
|
g_signal_connect_after (combo_box, "key_press_event",
|
|
|
|
G_CALLBACK (gtk_combo_box_key_press), combo_box);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
combo_box->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
|
|
|
|
gtk_container_add (GTK_CONTAINER (combo_box->priv->button),
|
|
|
|
combo_box->priv->arrow);
|
2004-02-27 01:34:11 +00:00
|
|
|
combo_box->priv->separator = NULL;
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_widget_show_all (combo_box->priv->button);
|
|
|
|
|
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
{
|
2004-03-04 20:43:41 +00:00
|
|
|
gtk_cell_view_set_background_color (GTK_CELL_VIEW (combo_box->priv->cell_view),
|
|
|
|
>K_WIDGET (combo_box)->style->base[GTK_WIDGET_STATE (combo_box)]);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-05-09 06:01:57 +00:00
|
|
|
combo_box->priv->box = gtk_event_box_new ();
|
|
|
|
gtk_event_box_set_visible_window (GTK_EVENT_BOX (combo_box->priv->box),
|
|
|
|
FALSE);
|
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
if (combo_box->priv->has_frame)
|
|
|
|
{
|
|
|
|
combo_box->priv->cell_view_frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->cell_view_frame),
|
|
|
|
GTK_SHADOW_IN);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
combo_box->priv->cell_view_frame = gtk_event_box_new ();
|
|
|
|
gtk_event_box_set_visible_window (GTK_EVENT_BOX (combo_box->priv->cell_view_frame),
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_set_parent (combo_box->priv->cell_view_frame,
|
|
|
|
GTK_BIN (combo_box)->child->parent);
|
2004-05-09 06:01:57 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (combo_box->priv->cell_view_frame),
|
|
|
|
combo_box->priv->box);
|
|
|
|
gtk_widget_show_all (combo_box->priv->cell_view_frame);
|
|
|
|
|
|
|
|
g_signal_connect (combo_box->priv->box, "button_press_event",
|
|
|
|
G_CALLBACK (gtk_combo_box_list_button_pressed),
|
|
|
|
combo_box);
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
combo_box->priv->tree_view = gtk_tree_view_new ();
|
|
|
|
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
|
2004-05-11 13:44:09 +00:00
|
|
|
gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE);
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (combo_box->priv->tree_view),
|
|
|
|
FALSE);
|
2004-05-10 17:15:14 +00:00
|
|
|
gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (combo_box->priv->tree_view),
|
|
|
|
TRUE);
|
2004-07-07 15:15:35 +00:00
|
|
|
gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (combo_box->priv->tree_view),
|
|
|
|
row_is_separator, combo_box, NULL);
|
2004-03-08 18:39:44 +00:00
|
|
|
if (combo_box->priv->model)
|
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
|
|
|
|
combo_box->priv->model);
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
g_signal_connect (combo_box->priv->tree_view, "button_press_event",
|
|
|
|
G_CALLBACK (gtk_combo_box_list_button_pressed),
|
|
|
|
combo_box);
|
|
|
|
g_signal_connect (combo_box->priv->tree_view, "button_release_event",
|
|
|
|
G_CALLBACK (gtk_combo_box_list_button_released),
|
|
|
|
combo_box);
|
|
|
|
g_signal_connect (combo_box->priv->tree_view, "key_press_event",
|
|
|
|
G_CALLBACK (gtk_combo_box_list_key_press),
|
|
|
|
combo_box);
|
|
|
|
|
|
|
|
combo_box->priv->column = gtk_tree_view_column_new ();
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (combo_box->priv->tree_view),
|
|
|
|
combo_box->priv->column);
|
|
|
|
|
|
|
|
/* sync up */
|
|
|
|
for (i = combo_box->priv->cells; i; i = i->next)
|
|
|
|
{
|
|
|
|
GSList *j;
|
|
|
|
ComboCellInfo *info = (ComboCellInfo *)i->data;
|
|
|
|
|
|
|
|
if (info->pack == GTK_PACK_START)
|
|
|
|
gtk_tree_view_column_pack_start (combo_box->priv->column,
|
|
|
|
info->cell, info->expand);
|
|
|
|
else if (info->pack == GTK_PACK_END)
|
|
|
|
gtk_tree_view_column_pack_end (combo_box->priv->column,
|
|
|
|
info->cell, info->expand);
|
|
|
|
|
|
|
|
for (j = info->attributes; j; j = j->next->next)
|
|
|
|
{
|
|
|
|
gtk_tree_view_column_add_attribute (combo_box->priv->column,
|
|
|
|
info->cell,
|
|
|
|
j->data,
|
|
|
|
GPOINTER_TO_INT (j->next->data));
|
|
|
|
}
|
2004-05-27 03:31:17 +00:00
|
|
|
|
|
|
|
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo_box->priv->column),
|
|
|
|
info->cell, info->func, info->func_data,
|
|
|
|
NULL);
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (combo_box->priv->active_item != -1)
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
path = gtk_tree_path_new_from_indices (combo_box->priv->active_item, -1);
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view),
|
|
|
|
path, NULL, FALSE);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set sample/popup widgets */
|
2004-02-15 23:05:48 +00:00
|
|
|
gtk_combo_box_set_popup_widget (combo_box, combo_box->priv->tree_view);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
gtk_widget_show (combo_box->priv->tree_view);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_list_destroy (GtkComboBox *combo_box)
|
|
|
|
{
|
|
|
|
/* disconnect signals */
|
|
|
|
g_signal_handlers_disconnect_matched (combo_box->priv->tree_view,
|
|
|
|
G_SIGNAL_MATCH_DATA,
|
|
|
|
0, 0, NULL, NULL, combo_box);
|
|
|
|
g_signal_handlers_disconnect_matched (combo_box->priv->button,
|
|
|
|
G_SIGNAL_MATCH_DATA,
|
|
|
|
0, 0, NULL,
|
|
|
|
gtk_combo_box_list_button_pressed,
|
|
|
|
NULL);
|
2004-05-27 04:08:26 +00:00
|
|
|
if (combo_box->priv->box)
|
|
|
|
g_signal_handlers_disconnect_matched (combo_box->priv->box,
|
|
|
|
G_SIGNAL_MATCH_DATA,
|
|
|
|
0, 0, NULL,
|
|
|
|
gtk_combo_box_list_button_pressed,
|
|
|
|
NULL);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
/* destroy things (unparent will kill the latest ref from us)
|
|
|
|
* last unref on button will destroy the arrow
|
|
|
|
*/
|
|
|
|
gtk_widget_unparent (combo_box->priv->button);
|
2004-02-27 01:34:11 +00:00
|
|
|
combo_box->priv->button = NULL;
|
|
|
|
combo_box->priv->arrow = NULL;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
{
|
|
|
|
g_object_set (G_OBJECT (combo_box->priv->cell_view),
|
|
|
|
"background_set", FALSE,
|
|
|
|
NULL);
|
2004-04-14 20:26:26 +00:00
|
|
|
}
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-04-14 20:26:26 +00:00
|
|
|
if (combo_box->priv->cell_view_frame)
|
|
|
|
{
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_widget_unparent (combo_box->priv->cell_view_frame);
|
2004-02-27 01:34:11 +00:00
|
|
|
combo_box->priv->cell_view_frame = NULL;
|
2004-05-09 06:01:57 +00:00
|
|
|
combo_box->priv->box = NULL;
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_destroy (combo_box->priv->tree_view);
|
2004-02-27 01:34:11 +00:00
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
combo_box->priv->tree_view = NULL;
|
|
|
|
combo_box->priv->popup_widget = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
static void
|
|
|
|
gtk_combo_box_list_remove_grabs (GtkComboBox *combo_box)
|
|
|
|
{
|
2004-07-18 15:14:05 +00:00
|
|
|
if (combo_box->priv->tree_view &&
|
|
|
|
GTK_WIDGET_HAS_GRAB (combo_box->priv->tree_view))
|
|
|
|
{
|
|
|
|
gtk_grab_remove (combo_box->priv->tree_view);
|
|
|
|
}
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-07-18 15:14:05 +00:00
|
|
|
if (combo_box->priv->popup_window &&
|
|
|
|
GTK_WIDGET_HAS_GRAB (combo_box->priv->popup_window))
|
2003-09-26 21:57:06 +00:00
|
|
|
{
|
|
|
|
gtk_grab_remove (combo_box->priv->popup_window);
|
2004-02-29 00:08:04 +00:00
|
|
|
gdk_keyboard_ungrab (GDK_CURRENT_TIME);
|
2003-09-26 21:57:06 +00:00
|
|
|
gdk_pointer_ungrab (GDK_CURRENT_TIME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_combo_box_list_button_pressed (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (data);
|
|
|
|
|
|
|
|
GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
|
|
|
|
|
|
|
|
if (ewidget == combo_box->priv->tree_view)
|
|
|
|
return TRUE;
|
|
|
|
|
2004-05-09 06:01:57 +00:00
|
|
|
if ((ewidget != combo_box->priv->button && ewidget != combo_box->priv->box) ||
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (combo_box->priv->button)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gtk_combo_box_popup (combo_box);
|
|
|
|
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
combo_box->priv->popup_in_progress = TRUE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_combo_box_list_button_released (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
GtkTreePath *path = NULL;
|
|
|
|
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (data);
|
|
|
|
|
|
|
|
gboolean popup_in_progress = FALSE;
|
|
|
|
|
|
|
|
GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
|
|
|
|
|
|
|
|
if (combo_box->priv->popup_in_progress)
|
|
|
|
{
|
|
|
|
popup_in_progress = TRUE;
|
|
|
|
combo_box->priv->popup_in_progress = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ewidget != combo_box->priv->tree_view)
|
|
|
|
{
|
|
|
|
if (ewidget == combo_box->priv->button &&
|
|
|
|
!popup_in_progress &&
|
|
|
|
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (combo_box->priv->button)))
|
|
|
|
{
|
|
|
|
gtk_combo_box_popdown (combo_box);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* released outside treeview */
|
|
|
|
if (ewidget != combo_box->priv->button)
|
|
|
|
{
|
|
|
|
gtk_combo_box_popdown (combo_box);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* select something cool */
|
|
|
|
ret = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
|
|
|
|
event->x, event->y,
|
|
|
|
&path,
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return TRUE; /* clicked outside window? */
|
|
|
|
|
|
|
|
gtk_combo_box_set_active (combo_box, gtk_tree_path_get_indices (path)[0]);
|
|
|
|
gtk_combo_box_popdown (combo_box);
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-04 23:35:31 +00:00
|
|
|
gtk_combo_box_key_press (GtkWidget *widget,
|
|
|
|
GdkEventKey *event,
|
|
|
|
gpointer data)
|
2003-09-26 21:57:06 +00:00
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (data);
|
2004-03-04 23:35:31 +00:00
|
|
|
guint state = event->state & gtk_accelerator_get_default_mod_mask ();
|
2004-06-15 05:12:27 +00:00
|
|
|
gint items = 0;
|
2004-03-04 23:35:31 +00:00
|
|
|
gint index = gtk_combo_box_get_active (combo_box);
|
|
|
|
gint new_index;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-06-15 05:12:27 +00:00
|
|
|
if (combo_box->priv->model)
|
|
|
|
items = gtk_tree_model_iter_n_children (combo_box->priv->model, NULL);
|
|
|
|
|
2004-03-04 23:35:31 +00:00
|
|
|
if ((event->keyval == GDK_Down || event->keyval == GDK_KP_Down) &&
|
|
|
|
state == GDK_MOD1_MASK)
|
2003-09-26 21:57:06 +00:00
|
|
|
{
|
2004-03-04 23:35:31 +00:00
|
|
|
gtk_combo_box_popup (combo_box);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-03-04 23:35:31 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event->keyval)
|
|
|
|
{
|
|
|
|
case GDK_Down:
|
|
|
|
case GDK_KP_Down:
|
|
|
|
new_index = index + 1;
|
2004-05-27 03:31:17 +00:00
|
|
|
while (new_index < items && !row_is_sensitive (combo_box, new_index))
|
|
|
|
new_index++;
|
|
|
|
if (new_index == items)
|
|
|
|
new_index = index;
|
2004-03-04 23:35:31 +00:00
|
|
|
break;
|
|
|
|
case GDK_Up:
|
|
|
|
case GDK_KP_Up:
|
|
|
|
new_index = index - 1;
|
2004-05-27 03:31:17 +00:00
|
|
|
while (new_index >= 0 && !row_is_sensitive (combo_box, new_index))
|
|
|
|
new_index--;
|
|
|
|
if (new_index < 0)
|
|
|
|
new_index = index;
|
2004-03-04 23:35:31 +00:00
|
|
|
break;
|
|
|
|
case GDK_Page_Up:
|
|
|
|
case GDK_KP_Page_Up:
|
|
|
|
case GDK_Home:
|
|
|
|
case GDK_KP_Home:
|
|
|
|
new_index = 0;
|
2004-05-27 03:31:17 +00:00
|
|
|
while (new_index < items - 1 && !row_is_sensitive (combo_box, new_index))
|
|
|
|
new_index++;
|
2004-03-04 23:35:31 +00:00
|
|
|
break;
|
|
|
|
case GDK_Page_Down:
|
|
|
|
case GDK_KP_Page_Down:
|
|
|
|
case GDK_End:
|
|
|
|
case GDK_KP_End:
|
|
|
|
new_index = items - 1;
|
2004-05-27 03:31:17 +00:00
|
|
|
while (new_index > 0 && !row_is_sensitive (combo_box, new_index))
|
|
|
|
new_index--;
|
2004-03-04 23:35:31 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-06-15 05:12:27 +00:00
|
|
|
|
|
|
|
if (items > 0)
|
|
|
|
gtk_combo_box_set_active (combo_box, CLAMP (new_index, 0, items - 1));
|
2004-03-04 23:35:31 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-03-04 23:35:31 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_combo_box_menu_key_press (GtkWidget *widget,
|
|
|
|
GdkEventKey *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (data);
|
|
|
|
guint state = event->state & gtk_accelerator_get_default_mod_mask ();
|
|
|
|
|
|
|
|
if ((event->keyval == GDK_Up || event->keyval == GDK_KP_Up) &&
|
|
|
|
state == GDK_MOD1_MASK)
|
|
|
|
{
|
2003-09-26 21:57:06 +00:00
|
|
|
gtk_combo_box_popdown (combo_box);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2004-03-04 23:35:31 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_combo_box_list_key_press (GtkWidget *widget,
|
|
|
|
GdkEventKey *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (data);
|
|
|
|
guint state = event->state & gtk_accelerator_get_default_mod_mask ();
|
|
|
|
|
|
|
|
if (event->keyval == GDK_Escape ||
|
|
|
|
((event->keyval == GDK_Up || event->keyval == GDK_KP_Up) &&
|
|
|
|
state == GDK_MOD1_MASK))
|
|
|
|
{
|
|
|
|
/* reset active item -- this is incredibly lame and ugly */
|
|
|
|
gtk_combo_box_set_active (combo_box,
|
|
|
|
gtk_combo_box_get_active (combo_box));
|
|
|
|
|
|
|
|
gtk_combo_box_popdown (combo_box);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event->keyval == GDK_Return || event->keyval == GDK_KP_Enter ||
|
|
|
|
event->keyval == GDK_space || event->keyval == GDK_KP_Space)
|
|
|
|
{
|
2004-06-15 05:12:27 +00:00
|
|
|
gboolean ret = FALSE;
|
2004-03-04 23:35:31 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeModel *model = NULL;
|
|
|
|
|
2004-06-15 05:12:27 +00:00
|
|
|
if (combo_box->priv->model)
|
|
|
|
{
|
|
|
|
GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view));
|
|
|
|
|
|
|
|
ret = gtk_tree_selection_get_selected (sel, &model, &iter);
|
|
|
|
}
|
2004-03-04 23:35:31 +00:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
path = gtk_tree_model_get_path (model, &iter);
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
gtk_combo_box_set_active (combo_box, gtk_tree_path_get_indices (path)[0]);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
}
|
2004-03-13 20:33:45 +00:00
|
|
|
|
|
|
|
gtk_combo_box_popdown (combo_box);
|
|
|
|
|
|
|
|
return TRUE;
|
2004-03-04 23:35:31 +00:00
|
|
|
}
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_list_row_changed (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (data);
|
|
|
|
gint width;
|
|
|
|
|
|
|
|
width = gtk_combo_box_calc_requested_width (combo_box, path);
|
|
|
|
|
|
|
|
if (width > combo_box->priv->width)
|
|
|
|
{
|
2004-02-24 23:12:57 +00:00
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
{
|
|
|
|
gtk_widget_set_size_request (combo_box->priv->cell_view, width, -1);
|
|
|
|
gtk_widget_queue_resize (combo_box->priv->cell_view);
|
|
|
|
}
|
2003-09-26 21:57:06 +00:00
|
|
|
combo_box->priv->width = width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-10-01 20:51:54 +00:00
|
|
|
* GtkCellLayout implementation
|
2003-09-26 21:57:06 +00:00
|
|
|
*/
|
2003-10-01 20:51:54 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_cell_layout_pack_start (GtkCellLayout *layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
gboolean expand)
|
2003-09-26 21:57:06 +00:00
|
|
|
{
|
|
|
|
ComboCellInfo *info;
|
2004-02-15 23:05:48 +00:00
|
|
|
GtkComboBox *combo_box;
|
2003-09-26 21:57:06 +00:00
|
|
|
GtkWidget *menu;
|
|
|
|
|
2004-02-15 23:05:48 +00:00
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (layout));
|
2003-09-26 21:57:06 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
|
|
|
|
|
2004-02-15 23:05:48 +00:00
|
|
|
combo_box = GTK_COMBO_BOX (layout);
|
|
|
|
|
2004-02-26 20:51:02 +00:00
|
|
|
g_object_ref (G_OBJECT (cell));
|
|
|
|
gtk_object_sink (GTK_OBJECT (cell));
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
info = g_new0 (ComboCellInfo, 1);
|
|
|
|
info->cell = cell;
|
|
|
|
info->expand = expand;
|
|
|
|
info->pack = GTK_PACK_START;
|
|
|
|
|
|
|
|
combo_box->priv->cells = g_slist_append (combo_box->priv->cells, info);
|
|
|
|
|
|
|
|
if (combo_box->priv->cell_view)
|
2003-10-01 20:51:54 +00:00
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
|
|
|
|
cell, expand);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
if (combo_box->priv->column)
|
|
|
|
gtk_tree_view_column_pack_start (combo_box->priv->column, cell, expand);
|
|
|
|
|
|
|
|
menu = combo_box->priv->popup_widget;
|
|
|
|
if (GTK_IS_MENU (menu))
|
|
|
|
{
|
|
|
|
GList *i, *list;
|
|
|
|
|
|
|
|
list = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
|
|
for (i = list; i; i = i->next)
|
|
|
|
{
|
|
|
|
GtkCellView *view;
|
|
|
|
|
2004-05-10 14:07:35 +00:00
|
|
|
if (GTK_IS_TEAROFF_MENU_ITEM (i->data))
|
|
|
|
continue;
|
|
|
|
|
2004-07-19 19:07:27 +00:00
|
|
|
if (GTK_IS_CELL_VIEW (i->data))
|
|
|
|
view = GTK_CELL_VIEW (i->data);
|
|
|
|
else
|
|
|
|
view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (view), cell, expand);
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
g_list_free (list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_cell_layout_pack_end (GtkCellLayout *layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
gboolean expand)
|
2003-09-26 21:57:06 +00:00
|
|
|
{
|
|
|
|
ComboCellInfo *info;
|
2004-02-15 23:05:48 +00:00
|
|
|
GtkComboBox *combo_box;
|
2003-09-26 21:57:06 +00:00
|
|
|
GtkWidget *menu;
|
|
|
|
|
2004-02-15 23:05:48 +00:00
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (layout));
|
2003-09-26 21:57:06 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
|
|
|
|
|
2004-02-15 23:05:48 +00:00
|
|
|
combo_box = GTK_COMBO_BOX (layout);
|
|
|
|
|
2004-02-26 20:51:02 +00:00
|
|
|
g_object_ref (G_OBJECT (cell));
|
|
|
|
gtk_object_sink (GTK_OBJECT (cell));
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
info = g_new0 (ComboCellInfo, 1);
|
|
|
|
info->cell = cell;
|
|
|
|
info->expand = expand;
|
|
|
|
info->pack = GTK_PACK_END;
|
|
|
|
|
|
|
|
if (combo_box->priv->cell_view)
|
2003-10-01 20:51:54 +00:00
|
|
|
gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
|
|
|
|
cell, expand);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
if (combo_box->priv->column)
|
|
|
|
gtk_tree_view_column_pack_end (combo_box->priv->column, cell, expand);
|
|
|
|
|
|
|
|
menu = combo_box->priv->popup_widget;
|
|
|
|
if (GTK_IS_MENU (menu))
|
|
|
|
{
|
|
|
|
GList *i, *list;
|
|
|
|
|
|
|
|
list = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
|
|
for (i = list; i; i = i->next)
|
|
|
|
{
|
|
|
|
GtkCellView *view;
|
|
|
|
|
2004-05-10 14:07:35 +00:00
|
|
|
if (GTK_IS_TEAROFF_MENU_ITEM (i->data))
|
|
|
|
continue;
|
|
|
|
|
2004-07-19 19:07:27 +00:00
|
|
|
if (GTK_IS_CELL_VIEW (i->data))
|
2003-09-26 21:57:06 +00:00
|
|
|
view = GTK_CELL_VIEW (i->data);
|
2004-07-19 19:07:27 +00:00
|
|
|
else
|
|
|
|
view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (view), cell, expand);
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
g_list_free (list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_cell_layout_clear (GtkCellLayout *layout)
|
|
|
|
{
|
|
|
|
GtkWidget *menu;
|
2004-02-15 23:05:48 +00:00
|
|
|
GtkComboBox *combo_box;
|
2004-02-11 01:09:25 +00:00
|
|
|
GSList *i;
|
|
|
|
|
2004-02-15 23:05:48 +00:00
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (layout));
|
2003-10-01 20:51:54 +00:00
|
|
|
|
2004-02-15 23:05:48 +00:00
|
|
|
combo_box = GTK_COMBO_BOX (layout);
|
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo_box->priv->cell_view));
|
|
|
|
|
|
|
|
if (combo_box->priv->column)
|
|
|
|
gtk_tree_view_column_clear (combo_box->priv->column);
|
|
|
|
|
2004-02-11 01:09:25 +00:00
|
|
|
for (i = combo_box->priv->cells; i; i = i->next)
|
|
|
|
{
|
|
|
|
ComboCellInfo *info = (ComboCellInfo *)i->data;
|
|
|
|
|
|
|
|
gtk_combo_box_cell_layout_clear_attributes (layout, info->cell);
|
|
|
|
g_object_unref (G_OBJECT (info->cell));
|
|
|
|
g_free (info);
|
2004-02-27 20:41:14 +00:00
|
|
|
i->data = NULL;
|
2004-02-11 01:09:25 +00:00
|
|
|
}
|
|
|
|
g_slist_free (combo_box->priv->cells);
|
|
|
|
combo_box->priv->cells = NULL;
|
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
menu = combo_box->priv->popup_widget;
|
|
|
|
if (GTK_IS_MENU (menu))
|
|
|
|
{
|
|
|
|
GList *i, *list;
|
|
|
|
|
|
|
|
list = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
|
|
for (i = list; i; i = i->next)
|
|
|
|
{
|
|
|
|
GtkCellView *view;
|
|
|
|
|
2004-05-10 14:07:35 +00:00
|
|
|
if (GTK_IS_TEAROFF_MENU_ITEM (i->data))
|
|
|
|
continue;
|
|
|
|
|
2004-07-19 19:07:27 +00:00
|
|
|
if (GTK_IS_CELL_VIEW (i->data))
|
2003-10-01 20:51:54 +00:00
|
|
|
view = GTK_CELL_VIEW (i->data);
|
2004-07-19 19:07:27 +00:00
|
|
|
else
|
|
|
|
view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
|
2003-10-01 20:51:54 +00:00
|
|
|
|
|
|
|
gtk_cell_layout_clear (GTK_CELL_LAYOUT (view));
|
|
|
|
}
|
2003-12-21 22:28:14 +00:00
|
|
|
g_list_free (list);
|
2003-10-01 20:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_cell_layout_add_attribute (GtkCellLayout *layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
const gchar *attribute,
|
|
|
|
gint column)
|
2003-09-26 21:57:06 +00:00
|
|
|
{
|
|
|
|
ComboCellInfo *info;
|
2004-02-15 23:05:48 +00:00
|
|
|
GtkComboBox *combo_box;
|
2003-09-26 21:57:06 +00:00
|
|
|
GtkWidget *menu;
|
|
|
|
|
2004-02-15 23:05:48 +00:00
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (layout));
|
2003-09-26 21:57:06 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
|
|
|
|
|
2004-02-15 23:05:48 +00:00
|
|
|
combo_box = GTK_COMBO_BOX (layout);
|
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
info = gtk_combo_box_get_cell_info (combo_box, cell);
|
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
info->attributes = g_slist_prepend (info->attributes,
|
|
|
|
GINT_TO_POINTER (column));
|
|
|
|
info->attributes = g_slist_prepend (info->attributes,
|
|
|
|
g_strdup (attribute));
|
|
|
|
|
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
|
|
|
|
cell, attribute, column);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
if (combo_box->priv->column)
|
|
|
|
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box->priv->column),
|
|
|
|
cell, attribute, column);
|
|
|
|
|
|
|
|
menu = combo_box->priv->popup_widget;
|
|
|
|
if (GTK_IS_MENU (menu))
|
2003-09-26 21:57:06 +00:00
|
|
|
{
|
2003-10-01 20:51:54 +00:00
|
|
|
GList *i, *list;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
list = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
|
|
for (i = list; i; i = i->next)
|
|
|
|
{
|
|
|
|
GtkCellView *view;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-05-10 14:07:35 +00:00
|
|
|
if (GTK_IS_TEAROFF_MENU_ITEM (i->data))
|
|
|
|
continue;
|
|
|
|
|
2004-07-19 19:07:27 +00:00
|
|
|
if (GTK_IS_CELL_VIEW (i->data))
|
2003-10-01 20:51:54 +00:00
|
|
|
view = GTK_CELL_VIEW (i->data);
|
2004-07-19 19:07:27 +00:00
|
|
|
else
|
|
|
|
view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (view), cell,
|
|
|
|
attribute, column);
|
|
|
|
}
|
|
|
|
g_list_free (list);
|
|
|
|
}
|
2003-09-26 21:57:06 +00:00
|
|
|
|
Fixes based on comments from Owen Taylor, #125264.
Tue Nov 18 19:47:59 2003 Kristian Rietveld <kris@gtk.org>
Fixes based on comments from Owen Taylor, #125264.
* gtk/gtkcellview.[ch] (gtk_cell_view_finalize): remove unused
variable,
(gtk_cell_view_set_value), (gtk_cell_view_set_displayed_model): queue
a resize,
(gtk_cell_view_get_size_of_row): new function,
(gtk_cell_view_set_value), (gtk_cell_view_set_valuesv),
(gtk_cell_view_set_values), (gtk_cell_view_set_model),
(gtk_cell_view_set_displayed_row), (gtk_cell_view_get_displayed_row):
s/cellview/cell_view/ in the function definitions, so they match
with the header file.
* gtk/gtkcombobox.c (gtk_combo_box_remeasure): remove the resize
flag again (:, and use gtk_cell_view_get_size_of_row instead of
the measurer, remove _set_size_request call,
(gtk_combo_box_calc_requested_width): use gtk_cell_view_get_size_of_row
instead of the measurer,
(gtk_combo_box_style_set): queue a resize,
(gtk_combo_box_size_request): update of _remeasure call,
(gtk_combo_box_init), (gtk_combo_box_cell_layout_pack_start),
(gtk_combo_box_cell_layout_pack_end),
(gtk_combo_box_cell_layout_clear),
(gtk_combo_box_set_model): get rid of the measurer,
(gtk_combo_box_cell_layout_add_attribute),
(gtk_combo_box_cell_layout_set_cell_data_func),
(gtk_combo_box_cell_layout_clear_attributes): ditto and queue a
resize instead of calling _remeasure.
2003-11-18 19:02:30 +00:00
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (combo_box));
|
2003-10-01 20:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_cell_layout_set_cell_data_func (GtkCellLayout *layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkCellLayoutDataFunc func,
|
|
|
|
gpointer func_data,
|
|
|
|
GDestroyNotify destroy)
|
|
|
|
{
|
|
|
|
ComboCellInfo *info;
|
2004-02-15 23:05:48 +00:00
|
|
|
GtkComboBox *combo_box;
|
2003-10-01 20:51:54 +00:00
|
|
|
GtkWidget *menu;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-02-15 23:05:48 +00:00
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (layout));
|
|
|
|
|
|
|
|
combo_box = GTK_COMBO_BOX (layout);
|
2003-10-01 20:51:54 +00:00
|
|
|
|
|
|
|
info = gtk_combo_box_get_cell_info (combo_box, cell);
|
|
|
|
g_return_if_fail (info != NULL);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
if (info->destroy)
|
|
|
|
{
|
|
|
|
GDestroyNotify d = info->destroy;
|
|
|
|
|
|
|
|
info->destroy = NULL;
|
|
|
|
d (info->func_data);
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
info->func = func;
|
|
|
|
info->func_data = func_data;
|
|
|
|
info->destroy = destroy;
|
|
|
|
|
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo_box->priv->cell_view), cell, func, func_data, NULL);
|
|
|
|
|
|
|
|
if (combo_box->priv->column)
|
|
|
|
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo_box->priv->column), cell, func, func_data, NULL);
|
2004-05-06 20:14:46 +00:00
|
|
|
|
2003-09-26 21:57:06 +00:00
|
|
|
menu = combo_box->priv->popup_widget;
|
|
|
|
if (GTK_IS_MENU (menu))
|
|
|
|
{
|
|
|
|
GList *i, *list;
|
|
|
|
|
|
|
|
list = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
|
|
for (i = list; i; i = i->next)
|
|
|
|
{
|
|
|
|
GtkCellView *view;
|
|
|
|
|
2004-05-10 14:07:35 +00:00
|
|
|
if (GTK_IS_TEAROFF_MENU_ITEM (i->data))
|
|
|
|
continue;
|
|
|
|
|
2004-07-19 19:07:27 +00:00
|
|
|
if (GTK_IS_CELL_VIEW (i->data))
|
2003-09-26 21:57:06 +00:00
|
|
|
view = GTK_CELL_VIEW (i->data);
|
2004-07-19 19:07:27 +00:00
|
|
|
else
|
|
|
|
view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (view), cell,
|
|
|
|
func, func_data, NULL);
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
g_list_free (list);
|
|
|
|
}
|
|
|
|
|
Fixes based on comments from Owen Taylor, #125264.
Tue Nov 18 19:47:59 2003 Kristian Rietveld <kris@gtk.org>
Fixes based on comments from Owen Taylor, #125264.
* gtk/gtkcellview.[ch] (gtk_cell_view_finalize): remove unused
variable,
(gtk_cell_view_set_value), (gtk_cell_view_set_displayed_model): queue
a resize,
(gtk_cell_view_get_size_of_row): new function,
(gtk_cell_view_set_value), (gtk_cell_view_set_valuesv),
(gtk_cell_view_set_values), (gtk_cell_view_set_model),
(gtk_cell_view_set_displayed_row), (gtk_cell_view_get_displayed_row):
s/cellview/cell_view/ in the function definitions, so they match
with the header file.
* gtk/gtkcombobox.c (gtk_combo_box_remeasure): remove the resize
flag again (:, and use gtk_cell_view_get_size_of_row instead of
the measurer, remove _set_size_request call,
(gtk_combo_box_calc_requested_width): use gtk_cell_view_get_size_of_row
instead of the measurer,
(gtk_combo_box_style_set): queue a resize,
(gtk_combo_box_size_request): update of _remeasure call,
(gtk_combo_box_init), (gtk_combo_box_cell_layout_pack_start),
(gtk_combo_box_cell_layout_pack_end),
(gtk_combo_box_cell_layout_clear),
(gtk_combo_box_set_model): get rid of the measurer,
(gtk_combo_box_cell_layout_add_attribute),
(gtk_combo_box_cell_layout_set_cell_data_func),
(gtk_combo_box_cell_layout_clear_attributes): ditto and queue a
resize instead of calling _remeasure.
2003-11-18 19:02:30 +00:00
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (combo_box));
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_cell_layout_clear_attributes (GtkCellLayout *layout,
|
|
|
|
GtkCellRenderer *cell)
|
2003-09-26 21:57:06 +00:00
|
|
|
{
|
2003-10-01 20:51:54 +00:00
|
|
|
ComboCellInfo *info;
|
2004-02-15 23:05:48 +00:00
|
|
|
GtkComboBox *combo_box;
|
2003-09-26 21:57:06 +00:00
|
|
|
GtkWidget *menu;
|
2004-02-11 01:09:25 +00:00
|
|
|
GSList *list;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (layout));
|
|
|
|
g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
|
|
|
|
|
2004-02-15 23:05:48 +00:00
|
|
|
combo_box = GTK_COMBO_BOX (layout);
|
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
info = gtk_combo_box_get_cell_info (combo_box, cell);
|
|
|
|
g_return_if_fail (info != NULL);
|
|
|
|
|
2004-02-11 01:09:25 +00:00
|
|
|
list = info->attributes;
|
|
|
|
while (list && list->next)
|
|
|
|
{
|
|
|
|
g_free (list->data);
|
|
|
|
list = list->next->next;
|
|
|
|
}
|
2004-02-06 22:25:01 +00:00
|
|
|
g_slist_free (info->attributes);
|
2003-10-01 20:51:54 +00:00
|
|
|
info->attributes = NULL;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
if (combo_box->priv->cell_view)
|
2003-10-01 20:51:54 +00:00
|
|
|
gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (combo_box->priv->cell_view), cell);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
if (combo_box->priv->column)
|
2003-10-01 20:51:54 +00:00
|
|
|
gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (combo_box->priv->column), cell);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
menu = combo_box->priv->popup_widget;
|
|
|
|
if (GTK_IS_MENU (menu))
|
|
|
|
{
|
|
|
|
GList *i, *list;
|
|
|
|
|
|
|
|
list = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
|
|
for (i = list; i; i = i->next)
|
|
|
|
{
|
|
|
|
GtkCellView *view;
|
|
|
|
|
2004-05-10 14:07:35 +00:00
|
|
|
if (GTK_IS_TEAROFF_MENU_ITEM (i->data))
|
|
|
|
continue;
|
|
|
|
|
2004-07-19 19:07:27 +00:00
|
|
|
if (GTK_IS_CELL_VIEW (i->data))
|
2003-09-26 21:57:06 +00:00
|
|
|
view = GTK_CELL_VIEW (i->data);
|
2004-07-19 19:07:27 +00:00
|
|
|
else
|
|
|
|
view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
gtk_cell_layout_clear_attributes (GTK_CELL_LAYOUT (view), cell);
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
2003-10-01 20:51:54 +00:00
|
|
|
g_list_free (list);
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
2003-10-01 20:51:54 +00:00
|
|
|
|
Fixes based on comments from Owen Taylor, #125264.
Tue Nov 18 19:47:59 2003 Kristian Rietveld <kris@gtk.org>
Fixes based on comments from Owen Taylor, #125264.
* gtk/gtkcellview.[ch] (gtk_cell_view_finalize): remove unused
variable,
(gtk_cell_view_set_value), (gtk_cell_view_set_displayed_model): queue
a resize,
(gtk_cell_view_get_size_of_row): new function,
(gtk_cell_view_set_value), (gtk_cell_view_set_valuesv),
(gtk_cell_view_set_values), (gtk_cell_view_set_model),
(gtk_cell_view_set_displayed_row), (gtk_cell_view_get_displayed_row):
s/cellview/cell_view/ in the function definitions, so they match
with the header file.
* gtk/gtkcombobox.c (gtk_combo_box_remeasure): remove the resize
flag again (:, and use gtk_cell_view_get_size_of_row instead of
the measurer, remove _set_size_request call,
(gtk_combo_box_calc_requested_width): use gtk_cell_view_get_size_of_row
instead of the measurer,
(gtk_combo_box_style_set): queue a resize,
(gtk_combo_box_size_request): update of _remeasure call,
(gtk_combo_box_init), (gtk_combo_box_cell_layout_pack_start),
(gtk_combo_box_cell_layout_pack_end),
(gtk_combo_box_cell_layout_clear),
(gtk_combo_box_set_model): get rid of the measurer,
(gtk_combo_box_cell_layout_add_attribute),
(gtk_combo_box_cell_layout_set_cell_data_func),
(gtk_combo_box_cell_layout_clear_attributes): ditto and queue a
resize instead of calling _remeasure.
2003-11-18 19:02:30 +00:00
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (combo_box));
|
2003-10-01 20:51:54 +00:00
|
|
|
}
|
|
|
|
|
2003-12-19 22:47:20 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_cell_layout_reorder (GtkCellLayout *layout,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
gint position)
|
|
|
|
{
|
|
|
|
ComboCellInfo *info;
|
2004-02-15 23:05:48 +00:00
|
|
|
GtkComboBox *combo_box;
|
2003-12-19 22:47:20 +00:00
|
|
|
GtkWidget *menu;
|
|
|
|
GSList *link;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (layout));
|
|
|
|
g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
|
|
|
|
|
2004-02-15 23:05:48 +00:00
|
|
|
combo_box = GTK_COMBO_BOX (layout);
|
|
|
|
|
2003-12-19 22:47:20 +00:00
|
|
|
info = gtk_combo_box_get_cell_info (combo_box, cell);
|
|
|
|
|
|
|
|
g_return_if_fail (info != NULL);
|
|
|
|
g_return_if_fail (position >= 0);
|
|
|
|
|
|
|
|
link = g_slist_find (combo_box->priv->cells, info);
|
|
|
|
|
|
|
|
g_return_if_fail (link != NULL);
|
|
|
|
|
|
|
|
combo_box->priv->cells = g_slist_remove_link (combo_box->priv->cells, link);
|
|
|
|
combo_box->priv->cells = g_slist_insert (combo_box->priv->cells, info,
|
|
|
|
position);
|
|
|
|
|
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
gtk_cell_layout_reorder (GTK_CELL_LAYOUT (combo_box->priv->cell_view),
|
|
|
|
cell, position);
|
|
|
|
|
|
|
|
if (combo_box->priv->column)
|
|
|
|
gtk_cell_layout_reorder (GTK_CELL_LAYOUT (combo_box->priv->column),
|
|
|
|
cell, position);
|
|
|
|
|
|
|
|
menu = combo_box->priv->popup_widget;
|
|
|
|
if (GTK_IS_MENU (menu))
|
|
|
|
{
|
|
|
|
GList *i, *list;
|
|
|
|
|
|
|
|
list = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
|
|
for (i = list; i; i = i->next)
|
|
|
|
{
|
|
|
|
GtkCellView *view;
|
|
|
|
|
2004-05-10 14:07:35 +00:00
|
|
|
if (GTK_IS_TEAROFF_MENU_ITEM (i->data))
|
|
|
|
continue;
|
|
|
|
|
2004-07-19 19:07:27 +00:00
|
|
|
if (GTK_IS_CELL_VIEW (i->data))
|
2003-12-19 22:47:20 +00:00
|
|
|
view = GTK_CELL_VIEW (i->data);
|
2004-07-19 19:07:27 +00:00
|
|
|
else
|
|
|
|
view = GTK_CELL_VIEW (GTK_BIN (i->data)->child);
|
2003-12-19 22:47:20 +00:00
|
|
|
|
|
|
|
gtk_cell_layout_reorder (GTK_CELL_LAYOUT (view), cell, position);
|
|
|
|
}
|
|
|
|
g_list_free (list);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (combo_box));
|
|
|
|
}
|
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
/*
|
|
|
|
* public API
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_combo_box_new:
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
*
|
|
|
|
* Creates a new empty #GtkComboBox.
|
|
|
|
*
|
|
|
|
* Return value: A new #GtkComboBox.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_combo_box_new (void)
|
|
|
|
{
|
2004-02-05 23:45:21 +00:00
|
|
|
return GTK_WIDGET (g_object_new (GTK_TYPE_COMBO_BOX, NULL));
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_combo_box_new_with_model:
|
2003-10-01 20:51:54 +00:00
|
|
|
* @model: A #GtkTreeModel.
|
|
|
|
*
|
|
|
|
* Creates a new #GtkComboBox with the model initialized to @model.
|
|
|
|
*
|
|
|
|
* Return value: A new #GtkComboBox.
|
2003-10-02 21:30:11 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-10-01 20:51:54 +00:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
gtk_combo_box_new_with_model (GtkTreeModel *model)
|
2003-10-01 20:51:54 +00:00
|
|
|
{
|
|
|
|
GtkComboBox *combo_box;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
|
|
|
|
|
2004-02-05 23:45:21 +00:00
|
|
|
combo_box = GTK_COMBO_BOX (g_object_new (GTK_TYPE_COMBO_BOX,
|
2003-10-01 20:51:54 +00:00
|
|
|
"model", model,
|
|
|
|
NULL));
|
|
|
|
|
|
|
|
return GTK_WIDGET (combo_box);
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
2004-05-06 04:06:35 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_get_wrap_width:
|
|
|
|
* @combo_box: A #GtkComboBox.
|
|
|
|
*
|
|
|
|
* Returns the wrap width which is used to determine the number
|
|
|
|
* of columns for the popup menu. If the wrap width is larger than
|
|
|
|
* 1, the combo box is in table mode.
|
|
|
|
*
|
|
|
|
* Returns: the wrap width.
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
*/
|
|
|
|
gint
|
|
|
|
gtk_combo_box_get_wrap_width (GtkComboBox *combo_box)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
|
|
|
|
|
|
|
|
return combo_box->priv->wrap_width;
|
|
|
|
}
|
|
|
|
|
2003-10-02 21:30:11 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_set_wrap_width:
|
|
|
|
* @combo_box: A #GtkComboBox.
|
|
|
|
* @width: Preferred number of columns.
|
|
|
|
*
|
|
|
|
* Sets the wrap width of @combo_box to be @width. The wrap width is basically
|
|
|
|
* the preferred number of columns when you want to the popup to be layed out
|
|
|
|
* in a table.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-09-26 21:57:06 +00:00
|
|
|
void
|
|
|
|
gtk_combo_box_set_wrap_width (GtkComboBox *combo_box,
|
|
|
|
gint width)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
2004-02-28 00:40:00 +00:00
|
|
|
g_return_if_fail (width >= 0);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-02-23 00:53:05 +00:00
|
|
|
if (width != combo_box->priv->wrap_width)
|
|
|
|
{
|
|
|
|
combo_box->priv->wrap_width = width;
|
2004-03-08 18:39:44 +00:00
|
|
|
|
|
|
|
gtk_combo_box_check_appearance (combo_box);
|
2004-02-23 00:53:05 +00:00
|
|
|
gtk_combo_box_relayout (combo_box);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (combo_box), "wrap_width");
|
|
|
|
}
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
2004-05-06 04:06:35 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_get_row_span_column:
|
|
|
|
* @combo_box: A #GtkComboBox.
|
|
|
|
*
|
|
|
|
* Returns the column with row span information for @combo_box.
|
|
|
|
*
|
|
|
|
* Returns: the row span column.
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
*/
|
|
|
|
gint
|
|
|
|
gtk_combo_box_get_row_span_column (GtkComboBox *combo_box)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
|
|
|
|
|
|
|
|
return combo_box->priv->row_column;
|
|
|
|
}
|
|
|
|
|
2003-10-02 21:30:11 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_set_row_span_column:
|
|
|
|
* @combo_box: A #GtkComboBox.
|
|
|
|
* @row_span: A column in the model passed during construction.
|
|
|
|
*
|
|
|
|
* Sets the column with row span information for @combo_box to be @row_span.
|
|
|
|
* The row span column contains integers which indicate how many rows
|
|
|
|
* an item should span.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-09-26 21:57:06 +00:00
|
|
|
void
|
|
|
|
gtk_combo_box_set_row_span_column (GtkComboBox *combo_box,
|
|
|
|
gint row_span)
|
|
|
|
{
|
|
|
|
gint col;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
|
|
|
|
|
|
col = gtk_tree_model_get_n_columns (combo_box->priv->model);
|
2004-07-07 15:15:35 +00:00
|
|
|
g_return_if_fail (row_span >= -1 && row_span < col);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-02-23 00:53:05 +00:00
|
|
|
if (row_span != combo_box->priv->row_column)
|
|
|
|
{
|
|
|
|
combo_box->priv->row_column = row_span;
|
|
|
|
|
|
|
|
gtk_combo_box_relayout (combo_box);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (combo_box), "row_span_column");
|
|
|
|
}
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
2004-05-06 04:06:35 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_get_column_span_column:
|
|
|
|
* @combo_box: A #GtkComboBox.
|
|
|
|
*
|
|
|
|
* Returns the column with column span information for @combo_box.
|
|
|
|
*
|
|
|
|
* Returns: the column span column.
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
*/
|
|
|
|
gint
|
|
|
|
gtk_combo_box_get_column_span_column (GtkComboBox *combo_box)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
|
|
|
|
|
|
|
|
return combo_box->priv->col_column;
|
|
|
|
}
|
|
|
|
|
2003-10-02 21:30:11 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_set_column_span_column:
|
|
|
|
* @combo_box: A #GtkComboBox.
|
|
|
|
* @column_span: A column in the model passed during construction.
|
|
|
|
*
|
|
|
|
* Sets the column with column span information for @combo_box to be
|
|
|
|
* @column_span. The column span column contains integers which indicate
|
|
|
|
* how many columns an item should span.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-09-26 21:57:06 +00:00
|
|
|
void
|
|
|
|
gtk_combo_box_set_column_span_column (GtkComboBox *combo_box,
|
|
|
|
gint column_span)
|
|
|
|
{
|
|
|
|
gint col;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
|
|
|
|
|
|
col = gtk_tree_model_get_n_columns (combo_box->priv->model);
|
2004-07-07 15:15:35 +00:00
|
|
|
g_return_if_fail (column_span >= -1 && column_span < col);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-02-23 00:53:05 +00:00
|
|
|
if (column_span != combo_box->priv->col_column)
|
|
|
|
{
|
|
|
|
combo_box->priv->col_column = column_span;
|
|
|
|
|
|
|
|
gtk_combo_box_relayout (combo_box);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-02-23 00:53:05 +00:00
|
|
|
g_object_notify (G_OBJECT (combo_box), "column_span_column");
|
|
|
|
}
|
2003-09-26 21:57:06 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 21:30:11 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_get_active:
|
|
|
|
* @combo_box: A #GtkComboBox.
|
|
|
|
*
|
2003-10-15 20:18:01 +00:00
|
|
|
* Returns the index of the currently active item, or -1 if there's no
|
|
|
|
* active item.
|
2003-10-02 21:30:11 +00:00
|
|
|
*
|
2003-10-15 20:18:01 +00:00
|
|
|
* Return value: An integer which is the index of the currently active item, or
|
|
|
|
* -1 if there's no active item.
|
2003-10-02 21:30:11 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-09-26 21:57:06 +00:00
|
|
|
gint
|
|
|
|
gtk_combo_box_get_active (GtkComboBox *combo_box)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
|
|
|
|
|
|
|
|
return combo_box->priv->active_item;
|
|
|
|
}
|
|
|
|
|
2003-10-02 21:30:11 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_set_active:
|
|
|
|
* @combo_box: A #GtkComboBox.
|
2004-06-02 03:16:03 +00:00
|
|
|
* @index_: An index in the model passed during construction, or -1 to have
|
2003-10-15 20:18:01 +00:00
|
|
|
* no active item.
|
2003-10-02 21:30:11 +00:00
|
|
|
*
|
|
|
|
* Sets the active item of @combo_box to be the item at @index.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-09-26 21:57:06 +00:00
|
|
|
void
|
|
|
|
gtk_combo_box_set_active (GtkComboBox *combo_box,
|
2004-06-02 03:16:03 +00:00
|
|
|
gint index_)
|
2003-09-26 21:57:06 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
|
|
/* -1 means "no item selected" */
|
2004-06-02 03:16:03 +00:00
|
|
|
g_return_if_fail (index_ >= -1);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
2004-06-02 03:16:03 +00:00
|
|
|
if (combo_box->priv->active_item == index_)
|
2003-09-26 21:57:06 +00:00
|
|
|
return;
|
2004-03-03 22:30:36 +00:00
|
|
|
|
2004-06-02 03:16:03 +00:00
|
|
|
gtk_combo_box_set_active_internal (combo_box, index_);
|
2004-03-03 22:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
|
|
|
|
gint index)
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
combo_box->priv->active_item = index;
|
|
|
|
|
|
|
|
if (index == -1)
|
|
|
|
{
|
|
|
|
if (combo_box->priv->tree_view)
|
|
|
|
gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (combo_box->priv->tree_view)));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkMenu *menu = GTK_MENU (combo_box->priv->popup_widget);
|
|
|
|
|
|
|
|
if (GTK_IS_MENU (menu))
|
|
|
|
gtk_menu_set_active (menu, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path = gtk_tree_path_new_from_indices (index, -1);
|
|
|
|
|
|
|
|
if (combo_box->priv->tree_view)
|
2004-03-03 22:30:36 +00:00
|
|
|
gtk_tree_view_set_cursor (GTK_TREE_VIEW (combo_box->priv->tree_view), path, NULL, FALSE);
|
2003-09-26 21:57:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkMenu *menu = GTK_MENU (combo_box->priv->popup_widget);
|
|
|
|
|
|
|
|
if (GTK_IS_MENU (menu))
|
|
|
|
gtk_menu_set_active (GTK_MENU (menu), index);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (combo_box->priv->cell_view)
|
2004-03-03 22:30:36 +00:00
|
|
|
gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (combo_box->priv->cell_view), path);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_emit_by_name (combo_box, "changed", NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2003-10-14 20:09:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_combo_box_get_active_iter:
|
|
|
|
* @combo_box: A #GtkComboBox
|
|
|
|
* @iter: The uninitialized #GtkTreeIter.
|
|
|
|
*
|
2004-02-28 00:40:00 +00:00
|
|
|
* Sets @iter to point to the current active item, if it exists.
|
2003-10-14 20:09:39 +00:00
|
|
|
*
|
|
|
|
* Return value: %TRUE, if @iter was set
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gtk_combo_box_get_active_iter (GtkComboBox *combo_box,
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
gint active;
|
|
|
|
gboolean retval;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
|
|
|
|
|
|
|
|
active = gtk_combo_box_get_active (combo_box);
|
|
|
|
if (active < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
path = gtk_tree_path_new_from_indices (active, -1);
|
|
|
|
retval = gtk_tree_model_get_iter (gtk_combo_box_get_model (combo_box),
|
|
|
|
iter, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_combo_box_set_active_iter:
|
|
|
|
* @combo_box: A #GtkComboBox
|
|
|
|
* @iter: The #GtkTreeIter.
|
|
|
|
*
|
2004-02-05 20:35:57 +00:00
|
|
|
* Sets the current active item to be the one referenced by @iter.
|
|
|
|
* @iter must correspond to a path of depth one.
|
2003-10-14 20:09:39 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_combo_box_set_active_iter (GtkComboBox *combo_box,
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
|
|
|
|
|
|
path = gtk_tree_model_get_path (gtk_combo_box_get_model (combo_box), iter);
|
|
|
|
g_return_if_fail (path != NULL);
|
2004-02-05 20:35:57 +00:00
|
|
|
g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
|
2003-10-14 20:09:39 +00:00
|
|
|
|
|
|
|
gtk_combo_box_set_active (combo_box, gtk_tree_path_get_indices (path)[0]);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_set_model:
|
|
|
|
* @combo_box: A #GtkComboBox.
|
|
|
|
* @model: A #GtkTreeModel.
|
|
|
|
*
|
|
|
|
* Sets the model used by @combo_box to be @model. Will unset a
|
|
|
|
* previously set model (if applicable).
|
2004-06-26 04:05:25 +00:00
|
|
|
* If model is %NULL, then it will unset the model.
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_combo_box_set_model (GtkComboBox *combo_box,
|
|
|
|
GtkTreeModel *model)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
2004-06-26 03:39:35 +00:00
|
|
|
|
|
|
|
if (!model)
|
|
|
|
{
|
|
|
|
gtk_combo_box_unset_model (combo_box);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
g_return_if_fail (GTK_IS_TREE_MODEL (model));
|
|
|
|
|
2004-03-08 18:39:44 +00:00
|
|
|
if (model == combo_box->priv->model)
|
|
|
|
return;
|
|
|
|
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
if (combo_box->priv->model)
|
2004-03-08 18:39:44 +00:00
|
|
|
gtk_combo_box_unset_model (combo_box);
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
|
|
|
|
combo_box->priv->model = model;
|
|
|
|
g_object_ref (G_OBJECT (combo_box->priv->model));
|
|
|
|
|
2004-03-08 18:39:44 +00:00
|
|
|
combo_box->priv->inserted_id =
|
|
|
|
g_signal_connect (combo_box->priv->model, "row_inserted",
|
|
|
|
G_CALLBACK (gtk_combo_box_model_row_inserted),
|
|
|
|
combo_box);
|
|
|
|
combo_box->priv->deleted_id =
|
|
|
|
g_signal_connect (combo_box->priv->model, "row_deleted",
|
|
|
|
G_CALLBACK (gtk_combo_box_model_row_deleted),
|
|
|
|
combo_box);
|
|
|
|
combo_box->priv->reordered_id =
|
|
|
|
g_signal_connect (combo_box->priv->model, "rows_reordered",
|
|
|
|
G_CALLBACK (gtk_combo_box_model_rows_reordered),
|
|
|
|
combo_box);
|
|
|
|
combo_box->priv->changed_id =
|
|
|
|
g_signal_connect (combo_box->priv->model, "row_changed",
|
|
|
|
G_CALLBACK (gtk_combo_box_model_row_changed),
|
|
|
|
combo_box);
|
|
|
|
|
|
|
|
if (combo_box->priv->tree_view)
|
|
|
|
{
|
|
|
|
/* list mode */
|
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (combo_box->priv->tree_view),
|
|
|
|
combo_box->priv->model);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* menu mode */
|
|
|
|
if (combo_box->priv->popup_widget)
|
|
|
|
gtk_combo_box_menu_fill (combo_box);
|
|
|
|
|
|
|
|
}
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
|
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view),
|
|
|
|
combo_box->priv->model);
|
|
|
|
}
|
|
|
|
|
2003-10-02 21:30:11 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_get_model
|
|
|
|
* @combo_box: A #GtkComboBox.
|
|
|
|
*
|
|
|
|
* Returns the #GtkTreeModel which is acting as data source for @combo_box.
|
|
|
|
*
|
|
|
|
* Return value: A #GtkTreeModel which was passed during construction.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-09-26 21:57:06 +00:00
|
|
|
GtkTreeModel *
|
|
|
|
gtk_combo_box_get_model (GtkComboBox *combo_box)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
|
|
|
|
|
|
|
|
return combo_box->priv->model;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-01 20:51:54 +00:00
|
|
|
/* convenience API for simple text combos */
|
2003-10-02 21:30:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_combo_box_new_text:
|
|
|
|
*
|
|
|
|
* Convenience function which constructs a new text combo box, which is a
|
|
|
|
* #GtkComboBox just displaying strings. If you use this function to create
|
2004-02-26 21:40:09 +00:00
|
|
|
* a text combo box, you should only manipulate its data source with the
|
2003-10-02 21:30:11 +00:00
|
|
|
* following convenience functions: gtk_combo_box_append_text(),
|
2004-02-26 21:40:09 +00:00
|
|
|
* gtk_combo_box_insert_text(), gtk_combo_box_prepend_text() and
|
|
|
|
* gtk_combo_box_remove_text().
|
2003-10-02 21:30:11 +00:00
|
|
|
*
|
|
|
|
* Return value: A new text combo box.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-09-26 21:57:06 +00:00
|
|
|
GtkWidget *
|
|
|
|
gtk_combo_box_new_text (void)
|
|
|
|
{
|
|
|
|
GtkWidget *combo_box;
|
|
|
|
GtkCellRenderer *cell;
|
|
|
|
GtkListStore *store;
|
|
|
|
|
|
|
|
store = gtk_list_store_new (1, G_TYPE_STRING);
|
Fixes #124373, Murray Cumming.
Mon Nov 17 00:11:21 2003 Kristian Rietveld <kris@gtk.org>
Fixes #124373, Murray Cumming.
* gtk/gtkcombobox.[ch] (gtk_combo_box_class_init): the model property
is no longer construct only,
(gtk_combo_box_unset_model), (gtk_combo_box_set_model_internal),
(gtk_combo_box_menu_fill): new functions,
(gtk_combo_box_menu_setup), (gtk_combo_box_menu_destroy),
(gtk_combo_box_menu_row_*), (gtk_combo_box_list_setup),
(gtk_combo_box_list_destroy): updated,
(gtk_combo_box_new), (gtk_combo_box_new_with_model): new/changed
functions,
(gtk_combo_box_set_model): is now public, updated,
(gtk_combo_box_get_model): small update.
* gtk/gtkcomboboxentry.[ch] (gtk_combo_box_entry_class_init): the
text_column property is no longer construct only,
(gtk_combo_box_entry_set_text_column): now public,
(gtk_combo_box_entry_new), (gtk_combo_box_entry_new_with_model):
new/changed functions.
* tests/testcombo.c: updated.
2003-11-16 23:20:15 +00:00
|
|
|
combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
|
2004-07-22 02:48:11 +00:00
|
|
|
g_object_unref (store);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
cell = gtk_cell_renderer_text_new ();
|
2003-10-01 20:51:54 +00:00
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
|
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
|
|
|
|
"text", 0,
|
|
|
|
NULL);
|
2003-09-26 21:57:06 +00:00
|
|
|
|
|
|
|
return combo_box;
|
|
|
|
}
|
|
|
|
|
2003-10-02 21:30:11 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_append_text:
|
|
|
|
* @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text().
|
|
|
|
* @text: A string.
|
|
|
|
*
|
|
|
|
* Appends @string to the list of strings stored in @combo_box. Note that
|
|
|
|
* you can only use this function with combo boxes constructed with
|
|
|
|
* gtk_combo_box_new_text().
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-09-26 21:57:06 +00:00
|
|
|
void
|
|
|
|
gtk_combo_box_append_text (GtkComboBox *combo_box,
|
|
|
|
const gchar *text)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkListStore *store;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
|
|
g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
|
|
|
|
g_return_if_fail (text != NULL);
|
|
|
|
|
|
|
|
store = GTK_LIST_STORE (combo_box->priv->model);
|
|
|
|
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter, 0, text, -1);
|
|
|
|
}
|
|
|
|
|
2003-10-02 21:30:11 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_insert_text:
|
|
|
|
* @combo_box: A #GtkComboBox constructed using gtk_combo_box_new_text().
|
|
|
|
* @position: An index to insert @text.
|
|
|
|
* @text: A string.
|
|
|
|
*
|
|
|
|
* Inserts @string at @position in the list of strings stored in @combo_box.
|
|
|
|
* Note that you can only use this function with combo boxes constructed
|
|
|
|
* with gtk_combo_box_new_text().
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-09-26 21:57:06 +00:00
|
|
|
void
|
|
|
|
gtk_combo_box_insert_text (GtkComboBox *combo_box,
|
|
|
|
gint position,
|
|
|
|
const gchar *text)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkListStore *store;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
|
|
g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
|
|
|
|
g_return_if_fail (position >= 0);
|
|
|
|
g_return_if_fail (text != NULL);
|
|
|
|
|
|
|
|
store = GTK_LIST_STORE (combo_box->priv->model);
|
|
|
|
|
|
|
|
gtk_list_store_insert (store, &iter, position);
|
|
|
|
gtk_list_store_set (store, &iter, 0, text, -1);
|
|
|
|
}
|
|
|
|
|
2003-10-02 21:30:11 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_prepend_text:
|
|
|
|
* @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
|
|
|
|
* @text: A string.
|
|
|
|
*
|
|
|
|
* Prepends @string to the list of strings stored in @combo_box. Note that
|
|
|
|
* you can only use this function with combo boxes constructed with
|
|
|
|
* gtk_combo_box_new_text().
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
2003-09-26 21:57:06 +00:00
|
|
|
void
|
|
|
|
gtk_combo_box_prepend_text (GtkComboBox *combo_box,
|
|
|
|
const gchar *text)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkListStore *store;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
|
|
g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
|
|
|
|
g_return_if_fail (text != NULL);
|
|
|
|
|
|
|
|
store = GTK_LIST_STORE (combo_box->priv->model);
|
|
|
|
|
|
|
|
gtk_list_store_prepend (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter, 0, text, -1);
|
|
|
|
}
|
2003-11-17 22:24:57 +00:00
|
|
|
|
2003-11-19 22:26:42 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_remove_text:
|
|
|
|
* @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
|
|
|
|
* @position: Index of the item to remove.
|
|
|
|
*
|
|
|
|
* Removes the string at @position from @combo_box. Note that you can only use
|
|
|
|
* this function with combo boxes constructed with gtk_combo_box_new_text().
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_combo_box_remove_text (GtkComboBox *combo_box,
|
|
|
|
gint position)
|
2003-11-17 22:24:57 +00:00
|
|
|
{
|
2003-11-19 22:26:42 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkListStore *store;
|
2003-11-17 22:24:57 +00:00
|
|
|
|
2003-11-19 22:26:42 +00:00
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
|
|
g_return_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model));
|
|
|
|
g_return_if_fail (position >= 0);
|
2003-11-17 22:24:57 +00:00
|
|
|
|
2003-11-19 22:26:42 +00:00
|
|
|
store = GTK_LIST_STORE (combo_box->priv->model);
|
2003-11-17 22:24:57 +00:00
|
|
|
|
2003-11-19 22:26:42 +00:00
|
|
|
if (gtk_tree_model_iter_nth_child (combo_box->priv->model, &iter,
|
|
|
|
NULL, position))
|
|
|
|
gtk_list_store_remove (store, &iter);
|
2003-11-17 22:24:57 +00:00
|
|
|
}
|
2004-02-05 20:35:57 +00:00
|
|
|
|
2004-05-06 03:49:15 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_get_active_text:
|
|
|
|
* @combo_box: A #GtkComboBox constructed with gtk_combo_box_new_text().
|
|
|
|
*
|
|
|
|
* Returns the currently active string in @combo_box or %NULL if none
|
|
|
|
* is selected. Note that you can only use this function with combo
|
|
|
|
* boxes constructed with gtk_combo_box_new_text().
|
|
|
|
*
|
|
|
|
* Returns: a newly allocated string containing the currently active text.
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
gtk_combo_box_get_active_text (GtkComboBox *combo_box)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gchar *text = NULL;
|
|
|
|
|
2004-05-08 16:25:15 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL);
|
|
|
|
g_return_val_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model), NULL);
|
2004-05-06 03:49:15 +00:00
|
|
|
|
|
|
|
if (gtk_combo_box_get_active_iter (combo_box, &iter))
|
|
|
|
gtk_tree_model_get (combo_box->priv->model, &iter,
|
|
|
|
0, &text, -1);
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
2004-02-05 20:35:57 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_combo_box_mnemonic_activate (GtkWidget *widget,
|
|
|
|
gboolean group_cycling)
|
|
|
|
{
|
2004-02-05 22:46:22 +00:00
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
|
|
|
|
|
2004-02-05 23:14:37 +00:00
|
|
|
gtk_widget_grab_focus (combo_box->priv->button);
|
2004-02-05 22:46:22 +00:00
|
|
|
|
2004-02-05 20:35:57 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2004-02-05 22:46:22 +00:00
|
|
|
|
2004-02-24 00:07:15 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_destroy (GtkObject *object)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (object);
|
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
if (combo_box->priv->popup_idle_id > 0)
|
|
|
|
{
|
|
|
|
g_source_remove (combo_box->priv->popup_idle_id);
|
|
|
|
combo_box->priv->popup_idle_id = 0;
|
|
|
|
}
|
|
|
|
|
2004-07-12 16:15:55 +00:00
|
|
|
gtk_combo_box_popdown (combo_box);
|
2004-07-16 20:27:40 +00:00
|
|
|
|
2004-03-13 00:36:27 +00:00
|
|
|
combo_box->priv->destroying = 1;
|
2004-07-16 20:27:40 +00:00
|
|
|
|
2004-02-24 00:07:15 +00:00
|
|
|
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
|
|
|
combo_box->priv->cell_view = NULL;
|
2004-07-16 20:27:40 +00:00
|
|
|
|
2004-03-13 00:36:27 +00:00
|
|
|
combo_box->priv->destroying = 0;
|
2004-02-24 00:07:15 +00:00
|
|
|
}
|
2004-02-05 23:45:21 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (object);
|
2004-02-26 20:51:02 +00:00
|
|
|
GSList *i;
|
2004-02-05 23:45:21 +00:00
|
|
|
|
|
|
|
if (GTK_IS_MENU (combo_box->priv->popup_widget))
|
2004-07-22 02:36:54 +00:00
|
|
|
{
|
|
|
|
gtk_combo_box_menu_destroy (combo_box);
|
|
|
|
gtk_menu_detach (GTK_MENU (combo_box->priv->popup_widget));
|
|
|
|
combo_box->priv->popup_widget = NULL;
|
|
|
|
}
|
2004-02-05 23:45:21 +00:00
|
|
|
|
|
|
|
if (GTK_IS_TREE_VIEW (combo_box->priv->tree_view))
|
|
|
|
gtk_combo_box_list_destroy (combo_box);
|
|
|
|
|
|
|
|
if (combo_box->priv->popup_window)
|
|
|
|
gtk_widget_destroy (combo_box->priv->popup_window);
|
|
|
|
|
2004-03-08 18:39:44 +00:00
|
|
|
gtk_combo_box_unset_model (combo_box);
|
|
|
|
|
2004-02-26 20:51:02 +00:00
|
|
|
for (i = combo_box->priv->cells; i; i = i->next)
|
|
|
|
{
|
|
|
|
ComboCellInfo *info = (ComboCellInfo *)i->data;
|
|
|
|
GSList *list = info->attributes;
|
|
|
|
|
|
|
|
if (info->destroy)
|
|
|
|
info->destroy (info->func_data);
|
|
|
|
|
|
|
|
while (list && list->next)
|
|
|
|
{
|
|
|
|
g_free (list->data);
|
|
|
|
list = list->next->next;
|
|
|
|
}
|
|
|
|
g_slist_free (info->attributes);
|
|
|
|
|
|
|
|
g_object_unref (G_OBJECT (info->cell));
|
|
|
|
g_free (info);
|
|
|
|
}
|
2004-02-11 01:09:25 +00:00
|
|
|
g_slist_free (combo_box->priv->cells);
|
2004-02-05 23:45:21 +00:00
|
|
|
|
2004-02-11 01:09:25 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2004-02-05 23:45:21 +00:00
|
|
|
}
|
2004-05-10 14:07:35 +00:00
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_cell_editable_key_press (GtkWidget *widget,
|
|
|
|
GdkEventKey *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (data);
|
|
|
|
|
|
|
|
if (event->keyval == GDK_Escape)
|
|
|
|
{
|
|
|
|
combo_box->priv->editing_canceled = TRUE;
|
2004-05-10 14:07:35 +00:00
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
|
|
|
|
gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (event->keyval == GDK_Return)
|
|
|
|
{
|
2004-07-19 19:07:27 +00:00
|
|
|
if (GTK_IS_CELL_EDITABLE (combo_box))
|
|
|
|
gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
|
2004-07-16 20:27:40 +00:00
|
|
|
if (GTK_IS_CELL_EDITABLE (combo_box))
|
|
|
|
gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
popdown_idle (gpointer data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (data);
|
|
|
|
|
|
|
|
gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
|
|
|
|
gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
|
|
|
|
|
|
|
|
g_object_unref (combo_box);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
popdown_handler (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
g_idle_add (popdown_idle, g_object_ref (data));
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
popup_idle (gpointer data)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (data);
|
|
|
|
|
|
|
|
if (GTK_IS_MENU (combo_box->priv->popup_widget) &&
|
|
|
|
combo_box->priv->cell_view)
|
|
|
|
g_signal_connect_object (combo_box->priv->popup_widget,
|
|
|
|
"unmap", G_CALLBACK (popdown_handler),
|
|
|
|
combo_box, 0);
|
|
|
|
|
|
|
|
/* we unset this if a menu item is activated */
|
|
|
|
combo_box->priv->editing_canceled = TRUE;
|
|
|
|
gtk_combo_box_popup (combo_box);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
|
|
|
|
GdkEvent *event)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo_box = GTK_COMBO_BOX (cell_editable);
|
|
|
|
|
|
|
|
combo_box->priv->is_cell_renderer = TRUE;
|
|
|
|
|
|
|
|
if (combo_box->priv->cell_view)
|
|
|
|
{
|
|
|
|
g_signal_connect (combo_box->priv->button, "key_press_event",
|
|
|
|
G_CALLBACK (gtk_cell_editable_key_press),
|
|
|
|
cell_editable);
|
|
|
|
|
|
|
|
gtk_widget_grab_focus (combo_box->priv->button);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_signal_connect (GTK_BIN (combo_box)->child, "key_press_event",
|
|
|
|
G_CALLBACK (gtk_cell_editable_key_press),
|
|
|
|
cell_editable);
|
|
|
|
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (GTK_BIN (combo_box)->child));
|
|
|
|
GTK_WIDGET_UNSET_FLAGS (combo_box->priv->button, GTK_CAN_FOCUS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we do the immediate popup only for the optionmenu-like
|
|
|
|
* appearance
|
|
|
|
*/
|
|
|
|
if (combo_box->priv->is_cell_renderer &&
|
|
|
|
combo_box->priv->cell_view && !combo_box->priv->tree_view)
|
|
|
|
combo_box->priv->popup_idle_id = g_idle_add (popup_idle, combo_box);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_combo_box_get_add_tearoffs:
|
|
|
|
* @combo_box: a #GtkComboBox
|
|
|
|
*
|
|
|
|
* Gets the current value of the :add-tearoffs property.
|
|
|
|
*
|
|
|
|
* Return value: the current value of the :add-tearoffs property.
|
|
|
|
**/
|
2004-05-10 14:07:35 +00:00
|
|
|
gboolean
|
|
|
|
gtk_combo_box_get_add_tearoffs (GtkComboBox *combo_box)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
|
|
|
|
|
|
|
|
return combo_box->priv->add_tearoffs;
|
|
|
|
}
|
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_set_add_tearoffs:
|
|
|
|
* @combo_box: a #GtkComboBox
|
|
|
|
* @add_tearoffs: %TRUE to add tearoff menu items
|
|
|
|
*
|
|
|
|
* Sets whether the popup menu should have a tearoff
|
|
|
|
* menu item.
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
**/
|
2004-05-10 14:07:35 +00:00
|
|
|
void
|
|
|
|
gtk_combo_box_set_add_tearoffs (GtkComboBox *combo_box,
|
|
|
|
gboolean add_tearoffs)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
|
|
|
|
|
|
add_tearoffs = add_tearoffs != FALSE;
|
|
|
|
|
|
|
|
if (combo_box->priv->add_tearoffs != add_tearoffs)
|
|
|
|
{
|
|
|
|
combo_box->priv->add_tearoffs = add_tearoffs;
|
|
|
|
gtk_combo_box_check_appearance (combo_box);
|
|
|
|
gtk_combo_box_relayout (combo_box);
|
|
|
|
g_object_notify (G_OBJECT (combo_box), "add_tearoffs");
|
|
|
|
}
|
|
|
|
}
|
2004-07-07 15:15:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_combo_box_set_row_separator_column:
|
|
|
|
* @combo_box: a #GtkComboBox
|
|
|
|
* @column: the index of a boolean model column, or -1 to
|
|
|
|
* turn off separators
|
|
|
|
*
|
|
|
|
* Sets the row separator column index.
|
|
|
|
* This model column contains boolean values which indicate
|
|
|
|
* whether a row is to be drawn as a separator or now.
|
|
|
|
* Setting the index to -1 turns off separators.
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_combo_box_set_row_separator_column (GtkComboBox *combo_box,
|
|
|
|
gint column)
|
|
|
|
{
|
|
|
|
gint col;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
|
|
|
col = gtk_tree_model_get_n_columns (combo_box->priv->model);
|
|
|
|
g_return_if_fail (column >= -1 && column < col);
|
|
|
|
|
|
|
|
if (combo_box->priv->separator_column != column)
|
|
|
|
{
|
|
|
|
combo_box->priv->separator_column = column;
|
|
|
|
|
2004-07-16 20:27:40 +00:00
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (combo_box));
|
2004-07-07 15:15:35 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (combo_box), "row_separator_column");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_combo_box_get_row_separator_column:
|
|
|
|
* @combo_box: a #GtkComboBox
|
|
|
|
*
|
|
|
|
* Returns the current row separator column index.
|
|
|
|
*
|
|
|
|
* Return value: the row separator column index
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
**/
|
|
|
|
gint
|
|
|
|
gtk_combo_box_get_row_separator_column (GtkComboBox *combo_box)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), -1);
|
|
|
|
|
|
|
|
return combo_box->priv->separator_column;
|
|
|
|
}
|
2004-07-16 20:27:40 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
_gtk_combo_box_editing_canceled (GtkComboBox *combo_box)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), TRUE);
|
|
|
|
|
|
|
|
return combo_box->priv->editing_canceled;
|
|
|
|
}
|