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
21 * It is a GtkTextView with an associated GtkAjustment, allowing to put in the
22 * GtkTextView only a part of a big amount of text. Cursor movements are not
23 * limited by the GtkTextView content but by the GtkAjustment.
24 *---------------------------------------------------------------------------*/
26 #include "chunk_view.h"
32 GtkAdjustment
*vadjustment
;
35 struct _DmaChunkViewClass
37 GtkTextViewClass parent_class
;
40 /* Used in dispose and finalize */
41 static GtkWidgetClass
*parent_class
= NULL
;
44 *---------------------------------------------------------------------------*/
47 set_adjustment_clamped (GtkAdjustment
*adj
, gdouble value
)
49 if (value
< adj
->lower
)
53 if (value
> (adj
->upper
- adj
->page_size
))
55 value
= adj
->upper
- adj
->page_size
;
57 gtk_adjustment_set_value (adj
, value
);
61 *---------------------------------------------------------------------------*/
64 dma_chunk_view_move_cursor (GtkTextView
*text_view
,
67 gboolean extend_selection
)
69 DmaChunkView
*view
= DMA_CHUNK_VIEW (text_view
);
70 gdouble value
= view
->vadjustment
->value
;
72 GtkTextBuffer
*buffer
;
78 case GTK_MOVEMENT_LOGICAL_POSITIONS
:
79 case GTK_MOVEMENT_VISUAL_POSITIONS
:
80 case GTK_MOVEMENT_WORDS
:
81 case GTK_MOVEMENT_DISPLAY_LINE_ENDS
:
82 case GTK_MOVEMENT_HORIZONTAL_PAGES
:
84 case GTK_MOVEMENT_DISPLAY_LINES
:
85 case GTK_MOVEMENT_PARAGRAPHS
:
86 case GTK_MOVEMENT_PARAGRAPH_ENDS
:
87 buffer
= gtk_text_view_get_buffer (text_view
);
88 mark
= gtk_text_buffer_get_insert (buffer
);
89 gtk_text_buffer_get_iter_at_mark (buffer
, &cur
, mark
);
90 line
= gtk_text_iter_get_line (&cur
);
92 if ((count
< 0) && (line
== 0))
94 value
+= count
* view
->vadjustment
->step_increment
;
95 set_adjustment_clamped (view
->vadjustment
, value
);
98 else if ((count
> 0) && (line
== gtk_text_buffer_get_line_count(buffer
) - 1))
100 value
+= count
* view
->vadjustment
->step_increment
;
101 set_adjustment_clamped (view
->vadjustment
, value
);
105 case GTK_MOVEMENT_PAGES
:
106 value
+= count
* view
->vadjustment
->page_increment
;
107 set_adjustment_clamped (view
->vadjustment
, value
);
109 case GTK_MOVEMENT_BUFFER_ENDS
:
110 set_adjustment_clamped (view
->vadjustment
, count
< 0 ? view
->vadjustment
->lower
: view
->vadjustment
->upper
);
116 GTK_TEXT_VIEW_CLASS (parent_class
)->move_cursor (text_view
,
122 *---------------------------------------------------------------------------*/
124 void dma_chunk_view_set_scroll_adjustment (DmaChunkView
*this, GtkAdjustment
* vadjustment
)
126 this->vadjustment
= vadjustment
;
130 *---------------------------------------------------------------------------*/
132 /* dispose is the first destruction step. It is used to unref object created
133 * with instance_init in order to break reference counting cycles. This
134 * function could be called several times. All function should still work
135 * after this call. It has to called its parents.*/
138 dma_chunk_view_dispose (GObject
*object
)
140 /*DmaChunkView *this = DMA_CHUNK_VIEW (obj);*/
142 G_OBJECT_CLASS (parent_class
)->dispose (object
);
145 /* finalize is the last destruction step. It must free all memory allocated
146 * with instance_init. It is called only one time just before releasing all
150 dma_chunk_view_finalize (GObject
*object
)
152 /*DmaChunkView *view = DMA_CHUNK_VIEW (object);*/
154 G_OBJECT_CLASS (parent_class
)->finalize (object
);
157 /* instance_init is the constructor. All functions should work after this
161 dma_chunk_view_instance_init (DmaChunkView
*view
)
163 // GtkAdjustment *adj;
165 // PangoFontDescription *font_desc;
169 /* class_init intialize the class itself not the instance */
172 dma_chunk_view_class_init (DmaChunkViewClass
* klass
)
174 GObjectClass
*gobject_class
;
175 GtkObjectClass
*object_class
;
176 GtkWidgetClass
*widget_class
;
177 GtkTextViewClass
*text_view_class
;
179 g_return_if_fail (klass
!= NULL
);
181 gobject_class
= G_OBJECT_CLASS (klass
);
182 object_class
= GTK_OBJECT_CLASS (klass
);
183 widget_class
= GTK_WIDGET_CLASS (klass
);
184 text_view_class
= GTK_TEXT_VIEW_CLASS (klass
);
185 parent_class
= GTK_WIDGET_CLASS (g_type_class_peek_parent (klass
));
187 gobject_class
->dispose
= dma_chunk_view_dispose
;
188 gobject_class
->finalize
= dma_chunk_view_finalize
;
190 text_view_class
->move_cursor
= dma_chunk_view_move_cursor
;
194 dma_chunk_view_get_type (void)
196 static GType type
= 0;
200 static const GTypeInfo type_info
=
202 sizeof (DmaChunkViewClass
),
203 (GBaseInitFunc
) NULL
,
204 (GBaseFinalizeFunc
) NULL
,
205 (GClassInitFunc
) dma_chunk_view_class_init
,
206 (GClassFinalizeFunc
) NULL
,
207 NULL
, /* class_data */
208 sizeof (DmaChunkView
),
210 (GInstanceInitFunc
) dma_chunk_view_instance_init
,
211 NULL
/* value_table */
214 type
= g_type_register_static (GTK_TYPE_TEXT_VIEW
,
215 "DmaChunkView", &type_info
, 0);
221 /* Creation and Destruction
222 *---------------------------------------------------------------------------*/
225 dma_chunk_view_new (void)
229 this = g_object_new (DMA_CHUNK_VIEW_TYPE
, NULL
);
230 g_assert (this != NULL
);
236 dma_chunk_view_free (DmaChunkView
*this)
238 g_object_unref (this);