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 _vdkeditor_h
00028 #define _vdkeditor_h
00029 #if HAVE_CONFIG_H
00030 #include <config.h>
00031 #endif
00032 #include <vdk/vdk.h>
00033 #include <vdk/gtksourceview.h>
00034 #define INSERT_MARK "insert"
00035
00036 typedef VDKValueList<VDKString> TokenList;
00037 typedef VDKValueListIterator<VDKString> TokenListIterator;
00038
00039
00040
00050 class VDKEditor : public VDKObject
00051 {
00052
00053 private:
00054 virtual void LocalConnect();
00055 static int TabHandler (GtkWidget *widget,
00056 GdkEvent *ev,
00057 gpointer gp);
00058 static void HandleRealize(GtkWidget*, gpointer);
00059 protected:
00060 TokenList* tokenlist;
00061 GtkSourceBuffer* buffer;
00062 GtkWidget* view;
00063 bool MakeCompletion(const char* word);
00064
00065 void ShowTipWindow(char* word);
00066 void AddToken();
00067 int ShowParenMatch(int start,char keyval,
00068 GtkWidget* widget,
00069 bool insert, int restore);
00070 static int OnKeyRelease (GtkWidget *widget,
00071 GdkEvent *ev,
00072 gpointer gp);
00073 static void OnBufferChanged(GtkWidget* buf, gpointer gp);
00074 public:
00086 VDKEditor(VDKForm* owner, GtkSourceBuffer* buff = NULL);
00090 virtual ~VDKEditor();
00098 static TokenList* LoadTokens( const char* filename);
00104 TokenList* SetTokens(TokenList* tkl = NULL)
00105 {
00106 if(tkl)
00107 tokenlist = tkl;
00108 return tokenlist;
00109 }
00110
00111 virtual void SetForeground(VDKRgb rgb,
00112 GtkStateType state = GTK_STATE_NORMAL);
00113
00114 virtual void SetBackground(VDKRgb color,
00115 GtkStateType state = GTK_STATE_NORMAL);
00116
00117 virtual void SetFont(VDKFont* font);
00118
00122 GtkSourceBuffer* Buffer(void) { return buffer; }
00127 void Scroll (int pointer = -1, int margin = 0);
00131 void Scroll(int line, int col, int margin = 0);
00137 char* GetWord(int pos = -1);
00138
00139
00140
00141 VDKReadWriteValueProp<VDKEditor,bool> Syntax;
00142
00147 VDKReadWriteValueProp<VDKEditor,int> Pointer;
00151 VDKReadWriteValueProp<VDKEditor,int> Column;
00155 VDKReadWriteValueProp<VDKEditor,int> Line;
00156
00157
00158
00159 VDKReadOnlyValueProp<VDKEditor,unsigned int> Length;
00160
00161
00162
00163 VDKReadWriteValueProp<VDKEditor,bool> Editable;
00164
00165
00166
00167 VDKReadWriteValueProp<VDKEditor,unsigned int> MaxUndo;
00168
00169
00170
00171 VDKReadWriteValueProp<VDKEditor,bool> LineAutoSelect;
00172
00173
00174
00175 VDKReadWriteValueProp<VDKEditor,bool> ShowLineNumbers;
00179 VDKReadOnlyValueProp<VDKEditor,int> FirstVisibleLine;
00183 VDKReadOnlyValueProp<VDKEditor,int> LastVisibleLine;
00187 VDKReadWriteValueProp<VDKEditor,bool> Changed;
00192 bool LoadFromFile(const char* filename);
00196 void Clear();
00207 gchar* GetChars(int start = 0, int end = -1);
00211 bool SaveToFile( const char* filename);
00212
00213 bool Undo();
00217 void Eol() { TextInsert("\n"); }
00223 void TextInsert(const char* txt, int nchar = -1);
00227 void ForwardDelete(int nchars);
00231 void BackwardDelete(int nchars);
00237 bool IsLineVisible(int line)
00238 {
00239 return (line >= FirstVisibleLine) &&
00240 (line <= LastVisibleLine);
00241 }
00247 int GetLineAtOffset(int offset);
00265 void InstallSyntaxTable (VDKColor *key_color,
00266 VDKFont *key_font,
00267 VDKColor *gtk_color,
00268 VDKFont *gtk_font,
00269 VDKColor *macro_color,
00270 VDKFont *macro_font,
00271 VDKColor *pp_color,
00272 VDKFont *pp_font,
00273 VDKColor *const_color,
00274 VDKFont *const_font,
00275 VDKColor *comment_color,
00276 VDKFont *comment_font );
00280 void ClearSyntaxTable();
00285 void ScrollToPos (int pointer = -1, int margin = 0);
00289 void ScrollToLine(int line, int col, int margin = 0);
00293 void SelectText(int start, int end);
00297 void UnselectText();
00298
00299
00300
00301 void SetSyntax(bool f);
00302 void SetPointer(int p);
00303 int GetPointer();
00304 void SetLine(int r);
00305 int GetLine();
00306 void SetColumn(int r);
00307 int GetColumn();
00308 unsigned int GetLength();
00309 bool GetEditable();
00310 void SetEditable(bool f);
00311 void SetShowLineNumbers(bool f);
00312 bool GetShowLineNumbers(void);
00313 int GetFirstVisibleLine();
00314 int GetLastVisibleLine();
00315 bool GetChanged();
00316 void SetChanged(bool f);
00317 void SetMaxUndo(int );
00318 };
00319
00320
00321
00322 class Tipwin: public VDKForm
00323 {
00324 VDKLabel* label;
00325 char* tip;
00326 public:
00327 Tipwin(VDKForm* owner, char* tip):
00328 VDKForm(owner,NULL,v_box,GTK_WINDOW_POPUP),tip(tip)
00329 {}
00330 ~Tipwin() {}
00331 void Setup(void);
00332
00333 };
00334 #endif