File: gtkextext.h

package info (click to toggle)
diasce 1.0.5-1.1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,964 kB
  • ctags: 1,732
  • sloc: ansic: 26,805; sh: 2,999; makefile: 399; yacc: 318
file content (418 lines) | stat: -rw-r--r-- 13,777 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
/*  GtkExText	
 * This is my first GtkWidget
 * GtkExText is Copyright (C) 1999 by:
 * Mikael Hermansson <mikeh@bahnhof.se>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef GTK_EXTEXT_H__
#define GTK_EXTEXT_H__
#ifdef __cplusplus
extern "C" {
#endif

#include <gdk/gdk.h>
//#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtkadjustment.h>
#include <gtk/gtkeditable.h>

#include <sys/types.h>

#ifdef _NETBSD
	#include "gnu-regex.h"
#endif
#ifdef _FREEBSD
	#include <gnuregex.h>
#endif
#ifdef _LINUX
	#include <regex.h>
#endif
 
#define GTK_TYPE_EXTEXT                  (gtk_extext_get_type ())
#define GTK_EXTEXT(obj)                  (GTK_CHECK_CAST ((obj), GTK_TYPE_EXTEXT, GtkExText))
#define GTK_EXTEXT_CLASS(klass)          (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_EXTEXT, GtkExTextClass))
#define GTK_IS_EXTEXT(obj)               (GTK_CHECK_TYPE ((obj), GTK_TYPE_EXTEXT))
#define GTK_IS_EXTEXT_CLASS(klass)       (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_EXTEXT))

#define LINE_DATA_LENGTH(cur) cur->lineptr->length
#define LINE_DATA_USERDATA(cur) cur->lineptr->user_data
#define LINE_DATA_WIDTH(cur) cur->lineptr->width
#define LINE_DATA_HEIGHT(cur) cur->lineptr->height


#define PROPERTY_INSERT 0
#define PROPERTY_REMOVEALL 1
#define PROPERTY_MERGE 2

typedef struct _GtkExText GtkExText;
typedef struct _GtkExTextClass GtkExTextClass;

typedef struct _GtkExTextMatch {
  gint startpos;
  gint endpos;
}GtkExTextMatch;

enum {	
  EXTEXT_UNDO_INSERT,	
  EXTEXT_UNDO_REMOVE
};	

typedef struct _GtkExTextUndoEntry
{
   gboolean insert;
   guint start;
   guint length;
   gchar *text;
}GtkExTextUndoEntry;

/* GtkExTextStyle Setup font and bg/fg colors */
/* to use in textdocument */
#define GTK_EXTEXT_STYLE_BG 0x0001
#define GTK_EXTEXT_STYLE_UNDER 0x0002
#define GTK_EXTEXT_STYLE_STRIKE 0x0004
typedef struct _GtkExTextStyle
{
	GdkFont *font;				/* font */
	GdkColor fg_color;    /* bg_color */
	GdkColor bg_color;   /* fg_color */
    gchar key[32];
      guint16 flags;
	gint rbearing;
	gint lbearing;
	gint ascent;
	gint descent;
}GtkExTextStyle;

/* Line struct */
/* holds all lines */
/* all lines ends with "\n" character */
typedef struct _Lines /* 20 bytes */
{
  guint16 length;
  guint16 flags;      /* unused at the moment */
  guint16 width;    
  guint16 height;
//   GdkPixbuf *pixbuf; /* pixmap/bitmap is ugly mush better use gdkpixbuf :-) this way we also saves 4 bytes in this structure :-) */
  gpointer user_data;   /* possible for the user to set */
  struct _Lines *next;
  struct _Lines *prev;
}Lines;

/* Property is used  to set a property mark in the textdoc*/
typedef struct _GtkExTextProperty
{
   /* startpos from begining of text */ 
   guint startpos;
   /* endpos from begining of text */
   guint endpos;
  /*User data */
  gpointer user_data;            
	/* private user should NOT change this */
  struct _GtkExTextProperty *next;
  struct _GtkExTextProperty *prev;
 /* pointer to GtkExTextStyle */
  GtkExTextStyle *style;
}GtkExTextProperty;

/* this is a wrapped and should be public for the user */
/* this calculates startpos and endpos */
/* and the return it to the user */
/* structure is READONLY for the user */
typedef struct _GtkExTextLineData
{
  /* in text startpos */
  gint startpos;
  /* in text endpos */
  gint endpos;
  /* the line number */
  gint line_number;
  /* first line property nearest backward  */
  GtkExTextProperty *property_first;
  /* the real lineptr */
  Lines *lineptr;
}GtkExTextLineData;

typedef struct _extext_cursor
{
  gboolean hide;
  gint offsetx;
  gint x;
  gint y;
  gint w;
  gint h;
}extext_cursor;

struct _GtkExText 
{
  GtkEditable editable;

  GdkWindow *text_area;
  GdkGC *gc;	
  GdkGC *bg_gc;	
  /* The default font */
  GdkFont *font;
  /* colors used for selection on focus/no focus */
  GdkColor scolor;
  GdkColor pcolor;

  GtkAdjustment *vadj;
  GtkAdjustment *hadj;
  GdkCursor *ecursor;
  GdkCursor *acursor;

  guint timer;
  guint button;

	/* double buffering  */
  GdkDrawable *draw_area;

  gint freeze_count;

  /* size is how mush allocated text memory */
  gint size;

  /* length is how mush used text memory */
  gint length;
	
  gint gap_len;
  gint part1len;
  guchar *text;
  guchar *part2text;

  guint text_insert_delete_flag : 1;
  guint undo_flag : 1;

  /* this is set if widget is readonly */
  guint read_only : 1;

  /* line cache coding see source for more info */	

  Lines *line_start; /* the line first */
  Lines *line_end;  /* the line cache last */
  Lines *line_ptr;  /* current position  */

  gint line_count;

  /* first visible line */		
  /* number of visible lines  scroll_line_start + scroll_line_count = last visible line*/
  gint scroll_line_count;

  GtkExTextLineData *scroll_line_start;
  gint line_number;        /* current line number */
  gint column_number;  /* current column number */
  //gint lci_bak;

  extext_cursor cursor;
  gint cursor_timer;
  guint cursor_blink : 1;
	
  /* Undo coding */
  /* FIXED/Replaced by Chicane */
  gint undo_max;
  GList *undo_redo;
  guint undo_level;

  /* Number drawing stuffs */
  guint draw_numbers : 1;
  gint number_width;

  /* Pixmap drawing stuffs */
  guint draw_pixbufs : 1;
  gint pixbuf_max_width;
	gint pixbuf_max_height;	

  /* number_width + pixmap_width */
  gint gutter_width;  

  guint select_line : 1;
  guint draw_cursor : 1;
  guint full_selection : 1;
  guint pseudo_select : 1;
  gint pseudo_start;
  gint pseudo_end;
  guint use_spaces :1;
  guint tab_stops : 1;
  gint default_tab_width;

  /* property handling */
   gint property_count;

  GtkWidget *margin_popupmenu;
  GtkWidget *text_popupmenu;

  GtkExTextProperty  *property_start;	
  GtkExTextProperty  *property_end;	
  GtkExTextProperty *property_current;
 
  /* hash list with font/color styles */
 GHashTable *hash_styles;
};

struct _GtkExTextClass
{
  GtkEditableClass parent_class;
  /* SIGNAL CALLBACKS */
  void (*property_destroy)(GtkExText *text,GtkExTextProperty *prop);
  gint (*property_text_insert)(GtkExText *text,GtkExTextProperty *prop,gint startpos,gint endpos);
  gint (*property_text_remove)(GtkExText *text,GtkExTextProperty *prop,gint startpos,gint endpos);
  gint (*undo_changed)(GtkExText *text);	

  void  (*set_scroll_adjustments) (GtkExText       *text,
				   GtkAdjustment  *hadjustment,
				   GtkAdjustment  *vadjustment);


  /* Is called everytime cursor comes to a new property */
  void (*property_mark)(GtkExText *text,GtkExTextProperty *prop);

  /* line_[insert/remove] signal is sent when insert/delete a line */
  /* Use for example when you need to update line marks/breakpoints or similar */ 
  gint (*line_insert)(GtkExText *text, gint line_number);
  gint (*line_remove)(GtkExText *text, gint line_number);
  void (*margin_clicked)(GtkExText *text,GdkEventButton *ev,gint line);

	/* line_funcs */
  GtkExTextLineData *(*line_by_offset)(GtkExText *text,gint y, gint *newoffsety);
  gint (*column_by_offset)(GtkExText *text,GtkExTextLineData *data,gint x, gint *newoffsetx);
};


/* GtkWidget API */
GtkType gtk_extext_get_type();
GtkWidget *gtk_extext_new();
void gtk_extext_set_adjustments(GtkExText *text,GtkAdjustment *hadj,GtkAdjustment *vadj);

/* text API */

void gtk_extext_insert(GtkExText *text,const gchar *chars,gint len);
void gtk_extext_insert_with_style(GtkExText *text,
				const char *chars,gint len, gchar *stylekey, gpointer userdata);

gint gtk_extext_get_length(GtkExText *text);

/* Editable class Wrapper API */
#define gtk_extext_backward_delete(a,b) gtk_editable_delete_text(GTK_EDITABLE(a),gtk_editable_get_position(GTK_EDITABLE(a))-b,b)
#define gtk_extext_forward_delete(a,b) gtk_editable_delete_text(GTK_EDITABLE(a),gtk_editable_get_position(GTK_EDITABLE(a)),b)
#define gtk_extext_get_text(a,b,c)	gtk_editable_get_chars(GTK_EDITABLE(a),b,c);
#define gtk_extext_set_point(a,b)	gtk_editable_set_position(GTK_EDITABLE(a),b);
#define gtk_extext_get_point(a)	gtk_editable_get_position(GTK_EDITABLE(a));

guchar gtk_extext_get_char_at_pos(GtkExText *text,gint pos);

/* Line and column API */

void gtk_extext_set_popup_menu(GtkExText *text,GtkWidget *widget,GtkWidget *marginmenu);
GtkExTextLineData *gtk_extext_get_line_data(GtkExText *text,gint line,GtkExTextLineData *old);
gboolean gtk_extext_get_line_data_prev(GtkExText *text, GtkExTextLineData *cur);
gboolean gtk_extext_get_line_data_next(GtkExText *text, GtkExTextLineData *cur);

gint gtk_extext_set_line(GtkExText *text,gint pos);
gint gtk_extext_get_line(GtkExText *text);

GtkExTextLineData *gtk_extext_get_first_visible_line(GtkExText *text);
GtkExTextLineData *gtk_extext_get_line_by_char_pos(GtkExText *text,gint pos,GtkExTextLineData *data);
GtkExTextLineData *gtk_extext_get_line_by_offset(GtkExText *text,gint y,gint *newoffsety);

gpointer gtk_extext_get_line_userdata(GtkExText *text,gint line);
void gtk_extext_set_line_userdata(GtkExText *text,gint line,gpointer userdata);
//void gtk_extext_set_line_pixbuf(GtkExText *text, gint line, GdkPixbuf *pixbuf);
//GdkPixbuf *gtk_extext_get_line_pixbuf(GtkExText *text, gint line);

gint gtk_extext_set_column(GtkExText *text,gint col);
gint gtk_extext_get_column(GtkExText *text);
gint gtk_extext_get_abs_column(GtkExText *text, gint pos);
gint gtk_extext_get_next_tab_stop(GtkExText *text, gint pos);
gint gtk_extext_get_column_by_offset(GtkExText *text,GtkExTextLineData *linedataptr,gint x,gint *newx);

/* Undo funcs */
gint gtk_extext_undo_get_max(GtkExText *text);
gboolean gtk_extext_undo_set_max(GtkExText *text, gint max);
gboolean gtk_extext_undo_is_empty(GtkExText *text);
gboolean gtk_extext_redo_is_empty(GtkExText *text);
void gtk_extext_undo_clear_all(GtkExText *text);
gboolean gtk_extext_undo(GtkExText *text);
gboolean gtk_extext_redo(GtkExText *text);

/* Style functions */
GtkExTextStyle *gtk_extext_style_insert(GtkExText *text,gchar *stylename,GdkFont *font,GdkColor *fg,GdkColor *bg, guint16 flags);
GtkExTextStyle *gtk_extext_style_get(GtkExText *text,gchar *key);
void gtk_extext_style_remove(GtkExText *textclass,gchar *key);
void gtk_extext_style_set(GtkWidget *widget,GtkStyle *old);

/* Property functions */
GtkExTextProperty *gtk_extext_property_insert(GtkExText *text,gchar*key,gint startpos, gint endpos,gpointer data,gint typ,GtkExTextProperty *prev);
GtkExTextProperty *gtk_extext_property_remove(GtkExText *text,GtkExTextProperty *remove);
GtkExTextProperty *gtk_extext_property_get_at_pos(GtkExText *text,gint pos,GtkExTextProperty *cur);
GtkExTextProperty *gtk_extext_property_move_all(GtkExText *text,gint pos, gint diff,GtkExTextProperty *cur);
GtkExTextProperty *gtk_extext_property_remove_all(GtkExText *text,gint start, gint end,GtkExTextProperty *cur);
GtkExTextProperty *gtk_extext_property_nearest_forward(GtkExText *text,gint pos,GtkExTextProperty *cur);
GtkExTextProperty *gtk_extext_property_nearest_backward(GtkExText *text,gint pos,GtkExTextProperty *cur);
GtkExTextProperty *gtk_extext_property_get_current(GtkExText *text);

/* utils returns true if found and the startpos and endpos will be updated */
/* you must initiate the startpos with some value */
/* for example startpos=gtk_editable_get_current_position() */

gboolean gtk_extext_get_current_word(GtkExText *text,gint *startpos,gint *endpos);
gboolean gtk_extext_get_next_word(GtkExText *text,gint *startpos,gint *endpos);
gboolean gtk_extext_get_previous_word(GtkExText *text,gint *startpos,gint *endpos);

void gtk_extext_freeze(GtkExText *text);
void gtk_extext_thaw(GtkExText *text);

void gtk_extext_set_pseudo_select(GtkExText *text, gint start, gint end);

void gtk_extext_set_use_spaces(GtkExText *text,gboolean spaces);
void gtk_extext_set_draw_numbers(GtkExText *text, gboolean draw);
void gtk_extext_set_draw_pixbufs(GtkExText *text, gboolean draw);
void gtk_extext_set_pixbuf_size(GtkExText *text, gint size);

void gtk_extext_set_select_line(GtkExText *text, gboolean select);
void gtk_extext_set_cursor_blink(GtkExText *text, gboolean blink);
void gtk_extext_set_draw_cursor(GtkExText *text, gboolean draw);
void gtk_extext_set_full_selection(GtkExText *text, gboolean full);

gint gtk_extext_get_tab_width(GtkExText *text);
void gtk_extext_set_tab_width(GtkExText *text, gint width);
void gtk_extext_set_use_tab_stops(GtkExText *text, gboolean tab_stops);

void gtk_extext_set_position(GtkEditable *editable,gint pos);
gint gtk_extext_get_position(GtkEditable *editable);
gboolean gtk_extext_get_editable(GtkExText *text);

GtkType gtk_extext_get_type(void);

#define GTK_EXTEXT_INDEX(extext,index)	(index < extext->part1len ? \
                                        extext->text[index] : extext->part2text[index])

/* search routines */
gboolean gtk_extext_search(GtkExText *text,gchar *search,gint pos,gboolean iscase,gboolean forward,GtkExTextMatch *m);

/* Regex functions */
typedef struct _Regex
{
  struct re_pattern_buffer buf;
  struct re_registers reg;
}Regex;

gint gtk_extext_regex_search(GtkExText *text,gint start,Regex *regex,gboolean forward,GtkExTextMatch *m);
gint gtk_extext_regex_match(GtkExText *text,gint pos,Regex *regex);

#ifdef __cplusplus
}
#endif

#endif