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
provides a raw color object
Definition: colors.h:37
Provides a nice source editor wrapping Mike Hammerson GtkSourceView. Editor provides:
Definition: vdkeditor.h:52
void Clear()
Definition: vdkeditor.cc:502
GtkSourceBuffer * Buffer(void)
Definition: vdkeditor.h:123
bool SaveToFile(const char *filename)
Definition: vdkeditor.cc:525
void RemoveLineMarks(int line)
Definition: vdkeditor.cc:902
VDKReadWriteValueProp< VDKEditor, int > Column
Definition: vdkeditor.h:152
static TokenList * LoadTokens(const char *filename)
Definition: vdkeditor.cc:1377
bool AddMarkIcon(VDKPixbuf *image, const char *icon_key, bool overwrite=true)
Definition: vdkeditor.cc:874
virtual void SetBackground(VDKRgb color, GtkStateType state=GTK_STATE_NORMAL)
Definition: vdkeditor.cc:114
void SelectText(int start, int end)
Definition: vdkeditor.cc:1314
int GetLineAtOffset(int offset)
Definition: vdkeditor.cc:601
void ForwardDelete(int nchars)
Definition: vdkeditor.cc:567
virtual void SetFont(VDKFont *font)
Definition: vdkeditor.cc:107
TokenList * SetTokens(TokenList *tkl=NULL)
Definition: vdkeditor.h:105
VDKReadWriteValueProp< VDKEditor, int > Line
Definition: vdkeditor.h:156
void InstallSyntaxTable(VDKColor *key_color, VDKFont *key_font, VDKColor *gtk_color, VDKFont *gtk_font, VDKColor *macro_color, VDKFont *macro_font, VDKColor *pp_color, VDKFont *pp_font, VDKColor *const_color, VDKFont *const_font, VDKColor *comment_color, VDKFont *comment_font)
Definition: vdkeditor.cc:190
void ClearSyntaxTable()
Definition: vdkeditor.cc:161
void ScrollToLine(int line, int col, int margin=0)
Definition: vdkeditor.cc:1363
VDKEditor(VDKForm *owner, GtkSourceBuffer *buff=NULL)
Definition: vdkeditor.cc:37
VDKReadOnlyValueProp< VDKEditor, int > LastVisibleLine
Definition: vdkeditor.h:188
void ScrollToPos(int pointer=-1, int margin=0)
Definition: vdkeditor.cc:1349
virtual void SetForeground(VDKRgb rgb, GtkStateType state=GTK_STATE_NORMAL)
Definition: vdkeditor.cc:129
void Eol()
Definition: vdkeditor.h:222
gchar * GetChars(int start=0, int end=-1)
Definition: vdkeditor.cc:511
void AddLineMark(int line, const char *icon_key)
Definition: vdkeditor.cc:886
bool IsLineVisible(int line)
Definition: vdkeditor.h:242
VDKReadWriteValueProp< VDKEditor, int > Pointer
Definition: vdkeditor.h:148
void RemoveLineMark(int line, const char *icon_key)
Definition: vdkeditor.cc:894
void Scroll(int pointer=-1, int margin=0)
Definition: vdkeditor.cc:476
void BackwardDelete(int nchars)
Definition: vdkeditor.cc:587
bool LoadFromFile(const char *filename)
Definition: vdkeditor.cc:137
char * GetWord(int pos=-1)
Definition: vdkeditor.cc:632
virtual ~VDKEditor()
Definition: vdkeditor.cc:99
VDKReadWriteValueProp< VDKEditor, bool > Changed
Definition: vdkeditor.h:192
void UnselectText()
Definition: vdkeditor.cc:1330
VDKReadOnlyValueProp< VDKEditor, int > FirstVisibleLine
Definition: vdkeditor.h:184
void TextInsert(const char *txt, int nchar=-1)
Definition: vdkeditor.cc:559
void RemoveAllLineMarks()
Definition: vdkeditor.cc:909
Provides a raw font.
Definition: vdkfont.h:38
VDKForm widgets, generally the outermost widget container.
Definition: forms.h:69
virtual void Setup(void)=0
Provides a gtklabel wrapper.
Definition: label.h:41
Definition: vdkobj.h:141
GtkWidget * widget
Definition: vdkobj.h:241
Provides a raw image wrapping GdkPixbuf This class should in time substitute VDKRawPixmap that from n...
Definition: rawpixbuf.h:41
Provides a simple RGB color structure.
Definition: vdkutils.h:38
provides a VDKValueList iterator
Definition: value_sem_list.h:180