[yast-commit] r62777 - in /branches/SuSE-Code-11-SP1-Branch/gtk/src: Makefile.am YGPackageSelector.cc YGTable.cc ygtkscrolledwindow.c ygtkscrolledwindow.h ygtktreeview.c ygtktreeview.h
Author: rpmcruz Date: Tue Nov 9 14:44:55 2010 New Revision: 62777 URL: http://svn.opensuse.org/viewcvs/yast?rev=62777&view=rev Log: * src/YGTable.cc: using new code in its place. * src/ygtktreeview.h & src/ygtktreeview.c: replaced old ygtkscrolledwindow files. * src/YGPackageSelector.cc: cope with new ygtktreeview. Added: branches/SuSE-Code-11-SP1-Branch/gtk/src/ygtktreeview.c branches/SuSE-Code-11-SP1-Branch/gtk/src/ygtktreeview.h Removed: branches/SuSE-Code-11-SP1-Branch/gtk/src/ygtkscrolledwindow.c branches/SuSE-Code-11-SP1-Branch/gtk/src/ygtkscrolledwindow.h Modified: branches/SuSE-Code-11-SP1-Branch/gtk/src/Makefile.am branches/SuSE-Code-11-SP1-Branch/gtk/src/YGPackageSelector.cc branches/SuSE-Code-11-SP1-Branch/gtk/src/YGTable.cc Modified: branches/SuSE-Code-11-SP1-Branch/gtk/src/Makefile.am URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/gtk/src/Makefile.am?rev=62777&r1=62776&r2=62777&view=diff ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/gtk/src/Makefile.am (original) +++ branches/SuSE-Code-11-SP1-Branch/gtk/src/Makefile.am Tue Nov 9 14:44:55 2010 @@ -60,7 +60,7 @@ ygdkmngloader.c \ ygtkimage.c \ ygtkcellrenderertextpixbuf.c \ - ygtkscrolledwindow.c \ + ygtktreeview.c \ ygtktogglebutton.c \ ygtkhtmlwrap.c \ ygtktimezonepicker.c \ Modified: branches/SuSE-Code-11-SP1-Branch/gtk/src/YGPackageSelector.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/gtk/src/YGPackageSelector.cc?rev=62777&r1=62776&r2=62777&view=diff ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/gtk/src/YGPackageSelector.cc (original) +++ branches/SuSE-Code-11-SP1-Branch/gtk/src/YGPackageSelector.cc Tue Nov 9 14:44:55 2010 @@ -20,7 +20,7 @@ #include "ygtkwizard.h" #include "ygtkfindentry.h" #include "ygtkmenubutton.h" -#include "ygtkscrolledwindow.h" +#include "ygtktreeview.h" #include "ygtktogglebutton.h" #include "ygtkhtmlwrap.h" #include "ygtkrichtext.h" @@ -423,7 +423,7 @@ TreeView (bool isTree, bool descriptiveTooltip, bool editable, PackagesView *parent) : View (parent), m_isTree (isTree), m_descriptiveTooltip (descriptiveTooltip) { - GtkTreeView *view = GTK_TREE_VIEW (m_widget = ygtk_tree_view_new()); + GtkTreeView *view = GTK_TREE_VIEW (m_widget = ygtk_tree_view_new (_("No matches."))); gtk_tree_view_set_headers_visible (view, FALSE); gtk_tree_view_set_search_column (view, YGtkZyppModel::NAME_COLUMN); gtk_tree_view_set_fixed_height_mode (view, TRUE); @@ -735,17 +735,10 @@ : m_listener (NULL), m_model (NULL), m_view (NULL), m_isTree (isTree), m_descriptiveTooltip (descriptiveTooltip) { if (useScrollWindow) { - m_bin = ygtk_scrolled_window_new(); - if (enableTilesMode) { - GtkWidget *buttons = gtk_vbox_new (FALSE, 0), *button; - button = create_toggle_button ("pkg-list-mode.xpm", _("View as list"), NULL); - gtk_box_pack_start (GTK_BOX (buttons), button, FALSE, TRUE, 0); - button = create_toggle_button ("pkg-tiles-mode.xpm", _("View as grid"), button); - gtk_box_pack_start (GTK_BOX (buttons), button, FALSE, TRUE, 0); - gtk_widget_show_all (buttons); - - ygtk_scrolled_window_set_corner_widget (YGTK_SCROLLED_WINDOW (m_bin), buttons); - } + m_bin = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_bin), + GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (m_bin), GTK_SHADOW_IN); } else m_bin = gtk_event_box_new(); Modified: branches/SuSE-Code-11-SP1-Branch/gtk/src/YGTable.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/gtk/src/YGTable.cc?rev=62777&r1=62776&r2=62777&view=diff ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/gtk/src/YGTable.cc (original) +++ branches/SuSE-Code-11-SP1-Branch/gtk/src/YGTable.cc Tue Nov 9 14:44:55 2010 @@ -1,7 +1,11 @@ /******************************************************************** * YaST2-GTK - http://en.opensuse.org/YaST2-GTK * ********************************************************************/ +/* + Textdomain "gtk" + */ +#include "YGi18n.h" #define YUILogComponent "gtk" #include "config.h" #include "YGUI.h" @@ -9,8 +13,7 @@ #include "YGWidget.h" #include "YSelectionWidget.h" #include "YGSelectionModel.h" -#include "ygtkcellrenderertextpixbuf.h" -#include "ygtkscrolledwindow.h" +#include "ygtktreeview.h" /* A generic widget for table related widgets. */ class YGTableView : public YGScrolledWidget, public YGSelectionModel @@ -56,31 +59,27 @@ void appendIconTextColumn (string header, YAlignmentType align, int icon_col, int text_col) { - GtkTreeViewColumn *column; - GtkCellRenderer *renderer; - - renderer = ygtk_cell_renderer_text_pixbuf_new(); - column = gtk_tree_view_column_new_with_attributes (header.c_str(), - renderer, "pixbuf", icon_col, "text", text_col, NULL); - gfloat xalign = -1; switch (align) { - case YAlignBegin: - xalign = 0.0; - break; - case YAlignCenter: - xalign = 0.5; - break; - case YAlignEnd: - xalign = 1.0; - break; - case YAlignUnchanged: - break; + case YAlignBegin: xalign = 0.0; break; + case YAlignCenter: xalign = 0.5; break; + case YAlignEnd: xalign = 1.0; break; + case YAlignUnchanged: break; } - if (xalign != -1) { + + GtkTreeViewColumn *column = gtk_tree_view_column_new(); + gtk_tree_view_column_set_title (column, header.c_str()); + GtkCellRenderer *renderer; + + renderer = gtk_cell_renderer_pixbuf_new(); + gtk_tree_view_column_pack_start (column, renderer, FALSE); + gtk_tree_view_column_set_attributes (column, renderer, "pixbuf", icon_col, NULL); + + renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_column_pack_start (column, renderer, TRUE); + gtk_tree_view_column_set_attributes (column, renderer, "text", text_col, NULL); + if (xalign != -1) g_object_set (renderer, "xalign", xalign, NULL); - gtk_tree_view_column_set_alignment (column, xalign); - } gtk_tree_view_column_set_resizable (column, TRUE); gtk_tree_view_append_column (getView(), column); @@ -88,14 +87,10 @@ void appendCheckColumn (string header, int bool_col) { - GtkTreeViewColumn *column; - GtkCellRenderer *renderer; - - renderer = gtk_cell_renderer_toggle_new(); + GtkCellRenderer *renderer = gtk_cell_renderer_toggle_new(); g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (bool_col)); - column = gtk_tree_view_column_new_with_attributes (header.c_str(), - renderer, "active", bool_col, NULL); - + GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes ( + header.c_str(), renderer, "active", bool_col, NULL); g_signal_connect (G_OBJECT (renderer), "toggled", G_CALLBACK (toggled_cb), this); @@ -103,10 +98,8 @@ gtk_tree_view_append_column (getView(), column); } - void appendDumbColumn() - { - gtk_tree_view_append_column (getView(), gtk_tree_view_column_new()); - } + void appendEmptyColumn() + { gtk_tree_view_append_column (getView(), gtk_tree_view_column_new()); } void setModel() { gtk_tree_view_set_model (GTK_TREE_VIEW (getWidget()), getModel()); } @@ -227,9 +220,7 @@ #if YAST2_VERSION > 2018003 static void right_click_cb (YGtkTreeView *view, gboolean outreach, YGTableView *pThis) - { - pThis->emitEvent (YEvent::ContextMenuActivated); - } + { pThis->emitEvent (YEvent::ContextMenuActivated); } #endif }; @@ -252,6 +243,7 @@ { gtk_tree_view_set_headers_visible (getView(), TRUE); gtk_tree_view_set_rules_hint (getView(), columns() > 1); + ygtk_tree_view_set_empty_text (YGTK_TREE_VIEW (getView()), _("No entries.")); #if YAST2_VERSION >= 2017005 if (multiSelection) gtk_tree_selection_set_mode (getSelection(), GTK_SELECTION_MULTIPLE); @@ -268,7 +260,7 @@ appendIconTextColumn (header (i), align, col, col+1); if ((align == YAlignCenter || align == YAlignEnd) && i == columns()-1) // if last col is aligned: add another so that it doesn't expand. - appendDumbColumn(); + appendEmptyColumn(); } setModel(); if (!keepSorting()) @@ -308,8 +300,8 @@ if (label == "X") label = YUI::app()->glyph (YUIGlyph_CheckMark); } - setCellIcon (iter, index, icon); - setCellLabel (iter, index+1, label); + setCellIcon (iter, index, icon); + setCellLabel (iter, index+1, label); } void setSortable (bool sortable) @@ -372,17 +364,6 @@ static void hack_right_click_cb (YGtkTreeView *view, gboolean outreach, YGTable *pThis) { -#if YAST2_VERSION > 2018003 - if (pThis->notifyContextMenu()) - return YGTableView::right_click_cb (view, outreach, pThis); -#endif - if (!YGDialog::currentDialog()->getFunctionWidget (5) || - // undetermined case -- more than one table exists - YGDialog::currentDialog()->getClassWidgets ("YTable").size() > 1) { - gtk_widget_error_bell (GTK_WIDGET (view)); - return; - } - struct inner { static void key_activate_cb (GtkMenuItem *item, YWidget *button) { activateButton (button); } @@ -394,18 +375,33 @@ item = gtk_image_menu_item_new_from_stock (stock, NULL); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect (G_OBJECT (item), "activate", - G_CALLBACK (key_activate_cb), button); + G_CALLBACK (key_activate_cb), button); } } }; +#if YAST2_VERSION > 2018003 + if (pThis->notifyContextMenu()) + return YGTableView::right_click_cb (view, outreach, pThis); +#endif GtkWidget *menu = gtk_menu_new(); - if (outreach) - inner::appendItem (menu, GTK_STOCK_ADD, 3); - else { - inner::appendItem (menu, GTK_STOCK_EDIT, 4); - inner::appendItem (menu, GTK_STOCK_DELETE, 5); + + YGDialog *dialog = YGDialog::currentDialog(); + if (dialog->getClassWidgets ("YTable").size() == 1) { + // if more than one table exists, function keys become ambiguous + if (outreach) { + if (dialog->getFunctionWidget(3)) + inner::appendItem (menu, GTK_STOCK_ADD, 3); + } + else { + if (dialog->getFunctionWidget(4)) + inner::appendItem (menu, GTK_STOCK_EDIT, 4); + if (dialog->getFunctionWidget(5)) + inner::appendItem (menu, GTK_STOCK_DELETE, 5); + } } + + menu = ygtk_tree_view_append_show_columns_item (YGTK_TREE_VIEW (view), menu); ygtk_tree_view_popup_menu (view, menu); } @@ -429,9 +425,10 @@ gchar *str_a, *str_b; gtk_tree_model_get (model, a, index, &str_a, -1); gtk_tree_model_get (model, b, index, &str_b, -1); + if (!str_a) str_a = g_strdup (""); + if (!str_b) str_b = g_strdup (""); int ret = strcmp (str_a, str_b); - g_free (str_a); - g_free (str_b); + g_free (str_a); g_free (str_b); return ret; } @@ -464,7 +461,7 @@ connect (getWidget(), "row-activated", G_CALLBACK (activated_cb), (YGTableView *) this); connect (getSelection(), "changed", G_CALLBACK (selection_changed_cb), (YGTableView *) this); #if YAST2_VERSION > 2018003 - connect (getWidget(), "right-click", G_CALLBACK (right_click_cb), this); + connect (getWidget(), "right-click", G_CALLBACK (right_click_cb), (YGTableView *) this); #endif } @@ -500,7 +497,7 @@ // Let the user toggle, using space/enter or double click (not an event). connect (getWidget(), "row-activated", G_CALLBACK (multi_activated_cb), this); #if YAST2_VERSION > 2018003 - connect (getWidget(), "right-click", G_CALLBACK (right_click_cb), this); + connect (getWidget(), "right-click", G_CALLBACK (right_click_cb), (YGTableView *) this); #endif } @@ -574,7 +571,7 @@ connect (getWidget(), "cursor-changed", G_CALLBACK (row_selected_cb), this); connect (getWidget(), "row-activated", G_CALLBACK (activated_cb), (YGTableView *) this); #if YAST2_VERSION > 2018003 - connect (getWidget(), "right-click", G_CALLBACK (right_click_cb), this); + connect (getWidget(), "right-click", G_CALLBACK (right_click_cb), (YGTableView *) this); #endif } Added: branches/SuSE-Code-11-SP1-Branch/gtk/src/ygtktreeview.c URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/gtk/src/ygtktreeview.c?rev=62777&view=auto ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/gtk/src/ygtktreeview.c (added) +++ branches/SuSE-Code-11-SP1-Branch/gtk/src/ygtktreeview.c Tue Nov 9 14:44:55 2010 @@ -0,0 +1,267 @@ +/******************************************************************** + * YaST2-GTK - http://en.opensuse.org/YaST2-GTK * + ********************************************************************/ +/* YGtkTreeView widget */ +// check the header file for information about this widget + +/* + Textdomain "gtk" + */ + +#include <config.h> +#include "ygtktreeview.h" +#include <gtk/gtk.h> +#define YGI18N_C +#include "YGi18n.h" + +static guint right_click_signal = 0; + +G_DEFINE_TYPE (YGtkTreeView, ygtk_tree_view, GTK_TYPE_TREE_VIEW) + +static void ygtk_tree_view_init (YGtkTreeView *view) +{ +} + +static void ygtk_tree_view_finalize (GObject *object) +{ + YGtkTreeView *view = YGTK_TREE_VIEW (object); + if (view->empty_text) { + g_free (view->empty_text); + view->empty_text = NULL; + } + G_OBJECT_CLASS (ygtk_tree_view_parent_class)->finalize (object); +} + +static void _gtk_widget_destroy (gpointer widget) +{ gtk_widget_destroy (GTK_WIDGET (widget)); } + +void ygtk_tree_view_popup_menu (YGtkTreeView *view, GtkWidget *menu) +{ + GtkWidget *widget = GTK_WIDGET (view); + // popup hack -- we can't destroy the menu at hide because it may not have + // emitted signals yet -- destroy it when replaced or the widget destroyed + g_object_set_data_full (G_OBJECT (view), "popup", menu, _gtk_widget_destroy); + + guint32 time = gtk_get_current_event_time(); + gtk_menu_attach_to_widget (GTK_MENU (menu), widget, NULL); + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 3, time); + gtk_widget_show_all (menu); +} + +static gboolean ygtk_tree_view_button_press_event (GtkWidget *widget, GdkEventButton *event) +{ + // workaround (based on gedit): we want the tree view to receive this press in order + // to select the row, but we can't use connect_after, so we throw a dummy mouse press + if (event->type == GDK_BUTTON_PRESS && event->button == 3) { + static gboolean safeguard = FALSE; + if (safeguard) return FALSE; + safeguard = TRUE; + + GtkTreeView *view = GTK_TREE_VIEW (widget); + GtkTreeSelection *selection = gtk_tree_view_get_selection (view); + + gboolean outreach; + outreach = !gtk_tree_view_get_path_at_pos (view, event->x, event->y, 0, 0, 0, 0); + if (gtk_tree_selection_count_selected_rows (selection) <= 1) { + // if there is a selection, let it be + event->button = 1; + if (!gtk_widget_event (widget, (GdkEvent *) event)) + return FALSE; + } + g_signal_emit (widget, right_click_signal, 0, outreach); + safeguard = FALSE; + return TRUE; + } + return GTK_WIDGET_CLASS (ygtk_tree_view_parent_class)->button_press_event (widget, event); +} + +static gboolean _ygtk_tree_view_popup_menu (GtkWidget *widget) +{ + GtkTreeView *view = GTK_TREE_VIEW (widget); + GtkTreeSelection *selection = gtk_tree_view_get_selection (view); + gboolean outreach = gtk_tree_selection_count_selected_rows (selection) == 0; + + g_signal_emit (widget, right_click_signal, 0, outreach); + return TRUE; +} + +static gboolean _ygtk_tree_view_expose_event (GtkWidget *widget, GdkEventExpose *event) +{ + GTK_WIDGET_CLASS (ygtk_tree_view_parent_class)->expose_event (widget, event); + + GtkTreeView *view = GTK_TREE_VIEW (widget); + YGtkTreeView *yview = YGTK_TREE_VIEW (widget); + if (yview->empty_text && event->window == gtk_tree_view_get_bin_window (view)) { + GtkTreeModel *model = gtk_tree_view_get_model (view); + GtkTreeIter iter; + if (!model || !gtk_tree_model_get_iter_first (model, &iter)) { // empty tree-view + const gchar *text = yview->empty_text; + if (!model) + text = _("Loading..."); + cairo_t *cr = gdk_cairo_create (event->window); + PangoLayout *layout; + layout = gtk_widget_create_pango_layout (widget, text); + + PangoAttrList *attrs = pango_attr_list_new(); + pango_attr_list_insert (attrs, pango_attr_foreground_new (160<<8, 160<<8, 160<<8)); + pango_layout_set_attributes (layout, attrs); + pango_attr_list_unref (attrs); + + int width, height; + pango_layout_get_pixel_size (layout, &width, &height); + int x, y; + x = (widget->allocation.width - width) / 2; + y = (widget->allocation.height - height) / 2; + cairo_move_to (cr, x, y); + + pango_cairo_show_layout (cr, layout); + g_object_unref (layout); + cairo_destroy (cr); + } + } + return FALSE; +} + +static void show_column_cb (GtkCheckMenuItem *item, GtkTreeView *view) +{ + int col = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "column")); + GtkTreeViewColumn *column = gtk_tree_view_get_column (view, col); + gboolean visible = gtk_check_menu_item_get_active (item); + gtk_tree_view_column_set_visible (column, visible); +} + +GtkWidget *ygtk_tree_view_create_show_columns_menu (YGtkTreeView *view) +{ + GtkWidget *menu = gtk_menu_new(); + GList *columns = gtk_tree_view_get_columns (GTK_TREE_VIEW (view)); + // see ygtk_tree_view_append_column(): we re-order arabic column insertion + gboolean reverse = gtk_widget_get_default_direction() == GTK_TEXT_DIR_RTL && + gtk_widget_get_direction (GTK_WIDGET (view)) != GTK_TEXT_DIR_RTL; + int n; + GList *i; + for (n = 0, i = columns; i; i = i->next, n++) { + GtkTreeViewColumn *column = (GtkTreeViewColumn *) i->data; + const gchar *header = gtk_tree_view_column_get_title (column); + if (header) { + GtkWidget *item = gtk_check_menu_item_new_with_label (header); + g_object_set_data (G_OBJECT (item), "column", GINT_TO_POINTER (n)); + + gboolean visible = gtk_tree_view_column_get_visible (column); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), visible); + g_signal_connect (G_OBJECT (item), "toggled", + G_CALLBACK (show_column_cb), view); + + if (reverse) + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); + else + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + + // if the user were to remove all columns, the right-click would no longer work + if (n == 0 && !reverse) + gtk_widget_set_sensitive (item, FALSE); + } + } + g_list_free (columns); + return menu; +} + +GtkWidget *ygtk_tree_view_append_show_columns_item (YGtkTreeView *view, GtkWidget *menu) +{ + if (!menu) + menu = gtk_menu_new(); + + GList *children = gtk_container_get_children (GTK_CONTAINER (menu)); + g_list_free (children); + if (children) // non-null if it has children (in which case, add separator) + gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new()); + + GtkWidget *submenu = ygtk_tree_view_create_show_columns_menu (view); + GtkWidget *item = gtk_menu_item_new_with_mnemonic (_("_Show column")); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu); + return menu; +} + +void ygtk_tree_view_append_column (YGtkTreeView *view, GtkTreeViewColumn *column) +{ + int pos = -1; + if (gtk_widget_get_default_direction() == GTK_TEXT_DIR_RTL) { + gtk_widget_set_direction (GTK_WIDGET (view), GTK_TEXT_DIR_LTR); + + GList *renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column)), *i; + for (i = renderers; i; i = i->next) { + GtkCellRenderer *renderer = (GtkCellRenderer *) i->data; + if (GTK_IS_CELL_RENDERER_TEXT (renderer)) { + PangoAlignment alignment; + g_object_get (G_OBJECT (renderer), "alignment", &alignment, NULL); + if (alignment == PANGO_ALIGN_LEFT) + alignment = PANGO_ALIGN_RIGHT; + else if (alignment == PANGO_ALIGN_RIGHT) + alignment = PANGO_ALIGN_LEFT; + g_object_set (G_OBJECT (renderer), "alignment", alignment, NULL); + + gfloat xalign; + g_object_get (G_OBJECT (renderer), "xalign", &xalign, NULL); + xalign = 1.0 - xalign; + g_object_set (G_OBJECT (renderer), "xalign", xalign, NULL); + + PangoEllipsizeMode ellipsize; + g_object_get (G_OBJECT (renderer), "ellipsize", &ellipsize, NULL); + if (ellipsize == PANGO_ELLIPSIZE_END) + ellipsize = PANGO_ELLIPSIZE_START; + else if (ellipsize == PANGO_ELLIPSIZE_START) + ellipsize = PANGO_ELLIPSIZE_END; + g_object_set (G_OBJECT (renderer), "ellipsize", ellipsize, NULL); + } + } + g_list_free (renderers); + pos = 0; + } + gtk_tree_view_insert_column (GTK_TREE_VIEW (view), column, pos); +} + +GtkTreeViewColumn *ygtk_tree_view_get_column (YGtkTreeView *view, gint nb) +{ + GtkTreeViewColumn *column; + if (gtk_widget_get_default_direction() == GTK_TEXT_DIR_RTL) { + GList *columns = gtk_tree_view_get_columns (GTK_TREE_VIEW (view)); + nb = g_list_length (columns) - nb - 1; + column = g_list_nth_data (columns, nb); + g_list_free (columns); + } + else + column = gtk_tree_view_get_column (GTK_TREE_VIEW (view), nb); + return column; +} + + +void ygtk_tree_view_set_empty_text (YGtkTreeView *view, const gchar *empty_text) +{ + if (view->empty_text) + g_free (view->empty_text); + view->empty_text = empty_text ? g_strdup (empty_text) : NULL; +} + +GtkWidget *ygtk_tree_view_new (const gchar *empty_text) +{ + YGtkTreeView *view = (YGtkTreeView *) g_object_new (YGTK_TYPE_TREE_VIEW, NULL); + view->empty_text = empty_text ? g_strdup (empty_text) : NULL; + return GTK_WIDGET (view); +} + +static void ygtk_tree_view_class_init (YGtkTreeViewClass *klass) +{ + GtkWidgetClass *gtkwidget_class = GTK_WIDGET_CLASS (klass); + gtkwidget_class->button_press_event = ygtk_tree_view_button_press_event; + gtkwidget_class->popup_menu = _ygtk_tree_view_popup_menu; + gtkwidget_class->expose_event = _ygtk_tree_view_expose_event; + + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + gobject_class->finalize = ygtk_tree_view_finalize; + + right_click_signal = g_signal_new ("right-click", + G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (YGtkTreeViewClass, right_click), + NULL, NULL, gtk_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN); +} + Added: branches/SuSE-Code-11-SP1-Branch/gtk/src/ygtktreeview.h URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/gtk/src/ygtktreeview.h?rev=62777&view=auto ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/gtk/src/ygtktreeview.h (added) +++ branches/SuSE-Code-11-SP1-Branch/gtk/src/ygtktreeview.h Tue Nov 9 14:44:55 2010 @@ -0,0 +1,62 @@ +/******************************************************************** + * YaST2-GTK - http://en.opensuse.org/YaST2-GTK * + ********************************************************************/ + +/* YGtkTreeView hacks support for a right-click signal. +*/ + +#ifndef YGTK_TREE_VIEW_H +#define YGTK_TREE_VIEW_H + +#include <gtk/gtktreeview.h> +G_BEGIN_DECLS + +#define YGTK_TYPE_TREE_VIEW (ygtk_tree_view_get_type ()) +#define YGTK_TREE_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + YGTK_TYPE_TREE_VIEW, YGtkTreeView)) +#define YGTK_TREE_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), \ + YGTK_TYPE_TREE_VIEW, YGtkTreeViewClass)) +#define YGTK_IS_TREE_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + YGTK_TYPE_TREE_VIEW)) +#define YGTK_IS_TREE_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), \ + YGTK_TYPE_TREE_VIEW)) +#define YGTK_TREE_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + YGTK_TYPE_TREE_VIEW, YGtkTreeViewClass)) + +typedef struct _YGtkTreeView +{ + GtkTreeView parent; + + // members: + gchar *empty_text; +} YGtkTreeView; + +typedef struct _YGtkTreeViewClass +{ + GtkTreeViewClass parent_class; + + // signals: + void (*right_click) (YGtkTreeView *view, gboolean outreach); +} YGtkTreeViewClass; + +GtkWidget* ygtk_tree_view_new (const gchar *empty_text); /* null to disable */ +GType ygtk_tree_view_get_type (void) G_GNUC_CONST; + +void ygtk_tree_view_set_empty_text (YGtkTreeView *view, const gchar *empty_text); + +void ygtk_tree_view_popup_menu (YGtkTreeView *view, GtkWidget *menu); + +GtkWidget *ygtk_tree_view_create_show_columns_menu (YGtkTreeView *view); +GtkWidget *ygtk_tree_view_append_show_columns_item (YGtkTreeView *view, GtkWidget *menu); + +// use this method of adding columns to overload gtk Arabic tree-view layout by +// a more sane and simpler one. +// (if you do, use it for all your column adding needs.) +void ygtk_tree_view_append_column (YGtkTreeView *view, GtkTreeViewColumn *column); + +// use this if you have used our ygtk_tree_view_append_column() +GtkTreeViewColumn *ygtk_tree_view_get_column (YGtkTreeView *view, gint nb); + +G_END_DECLS +#endif /*YGTK_TREE_VIEW_H*/ + -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
rpmcruz@svn2.opensuse.org