Re: popt



-> http://www.gnome.org/mailing-lists/archives/gtk-devel-list/2000-January/0195.shtml

	Thank you.

--Derek

P.S.> I've written my text-widget buffer object, and am just now starting
on the view design.  I still have a few bugs in the buffer to fix, though;
it's currently at about 4200 lines of code, and I'm pondering re-writing a
couple of the functions.  I've attached the .h file, which shows the
(fully-documented!) API, and how my Styles work, just in case anybody's
curious...
#ifndef GTK_ETEXT_BUFFER_H
#define GTK_ETEXT_BUFFER_H

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#include <gtk/gtk.h>
#include "gdkbuffergap.h"
#include "gtkmarshal-extensions.h"

/* Type system macros: */
#define GTK_TYPE_ETEXT_BUFFER (gtk_etext_buffer_get_type())
#define GTK_ETEXT_BUFFER(obj)  (GTK_CHECK_CAST ((obj), GTK_TYPE_ETEXT_BUFFER, GtkEtextBuffer))
#define GTK_ETEXT_BUFFER_CLASS(klass)  (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_ETEXT_BUFFER, GtkEtextBufferClass))
#define GTK_IS_ETEXT_BUFFER(obj)  (GTK_CHECK_TYPE ((obj), GTK_TYPE_ETEXT_BUFFER))
#define GTK_IS_ETEXT_BUFFER_CLASS(klass)  (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_ETEXT_BUFFER))


/* First, the GtkEtextStyle structure: */
typedef struct _GtkEtextStyle GtkEtextStyle;

struct _GtkEtextStyle {
  
  GdkGCValues		gc_values;
  GdkGCValuesMask	gc_values_mask;
  
  gboolean		underline;   /* Simple underline */
  GdkColor		underline_color;

  gboolean		underline2;  /* squigly underline? */
  GdkColor		underline2_color;
  
  gboolean		strikethrough;
  GdkColor		strikethrough_color;
  
  gpointer		user_data;
  /* FIXME: What am I missing here?  Anything...? */  
};

/**
 * gtk_etext_style_new:
 * @gc_values: The GdkGCValues as you would like them applied to the text.
 * @gc_values_mask: Bitmask of which values you actually want the viewer to pay 
 * attention to when rendering the text.
 * @underline: Whether or not you want the text to be underlined.
 * @underline_color: The color you want the underline to be.
 * @underline2: Whether or not you want the text to have the secondary underline.
 * @underline2_color: The color you want the secondary underline style to be.
 * @strikethrough: Whether or not you want the text to have a line through it.
 * @strikethrough:_color: The color you want the strikethrough to be.
 * @user_data: A #gpointer to hold any custom information you wish to track
 * 
 * This function creates a new GtkEtextStyle.  Any pixmaps or fonts pointed to by
 * @gc_values (specifically, @gc_values.font, @gc_values.tile, @gc_values.stipple,
 * and @gc_values.clip_mask) will have their ref_count increased by one, so you can
 * unref that font and those pixmaps after calling this function and
 * calling gtk_etext_style_destroy() will unref them later (and thus destroy them,
 * unless you are using them in another style somewhere).  Note: it will only
 * ref the resources if the flag is also set to use it: i.e., 
 * GDK_GC_FONT, GDK_GC_TILE, GDK_GC_STIPPLE, or GDK_GC_CLIP_MASK must be set
 * before the corresponding font or tile will be reffed.
 * Preconditions: none.
 * Postconditions: The memory for the GtkEtextStyle is allocated, and if the 
 * mask specifies a #GdkFont or #GdkPixmap, those are 'ref'erenced once.
 *
 * Returns: A pointer to the newly-allocated and filled-in #GtkEtextStyle.
 */
GtkEtextStyle *gtk_etext_style_new(	GdkGCValues gc_values,
					GdkGCValuesMask gc_values_mask,
					gboolean underline,
					GdkColor underline_color,
					gboolean underline2,
					GdkColor underline2_color,
					gboolean strikethrough,
					GdkColor strikethrough_color,
					gpointer user_data);

/**
 * gtk_etext_style_free:
 * @style: The #GtkEtextStyle you wish to free.
 * 
 * This frees the style, and unrefs any #GdkFonts or #GdkColors used.
 * Preconditions: @style should point to a valid #GtkEtextStyle.  Any data 
 * pointed to by @style->user_data should be freed ahead of time.
 * Postconditions: @style's memory is freed, and if the @style's gc_values_mask 
 * has GDK_GC_FONT, GDK_GC_TILE, GDK_GC_STIPPLE, GDK_GC_CLIP_MASK set the 
 * appropriate _unref() function is called on the corresponding pointer.
 * 
 * Returns: nothing.
 */
void gtk_etext_style_free(GtkEtextStyle *dead_style);


/* Next, the GtkEtextLineMarkType (for 'bookmarking' lines). */

/* These should become more descriptive in the future, i.e. 
   names like "BookMark", "BreakPoint", "EndLine", or whatever */
typedef enum {
  type1		= 1<<0,    /* "Bookmark" graphic? */
  type2		= 1<<1,    /* "Breakpoint" graphic (stop sign)? */
  type3		= 1<<2     /* "Warning" graphic (yield sign)? */
  type4		= 1<<3     /* "Error" graphic (exclamation point)? */
} GtkEtextLineMarkType;


typedef struct _GtkEtextBuffer GtkEtextBuffer;
typedef struct _GtkEtextBufferClass GtkEtextBufferClass;

struct _GtkEtextBuffer {
  GtkObject parent_instance;
  
  /* These position numbers start with 0 (zero) */
  guint current_pos;		/* The current cursor/insertion point position */
  guint current_line_num;	/* The line number ('\n') we're currently on */
  guint column_num;		/* The current "column" we're on. */

  guint	line_count;		/* Number of '\n's in the buffer */

  GdkBufferGap *bufgap;	/* The gapped text buffer used to hold the chars */
  GList *lines;		/* The linked list of GtkEtextLines (per '\n') */

  /* FIXME: I don't think this is used.  Check and then delete.  May be
     necessary for the "nearest third" optimization... */
  GList *lines_end;	/* The end of the list, tracked for faster searches */
  
  GtkEtextStyle *plain_style;	/* The malloced "default" style for text */
  GtkEtextStyle *current_style;	/* The style applied to the current_pos */
  
  GList *current_line_node;	/* A  pointer to the current "Line" node */

  /* FIXME: I think I could use GSList for these.  Check and make the mods. */
  GList *current_style_tag_node;/* An internal pointer to the current "StyleTag"
                                    node.  These are for efficiency only */

  guint use_wchar:1;		/* FIXME: We'll want this to work with GUChar,
  				    so we may want to replace this boolean with
				    something a little more flexible. Anyway, 
				    I don't really understand this... --dereks */
};


struct _GtkEtextBufferClass {
  GtkObject parent_class;
  /* Signal handlers: */

  /* An application may only be concerned if the text changed,
     and may not care about the styles changing.  A syntax-highlighted
     editor (where highlighting is done in the background) is one such
     example.  Therefor, we split the "changed" signal into the
     "text_changed", "styles_changed", and "line_mark_changed" signals. */
  void (* text_changed)           (GtkEtextBuffer *buf);

  void (* style_changed)          (GtkEtextBuffer *buf);

  void (* line_mark_changed)	  (GtkEtextBuffer *buf);


  gint (* insert)       (GtkEtextBuffer *buf,
                         const gchar    *text,
                         gint            length);

  guint (* delete)       (GtkEtextBuffer *buf,
                         guint           num_chars,
                         gboolean        forward); 

  void (* set_position) (GtkEtextBuffer *buf, 
                             guint         position);

  /* Note that SET_COORDS is a separate signal from SET_POSITION.  If
     you are monitoring one, you'll probably want to monitor both.  */
  guint (* set_coords) (GtkEtextBuffer *buf, 
                             guint         line_num,
			     gint	   column_num);

  gint  (* set_text_style) (GtkEtextBuffer *buf,
                                guint              start_pos,
                                guint              end_pos,
				GtkEtextStyle	  *style);
  
  void (* set_line_mark)               (GtkEtextBuffer *buf,
					guint line_number,
					GtkEtextLineMarkType mark_type,
					gboolean mark_value);

  gboolean (* toggle_line_mark)        (GtkEtextBuffer *buf,
					guint line_number,
					GtkEtextLineMarkType mark_type);

  /* Bindings: */
  /* none.  See the GtkEtextView for bindings. */

  /* Virtual functions (not signals) */
  gchar* (* get_chars)            (GtkEtextBuffer *buf,
				  guint start_pos,
				  guint end_pos);

  GtkEtextStyle* (* get_text_style)  (GtkEtextBuffer    *buf,
                                      guint            position);

  guint (* get_length)      (GtkEtextBuffer    *buf);

  guint (* get_position)      (GtkEtextBuffer    *buf);

  gboolean (* get_line_mark)           (GtkEtextBuffer *buf,
					guint line_number,
					GtkEtextLineMarkType mark_type);

  guint (* get_text_style_length)  (GtkEtextBuffer *buf,
					gint              position);
					
  gint (* get_next_line_mark)          (GtkEtextBuffer *buf,
					guint line_number,
					GtkEtextLineMarkType mark_type,
					gboolean forward);

  guint (* get_text_style_tag_position) (GtkEtextBuffer *buf,
					gint              position);  

  gint (* find)				 (GtkEtextBuffer *buf,
				         const gchar *search_text,
					 guint start_pos,
					 gboolean forward);

  guint (* get_line_number)   (GtkEtextBuffer  *buf);
  guint (* get_column_number)   (GtkEtextBuffer  *buf);



};

/**
 * gtk_etext_buffer_insert:
 * @buf: The #GtkEtextBuffer to insert text into
 * @new_text: The text you want to insert (multibyte format--?)
 * @new_text_length: the number of bytes comprising @new_text
 * 
 * Inserts text into the buffer.
 * Preconditions: @buf should be initialized and non-NULL.
 * Postconditions: @new_text is inserted into the buffer.  If necessary,
 * memory may be malloced to make room in @buf.  Also, the insertion point
 * will be left right after the newly inserted text--i.e., it will be
 * at the returned value + new_text_length.
 * 
 * Returns: The position the text was inserted at, or <0 if an error occurred.
 */
gint       gtk_etext_buffer_insert       (GtkEtextBuffer  *buf,
                                          const gchar     *new_text,
                                          gint             new_text_length);

/**
 * gtk_etext_buffer_insert_with_style:
 * @buf: The #GtkEtextBuffer to insert text into
 * @new_text: The text you want to insert (multibyte format--?)
 * @new_text_length: the number of bytes comprising @new_text
 * @style: The #GtkEtextStyle you wish applied to the text
 * 
 * This is a convenience function that inserts text with the given style.
 * Preconditions: @buf and @style should be valid and non-NULL.
 * Postconditions: @new_text is inserted into the buffer.  If necessary,
 * memory may be malloced to make room in @buf.  Also, the insertion point
 * will be left right after the newly inserted text--i.e., it will be
 * at the returned value + new_text_length.
 * 
 * Returns: The position the text was inserted at, or <0 if an error occurred.
 */
gint       gtk_etext_buffer_insert_with_style   (GtkEtextBuffer  *buf,
                                          const gchar     *new_text,
                                          gint             new_text_length,
  					  GtkEtextStyle	  *style);

/**
 * gtk_etext_buffer_insert_at_position:
 * @buf: The #GtkEtextBuffer to insert text into
 * @new_text: The text you want to insert (multibyte format--?)
 * @new_text_length: the number of bytes comprising @new_text
 * @position: The position you wish to insert the text at.  If negative,
 * the text will be appended to the end of the buffer.
 * 
 * This is a convenience function that inserts text with the given style.
 * Preconditions: @buf and @style should be valid and non-NULL.
 * Postconditions: @new_text is inserted into the buffer.  If necessary,
 * memory may be malloced to make room in @buf.  Also, the insertion point
 * will be left right after the newly inserted text--i.e., it will be
 * at the returned value + new_text_length.
 * 
 * Returns: The actual position the text was inserted at, or <0 if an error
 * occurred.
 */
gint       gtk_etext_buffer_insert_at_position  (GtkEtextBuffer  *buf,
                                          const gchar     *new_text,
                                          gint             new_text_length,
                                          gint             position);

/**
 * gtk_etext_buffer_insert_at_position_with_style:
 * @buf: The #GtkEtextBuffer to insert text into
 * @new_text: The text to add
 * @new_text_length: The number of bytes in the text you're adding
 * @position: Specifies the position to insert the text (starting at zero).
 * If position is negative, then the text will be appended to the end of
 * the buffer.
 * @style: The #GtkEtextStyle you wish the inserted text to have.  If this is
 *  NULL, the existing (current) style will simply (and silently) be used.
 * 
 * This is a convenience function that will insert the text at the given position 
 * with the specified style.
 * Preconditions: @buf and @style should be valid and non-NULL.
 * Postconditions: The text is inserted at the given position.  If necessary, 
 * memory may be malloced to make room in @buf.  Also, the insertion point
 * will be left right after the newly inserted text--i.e., it will be
 * at the returned value + new_text_length.
 * 
 * Returns: The actual position the text was inserted at, or <0 if an error
 * occurred.
 */
gint       gtk_etext_buffer_insert_at_position_with_style 
                                       (GtkEtextBuffer *buf,
                                        const gchar      *new_text,
                                        gint             new_text_length,
                                        gint             position,
					GtkEtextStyle	 *style);

/**
 * gtk_etext_buffer_delete:
 * @buf: The #GtkEtextBuffer to delete characters from
 * @num_chars: The number of characters you wish to delete
 * @forward: if TRUE, @num_chars to the right of the current position will be
 * deleted.  If FALSE, @num_chars to the left of the current position will be
 * deleted.
 * 
 * Deletes text from the current insertion point.  It can delete
 * forward (i.e, enduser hits the DELETE key) or backward (i.e., enduser hits the
 * BACKSPACE key).  If you try to delete more characters than are physically
 * possible (like you delete 10 chars in a buffer that has only 5 chars, or you
 * delete 10 chars "forward" when the gap is as the very end of the buffer) then 
 * it will silently delete as many characters as possible.
 * Preconditions: @buf should be valid and non-NULL
 * Postconditions: The text is deleted from the buffer.  If forward is FALSE,
 * the insertion point will move backward num_chars, otherwise it will stay in
 * the same place.
 * 
 * Returns: The actual number of characters deleted, or <0 if an error occurred.
 */
gint           gtk_etext_buffer_delete (GtkEtextBuffer *buf,
                                        guint             num_chars,
                                        gboolean          forward);


/**
 * gtk_etext_buffer_delete_at_position:
 * @buf: The #GtkEtextBuffer to delete characters from
 * @num_chars: The number of characters you wish to delete
 * @forward: if TRUE, @num_chars to the right of the current position will be
 * deleted.  If FALSE, @num_chars to the left of the current position will be
 * deleted.
 * @position: The position to delete characters from.
 * 
 * Convenience function.  Works just like gtk_etext_buffer_delete() but moves
 * the cursor to @position first.
 * Preconditions: @buf should be valid and non-NULL
 * Postconditions: The text is deleted from the buffer.  If forward is FALSE,
 * the insertion point will move backward num_chars from @position, 
 * otherwise it will stay at @position.
 * 
 * Returns: The actual number of characters deleted, or <0 if an error occurred.
 */
gint           gtk_etext_buffer_delete_at_position (GtkEtextBuffer *buf,
                                        guint             num_chars,
                                        gboolean          forward,
					gint		  position);


/**
 * gtk_etext_buffer_set_position:
 * @buf: The #GtkEtextBuffer whose position you wish to set.
 * @position: The position to move the insertion point to.
 * 
 * Sets the insertion point (aka cursor) to the given position.  If @position
 * is negative, it moves the cursor the end of the buffer.  If @position is
 * greater than the size of the buffer, it will be moved to the end of the
 * buffer.
 * 
 * Preconditions: @buf should be valid and non-NULL.
 * Postconditions: The cursor is at the new position. Future 
 * gtk_etext_buffer_delete() and gtk_etext_buffer_insert() operations will 
 * take place at that position.
 * 
 * Returns: The actual new position of the cursor, or <0 if an error occurred.
 */
gint       gtk_etext_buffer_set_position   (GtkEtextBuffer  *buf,
                                            gint             position);

/**
 * gtk_etext_buffer_get_position:
 * @buf: The #GtkEtextBuffer whose position you wish to get.
 * 
 * Tells you the position of the insertion point (aka cursor) in the buffer.
 * The cursor is where gtk_etext_buffer_insert() and gtk_etext_buffer_delete()
 * will make their changes.
 * Preconditions: @buf should be valid and non-NULL.
 * Postconditions: none.
 * 
 * Returns: The position of the cursor (aka insertion point), or <0 if an
 * error occurred.
 */
gint       gtk_etext_buffer_get_position   (GtkEtextBuffer  *buf);


/**
 * gtk_etext_buffer_set_coords:
 * @buf: The #GtkEtextBuffer whose line and column position you wish to set.
 * @line_number: The line number you wish to move to.  If negative, it moves
 * to the last line in the buffer.  If greater than the total number of lines,
 * it moves to the last line in the buffer.
 * @column_number: The number of characters (from the beginning of the line)
 * to place the insertion point at.  If column_number is invalid (i.e., the line
 * only has 3 characters but you specify @column_number to be 10) or negative then
 * the cursor will be placed at the end of the line.
 * 
 * This function provides another way to move the insertion point.  The first
 * Line in the buffer is line zero (0), and the leftmost column is column
 * zero (0).
 * Preconditions: @buf should be valid and non-NULL.
 * Postconditions: The insertion point is moved to the appropriate position.
 * 
 * Returns: the new position of the cursor (aka insertion point), or <0 if
 * an error occurred.
 */
gint        gtk_etext_buffer_set_coords   (GtkEtextBuffer  *buf,
						gint line_number,
						gint column_number);

/**
 * gtk_etext_buffer_get_line_number:
 * @buf: The #GtkEtextBuffer whose line number you wish to get.
 * 
 * This tells you what line number ('\n' line) the cursor (aka insertion point)
 *  is currently at.
 * Preconditions: @buf should be valid and non-NULL.
 * Postconditions: none.
 * 
 * Returns: The current line number, or <0 if an error occurred.
 */
gint        gtk_etext_buffer_get_line_number   (GtkEtextBuffer  *buf);


/**
 * gtk_etext_buffer_get_column_number:
 * @buf: The #GtkEtextBuffer whose column number you wish to get.
 * 
 * This tells you what column number the cursor (aka insertion point)
 *  is currently at.  It's really just the number of characters to the nearest
 *  '\n' back (or if we're on the first line, to the beginning of the buffer).
 *  reconditions: @buf should be valid and non-NULL.
 * Postconditions: none.
 * 
 * Returns: The current column number, or <0 if an error occurred.
 */
gint       gtk_etext_buffer_get_column_number   (GtkEtextBuffer  *buf);

/**
 * gtk_etext_buffer_set_text_style:
 * @buf: The #GtkEtextBuffer whose text you wish to set a style for.
 * @start_pos: The starting position.
 * @end_pos: The ending position.
 * @style: The #GtkEtextStyle you want to set the text to.
 * 
 * This sets the style on the given region.  The characters modified are those 
 * characters at positions from start_pos up to, but not including
 * end_pos. If end_pos is negative, then the the characters modified will be 
 * those characters from start_pos to the end of the text.
 * Preconditions: @buf, @style should be valid and non-NULL.
 * Postconditions: Text is set to given @style.
 * 
 * Returns: The actual number of chars tagged, or <0 if an error occurred.
 */
gint       gtk_etext_buffer_set_text_style   (GtkEtextBuffer *buf,
                                        gint              start_pos,
                                        gint              end_pos,
					GtkEtextStyle	  *style);


/**
 * gtk_etext_buffer_get_text_style:
 * @buf: The #GtkEtextBuffer whose style at the given @position you wish to get.
 * @position: The position at which you wish to get the current style.  If
 * 	negative, gets the style at the end of the position.
 * 
 * This lets you know what text at the given position will look like.
 * Preconditions: @buf should be valid and non-NULL.
 * Postconditions: none.
 * 
 * Returns: A pointer to the #GtkEtextStyle that is active at @position, or
 * NULL if an error occurred.
 */
GtkEtextStyle *gtk_etext_buffer_get_text_style  (GtkEtextBuffer *buf,
					gint              position);

/**
 * gtk_etext_buffer_get_text_style_length:
 * @buf: The #GtkEtextBuffer you are inquiring about
 * @position: The position at which you wish to get the style length.
 * 
 * This function tells you how many more characters the style at @position 
 * applies to.  This is useful if you want to save the text data with the
 * style information (i.e., as an HTML document), because you can use this
 * instead of calling gtk_etext_buffer_get_text_style() on every single 
 * position in the buffer when saving the style info.
 * Preconditions: @buf should be valid and non-NULL.
 * Postconditions: none.
 * 
 * Returns: The number of characters forward that have the same #GtkEtextStyle
 *  as the style that applies at @position, or <0 if an error occurred.
 */
gint gtk_etext_buffer_get_text_style_length  (GtkEtextBuffer *buf,
					gint              position);


/**
 * gtk_etext_buffer_get_text_style_tag_position:
 * @buf: The #GtkEtextBuffer you are inquiring about
 * @position: The position who tag location you want to know.  If negative, gets
 * the position of the StyleTag affecting the last position.
 * 
 * Internally, GtkEtext maintains style information with something called 
 * StyleTags.  Normally, you do not need to worry about these.  However, the
 * optimal syntax highlighting algorithm requires you to know the region that was
 * last successfully highlighted--so this function exists for that purpose only.
 * Unless you're doing syntax highlighting, don't worry about this function,
 * or StyleTags.
 * 
 * This function returns the position of the StyleTag for the given @position.
 * Preconditions: @buf should be valid and non-NULL.
 * Postconditions: none.
 * 
 * Returns: The position of the tag who is responsible for the passed @position.
 * The tag's position is the first character that is affected by that tag.  <0
 * is returned if an error occurred.
 */
gint gtk_etext_buffer_get_text_style_tag_position  (GtkEtextBuffer *buf,
					gint              position);


/**
 * gtk_etext_buffer_set_line_mark:
 * @buf: The #GtkEtextBuffer whose line you wish to mark
 * @line_number: The text line number ('\n' line) you wish to flag
 * @mark_type: The #GtkEtextLineMarkType you wish to flag
 * @mark_value: Whether you want to set the mark to be on or off
 * 
 * This lets you flag a line.  Applications can use this to set bookmarks,
 * set "breakpoints" in GUI debuggers, flag lines where a string is found, etc.
 * They are a very useful feature.
 * Preconditions: @buf should be valid and non-NULL.
 * Postconditions: the line at @line_number is flagged with @mark_type.
 * 
 * Returns: nothing.
 */
void gtk_etext_buffer_set_line_mark(GtkEtextBuffer *buf,
					guint line_number,
					GtkEtextLineMarkType mark_type,
					gboolean mark_value);

/**
 * gtk_etext_buffer_toggle_line_mark:
 * @buf: The #GtkEtextBuffer whose line you wish to toggle
 * @line_number: The text line number ('\n' line) you wish to toggle
 * @mark_type: The #GtkEtextLineMarkType you wish to toggle
 * 
 * This convenience function lets you toggle a particular line's marks on or off.
 * Preconditions: @buf should be valid and non-NULL.
 * Postconditions: the line at @line_number is toggled with @mark_type.
 * 
 * Returns: The new value of the mark (i.e, TRUE if it is now on, or FALSE if it
 * is now off), or a default to FALSE (with warning) if an error occurs.
 */
gboolean gtk_etext_buffer_toggle_line_mark(GtkEtextBuffer *buf,
					guint line_number,
					GtkEtextLineMarkType mark_type);

/**
 * gtk_etext_buffer_get_line_mark:
 * @buf: The #GtkEtextBuffer whose line you wish to inquire about
 * @line_number: The text line number ('\n' line) you wish to inquire about
 * @mark_type: The #GtkEtextLineMarkType you wish to find the value of
 * 
 * This returns the current value of a particular mark_type, for a particular
 * line.
 * Preconditions: @buf should be valid and non-NULL.
 * Postconditions: none.
 * 
 * Returns: The value of the mark (i.e, TRUE if it is on, or FALSE if
 * it is off), or a default to FALSE (with warning) if an error occurs.
 */
gboolean gtk_etext_buffer_get_line_mark(GtkEtextBuffer *buf,
					guint line_number,
					GtkEtextLineMarkType mark_type);


/**
 * gtk_etext_buffer_get_next_line_mark:
 * @buf: The #GtkEtextBuffer you want to inquire about
 * @line_number: The line number to start the search from
 * @mark_type: The #GtkEtextLineMarkType you want to inquire about
 * @forward: Whether to search forward (TRUE) or backward (FALSE)
 * 
 * This returns the line number of the next line which is marked with @mark_type.
 * It starts at @line_number.  If it reaches the end of the without finding any more
 * lines marked with @mark_type, it returns -1.
 * Preconditions: @buf should be valid and non-NULL.
 * Postconditions: none.
 * 
 * Returns: the line number of the next marked line, or -1 if the end 
 * (if forward) or front (if backward) of the buffer is reached without
 * finding a marked line, or <-1 if an error occurs.
 */
gint gtk_etext_buffer_get_next_line_mark(GtkEtextBuffer *buf,
					guint line_number,
					GtkEtextLineMarkType mark_type,
					gboolean forward);

/**
 * gtk_etext_buffer_find:
 * @buf: The #GtkEtextBuffer you wish to search in
 * @search_text: The string you wish to search backward for
 * @start_pos: The position to start the search at
 * @forward: The direction you wish to search
 * 
 * This function lets you do a (very) simple strcmp() search for a particular
 * string.  This is useful for things like keybindings (it makes it easy
 * to find the previous space (" ") if you want to move to the beginning or
 * end of the previous word, for example) or if you want to move to the last
 * paragraph by searching for "\n\n" or some such thing.
 * Preconditions: @buf should be valid and non-NULL.
 * Postconditions: none.
 * 
 * Returns: The position that @search_text is found at, or -1 if it's not found,
 * or <-1 if an error occurs.
 */
gint gtk_etext_buffer_find (GtkEtextBuffer *buf,
				         const gchar *search_text,
					 guint start_pos,
					 gboolean forward);


/**
 * gtk_etext_buffer_get_chars:
 * @buf: The #GtkEtextBuffer you wish to read from
 * @start_pos: The starting position (where zero is the first position).
 * @end_pos: The end position.  If negative, the text from @start_pos to the
 * end of the buffer is returned.
 * 
 * This lets you read text from the buffer.  The returned NULL-terminated string
 * must be g_free()ed before when the application is done with it.
 * 
 * Preconditions: @buf should be valid and non-NULL.
 * Postconditions: none.
 * 
 * Returns: The NULL-terminated string, or NULL (with warning) if an error
 * occurs.
 */
gchar *gtk_etext_buffer_get_chars(GtkEtextBuffer *buf,
				  gint start_pos,
				  gint end_pos);

/**
 * gtk_etext_buffer_get_length:
 * @buf: The #GtkEtextBuffer whose character count you'd like to know.
 * 
 * This tells you the number of characters in the buffer.    The last
 * valid position in the buffer is gtk_etext_buffer_get_length() - 1.
 * Preconditions: @buf should be valid and non-NULL.
 * Postconditions: none.
 * 
 * Returns: The total number of characters in the buffer, or -1 if an
 * error occurs.
 */
gint gtk_etext_buffer_get_length(GtkEtextBuffer *buf);


/* Standard stuff */
GtkType gtk_etext_buffer_get_type(void);
GtkEtextBuffer *gtk_etext_buffer_new(void);

#ifdef __cplusplus
}
#endif /* __cplusplus */
                                     
                                     
#endif /* __GTK_ETEXT_BUFFER_H__ */




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