00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _vdktextview_h
00028 #define _vdktextview_h
00029 #include <vdk/widcontain.h>
00030 #include <vdk/vdkprops.h>
00031 #include <vdk/eventbox.h>
00032 #define INSERT_MARK "insert"
00033 class VDKTextView;
00046 #ifndef USE_SIGCPLUSPLUS
00047 class VDKTextBuffer : public VDKNotCopyAble
00048 #else
00049 class VDKTextBuffer : public SigC::Object, public VDKNotCopyAble
00050 #endif
00051 {
00052 friend class VDKTextView;
00053
00054 private:
00055 unsigned int ref;
00056 void Ref();
00057 void Unref();
00058
00059 protected:
00060
00061 GtkTextBuffer* buffer;
00062 public:
00067 VDKReadWriteValueProp<VDKTextBuffer,int> Pointer;
00071 VDKReadWriteValueProp<VDKTextBuffer,int> Column;
00075 VDKReadWriteValueProp<VDKTextBuffer,int> Line;
00076
00077
00078
00079 VDKReadOnlyValueProp<VDKTextBuffer,unsigned int> Length;
00083 VDKReadWriteValueProp<VDKTextBuffer,bool> Changed;
00087 VDKTextBuffer();
00092 VDKTextBuffer(char* filename);
00096 virtual ~VDKTextBuffer();
00101 bool LoadFromFile(const char* filename);
00105 bool SaveToFile(const char* filename);
00109 GtkTextBuffer* Buffer() { return buffer; }
00113 void Clear();
00119 void TextInsert(const char* txt, int nchar = -1);
00130 gchar* GetChars(int start, int end = -1);
00134 void ForwardDelete(int nchars);
00138 void BackwardDelete(int nchars);
00142 void Undo() { }
00148 int GetLineAtOffset(int offset);
00149
00150
00151
00152 void SetPointer(int p);
00153 int GetPointer();
00154 void SetLine(int r);
00155 int GetLine();
00156 void SetColumn(int r);
00157 int GetColumn();
00158 unsigned int GetLength()
00159 {
00160 return gtk_text_buffer_get_char_count(buffer);
00161 }
00162 bool GetChanged()
00163 {
00164 return gtk_text_buffer_get_modified(buffer);
00165 }
00166 void SetChanged(bool f)
00167 {
00168 gtk_text_buffer_set_modified(buffer,f);
00169 }
00170 };
00171
00172
00181
00182
00183
00184 #define TVB_ALL 0x0000
00185 #define TVB_LEFT 0x0001
00186 #define TVB_TOP 0x0002
00187 #define TVB_RIGHT 0x0004
00188 #define TVB_BOTTOM 0x0008
00189 #define TVB_TYPEMASK 0x000F
00190
00191
00192 class VDKTextView : public VDKObjectContainer
00193 {
00194 protected:
00195 VDKTextBuffer* buffer;
00196 GtkWidget* view;
00197 void ConnectSignals();
00198 static void HandleRealize(GtkWidget*, gpointer);
00199 int left_border;
00200 public:
00212 VDKTextView(VDKForm* owner, VDKTextBuffer* buffer = NULL,
00213 int left_border = 0);
00217 virtual ~VDKTextView();
00218
00219 virtual void SetForeground(VDKRgb rgb,
00220 GtkStateType state = GTK_STATE_NORMAL);
00221 virtual void SetBackground(VDKRgb color,
00222 GtkStateType state = GTK_STATE_NORMAL);
00223 virtual void SetFont(VDKFont* font);
00234 VDKTextBuffer* Buffer(VDKTextBuffer* buff = NULL);
00246 void TextBorder(int size, int which = TVB_ALL);
00251 void ScrollToPos (int pointer = -1, int margin = 0);
00255 void ScrollToLine(int line, int col, int margin = 0);
00260 VDKReadWriteValueProp<VDKTextView,int> Pointer;
00264 VDKReadWriteValueProp<VDKTextView,int> Column;
00268 VDKReadWriteValueProp<VDKTextView,int> Line;
00269
00270
00271
00272 VDKReadOnlyValueProp<VDKTextView,unsigned int> Length;
00273
00274
00275
00276 VDKReadWriteValueProp<VDKTextView,bool> Editable;
00277
00278
00279
00280 VDKReadWriteValueProp<VDKTextView,unsigned int> MaxUndo;
00281
00282
00283
00284 VDKReadWriteValueProp<VDKTextView,bool> LineAutoSelect;
00285
00286
00287
00288 VDKReadWriteValueProp<VDKTextView,bool> ShowLineNumbers;
00292 VDKReadOnlyValueProp<VDKTextView,int> FirstVisibleLine;
00296 VDKReadOnlyValueProp<VDKTextView,int> LastVisibleLine;
00300 VDKReadWriteValueProp<VDKTextView,bool> Changed;
00301
00306 bool LoadFromFile(char* filename)
00307 {
00308 return buffer->LoadFromFile(filename);
00309 }
00313 void Clear() { buffer->Clear(); }
00324 gchar* GetChars(int start = 0, int end = -1)
00325 {
00326 return buffer->GetChars(start,end);
00327 }
00331 bool SaveToFile(char* filename) { return buffer->SaveToFile(filename); }
00335 void Thaw() {}
00339 void Freeze()
00340 {
00341 }
00345 void Undo() { buffer->Undo(); }
00349 void Eol() { TextInsert("\n"); }
00355 void TextInsert(const char* txt, int nchar = -1)
00356 {
00357 buffer->TextInsert(txt,nchar);
00358 }
00362 void ForwardDelete(int nchars)
00363 { buffer->ForwardDelete(nchars); }
00367 void BackwardDelete(int nchars)
00368 { buffer->BackwardDelete(nchars); }
00374 bool IsLineVisible(int line)
00375 {
00376 return (line >= FirstVisibleLine) &&
00377 (line <= LastVisibleLine);
00378 }
00384 int GetLineAtOffset(int offset)
00385 { return buffer->GetLineAtOffset(offset); }
00386
00387
00388
00389 void SetPointer(int p) { buffer->SetPointer(p); }
00390 int GetPointer() { return buffer->GetPointer(); }
00391 void SetLine(int r) { buffer->SetLine(r); }
00392 int GetLine() { return buffer->GetLine(); }
00393 void SetColumn(int r) { buffer->SetColumn(r); }
00394 int GetColumn() { return buffer->GetColumn(); }
00395 unsigned int GetLength() { return buffer->GetLength(); }
00396 bool GetEditable()
00397 { return gtk_text_view_get_editable (GTK_TEXT_VIEW(view));}
00398 void SetEditable(bool f)
00399 { gtk_text_view_set_editable (GTK_TEXT_VIEW(view),f);}
00400 void SetShowLineNumbers(bool f);
00401 int GetFirstVisibleLine();
00402 int GetLastVisibleLine();
00403 bool GetChanged() { return buffer->GetChanged(); }
00404 void SetChanged(bool f) { buffer->SetChanged(f); }
00405 };
00406 #endif