X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpspp-sheet-view-column.c;h=3afa10fdcc7d254050f069b26059bd6b66097595;hb=2fd2474505b93912de67053897566bf325dd5b08;hp=d8f863dc3bde232d44aee50dbbe6c2f118bfa7f1;hpb=7ecdf4e88e39024da846a25c98caa2887f0dac59;p=pspp diff --git a/src/ui/gui/pspp-sheet-view-column.c b/src/ui/gui/pspp-sheet-view-column.c index d8f863dc3b..3afa10fdcc 100644 --- a/src/ui/gui/pspp-sheet-view-column.c +++ b/src/ui/gui/pspp-sheet-view-column.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2011, 2012 Free Software Foundation, Inc. + Copyright (C) 2011, 2012, 2015 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -43,6 +43,8 @@ #include #include "ui/gui/psppire-marshal.h" +#include "ui/gui/pspp-sheet-selection.h" +#include "ui/gui/pspp-widget-facade.h" #define P_(STRING) STRING #define GTK_PARAM_READABLE G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB @@ -66,12 +68,20 @@ enum PROP_REORDERABLE, PROP_SORT_INDICATOR, PROP_SORT_ORDER, - PROP_SORT_COLUMN_ID + PROP_SORT_COLUMN_ID, + PROP_QUICK_EDIT, + PROP_SELECTED, + PROP_SELECTABLE, + PROP_ROW_HEAD, + PROP_TABBABLE }; enum { CLICKED, + QUERY_TOOLTIP, + POPUP_MENU, + BUTTON_PRESS_EVENT, LAST_SIGNAL }; @@ -131,17 +141,22 @@ static GList *pspp_sheet_view_column_cell_layout_get_cells (GtkCellLayout /* Button handling code */ static void pspp_sheet_view_column_create_button (PsppSheetViewColumn *tree_column); -static void pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column); +void pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column); /* Button signal handlers */ static gint pspp_sheet_view_column_button_event (GtkWidget *widget, - GdkEvent *event, + GdkEventButton *event, gpointer data); static void pspp_sheet_view_column_button_clicked (GtkWidget *widget, gpointer data); +static void pspp_sheet_view_column_button_popup_menu (GtkWidget *widget, + gpointer data); static gboolean pspp_sheet_view_column_mnemonic_activate (GtkWidget *widget, gboolean group_cycling, gpointer data); +static gboolean on_pspp_sheet_view_column_button_clicked (PsppSheetViewColumn *); +static gboolean on_pspp_sheet_view_column_button_press_event (PsppSheetViewColumn *, + GdkEventButton *); /* Property handlers */ static void pspp_sheet_view_model_sort_column_changed (GtkTreeSortable *sortable, @@ -171,7 +186,7 @@ static void pspp_sheet_view_column_buildable_init (GtkBuildableI static guint tree_column_signals[LAST_SIGNAL] = { 0 }; -G_DEFINE_TYPE_WITH_CODE (PsppSheetViewColumn, pspp_sheet_view_column, GTK_TYPE_OBJECT, +G_DEFINE_TYPE_WITH_CODE (PsppSheetViewColumn, pspp_sheet_view_column, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT, pspp_sheet_view_column_cell_layout_init) G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, @@ -185,7 +200,8 @@ pspp_sheet_view_column_class_init (PsppSheetViewColumnClass *class) object_class = (GObjectClass*) class; - class->clicked = NULL; + class->clicked = on_pspp_sheet_view_column_button_clicked; + class->button_press_event = on_pspp_sheet_view_column_button_press_event; object_class->finalize = pspp_sheet_view_column_finalize; object_class->set_property = pspp_sheet_view_column_set_property; @@ -196,10 +212,39 @@ pspp_sheet_view_column_class_init (PsppSheetViewColumnClass *class) G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (PsppSheetViewColumnClass, clicked), + g_signal_accumulator_true_handled, NULL, + psppire_marshal_BOOLEAN__VOID, + G_TYPE_BOOLEAN, 0); + + tree_column_signals[POPUP_MENU] = + g_signal_new ("popup-menu", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + tree_column_signals[QUERY_TOOLTIP] = + g_signal_new ("query-tooltip", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + 0, + g_signal_accumulator_true_handled, NULL, + psppire_marshal_BOOLEAN__OBJECT, + G_TYPE_BOOLEAN, 1, + GTK_TYPE_TOOLTIP); + + tree_column_signals[BUTTON_PRESS_EVENT] = + g_signal_new ("button-press-event", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (PsppSheetViewColumnClass, button_press_event), + g_signal_accumulator_true_handled, NULL, + psppire_marshal_BOOLEAN__BOXED, + G_TYPE_BOOLEAN, 1, + GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); + g_object_class_install_property (object_class, PROP_VISIBLE, g_param_spec_boolean ("visible", @@ -350,14 +395,76 @@ pspp_sheet_view_column_class_init (PsppSheetViewColumnClass *class) G_MAXINT, -1, GTK_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_QUICK_EDIT, + g_param_spec_boolean ("quick-edit", + P_("Quick edit"), + P_("If true, editing starts upon the first click in the column. If false, the first click selects the column and a second click is needed to begin editing. This has no effect on cells that are not editable."), + TRUE, + GTK_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_SELECTED, + g_param_spec_boolean ("selected", + P_("Selected"), + P_("If true, this column is selected as part of a rectangular selection."), + FALSE, + GTK_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_SELECTABLE, + g_param_spec_boolean ("selectable", + P_("Selectable"), + P_("If true, this column may be selected as part of a rectangular selection."), + TRUE, + GTK_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_ROW_HEAD, + g_param_spec_boolean ("row-head", + P_("Row head"), + P_("If true, this column is a \"row head\", equivalent to a column head. If rectangular selection is enabled, then shift+click and control+click in the column select row ranges and toggle row selection, respectively. The column should ordinarily include a button cell; clicking on the button will select the row (and deselect all other rows)."), + FALSE, + GTK_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_TABBABLE, + g_param_spec_boolean ("tabbable", + P_("Tabbable"), + P_("If true, Tab and Shift+Tab visit this column. If false, Tab and Shift+Tab skip this column."), + TRUE, + GTK_PARAM_READWRITE)); } + +static void _cell_layout_buildable_custom_tag_end (GtkBuildable *buildable, + GtkBuilder *builder, + GObject *child, + const gchar *tagname, + gpointer *data); + + +static void _cell_layout_buildable_add_child (GtkBuildable *buildable, + GtkBuilder *builder, + GObject *child, + const gchar *type); + + +static gboolean _cell_layout_buildable_custom_tag_start (GtkBuildable *buildable, + GtkBuilder *builder, + GObject *child, + const gchar *tagname, + GMarkupParser *parser, + gpointer *data); + + static void pspp_sheet_view_column_buildable_init (GtkBuildableIface *iface) { - iface->add_child = _gtk_cell_layout_buildable_add_child; - iface->custom_tag_start = _gtk_cell_layout_buildable_custom_tag_start; - iface->custom_tag_end = _gtk_cell_layout_buildable_custom_tag_end; + iface->add_child = _cell_layout_buildable_add_child; + iface->custom_tag_start = _cell_layout_buildable_custom_tag_start; + iface->custom_tag_end = _cell_layout_buildable_custom_tag_end; } static void @@ -389,6 +496,10 @@ pspp_sheet_view_column_init (PsppSheetViewColumn *tree_column) tree_column->expand = FALSE; tree_column->clickable = FALSE; tree_column->dirty = TRUE; + tree_column->selected = FALSE; + tree_column->selectable = TRUE; + tree_column->row_head = FALSE; + tree_column->tabbable = TRUE; tree_column->sort_order = GTK_SORT_ASCENDING; tree_column->show_sort_indicator = FALSE; tree_column->property_changed_signal = 0; @@ -400,6 +511,7 @@ pspp_sheet_view_column_init (PsppSheetViewColumn *tree_column) tree_column->fixed_width = 1; tree_column->use_resized_width = FALSE; tree_column->title = g_strdup (""); + tree_column->quick_edit = TRUE; } static void @@ -519,7 +631,32 @@ pspp_sheet_view_column_set_property (GObject *object, pspp_sheet_view_column_set_sort_column_id (tree_column, g_value_get_int (value)); break; - + + case PROP_QUICK_EDIT: + pspp_sheet_view_column_set_quick_edit (tree_column, + g_value_get_boolean (value)); + break; + + case PROP_SELECTED: + pspp_sheet_view_column_set_selected (tree_column, + g_value_get_boolean (value)); + break; + + case PROP_SELECTABLE: + pspp_sheet_view_column_set_selectable (tree_column, + g_value_get_boolean (value)); + break; + + case PROP_ROW_HEAD: + pspp_sheet_view_column_set_row_head (tree_column, + g_value_get_boolean (value)); + break; + + case PROP_TABBABLE: + pspp_sheet_view_column_set_tabbable (tree_column, + g_value_get_boolean (value)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -617,7 +754,32 @@ pspp_sheet_view_column_get_property (GObject *object, g_value_set_int (value, pspp_sheet_view_column_get_sort_column_id (tree_column)); break; - + + case PROP_QUICK_EDIT: + g_value_set_boolean (value, + pspp_sheet_view_column_get_quick_edit (tree_column)); + break; + + case PROP_SELECTED: + g_value_set_boolean (value, + pspp_sheet_view_column_get_selected (tree_column)); + break; + + case PROP_SELECTABLE: + g_value_set_boolean (value, + pspp_sheet_view_column_get_selectable (tree_column)); + break; + + case PROP_ROW_HEAD: + g_value_set_boolean (value, + pspp_sheet_view_column_get_row_head (tree_column)); + break; + + case PROP_TABBABLE: + g_value_set_boolean (value, + pspp_sheet_view_column_get_tabbable (tree_column)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -812,6 +974,35 @@ pspp_sheet_view_column_clear_attributes_by_info (PsppSheetViewColumn *tree_colum _pspp_sheet_view_column_cell_set_dirty (tree_column); } +static gboolean +on_query_tooltip (GtkWidget *widget, + gint x, + gint y, + gboolean keyboard_mode, + GtkTooltip *tooltip, + gpointer user_data) +{ + PsppSheetViewColumn *tree_column = user_data; + gboolean handled; + + g_signal_emit (tree_column, tree_column_signals[QUERY_TOOLTIP], 0, + tooltip, &handled); + return handled; +} + +static gboolean +on_button_pressed (GtkWidget *widget, GdkEventButton *event, + gpointer user_data) +{ + PsppSheetViewColumn *tree_column = user_data; + gboolean handled; + + /* XXX See "Implement GtkWidget::popup_menu" in GTK+ reference manual. */ + g_signal_emit (tree_column, tree_column_signals[BUTTON_PRESS_EVENT], + 0, event, &handled); + return handled; +} + /* Helper functions */ @@ -829,10 +1020,8 @@ pspp_sheet_view_column_create_button (PsppSheetViewColumn *tree_column) g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view)); g_return_if_fail (tree_column->button == NULL); - gtk_widget_push_composite_child (); tree_column->button = gtk_button_new (); gtk_widget_add_events (tree_column->button, GDK_POINTER_MOTION_MASK); - gtk_widget_pop_composite_child (); /* make sure we own a reference to it as well. */ if (tree_view->priv->header_window) @@ -845,11 +1034,19 @@ pspp_sheet_view_column_create_button (PsppSheetViewColumn *tree_column) g_signal_connect (tree_column->button, "clicked", G_CALLBACK (pspp_sheet_view_column_button_clicked), tree_column); + g_signal_connect (tree_column->button, "popup-menu", + G_CALLBACK (pspp_sheet_view_column_button_popup_menu), + tree_column); + g_signal_connect (tree_column->button, "button-press-event", + G_CALLBACK (on_button_pressed), tree_column); + + g_signal_connect (tree_column->button, "query-tooltip", + G_CALLBACK (on_query_tooltip), tree_column); + g_object_set (tree_column->button, "has-tooltip", TRUE, NULL); tree_column->alignment = gtk_alignment_new (tree_column->xalign, 0.5, 0.0, 0.0); - hbox = gtk_hbox_new (FALSE, 2); - tree_column->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN); + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2); if (tree_column->child) child = tree_column->child; @@ -863,10 +1060,6 @@ pspp_sheet_view_column_create_button (PsppSheetViewColumn *tree_column) G_CALLBACK (pspp_sheet_view_column_mnemonic_activate), tree_column); - if (tree_column->xalign <= 0.5) - gtk_box_pack_end (GTK_BOX (hbox), tree_column->arrow, FALSE, FALSE, 0); - else - gtk_box_pack_start (GTK_BOX (hbox), tree_column->arrow, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), tree_column->alignment, TRUE, TRUE, 0); @@ -878,16 +1071,14 @@ pspp_sheet_view_column_create_button (PsppSheetViewColumn *tree_column) pspp_sheet_view_column_update_button (tree_column); } -static void +void pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column) { gint sort_column_id = -1; - GtkWidget *hbox; GtkWidget *alignment; - GtkWidget *arrow; GtkWidget *current_child; - GtkArrowType arrow_type = GTK_ARROW_NONE; GtkTreeModel *model; + gboolean can_focus; if (tree_column->tree_view) model = pspp_sheet_view_get_model (PSPP_SHEET_VIEW (tree_column->tree_view)); @@ -904,10 +1095,8 @@ pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column) if (! tree_column->button) return; - hbox = GTK_BIN (tree_column->button)->child; alignment = tree_column->alignment; - arrow = tree_column->arrow; - current_child = GTK_BIN (alignment)->child; + current_child = gtk_bin_get_child (GTK_BIN (alignment)); /* Set up the actual button */ gtk_alignment_set (GTK_ALIGNMENT (alignment), tree_column->xalign, @@ -948,58 +1137,6 @@ pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column) &sort_column_id, NULL); - if (tree_column->show_sort_indicator) - { - gboolean alternative; - - g_object_get (gtk_widget_get_settings (tree_column->tree_view), - "gtk-alternative-sort-arrows", &alternative, - NULL); - - switch (tree_column->sort_order) - { - case GTK_SORT_ASCENDING: - arrow_type = alternative ? GTK_ARROW_UP : GTK_ARROW_DOWN; - break; - - case GTK_SORT_DESCENDING: - arrow_type = alternative ? GTK_ARROW_DOWN : GTK_ARROW_UP; - break; - - default: - g_warning (G_STRLOC": bad sort order"); - break; - } - } - - gtk_arrow_set (GTK_ARROW (arrow), - arrow_type, - GTK_SHADOW_IN); - - /* Put arrow on the right if the text is left-or-center justified, and on the - * left otherwise; do this by packing boxes, so flipping text direction will - * reverse things - */ - g_object_ref (arrow); - gtk_container_remove (GTK_CONTAINER (hbox), arrow); - - if (tree_column->xalign <= 0.5) - { - gtk_box_pack_end (GTK_BOX (hbox), arrow, FALSE, FALSE, 0); - } - else - { - gtk_box_pack_start (GTK_BOX (hbox), arrow, FALSE, FALSE, 0); - /* move it to the front */ - gtk_box_reorder_child (GTK_BOX (hbox), arrow, 0); - } - g_object_unref (arrow); - - if (tree_column->show_sort_indicator - || (GTK_IS_TREE_SORTABLE (model) && tree_column->sort_column_id >= 0)) - gtk_widget_show (arrow); - else - gtk_widget_hide (arrow); /* It's always safe to hide the button. It isn't always safe to show it, as * if you show it before it's realized, it'll get the wrong window. */ @@ -1009,7 +1146,7 @@ pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column) { if (tree_column->visible) { - gtk_widget_show_now (tree_column->button); + gtk_widget_show (tree_column->button); if (tree_column->window) { if (tree_column->resizable) @@ -1030,23 +1167,18 @@ pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column) gdk_window_hide (tree_column->window); } } - - if (tree_column->reorderable || tree_column->clickable) - { - gtk_widget_set_can_focus (tree_column->button, TRUE); - } - else + + can_focus = pspp_sheet_view_column_can_focus (tree_column); + gtk_widget_set_can_focus (tree_column->button, can_focus); + if (!can_focus && gtk_widget_has_focus (tree_column->button)) { - gtk_widget_set_can_focus (tree_column->button, FALSE); - if (gtk_widget_has_focus (tree_column->button)) - { - GtkWidget *toplevel = gtk_widget_get_toplevel (tree_column->tree_view); - if (gtk_widget_is_toplevel (toplevel)) - { - gtk_window_set_focus (GTK_WINDOW (toplevel), NULL); - } - } + GtkWidget *toplevel = gtk_widget_get_toplevel (tree_column->tree_view); + if (gtk_widget_is_toplevel (toplevel)) + { + gtk_window_set_focus (GTK_WINDOW (toplevel), NULL); + } } + /* Queue a resize on the assumption that we always want to catch all changes * and columns don't change all that often. */ @@ -1060,7 +1192,7 @@ pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column) static gint pspp_sheet_view_column_button_event (GtkWidget *widget, - GdkEvent *event, + GdkEventButton *event, gpointer data) { PsppSheetViewColumn *column = (PsppSheetViewColumn *) data; @@ -1072,7 +1204,8 @@ pspp_sheet_view_column_button_event (GtkWidget *widget, ((GdkEventButton *)event)->button == 1) { column->maybe_reordered = TRUE; - gdk_window_get_pointer (GTK_BUTTON (widget)->event_window, + gdk_window_get_device_position (gtk_button_get_event_window (GTK_BUTTON (widget)), + event->device, &column->drag_x, &column->drag_y, NULL); @@ -1099,9 +1232,6 @@ pspp_sheet_view_column_button_event (GtkWidget *widget, { switch (event->type) { - case GDK_BUTTON_PRESS: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: case GDK_MOTION_NOTIFY: case GDK_BUTTON_RELEASE: case GDK_ENTER_NOTIFY: @@ -1114,11 +1244,131 @@ pspp_sheet_view_column_button_event (GtkWidget *widget, return FALSE; } +static gboolean +all_rows_selected (PsppSheetView *sheet_view) +{ + PsppSheetSelection *selection = sheet_view->priv->selection; + gint n_rows, n_selected_rows; + + n_rows = sheet_view->priv->row_count; + n_selected_rows = pspp_sheet_selection_count_selected_rows (selection); + + return n_rows > 0 && n_selected_rows >= n_rows; +} + +static gboolean +on_pspp_sheet_view_column_button_press_event (PsppSheetViewColumn *column, + GdkEventButton *event) +{ + PsppSheetView *sheet_view = PSPP_SHEET_VIEW (column->tree_view); + PsppSheetSelection *selection; + GSignalInvocationHint *hint; + guint modifiers; + + /* We only want to run first, not last, but combining that with return type + `gboolean' makes GObject warn, so just ignore the run_last call. */ + hint = g_signal_get_invocation_hint (column); + g_return_val_if_fail (hint != NULL, FALSE); + if (hint->run_type != G_SIGNAL_RUN_FIRST) + return FALSE; + + g_return_val_if_fail (sheet_view != NULL, FALSE); + + selection = sheet_view->priv->selection; + g_return_val_if_fail (selection != NULL, FALSE); + + if (pspp_sheet_selection_get_mode (selection) != PSPP_SHEET_SELECTION_RECTANGLE) + return FALSE; + + modifiers = event->state & gtk_accelerator_get_default_mod_mask (); + if (event->type == GDK_BUTTON_PRESS && event->button == 3) + { + if (pspp_sheet_selection_count_selected_columns (selection) <= 1 + || !all_rows_selected (sheet_view)) + { + pspp_sheet_selection_select_all (selection); + pspp_sheet_selection_unselect_all_columns (selection); + pspp_sheet_selection_select_column (selection, column); + sheet_view->priv->anchor_column = column; + } + return FALSE; + } + else if (event->type == GDK_BUTTON_PRESS && event->button == 1 + && modifiers == GDK_CONTROL_MASK) + { + gboolean is_selected; + + if (!all_rows_selected (sheet_view)) + { + pspp_sheet_selection_select_all (selection); + pspp_sheet_selection_unselect_all_columns (selection); + } + sheet_view->priv->anchor_column = column; + + is_selected = pspp_sheet_view_column_get_selected (column); + pspp_sheet_view_column_set_selected (column, !is_selected); + + return TRUE; + } + else if (event->type == GDK_BUTTON_PRESS && event->button == 1 + && modifiers == GDK_SHIFT_MASK) + { + if (!all_rows_selected (sheet_view)) + { + pspp_sheet_selection_select_all (selection); + pspp_sheet_selection_unselect_all_columns (selection); + sheet_view->priv->anchor_column = column; + } + else if (sheet_view->priv->anchor_column == NULL) + sheet_view->priv->anchor_column = column; + + pspp_sheet_selection_unselect_all_columns (selection); + pspp_sheet_selection_select_column_range (selection, + sheet_view->priv->anchor_column, + column); + return TRUE; + } + + return FALSE; +} + +static gboolean +on_pspp_sheet_view_column_button_clicked (PsppSheetViewColumn *column) +{ + PsppSheetSelection *selection; + PsppSheetView *sheet_view; + + sheet_view = PSPP_SHEET_VIEW (pspp_sheet_view_column_get_tree_view (column)); + selection = pspp_sheet_view_get_selection (sheet_view); + if (pspp_sheet_selection_get_mode (selection) == PSPP_SHEET_SELECTION_RECTANGLE) + { + pspp_sheet_selection_select_all (selection); + if (pspp_sheet_view_column_get_row_head (column)) + pspp_sheet_selection_select_all_columns (selection); + else + { + pspp_sheet_selection_unselect_all_columns (selection); + pspp_sheet_selection_select_column (selection, column); + } + sheet_view->priv->anchor_column = column; + return TRUE; + } + return FALSE; +} static void pspp_sheet_view_column_button_clicked (GtkWidget *widget, gpointer data) { - g_signal_emit_by_name (data, "clicked"); + PsppSheetViewColumn *column = data; + gboolean handled; + + g_signal_emit (column, tree_column_signals[CLICKED], 0, &handled); +} + +static void +pspp_sheet_view_column_button_popup_menu (GtkWidget *widget, gpointer data) +{ + g_signal_emit_by_name (data, "popup-menu"); } static gboolean @@ -1259,6 +1509,7 @@ pspp_sheet_view_column_setup_sort_column_id_callback (PsppSheetViewColumn *tree_ void _pspp_sheet_view_column_realize_button (PsppSheetViewColumn *column) { + GtkAllocation allocation; PsppSheetView *tree_view; GdkWindowAttr attr; guint attributes_mask; @@ -1270,6 +1521,9 @@ _pspp_sheet_view_column_realize_button (PsppSheetViewColumn *column) g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view)); g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view))); g_return_if_fail (tree_view->priv->header_window != NULL); + if (!column->button) + return; + g_return_if_fail (column->button != NULL); gtk_widget_set_parent_window (column->button, tree_view->priv->header_window); @@ -1280,7 +1534,6 @@ _pspp_sheet_view_column_realize_button (PsppSheetViewColumn *column) attr.window_type = GDK_WINDOW_CHILD; attr.wclass = GDK_INPUT_ONLY; attr.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view)); - attr.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view)); attr.event_mask = gtk_widget_get_events (GTK_WIDGET (tree_view)) | (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | @@ -1288,31 +1541,32 @@ _pspp_sheet_view_column_realize_button (PsppSheetViewColumn *column) GDK_POINTER_MOTION_HINT_MASK | GDK_KEY_PRESS_MASK); attributes_mask = GDK_WA_CURSOR | GDK_WA_X | GDK_WA_Y; - attr.cursor = gdk_cursor_new_for_display (gdk_drawable_get_display (tree_view->priv->header_window), + attr.cursor = gdk_cursor_new_for_display (gdk_window_get_display (tree_view->priv->header_window), GDK_SB_H_DOUBLE_ARROW); attr.y = 0; attr.width = TREE_VIEW_DRAG_WIDTH; attr.height = tree_view->priv->header_height; - - attr.x = (column->button->allocation.x + (rtl ? 0 : column->button->allocation.width)) - TREE_VIEW_DRAG_WIDTH / 2; + gtk_widget_get_allocation (column->button, &allocation); + attr.x = (allocation.x + (rtl ? 0 : allocation.width)) - TREE_VIEW_DRAG_WIDTH / 2; column->window = gdk_window_new (tree_view->priv->header_window, &attr, attributes_mask); gdk_window_set_user_data (column->window, tree_view); pspp_sheet_view_column_update_button (column); - gdk_cursor_unref (attr.cursor); + g_object_unref (attr.cursor); } void _pspp_sheet_view_column_unrealize_button (PsppSheetViewColumn *column) { g_return_if_fail (column != NULL); - g_return_if_fail (column->window != NULL); - - gdk_window_set_user_data (column->window, NULL); - gdk_window_destroy (column->window); - column->window = NULL; + if (column->window != NULL) + { + gdk_window_set_user_data (column->window, NULL); + gdk_window_destroy (column->window); + column->window = NULL; + } } void @@ -1376,9 +1630,12 @@ _pspp_sheet_view_column_has_editable_cell (PsppSheetViewColumn *column) GList *list; for (list = column->cell_list; list; list = list->next) - if (((PsppSheetViewColumnCellInfo *)list->data)->cell->mode == - GTK_CELL_RENDERER_MODE_EDITABLE) - return TRUE; + { + GtkCellRendererMode mode; + g_object_get (((PsppSheetViewColumnCellInfo *)list->data)->cell, "mode", &mode, NULL); + if (mode == GTK_CELL_RENDERER_MODE_EDITABLE) + return TRUE; + } return FALSE; } @@ -1406,9 +1663,12 @@ _pspp_sheet_view_column_count_special_cells (PsppSheetViewColumn *column) { PsppSheetViewColumnCellInfo *cellinfo = list->data; - if ((cellinfo->cell->mode == GTK_CELL_RENDERER_MODE_EDITABLE || - cellinfo->cell->mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE) && - cellinfo->cell->visible) + GtkCellRendererMode mode; + g_object_get (cellinfo->cell, "mode", &mode, NULL); + + if ((mode == GTK_CELL_RENDERER_MODE_EDITABLE || + mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE) && + gtk_cell_renderer_get_visible (cellinfo->cell)) i++; } @@ -2065,7 +2325,7 @@ pspp_sheet_view_column_set_title (PsppSheetViewColumn *tree_column, * Return value: the title of the column. This string should not be * modified or freed. **/ -G_CONST_RETURN gchar * +const gchar * pspp_sheet_view_column_get_title (PsppSheetViewColumn *tree_column) { g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), NULL); @@ -2091,7 +2351,7 @@ pspp_sheet_view_column_set_expand (PsppSheetViewColumn *tree_column, { g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column)); - expand = expand?TRUE:FALSE; + expand = !!expand; if (tree_column->expand == expand) return; tree_column->expand = expand; @@ -2272,10 +2532,11 @@ pspp_sheet_view_column_set_reorderable (PsppSheetViewColumn *tree_column, /* if (reorderable) pspp_sheet_view_column_set_clickable (tree_column, TRUE);*/ - if (tree_column->reorderable == (reorderable?TRUE:FALSE)) + reorderable = !!reorderable; + if (tree_column->reorderable == reorderable) return; - tree_column->reorderable = (reorderable?TRUE:FALSE); + tree_column->reorderable = reorderable; pspp_sheet_view_column_update_button (tree_column); g_object_notify (G_OBJECT (tree_column), "reorderable"); } @@ -2296,6 +2557,209 @@ pspp_sheet_view_column_get_reorderable (PsppSheetViewColumn *tree_column) return tree_column->reorderable; } +/** + * pspp_sheet_view_column_set_quick_edit: + * @tree_column: A #PsppSheetViewColumn + * @quick_edit: If true, editing starts upon the first click in the column. If + * false, the first click selects the column and a second click is needed to + * begin editing. This has no effect on cells that are not editable. + **/ +void +pspp_sheet_view_column_set_quick_edit (PsppSheetViewColumn *tree_column, + gboolean quick_edit) +{ + g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column)); + + quick_edit = !!quick_edit; + if (tree_column->quick_edit != quick_edit) + { + tree_column->quick_edit = quick_edit; + g_object_notify (G_OBJECT (tree_column), "quick-edit"); + } +} + +/** + * pspp_sheet_view_column_get_quick_edit: + * @tree_column: A #PsppSheetViewColumn + * + * Returns %TRUE if editing starts upon the first click in the column. Returns + * %FALSE, the first click selects the column and a second click is needed to + * begin editing. This is not meaningful for cells that are not editable. + * + * Return value: %TRUE if editing starts upon the first click. + **/ +gboolean +pspp_sheet_view_column_get_quick_edit (PsppSheetViewColumn *tree_column) +{ + g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE); + + return tree_column->quick_edit; +} + + +/** + * pspp_sheet_view_column_set_selected: + * @tree_column: A #PsppSheetViewColumn + * @selected: If true, the column is selected as part of a rectangular + * selection. + **/ +void +pspp_sheet_view_column_set_selected (PsppSheetViewColumn *tree_column, + gboolean selected) +{ + g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column)); + + selected = !!selected; + if (tree_column->selected != selected) + { + PsppSheetSelection *selection; + PsppSheetView *sheet_view; + + if (tree_column->tree_view != NULL) + gtk_widget_queue_draw (GTK_WIDGET (tree_column->tree_view)); + tree_column->selected = selected; + g_object_notify (G_OBJECT (tree_column), "selected"); + + sheet_view = PSPP_SHEET_VIEW (pspp_sheet_view_column_get_tree_view ( + tree_column)); + selection = pspp_sheet_view_get_selection (sheet_view); + _pspp_sheet_selection_emit_changed (selection); + } +} + +/** + * pspp_sheet_view_column_get_selected: + * @tree_column: A #PsppSheetViewColumn + * + * Returns %TRUE if the column is selected as part of a rectangular + * selection. + * + * Return value: %TRUE if the column is selected as part of a rectangular + * selection. + **/ +gboolean +pspp_sheet_view_column_get_selected (PsppSheetViewColumn *tree_column) +{ + g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE); + + return tree_column->selected; +} + +/** + * pspp_sheet_view_column_set_selectable: + * @tree_column: A #PsppSheetViewColumn + * @selectable: If true, the column may be selected as part of a rectangular + * selection. + **/ +void +pspp_sheet_view_column_set_selectable (PsppSheetViewColumn *tree_column, + gboolean selectable) +{ + g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column)); + + selectable = !!selectable; + if (tree_column->selectable != selectable) + { + if (tree_column->tree_view != NULL) + gtk_widget_queue_draw (GTK_WIDGET (tree_column->tree_view)); + tree_column->selectable = selectable; + g_object_notify (G_OBJECT (tree_column), "selectable"); + } +} + +/** + * pspp_sheet_view_column_get_selectable: + * @tree_column: A #PsppSheetViewColumn + * + * Returns %TRUE if the column may be selected as part of a rectangular + * selection. + * + * Return value: %TRUE if the column may be selected as part of a rectangular + * selection. + **/ +gboolean +pspp_sheet_view_column_get_selectable (PsppSheetViewColumn *tree_column) +{ + g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE); + + return tree_column->selectable; +} + + +/** + * pspp_sheet_view_column_set_row_head: + * @tree_column: A #PsppSheetViewColumn + * @row_head: If true, the column is a "row head", analogous to a column head. + * See the description of the row-head property for more information. + **/ +void +pspp_sheet_view_column_set_row_head (PsppSheetViewColumn *tree_column, + gboolean row_head) +{ + g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column)); + + row_head = !!row_head; + if (tree_column->row_head != row_head) + { + tree_column->row_head = row_head; + g_object_notify (G_OBJECT (tree_column), "row_head"); + } +} + +/** + * pspp_sheet_view_column_get_row_head: + * @tree_column: A #PsppSheetViewColumn + * + * Returns %TRUE if the column is a row head. + * + * Return value: %TRUE if the column is a row head. + **/ +gboolean +pspp_sheet_view_column_get_row_head (PsppSheetViewColumn *tree_column) +{ + g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE); + + return tree_column->row_head; +} + + +/** + * pspp_sheet_view_column_set_tabbable: + * @tree_column: A #PsppSheetViewColumn + * @tabbable: If true, the column is "tabbable", meaning that Tab and Shift+Tab + * in the sheet visit this column. If false, Tab and Shift+Tab skip this + * column. + **/ +void +pspp_sheet_view_column_set_tabbable (PsppSheetViewColumn *tree_column, + gboolean tabbable) +{ + g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column)); + + tabbable = !!tabbable; + if (tree_column->tabbable != tabbable) + { + tree_column->tabbable = tabbable; + g_object_notify (G_OBJECT (tree_column), "tabbable"); + } +} + +/** + * pspp_sheet_view_column_get_tabbable: + * @tree_column: A #PsppSheetViewColumn + * + * Returns %TRUE if the column is tabbable. + * + * Return value: %TRUE if the column is tabbable. + **/ +gboolean +pspp_sheet_view_column_get_tabbable (PsppSheetViewColumn *tree_column) +{ + g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), FALSE); + + return tree_column->tabbable; +} + /** * pspp_sheet_view_column_set_sort_column_id: @@ -2592,12 +3056,11 @@ enum { static gboolean pspp_sheet_view_column_cell_process_action (PsppSheetViewColumn *tree_column, - GdkWindow *window, + cairo_t *cr, const GdkRectangle *background_area, const GdkRectangle *cell_area, guint flags, gint action, - const GdkRectangle *expose_area, /* RENDER */ GdkRectangle *focus_rectangle, /* FOCUS */ GtkCellEditable **editable_widget, /* EVENT */ GdkEvent *event, /* EVENT */ @@ -2606,7 +3069,6 @@ pspp_sheet_view_column_cell_process_action (PsppSheetViewColumn *tree_column, GList *list; GdkRectangle real_cell_area; GdkRectangle real_background_area; - GdkRectangle real_expose_area = *cell_area; gint depth = 0; gint expand_cell_count = 0; gint full_requested_width = 0; @@ -2679,7 +3141,7 @@ pspp_sheet_view_column_cell_process_action (PsppSheetViewColumn *tree_column, { PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *)list->data; - if (! info->cell->visible) + if (! gtk_cell_renderer_get_visible (info->cell)) continue; if (info->expand == TRUE) @@ -2706,7 +3168,7 @@ pspp_sheet_view_column_cell_process_action (PsppSheetViewColumn *tree_column, if (info->pack == GTK_PACK_END) continue; - if (! info->cell->visible) + if (! gtk_cell_renderer_get_visible (info->cell)) continue; if ((info->has_focus || special_cells == 1) && cursor_row) @@ -2751,11 +3213,10 @@ pspp_sheet_view_column_cell_process_action (PsppSheetViewColumn *tree_column, if (action == CELL_ACTION_RENDER) { gtk_cell_renderer_render (info->cell, - window, + cr, tree_column->tree_view, &rtl_background_area, &rtl_cell_area, - &real_expose_area, flags); } /* FOCUS */ @@ -2881,7 +3342,7 @@ pspp_sheet_view_column_cell_process_action (PsppSheetViewColumn *tree_column, if (info->pack == GTK_PACK_START) continue; - if (! info->cell->visible) + if (! gtk_cell_renderer_get_visible (info->cell)) continue; if ((info->has_focus || special_cells == 1) && cursor_row) @@ -2916,11 +3377,10 @@ pspp_sheet_view_column_cell_process_action (PsppSheetViewColumn *tree_column, if (action == CELL_ACTION_RENDER) { gtk_cell_renderer_render (info->cell, - window, + cr, tree_column->tree_view, &rtl_background_area, &rtl_cell_area, - &real_expose_area, flags); } /* FOCUS */ @@ -3064,7 +3524,6 @@ pspp_sheet_view_column_cell_process_action (PsppSheetViewColumn *tree_column, * @window: a #GdkDrawable to draw to * @background_area: entire cell area (including tree expanders and maybe padding on the sides) * @cell_area: area normally rendered by a cell renderer - * @expose_area: area that actually needs updating * @flags: flags that affect rendering * * Renders the cell contained by #tree_column. This is used primarily by the @@ -3072,24 +3531,21 @@ pspp_sheet_view_column_cell_process_action (PsppSheetViewColumn *tree_column, **/ void _pspp_sheet_view_column_cell_render (PsppSheetViewColumn *tree_column, - GdkWindow *window, + cairo_t *cr, const GdkRectangle *background_area, const GdkRectangle *cell_area, - const GdkRectangle *expose_area, guint flags) { g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column)); g_return_if_fail (background_area != NULL); g_return_if_fail (cell_area != NULL); - g_return_if_fail (expose_area != NULL); pspp_sheet_view_column_cell_process_action (tree_column, - window, + cr, background_area, cell_area, flags, CELL_ACTION_RENDER, - expose_area, NULL, NULL, NULL, NULL); } @@ -3110,7 +3566,7 @@ _pspp_sheet_view_column_cell_event (PsppSheetViewColumn *tree_column, cell_area, flags, CELL_ACTION_EVENT, - NULL, NULL, + NULL, editable_widget, event, path_string); @@ -3128,7 +3584,6 @@ _pspp_sheet_view_column_get_focus_area (PsppSheetViewColumn *tree_column, cell_area, 0, CELL_ACTION_FOCUS, - NULL, focus_area, NULL, NULL, NULL); } @@ -3384,10 +3839,9 @@ _pspp_sheet_view_column_cell_focus (PsppSheetViewColumn *tree_column, void _pspp_sheet_view_column_cell_draw_focus (PsppSheetViewColumn *tree_column, - GdkWindow *window, + cairo_t *cr, const GdkRectangle *background_area, const GdkRectangle *cell_area, - const GdkRectangle *expose_area, guint flags) { gint focus_line_width; @@ -3417,22 +3871,21 @@ _pspp_sheet_view_column_cell_draw_focus (PsppSheetViewColumn *tree_column, { GdkRectangle focus_rectangle; pspp_sheet_view_column_cell_process_action (tree_column, - window, + cr, background_area, cell_area, flags, CELL_ACTION_FOCUS, - expose_area, &focus_rectangle, NULL, NULL, NULL); cell_state = flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED : (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT : (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL)); - gtk_paint_focus (tree_column->tree_view->style, - window, + + gtk_paint_focus (gtk_widget_get_style (GTK_WIDGET (tree_column->tree_view)), + cr, cell_state, - cell_area, tree_column->tree_view, "treeview", focus_rectangle.x, @@ -3463,7 +3916,7 @@ pspp_sheet_view_column_cell_is_visible (PsppSheetViewColumn *tree_column) { PsppSheetViewColumnCellInfo *info = (PsppSheetViewColumnCellInfo *) list->data; - if (info->cell->visible) + if (gtk_cell_renderer_get_visible (info->cell)) return TRUE; } @@ -3587,7 +4040,7 @@ _pspp_sheet_view_column_get_neighbor_sizes (PsppSheetViewColumn *column, if (info->cell == cell) break; - if (info->cell->visible) + if (gtk_cell_renderer_get_visible (info->cell)) l += info->real_width + column->spacing; } @@ -3597,7 +4050,7 @@ _pspp_sheet_view_column_get_neighbor_sizes (PsppSheetViewColumn *column, list = pspp_sheet_view_column_cell_next (column, list); - if (info->cell->visible) + if (gtk_cell_renderer_get_visible (info->cell)) r += info->real_width + column->spacing; } @@ -3644,7 +4097,7 @@ pspp_sheet_view_column_cell_get_position (PsppSheetViewColumn *tree_column, break; } - if (cellinfo->cell->visible) + if (gtk_cell_renderer_get_visible (cellinfo->cell)) current_x += cellinfo->real_width; } @@ -3771,8 +4224,8 @@ static const GMarkupParser attributes_parser = attributes_text_element, }; -gboolean -_gtk_cell_layout_buildable_custom_tag_start (GtkBuildable *buildable, +static gboolean +_cell_layout_buildable_custom_tag_start (GtkBuildable *buildable, GtkBuilder *builder, GObject *child, const gchar *tagname, @@ -3799,8 +4252,8 @@ _gtk_cell_layout_buildable_custom_tag_start (GtkBuildable *buildable, return FALSE; } -void -_gtk_cell_layout_buildable_custom_tag_end (GtkBuildable *buildable, +static void +_cell_layout_buildable_custom_tag_end (GtkBuildable *buildable, GtkBuilder *builder, GObject *child, const gchar *tagname, @@ -3813,8 +4266,8 @@ _gtk_cell_layout_buildable_custom_tag_end (GtkBuildable *buildable, g_slice_free (AttributesSubParserData, parser_data); } -void -_gtk_cell_layout_buildable_add_child (GtkBuildable *buildable, +static void +_cell_layout_buildable_add_child (GtkBuildable *buildable, GtkBuilder *builder, GObject *child, const gchar *type) @@ -3828,3 +4281,52 @@ _gtk_cell_layout_buildable_add_child (GtkBuildable *buildable, g_return_if_fail (iface->pack_start != NULL); iface->pack_start (GTK_CELL_LAYOUT (buildable), GTK_CELL_RENDERER (child), FALSE); } + +void +pspp_sheet_view_column_size_request (PsppSheetViewColumn *tree_column, + GtkRequisition *request) +{ + GtkWidget *base = GTK_WIDGET (tree_column->tree_view); + GtkRequisition label_req; + GtkRequisition align_req; + GtkRequisition arrow_req; + GtkRequisition hbox_req; + GtkStyle **button_style; + + if (tree_column->button) + { + gtk_widget_size_request (tree_column->button, request); + return; + } + + facade_label_get_size_request (0, 0, base, tree_column->title, &label_req); + facade_alignment_get_size_request (0, 0, 0, 0, 0, &label_req, &align_req); + facade_arrow_get_size_request (0, 0, &arrow_req); + + facade_hbox_get_base_size_request (0, 2, 2, &hbox_req); + facade_hbox_add_child_size_request (0, &arrow_req, 0, &hbox_req); + facade_hbox_add_child_size_request (0, &align_req, 0, &hbox_req); + + button_style = &PSPP_SHEET_VIEW (tree_column->tree_view)->priv->button_style; + if (*button_style == NULL) + { + *button_style = facade_get_style (base, GTK_TYPE_BUTTON, 0); + g_object_ref (*button_style); + } + facade_button_get_size_request (0, base, *button_style, &hbox_req, request); +} + +void +pspp_sheet_view_column_size_allocate (PsppSheetViewColumn *tree_column, + GtkAllocation *allocation) +{ + tree_column->allocation = *allocation; + if (tree_column->button) + gtk_widget_size_allocate (tree_column->button, allocation); +} + +gboolean +pspp_sheet_view_column_can_focus (PsppSheetViewColumn *tree_column) +{ + return tree_column->reorderable || tree_column->clickable; +}