vdk 2.4.0
vdktextview.h
1/*
2 * ===========================
3 * VDK Visual Development Kit
4 * Version 2.0.0
5 * December 2000
6 * ===========================
7 *
8 * Copyright (C) 1998,199,2000,2001 Mario Motta
9 * Developed by Mario Motta <mmotta@guest.net>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
20 *
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 * 02111-1307, USA.
25 */
26
27#ifndef _vdktextview_h
28#define _vdktextview_h
29#include <vdk/widcontain.h>
30#include <vdk/vdkprops.h>
31#include <vdk/eventbox.h>
32#define INSERT_MARK "insert"
33class VDKTextView;
46#ifndef USE_SIGCPLUSPLUS
48#else
49class VDKTextBuffer : public SigC::Object, public VDKNotCopyAble
50#endif
51{
52 friend class VDKTextView;
53
54private:
55 unsigned int ref;
56 void Ref();
57 void Unref();
58
59protected:
60
61 GtkTextBuffer* buffer;
62public:
67 VDKReadWriteValueProp<VDKTextBuffer,int> Pointer;
71 VDKReadWriteValueProp<VDKTextBuffer,int> Column;
75 VDKReadWriteValueProp<VDKTextBuffer,int> Line;
76 /*
77 Gets buffer length in chars
78 */
79 VDKReadOnlyValueProp<VDKTextBuffer,unsigned int> Length;
83 VDKReadWriteValueProp<VDKTextBuffer,bool> Changed;
92 VDKTextBuffer(char* filename);
96 virtual ~VDKTextBuffer();
101 bool LoadFromFile(const char* filename);
105 bool SaveToFile(const char* filename);
109 GtkTextBuffer* Buffer() { return buffer; }
113 void Clear();
119 void TextInsert(const char* txt, int nchar = -1);
130 gchar* GetChars(int start, int end = -1);
134 void ForwardDelete(int nchars);
138 void BackwardDelete(int nchars);
142 void Undo() { }
148 int GetLineAtOffset(int offset);
149 /*
150 properties setting/getting functions
151 */
152 void SetPointer(int p);
153 int GetPointer();
154 void SetLine(int r);
155 int GetLine();
156 void SetColumn(int r);
157 int GetColumn();
158 unsigned int GetLength()
159 {
160 return gtk_text_buffer_get_char_count(buffer);
161 }
162 bool GetChanged()
163 {
164 return gtk_text_buffer_get_modified(buffer);
165 }
166 void SetChanged(bool f)
167 {
168 gtk_text_buffer_set_modified(buffer,f);
169 }
170};
171
172
181/* TextView border interested windows
182 used by VDKTextView::TextBorder()
183 */
184#define TVB_ALL 0x0000
185#define TVB_LEFT 0x0001
186#define TVB_TOP 0x0002
187#define TVB_RIGHT 0x0004
188#define TVB_BOTTOM 0x0008
189#define TVB_TYPEMASK 0x000F
190
191
193{
194 protected:
195 VDKTextBuffer* buffer;
196 GtkWidget* view;
197 void ConnectSignals();
198 static void HandleRealize(GtkWidget*, gpointer);
199 int left_border;
200 public:
212 VDKTextView(VDKForm* owner, VDKTextBuffer* buffer = NULL,
213 int left_border = 0);
217 virtual ~VDKTextView();
218
219 virtual void SetForeground(VDKRgb rgb,
220 GtkStateType state = GTK_STATE_NORMAL);
221 virtual void SetBackground(VDKRgb color,
222 GtkStateType state = GTK_STATE_NORMAL);
223 virtual void SetFont(VDKFont* font);
234 VDKTextBuffer* Buffer(VDKTextBuffer* buff = NULL);
246 void TextBorder(int size, int which = TVB_ALL);
251 void ScrollToPos (int pointer = -1, int margin = 0);
255 void ScrollToLine(int line, int col, int margin = 0);
260 VDKReadWriteValueProp<VDKTextView,int> Pointer;
264 VDKReadWriteValueProp<VDKTextView,int> Column;
268 VDKReadWriteValueProp<VDKTextView,int> Line;
269 /*
270 Gets buffer length in chars
271 */
272 VDKReadOnlyValueProp<VDKTextView,unsigned int> Length;
273 /*
274 Sets/gets text view editable
275 */
276 VDKReadWriteValueProp<VDKTextView,bool> Editable;
277 /*
278 Sets/gets max undo (dummy for now)
279 */
280 VDKReadWriteValueProp<VDKTextView,unsigned int> MaxUndo;
281 /*
282 Sets/gets text line auto select (dummy for now)
283 */
284 VDKReadWriteValueProp<VDKTextView,bool> LineAutoSelect;
285 /*
286 Sets/gets text show line numbers (dummy for now)
287 */
288 VDKReadWriteValueProp<VDKTextView,bool> ShowLineNumbers;
292 VDKReadOnlyValueProp<VDKTextView,int> FirstVisibleLine;
296 VDKReadOnlyValueProp<VDKTextView,int> LastVisibleLine;
300 VDKReadWriteValueProp<VDKTextView,bool> Changed;
301
306 bool LoadFromFile(char* filename)
307 {
308 return buffer->LoadFromFile(filename);
309 }
313 void Clear() { buffer->Clear(); }
324 gchar* GetChars(int start = 0, int end = -1)
325 {
326 return buffer->GetChars(start,end);
327 }
331 bool SaveToFile(char* filename) { return buffer->SaveToFile(filename); }
335 void Thaw() {}
339 void Freeze()
340 {
341 }
345 void Undo() { buffer->Undo(); }
349 void Eol() { TextInsert("\n"); }
355 void TextInsert(const char* txt, int nchar = -1)
356 {
357 buffer->TextInsert(txt,nchar);
358 }
362 void ForwardDelete(int nchars)
363 { buffer->ForwardDelete(nchars); }
367 void BackwardDelete(int nchars)
368 { buffer->BackwardDelete(nchars); }
374 bool IsLineVisible(int line)
375 {
376 return (line >= FirstVisibleLine) &&
377 (line <= LastVisibleLine);
378 }
384 int GetLineAtOffset(int offset)
385 { return buffer->GetLineAtOffset(offset); }
386 /*
387 properties setting/getting functions
388 */
389 void SetPointer(int p) { buffer->SetPointer(p); }
390 int GetPointer() { return buffer->GetPointer(); }
391 void SetLine(int r) { buffer->SetLine(r); }
392 int GetLine() { return buffer->GetLine(); }
393 void SetColumn(int r) { buffer->SetColumn(r); }
394 int GetColumn() { return buffer->GetColumn(); }
395 unsigned int GetLength() { return buffer->GetLength(); }
396 bool GetEditable()
397 { return gtk_text_view_get_editable (GTK_TEXT_VIEW(view));}
398 void SetEditable(bool f)
399 { gtk_text_view_set_editable (GTK_TEXT_VIEW(view),f);}
400 void SetShowLineNumbers(bool f);
401 int GetFirstVisibleLine();
402 int GetLastVisibleLine();
403 bool GetChanged() { return buffer->GetChanged(); }
404 void SetChanged(bool f) { buffer->SetChanged(f); }
405};
406#endif
Provides a raw font.
Definition: vdkfont.h:38
VDKForm widgets, generally the outermost widget container.
Definition: forms.h:69
Hierarchy root class.
Definition: vdkutils.h:264
Containers base class.
Definition: widcontain.h:40
Provides a simple RGB color structure.
Definition: vdkutils.h:38
Provides a gtk+ gtktextbuffer wrapper.
Definition: vdktextview.h:51
void BackwardDelete(int nchars)
Definition: vdktextview.cc:270
VDKReadWriteValueProp< VDKTextBuffer, int > Column
Definition: vdktextview.h:71
int GetLineAtOffset(int offset)
Definition: vdktextview.cc:286
void ForwardDelete(int nchars)
Definition: vdktextview.cc:250
virtual ~VDKTextBuffer()
Definition: vdktextview.cc:83
bool SaveToFile(const char *filename)
Definition: vdktextview.cc:119
VDKReadWriteValueProp< VDKTextBuffer, bool > Changed
Definition: vdktextview.h:83
VDKReadWriteValueProp< VDKTextBuffer, int > Pointer
Definition: vdktextview.h:67
void Undo()
Definition: vdktextview.h:142
VDKReadWriteValueProp< VDKTextBuffer, int > Line
Definition: vdktextview.h:75
void Clear()
Definition: vdktextview.cc:152
void TextInsert(const char *txt, int nchar=-1)
Definition: vdktextview.cc:145
GtkTextBuffer * Buffer()
Definition: vdktextview.h:109
VDKTextBuffer()
Definition: vdktextview.cc:56
bool LoadFromFile(const char *filename)
Definition: vdktextview.cc:93
gchar * GetChars(int start, int end=-1)
Definition: vdktextview.cc:233
Provides a gtk+ gtktextview wrapper. This widget works under a buffer-view model, text buffer take ca...
Definition: vdktextview.h:193
void Freeze()
Definition: vdktextview.h:339
void Undo()
Definition: vdktextview.h:345
VDKTextView(VDKForm *owner, VDKTextBuffer *buffer=NULL, int left_border=0)
Definition: vdktextview.cc:301
void ScrollToLine(int line, int col, int margin=0)
Definition: vdktextview.cc:458
void Eol()
Definition: vdktextview.h:349
bool LoadFromFile(char *filename)
Definition: vdktextview.h:306
void Clear()
Definition: vdktextview.h:313
VDKReadWriteValueProp< VDKTextView, bool > Changed
Definition: vdktextview.h:300
void Thaw()
Definition: vdktextview.h:335
int GetLineAtOffset(int offset)
Definition: vdktextview.h:384
void BackwardDelete(int nchars)
Definition: vdktextview.h:367
void ScrollToPos(int pointer=-1, int margin=0)
Definition: vdktextview.cc:444
bool SaveToFile(char *filename)
Definition: vdktextview.h:331
VDKReadOnlyValueProp< VDKTextView, int > LastVisibleLine
Definition: vdktextview.h:296
void TextInsert(const char *txt, int nchar=-1)
Definition: vdktextview.h:355
virtual void SetBackground(VDKRgb color, GtkStateType state=GTK_STATE_NORMAL)
Definition: vdktextview.cc:391
VDKReadOnlyValueProp< VDKTextView, int > FirstVisibleLine
Definition: vdktextview.h:292
bool IsLineVisible(int line)
Definition: vdktextview.h:374
gchar * GetChars(int start=0, int end=-1)
Definition: vdktextview.h:324
virtual ~VDKTextView()
Definition: vdktextview.cc:369
VDKReadWriteValueProp< VDKTextView, int > Pointer
Definition: vdktextview.h:260
VDKReadWriteValueProp< VDKTextView, int > Column
Definition: vdktextview.h:264
virtual void SetFont(VDKFont *font)
Definition: vdktextview.cc:412
void TextBorder(int size, int which=TVB_ALL)
Definition: vdktextview.cc:418
VDKTextBuffer * Buffer(VDKTextBuffer *buff=NULL)
Definition: vdktextview.cc:377
void ForwardDelete(int nchars)
Definition: vdktextview.h:362
virtual void SetForeground(VDKRgb rgb, GtkStateType state=GTK_STATE_NORMAL)
Definition: vdktextview.cc:405
VDKReadWriteValueProp< VDKTextView, int > Line
Definition: vdktextview.h:268