From d7ff4b1d3191a0b45baaf6e36d47fd9204269ac9 Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Mon, 24 Apr 2006 14:04:47 -0500 Subject: [PATCH] Use one placeholder tag per view --- moo/mooedit/mooeditinput.c | 46 ----------------- moo/mooedit/mooplaceholder.c | 37 +------------- moo/mooedit/mooplaceholder.h | 2 - moo/mooedit/mootextview-private.h | 26 +--------- moo/mooedit/mootextview.c | 82 +++++++++++++++++++++++++------ 5 files changed, 68 insertions(+), 125 deletions(-) diff --git a/moo/mooedit/mooeditinput.c b/moo/mooedit/mooeditinput.c index cb686d46..79d5e380 100644 --- a/moo/mooedit/mooeditinput.c +++ b/moo/mooedit/mooeditinput.c @@ -1339,49 +1339,3 @@ handle_ctrl_pgup (MooTextView *view, return TRUE; } - - -/***********************************************************************/ -/* Drag'n'drop -/*/ - -void -_moo_text_view_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - int x, - int y, - GtkSelectionData *data, - guint info, - guint time) -{ -} - - -gboolean -_moo_text_view_drag_drop (GtkWidget *widget, - GdkDragContext *context, - int x, - int y, - guint time) -{ - return FALSE; -} - - -void -_moo_text_view_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time) -{ -} - - -gboolean -_moo_text_view_drag_motion (GtkWidget *widget, - GdkDragContext *context, - int x, - int y, - guint time) -{ - return FALSE; -} diff --git a/moo/mooedit/mooplaceholder.c b/moo/mooedit/mooplaceholder.c index 4a6f7a92..8d5cd2d5 100644 --- a/moo/mooedit/mooplaceholder.c +++ b/moo/mooedit/mooplaceholder.c @@ -50,7 +50,7 @@ moo_placeholder_update_size (GtkWidget *ph) PangoLayout *layout; PangoLayoutLine *line; PangoRectangle rect; - int height, rise; + int height; ctx = gtk_widget_get_pango_context (parent); g_return_if_fail (ctx != NULL); @@ -62,14 +62,10 @@ moo_placeholder_update_size (GtkWidget *ph) pango_layout_line_get_extents (line, NULL, &rect); height = rect.height / PANGO_SCALE; - rise = rect.y + rect.height; gtk_widget_set_size_request (ph, -1, height); gtk_widget_modify_font (ph, parent->style->font_desc); - if (MOO_PLACEHOLDER(ph)->tag) - g_object_set (MOO_PLACEHOLDER(ph)->tag, "rise", -rise, NULL); - g_object_unref (layout); } } @@ -101,28 +97,9 @@ moo_placeholder_parent_set (GtkWidget *widget, } -static void -moo_placeholder_destroy (GtkObject *object) -{ - MooPlaceholder *ph = MOO_PLACEHOLDER (object); - - if (ph->tag) - { - gtk_text_tag_table_remove (ph->table, ph->tag); - g_object_unref (ph->tag); - g_object_unref (ph->table); - ph->tag = NULL; - ph->table = NULL; - } - - GTK_OBJECT_CLASS(_moo_placeholder_parent_class)->destroy (object); -} - - static void _moo_placeholder_class_init (MooPlaceholderClass *klass) { - GTK_OBJECT_CLASS(klass)->destroy = moo_placeholder_destroy; GTK_WIDGET_CLASS(klass)->parent_set = moo_placeholder_parent_set; } @@ -132,15 +109,3 @@ _moo_placeholder_init (MooPlaceholder *ph) { gtk_label_set_text (GTK_LABEL (ph), " "); } - - -void -_moo_placeholder_set_tag (MooPlaceholder *ph, - GtkTextTagTable *table, - GtkTextTag *tag) -{ - g_return_if_fail (ph->tag == NULL); - ph->tag = g_object_ref (tag); - ph->table = g_object_ref (table); - moo_placeholder_update_size (GTK_WIDGET (ph)); -} diff --git a/moo/mooedit/mooplaceholder.h b/moo/mooedit/mooplaceholder.h index d9b894f7..7e8a1caf 100644 --- a/moo/mooedit/mooplaceholder.h +++ b/moo/mooedit/mooplaceholder.h @@ -49,8 +49,6 @@ typedef struct _MooTextAnchorClass MooTextAnchorClass; struct _MooPlaceholder { GtkLabel parent; - GtkTextTagTable *table; - GtkTextTag *tag; }; struct _MooPlaceholderClass diff --git a/moo/mooedit/mootextview-private.h b/moo/mooedit/mootextview-private.h index cb607c6d..afba4207 100644 --- a/moo/mooedit/mootextview-private.h +++ b/moo/mooedit/mootextview-private.h @@ -27,31 +27,6 @@ G_BEGIN_DECLS -/***********************************************************************/ -/* Drag'n'drop -/*/ -void _moo_text_view_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - int x, - int y, - GtkSelectionData *data, - guint info, - guint time); -gboolean _moo_text_view_drag_drop (GtkWidget *widget, - GdkDragContext *context, - int x, - int y, - guint time); -void _moo_text_view_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time); -gboolean _moo_text_view_drag_motion (GtkWidget *widget, - GdkDragContext *context, - int x, - int y, - guint time); - - /***********************************************************************/ /* GtkTextView stuff /*/ @@ -191,6 +166,7 @@ struct _MooTextViewPrivate { /* Children /*/ GtkWidget *children[4]; + GSList *placeholders; /***********************************************************************/ /* Search diff --git a/moo/mooedit/mootextview.c b/moo/mooedit/mootextview.c index 3030af78..3ddfc709 100644 --- a/moo/mooedit/mootextview.c +++ b/moo/mooedit/mootextview.c @@ -1,5 +1,4 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4; coding: utf-8 -*- - * +/* * mootextview.c * * Copyright (C) 2004-2006 by Yevgen Muntyan @@ -158,6 +157,7 @@ static void fold_toggled (MooTextView *view, MooFold *fold); static gboolean has_placeholders (MooTextView *view); +static void update_placeholder_tag (MooTextView *view); enum { @@ -240,12 +240,6 @@ static void moo_text_view_class_init (MooTextViewClass *klass) widget_class->style_set = moo_text_view_style_set; widget_class->size_request = moo_text_view_size_request; widget_class->size_allocate = moo_text_view_size_allocate; -#if 0 - widget_class->drag_data_received = _moo_text_view_drag_data_received; - widget_class->drag_drop = _moo_text_view_drag_drop; - widget_class->drag_leave = _moo_text_view_drag_leave; - widget_class->drag_motion = _moo_text_view_drag_motion; -#endif container_class->remove = moo_text_view_remove; @@ -1718,6 +1712,8 @@ moo_text_view_realize (GtkWidget *widget) if (view->priv->children[i] && GTK_WIDGET_VISIBLE (view->priv->children[i])) lower_border_window (GTK_TEXT_VIEW (view), i); } + + update_placeholder_tag (view); } @@ -2809,6 +2805,8 @@ moo_text_view_style_set (GtkWidget *widget, NULL); view->priv->expander_size += EXPANDER_PADDING; + update_placeholder_tag (view); + GTK_WIDGET_CLASS(moo_text_view_parent_class)->style_set (widget, prev_style); } @@ -3654,6 +3652,10 @@ moo_text_view_remove (GtkContainer *container, guint i; MooTextView *view = MOO_TEXT_VIEW (container); + if (MOO_IS_PLACEHOLDER (widget)) + view->priv->placeholders = + g_slist_remove (view->priv->placeholders, widget); + if (widget == view->priv->qs.evbox) { view->priv->qs.in_search = FALSE; @@ -4029,6 +4031,56 @@ start_quick_search (MooTextView *view) /* Placeholders */ +static void +update_placeholder_tag (MooTextView *view) +{ + GtkTextTag *tag = moo_text_view_lookup_tag (view, "moo-placeholder"); + + if (tag && GTK_WIDGET_REALIZED (view)) + { + PangoContext *ctx; + PangoLayout *layout; + PangoLayoutLine *line; + PangoRectangle rect; + int rise; + + ctx = gtk_widget_get_pango_context (GTK_WIDGET (view)); + g_return_if_fail (ctx != NULL); + + layout = pango_layout_new (ctx); + pango_layout_set_text (layout, "AA", -1); + line = pango_layout_get_line (layout, 0); + + pango_layout_line_get_extents (line, NULL, &rect); + + rise = rect.y + rect.height; + + if (tag) + g_object_set (tag, "rise", -rise, NULL); + + g_object_unref (layout); + } +} + + +static GtkTextTag * +create_placeholder_tag (MooTextView *view) +{ + GtkTextTag *tag; + + tag = moo_text_view_lookup_tag (view, "moo-placeholder"); + + if (!tag) + { + GtkTextBuffer *buffer = get_buffer (view); + tag = gtk_text_buffer_create_tag (buffer, "moo-placeholder", NULL); + update_placeholder_tag (view); + } + + return tag; +} + + void moo_text_view_insert_placeholder (MooTextView *view, GtkTextIter *iter) @@ -4037,7 +4089,6 @@ moo_text_view_insert_placeholder (MooTextView *view, GtkTextChildAnchor *anchor; GtkWidget *ph; GtkTextTag *tag; - GtkTextTagTable *table; GtkTextIter start; g_return_if_fail (MOO_IS_TEXT_VIEW (view)); @@ -4050,16 +4101,15 @@ moo_text_view_insert_placeholder (MooTextView *view, buffer = get_buffer (view); gtk_text_buffer_insert_child_anchor (buffer, iter, anchor); - gtk_widget_show (ph); - gtk_text_view_add_child_at_anchor (GTK_TEXT_VIEW (view), ph, anchor); - - table = gtk_text_buffer_get_tag_table (buffer); - tag = gtk_text_buffer_create_tag (buffer, NULL, NULL); - _moo_placeholder_set_tag (MOO_PLACEHOLDER (ph), table, tag); + tag = create_placeholder_tag (view); start = *iter; gtk_text_iter_backward_char (&start); gtk_text_buffer_apply_tag (buffer, tag, &start, iter); + gtk_widget_show (ph); + gtk_text_view_add_child_at_anchor (GTK_TEXT_VIEW (view), ph, anchor); + view->priv->placeholders = g_slist_prepend (view->priv->placeholders, ph); + g_object_unref (anchor); } @@ -4067,7 +4117,7 @@ moo_text_view_insert_placeholder (MooTextView *view, static gboolean has_placeholders (MooTextView *view) { - return TRUE; + return view->priv->placeholders != NULL; }