2013-06-10 09:17:10 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2012 Alexander Larsson <alexl@redhat.com>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2013-06-15 16:13:28 +00:00
|
|
|
|
#include "gtklistbox.h"
|
|
|
|
|
#include "gtkwidget.h"
|
|
|
|
|
#include "gtkmarshalers.h"
|
|
|
|
|
#include "gtkprivate.h"
|
|
|
|
|
#include "gtkintl.h"
|
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
#include <float.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "a11y/gtklistboxaccessibleprivate.h"
|
2013-09-22 00:49:18 +00:00
|
|
|
|
#include "a11y/gtklistboxrowaccessible.h"
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SECTION:gtklistbox
|
|
|
|
|
* @Short_description: A list container
|
|
|
|
|
* @Title: GtkListBox
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* @See_also: #GtkScrolledWindow
|
2013-06-10 09:17:10 +00:00
|
|
|
|
*
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* A GtkListBox is a vertical container that contains GtkListBoxRow
|
|
|
|
|
* children. These rows can by dynamically sorted and filtered, and
|
|
|
|
|
* headers can be added dynamically depending on the row content.
|
|
|
|
|
* It also allows keyboard and mouse navigation and selection like
|
|
|
|
|
* a typical list.
|
|
|
|
|
*
|
|
|
|
|
* Using GtkListBox is often an alternative to #GtkTreeView, especially
|
|
|
|
|
* when the list contents has a more complicated layout than what is allowed
|
|
|
|
|
* by a #GtkCellRenderer, or when the contents is interactive (i.e. has a
|
|
|
|
|
* button in it).
|
|
|
|
|
*
|
|
|
|
|
* Although a #GtkListBox must have only #GtkListBoxRow children you can
|
|
|
|
|
* add any kind of widget to it via gtk_container_add(), and a #GtkListBoxRow
|
|
|
|
|
* widget will automatically be inserted between the list and the widget.
|
|
|
|
|
*
|
|
|
|
|
* The GtkListBox widget was added in GTK+ 3.10.
|
2013-06-15 16:13:28 +00:00
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2013-07-02 11:44:17 +00:00
|
|
|
|
typedef struct
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GSequence *children;
|
2013-06-11 12:09:19 +00:00
|
|
|
|
GHashTable *header_hash;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2013-06-11 14:53:31 +00:00
|
|
|
|
GtkWidget *placeholder;
|
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkListBoxSortFunc sort_func;
|
|
|
|
|
gpointer sort_func_target;
|
|
|
|
|
GDestroyNotify sort_func_target_destroy_notify;
|
|
|
|
|
|
|
|
|
|
GtkListBoxFilterFunc filter_func;
|
|
|
|
|
gpointer filter_func_target;
|
|
|
|
|
GDestroyNotify filter_func_target_destroy_notify;
|
|
|
|
|
|
2013-06-11 12:09:19 +00:00
|
|
|
|
GtkListBoxUpdateHeaderFunc update_header_func;
|
|
|
|
|
gpointer update_header_func_target;
|
|
|
|
|
GDestroyNotify update_header_func_target_destroy_notify;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
GtkListBoxRow *selected_row;
|
|
|
|
|
GtkListBoxRow *prelight_row;
|
|
|
|
|
GtkListBoxRow *cursor_row;
|
|
|
|
|
|
|
|
|
|
gboolean active_row_active;
|
|
|
|
|
GtkListBoxRow *active_row;
|
|
|
|
|
|
|
|
|
|
GtkSelectionMode selection_mode;
|
|
|
|
|
|
|
|
|
|
GtkAdjustment *adjustment;
|
|
|
|
|
gboolean activate_single_click;
|
|
|
|
|
|
|
|
|
|
/* DnD */
|
|
|
|
|
GtkListBoxRow *drag_highlighted_row;
|
2013-06-11 14:20:45 +00:00
|
|
|
|
|
|
|
|
|
int n_visible_rows;
|
2013-06-17 13:13:17 +00:00
|
|
|
|
gboolean in_widget;
|
2013-07-02 11:44:17 +00:00
|
|
|
|
} GtkListBoxPrivate;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2013-07-02 11:44:17 +00:00
|
|
|
|
typedef struct
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GSequenceIter *iter;
|
2013-06-11 12:09:19 +00:00
|
|
|
|
GtkWidget *header;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
gint y;
|
|
|
|
|
gint height;
|
2013-06-11 14:13:00 +00:00
|
|
|
|
gboolean visible;
|
2014-03-29 01:34:39 +00:00
|
|
|
|
gboolean selected;
|
2013-07-02 11:44:17 +00:00
|
|
|
|
} GtkListBoxRowPrivate;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
ROW_SELECTED,
|
|
|
|
|
ROW_ACTIVATED,
|
|
|
|
|
ACTIVATE_CURSOR_ROW,
|
|
|
|
|
TOGGLE_CURSOR_ROW,
|
|
|
|
|
MOVE_CURSOR,
|
2014-03-28 23:21:57 +00:00
|
|
|
|
SELECTED_ROWS_CHANGED,
|
|
|
|
|
SELECT_ALL,
|
|
|
|
|
UNSELECT_ALL,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
2013-09-10 12:12:07 +00:00
|
|
|
|
enum {
|
|
|
|
|
ROW__ACTIVATE,
|
|
|
|
|
ROW__LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_SELECTION_MODE,
|
|
|
|
|
PROP_ACTIVATE_ON_SINGLE_CLICK,
|
|
|
|
|
LAST_PROPERTY
|
|
|
|
|
};
|
|
|
|
|
|
2014-03-29 01:34:39 +00:00
|
|
|
|
#define BOX_PRIV(box) ((GtkListBoxPrivate*)gtk_list_box_get_instance_private ((GtkListBox*)(box)))
|
|
|
|
|
#define ROW_PRIV(row) ((GtkListBoxRowPrivate*)gtk_list_box_row_get_instance_private ((GtkListBoxRow*)(row)))
|
|
|
|
|
|
2013-07-02 11:44:17 +00:00
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkListBox, gtk_list_box, GTK_TYPE_CONTAINER)
|
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkListBoxRow, gtk_list_box_row, GTK_TYPE_BIN)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
static void gtk_list_box_apply_filter_all (GtkListBox *box);
|
|
|
|
|
static void gtk_list_box_update_header (GtkListBox *box,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GSequenceIter *iter);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
static GSequenceIter * gtk_list_box_get_next_visible (GtkListBox *box,
|
|
|
|
|
GSequenceIter *iter);
|
|
|
|
|
static void gtk_list_box_apply_filter (GtkListBox *box,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkListBoxRow *row);
|
|
|
|
|
static void gtk_list_box_add_move_binding (GtkBindingSet *binding_set,
|
|
|
|
|
guint keyval,
|
|
|
|
|
GdkModifierType modmask,
|
|
|
|
|
GtkMovementStep step,
|
|
|
|
|
gint count);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
static void gtk_list_box_update_cursor (GtkListBox *box,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkListBoxRow *row);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
static void gtk_list_box_select_and_activate (GtkListBox *box,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkListBoxRow *row);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
static void gtk_list_box_update_prelight (GtkListBox *box,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkListBoxRow *row);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
static void gtk_list_box_update_active (GtkListBox *box,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkListBoxRow *row);
|
2013-09-28 02:00:38 +00:00
|
|
|
|
static gboolean gtk_list_box_enter_notify_event (GtkWidget *widget,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GdkEventCrossing *event);
|
2013-09-28 02:00:38 +00:00
|
|
|
|
static gboolean gtk_list_box_leave_notify_event (GtkWidget *widget,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GdkEventCrossing *event);
|
2013-09-28 02:00:38 +00:00
|
|
|
|
static gboolean gtk_list_box_motion_notify_event (GtkWidget *widget,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GdkEventMotion *event);
|
2013-09-28 02:00:38 +00:00
|
|
|
|
static gboolean gtk_list_box_button_press_event (GtkWidget *widget,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GdkEventButton *event);
|
2013-09-28 02:00:38 +00:00
|
|
|
|
static gboolean gtk_list_box_button_release_event (GtkWidget *widget,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GdkEventButton *event);
|
2013-09-28 02:00:38 +00:00
|
|
|
|
static void gtk_list_box_show (GtkWidget *widget);
|
|
|
|
|
static gboolean gtk_list_box_focus (GtkWidget *widget,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkDirectionType direction);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
static GSequenceIter* gtk_list_box_get_previous_visible (GtkListBox *box,
|
|
|
|
|
GSequenceIter *iter);
|
|
|
|
|
static GtkListBoxRow *gtk_list_box_get_first_focusable (GtkListBox *box);
|
|
|
|
|
static GtkListBoxRow *gtk_list_box_get_last_focusable (GtkListBox *box);
|
2013-09-28 02:00:38 +00:00
|
|
|
|
static gboolean gtk_list_box_draw (GtkWidget *widget,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
cairo_t *cr);
|
2013-09-28 02:00:38 +00:00
|
|
|
|
static void gtk_list_box_realize (GtkWidget *widget);
|
|
|
|
|
static void gtk_list_box_add (GtkContainer *container,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkWidget *widget);
|
2013-09-28 02:00:38 +00:00
|
|
|
|
static void gtk_list_box_remove (GtkContainer *container,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkWidget *widget);
|
2013-09-28 02:00:38 +00:00
|
|
|
|
static void gtk_list_box_forall_internal (GtkContainer *container,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
gboolean include_internals,
|
|
|
|
|
GtkCallback callback,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
gpointer callback_target);
|
2013-09-28 02:00:38 +00:00
|
|
|
|
static void gtk_list_box_compute_expand_internal (GtkWidget *widget,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
gboolean *hexpand,
|
|
|
|
|
gboolean *vexpand);
|
2013-09-28 02:00:38 +00:00
|
|
|
|
static GType gtk_list_box_child_type (GtkContainer *container);
|
|
|
|
|
static GtkSizeRequestMode gtk_list_box_get_request_mode (GtkWidget *widget);
|
|
|
|
|
static void gtk_list_box_size_allocate (GtkWidget *widget,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkAllocation *allocation);
|
2013-09-28 02:00:38 +00:00
|
|
|
|
static void gtk_list_box_drag_leave (GtkWidget *widget,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
guint time_);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
static void gtk_list_box_activate_cursor_row (GtkListBox *box);
|
|
|
|
|
static void gtk_list_box_toggle_cursor_row (GtkListBox *box);
|
|
|
|
|
static void gtk_list_box_move_cursor (GtkListBox *box,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkMovementStep step,
|
|
|
|
|
gint count);
|
|
|
|
|
static void gtk_list_box_finalize (GObject *obj);
|
2013-09-28 02:00:38 +00:00
|
|
|
|
static void gtk_list_box_parent_set (GtkWidget *widget,
|
2013-06-10 14:07:20 +00:00
|
|
|
|
GtkWidget *prev_parent);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2013-09-28 02:00:38 +00:00
|
|
|
|
static void gtk_list_box_get_preferred_height (GtkWidget *widget,
|
|
|
|
|
gint *minimum_height,
|
|
|
|
|
gint *natural_height);
|
|
|
|
|
static void gtk_list_box_get_preferred_height_for_width (GtkWidget *widget,
|
|
|
|
|
gint width,
|
|
|
|
|
gint *minimum_height,
|
|
|
|
|
gint *natural_height);
|
|
|
|
|
static void gtk_list_box_get_preferred_width (GtkWidget *widget,
|
|
|
|
|
gint *minimum_width,
|
|
|
|
|
gint *natural_width);
|
|
|
|
|
static void gtk_list_box_get_preferred_width_for_height (GtkWidget *widget,
|
|
|
|
|
gint height,
|
|
|
|
|
gint *minimum_width,
|
|
|
|
|
gint *natural_width);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 01:34:39 +00:00
|
|
|
|
static void gtk_list_box_select_row_internal (GtkListBox *box,
|
|
|
|
|
GtkListBoxRow *row);
|
|
|
|
|
static void gtk_list_box_unselect_row_internal (GtkListBox *box,
|
|
|
|
|
GtkListBoxRow *row);
|
|
|
|
|
static void gtk_list_box_select_all_between (GtkListBox *box,
|
|
|
|
|
GtkListBoxRow *row1,
|
|
|
|
|
GtkListBoxRow *row2,
|
|
|
|
|
gboolean modify);
|
|
|
|
|
static gboolean gtk_list_box_unselect_all_internal (GtkListBox *box);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
static void gtk_list_box_selected_rows_changed (GtkListBox *box);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
static GParamSpec *properties[LAST_PROPERTY] = { NULL, };
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
2013-09-10 12:12:07 +00:00
|
|
|
|
static guint row_signals[ROW__LAST_SIGNAL] = { 0 };
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2013-06-11 10:59:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_new:
|
|
|
|
|
*
|
|
|
|
|
* Creates a new #GtkListBox container.
|
|
|
|
|
*
|
|
|
|
|
* Returns: a new #GtkListBox
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkWidget *
|
|
|
|
|
gtk_list_box_new (void)
|
|
|
|
|
{
|
|
|
|
|
return g_object_new (GTK_TYPE_LIST_BOX, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_init (GtkListBox *box)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
|
|
|
|
GtkWidget *widget = GTK_WIDGET (box);
|
2013-06-12 10:00:11 +00:00
|
|
|
|
GtkStyleContext *context;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_widget_set_has_window (widget, TRUE);
|
|
|
|
|
gtk_widget_set_redraw_on_allocate (widget, TRUE);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
priv->selection_mode = GTK_SELECTION_SINGLE;
|
|
|
|
|
priv->activate_single_click = TRUE;
|
|
|
|
|
|
|
|
|
|
priv->children = g_sequence_new (NULL);
|
2013-06-11 12:09:19 +00:00
|
|
|
|
priv->header_hash = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, NULL);
|
2013-06-12 10:00:11 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
context = gtk_widget_get_style_context (widget);
|
2013-06-12 10:00:11 +00:00
|
|
|
|
gtk_style_context_add_class (context, GTK_STYLE_CLASS_LIST);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_list_box_get_property (GObject *obj,
|
|
|
|
|
guint property_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (obj);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_SELECTION_MODE:
|
2013-07-02 11:44:17 +00:00
|
|
|
|
g_value_set_enum (value, priv->selection_mode);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_ACTIVATE_ON_SINGLE_CLICK:
|
2013-07-02 11:44:17 +00:00
|
|
|
|
g_value_set_boolean (value, priv->activate_single_click);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_list_box_set_property (GObject *obj,
|
|
|
|
|
guint property_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBox *box = GTK_LIST_BOX (obj);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_SELECTION_MODE:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_set_selection_mode (box, g_value_get_enum (value));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_ACTIVATE_ON_SINGLE_CLICK:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_set_activate_on_single_click (box, g_value_get_boolean (value));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_list_box_finalize (GObject *obj)
|
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (obj);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
if (priv->sort_func_target_destroy_notify != NULL)
|
|
|
|
|
priv->sort_func_target_destroy_notify (priv->sort_func_target);
|
|
|
|
|
if (priv->filter_func_target_destroy_notify != NULL)
|
|
|
|
|
priv->filter_func_target_destroy_notify (priv->filter_func_target);
|
2013-06-11 12:09:19 +00:00
|
|
|
|
if (priv->update_header_func_target_destroy_notify != NULL)
|
|
|
|
|
priv->update_header_func_target_destroy_notify (priv->update_header_func_target);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
g_clear_object (&priv->adjustment);
|
|
|
|
|
g_clear_object (&priv->drag_highlighted_row);
|
|
|
|
|
|
|
|
|
|
g_sequence_free (priv->children);
|
2013-06-11 12:09:19 +00:00
|
|
|
|
g_hash_table_unref (priv->header_hash);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_list_box_parent_class)->finalize (obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_list_box_class_init (GtkListBoxClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
|
|
|
|
|
GtkBindingSet *binding_set;
|
|
|
|
|
|
|
|
|
|
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_LIST_BOX_ACCESSIBLE);
|
|
|
|
|
|
|
|
|
|
object_class->get_property = gtk_list_box_get_property;
|
|
|
|
|
object_class->set_property = gtk_list_box_set_property;
|
|
|
|
|
object_class->finalize = gtk_list_box_finalize;
|
2013-09-28 02:00:38 +00:00
|
|
|
|
widget_class->enter_notify_event = gtk_list_box_enter_notify_event;
|
|
|
|
|
widget_class->leave_notify_event = gtk_list_box_leave_notify_event;
|
|
|
|
|
widget_class->motion_notify_event = gtk_list_box_motion_notify_event;
|
|
|
|
|
widget_class->button_press_event = gtk_list_box_button_press_event;
|
|
|
|
|
widget_class->button_release_event = gtk_list_box_button_release_event;
|
|
|
|
|
widget_class->show = gtk_list_box_show;
|
|
|
|
|
widget_class->focus = gtk_list_box_focus;
|
|
|
|
|
widget_class->draw = gtk_list_box_draw;
|
|
|
|
|
widget_class->realize = gtk_list_box_realize;
|
|
|
|
|
widget_class->compute_expand = gtk_list_box_compute_expand_internal;
|
|
|
|
|
widget_class->get_request_mode = gtk_list_box_get_request_mode;
|
|
|
|
|
widget_class->get_preferred_height = gtk_list_box_get_preferred_height;
|
|
|
|
|
widget_class->get_preferred_height_for_width = gtk_list_box_get_preferred_height_for_width;
|
|
|
|
|
widget_class->get_preferred_width = gtk_list_box_get_preferred_width;
|
|
|
|
|
widget_class->get_preferred_width_for_height = gtk_list_box_get_preferred_width_for_height;
|
|
|
|
|
widget_class->size_allocate = gtk_list_box_size_allocate;
|
|
|
|
|
widget_class->drag_leave = gtk_list_box_drag_leave;
|
|
|
|
|
widget_class->parent_set = gtk_list_box_parent_set;
|
|
|
|
|
container_class->add = gtk_list_box_add;
|
|
|
|
|
container_class->remove = gtk_list_box_remove;
|
|
|
|
|
container_class->forall = gtk_list_box_forall_internal;
|
|
|
|
|
container_class->child_type = gtk_list_box_child_type;
|
|
|
|
|
klass->activate_cursor_row = gtk_list_box_activate_cursor_row;
|
|
|
|
|
klass->toggle_cursor_row = gtk_list_box_toggle_cursor_row;
|
|
|
|
|
klass->move_cursor = gtk_list_box_move_cursor;
|
2014-03-29 01:34:39 +00:00
|
|
|
|
klass->select_all = gtk_list_box_select_all;
|
|
|
|
|
klass->unselect_all = gtk_list_box_unselect_all;
|
|
|
|
|
klass->selected_rows_changed = gtk_list_box_selected_rows_changed;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
properties[PROP_SELECTION_MODE] =
|
|
|
|
|
g_param_spec_enum ("selection-mode",
|
2013-06-15 16:13:28 +00:00
|
|
|
|
P_("Selection mode"),
|
|
|
|
|
P_("The selection mode"),
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GTK_TYPE_SELECTION_MODE,
|
|
|
|
|
GTK_SELECTION_SINGLE,
|
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
|
|
properties[PROP_ACTIVATE_ON_SINGLE_CLICK] =
|
|
|
|
|
g_param_spec_boolean ("activate-on-single-click",
|
2013-06-15 16:13:28 +00:00
|
|
|
|
P_("Activate on Single Click"),
|
|
|
|
|
P_("Activate row on a single click"),
|
2013-06-10 09:17:10 +00:00
|
|
|
|
TRUE,
|
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, LAST_PROPERTY, properties);
|
|
|
|
|
|
2013-06-11 10:59:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkListBox::row-selected:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: the #GtkListBox
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* @row: the selected row
|
|
|
|
|
*
|
|
|
|
|
* The ::row-selected signal is emitted when a new row is selected, or
|
|
|
|
|
* (with a %NULL @row) when the selection is cleared.
|
|
|
|
|
*
|
2014-03-28 23:21:57 +00:00
|
|
|
|
* Also see #GtkListBox::selected-rows-changed.
|
|
|
|
|
*
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* Since: 3.10
|
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
signals[ROW_SELECTED] =
|
|
|
|
|
g_signal_new ("row-selected",
|
|
|
|
|
GTK_TYPE_LIST_BOX,
|
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkListBoxClass, row_selected),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
g_cclosure_marshal_VOID__OBJECT,
|
|
|
|
|
G_TYPE_NONE, 1,
|
2013-06-11 10:59:32 +00:00
|
|
|
|
GTK_TYPE_LIST_BOX_ROW);
|
2013-06-15 16:13:28 +00:00
|
|
|
|
|
2014-03-28 23:21:57 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkListBox::selected-rows-changed:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: the #GtkListBox on wich the signal is emitted
|
2014-03-28 23:21:57 +00:00
|
|
|
|
*
|
|
|
|
|
* The ::selected-rows-changed signal is emitted when the
|
|
|
|
|
* set of selected rows changes.
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.14
|
|
|
|
|
*/
|
|
|
|
|
signals[SELECTED_ROWS_CHANGED] = g_signal_new ("selected-rows-changed",
|
|
|
|
|
GTK_TYPE_LIST_BOX,
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkListBoxClass, selected_rows_changed),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GtkListBox::select-all:
|
|
|
|
|
* @box: the #GtkListBox on which the signal is emitted
|
|
|
|
|
*
|
|
|
|
|
* The ::select-all signal is a [keybinding signal][GtkBindingSignal]
|
|
|
|
|
* which gets emitted to select all children of the box, if the selection
|
|
|
|
|
* mode permits it.
|
|
|
|
|
*
|
|
|
|
|
* The default bindings for this signal is Ctrl-a.
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.14
|
|
|
|
|
*/
|
|
|
|
|
signals[SELECT_ALL] = g_signal_new ("select-all",
|
|
|
|
|
GTK_TYPE_LIST_BOX,
|
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
|
G_STRUCT_OFFSET (GtkListBoxClass, select_all),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GtkListBox::unselect-all:
|
|
|
|
|
* @box: the #GtkListBox on which the signal is emitted
|
|
|
|
|
*
|
|
|
|
|
* The ::unselect-all signal is a [keybinding signal][GtkBindingSignal]
|
|
|
|
|
* which gets emitted to unselect all children of the box, if the selection
|
|
|
|
|
* mode permits it.
|
|
|
|
|
*
|
|
|
|
|
* The default bindings for this signal is Ctrl-Shift-a.
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.14
|
|
|
|
|
*/
|
|
|
|
|
signals[UNSELECT_ALL] = g_signal_new ("unselect-all",
|
|
|
|
|
GTK_TYPE_LIST_BOX,
|
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
|
G_STRUCT_OFFSET (GtkListBoxClass, unselect_all),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
2013-06-11 10:59:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkListBox::row-activated:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: the #GtkListBox
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* @row: the activated row
|
|
|
|
|
*
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* The ::row-activated signal is emitted when a row has been activated by the user.
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
signals[ROW_ACTIVATED] =
|
|
|
|
|
g_signal_new ("row-activated",
|
|
|
|
|
GTK_TYPE_LIST_BOX,
|
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkListBoxClass, row_activated),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
g_cclosure_marshal_VOID__OBJECT,
|
|
|
|
|
G_TYPE_NONE, 1,
|
2013-06-11 10:59:32 +00:00
|
|
|
|
GTK_TYPE_LIST_BOX_ROW);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
signals[ACTIVATE_CURSOR_ROW] =
|
|
|
|
|
g_signal_new ("activate-cursor-row",
|
|
|
|
|
GTK_TYPE_LIST_BOX,
|
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
|
G_STRUCT_OFFSET (GtkListBoxClass, activate_cursor_row),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
signals[TOGGLE_CURSOR_ROW] =
|
|
|
|
|
g_signal_new ("toggle-cursor-row",
|
|
|
|
|
GTK_TYPE_LIST_BOX,
|
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
|
G_STRUCT_OFFSET (GtkListBoxClass, toggle_cursor_row),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
signals[MOVE_CURSOR] =
|
|
|
|
|
g_signal_new ("move-cursor",
|
|
|
|
|
GTK_TYPE_LIST_BOX,
|
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
|
G_STRUCT_OFFSET (GtkListBoxClass, move_cursor),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
_gtk_marshal_VOID__ENUM_INT,
|
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
|
GTK_TYPE_MOVEMENT_STEP, G_TYPE_INT);
|
|
|
|
|
|
|
|
|
|
widget_class->activate_signal = signals[ACTIVATE_CURSOR_ROW];
|
|
|
|
|
|
|
|
|
|
binding_set = gtk_binding_set_by_class (klass);
|
|
|
|
|
gtk_list_box_add_move_binding (binding_set, GDK_KEY_Home, 0,
|
|
|
|
|
GTK_MOVEMENT_BUFFER_ENDS, -1);
|
|
|
|
|
gtk_list_box_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
|
|
|
|
|
GTK_MOVEMENT_BUFFER_ENDS, -1);
|
|
|
|
|
gtk_list_box_add_move_binding (binding_set, GDK_KEY_End, 0,
|
|
|
|
|
GTK_MOVEMENT_BUFFER_ENDS, 1);
|
|
|
|
|
gtk_list_box_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
|
|
|
|
|
GTK_MOVEMENT_BUFFER_ENDS, 1);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
gtk_list_box_add_move_binding (binding_set, GDK_KEY_Up, 0,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GTK_MOVEMENT_DISPLAY_LINES, -1);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
gtk_list_box_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GTK_MOVEMENT_DISPLAY_LINES, -1);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
gtk_list_box_add_move_binding (binding_set, GDK_KEY_Down, 0,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GTK_MOVEMENT_DISPLAY_LINES, 1);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
gtk_list_box_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GTK_MOVEMENT_DISPLAY_LINES, 1);
|
|
|
|
|
gtk_list_box_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
|
|
|
|
|
GTK_MOVEMENT_PAGES, -1);
|
|
|
|
|
gtk_list_box_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
|
|
|
|
|
GTK_MOVEMENT_PAGES, -1);
|
|
|
|
|
gtk_list_box_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
|
|
|
|
|
GTK_MOVEMENT_PAGES, 1);
|
|
|
|
|
gtk_list_box_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
|
|
|
|
|
GTK_MOVEMENT_PAGES, 1);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
|
|
|
|
|
"toggle-cursor-row", 0, NULL);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
|
|
|
|
|
"toggle-cursor-row", 0, NULL);
|
|
|
|
|
|
|
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
|
|
|
|
|
"select-all", 0);
|
|
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
|
|
|
|
|
"unselect-all", 0);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_get_selected_row:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-10 09:17:10 +00:00
|
|
|
|
*
|
|
|
|
|
* Gets the selected row.
|
|
|
|
|
*
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* Note that the box may allow multiple selection, in which
|
|
|
|
|
* case you should use gtk_list_box_selected_foreach() to
|
|
|
|
|
* find all selected rows.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer none): the selected row
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
2013-06-15 16:13:28 +00:00
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkListBoxRow *
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_get_selected_row (GtkListBox *box)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_LIST_BOX (box), NULL);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
return BOX_PRIV (box)->selected_row;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_get_row_at_index:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-15 16:13:28 +00:00
|
|
|
|
* @index_: the index of the row
|
2013-06-10 09:17:10 +00:00
|
|
|
|
*
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* Gets the n-th child in the list (not counting headers).
|
2013-06-10 09:17:10 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: (transfer none): the child #GtkWidget
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
2013-06-15 16:13:28 +00:00
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkListBoxRow *
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_get_row_at_index (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
gint index_)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GSequenceIter *iter;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_LIST_BOX (box), NULL);
|
2013-09-28 01:39:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
iter = g_sequence_get_iter_at_pos (BOX_PRIV (box)->children, index_);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
if (iter)
|
|
|
|
|
return g_sequence_get (iter);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_get_row_at_y:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-10 09:17:10 +00:00
|
|
|
|
* @y: position
|
|
|
|
|
*
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* Gets the row at the @y position.
|
2013-06-10 09:17:10 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: (transfer none): the row
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
2013-06-15 16:13:28 +00:00
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkListBoxRow *
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_get_row_at_y (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
gint y)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row, *found_row;
|
|
|
|
|
GtkListBoxRowPrivate *row_priv;
|
|
|
|
|
GSequenceIter *iter;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_LIST_BOX (box), NULL);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
/* TODO: This should use g_sequence_search */
|
|
|
|
|
|
|
|
|
|
found_row = NULL;
|
2014-03-29 03:07:41 +00:00
|
|
|
|
for (iter = g_sequence_get_begin_iter (BOX_PRIV (box)->children);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
!g_sequence_iter_is_end (iter);
|
|
|
|
|
iter = g_sequence_iter_next (iter))
|
|
|
|
|
{
|
|
|
|
|
row = (GtkListBoxRow*) g_sequence_get (iter);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
row_priv = ROW_PRIV (row);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
if (y >= row_priv->y && y < (row_priv->y + row_priv->height))
|
|
|
|
|
{
|
|
|
|
|
found_row = row;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return found_row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_select_row:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-10 09:17:10 +00:00
|
|
|
|
* @row: (allow-none): The row to select or %NULL
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Make @row the currently selected row.
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
2013-06-10 09:17:10 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_select_row (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GtkListBoxRow *row)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2014-03-28 23:21:57 +00:00
|
|
|
|
g_return_if_fail (row == NULL || GTK_IS_LIST_BOX_ROW (row));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 01:34:39 +00:00
|
|
|
|
if (row)
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_select_row_internal (box, row);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
else
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_unselect_all_internal (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-28 23:21:57 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_unselect_row:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2014-03-28 23:21:57 +00:00
|
|
|
|
* @row: the row to unselected
|
|
|
|
|
*
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* Unselects a single row of @box, if the selection mode allows it.
|
2014-03-28 23:21:57 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.14
|
|
|
|
|
*/
|
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_unselect_row (GtkListBox *box,
|
2014-03-28 23:21:57 +00:00
|
|
|
|
GtkListBoxRow *row)
|
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2014-03-28 23:21:57 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX_ROW (row));
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_unselect_row_internal (box, row);
|
2014-03-28 23:21:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_select_all:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2014-03-28 23:21:57 +00:00
|
|
|
|
*
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* Select all children of @box, if the selection mode allows it.
|
2014-03-28 23:21:57 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.14
|
|
|
|
|
*/
|
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_select_all (GtkListBox *box)
|
2014-03-28 23:21:57 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2014-03-29 01:34:39 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
if (BOX_PRIV (box)->selection_mode != GTK_SELECTION_MULTIPLE)
|
2014-03-29 01:34:39 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
if (g_sequence_get_length (BOX_PRIV (box)->children) > 0)
|
2014-03-29 01:34:39 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_select_all_between (box, NULL, NULL, FALSE);
|
|
|
|
|
g_signal_emit (box, signals[SELECTED_ROWS_CHANGED], 0);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
}
|
2014-03-28 23:21:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_unselect_all:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2014-03-28 23:21:57 +00:00
|
|
|
|
*
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* Unselect all children of @box, if the selection mode allows it.
|
2014-03-28 23:21:57 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.14
|
|
|
|
|
*/
|
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_unselect_all (GtkListBox *box)
|
2014-03-28 23:21:57 +00:00
|
|
|
|
{
|
2014-03-29 01:34:39 +00:00
|
|
|
|
gboolean dirty = FALSE;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2014-03-28 23:21:57 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
if (BOX_PRIV (box)->selection_mode == GTK_SELECTION_BROWSE)
|
2014-03-29 01:34:39 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
dirty = gtk_list_box_unselect_all_internal (box);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
|
|
|
|
|
if (dirty)
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_signal_emit (box, signals[SELECTED_ROWS_CHANGED], 0);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_selected_rows_changed (GtkListBox *box)
|
2014-03-29 01:34:39 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
_gtk_list_box_accessible_selection_changed (box);
|
2014-03-28 23:21:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GtkListBoxForeachFunc:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2014-03-28 23:21:57 +00:00
|
|
|
|
* @row: a #GtkListBoxRow
|
|
|
|
|
* @user_data: (closure): user data
|
|
|
|
|
*
|
|
|
|
|
* A function used by gtk_list_box_selected_foreach().
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* It will be called on every selected child of the @box.
|
2014-03-28 23:21:57 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.14
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_selected_foreach:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2014-03-28 23:21:57 +00:00
|
|
|
|
* @func: (scope call): the function to call for each selected child
|
|
|
|
|
* @data: user data to pass to the function
|
|
|
|
|
*
|
|
|
|
|
* Calls a function for each selected child.
|
|
|
|
|
*
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* Note that the selection cannot be modified from within this function.
|
2014-03-28 23:21:57 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.14
|
|
|
|
|
*/
|
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_selected_foreach (GtkListBox *box,
|
2014-03-28 23:21:57 +00:00
|
|
|
|
GtkListBoxForeachFunc func,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
GSequenceIter *iter;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2014-03-28 23:21:57 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
for (iter = g_sequence_get_begin_iter (BOX_PRIV (box)->children);
|
2014-03-28 23:21:57 +00:00
|
|
|
|
!g_sequence_iter_is_end (iter);
|
|
|
|
|
iter = g_sequence_iter_next (iter))
|
|
|
|
|
{
|
|
|
|
|
row = g_sequence_get (iter);
|
|
|
|
|
if (gtk_list_box_row_is_selected (row))
|
2014-03-29 03:07:41 +00:00
|
|
|
|
(*func) (box, row, data);
|
2014-03-28 23:21:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-13 20:55:28 +00:00
|
|
|
|
* gtk_list_box_get_selected_rows:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2014-03-28 23:21:57 +00:00
|
|
|
|
*
|
|
|
|
|
* Creates a list of all selected children.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (element-type GtkListBoxRow) (transfer container):
|
|
|
|
|
* A #GList containing the #GtkWidget for each selected child.
|
|
|
|
|
* Free with g_list_free() when done.
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.14
|
|
|
|
|
*/
|
|
|
|
|
GList *
|
2014-04-13 20:55:28 +00:00
|
|
|
|
gtk_list_box_get_selected_rows (GtkListBox *box)
|
2014-03-28 23:21:57 +00:00
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
GSequenceIter *iter;
|
|
|
|
|
GList *selected = NULL;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_LIST_BOX (box), NULL);
|
2014-03-28 23:21:57 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
for (iter = g_sequence_get_begin_iter (BOX_PRIV (box)->children);
|
2014-03-28 23:21:57 +00:00
|
|
|
|
!g_sequence_iter_is_end (iter);
|
|
|
|
|
iter = g_sequence_iter_next (iter))
|
|
|
|
|
{
|
|
|
|
|
row = g_sequence_get (iter);
|
|
|
|
|
if (gtk_list_box_row_is_selected (row))
|
|
|
|
|
selected = g_list_prepend (selected, row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return g_list_reverse (selected);
|
|
|
|
|
}
|
2013-06-11 14:53:31 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_set_placeholder:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-11 14:53:31 +00:00
|
|
|
|
* @placeholder: (allow-none): a #GtkWidget or %NULL
|
|
|
|
|
*
|
|
|
|
|
* Sets the placeholder widget that is shown in the list when
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* it doesn't display any visible children.
|
2013-06-11 14:53:31 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
|
|
|
|
*/
|
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_set_placeholder (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GtkWidget *placeholder)
|
2013-06-11 14:53:31 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2013-09-28 01:39:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2013-06-11 14:53:31 +00:00
|
|
|
|
|
|
|
|
|
if (priv->placeholder)
|
|
|
|
|
{
|
|
|
|
|
gtk_widget_unparent (priv->placeholder);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (box));
|
2013-06-11 14:53:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
priv->placeholder = placeholder;
|
|
|
|
|
|
|
|
|
|
if (placeholder)
|
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_widget_set_parent (GTK_WIDGET (placeholder), GTK_WIDGET (box));
|
2013-06-11 14:53:31 +00:00
|
|
|
|
gtk_widget_set_child_visible (GTK_WIDGET (placeholder),
|
|
|
|
|
priv->n_visible_rows == 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-06-11 10:59:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_set_adjustment:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-15 16:13:28 +00:00
|
|
|
|
* @adjustment: (allow-none): the adjustment, or %NULL
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Sets the adjustment (if any) that the widget uses to
|
|
|
|
|
* for vertical scrolling. For instance, this is used
|
|
|
|
|
* to get the page size for PageUp/Down key handling.
|
|
|
|
|
*
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* In the normal case when the @box is packed inside
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* a #GtkScrolledWindow the adjustment from that will
|
|
|
|
|
* be picked up automatically, so there is no need
|
|
|
|
|
* to manually do that.
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_set_adjustment (GtkListBox *box,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkAdjustment *adjustment)
|
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2013-09-28 01:39:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2013-09-04 19:00:23 +00:00
|
|
|
|
g_object_ref_sink (adjustment);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
if (priv->adjustment)
|
|
|
|
|
g_object_unref (priv->adjustment);
|
|
|
|
|
priv->adjustment = adjustment;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-11 10:59:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_get_adjustment:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Gets the adjustment (if any) that the widget uses to
|
|
|
|
|
* for vertical scrolling.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: (transfer none): the adjustment
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkAdjustment *
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_get_adjustment (GtkListBox *box)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_LIST_BOX (box), NULL);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
return BOX_PRIV (box)->adjustment;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-10 14:07:20 +00:00
|
|
|
|
static void
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_parent_set (GtkWidget *widget,
|
|
|
|
|
GtkWidget *prev_parent)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2013-06-10 14:07:20 +00:00
|
|
|
|
GtkWidget *parent;
|
|
|
|
|
GtkAdjustment *adjustment;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2013-06-10 14:07:20 +00:00
|
|
|
|
parent = gtk_widget_get_parent (widget);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2013-06-10 14:07:20 +00:00
|
|
|
|
if (parent && GTK_IS_SCROLLABLE (parent))
|
|
|
|
|
{
|
|
|
|
|
adjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (parent));
|
|
|
|
|
gtk_list_box_set_adjustment (GTK_LIST_BOX (widget), adjustment);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2013-06-11 10:59:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_set_selection_mode:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* @mode: The #GtkSelectionMode
|
|
|
|
|
*
|
|
|
|
|
* Sets how selection works in the listbox.
|
|
|
|
|
* See #GtkSelectionMode for details.
|
|
|
|
|
*
|
|
|
|
|
* Note: #GtkListBox does not support @GTK_SELECTION_MULTIPLE.
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_set_selection_mode (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GtkSelectionMode mode)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
gboolean dirty = FALSE;
|
2013-09-28 01:39:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 01:34:39 +00:00
|
|
|
|
if (priv->selection_mode == mode)
|
|
|
|
|
return;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 01:34:39 +00:00
|
|
|
|
if (mode == GTK_SELECTION_NONE ||
|
|
|
|
|
priv->selection_mode == GTK_SELECTION_MULTIPLE)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
dirty = gtk_list_box_unselect_all_internal (box);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
priv->selected_row = NULL;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
priv->selection_mode = mode;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (box), properties[PROP_SELECTION_MODE]);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
|
|
|
|
|
if (dirty)
|
2014-04-13 20:51:49 +00:00
|
|
|
|
{
|
|
|
|
|
g_signal_emit (box, signals[ROW_SELECTED], 0, NULL);
|
|
|
|
|
g_signal_emit (box, signals[SELECTED_ROWS_CHANGED], 0);
|
|
|
|
|
}
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-11 10:59:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_get_selection_mode:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Gets the selection mode of the listbox.
|
|
|
|
|
*
|
|
|
|
|
* Returns: a #GtkSelectionMode
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkSelectionMode
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_get_selection_mode (GtkListBox *box)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_LIST_BOX (box), GTK_SELECTION_NONE);
|
2013-09-28 01:39:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
return BOX_PRIV (box)->selection_mode;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_set_filter_func:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-15 16:13:28 +00:00
|
|
|
|
* @filter_func: (closure user_data) (allow-none): callback that lets you filter which rows to show
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* @user_data: user data passed to @filter_func
|
|
|
|
|
* @destroy: destroy notifier for @user_data
|
|
|
|
|
*
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* By setting a filter function on the @box one can decide dynamically which
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* of the rows to show. For instance, to implement a search function on a list that
|
|
|
|
|
* filters the original list to only show the matching rows.
|
|
|
|
|
*
|
|
|
|
|
* The @filter_func will be called for each row after the call, and it will
|
|
|
|
|
* continue to be called each time a row changes (via gtk_list_box_row_changed()) or
|
2013-06-11 14:58:22 +00:00
|
|
|
|
* when gtk_list_box_invalidate_filter() is called.
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
2013-06-10 09:17:10 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_set_filter_func (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GtkListBoxFilterFunc filter_func,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
GDestroyNotify destroy)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
if (priv->filter_func_target_destroy_notify != NULL)
|
|
|
|
|
priv->filter_func_target_destroy_notify (priv->filter_func_target);
|
|
|
|
|
|
|
|
|
|
priv->filter_func = filter_func;
|
|
|
|
|
priv->filter_func_target = user_data;
|
|
|
|
|
priv->filter_func_target_destroy_notify = destroy;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_invalidate_filter (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-06-11 12:09:19 +00:00
|
|
|
|
* gtk_list_box_set_header_func:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-15 16:13:28 +00:00
|
|
|
|
* @update_header: (closure user_data) (allow-none): callback that lets you add row headers
|
2013-06-11 12:09:19 +00:00
|
|
|
|
* @user_data: user data passed to @update_header
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* @destroy: destroy notifier for @user_data
|
|
|
|
|
*
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* By setting a header function on the @box one can dynamically add headers
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* in front of rows, depending on the contents of the row and its position in the list.
|
|
|
|
|
* For instance, one could use it to add headers in front of the first item of a
|
|
|
|
|
* new kind, in a list sorted by the kind.
|
|
|
|
|
*
|
2013-06-11 12:09:19 +00:00
|
|
|
|
* The @update_header can look at the current header widget using gtk_list_box_row_get_header()
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* and either update the state of the widget as needed, or set a new one using
|
2013-06-11 12:09:19 +00:00
|
|
|
|
* gtk_list_box_row_set_header(). If no header is needed, set the header to %NULL.
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
2013-06-11 12:09:19 +00:00
|
|
|
|
* Note that you may get many calls @update_header to this for a particular row when e.g.
|
2014-02-07 18:32:47 +00:00
|
|
|
|
* changing things that don’t affect the header. In this case it is important for performance
|
2013-06-11 12:09:19 +00:00
|
|
|
|
* to not blindly replace an exisiting header widh an identical one.
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
2013-06-11 12:09:19 +00:00
|
|
|
|
* The @update_header function will be called for each row after the call, and it will
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* continue to be called each time a row changes (via gtk_list_box_row_changed()) and when
|
|
|
|
|
* the row before changes (either by gtk_list_box_row_changed() on the previous row, or when
|
|
|
|
|
* the previous row becomes a different row). It is also called for all rows when
|
2013-06-11 14:58:22 +00:00
|
|
|
|
* gtk_list_box_invalidate_headers() is called.
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
2013-06-10 09:17:10 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_set_header_func (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GtkListBoxUpdateHeaderFunc update_header,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
GDestroyNotify destroy)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2013-06-11 12:09:19 +00:00
|
|
|
|
if (priv->update_header_func_target_destroy_notify != NULL)
|
|
|
|
|
priv->update_header_func_target_destroy_notify (priv->update_header_func_target);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2013-06-11 12:09:19 +00:00
|
|
|
|
priv->update_header_func = update_header;
|
|
|
|
|
priv->update_header_func_target = user_data;
|
|
|
|
|
priv->update_header_func_target_destroy_notify = destroy;
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_invalidate_headers (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-11 10:59:32 +00:00
|
|
|
|
/**
|
2013-06-11 14:58:22 +00:00
|
|
|
|
* gtk_list_box_invalidate_filter:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Update the filtering for all rows. Call this when result
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* of the filter function on the @box is changed due
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* to an external factor. For instance, this would be used
|
|
|
|
|
* if the filter function just looked for a specific search
|
|
|
|
|
* string and the entry with the search string has changed.
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_invalidate_filter (GtkListBox *box)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_apply_filter_all (box);
|
|
|
|
|
gtk_list_box_invalidate_headers (box);
|
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
|
|
|
|
do_sort (GtkListBoxRow *a,
|
|
|
|
|
GtkListBoxRow *b,
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBox *box)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
return priv->sort_func (a, b, priv->sort_func_target);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-11 10:59:32 +00:00
|
|
|
|
/**
|
2013-06-11 14:58:22 +00:00
|
|
|
|
* gtk_list_box_invalidate_sort:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Update the sorting for all rows. Call this when result
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* of the sort function on the @box is changed due
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* to an external factor.
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_invalidate_sort (GtkListBox *box)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2013-09-28 01:39:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_sequence_sort (priv->children, (GCompareDataFunc)do_sort, box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_invalidate_headers (box);
|
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-11 14:04:58 +00:00
|
|
|
|
static void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_do_reseparate (GtkListBox *box)
|
2013-06-11 14:04:58 +00:00
|
|
|
|
{
|
|
|
|
|
GSequenceIter *iter;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
for (iter = g_sequence_get_begin_iter (BOX_PRIV (box)->children);
|
2013-06-11 14:04:58 +00:00
|
|
|
|
!g_sequence_iter_is_end (iter);
|
|
|
|
|
iter = g_sequence_iter_next (iter))
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_update_header (box, iter);
|
2013-06-11 14:04:58 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (box));
|
2013-06-11 14:04:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-06-11 10:59:32 +00:00
|
|
|
|
/**
|
2013-06-11 14:58:22 +00:00
|
|
|
|
* gtk_list_box_invalidate_headers:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Update the separators for all rows. Call this when result
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* of the header function on the @box is changed due
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* to an external factor.
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_invalidate_headers (GtkListBox *box)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
if (!gtk_widget_get_visible (GTK_WIDGET (box)))
|
2013-06-11 14:04:58 +00:00
|
|
|
|
return;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_do_reseparate (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_set_sort_func:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-15 16:13:28 +00:00
|
|
|
|
* @sort_func: (closure user_data) (allow-none): the sort function
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* @user_data: user data passed to @sort_func
|
|
|
|
|
* @destroy: destroy notifier for @user_data
|
|
|
|
|
*
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* By setting a sort function on the @box one can dynamically reorder the rows
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* of the list, based on the contents of the rows.
|
|
|
|
|
*
|
|
|
|
|
* The @sort_func will be called for each row after the call, and will continue to
|
|
|
|
|
* be called each time a row changes (via gtk_list_box_row_changed()) and when
|
2013-06-11 14:58:22 +00:00
|
|
|
|
* gtk_list_box_invalidate_sort() is called.
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
2013-06-10 09:17:10 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_set_sort_func (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GtkListBoxSortFunc sort_func,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
GDestroyNotify destroy)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
if (priv->sort_func_target_destroy_notify != NULL)
|
|
|
|
|
priv->sort_func_target_destroy_notify (priv->sort_func_target);
|
|
|
|
|
|
|
|
|
|
priv->sort_func = sort_func;
|
|
|
|
|
priv->sort_func_target = user_data;
|
|
|
|
|
priv->sort_func_target_destroy_notify = destroy;
|
2013-09-28 01:39:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_invalidate_sort (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_got_row_changed (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GtkListBoxRow *row)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
|
|
|
|
GtkListBoxRowPrivate *row_priv = ROW_PRIV (row);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GSequenceIter *prev_next, *next;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2013-09-28 01:39:10 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX_ROW (row));
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
prev_next = gtk_list_box_get_next_visible (box, row_priv->iter);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
if (priv->sort_func != NULL)
|
|
|
|
|
{
|
2013-07-02 11:44:17 +00:00
|
|
|
|
g_sequence_sort_changed (row_priv->iter,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
(GCompareDataFunc)do_sort,
|
2014-03-29 03:07:41 +00:00
|
|
|
|
box);
|
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_apply_filter (box, row);
|
|
|
|
|
if (gtk_widget_get_visible (GTK_WIDGET (box)))
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
next = gtk_list_box_get_next_visible (box, row_priv->iter);
|
|
|
|
|
gtk_list_box_update_header (box, row_priv->iter);
|
|
|
|
|
gtk_list_box_update_header (box, next);
|
|
|
|
|
gtk_list_box_update_header (box, prev_next);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-11 10:59:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_set_activate_on_single_click:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* @single: a boolean
|
|
|
|
|
*
|
2013-06-15 16:13:28 +00:00
|
|
|
|
* If @single is %TRUE, rows will be activated when you click on them,
|
|
|
|
|
* otherwise you need to double-click.
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_set_activate_on_single_click (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
gboolean single)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
single = single != FALSE;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
if (BOX_PRIV (box)->activate_single_click == single)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
BOX_PRIV (box)->activate_single_click = single;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (box), properties[PROP_ACTIVATE_ON_SINGLE_CLICK]);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-12 07:40:06 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_get_activate_on_single_click:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-12 07:40:06 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns whether rows activate on single clicks.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if rows are activated on single click, %FALSE otherwise
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_get_activate_on_single_click (GtkListBox *box)
|
2013-06-12 07:40:06 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_LIST_BOX (box), FALSE);
|
2013-06-12 07:40:06 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
return BOX_PRIV (box)->activate_single_click;
|
2013-06-12 07:40:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
static void
|
2013-06-15 16:13:28 +00:00
|
|
|
|
gtk_list_box_add_move_binding (GtkBindingSet *binding_set,
|
|
|
|
|
guint keyval,
|
|
|
|
|
GdkModifierType modmask,
|
|
|
|
|
GtkMovementStep step,
|
|
|
|
|
gint count)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 01:34:39 +00:00
|
|
|
|
GdkDisplay *display;
|
|
|
|
|
GdkModifierType extend_mod_mask = GDK_SHIFT_MASK;
|
|
|
|
|
GdkModifierType modify_mod_mask = GDK_CONTROL_MASK;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 01:34:39 +00:00
|
|
|
|
display = gdk_display_get_default ();
|
|
|
|
|
if (display)
|
|
|
|
|
{
|
|
|
|
|
extend_mod_mask = gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
|
|
|
|
|
GDK_MODIFIER_INTENT_EXTEND_SELECTION);
|
|
|
|
|
modify_mod_mask = gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
|
|
|
|
|
GDK_MODIFIER_INTENT_MODIFY_SELECTION);
|
|
|
|
|
}
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 01:34:39 +00:00
|
|
|
|
gtk_binding_entry_add_signal (binding_set, keyval, modmask,
|
|
|
|
|
"move-cursor", 2,
|
|
|
|
|
GTK_TYPE_MOVEMENT_STEP, step,
|
|
|
|
|
G_TYPE_INT, count,
|
|
|
|
|
NULL);
|
|
|
|
|
gtk_binding_entry_add_signal (binding_set, keyval, modmask | extend_mod_mask,
|
|
|
|
|
"move-cursor", 2,
|
|
|
|
|
GTK_TYPE_MOVEMENT_STEP, step,
|
|
|
|
|
G_TYPE_INT, count,
|
|
|
|
|
NULL);
|
|
|
|
|
gtk_binding_entry_add_signal (binding_set, keyval, modmask | modify_mod_mask,
|
|
|
|
|
"move-cursor", 2,
|
|
|
|
|
GTK_TYPE_MOVEMENT_STEP, step,
|
|
|
|
|
G_TYPE_INT, count,
|
|
|
|
|
NULL);
|
|
|
|
|
gtk_binding_entry_add_signal (binding_set, keyval, modmask | extend_mod_mask | modify_mod_mask,
|
|
|
|
|
"move-cursor", 2,
|
|
|
|
|
GTK_TYPE_MOVEMENT_STEP, step,
|
|
|
|
|
G_TYPE_INT, count,
|
|
|
|
|
NULL);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_update_cursor (GtkListBox *box,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkListBoxRow *row)
|
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
BOX_PRIV (box)->cursor_row = row;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (row));
|
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (row));
|
2014-03-29 03:07:41 +00:00
|
|
|
|
_gtk_list_box_accessible_update_cursor (box, row);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 01:34:39 +00:00
|
|
|
|
static GtkListBox *
|
|
|
|
|
gtk_list_box_row_get_box (GtkListBoxRow *row)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 01:34:39 +00:00
|
|
|
|
GtkWidget *parent;
|
|
|
|
|
|
|
|
|
|
parent = gtk_widget_get_parent (GTK_WIDGET (row));
|
|
|
|
|
if (parent && GTK_IS_LIST_BOX (parent))
|
|
|
|
|
return GTK_LIST_BOX (parent);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
row_is_visible (GtkListBoxRow *row)
|
|
|
|
|
{
|
|
|
|
|
return ROW_PRIV (row)->visible;
|
|
|
|
|
}
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 01:34:39 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gtk_list_box_row_set_selected (GtkListBoxRow *row,
|
|
|
|
|
gboolean selected)
|
|
|
|
|
{
|
2014-03-29 05:03:06 +00:00
|
|
|
|
if (ROW_PRIV (row)->selected != selected)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 05:03:06 +00:00
|
|
|
|
ROW_PRIV (row)->selected = selected;
|
2014-03-29 01:34:39 +00:00
|
|
|
|
if (selected)
|
|
|
|
|
gtk_widget_set_state_flags (GTK_WIDGET (row),
|
|
|
|
|
GTK_STATE_FLAG_SELECTED, FALSE);
|
|
|
|
|
else
|
|
|
|
|
gtk_widget_unset_state_flags (GTK_WIDGET (row),
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GTK_STATE_FLAG_SELECTED);
|
2014-03-28 23:21:57 +00:00
|
|
|
|
|
2014-03-29 01:34:39 +00:00
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (row));
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
2014-03-29 01:34:39 +00:00
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_list_box_unselect_all_internal (GtkListBox *box)
|
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
GSequenceIter *iter;
|
|
|
|
|
gboolean dirty = FALSE;
|
|
|
|
|
|
|
|
|
|
if (BOX_PRIV (box)->selection_mode == GTK_SELECTION_NONE)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
for (iter = g_sequence_get_begin_iter (BOX_PRIV (box)->children);
|
|
|
|
|
!g_sequence_iter_is_end (iter);
|
|
|
|
|
iter = g_sequence_iter_next (iter))
|
|
|
|
|
{
|
|
|
|
|
row = g_sequence_get (iter);
|
|
|
|
|
dirty |= gtk_list_box_row_set_selected (row, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dirty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_list_box_unselect_row_internal (GtkListBox *box,
|
|
|
|
|
GtkListBoxRow *row)
|
|
|
|
|
{
|
|
|
|
|
if (!ROW_PRIV (row)->selected)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (BOX_PRIV (box)->selection_mode == GTK_SELECTION_NONE)
|
|
|
|
|
return;
|
|
|
|
|
else if (BOX_PRIV (box)->selection_mode != GTK_SELECTION_MULTIPLE)
|
|
|
|
|
gtk_list_box_unselect_all_internal (box);
|
|
|
|
|
else
|
|
|
|
|
gtk_list_box_row_set_selected (row, FALSE);
|
|
|
|
|
|
|
|
|
|
g_signal_emit (box, signals[SELECTED_ROWS_CHANGED], 0);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-03-29 01:34:39 +00:00
|
|
|
|
gtk_list_box_select_row_internal (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GtkListBoxRow *row)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 01:34:39 +00:00
|
|
|
|
if (ROW_PRIV (row)->selected)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (BOX_PRIV (box)->selection_mode == GTK_SELECTION_NONE)
|
|
|
|
|
return;
|
|
|
|
|
if (BOX_PRIV (box)->selection_mode != GTK_SELECTION_MULTIPLE)
|
|
|
|
|
gtk_list_box_unselect_all_internal (box);
|
|
|
|
|
|
|
|
|
|
gtk_list_box_row_set_selected (row, TRUE);
|
|
|
|
|
BOX_PRIV (box)->selected_row = row;
|
|
|
|
|
|
2014-04-08 03:17:56 +00:00
|
|
|
|
g_signal_emit (box, signals[ROW_SELECTED], 0, row);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
g_signal_emit (box, signals[SELECTED_ROWS_CHANGED], 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_list_box_select_all_between (GtkListBox *box,
|
|
|
|
|
GtkListBoxRow *row1,
|
|
|
|
|
GtkListBoxRow *row2,
|
|
|
|
|
gboolean modify)
|
|
|
|
|
{
|
|
|
|
|
GSequenceIter *iter, *iter1, *iter2;
|
|
|
|
|
|
|
|
|
|
if (row1)
|
|
|
|
|
iter1 = ROW_PRIV (row1)->iter;
|
|
|
|
|
else
|
|
|
|
|
iter1 = g_sequence_get_begin_iter (BOX_PRIV (box)->children);
|
|
|
|
|
|
|
|
|
|
if (row2)
|
|
|
|
|
iter2 = ROW_PRIV (row2)->iter;
|
|
|
|
|
else
|
|
|
|
|
iter2 = g_sequence_get_end_iter (BOX_PRIV (box)->children);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 01:34:39 +00:00
|
|
|
|
if (g_sequence_iter_compare (iter2, iter1) < 0)
|
|
|
|
|
{
|
|
|
|
|
iter = iter1;
|
|
|
|
|
iter1 = iter2;
|
|
|
|
|
iter2 = iter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (iter = iter1;
|
|
|
|
|
!g_sequence_iter_is_end (iter);
|
|
|
|
|
iter = g_sequence_iter_next (iter))
|
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
|
|
|
|
|
row = GTK_LIST_BOX_ROW (g_sequence_get (iter));
|
|
|
|
|
if (row_is_visible (row))
|
|
|
|
|
{
|
|
|
|
|
if (modify)
|
|
|
|
|
gtk_list_box_row_set_selected (row, !ROW_PRIV (row)->selected);
|
|
|
|
|
else
|
|
|
|
|
gtk_list_box_row_set_selected (row, TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (g_sequence_iter_compare (iter, iter2) == 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_list_box_update_selection (GtkListBox *box,
|
|
|
|
|
GtkListBoxRow *row,
|
|
|
|
|
gboolean modify,
|
|
|
|
|
gboolean extend)
|
|
|
|
|
{
|
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
|
|
|
|
|
|
|
|
|
gtk_list_box_update_cursor (box, row);
|
|
|
|
|
|
|
|
|
|
if (priv->selection_mode == GTK_SELECTION_NONE)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (priv->selection_mode == GTK_SELECTION_BROWSE)
|
|
|
|
|
{
|
|
|
|
|
gtk_list_box_unselect_all_internal (box);
|
|
|
|
|
gtk_list_box_row_set_selected (row, TRUE);
|
|
|
|
|
priv->selected_row = row;
|
|
|
|
|
}
|
|
|
|
|
else if (priv->selection_mode == GTK_SELECTION_SINGLE)
|
|
|
|
|
{
|
|
|
|
|
gboolean was_selected;
|
|
|
|
|
|
|
|
|
|
was_selected = ROW_PRIV (row)->selected;
|
|
|
|
|
gtk_list_box_unselect_all_internal (box);
|
|
|
|
|
gtk_list_box_row_set_selected (row, modify ? !was_selected : TRUE);
|
|
|
|
|
priv->selected_row = ROW_PRIV (row)->selected ? row : NULL;
|
|
|
|
|
}
|
|
|
|
|
else /* GTK_SELECTION_MULTIPLE */
|
|
|
|
|
{
|
|
|
|
|
if (extend)
|
|
|
|
|
{
|
|
|
|
|
gtk_list_box_unselect_all_internal (box);
|
|
|
|
|
if (priv->selected_row == NULL)
|
|
|
|
|
{
|
|
|
|
|
gtk_list_box_row_set_selected (row, TRUE);
|
|
|
|
|
priv->selected_row = row;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
gtk_list_box_select_all_between (box, priv->selected_row, row, FALSE);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (modify)
|
|
|
|
|
{
|
|
|
|
|
gtk_list_box_row_set_selected (row, !ROW_PRIV (row)->selected);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gtk_list_box_unselect_all_internal (box);
|
|
|
|
|
gtk_list_box_row_set_selected (row, !ROW_PRIV (row)->selected);
|
|
|
|
|
priv->selected_row = row;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_signal_emit (box, signals[SELECTED_ROWS_CHANGED], 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_list_box_select_and_activate (GtkListBox *box,
|
|
|
|
|
GtkListBoxRow *row)
|
|
|
|
|
{
|
2013-06-10 09:17:10 +00:00
|
|
|
|
if (row != NULL)
|
2014-03-29 01:34:39 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_list_box_select_row_internal (box, row);
|
|
|
|
|
gtk_list_box_update_cursor (box, row);
|
|
|
|
|
g_signal_emit (box, signals[ROW_ACTIVATED], 0, row);
|
|
|
|
|
}
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_update_prelight (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GtkListBoxRow *row)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
if (row != priv->prelight_row)
|
|
|
|
|
{
|
|
|
|
|
if (priv->prelight_row)
|
|
|
|
|
gtk_widget_unset_state_flags (GTK_WIDGET (priv->prelight_row),
|
|
|
|
|
GTK_STATE_FLAG_PRELIGHT);
|
2013-07-29 09:23:58 +00:00
|
|
|
|
|
|
|
|
|
if (row != NULL && gtk_widget_is_sensitive (GTK_WIDGET (row)))
|
|
|
|
|
{
|
|
|
|
|
priv->prelight_row = row;
|
|
|
|
|
gtk_widget_set_state_flags (GTK_WIDGET (priv->prelight_row),
|
|
|
|
|
GTK_STATE_FLAG_PRELIGHT,
|
|
|
|
|
FALSE);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
priv->prelight_row = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_update_active (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GtkListBoxRow *row)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
gboolean val;
|
|
|
|
|
|
|
|
|
|
val = priv->active_row == row;
|
|
|
|
|
if (priv->active_row != NULL &&
|
|
|
|
|
val != priv->active_row_active)
|
|
|
|
|
{
|
|
|
|
|
priv->active_row_active = val;
|
|
|
|
|
if (priv->active_row_active)
|
|
|
|
|
gtk_widget_set_state_flags (GTK_WIDGET (priv->active_row),
|
|
|
|
|
GTK_STATE_FLAG_ACTIVE,
|
|
|
|
|
FALSE);
|
|
|
|
|
else
|
|
|
|
|
gtk_widget_unset_state_flags (GTK_WIDGET (priv->active_row),
|
|
|
|
|
GTK_STATE_FLAG_ACTIVE);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_enter_notify_event (GtkWidget *widget,
|
|
|
|
|
GdkEventCrossing *event)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBox *box = GTK_LIST_BOX (widget);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
if (event->window != gtk_widget_get_window (widget))
|
2013-06-10 09:17:10 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
BOX_PRIV (box)->in_widget = TRUE;
|
2013-06-17 13:13:17 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
row = gtk_list_box_get_row_at_y (box, event->y);
|
|
|
|
|
gtk_list_box_update_prelight (box, row);
|
|
|
|
|
gtk_list_box_update_active (box, row);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_leave_notify_event (GtkWidget *widget,
|
|
|
|
|
GdkEventCrossing *event)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBox *box = GTK_LIST_BOX (widget);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkListBoxRow *row = NULL;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
if (event->window != gtk_widget_get_window (widget))
|
2013-06-10 09:17:10 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (event->detail != GDK_NOTIFY_INFERIOR)
|
2013-06-17 13:13:17 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
BOX_PRIV (box)->in_widget = FALSE;
|
2013-06-17 13:13:17 +00:00
|
|
|
|
row = NULL;
|
|
|
|
|
}
|
2013-06-10 09:17:10 +00:00
|
|
|
|
else
|
2014-03-29 03:07:41 +00:00
|
|
|
|
row = gtk_list_box_get_row_at_y (box, event->y);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_update_prelight (box, row);
|
|
|
|
|
gtk_list_box_update_active (box, row);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_motion_notify_event (GtkWidget *widget,
|
|
|
|
|
GdkEventMotion *event)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBox *box = GTK_LIST_BOX (widget);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
GdkWindow *window, *event_window;
|
|
|
|
|
gint relative_y;
|
|
|
|
|
gdouble parent_y;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
if (!BOX_PRIV (box)->in_widget)
|
2013-06-17 13:13:17 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
window = gtk_widget_get_window (widget);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
event_window = event->window;
|
|
|
|
|
relative_y = event->y;
|
|
|
|
|
|
|
|
|
|
while ((event_window != NULL) && (event_window != window))
|
|
|
|
|
{
|
|
|
|
|
gdk_window_coords_to_parent (event_window, 0, relative_y, NULL, &parent_y);
|
|
|
|
|
relative_y = parent_y;
|
|
|
|
|
event_window = gdk_window_get_effective_parent (event_window);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
row = gtk_list_box_get_row_at_y (box, relative_y);
|
|
|
|
|
gtk_list_box_update_prelight (box, row);
|
|
|
|
|
gtk_list_box_update_active (box, row);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_button_press_event (GtkWidget *widget,
|
|
|
|
|
GdkEventButton *event)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBox *box = GTK_LIST_BOX (widget);
|
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2014-01-28 15:44:01 +00:00
|
|
|
|
gboolean retval = GDK_EVENT_PROPAGATE;
|
2013-06-17 12:52:05 +00:00
|
|
|
|
GdkWindow *window;
|
|
|
|
|
double x, y;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
if (event->button == GDK_BUTTON_PRIMARY)
|
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row;
|
2013-06-11 13:04:02 +00:00
|
|
|
|
|
|
|
|
|
priv->active_row = NULL;
|
|
|
|
|
|
2013-06-17 12:52:05 +00:00
|
|
|
|
window = event->window;
|
|
|
|
|
x = event->x;
|
|
|
|
|
y = event->y;
|
|
|
|
|
|
|
|
|
|
while (window && window != gtk_widget_get_window (widget))
|
|
|
|
|
{
|
|
|
|
|
gdk_window_coords_to_parent (window, x, y, &x, &y);
|
|
|
|
|
window = gdk_window_get_effective_parent (window);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
row = gtk_list_box_get_row_at_y (box, y);
|
2013-07-29 09:23:58 +00:00
|
|
|
|
if (row != NULL && gtk_widget_is_sensitive (GTK_WIDGET (row)))
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 01:34:39 +00:00
|
|
|
|
priv->active_row = row;
|
|
|
|
|
priv->active_row_active = TRUE;
|
|
|
|
|
gtk_widget_set_state_flags (GTK_WIDGET (priv->active_row),
|
|
|
|
|
GTK_STATE_FLAG_ACTIVE,
|
|
|
|
|
FALSE);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (box));
|
2014-03-29 01:34:39 +00:00
|
|
|
|
if (event->type == GDK_2BUTTON_PRESS &&
|
|
|
|
|
!priv->activate_single_click)
|
2013-06-11 13:04:02 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_signal_emit (box, signals[ROW_ACTIVATED], 0, row);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
retval = GDK_EVENT_STOP;
|
2013-06-11 13:04:02 +00:00
|
|
|
|
}
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 15:44:01 +00:00
|
|
|
|
return retval;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 01:34:39 +00:00
|
|
|
|
static void
|
|
|
|
|
get_current_selection_modifiers (GtkWidget *widget,
|
|
|
|
|
gboolean *modify,
|
|
|
|
|
gboolean *extend)
|
|
|
|
|
{
|
|
|
|
|
GdkModifierType state = 0;
|
|
|
|
|
GdkModifierType mask;
|
|
|
|
|
|
|
|
|
|
*modify = FALSE;
|
|
|
|
|
*extend = FALSE;
|
|
|
|
|
|
|
|
|
|
if (gtk_get_current_event_state (&state))
|
|
|
|
|
{
|
|
|
|
|
mask = gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
|
|
|
|
|
if ((state & mask) == mask)
|
|
|
|
|
*modify = TRUE;
|
|
|
|
|
mask = gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
|
|
|
|
|
if ((state & mask) == mask)
|
|
|
|
|
*extend = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
static gboolean
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_button_release_event (GtkWidget *widget,
|
|
|
|
|
GdkEventButton *event)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBox *box = GTK_LIST_BOX (widget);
|
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2014-01-28 15:44:01 +00:00
|
|
|
|
gboolean retval = GDK_EVENT_PROPAGATE;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 01:34:39 +00:00
|
|
|
|
/* Take a ref to protect against reentrancy
|
|
|
|
|
* (the activation may destroy the widget)
|
|
|
|
|
*/
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_object_ref (box);
|
2013-06-12 11:20:15 +00:00
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
if (event->button == GDK_BUTTON_PRIMARY)
|
|
|
|
|
{
|
2014-03-29 01:34:39 +00:00
|
|
|
|
if (priv->active_row != NULL && priv->active_row_active)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2013-06-12 11:20:15 +00:00
|
|
|
|
gtk_widget_unset_state_flags (GTK_WIDGET (priv->active_row),
|
|
|
|
|
GTK_STATE_FLAG_ACTIVE);
|
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
if (priv->activate_single_click)
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_select_and_activate (box, priv->active_row);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
else
|
2014-03-29 01:34:39 +00:00
|
|
|
|
{
|
|
|
|
|
gboolean modify;
|
|
|
|
|
gboolean extend;
|
|
|
|
|
GdkDevice *device;
|
|
|
|
|
|
|
|
|
|
get_current_selection_modifiers (widget, &modify, &extend);
|
|
|
|
|
|
|
|
|
|
/* With touch, we default to modifying the selection.
|
|
|
|
|
* You can still clear the selection and start over
|
|
|
|
|
* by holding Ctrl.
|
|
|
|
|
*/
|
|
|
|
|
device = gdk_event_get_source_device ((GdkEvent *)event);
|
|
|
|
|
if (gdk_device_get_source (device) == GDK_SOURCE_TOUCHSCREEN)
|
|
|
|
|
modify = !modify;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_update_selection (box, priv->active_row, modify, extend);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
}
|
2013-06-12 11:08:36 +00:00
|
|
|
|
|
2014-01-28 15:44:01 +00:00
|
|
|
|
retval = GDK_EVENT_STOP;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
2014-03-29 01:34:39 +00:00
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
priv->active_row = NULL;
|
|
|
|
|
priv->active_row_active = FALSE;
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_object_unref (box);
|
2013-06-12 11:20:15 +00:00
|
|
|
|
|
2014-01-28 15:44:01 +00:00
|
|
|
|
return retval;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_show (GtkWidget *widget)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_do_reseparate (GTK_LIST_BOX (widget));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_list_box_parent_class)->show (widget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_focus (GtkWidget *widget,
|
|
|
|
|
GtkDirectionType direction)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBox *box = GTK_LIST_BOX (widget);
|
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkWidget *focus_child;
|
|
|
|
|
GtkListBoxRow *next_focus_row;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
focus_child = gtk_container_get_focus_child ((GtkContainer *)box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
next_focus_row = NULL;
|
|
|
|
|
if (focus_child != NULL)
|
|
|
|
|
{
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GSequenceIter *i;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
if (gtk_widget_child_focus (focus_child, direction))
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
if (direction == GTK_DIR_UP || direction == GTK_DIR_TAB_BACKWARD)
|
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
i = gtk_list_box_get_previous_visible (box, ROW_PRIV (GTK_LIST_BOX_ROW (focus_child))->iter);
|
2013-09-15 20:31:12 +00:00
|
|
|
|
while (i != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (gtk_widget_get_sensitive (g_sequence_get (i)))
|
|
|
|
|
{
|
|
|
|
|
next_focus_row = g_sequence_get (i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
i = gtk_list_box_get_previous_visible (box, i);
|
2013-09-15 20:31:12 +00:00
|
|
|
|
}
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
else if (direction == GTK_DIR_DOWN || direction == GTK_DIR_TAB_FORWARD)
|
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
i = gtk_list_box_get_next_visible (box, ROW_PRIV (GTK_LIST_BOX_ROW (focus_child))->iter);
|
2013-09-15 20:31:12 +00:00
|
|
|
|
while (!g_sequence_iter_is_end (i))
|
|
|
|
|
{
|
|
|
|
|
if (gtk_widget_get_sensitive (g_sequence_get (i)))
|
|
|
|
|
{
|
|
|
|
|
next_focus_row = g_sequence_get (i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
i = gtk_list_box_get_next_visible (box, i);
|
2013-09-15 20:31:12 +00:00
|
|
|
|
}
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* No current focus row */
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
case GTK_DIR_UP:
|
|
|
|
|
case GTK_DIR_TAB_BACKWARD:
|
|
|
|
|
next_focus_row = priv->selected_row;
|
|
|
|
|
if (next_focus_row == NULL)
|
2014-03-29 03:07:41 +00:00
|
|
|
|
next_focus_row = gtk_list_box_get_last_focusable (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
next_focus_row = priv->selected_row;
|
|
|
|
|
if (next_focus_row == NULL)
|
2014-03-29 03:07:41 +00:00
|
|
|
|
next_focus_row = gtk_list_box_get_first_focusable (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (next_focus_row == NULL)
|
|
|
|
|
{
|
|
|
|
|
if (direction == GTK_DIR_UP || direction == GTK_DIR_DOWN)
|
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
if (gtk_widget_keynav_failed (GTK_WIDGET (box), direction))
|
2013-06-10 09:17:10 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gtk_widget_child_focus (GTK_WIDGET (next_focus_row), direction))
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_draw (GtkWidget *widget,
|
|
|
|
|
cairo_t *cr)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GtkAllocation allocation;
|
|
|
|
|
GtkStyleContext *context;
|
|
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
context = gtk_widget_get_style_context (widget);
|
|
|
|
|
gtk_render_background (context, cr, 0, 0, allocation.width, allocation.height);
|
|
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_list_box_parent_class)->draw (widget, cr);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_realize (GtkWidget *widget)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GtkAllocation allocation;
|
2013-09-28 02:00:38 +00:00
|
|
|
|
GdkWindowAttr attributes = { 0, };
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GdkWindow *window;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
gtk_widget_set_realized (widget, TRUE);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
attributes.x = allocation.x;
|
|
|
|
|
attributes.y = allocation.y;
|
|
|
|
|
attributes.width = allocation.width;
|
|
|
|
|
attributes.height = allocation.height;
|
|
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
2014-03-29 03:07:41 +00:00
|
|
|
|
attributes.event_mask = gtk_widget_get_events (widget) |
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK |
|
|
|
|
|
GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK;
|
|
|
|
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
window = gdk_window_new (gtk_widget_get_parent_window (widget),
|
2013-06-10 09:17:10 +00:00
|
|
|
|
&attributes, GDK_WA_X | GDK_WA_Y);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_style_context_set_background (gtk_widget_get_style_context (widget), window);
|
|
|
|
|
gdk_window_set_user_data (window, (GObject*) widget);
|
|
|
|
|
gtk_widget_set_window (widget, window); /* Passes ownership */
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-11 14:53:31 +00:00
|
|
|
|
static void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
list_box_add_visible_rows (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
gint n)
|
2013-06-11 14:53:31 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2013-06-11 14:53:31 +00:00
|
|
|
|
int was_zero;
|
|
|
|
|
|
|
|
|
|
was_zero = priv->n_visible_rows == 0;
|
|
|
|
|
priv->n_visible_rows += n;
|
|
|
|
|
|
|
|
|
|
if (priv->placeholder &&
|
|
|
|
|
(was_zero || priv->n_visible_rows == 0))
|
|
|
|
|
gtk_widget_set_child_visible (GTK_WIDGET (priv->placeholder),
|
|
|
|
|
priv->n_visible_rows == 0);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-11 14:13:00 +00:00
|
|
|
|
/* Children are visible if they are shown by the app (visible)
|
2013-06-15 16:13:28 +00:00
|
|
|
|
* and not filtered out (child_visible) by the listbox
|
|
|
|
|
*/
|
2013-06-11 14:13:00 +00:00
|
|
|
|
static void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
update_row_is_visible (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GtkListBoxRow *row)
|
2013-06-11 14:13:00 +00:00
|
|
|
|
{
|
2013-09-28 01:39:10 +00:00
|
|
|
|
GtkListBoxRowPrivate *row_priv = ROW_PRIV (row);
|
2013-06-11 14:20:45 +00:00
|
|
|
|
gboolean was_visible;
|
|
|
|
|
|
2013-07-02 11:44:17 +00:00
|
|
|
|
was_visible = row_priv->visible;
|
2013-06-11 14:20:45 +00:00
|
|
|
|
|
2013-07-02 11:44:17 +00:00
|
|
|
|
row_priv->visible =
|
2013-06-11 14:20:45 +00:00
|
|
|
|
gtk_widget_get_visible (GTK_WIDGET (row)) &&
|
|
|
|
|
gtk_widget_get_child_visible (GTK_WIDGET (row));
|
|
|
|
|
|
2013-07-02 11:44:17 +00:00
|
|
|
|
if (was_visible && !row_priv->visible)
|
2014-03-29 03:07:41 +00:00
|
|
|
|
list_box_add_visible_rows (box, -1);
|
2013-07-02 11:44:17 +00:00
|
|
|
|
if (!was_visible && row_priv->visible)
|
2014-03-29 03:07:41 +00:00
|
|
|
|
list_box_add_visible_rows (box, 1);
|
2013-06-11 14:13:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
static void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_apply_filter (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GtkListBoxRow *row)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
gboolean do_show;
|
|
|
|
|
|
|
|
|
|
do_show = TRUE;
|
|
|
|
|
if (priv->filter_func != NULL)
|
|
|
|
|
do_show = priv->filter_func (row, priv->filter_func_target);
|
|
|
|
|
|
|
|
|
|
gtk_widget_set_child_visible (GTK_WIDGET (row), do_show);
|
2013-06-11 14:13:00 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
update_row_is_visible (box, row);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_apply_filter_all (GtkListBox *box)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
GSequenceIter *iter;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
for (iter = g_sequence_get_begin_iter (BOX_PRIV (box)->children);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
!g_sequence_iter_is_end (iter);
|
|
|
|
|
iter = g_sequence_iter_next (iter))
|
|
|
|
|
{
|
|
|
|
|
row = g_sequence_get (iter);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_apply_filter (box, row);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkListBoxRow *
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_get_first_focusable (GtkListBox *box)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
GSequenceIter *iter;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
for (iter = g_sequence_get_begin_iter (BOX_PRIV (box)->children);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
!g_sequence_iter_is_end (iter);
|
|
|
|
|
iter = g_sequence_iter_next (iter))
|
|
|
|
|
{
|
|
|
|
|
row = g_sequence_get (iter);
|
2013-09-15 20:31:12 +00:00
|
|
|
|
if (row_is_visible (row) && gtk_widget_is_sensitive (GTK_WIDGET (row)))
|
2013-06-10 09:17:10 +00:00
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkListBoxRow *
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_get_last_focusable (GtkListBox *box)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
GSequenceIter *iter;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
iter = g_sequence_get_end_iter (BOX_PRIV (box)->children);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
while (!g_sequence_iter_is_begin (iter))
|
|
|
|
|
{
|
|
|
|
|
iter = g_sequence_iter_prev (iter);
|
|
|
|
|
row = g_sequence_get (iter);
|
2013-09-15 20:31:12 +00:00
|
|
|
|
if (row_is_visible (row) && gtk_widget_is_sensitive (GTK_WIDGET (row)))
|
2013-06-10 09:17:10 +00:00
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 16:13:28 +00:00
|
|
|
|
static GSequenceIter *
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_get_previous_visible (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GSequenceIter *iter)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
|
|
|
|
|
if (g_sequence_iter_is_begin (iter))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
iter = g_sequence_iter_prev (iter);
|
|
|
|
|
row = g_sequence_get (iter);
|
|
|
|
|
if (row_is_visible (row))
|
|
|
|
|
return iter;
|
|
|
|
|
}
|
|
|
|
|
while (!g_sequence_iter_is_begin (iter));
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 16:13:28 +00:00
|
|
|
|
static GSequenceIter *
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_get_next_visible (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GSequenceIter *iter)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
|
|
|
|
|
if (g_sequence_iter_is_end (iter))
|
|
|
|
|
return iter;
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
iter = g_sequence_iter_next (iter);
|
|
|
|
|
if (!g_sequence_iter_is_end (iter))
|
|
|
|
|
{
|
|
|
|
|
row = g_sequence_get (iter);
|
|
|
|
|
if (row_is_visible (row))
|
|
|
|
|
return iter;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while (!g_sequence_iter_is_end (iter));
|
|
|
|
|
|
|
|
|
|
return iter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_update_header (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GSequenceIter *iter)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
GSequenceIter *before_iter;
|
|
|
|
|
GtkListBoxRow *before_row;
|
2013-06-11 12:09:19 +00:00
|
|
|
|
GtkWidget *old_header;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
if (iter == NULL || g_sequence_iter_is_end (iter))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
row = g_sequence_get (iter);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
before_iter = gtk_list_box_get_previous_visible (box, iter);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
if (row)
|
|
|
|
|
g_object_ref (row);
|
|
|
|
|
before_row = NULL;
|
|
|
|
|
if (before_iter != NULL)
|
|
|
|
|
{
|
|
|
|
|
before_row = g_sequence_get (before_iter);
|
|
|
|
|
if (before_row)
|
|
|
|
|
g_object_ref (before_row);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-11 12:09:19 +00:00
|
|
|
|
if (priv->update_header_func != NULL &&
|
2013-06-10 09:17:10 +00:00
|
|
|
|
row_is_visible (row))
|
|
|
|
|
{
|
2013-07-02 11:44:17 +00:00
|
|
|
|
old_header = ROW_PRIV (row)->header;
|
2013-06-11 12:09:19 +00:00
|
|
|
|
if (old_header)
|
|
|
|
|
g_object_ref (old_header);
|
|
|
|
|
priv->update_header_func (row,
|
|
|
|
|
before_row,
|
|
|
|
|
priv->update_header_func_target);
|
2013-07-02 11:44:17 +00:00
|
|
|
|
if (old_header != ROW_PRIV (row)->header)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2013-06-11 12:09:19 +00:00
|
|
|
|
if (old_header != NULL)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2013-06-11 12:09:19 +00:00
|
|
|
|
gtk_widget_unparent (old_header);
|
|
|
|
|
g_hash_table_remove (priv->header_hash, old_header);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
2013-07-02 11:44:17 +00:00
|
|
|
|
if (ROW_PRIV (row)->header != NULL)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2013-07-02 11:44:17 +00:00
|
|
|
|
g_hash_table_insert (priv->header_hash, ROW_PRIV (row)->header, row);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_widget_set_parent (ROW_PRIV (row)->header, GTK_WIDGET (box));
|
2013-07-02 11:44:17 +00:00
|
|
|
|
gtk_widget_show (ROW_PRIV (row)->header);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
2013-06-11 12:09:19 +00:00
|
|
|
|
if (old_header)
|
|
|
|
|
g_object_unref (old_header);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-07-02 11:44:17 +00:00
|
|
|
|
if (ROW_PRIV (row)->header != NULL)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2013-07-02 11:44:17 +00:00
|
|
|
|
g_hash_table_remove (priv->header_hash, ROW_PRIV (row)->header);
|
|
|
|
|
gtk_widget_unparent (ROW_PRIV (row)->header);
|
2013-06-11 12:09:19 +00:00
|
|
|
|
gtk_list_box_row_set_header (row, NULL);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (before_row)
|
|
|
|
|
g_object_unref (before_row);
|
|
|
|
|
if (row)
|
|
|
|
|
g_object_unref (row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_row_visibility_changed (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GtkListBoxRow *row)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
update_row_is_visible (box, row);
|
2013-06-11 14:13:00 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
if (gtk_widget_get_visible (GTK_WIDGET (box)))
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_update_header (box, ROW_PRIV (row)->iter);
|
|
|
|
|
gtk_list_box_update_header (box,
|
|
|
|
|
gtk_list_box_get_next_visible (box, ROW_PRIV (row)->iter));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-06 12:57:22 +00:00
|
|
|
|
static void
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_add (GtkContainer *container,
|
|
|
|
|
GtkWidget *child)
|
2013-08-06 12:57:22 +00:00
|
|
|
|
{
|
2013-08-07 10:36:03 +00:00
|
|
|
|
gtk_list_box_insert (GTK_LIST_BOX (container), child, -1);
|
2013-08-06 12:57:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
static void
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_remove (GtkContainer *container,
|
|
|
|
|
GtkWidget *child)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkWidget *widget = GTK_WIDGET (container);
|
|
|
|
|
GtkListBox *box = GTK_LIST_BOX (container);
|
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
gboolean was_visible;
|
2014-03-29 01:34:39 +00:00
|
|
|
|
gboolean was_selected;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
GSequenceIter *next;
|
|
|
|
|
|
|
|
|
|
was_visible = gtk_widget_get_visible (child);
|
|
|
|
|
|
|
|
|
|
if (!GTK_IS_LIST_BOX_ROW (child))
|
|
|
|
|
{
|
2013-06-11 12:09:19 +00:00
|
|
|
|
row = g_hash_table_lookup (priv->header_hash, child);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
if (row != NULL)
|
|
|
|
|
{
|
2013-06-11 12:09:19 +00:00
|
|
|
|
g_hash_table_remove (priv->header_hash, child);
|
2013-07-02 11:44:17 +00:00
|
|
|
|
g_clear_object (&ROW_PRIV (row)->header);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
gtk_widget_unparent (child);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
if (was_visible && gtk_widget_get_visible (widget))
|
|
|
|
|
gtk_widget_queue_resize (widget);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_warning ("Tried to remove non-child %p\n", child);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
row = GTK_LIST_BOX_ROW (child);
|
2013-07-02 11:44:17 +00:00
|
|
|
|
if (g_sequence_iter_get_sequence (ROW_PRIV (row)->iter) != priv->children)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
g_warning ("Tried to remove non-child %p\n", child);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 01:34:39 +00:00
|
|
|
|
was_selected = ROW_PRIV (row)->selected;
|
|
|
|
|
|
2013-07-02 11:44:17 +00:00
|
|
|
|
if (ROW_PRIV (row)->visible)
|
2014-03-29 03:07:41 +00:00
|
|
|
|
list_box_add_visible_rows (box, -1);
|
2013-06-11 14:20:45 +00:00
|
|
|
|
|
2013-07-02 11:44:17 +00:00
|
|
|
|
if (ROW_PRIV (row)->header != NULL)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2013-07-02 11:44:17 +00:00
|
|
|
|
g_hash_table_remove (priv->header_hash, ROW_PRIV (row)->header);
|
|
|
|
|
gtk_widget_unparent (ROW_PRIV (row)->header);
|
|
|
|
|
g_clear_object (&ROW_PRIV (row)->header);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (row == priv->selected_row)
|
2014-03-29 03:07:41 +00:00
|
|
|
|
priv->selected_row = NULL;
|
2014-03-29 01:34:39 +00:00
|
|
|
|
if (row == priv->prelight_row)
|
|
|
|
|
{
|
|
|
|
|
gtk_widget_unset_state_flags (GTK_WIDGET (row), GTK_STATE_FLAG_PRELIGHT);
|
|
|
|
|
priv->prelight_row = NULL;
|
|
|
|
|
}
|
2013-06-10 09:17:10 +00:00
|
|
|
|
if (row == priv->cursor_row)
|
|
|
|
|
priv->cursor_row = NULL;
|
2014-03-29 01:34:39 +00:00
|
|
|
|
if (row == priv->active_row)
|
|
|
|
|
{
|
|
|
|
|
gtk_widget_unset_state_flags (GTK_WIDGET (row), GTK_STATE_FLAG_ACTIVE);
|
|
|
|
|
priv->active_row = NULL;
|
|
|
|
|
}
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2013-06-10 13:15:22 +00:00
|
|
|
|
if (row == priv->drag_highlighted_row)
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_drag_unhighlight_row (box);
|
2013-06-10 13:15:22 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
next = gtk_list_box_get_next_visible (box, ROW_PRIV (row)->iter);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
gtk_widget_unparent (child);
|
2013-07-02 11:44:17 +00:00
|
|
|
|
g_sequence_remove (ROW_PRIV (row)->iter);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
if (gtk_widget_get_visible (widget))
|
|
|
|
|
gtk_list_box_update_header (box, next);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
if (was_visible && gtk_widget_get_visible (GTK_WIDGET (box)))
|
|
|
|
|
gtk_widget_queue_resize (widget);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
|
|
|
|
|
if (was_selected)
|
2014-04-13 20:51:49 +00:00
|
|
|
|
{
|
|
|
|
|
g_signal_emit (box, signals[ROW_SELECTED], 0, NULL);
|
|
|
|
|
g_signal_emit (box, signals[SELECTED_ROWS_CHANGED], 0);
|
|
|
|
|
}
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_forall_internal (GtkContainer *container,
|
|
|
|
|
gboolean include_internals,
|
|
|
|
|
GtkCallback callback,
|
|
|
|
|
gpointer callback_target)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (container);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GSequenceIter *iter;
|
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
|
2013-06-11 14:53:31 +00:00
|
|
|
|
if (priv->placeholder != NULL && include_internals)
|
|
|
|
|
callback (priv->placeholder, callback_target);
|
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
iter = g_sequence_get_begin_iter (priv->children);
|
|
|
|
|
while (!g_sequence_iter_is_end (iter))
|
|
|
|
|
{
|
|
|
|
|
row = g_sequence_get (iter);
|
|
|
|
|
iter = g_sequence_iter_next (iter);
|
2013-07-02 11:44:17 +00:00
|
|
|
|
if (ROW_PRIV (row)->header != NULL && include_internals)
|
|
|
|
|
callback (ROW_PRIV (row)->header, callback_target);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
callback (GTK_WIDGET (row), callback_target);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_compute_expand_internal (GtkWidget *widget,
|
|
|
|
|
gboolean *hexpand,
|
|
|
|
|
gboolean *vexpand)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_list_box_parent_class)->compute_expand (widget,
|
|
|
|
|
hexpand, vexpand);
|
|
|
|
|
|
|
|
|
|
/* We don't expand vertically beyound the minimum size */
|
|
|
|
|
if (vexpand)
|
|
|
|
|
*vexpand = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GType
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_child_type (GtkContainer *container)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2013-06-15 16:13:28 +00:00
|
|
|
|
/* We really support any type but we wrap it in a row. But that is
|
|
|
|
|
* more like a C helper function, in an abstract sense we only support
|
|
|
|
|
* row children, so that is what tools accessing this should use.
|
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
return GTK_TYPE_LIST_BOX_ROW;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkSizeRequestMode
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_get_request_mode (GtkWidget *widget)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_get_preferred_height (GtkWidget *widget,
|
|
|
|
|
gint *minimum_height,
|
|
|
|
|
gint *natural_height)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
gint natural_width;
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_get_preferred_width (widget, NULL, &natural_width);
|
|
|
|
|
gtk_list_box_get_preferred_height_for_width (widget, natural_width,
|
|
|
|
|
minimum_height, natural_height);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_get_preferred_height_for_width (GtkWidget *widget,
|
|
|
|
|
gint width,
|
|
|
|
|
gint *minimum_height_out,
|
|
|
|
|
gint *natural_height_out)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (widget);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GSequenceIter *iter;
|
|
|
|
|
gint minimum_height;
|
|
|
|
|
|
|
|
|
|
minimum_height = 0;
|
|
|
|
|
|
2013-06-11 14:53:31 +00:00
|
|
|
|
if (priv->placeholder != NULL && gtk_widget_get_child_visible (priv->placeholder))
|
|
|
|
|
gtk_widget_get_preferred_height_for_width (priv->placeholder, width,
|
|
|
|
|
&minimum_height, NULL);
|
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
for (iter = g_sequence_get_begin_iter (priv->children);
|
|
|
|
|
!g_sequence_iter_is_end (iter);
|
|
|
|
|
iter = g_sequence_iter_next (iter))
|
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
gint row_min = 0;
|
|
|
|
|
|
|
|
|
|
row = g_sequence_get (iter);
|
|
|
|
|
if (!row_is_visible (row))
|
|
|
|
|
continue;
|
|
|
|
|
|
2013-07-02 11:44:17 +00:00
|
|
|
|
if (ROW_PRIV (row)->header != NULL)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2013-07-02 11:44:17 +00:00
|
|
|
|
gtk_widget_get_preferred_height_for_width (ROW_PRIV (row)->header, width, &row_min, NULL);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
minimum_height += row_min;
|
|
|
|
|
}
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_widget_get_preferred_height_for_width (GTK_WIDGET (row), width, &row_min, NULL);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
minimum_height += row_min;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 16:13:28 +00:00
|
|
|
|
/* We always allocate the minimum height, since handling expanding rows is way too costly,
|
|
|
|
|
* and unlikely to be used, as lists are generally put inside a scrolling window anyway.
|
|
|
|
|
*/
|
2014-04-30 07:19:33 +00:00
|
|
|
|
*minimum_height_out = minimum_height;
|
|
|
|
|
*natural_height_out = minimum_height;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_get_preferred_width (GtkWidget *widget,
|
|
|
|
|
gint *minimum_width_out,
|
|
|
|
|
gint *natural_width_out)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (widget);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
gint minimum_width;
|
|
|
|
|
gint natural_width;
|
|
|
|
|
GSequenceIter *iter;
|
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
gint row_min;
|
|
|
|
|
gint row_nat;
|
|
|
|
|
|
|
|
|
|
minimum_width = 0;
|
|
|
|
|
natural_width = 0;
|
|
|
|
|
|
2013-06-11 14:53:31 +00:00
|
|
|
|
if (priv->placeholder != NULL && gtk_widget_get_child_visible (priv->placeholder))
|
|
|
|
|
gtk_widget_get_preferred_width (priv->placeholder,
|
|
|
|
|
&minimum_width, &natural_width);
|
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
for (iter = g_sequence_get_begin_iter (priv->children);
|
|
|
|
|
!g_sequence_iter_is_end (iter);
|
|
|
|
|
iter = g_sequence_iter_next (iter))
|
|
|
|
|
{
|
|
|
|
|
row = g_sequence_get (iter);
|
2013-06-13 08:47:52 +00:00
|
|
|
|
|
2013-06-15 16:13:28 +00:00
|
|
|
|
/* We *do* take visible but filtered rows into account here so that
|
|
|
|
|
* the list width doesn't change during filtering
|
|
|
|
|
*/
|
2013-06-13 08:47:52 +00:00
|
|
|
|
if (!gtk_widget_get_visible (GTK_WIDGET (row)))
|
2013-06-10 09:17:10 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
gtk_widget_get_preferred_width (GTK_WIDGET (row), &row_min, &row_nat);
|
|
|
|
|
minimum_width = MAX (minimum_width, row_min);
|
|
|
|
|
natural_width = MAX (natural_width, row_nat);
|
|
|
|
|
|
2013-07-02 11:44:17 +00:00
|
|
|
|
if (ROW_PRIV (row)->header != NULL)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2013-07-02 11:44:17 +00:00
|
|
|
|
gtk_widget_get_preferred_width (ROW_PRIV (row)->header, &row_min, &row_nat);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
minimum_width = MAX (minimum_width, row_min);
|
|
|
|
|
natural_width = MAX (natural_width, row_nat);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-30 07:19:33 +00:00
|
|
|
|
*minimum_width_out = minimum_width;
|
|
|
|
|
*natural_width_out = natural_width;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_get_preferred_width_for_height (GtkWidget *widget,
|
|
|
|
|
gint height,
|
|
|
|
|
gint *minimum_width,
|
|
|
|
|
gint *natural_width)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_get_preferred_width (widget, minimum_width, natural_width);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_size_allocate (GtkWidget *widget,
|
|
|
|
|
GtkAllocation *allocation)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (widget);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkAllocation child_allocation;
|
2013-06-11 12:09:19 +00:00
|
|
|
|
GtkAllocation header_allocation;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
GdkWindow *window;
|
|
|
|
|
GSequenceIter *iter;
|
|
|
|
|
int child_min;
|
|
|
|
|
|
|
|
|
|
child_allocation.x = 0;
|
|
|
|
|
child_allocation.y = 0;
|
|
|
|
|
child_allocation.width = 0;
|
|
|
|
|
child_allocation.height = 0;
|
|
|
|
|
|
2013-06-11 12:09:19 +00:00
|
|
|
|
header_allocation.x = 0;
|
|
|
|
|
header_allocation.y = 0;
|
|
|
|
|
header_allocation.width = 0;
|
|
|
|
|
header_allocation.height = 0;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_widget_set_allocation (widget, allocation);
|
|
|
|
|
window = gtk_widget_get_window (widget);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
if (window != NULL)
|
|
|
|
|
gdk_window_move_resize (window,
|
|
|
|
|
allocation->x, allocation->y,
|
|
|
|
|
allocation->width, allocation->height);
|
|
|
|
|
|
|
|
|
|
child_allocation.x = 0;
|
|
|
|
|
child_allocation.y = 0;
|
|
|
|
|
child_allocation.width = allocation->width;
|
2013-06-11 12:09:19 +00:00
|
|
|
|
header_allocation.x = 0;
|
|
|
|
|
header_allocation.width = allocation->width;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2013-06-11 14:53:31 +00:00
|
|
|
|
if (priv->placeholder != NULL && gtk_widget_get_child_visible (priv->placeholder))
|
|
|
|
|
{
|
|
|
|
|
gtk_widget_get_preferred_height_for_width (priv->placeholder,
|
|
|
|
|
allocation->width, &child_min, NULL);
|
2013-11-01 11:30:07 +00:00
|
|
|
|
header_allocation.height = allocation->height;
|
2013-06-11 14:53:31 +00:00
|
|
|
|
header_allocation.y = child_allocation.y;
|
|
|
|
|
gtk_widget_size_allocate (priv->placeholder,
|
|
|
|
|
&header_allocation);
|
|
|
|
|
child_allocation.y += child_min;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
for (iter = g_sequence_get_begin_iter (priv->children);
|
|
|
|
|
!g_sequence_iter_is_end (iter);
|
|
|
|
|
iter = g_sequence_iter_next (iter))
|
|
|
|
|
{
|
|
|
|
|
row = g_sequence_get (iter);
|
|
|
|
|
if (!row_is_visible (row))
|
|
|
|
|
{
|
2013-07-02 11:44:17 +00:00
|
|
|
|
ROW_PRIV (row)->y = child_allocation.y;
|
|
|
|
|
ROW_PRIV (row)->height = 0;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-02 11:44:17 +00:00
|
|
|
|
if (ROW_PRIV (row)->header != NULL)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2013-07-02 11:44:17 +00:00
|
|
|
|
gtk_widget_get_preferred_height_for_width (ROW_PRIV (row)->header,
|
2013-06-10 09:17:10 +00:00
|
|
|
|
allocation->width, &child_min, NULL);
|
2013-06-11 12:09:19 +00:00
|
|
|
|
header_allocation.height = child_min;
|
|
|
|
|
header_allocation.y = child_allocation.y;
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_widget_size_allocate (ROW_PRIV (row)->header, &header_allocation);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
child_allocation.y += child_min;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-02 11:44:17 +00:00
|
|
|
|
ROW_PRIV (row)->y = child_allocation.y;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_widget_get_preferred_height_for_width (GTK_WIDGET (row),
|
|
|
|
|
child_allocation.width, &child_min, NULL);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
child_allocation.height = child_min;
|
|
|
|
|
|
2013-07-02 11:44:17 +00:00
|
|
|
|
ROW_PRIV (row)->height = child_allocation.height;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
gtk_widget_size_allocate (GTK_WIDGET (row), &child_allocation);
|
|
|
|
|
child_allocation.y += child_min;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-06 12:57:22 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_prepend:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-08-06 12:57:22 +00:00
|
|
|
|
* @child: the #GtkWidget to add
|
|
|
|
|
*
|
|
|
|
|
* Prepend a widget to the list. If a sort function is set, the widget will
|
|
|
|
|
* actually be inserted at the calculated position and this function has the
|
|
|
|
|
* same effect of gtk_container_add().
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
|
|
|
|
*/
|
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_prepend (GtkListBox *box,
|
2013-08-06 12:57:22 +00:00
|
|
|
|
GtkWidget *child)
|
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_insert (box, child, 0);
|
2013-08-06 12:57:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 06:06:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_insert:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-08-08 06:06:27 +00:00
|
|
|
|
* @child: the #GtkWidget to add
|
|
|
|
|
* @position: the position to insert @child in
|
|
|
|
|
*
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* Insert the @child into the @box at @position. If a sort function is
|
2013-08-08 06:06:27 +00:00
|
|
|
|
* set, the widget will actually be inserted at the calculated position and
|
|
|
|
|
* this function has the same effect of gtk_container_add().
|
|
|
|
|
*
|
|
|
|
|
* If @position is -1, or larger than the total number of items in the
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box, then the @child will be appended to the end.
|
2013-08-08 06:06:27 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
|
|
|
|
*/
|
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_insert (GtkListBox *box,
|
2013-08-08 06:06:27 +00:00
|
|
|
|
GtkWidget *child,
|
|
|
|
|
gint position)
|
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2013-08-08 06:06:27 +00:00
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
GSequenceIter *iter = NULL;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2013-09-28 01:39:10 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (child));
|
2013-08-08 06:06:27 +00:00
|
|
|
|
|
|
|
|
|
if (GTK_IS_LIST_BOX_ROW (child))
|
|
|
|
|
row = GTK_LIST_BOX_ROW (child);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
row = GTK_LIST_BOX_ROW (gtk_list_box_row_new ());
|
|
|
|
|
gtk_widget_show (GTK_WIDGET (row));
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (row), child);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (priv->sort_func != NULL)
|
|
|
|
|
iter = g_sequence_insert_sorted (priv->children, row,
|
2014-03-29 03:07:41 +00:00
|
|
|
|
(GCompareDataFunc)do_sort, box);
|
2013-08-08 06:06:27 +00:00
|
|
|
|
else if (position == 0)
|
|
|
|
|
iter = g_sequence_prepend (priv->children, row);
|
|
|
|
|
else if (position == -1)
|
|
|
|
|
iter = g_sequence_append (priv->children, row);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GSequenceIter *current_iter;
|
|
|
|
|
|
|
|
|
|
current_iter = g_sequence_get_iter_at_pos (priv->children, position);
|
|
|
|
|
iter = g_sequence_insert_before (current_iter, row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ROW_PRIV (row)->iter = iter;
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_widget_set_parent (GTK_WIDGET (row), GTK_WIDGET (box));
|
2013-08-08 06:06:27 +00:00
|
|
|
|
gtk_widget_set_child_visible (GTK_WIDGET (row), TRUE);
|
|
|
|
|
ROW_PRIV (row)->visible = gtk_widget_get_visible (GTK_WIDGET (row));
|
|
|
|
|
if (ROW_PRIV (row)->visible)
|
2014-03-29 03:07:41 +00:00
|
|
|
|
list_box_add_visible_rows (box, 1);
|
|
|
|
|
gtk_list_box_apply_filter (box, row);
|
|
|
|
|
if (gtk_widget_get_visible (GTK_WIDGET (box)))
|
2013-08-08 06:06:27 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_update_header (box, ROW_PRIV (row)->iter);
|
|
|
|
|
gtk_list_box_update_header (box,
|
|
|
|
|
gtk_list_box_get_next_visible (box, ROW_PRIV (row)->iter));
|
2013-08-08 06:06:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-11 10:59:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_drag_unhighlight_row:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* If a row has previously been highlighted via gtk_list_box_drag_highlight_row()
|
|
|
|
|
* it will have the highlight removed.
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
2013-06-15 16:13:28 +00:00
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_drag_unhighlight_row (GtkListBox *box)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
if (priv->drag_highlighted_row == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
gtk_drag_unhighlight (GTK_WIDGET (priv->drag_highlighted_row));
|
|
|
|
|
g_clear_object (&priv->drag_highlighted_row);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-11 10:59:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_drag_highlight_row:
|
2014-03-29 03:07:41 +00:00
|
|
|
|
* @box: a #GtkListBox
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* @row: a #GtkListBoxRow
|
|
|
|
|
*
|
|
|
|
|
* This is a helper function for implementing DnD onto a #GtkListBox.
|
|
|
|
|
* The passed in @row will be highlighted via gtk_drag_highlight(),
|
|
|
|
|
* and any previously highlighted row will be unhighlighted.
|
|
|
|
|
*
|
|
|
|
|
* The row will also be unhighlighted when the widget gets
|
|
|
|
|
* a drag leave event.
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
2013-06-15 16:13:28 +00:00
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_drag_highlight_row (GtkListBox *box,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GtkListBoxRow *row)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2013-09-28 01:39:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX (box));
|
2013-09-28 01:39:10 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX_ROW (row));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
if (priv->drag_highlighted_row == row)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_drag_unhighlight_row (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
gtk_drag_highlight (GTK_WIDGET (row));
|
|
|
|
|
priv->drag_highlighted_row = g_object_ref (row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-28 02:00:38 +00:00
|
|
|
|
gtk_list_box_drag_leave (GtkWidget *widget,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
guint time_)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_drag_unhighlight_row (GTK_LIST_BOX (widget));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_activate_cursor_row (GtkListBox *box)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_select_and_activate (box, BOX_PRIV (box)->cursor_row);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_toggle_cursor_row (GtkListBox *box)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
if (priv->cursor_row == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-03-29 01:34:39 +00:00
|
|
|
|
if ((priv->selection_mode == GTK_SELECTION_SINGLE ||
|
|
|
|
|
priv->selection_mode == GTK_SELECTION_MULTIPLE) &&
|
|
|
|
|
ROW_PRIV (priv->cursor_row)->selected)
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_unselect_row_internal (box, priv->cursor_row);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
else
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_select_and_activate (box, priv->cursor_row);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_move_cursor (GtkListBox *box,
|
2013-09-28 02:00:38 +00:00
|
|
|
|
GtkMovementStep step,
|
|
|
|
|
gint count)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBoxPrivate *priv = BOX_PRIV (box);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
gboolean modify;
|
|
|
|
|
gboolean extend;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
GtkListBoxRow *prev;
|
|
|
|
|
GtkListBoxRow *next;
|
|
|
|
|
gint page_size;
|
|
|
|
|
GSequenceIter *iter;
|
|
|
|
|
gint start_y;
|
|
|
|
|
gint end_y;
|
|
|
|
|
|
|
|
|
|
row = NULL;
|
|
|
|
|
switch (step)
|
|
|
|
|
{
|
|
|
|
|
case GTK_MOVEMENT_BUFFER_ENDS:
|
|
|
|
|
if (count < 0)
|
2014-03-29 03:07:41 +00:00
|
|
|
|
row = gtk_list_box_get_first_focusable (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
else
|
2014-03-29 03:07:41 +00:00
|
|
|
|
row = gtk_list_box_get_last_focusable (box);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_MOVEMENT_DISPLAY_LINES:
|
|
|
|
|
if (priv->cursor_row != NULL)
|
|
|
|
|
{
|
2013-10-08 21:56:19 +00:00
|
|
|
|
int i = count;
|
2013-07-02 11:44:17 +00:00
|
|
|
|
iter = ROW_PRIV (priv->cursor_row)->iter;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2013-10-08 21:56:19 +00:00
|
|
|
|
while (i < 0 && iter != NULL)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
iter = gtk_list_box_get_previous_visible (box, iter);
|
2013-10-08 21:56:19 +00:00
|
|
|
|
i = i + 1;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
2013-10-08 21:56:19 +00:00
|
|
|
|
while (i > 0 && iter != NULL)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
iter = gtk_list_box_get_next_visible (box, iter);
|
2013-10-08 21:56:19 +00:00
|
|
|
|
i = i - 1;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (iter != NULL && !g_sequence_iter_is_end (iter))
|
|
|
|
|
row = g_sequence_get (iter);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case GTK_MOVEMENT_PAGES:
|
|
|
|
|
page_size = 100;
|
|
|
|
|
if (priv->adjustment != NULL)
|
|
|
|
|
page_size = gtk_adjustment_get_page_increment (priv->adjustment);
|
|
|
|
|
|
|
|
|
|
if (priv->cursor_row != NULL)
|
|
|
|
|
{
|
2013-07-02 11:44:17 +00:00
|
|
|
|
start_y = ROW_PRIV (priv->cursor_row)->y;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
end_y = start_y;
|
2013-07-02 11:44:17 +00:00
|
|
|
|
iter = ROW_PRIV (priv->cursor_row)->iter;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
row = priv->cursor_row;
|
|
|
|
|
if (count < 0)
|
|
|
|
|
{
|
|
|
|
|
/* Up */
|
|
|
|
|
while (iter != NULL && !g_sequence_iter_is_begin (iter))
|
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
iter = gtk_list_box_get_previous_visible (box, iter);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
if (iter == NULL)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
prev = g_sequence_get (iter);
|
2013-07-02 11:44:17 +00:00
|
|
|
|
if (ROW_PRIV (prev)->y < start_y - page_size)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
row = prev;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Down */
|
|
|
|
|
while (iter != NULL && !g_sequence_iter_is_end (iter))
|
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
iter = gtk_list_box_get_next_visible (box, iter);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
if (g_sequence_iter_is_end (iter))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
next = g_sequence_get (iter);
|
2013-07-02 11:44:17 +00:00
|
|
|
|
if (ROW_PRIV (next)->y > start_y + page_size)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
row = next;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-02 11:44:17 +00:00
|
|
|
|
end_y = ROW_PRIV (row)->y;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
if (end_y != start_y && priv->adjustment != NULL)
|
|
|
|
|
gtk_adjustment_set_value (priv->adjustment,
|
|
|
|
|
gtk_adjustment_get_value (priv->adjustment) +
|
|
|
|
|
end_y - start_y);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (row == NULL || row == priv->cursor_row)
|
|
|
|
|
{
|
|
|
|
|
GtkDirectionType direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
if (!gtk_widget_keynav_failed (GTK_WIDGET (box), direction))
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (box));
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
if (toplevel)
|
|
|
|
|
gtk_widget_child_focus (toplevel,
|
|
|
|
|
direction == GTK_DIR_UP ?
|
|
|
|
|
GTK_DIR_TAB_BACKWARD :
|
|
|
|
|
GTK_DIR_TAB_FORWARD);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
get_current_selection_modifiers (GTK_WIDGET (box), &modify, &extend);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_update_cursor (box, row);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
if (!modify)
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_update_selection (box, row, FALSE, extend);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-06-11 10:59:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_row_new:
|
|
|
|
|
*
|
|
|
|
|
* Creates a new #GtkListBoxRow, to be used as a child of a #GtkListBox.
|
|
|
|
|
*
|
|
|
|
|
* Returns: a new #GtkListBoxRow
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
GtkWidget *
|
|
|
|
|
gtk_list_box_row_new (void)
|
|
|
|
|
{
|
|
|
|
|
return g_object_new (GTK_TYPE_LIST_BOX_ROW, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_list_box_row_init (GtkListBoxRow *row)
|
|
|
|
|
{
|
2013-06-12 10:00:11 +00:00
|
|
|
|
GtkStyleContext *context;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
gtk_widget_set_can_focus (GTK_WIDGET (row), TRUE);
|
|
|
|
|
gtk_widget_set_redraw_on_allocate (GTK_WIDGET (row), TRUE);
|
2013-06-12 10:00:11 +00:00
|
|
|
|
|
|
|
|
|
context = gtk_widget_get_style_context (GTK_WIDGET (row));
|
|
|
|
|
gtk_style_context_add_class (context, GTK_STYLE_CLASS_LIST_ROW);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_list_box_row_set_focus (GtkListBoxRow *row)
|
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBox *box = gtk_list_box_row_get_box (row);
|
2014-03-29 01:34:39 +00:00
|
|
|
|
gboolean modify;
|
|
|
|
|
gboolean extend;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
if (!box)
|
2013-10-03 12:00:30 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2014-03-29 01:34:39 +00:00
|
|
|
|
get_current_selection_modifiers (GTK_WIDGET (row), &modify, &extend);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2014-03-29 01:34:39 +00:00
|
|
|
|
if (modify)
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_update_cursor (box, row);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
else
|
2014-03-29 03:07:41 +00:00
|
|
|
|
gtk_list_box_update_selection (box, row, FALSE, FALSE);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2013-09-28 01:39:10 +00:00
|
|
|
|
gtk_list_box_row_focus (GtkWidget *widget,
|
|
|
|
|
GtkDirectionType direction)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row = GTK_LIST_BOX_ROW (widget);
|
|
|
|
|
gboolean had_focus = FALSE;
|
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (widget));
|
|
|
|
|
|
|
|
|
|
g_object_get (widget, "has-focus", &had_focus, NULL);
|
|
|
|
|
if (had_focus)
|
|
|
|
|
{
|
|
|
|
|
/* If on row, going right, enter into possible container */
|
|
|
|
|
if (child &&
|
|
|
|
|
(direction == GTK_DIR_RIGHT || direction == GTK_DIR_TAB_FORWARD))
|
|
|
|
|
{
|
|
|
|
|
if (gtk_widget_child_focus (GTK_WIDGET (child), direction))
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
else if (gtk_container_get_focus_child (GTK_CONTAINER (row)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
/* Child has focus, always navigate inside it first */
|
|
|
|
|
if (gtk_widget_child_focus (child, direction))
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
/* If exiting child container to the left, select row */
|
|
|
|
|
if (direction == GTK_DIR_LEFT || direction == GTK_DIR_TAB_BACKWARD)
|
|
|
|
|
{
|
|
|
|
|
gtk_list_box_row_set_focus (row);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* If coming from the left, enter into possible container */
|
|
|
|
|
if (child &&
|
|
|
|
|
(direction == GTK_DIR_LEFT || direction == GTK_DIR_TAB_BACKWARD))
|
|
|
|
|
{
|
|
|
|
|
if (gtk_widget_child_focus (child, direction))
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_list_box_row_set_focus (row);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 12:12:07 +00:00
|
|
|
|
static void
|
2013-09-28 01:39:10 +00:00
|
|
|
|
gtk_list_box_row_activate (GtkListBoxRow *row)
|
2013-09-10 12:12:07 +00:00
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBox *box;
|
2013-09-10 12:12:07 +00:00
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
box = gtk_list_box_row_get_box (row);
|
|
|
|
|
if (box)
|
|
|
|
|
gtk_list_box_select_and_activate (box, row);
|
2013-09-10 12:12:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
static void
|
2013-09-28 01:39:10 +00:00
|
|
|
|
gtk_list_box_row_show (GtkWidget *widget)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row = GTK_LIST_BOX_ROW (widget);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBox *box;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_list_box_row_parent_class)->show (widget);
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
box = gtk_list_box_row_get_box (row);
|
|
|
|
|
if (box)
|
|
|
|
|
gtk_list_box_row_visibility_changed (box, row);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-28 01:39:10 +00:00
|
|
|
|
gtk_list_box_row_hide (GtkWidget *widget)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row = GTK_LIST_BOX_ROW (widget);
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBox *box;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_list_box_row_parent_class)->hide (widget);
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
box = gtk_list_box_row_get_box (row);
|
|
|
|
|
if (box)
|
|
|
|
|
gtk_list_box_row_visibility_changed (box, row);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2013-09-28 01:39:10 +00:00
|
|
|
|
gtk_list_box_row_draw (GtkWidget *widget,
|
|
|
|
|
cairo_t *cr)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row = GTK_LIST_BOX_ROW (widget);
|
|
|
|
|
GtkAllocation allocation = {0};
|
|
|
|
|
GtkStyleContext* context;
|
|
|
|
|
GtkStateFlags state;
|
|
|
|
|
GtkBorder border;
|
|
|
|
|
gint focus_pad;
|
|
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
context = gtk_widget_get_style_context (widget);
|
|
|
|
|
state = gtk_widget_get_state_flags (widget);
|
|
|
|
|
|
|
|
|
|
gtk_render_background (context, cr, (gdouble) 0, (gdouble) 0, (gdouble) allocation.width, (gdouble) allocation.height);
|
|
|
|
|
gtk_render_frame (context, cr, (gdouble) 0, (gdouble) 0, (gdouble) allocation.width, (gdouble) allocation.height);
|
|
|
|
|
|
|
|
|
|
if (gtk_widget_has_visible_focus (GTK_WIDGET (row)))
|
|
|
|
|
{
|
|
|
|
|
gtk_style_context_get_border (context, state, &border);
|
|
|
|
|
|
|
|
|
|
gtk_style_context_get_style (context,
|
|
|
|
|
"focus-padding", &focus_pad,
|
|
|
|
|
NULL);
|
|
|
|
|
gtk_render_focus (context, cr, border.left + focus_pad, border.top + focus_pad,
|
|
|
|
|
allocation.width - 2 * focus_pad - border.left - border.right,
|
|
|
|
|
allocation.height - 2 * focus_pad - border.top - border.bottom);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_list_box_row_parent_class)->draw (widget, cr);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_list_box_row_get_full_border (GtkListBoxRow *row,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GtkBorder *full_border)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget *widget = GTK_WIDGET (row);
|
|
|
|
|
GtkStyleContext *context;
|
|
|
|
|
GtkStateFlags state;
|
|
|
|
|
GtkBorder padding, border;
|
|
|
|
|
int focus_width, focus_pad;
|
|
|
|
|
|
|
|
|
|
context = gtk_widget_get_style_context (widget);
|
|
|
|
|
state = gtk_style_context_get_state (context);
|
|
|
|
|
|
|
|
|
|
gtk_style_context_get_padding (context, state, &padding);
|
|
|
|
|
gtk_style_context_get_border (context, state, &border);
|
|
|
|
|
gtk_style_context_get_style (context,
|
|
|
|
|
"focus-line-width", &focus_width,
|
|
|
|
|
"focus-padding", &focus_pad,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
full_border->left = padding.left + border.left + focus_width + focus_pad;
|
|
|
|
|
full_border->right = padding.right + border.right + focus_width + focus_pad;
|
|
|
|
|
full_border->top = padding.top + border.top + focus_width + focus_pad;
|
|
|
|
|
full_border->bottom = padding.bottom + border.bottom + focus_width + focus_pad;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-28 01:39:10 +00:00
|
|
|
|
static void gtk_list_box_row_get_preferred_height_for_width (GtkWidget *widget,
|
|
|
|
|
gint width,
|
|
|
|
|
gint *minimum_height_out,
|
|
|
|
|
gint *natural_height_out);
|
|
|
|
|
static void gtk_list_box_row_get_preferred_width (GtkWidget *widget,
|
|
|
|
|
gint *minimum_width_out,
|
|
|
|
|
gint *natural_width_out);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
static void
|
2013-09-28 01:39:10 +00:00
|
|
|
|
gtk_list_box_row_get_preferred_height (GtkWidget *widget,
|
|
|
|
|
gint *minimum_height,
|
|
|
|
|
gint *natural_height)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
gint natural_width;
|
2013-09-28 01:39:10 +00:00
|
|
|
|
|
|
|
|
|
gtk_list_box_row_get_preferred_width (widget, NULL, &natural_width);
|
|
|
|
|
gtk_list_box_row_get_preferred_height_for_width (widget, natural_width,
|
|
|
|
|
minimum_height, natural_height);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-28 01:39:10 +00:00
|
|
|
|
gtk_list_box_row_get_preferred_height_for_width (GtkWidget *widget,
|
|
|
|
|
gint width,
|
|
|
|
|
gint *minimum_height_out,
|
|
|
|
|
gint *natural_height_out)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row = GTK_LIST_BOX_ROW (widget);
|
|
|
|
|
GtkWidget *child;
|
|
|
|
|
gint child_min = 0, child_natural = 0;
|
|
|
|
|
GtkBorder full_border;
|
|
|
|
|
|
|
|
|
|
gtk_list_box_row_get_full_border (row, &full_border);
|
|
|
|
|
|
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (row));
|
|
|
|
|
if (child && gtk_widget_get_visible (child))
|
|
|
|
|
gtk_widget_get_preferred_height_for_width (child, width - full_border.left - full_border.right,
|
|
|
|
|
&child_min, &child_natural);
|
|
|
|
|
|
2014-04-30 07:19:33 +00:00
|
|
|
|
*minimum_height_out = full_border.top + child_min + full_border.bottom;
|
|
|
|
|
*natural_height_out = full_border.top + child_natural + full_border.bottom;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-28 01:39:10 +00:00
|
|
|
|
gtk_list_box_row_get_preferred_width (GtkWidget *widget,
|
|
|
|
|
gint *minimum_width_out,
|
|
|
|
|
gint *natural_width_out)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row = GTK_LIST_BOX_ROW (widget);
|
|
|
|
|
GtkWidget *child;
|
|
|
|
|
gint child_min = 0, child_natural = 0;
|
|
|
|
|
GtkBorder full_border;
|
|
|
|
|
|
|
|
|
|
gtk_list_box_row_get_full_border (row, &full_border);
|
|
|
|
|
|
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (row));
|
|
|
|
|
if (child && gtk_widget_get_visible (child))
|
|
|
|
|
gtk_widget_get_preferred_width (child,
|
|
|
|
|
&child_min, &child_natural);
|
|
|
|
|
|
2014-04-30 07:19:33 +00:00
|
|
|
|
*minimum_width_out = full_border.left + child_min + full_border.right;
|
|
|
|
|
*natural_width_out = full_border.left + child_natural + full_border.bottom;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-28 01:39:10 +00:00
|
|
|
|
gtk_list_box_row_get_preferred_width_for_height (GtkWidget *widget,
|
|
|
|
|
gint height,
|
|
|
|
|
gint *minimum_width,
|
|
|
|
|
gint *natural_width)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2013-09-28 01:39:10 +00:00
|
|
|
|
gtk_list_box_row_get_preferred_width (widget, minimum_width, natural_width);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-28 01:39:10 +00:00
|
|
|
|
gtk_list_box_row_size_allocate (GtkWidget *widget,
|
|
|
|
|
GtkAllocation *allocation)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *row = GTK_LIST_BOX_ROW (widget);
|
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
|
|
gtk_widget_set_allocation (widget, allocation);
|
|
|
|
|
|
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (row));
|
|
|
|
|
if (child && gtk_widget_get_visible (child))
|
|
|
|
|
{
|
|
|
|
|
GtkAllocation child_allocation;
|
|
|
|
|
GtkBorder border;
|
|
|
|
|
|
|
|
|
|
gtk_list_box_row_get_full_border (row, &border);
|
|
|
|
|
|
|
|
|
|
child_allocation.x = allocation->x + border.left;
|
|
|
|
|
child_allocation.y = allocation->y + border.top;
|
|
|
|
|
child_allocation.width = allocation->width - border.left - border.right;
|
|
|
|
|
child_allocation.height = allocation->height - border.top - border.bottom;
|
|
|
|
|
|
|
|
|
|
child_allocation.width = MAX (1, child_allocation.width);
|
|
|
|
|
child_allocation.height = MAX (1, child_allocation.height);
|
|
|
|
|
|
|
|
|
|
gtk_widget_size_allocate (child, &child_allocation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-11 10:59:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_row_changed:
|
|
|
|
|
* @row: a #GtkListBoxRow
|
|
|
|
|
*
|
|
|
|
|
* Marks @row as changed, causing any state that depends on this
|
2013-06-24 13:58:10 +00:00
|
|
|
|
* to be updated. This affects sorting, filtering and headers.
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Note that calls to this method must be in sync with the data
|
|
|
|
|
* used for the row functions. For instance, if the list is
|
|
|
|
|
* mirroring some external data set, and *two* rows changed in the
|
|
|
|
|
* external data set then when you call gtk_list_box_row_changed()
|
|
|
|
|
* on the first row the sort function must only read the new data
|
|
|
|
|
* for the first of the two changed rows, otherwise the resorting
|
|
|
|
|
* of the rows will be wrong.
|
|
|
|
|
*
|
2014-02-07 18:32:47 +00:00
|
|
|
|
* This generally means that if you don’t fully control the data
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* model you have to duplicate the data that affects the listbox
|
|
|
|
|
* row functions into the row widgets themselves. Another alternative
|
2013-06-15 16:13:28 +00:00
|
|
|
|
* is to call gtk_list_box_invalidate_sort() on any model change,
|
|
|
|
|
* but that is more expensive.
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
|
|
|
|
*/
|
2013-06-10 09:17:10 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_list_box_row_changed (GtkListBoxRow *row)
|
|
|
|
|
{
|
2014-03-29 03:07:41 +00:00
|
|
|
|
GtkListBox *box;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2013-07-04 13:50:09 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX_ROW (row));
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
box = gtk_list_box_row_get_box (row);
|
|
|
|
|
if (box)
|
|
|
|
|
gtk_list_box_got_row_changed (box, row);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-06-11 12:09:19 +00:00
|
|
|
|
* gtk_list_box_row_get_header:
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* @row: a #GtkListBoxRow
|
2013-06-10 09:17:10 +00:00
|
|
|
|
*
|
2013-06-11 12:09:19 +00:00
|
|
|
|
* Returns the current header of the @row. This can be used
|
2013-06-24 13:58:10 +00:00
|
|
|
|
* in a #GtkListBoxUpdateHeaderFunc to see if there is a header
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* set already, and if so to update the state of it.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: (transfer none): the current header, or %NULL if none
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
2013-06-10 09:17:10 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkWidget *
|
2013-06-11 12:09:19 +00:00
|
|
|
|
gtk_list_box_row_get_header (GtkListBoxRow *row)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2013-07-04 13:50:09 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_LIST_BOX_ROW (row), NULL);
|
|
|
|
|
|
2013-09-28 01:39:10 +00:00
|
|
|
|
return ROW_PRIV (row)->header;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-06-11 12:09:19 +00:00
|
|
|
|
* gtk_list_box_row_set_header:
|
2013-06-11 10:59:32 +00:00
|
|
|
|
* @row: a #GtkListBoxRow
|
2013-06-15 16:13:28 +00:00
|
|
|
|
* @header: (allow-none): the header, or %NULL
|
2013-06-10 09:17:10 +00:00
|
|
|
|
*
|
2013-06-11 12:09:19 +00:00
|
|
|
|
* Sets the current header of the @row. This is only allowed to be called
|
2013-06-24 13:58:10 +00:00
|
|
|
|
* from a #GtkListBoxUpdateHeaderFunc. It will replace any existing
|
2013-06-11 12:09:19 +00:00
|
|
|
|
* header in the row, and be shown in front of the row in the listbox.
|
2013-06-11 10:59:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
2013-06-10 09:17:10 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
2013-06-11 12:09:19 +00:00
|
|
|
|
gtk_list_box_row_set_header (GtkListBoxRow *row,
|
2013-06-15 16:13:28 +00:00
|
|
|
|
GtkWidget *header)
|
2013-06-10 09:17:10 +00:00
|
|
|
|
{
|
2013-09-28 01:39:10 +00:00
|
|
|
|
GtkListBoxRowPrivate *priv;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2013-07-04 13:50:09 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_LIST_BOX_ROW (row));
|
|
|
|
|
g_return_if_fail (header == NULL || GTK_IS_WIDGET (header));
|
|
|
|
|
|
2013-09-28 01:39:10 +00:00
|
|
|
|
priv = ROW_PRIV (row);
|
|
|
|
|
|
2013-07-02 11:44:17 +00:00
|
|
|
|
if (priv->header)
|
|
|
|
|
g_object_unref (priv->header);
|
|
|
|
|
|
|
|
|
|
priv->header = header;
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
2013-06-11 12:09:19 +00:00
|
|
|
|
if (header)
|
2013-09-04 19:00:23 +00:00
|
|
|
|
g_object_ref_sink (header);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-04 11:40:21 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_row_get_index:
|
|
|
|
|
* @row: a #GtkListBoxRow
|
|
|
|
|
*
|
|
|
|
|
* Gets the current index of the @row in its #GtkListBox container.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the index of the @row, or -1 if the @row is not in a listbox
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.10
|
|
|
|
|
*/
|
|
|
|
|
gint
|
|
|
|
|
gtk_list_box_row_get_index (GtkListBoxRow *row)
|
|
|
|
|
{
|
2013-09-28 01:39:10 +00:00
|
|
|
|
GtkListBoxRowPrivate *priv;
|
2013-07-04 11:40:21 +00:00
|
|
|
|
|
2013-07-04 13:50:09 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_LIST_BOX_ROW (row), -1);
|
|
|
|
|
|
2013-09-28 01:39:10 +00:00
|
|
|
|
priv = ROW_PRIV (row);
|
|
|
|
|
|
2013-07-04 11:40:21 +00:00
|
|
|
|
if (priv->iter != NULL)
|
|
|
|
|
return g_sequence_iter_get_position (priv->iter);
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-28 23:21:57 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_list_box_row_is_selected:
|
|
|
|
|
* @row: a #GtkListBoxRow
|
|
|
|
|
*
|
|
|
|
|
* Returns whether the child is currently selected in its
|
|
|
|
|
* #GtkListBox container.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if @row is selected
|
|
|
|
|
*
|
|
|
|
|
* Since: 3.14
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_list_box_row_is_selected (GtkListBoxRow *row)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_LIST_BOX_ROW (row), FALSE);
|
|
|
|
|
|
2014-03-29 03:07:41 +00:00
|
|
|
|
return ROW_PRIV (row)->selected;
|
2014-03-28 23:21:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_list_box_row_finalize (GObject *obj)
|
|
|
|
|
{
|
2013-09-28 01:39:10 +00:00
|
|
|
|
g_clear_object (&ROW_PRIV (GTK_LIST_BOX_ROW (obj))->header);
|
2013-06-10 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_list_box_row_parent_class)->finalize (obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_list_box_row_class_init (GtkListBoxRowClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
2013-09-22 00:49:18 +00:00
|
|
|
|
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_LIST_BOX_ROW_ACCESSIBLE);
|
|
|
|
|
|
2013-06-10 09:17:10 +00:00
|
|
|
|
object_class->finalize = gtk_list_box_row_finalize;
|
|
|
|
|
|
2013-09-28 01:39:10 +00:00
|
|
|
|
widget_class->show = gtk_list_box_row_show;
|
|
|
|
|
widget_class->hide = gtk_list_box_row_hide;
|
|
|
|
|
widget_class->draw = gtk_list_box_row_draw;
|
|
|
|
|
widget_class->get_preferred_height = gtk_list_box_row_get_preferred_height;
|
|
|
|
|
widget_class->get_preferred_height_for_width = gtk_list_box_row_get_preferred_height_for_width;
|
|
|
|
|
widget_class->get_preferred_width = gtk_list_box_row_get_preferred_width;
|
|
|
|
|
widget_class->get_preferred_width_for_height = gtk_list_box_row_get_preferred_width_for_height;
|
|
|
|
|
widget_class->size_allocate = gtk_list_box_row_size_allocate;
|
|
|
|
|
widget_class->focus = gtk_list_box_row_focus;
|
|
|
|
|
|
|
|
|
|
klass->activate = gtk_list_box_row_activate;
|
2013-09-10 12:12:07 +00:00
|
|
|
|
|
|
|
|
|
row_signals[ROW__ACTIVATE] =
|
|
|
|
|
g_signal_new (I_("activate"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (object_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
|
G_STRUCT_OFFSET (GtkListBoxRowClass, activate),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
_gtk_marshal_VOID__VOID,
|
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
widget_class->activate_signal = row_signals[ROW__ACTIVATE];
|
2013-06-10 09:17:10 +00:00
|
|
|
|
}
|