Put all of the UI utility functions into the "git" namespace.
[anjuta-git-plugin.git] / plugins / debug-manager / chunk_view.c
bloba57b5997675da62c5712261d9b29964165d4a6b1
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 chunk_view.c
4 Copyright (C) 2006 Sebastien Granjoux
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 * It is a GtkTextView with an associated GtkAjustment, allowing to put in the
23 * GtkTextView only a part of a big amount of text. Cursor movements are not
24 * limited by the GtkTextView content but by the GtkAjustment.
25 *---------------------------------------------------------------------------*/
27 #include "chunk_view.h"
29 struct _DmaChunkView
31 GtkTextView parent;
33 GtkAdjustment *vadjustment;
36 struct _DmaChunkViewClass
38 GtkTextViewClass parent_class;
41 /* Used in dispose and finalize */
42 static GtkWidgetClass *parent_class = NULL;
44 /* Helper functions
45 *---------------------------------------------------------------------------*/
47 static void
48 set_adjustment_clamped (GtkAdjustment *adj, gdouble value)
50 if (value < adj->lower)
52 value = adj->lower;
54 if (value > (adj->upper - adj->page_size))
56 value = adj->upper - adj->page_size;
58 gtk_adjustment_set_value (adj, value);
61 /* Private functions
62 *---------------------------------------------------------------------------*/
64 static void
65 dma_chunk_view_move_cursor (GtkTextView *text_view,
66 GtkMovementStep step,
67 gint count,
68 gboolean extend_selection)
70 DmaChunkView *view = DMA_CHUNK_VIEW (text_view);
71 gdouble value = view->vadjustment->value;
72 GtkTextMark *mark;
73 GtkTextBuffer *buffer;
74 GtkTextIter cur;
75 gint line;
77 switch (step)
79 case GTK_MOVEMENT_LOGICAL_POSITIONS:
80 case GTK_MOVEMENT_VISUAL_POSITIONS:
81 case GTK_MOVEMENT_WORDS:
82 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
83 case GTK_MOVEMENT_HORIZONTAL_PAGES:
84 break;
85 case GTK_MOVEMENT_DISPLAY_LINES:
86 case GTK_MOVEMENT_PARAGRAPHS:
87 case GTK_MOVEMENT_PARAGRAPH_ENDS:
88 buffer = gtk_text_view_get_buffer (text_view);
89 mark = gtk_text_buffer_get_insert (buffer);
90 gtk_text_buffer_get_iter_at_mark (buffer, &cur, mark);
91 line = gtk_text_iter_get_line (&cur);
93 if ((count < 0) && (line == 0))
95 value += count * view->vadjustment->step_increment;
96 set_adjustment_clamped (view->vadjustment, value);
97 return;
99 else if ((count > 0) && (line == gtk_text_buffer_get_line_count(buffer) - 1))
101 value += count * view->vadjustment->step_increment;
102 set_adjustment_clamped (view->vadjustment, value);
103 return;
105 break;
106 case GTK_MOVEMENT_PAGES:
107 value += count * view->vadjustment->page_increment;
108 set_adjustment_clamped (view->vadjustment, value);
109 return;
110 case GTK_MOVEMENT_BUFFER_ENDS:
111 set_adjustment_clamped (view->vadjustment, count < 0 ? view->vadjustment->lower : view->vadjustment->upper);
112 return;
113 default:
114 break;
117 GTK_TEXT_VIEW_CLASS (parent_class)->move_cursor (text_view,
118 step, count,
119 extend_selection);
122 /* Public functions
123 *---------------------------------------------------------------------------*/
125 void dma_chunk_view_set_scroll_adjustment (DmaChunkView *this, GtkAdjustment* vadjustment)
127 this->vadjustment = vadjustment;
130 /* GObject functions
131 *---------------------------------------------------------------------------*/
133 /* dispose is the first destruction step. It is used to unref object created
134 * with instance_init in order to break reference counting cycles. This
135 * function could be called several times. All function should still work
136 * after this call. It has to called its parents.*/
138 static void
139 dma_chunk_view_dispose (GObject *object)
141 /*DmaChunkView *this = DMA_CHUNK_VIEW (obj);*/
143 G_OBJECT_CLASS (parent_class)->dispose (object);
146 /* finalize is the last destruction step. It must free all memory allocated
147 * with instance_init. It is called only one time just before releasing all
148 * memory */
150 static void
151 dma_chunk_view_finalize (GObject *object)
153 /*DmaChunkView *view = DMA_CHUNK_VIEW (object);*/
155 G_OBJECT_CLASS (parent_class)->finalize (object);
158 /* instance_init is the constructor. All functions should work after this
159 * call. */
161 static void
162 dma_chunk_view_instance_init (DmaChunkView *view)
164 // GtkAdjustment *adj;
165 // GtkWidget* wid;
166 // PangoFontDescription *font_desc;
170 /* class_init intialize the class itself not the instance */
172 static void
173 dma_chunk_view_class_init (DmaChunkViewClass * klass)
175 GObjectClass *gobject_class;
176 GtkObjectClass *object_class;
177 GtkWidgetClass *widget_class;
178 GtkTextViewClass *text_view_class;
180 g_return_if_fail (klass != NULL);
182 gobject_class = G_OBJECT_CLASS (klass);
183 object_class = GTK_OBJECT_CLASS (klass);
184 widget_class = GTK_WIDGET_CLASS (klass);
185 text_view_class = GTK_TEXT_VIEW_CLASS (klass);
186 parent_class = GTK_WIDGET_CLASS (g_type_class_peek_parent (klass));
188 gobject_class->dispose = dma_chunk_view_dispose;
189 gobject_class->finalize = dma_chunk_view_finalize;
191 text_view_class->move_cursor = dma_chunk_view_move_cursor;
194 GType
195 dma_chunk_view_get_type (void)
197 static GType type = 0;
199 if (!type)
201 static const GTypeInfo type_info =
203 sizeof (DmaChunkViewClass),
204 (GBaseInitFunc) NULL,
205 (GBaseFinalizeFunc) NULL,
206 (GClassInitFunc) dma_chunk_view_class_init,
207 (GClassFinalizeFunc) NULL,
208 NULL, /* class_data */
209 sizeof (DmaChunkView),
210 0, /* n_preallocs */
211 (GInstanceInitFunc) dma_chunk_view_instance_init,
212 NULL /* value_table */
215 type = g_type_register_static (GTK_TYPE_TEXT_VIEW,
216 "DmaChunkView", &type_info, 0);
219 return type;
222 /* Creation and Destruction
223 *---------------------------------------------------------------------------*/
225 GtkWidget*
226 dma_chunk_view_new (void)
228 GtkWidget *this;
230 this = g_object_new (DMA_CHUNK_VIEW_TYPE, NULL);
231 g_assert (this != NULL);
233 return this;
236 void
237 dma_chunk_view_free (DmaChunkView *this)
239 g_object_unref (this);