Author: rpmcruz Date: Wed Dec 10 01:21:16 2008 New Revision: 54014 URL: http://svn.opensuse.org/viewcvs/yast?rev=54014&view=rev Log: Ups, forgot to add the stars. Added: trunk/gtk/src/ygtktextview.c trunk/gtk/src/ygtktextview.h Added: trunk/gtk/src/ygtktextview.c URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/ygtktextview.c?rev=54014&view=auto ============================================================================== --- trunk/gtk/src/ygtktextview.c (added) +++ trunk/gtk/src/ygtktextview.c Wed Dec 10 01:21:16 2008 @@ -0,0 +1,79 @@ +/******************************************************************** + * YaST2-GTK - http://en.opensuse.org/YaST2-GTK * + ********************************************************************/ + +/* YGtkTextView widget */ +// check the header file for information about this widget + +#include <config.h> +#include "ygtktextview.h" +#include <gtk/gtk.h> + +G_DEFINE_TYPE (YGtkTextView, ygtk_text_view, GTK_TYPE_TEXT_VIEW) + +static void ygtk_text_view_init (YGtkTextView *view) +{ +} + +static void ygtk_text_view_realize (GtkWidget *widget) +{ + GTK_WIDGET_CLASS (ygtk_text_view_parent_class)->realize (widget); + + GtkTextView *view = GTK_TEXT_VIEW (widget); + if (!gtk_text_view_get_editable (view)) { + gtk_text_view_set_cursor_visible (view, FALSE); + GdkWindow *window = gtk_text_view_get_window (view, GTK_TEXT_WINDOW_TEXT); + gdk_window_set_cursor (window, NULL); + } +} + +// popup utilities +static void copy_activate_cb (GtkMenuItem *item, GtkTextBuffer *buffer) +{ + gtk_text_buffer_copy_clipboard (buffer, gtk_clipboard_get (GDK_SELECTION_CLIPBOARD)); +} +static void select_all_activate_cb (GtkMenuItem *item, GtkTextBuffer *buffer) +{ + GtkTextIter start, end; + gtk_text_buffer_get_bounds (buffer, &start, &end); + gtk_text_buffer_select_range (buffer, &start, &end); +} + +static void ygtk_text_view_populate_popup (GtkTextView *view, GtkMenu *menu) +{ + if (gtk_text_view_get_editable (view)) + return; + GtkTextBuffer *buffer = gtk_text_view_get_buffer (view); + + GList *items = gtk_container_get_children (GTK_CONTAINER (menu)), *i; + for (i = items; i; i = i->next) + gtk_container_remove (GTK_CONTAINER (menu), i->data); + g_list_free (items); + + GtkWidget *item; + item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + if (gtk_text_buffer_get_has_selection (buffer)) + g_signal_connect (item, "activate", G_CALLBACK (copy_activate_cb), buffer); + else + gtk_widget_set_sensitive (item, FALSE); + item = gtk_separator_menu_item_new(); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + g_signal_connect (item, "activate", G_CALLBACK (select_all_activate_cb), buffer); + gtk_widget_show_all (GTK_WIDGET (menu)); +} + +GtkWidget *ygtk_text_view_new (gboolean editable) +{ return g_object_new (YGTK_TYPE_TEXT_VIEW, "editable", editable, NULL); } + +static void ygtk_text_view_class_init (YGtkTextViewClass *klass) +{ + GtkTextViewClass *gtktextview_class = GTK_TEXT_VIEW_CLASS (klass); + gtktextview_class->populate_popup = ygtk_text_view_populate_popup; + + GtkWidgetClass *gtkwidget_class = GTK_WIDGET_CLASS (klass); + gtkwidget_class->realize = ygtk_text_view_realize; +} + Added: trunk/gtk/src/ygtktextview.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/ygtktextview.h?rev=54014&view=auto ============================================================================== --- trunk/gtk/src/ygtktextview.h (added) +++ trunk/gtk/src/ygtktextview.h Wed Dec 10 01:21:16 2008 @@ -0,0 +1,42 @@ +/******************************************************************** + * YaST2-GTK - http://en.opensuse.org/YaST2-GTK * + ********************************************************************/ + +/* YGtkTextView polishes GtkTextView a little bit, especially on + read-only mode. +*/ + +#ifndef YGTK_TEXT_VIEW_H +#define YGTK_TEXT_VIEW_H + +#include <gtk/gtktextview.h> +G_BEGIN_DECLS + +#define YGTK_TYPE_TEXT_VIEW (ygtk_text_view_get_type ()) +#define YGTK_TEXT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + YGTK_TYPE_TEXT_VIEW, YGtkTextView)) +#define YGTK_TEXT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), \ + YGTK_TYPE_TEXT_VIEW, YGtkTextViewClass)) +#define YGTK_IS_TEXT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + YGTK_TYPE_TEXT_VIEW)) +#define YGTK_IS_TEXT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), \ + YGTK_TYPE_TEXT_VIEW)) +#define YGTK_TEXT_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + YGTK_TYPE_TEXT_VIEW, YGtkTextViewClass)) + +typedef struct _YGtkTextView +{ + GtkTextView parent; +} YGtkTextView; + +typedef struct _YGtkTextViewClass +{ + GtkTextViewClass parent_class; +} YGtkTextViewClass; + +GtkWidget* ygtk_text_view_new (gboolean editable); +GType ygtk_text_view_get_type (void) G_GNUC_CONST; + +G_END_DECLS +#endif /*YGTK_SCROLLED_WINDOW_H*/ + -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org