Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | Related Pages

vdktextview.h

00001 /*
00002  * ===========================
00003  * VDK Visual Development Kit
00004  * Version 2.0.0
00005  * December 2000
00006  * ===========================
00007  *
00008  * Copyright (C) 1998,199,2000,2001 Mario Motta
00009  * Developed by Mario Motta <mmotta@guest.net>
00010  *
00011  * This library is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU Library General Public
00013  * License as published by the Free Software Foundation; either
00014  * version 2 of the License, or (at your option) any later version.
00015  *
00016  * This library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * Library General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Library General Public
00022  * License along with this library; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00024  * 02111-1307, USA.
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   Gets buffer length in chars
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   properties setting/getting functions
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 /* TextView border interested windows
00182   used by VDKTextView::TextBorder()
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   Gets buffer length in chars
00271   */
00272   VDKReadOnlyValueProp<VDKTextView,unsigned int> Length;
00273   /*
00274   Sets/gets text view editable
00275   */
00276   VDKReadWriteValueProp<VDKTextView,bool> Editable;
00277   /*
00278   Sets/gets max undo (dummy for now)
00279   */
00280   VDKReadWriteValueProp<VDKTextView,unsigned int> MaxUndo;
00281   /*
00282   Sets/gets text line auto select (dummy for now)
00283   */
00284   VDKReadWriteValueProp<VDKTextView,bool> LineAutoSelect;
00285   /*
00286   Sets/gets text show line numbers (dummy for now)
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   properties setting/getting functions
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

Generated on Wed Aug 6 11:01:52 2003 for vdk 2.0.3 by doxygen 1.3.2