vdk 2.4.0
vdkeditor.h
1 /*
2  * ===========================
3  * VDK Visual Development Kit
4  * Version 2.0.0
5  * February 2001
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 _vdkeditor_h
28 #define _vdkeditor_h
29 #if HAVE_CONFIG_H
30 #include <config.h>
31 #endif
32 #include <vdk/vdk.h>
33 #include <vdk/gtksourceview.h>
34 #include <vdk/rawpixbuf.h>
35 #define INSERT_MARK "insert"
36 
39 /*
40  Syntax editor class
41 */
51 class VDKEditor : public VDKObject
52 {
53  // signal section
54  private:
55  virtual void LocalConnect();
56  static int TabHandler (GtkWidget *widget,
57  GdkEvent *ev,
58  gpointer gp);
59  static void HandleRealize(GtkWidget*, gpointer);
60  protected:
61  TokenList* tokenlist;
62  GtkSourceBuffer* buffer;
63  GtkWidget* view;
64  bool MakeCompletion(const char* word);
65 
66  void ShowTipWindow(char* word);
67  void AddToken();
68  int ShowParenMatch(int start,char keyval,
69  GtkWidget* widget,
70  bool insert, int restore);
71  static int OnKeyRelease (GtkWidget *widget,
72  GdkEvent *ev,
73  gpointer gp);
74  static void OnBufferChanged(GtkWidget* buf, gpointer gp);
75  public:
87  VDKEditor(VDKForm* owner, GtkSourceBuffer* buff = NULL);
91  virtual ~VDKEditor();
99  static TokenList* LoadTokens( const char* filename);
106  {
107  if(tkl)
108  tokenlist = tkl;
109  return tokenlist;
110  }
111 
112  virtual void SetForeground(VDKRgb rgb,
113  GtkStateType state = GTK_STATE_NORMAL);
114 
115  virtual void SetBackground(VDKRgb color,
116  GtkStateType state = GTK_STATE_NORMAL);
117 
118  virtual void SetFont(VDKFont* font);
119 
123  GtkSourceBuffer* Buffer(void) { return buffer; }
128  void Scroll (int pointer = -1, int margin = 0);
132  void Scroll(int line, int col, int margin = 0);
138  char* GetWord(int pos = -1);
139  /*
140  Sets/gets syntax higlighting
141  */
142  VDKReadWriteValueProp<VDKEditor,bool> Syntax;
143 
148  VDKReadWriteValueProp<VDKEditor,int> Pointer;
152  VDKReadWriteValueProp<VDKEditor,int> Column;
156  VDKReadWriteValueProp<VDKEditor,int> Line;
157  /*
158  Gets buffer length in chars
159  */
160  VDKReadOnlyValueProp<VDKEditor,unsigned int> Length;
161  /*
162  Sets/gets text view editable
163  */
164  VDKReadWriteValueProp<VDKEditor,bool> Editable;
165  /*
166  Sets/gets tab stops
167  */
168  VDKReadWriteValueProp<VDKEditor,int> TabStop;
169  /*
170  Sets/gets max undo (dummy for now)
171  */
172  VDKReadWriteValueProp<VDKEditor,unsigned int> MaxUndo;
173  /*
174  Sets/gets text line auto select (dummy for now)
175  */
176  VDKReadWriteValueProp<VDKEditor,bool> LineAutoSelect;
177  /*
178  Sets/gets text show line numbers (dummy for now)
179  */
180  VDKReadWriteValueProp<VDKEditor,bool> ShowLineNumbers;
184  VDKReadOnlyValueProp<VDKEditor,int> FirstVisibleLine;
188  VDKReadOnlyValueProp<VDKEditor,int> LastVisibleLine;
192  VDKReadWriteValueProp<VDKEditor,bool> Changed;
197  bool LoadFromFile(const char* filename);
201  void Clear();
212  gchar* GetChars(int start = 0, int end = -1);
216  bool SaveToFile( const char* filename);
217  // dummy
218  bool Undo();
222  void Eol() { TextInsert("\n"); }
228  void TextInsert(const char* txt, int nchar = -1);
232  void ForwardDelete(int nchars);
236  void BackwardDelete(int nchars);
242  bool IsLineVisible(int line)
243  {
244  return (line >= FirstVisibleLine) &&
245  (line <= LastVisibleLine);
246  }
252  int GetLineAtOffset(int offset);
270  void InstallSyntaxTable (VDKColor *key_color,
271  VDKFont *key_font,
272  VDKColor *gtk_color,
273  VDKFont *gtk_font,
274  VDKColor *macro_color,
275  VDKFont *macro_font,
276  VDKColor *pp_color,
277  VDKFont *pp_font,
278  VDKColor *const_color,
279  VDKFont *const_font,
280  VDKColor *comment_color,
281  VDKFont *comment_font );
285  void ClearSyntaxTable();
290  void ScrollToPos (int pointer = -1, int margin = 0);
294  void ScrollToLine(int line, int col, int margin = 0);
298  void SelectText(int start, int end);
302  void UnselectText();
309  bool AddMarkIcon(VDKPixbuf* image, const char * icon_key, bool overwrite = true);
315  void AddLineMark(int line, const char* icon_key);
321  void RemoveLineMark(int line, const char* icon_key);
326 void RemoveLineMarks(int line);
330  void RemoveAllLineMarks();
331  /*
332  properties setting/getting functions
333  */
334  void SetSyntax(bool f);
335  void SetPointer(int p);
336  int GetPointer();
337  void SetLine(int r);
338  int GetLine();
339  void SetTabStop(int r);
340  int GetTabStop();
341  void SetColumn(int r);
342  int GetColumn();
343  unsigned int GetLength();
344  bool GetEditable();
345  void SetEditable(bool f);
346  void SetShowLineNumbers(bool f);
347  bool GetShowLineNumbers(void);
348  int GetFirstVisibleLine();
349  int GetLastVisibleLine();
350  bool GetChanged();
351  void SetChanged(bool f);
352  void SetMaxUndo(int );
353 };
354 /*
355 showed hints forms
356 */
357 class Tipwin: public VDKForm
358 {
359  VDKLabel* label;
360  char* tip;
361 public:
362  Tipwin(VDKForm* owner, char* tip):
363  VDKForm(owner,NULL,v_box,GTK_WINDOW_POPUP),tip(tip)
364  {}
365  ~Tipwin() {}
366  void Setup(void);
367 
368 };
369 #endif