GtkExText algoritm



Here is how i have done it.

I have tree structures:

struct GtkExTextStyle 
{
  GdkFont *font;
  GdkColor *bg;
  GdkColor *fg;
};

struct LineCache 
{
  gint len; /* line length */
  gpointer user_data;

  LineCache *next;
  LineCache *prev;
};

struct GtkExTextProperty
{
  gint startpos;
  gint endpos;
  
   gpointer user_data;
  GtkExTextStyle *style;
  
  GtkExTextProperty *next;
  GtkExTextProperty *prev;
};

struct GtkExTextLineData
{
   gint line_number;
   gint startpos;
   gint endpos;

   GtkExText *lineptr;
   GtkExTextProperty *property_first;
   gint height;
   ......
}

How this works:

there is a GtkExTextLineData structure in the widget with the first 
visible line:

GTK_EXTEXT(widget)->scroll_line_start;

gtk_extext_get_line_data 
calculates the correct propertys/line position and so on.
and takes this parameters:

gtk_extext_get_line_data
(GtkExText *text,gint line_number,GtkExTextLineData *cur);  

pass NULL as cur  iterates from start of text 
if line_number < (text->line_count/2) else it iterates from end of text.

if pass an already created GtkExTextLineData structure 
(for example text->scroll_line_start) it will iterate from that pos.

*_get_line_data will return a newly created structure if cur was 
NULL/text->scroll_line_start  else it will return a already created 
structure.

this must be g_free:d after use and should NOT be saved.
because its probadly broken after a new insert/delete of text.

Example:

myfunc()
{
 GtkExTextLineData *lp=text->scroll_line_start; 

 for (gint i=lp->line_number; i <= text->line_count ; i++)
 {
   lp=gtk_extext_get_line_data(text,i,lp); /* first call creates a new 
struct */

   g_print("line_number %d property_first %X line length %d\n",
	lp->line_number,lp->property_first,LINE_DATA_LEN(lp));
 }
 g_free(lp); /* free the struct */
}

update propertys:
-----------------

property_move_all(GtkExText *prop, gint frompos, gint diff, 
GtkExTextProperty *prev)

[+-]diff how many chars to move property fromcharpos 
forward/backward(+-).

property_remove_all(GtkExText *prop,gint startpos,gint 
endpos,GtkExTextProperty *prev)

property_get_at_pos(GtkExText *prop,gint pos,GtkExTextProperty *prev)

All gtk_extext_property_* funcs returns previous prop 
if you want to iterate again. This should NOT be g_free:d.

for more info see my sourcecode at:

http://www.bahnhof.se/~mikeh/linux_software.html
http://www.bahnhof.se/~mikeh/files/gtkextext/

Greats

MikeH

---

Check out my homepage at (under heavy reconstruction): 
http://www.bahnhof.se/~mikeh	

Email: mikeh@bahnhof.se
international Phone 46-44-126995
Sweden Phone: 044-126995
ICQ: Error fix later



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]