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
#include <vdk/rawpixbuf.h>
00035
#define INSERT_MARK "insert"
00036
00037
typedef VDKValueList<VDKString> TokenList;
00038
typedef VDKValueListIterator<VDKString> TokenListIterator;
00039
00040
00041
00051 class VDKEditor :
public VDKObject
00052 {
00053
00054
private:
00055
virtual void LocalConnect();
00056
static int TabHandler (GtkWidget *widget,
00057 GdkEvent *ev,
00058 gpointer gp);
00059
static void HandleRealize(GtkWidget*, gpointer);
00060
protected:
00061 TokenList* tokenlist;
00062 GtkSourceBuffer* buffer;
00063 GtkWidget* view;
00064
bool MakeCompletion(
const char* word);
00065
00066
void ShowTipWindow(
char* word);
00067
void AddToken();
00068
int ShowParenMatch(
int start,
char keyval,
00069 GtkWidget* widget,
00070
bool insert,
int restore);
00071
static int OnKeyRelease (GtkWidget *widget,
00072 GdkEvent *ev,
00073 gpointer gp);
00074
static void OnBufferChanged(GtkWidget* buf, gpointer gp);
00075
public:
00087
VDKEditor(
VDKForm* owner, GtkSourceBuffer* buff = NULL);
00091
virtual ~VDKEditor();
00099
static TokenList*
LoadTokens(
const char* filename);
00105 TokenList*
SetTokens(TokenList* tkl = NULL)
00106 {
00107
if(tkl)
00108 tokenlist = tkl;
00109
return tokenlist;
00110 }
00111
00112
virtual void SetForeground(
VDKRgb rgb,
00113 GtkStateType state = GTK_STATE_NORMAL);
00114
00115
virtual void SetBackground(
VDKRgb color,
00116 GtkStateType state = GTK_STATE_NORMAL);
00117
00118
virtual void SetFont(
VDKFont* font);
00119
00123 GtkSourceBuffer*
Buffer(
void) {
return buffer; }
00128
void Scroll (
int pointer = -1,
int margin = 0);
00132
void Scroll(
int line,
int col,
int margin = 0);
00138
char* GetWord(
int pos = -1);
00139
00140
00141
00142 VDKReadWriteValueProp<VDKEditor,bool> Syntax;
00143
00148 VDKReadWriteValueProp<VDKEditor,int>
Pointer;
00152 VDKReadWriteValueProp<VDKEditor,int>
Column;
00156 VDKReadWriteValueProp<VDKEditor,int>
Line;
00157
00158
00159
00160 VDKReadOnlyValueProp<VDKEditor,unsigned int> Length;
00161
00162
00163
00164 VDKReadWriteValueProp<VDKEditor,bool> Editable;
00165
00166
00167
00168 VDKReadWriteValueProp<VDKEditor,int> TabStop;
00169
00170
00171
00172 VDKReadWriteValueProp<VDKEditor,unsigned int> MaxUndo;
00173
00174
00175
00176 VDKReadWriteValueProp<VDKEditor,bool> LineAutoSelect;
00177
00178
00179
00180 VDKReadWriteValueProp<VDKEditor,bool> ShowLineNumbers;
00184 VDKReadOnlyValueProp<VDKEditor,int>
FirstVisibleLine;
00188 VDKReadOnlyValueProp<VDKEditor,int>
LastVisibleLine;
00192 VDKReadWriteValueProp<VDKEditor,bool>
Changed;
00197
bool LoadFromFile(
const char* filename);
00201
void Clear();
00212 gchar*
GetChars(
int start = 0,
int end = -1);
00216
bool SaveToFile(
const char* filename);
00217
00218
bool Undo();
00222 void Eol() {
TextInsert(
"\n"); }
00228
void TextInsert(
const char* txt,
int nchar = -1);
00232
void ForwardDelete(
int nchars);
00236
void BackwardDelete(
int nchars);
00242 bool IsLineVisible(
int line)
00243 {
00244
return (line >=
FirstVisibleLine) &&
00245 (line <=
LastVisibleLine);
00246 }
00252
int GetLineAtOffset(
int offset);
00270
void InstallSyntaxTable (
VDKColor *key_color,
00271
VDKFont *key_font,
00272
VDKColor *gtk_color,
00273
VDKFont *gtk_font,
00274
VDKColor *macro_color,
00275
VDKFont *macro_font,
00276
VDKColor *pp_color,
00277
VDKFont *pp_font,
00278
VDKColor *const_color,
00279
VDKFont *const_font,
00280
VDKColor *comment_color,
00281
VDKFont *comment_font );
00285
void ClearSyntaxTable();
00290
void ScrollToPos (
int pointer = -1,
int margin = 0);
00294
void ScrollToLine(
int line,
int col,
int margin = 0);
00298
void SelectText(
int start,
int end);
00302
void UnselectText();
00309
bool AddMarkIcon(
VDKPixbuf* image,
const char * icon_key,
bool overwrite =
true);
00315
void AddLineMark(
int line,
const char* icon_key);
00321
void RemoveLineMark(
int line,
const char* icon_key);
00326
void RemoveLineMarks(
int line);
00330
void RemoveAllLineMarks();
00331
00332
00333
00334
void SetSyntax(
bool f);
00335
void SetPointer(
int p);
00336
int GetPointer();
00337
void SetLine(
int r);
00338
int GetLine();
00339
void SetTabStop(
int r);
00340
int GetTabStop();
00341
void SetColumn(
int r);
00342
int GetColumn();
00343
unsigned int GetLength();
00344
bool GetEditable();
00345
void SetEditable(
bool f);
00346
void SetShowLineNumbers(
bool f);
00347
bool GetShowLineNumbers(
void);
00348
int GetFirstVisibleLine();
00349
int GetLastVisibleLine();
00350
bool GetChanged();
00351
void SetChanged(
bool f);
00352
void SetMaxUndo(
int );
00353 };
00354
00355
00356
00357
class Tipwin:
public VDKForm
00358 {
00359
VDKLabel* label;
00360
char* tip;
00361
public:
00362 Tipwin(
VDKForm* owner,
char* tip):
00363
VDKForm(owner,NULL,v_box,GTK_WINDOW_POPUP),tip(tip)
00364 {}
00365 ~Tipwin() {}
00366
void Setup(
void);
00367
00368 };
00369
#endif