2006-11-14 Günther Brammer <GBrammer@gmx.de>
[anjuta-git-plugin.git] / plugins / debug-manager / chunk_view.c
blob7c7491f14a752f1bab732c86b0ab498eac475c7d
1 /*
2 chunk_view.c
3 Copyright (C) 2006 Sebastien Granjoux
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "chunk_view.h"
22 #include "data_buffer.h"
24 struct _DmaChunkView
26 GtkTextView parent;
28 GtkAdjustment *vadjustment;
31 struct _DmaChunkViewClass
33 GtkTextViewClass parent_class;
36 /* Used in dispose and finalize */
37 static GtkWidgetClass *parent_class = NULL;
39 /* Helper functions
40 *---------------------------------------------------------------------------*/
42 static void
43 set_adjustment_clamped (GtkAdjustment *adj, gdouble value)
45 if (value < adj->lower)
47 value = adj->lower;
49 if (value > (adj->upper - adj->page_size))
51 value = adj->upper - adj->page_size;
53 gtk_adjustment_set_value (adj, value);
56 /* Private functions
57 *---------------------------------------------------------------------------*/
59 static void
60 dma_chunk_view_move_cursor (GtkTextView *text_view,
61 GtkMovementStep step,
62 gint count,
63 gboolean extend_selection)
65 DmaChunkView *view = DMA_CHUNK_VIEW (text_view);
66 gdouble value = view->vadjustment->value;
67 GtkTextMark *mark;
68 GtkTextBuffer *buffer;
69 GtkTextIter cur;
70 gint line;
72 switch (step)
74 case GTK_MOVEMENT_LOGICAL_POSITIONS:
75 case GTK_MOVEMENT_VISUAL_POSITIONS:
76 case GTK_MOVEMENT_WORDS:
77 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
78 case GTK_MOVEMENT_HORIZONTAL_PAGES:
79 break;
80 case GTK_MOVEMENT_DISPLAY_LINES:
81 case GTK_MOVEMENT_PARAGRAPHS:
82 case GTK_MOVEMENT_PARAGRAPH_ENDS:
83 buffer = gtk_text_view_get_buffer (text_view);
84 mark = gtk_text_buffer_get_insert (buffer);
85 gtk_text_buffer_get_iter_at_mark (buffer, &cur, mark);
86 line = gtk_text_iter_get_line (&cur);
88 if ((count < 0) && (line == 0))
90 value += count * view->vadjustment->step_increment;
91 set_adjustment_clamped (view->vadjustment, value);
92 return;
94 else if ((count > 0) && (line == gtk_text_buffer_get_line_count(buffer) - 1))
96 value += count * view->vadjustment->step_increment;
97 set_adjustment_clamped (view->vadjustment, value);
98 return;
100 break;
101 case GTK_MOVEMENT_PAGES:
102 value += count * view->vadjustment->page_increment;
103 set_adjustment_clamped (view->vadjustment, value);
104 return;
105 case GTK_MOVEMENT_BUFFER_ENDS:
106 set_adjustment_clamped (view->vadjustment, count < 0 ? view->vadjustment->lower : view->vadjustment->upper);
107 return;
108 default:
109 break;
112 GTK_TEXT_VIEW_CLASS (parent_class)->move_cursor (text_view,
113 step, count,
114 extend_selection);
117 /* Public functions
118 *---------------------------------------------------------------------------*/
120 void dma_chunk_view_set_scroll_adjustment (DmaChunkView *this, GtkAdjustment* vadjustment)
122 this->vadjustment = vadjustment;
125 /* GObject functions
126 *---------------------------------------------------------------------------*/
128 /* dispose is the first destruction step. It is used to unref object created
129 * with instance_init in order to break reference counting cycles. This
130 * function could be called several times. All function should still work
131 * after this call. It has to called its parents.*/
133 static void
134 dma_chunk_view_dispose (GObject *object)
136 /*DmaChunkView *this = DMA_CHUNK_VIEW (obj);*/
138 G_OBJECT_CLASS (parent_class)->dispose (object);
141 /* finalize is the last destruction step. It must free all memory allocated
142 * with instance_init. It is called only one time just before releasing all
143 * memory */
145 static void
146 dma_chunk_view_finalize (GObject *object)
148 /*DmaChunkView *view = DMA_CHUNK_VIEW (object);*/
150 G_OBJECT_CLASS (parent_class)->finalize (object);
153 /* instance_init is the constructor. All functions should work after this
154 * call. */
156 static void
157 dma_chunk_view_instance_init (DmaChunkView *view)
159 // GtkAdjustment *adj;
160 // GtkWidget* wid;
161 // PangoFontDescription *font_desc;
165 /* class_init intialize the class itself not the instance */
167 static void
168 dma_chunk_view_class_init (DmaChunkViewClass * klass)
170 GObjectClass *gobject_class;
171 GtkObjectClass *object_class;
172 GtkWidgetClass *widget_class;
173 GtkTextViewClass *text_view_class;
175 g_return_if_fail (klass != NULL);
177 gobject_class = G_OBJECT_CLASS (klass);
178 object_class = GTK_OBJECT_CLASS (klass);
179 widget_class = GTK_WIDGET_CLASS (klass);
180 text_view_class = GTK_TEXT_VIEW_CLASS (klass);
181 parent_class = GTK_WIDGET_CLASS (g_type_class_peek_parent (klass));
183 gobject_class->dispose = dma_chunk_view_dispose;
184 gobject_class->finalize = dma_chunk_view_finalize;
186 text_view_class->move_cursor = dma_chunk_view_move_cursor;
189 GType
190 dma_chunk_view_get_type (void)
192 static GType type = 0;
194 if (!type)
196 static const GTypeInfo type_info =
198 sizeof (DmaChunkViewClass),
199 (GBaseInitFunc) NULL,
200 (GBaseFinalizeFunc) NULL,
201 (GClassInitFunc) dma_chunk_view_class_init,
202 (GClassFinalizeFunc) NULL,
203 NULL, /* class_data */
204 sizeof (DmaChunkView),
205 0, /* n_preallocs */
206 (GInstanceInitFunc) dma_chunk_view_instance_init,
207 NULL /* value_table */
210 type = g_type_register_static (GTK_TYPE_TEXT_VIEW,
211 "DmaChunkView", &type_info, 0);
214 return type;
217 /* Creation and Destruction
218 *---------------------------------------------------------------------------*/
220 GtkWidget*
221 dma_chunk_view_new (void)
223 GtkWidget *this;
225 this = g_object_new (DMA_CHUNK_VIEW_TYPE, NULL);
226 g_assert (this != NULL);
228 return this;
231 void
232 dma_chunk_view_free (DmaChunkView *this)
234 g_object_unref (this);