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"
33 class VDKTextView;
46 #ifndef USE_SIGCPLUSPLUS
48 #else
49 class VDKTextBuffer : public SigC::Object, public VDKNotCopyAble
50 #endif
51 {
52  friend class VDKTextView;
53 
54 private:
55  unsigned int ref;
56  void Ref();
57  void Unref();
58 
59 protected:
60 
61  GtkTextBuffer* buffer;
62 public:
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;
87  VDKTextBuffer();
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
VDKTextView::ForwardDelete
void ForwardDelete(int nchars)
Definition: vdktextview.h:362
VDKTextView::SaveToFile
bool SaveToFile(char *filename)
Definition: vdktextview.h:331
VDKTextView::Column
VDKReadWriteValueProp< VDKTextView, int > Column
Definition: vdktextview.h:264
VDKTextBuffer::GetChars
gchar * GetChars(int start, int end=-1)
Definition: vdktextview.cc:233
VDKTextView::Line
VDKReadWriteValueProp< VDKTextView, int > Line
Definition: vdktextview.h:268
VDKTextBuffer::Undo
void Undo()
Definition: vdktextview.h:142
VDKTextView::BackwardDelete
void BackwardDelete(int nchars)
Definition: vdktextview.h:367
VDKTextView::Pointer
VDKReadWriteValueProp< VDKTextView, int > Pointer
Definition: vdktextview.h:260
VDKTextView
Provides a gtk+ gtktextview wrapper. This widget works under a buffer-view model, text buffer take ca...
Definition: vdktextview.h:192
VDKTextBuffer::LoadFromFile
bool LoadFromFile(const char *filename)
Definition: vdktextview.cc:93
VDKObjectContainer
Containers base class.
Definition: widcontain.h:39
VDKRgb
Provides a simple RGB color structure.
Definition: vdkutils.h:37
VDKTextView::VDKTextView
VDKTextView(VDKForm *owner, VDKTextBuffer *buffer=NULL, int left_border=0)
Definition: vdktextview.cc:301
VDKTextView::Eol
void Eol()
Definition: vdktextview.h:349
VDKTextBuffer
Provides a gtk+ gtktextbuffer wrapper.
Definition: vdktextview.h:47
VDKTextBuffer::BackwardDelete
void BackwardDelete(int nchars)
Definition: vdktextview.cc:270
VDKTextBuffer::ForwardDelete
void ForwardDelete(int nchars)
Definition: vdktextview.cc:250
VDKTextView::LoadFromFile
bool LoadFromFile(char *filename)
Definition: vdktextview.h:306
VDKTextBuffer::Buffer
GtkTextBuffer * Buffer()
Definition: vdktextview.h:109
VDKTextView::SetFont
virtual void SetFont(VDKFont *font)
Definition: vdktextview.cc:412
VDKNotCopyAble
Hierarchy root class.
Definition: vdkutils.h:263
VDKTextView::SetBackground
virtual void SetBackground(VDKRgb color, GtkStateType state=GTK_STATE_NORMAL)
Definition: vdktextview.cc:391
VDKTextView::Undo
void Undo()
Definition: vdktextview.h:345
VDKTextView::Buffer
VDKTextBuffer * Buffer(VDKTextBuffer *buff=NULL)
Definition: vdktextview.cc:377
VDKTextBuffer::Column
VDKReadWriteValueProp< VDKTextBuffer, int > Column
Definition: vdktextview.h:71
VDKForm
VDKForm widgets, generally the outermost widget container.
Definition: forms.h:68
VDKTextView::Thaw
void Thaw()
Definition: vdktextview.h:335
VDKTextView::GetLineAtOffset
int GetLineAtOffset(int offset)
Definition: vdktextview.h:384
VDKTextBuffer::~VDKTextBuffer
virtual ~VDKTextBuffer()
Definition: vdktextview.cc:83
VDKTextView::Freeze
void Freeze()
Definition: vdktextview.h:339
VDKTextView::TextBorder
void TextBorder(int size, int which=TVB_ALL)
Definition: vdktextview.cc:418
VDKTextView::~VDKTextView
virtual ~VDKTextView()
Definition: vdktextview.cc:369
VDKTextView::FirstVisibleLine
VDKReadOnlyValueProp< VDKTextView, int > FirstVisibleLine
Definition: vdktextview.h:292
VDKTextView::ScrollToLine
void ScrollToLine(int line, int col, int margin=0)
Definition: vdktextview.cc:458
VDKTextBuffer::Pointer
VDKReadWriteValueProp< VDKTextBuffer, int > Pointer
Definition: vdktextview.h:67
VDKTextBuffer::Changed
VDKReadWriteValueProp< VDKTextBuffer, bool > Changed
Definition: vdktextview.h:83
VDKTextBuffer::Line
VDKReadWriteValueProp< VDKTextBuffer, int > Line
Definition: vdktextview.h:75
VDKTextView::Changed
VDKReadWriteValueProp< VDKTextView, bool > Changed
Definition: vdktextview.h:300
VDKTextBuffer::SaveToFile
bool SaveToFile(const char *filename)
Definition: vdktextview.cc:119
VDKTextBuffer::VDKTextBuffer
VDKTextBuffer()
Definition: vdktextview.cc:56
VDKTextView::GetChars
gchar * GetChars(int start=0, int end=-1)
Definition: vdktextview.h:324
VDKTextBuffer::Clear
void Clear()
Definition: vdktextview.cc:152
VDKTextView::SetForeground
virtual void SetForeground(VDKRgb rgb, GtkStateType state=GTK_STATE_NORMAL)
Definition: vdktextview.cc:405
VDKTextView::Clear
void Clear()
Definition: vdktextview.h:313
VDKTextView::ScrollToPos
void ScrollToPos(int pointer=-1, int margin=0)
Definition: vdktextview.cc:444
VDKTextView::LastVisibleLine
VDKReadOnlyValueProp< VDKTextView, int > LastVisibleLine
Definition: vdktextview.h:296
VDKTextBuffer::TextInsert
void TextInsert(const char *txt, int nchar=-1)
Definition: vdktextview.cc:145
VDKTextView::IsLineVisible
bool IsLineVisible(int line)
Definition: vdktextview.h:374
VDKTextView::TextInsert
void TextInsert(const char *txt, int nchar=-1)
Definition: vdktextview.h:355
VDKFont
Provides a raw font.
Definition: vdkfont.h:37
VDKTextBuffer::GetLineAtOffset
int GetLineAtOffset(int offset)
Definition: vdktextview.cc:286