gtkimhtml.h

Go to the documentation of this file.
00001 
00023 #ifndef _PIDGINIMHTML_H_
00024 #define _PIDGINIMHTML_H_
00025 
00026 #include <gdk/gdk.h>
00027 #include <gtk/gtktextview.h>
00028 #include <gtk/gtktooltips.h>
00029 #include <gtk/gtkimage.h>
00030 #include "gtksourceundomanager.h"
00031 
00032 #include "connection.h"
00033 
00034 #ifdef __cplusplus
00035 extern "C" {
00036 #endif
00037 
00038 /**************************************************************************
00039  * @name Structures
00040  **************************************************************************/
00043 #define GTK_TYPE_IMHTML            (gtk_imhtml_get_type ())
00044 #define GTK_IMHTML(obj)            (GTK_CHECK_CAST ((obj), GTK_TYPE_IMHTML, GtkIMHtml))
00045 #define GTK_IMHTML_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_IMHTML, GtkIMHtmlClass))
00046 #define GTK_IS_IMHTML(obj)         (GTK_CHECK_TYPE ((obj), GTK_TYPE_IMHTML))
00047 #define GTK_IS_IMHTML_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_IMHTML))
00048 #define GTK_IMHTML_SCALABLE(obj)   ((GtkIMHtmlScalable *)obj)
00049 #define GTK_IMHTML_ANIMATION(obj)   ((GtkIMHtmlAnimation *)obj)
00050 
00051 typedef struct _GtkIMHtml           GtkIMHtml;
00052 typedef struct _GtkIMHtmlClass      GtkIMHtmlClass;
00053 typedef struct _GtkIMHtmlFontDetail GtkIMHtmlFontDetail;    /* The five elements contained in a FONT tag */
00054 typedef struct _GtkSmileyTree       GtkSmileyTree;
00055 typedef struct _GtkIMHtmlSmiley     GtkIMHtmlSmiley;
00056 typedef struct _GtkIMHtmlScalable   GtkIMHtmlScalable;
00057 typedef struct _GtkIMHtmlImage      GtkIMHtmlImage;
00058 typedef struct _GtkIMHtmlAnimation  GtkIMHtmlAnimation;
00059 typedef struct _GtkIMHtmlHr         GtkIMHtmlHr;
00060 typedef struct _GtkIMHtmlFuncs      GtkIMHtmlFuncs;
00061 
00062 typedef enum {
00063     GTK_IMHTML_BOLD =       1 << 0,
00064     GTK_IMHTML_ITALIC =     1 << 1,
00065     GTK_IMHTML_UNDERLINE =  1 << 2,
00066     GTK_IMHTML_GROW =       1 << 3,
00067     GTK_IMHTML_SHRINK =     1 << 4,
00068     GTK_IMHTML_FACE =       1 << 5,
00069     GTK_IMHTML_FORECOLOR =  1 << 6,
00070     GTK_IMHTML_BACKCOLOR =  1 << 7,
00071     GTK_IMHTML_BACKGROUND = 1 << 8,
00072     GTK_IMHTML_LINK =       1 << 9,
00073     GTK_IMHTML_IMAGE =      1 << 10,
00074     GTK_IMHTML_SMILEY =     1 << 11,
00075     GTK_IMHTML_LINKDESC =   1 << 12,
00076     GTK_IMHTML_STRIKE =     1 << 13,
00077     GTK_IMHTML_ALL =       -1
00078 } GtkIMHtmlButtons;
00079 
00080 typedef enum {
00081     GTK_IMHTML_SMILEY_CUSTOM =  1 << 0
00082 } GtkIMHtmlSmileyFlags;
00083 
00084 struct _GtkIMHtml {
00085     GtkTextView text_view;
00086     GtkTextBuffer *text_buffer;
00087     GdkCursor *hand_cursor;
00088     GdkCursor *arrow_cursor;
00089     GdkCursor *text_cursor;
00090     GHashTable *smiley_data;
00091     GtkSmileyTree *default_smilies;
00092     char *protocol_name;
00093     guint scroll_src;
00094     GTimer *scroll_time;
00095     GQueue *animations;
00096     int num_animations;
00097 
00098     gboolean show_comments;
00099 
00100     GtkWidget *tip_window;
00101     char *tip;
00102     guint tip_timer;
00103     GtkTextTag *prelit_tag;
00104 
00105     GList *scalables;
00106     GdkRectangle old_rect;
00107 
00108     gchar *search_string;
00109 
00110     gboolean editable;
00111     GtkIMHtmlButtons format_functions;
00112     gboolean wbfo;  /* Whole buffer formatting only. */
00113 
00114     gint insert_offset;
00115 
00116     struct {
00117         gboolean bold:1;
00118         gboolean italic:1;
00119         gboolean underline:1;
00120         gboolean strike:1;
00121         gchar *forecolor;
00122         gchar *backcolor;
00123         gchar *background;
00124         gchar *fontface;
00125         int fontsize;
00126         GtkTextTag *link;
00127     } edit;
00128 
00129     char *clipboard_text_string;
00130     char *clipboard_html_string;
00131 
00132     GSList *im_images;
00133     GtkIMHtmlFuncs *funcs;
00134     GtkSourceUndoManager *undo_manager;
00135 };
00136 
00137 struct _GtkIMHtmlClass {
00138     GtkTextViewClass parent_class;
00139 
00140     void (*url_clicked)(GtkIMHtml *, const gchar *);
00141     void (*buttons_update)(GtkIMHtml *, GtkIMHtmlButtons);
00142     void (*toggle_format)(GtkIMHtml *, GtkIMHtmlButtons);
00143     void (*clear_format)(GtkIMHtml *);
00144     void (*update_format)(GtkIMHtml *);
00145     gboolean (*message_send)(GtkIMHtml *);
00146     void (*undo)(GtkIMHtml *);
00147     void (*redo)(GtkIMHtml *);
00148 };
00149 
00150 struct _GtkIMHtmlFontDetail {
00151     gushort size;
00152     gchar *face;
00153     gchar *fore;
00154     gchar *back;
00155     gchar *bg;
00156     gchar *sml;
00157     gboolean underline;
00158     gshort bold;
00159 };
00160 
00161 struct _GtkSmileyTree {
00162     GString *values;
00163     GtkSmileyTree **children;
00164     GtkIMHtmlSmiley *image;
00165 };
00166 
00167 struct _GtkIMHtmlSmiley {
00168     gchar *smile;
00169     gchar *file;
00170     GdkPixbufAnimation *icon;
00171     gboolean hidden;
00172     GdkPixbufLoader *loader;
00173     GSList *anchors;
00174     GtkIMHtmlSmileyFlags flags;
00175     GtkIMHtml *imhtml;
00176 };
00177 
00178 struct _GtkIMHtmlScalable {
00179     void (*scale)(struct _GtkIMHtmlScalable *, int, int);
00180     void (*add_to)(struct _GtkIMHtmlScalable *, GtkIMHtml *, GtkTextIter *);
00181     void (*free)(struct _GtkIMHtmlScalable *);
00182 };
00183 
00184 struct _GtkIMHtmlImage {
00185     GtkIMHtmlScalable scalable;
00186     GtkImage *image; 
00187     GdkPixbuf *pixbuf; 
00188     GtkTextMark *mark;
00189     gchar *filename;
00190     int width;
00191     int height;
00192     int id;
00193     GtkWidget *filesel;
00194 };
00195 
00196 struct _GtkIMHtmlAnimation {
00197     GtkIMHtmlImage imhtmlimage;
00198     GdkPixbufAnimation *anim; 
00199     GdkPixbufAnimationIter *iter;
00200     guint timer;
00201 };
00202 
00203 struct _GtkIMHtmlHr {
00204     GtkIMHtmlScalable scalable;
00205     GtkWidget *sep;
00206 };
00207 
00208 typedef enum {
00209     GTK_IMHTML_NO_COLOURS          = 1 << 0,
00210     GTK_IMHTML_NO_FONTS            = 1 << 1,
00211     GTK_IMHTML_NO_COMMENTS         = 1 << 2, /* Remove */
00212     GTK_IMHTML_NO_TITLE            = 1 << 3,
00213     GTK_IMHTML_NO_NEWLINE          = 1 << 4,
00214     GTK_IMHTML_NO_SIZES            = 1 << 5,
00215     GTK_IMHTML_NO_SCROLL           = 1 << 6,
00216     GTK_IMHTML_RETURN_LOG          = 1 << 7,
00217     GTK_IMHTML_USE_POINTSIZE       = 1 << 8,
00218     GTK_IMHTML_NO_FORMATTING       = 1 << 9,
00219     GTK_IMHTML_USE_SMOOTHSCROLLING = 1 << 10
00220 } GtkIMHtmlOptions;
00221 
00222 enum {
00223     GTK_IMHTML_DRAG_URL = 0,
00224     GTK_IMHTML_DRAG_HTML,
00225     GTK_IMHTML_DRAG_UTF8_STRING,
00226     GTK_IMHTML_DRAG_COMPOUND_TEXT,
00227     GTK_IMHTML_DRAG_STRING,
00228     GTK_IMHTML_DRAG_TEXT,
00229     GTK_IMHTML_DRAG_NUM
00230 };
00231 
00232 #define GTK_IMHTML_DND_TARGETS  \
00233     { "text/uri-list", 0, GTK_IMHTML_DRAG_URL }, \
00234     { "_NETSCAPE_URL", 0, GTK_IMHTML_DRAG_URL }, \
00235     { "text/html", 0, GTK_IMHTML_DRAG_HTML }, \
00236     { "x-url/ftp", 0, GTK_IMHTML_DRAG_URL }, \
00237     { "x-url/http", 0, GTK_IMHTML_DRAG_URL }, \
00238     { "UTF8_STRING", 0, GTK_IMHTML_DRAG_UTF8_STRING }, \
00239     { "COMPOUND_TEXT", 0, GTK_IMHTML_DRAG_COMPOUND_TEXT }, \
00240     { "STRING", 0, GTK_IMHTML_DRAG_STRING }, \
00241     { "text/plain", 0, GTK_IMHTML_DRAG_TEXT }, \
00242     { "TEXT", 0, GTK_IMHTML_DRAG_TEXT }
00243 
00244 typedef gpointer    (*GtkIMHtmlGetImageFunc)        (int id);
00245 typedef gpointer    (*GtkIMHtmlGetImageDataFunc)    (gpointer i);
00246 typedef size_t      (*GtkIMHtmlGetImageSizeFunc)    (gpointer i);
00247 typedef const char *(*GtkIMHtmlGetImageFilenameFunc)(gpointer i);
00248 typedef void        (*GtkIMHtmlImageRefFunc)        (int id);
00249 typedef void        (*GtkIMHtmlImageUnrefFunc)      (int id);
00250 
00251 struct _GtkIMHtmlFuncs {
00252     GtkIMHtmlGetImageFunc image_get;
00253     GtkIMHtmlGetImageDataFunc image_get_data;
00254     GtkIMHtmlGetImageSizeFunc image_get_size;
00255     GtkIMHtmlGetImageFilenameFunc image_get_filename;
00256     GtkIMHtmlImageRefFunc image_ref;
00257     GtkIMHtmlImageUnrefFunc image_unref;
00258 };
00259 
00262 /**************************************************************************
00263  * @name GTK+ IM/HTML rendering component API
00264  **************************************************************************/
00272 GType gtk_imhtml_get_type(void);
00273 
00279 GtkWidget *gtk_imhtml_new(void *, void *);
00280 
00289 GtkIMHtmlSmiley *gtk_imhtml_smiley_get(GtkIMHtml * imhtml,
00290                                         const gchar * sml, const gchar * text);
00291 
00292 
00300 void gtk_imhtml_associate_smiley(GtkIMHtml *imhtml, const gchar *sml, GtkIMHtmlSmiley *smiley);
00301 
00307 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml);
00308 
00315 void gtk_imhtml_set_funcs(GtkIMHtml *imhtml, GtkIMHtmlFuncs *f);
00316 
00323 void gtk_imhtml_show_comments(GtkIMHtml *imhtml, gboolean show);
00324 
00330 const char *gtk_imhtml_get_protocol_name(GtkIMHtml *imhtml);
00331 
00338 void gtk_imhtml_set_protocol_name(GtkIMHtml *imhtml, const gchar *protocol_name);
00339 
00347 #define gtk_imhtml_append_text(imhtml, text, options) \
00348  gtk_imhtml_append_text_with_images(imhtml, text, options, NULL)
00349 
00358 void gtk_imhtml_append_text_with_images(GtkIMHtml *imhtml,
00359                                          const gchar *text,
00360                                          GtkIMHtmlOptions options,
00361                                          GSList *unused);
00362 
00371 void gtk_imhtml_insert_html_at_iter(GtkIMHtml        *imhtml,
00372                                     const gchar      *text,
00373                                     GtkIMHtmlOptions  options,
00374                                     GtkTextIter      *iter);
00375 
00382 void gtk_imhtml_scroll_to_end(GtkIMHtml *imhtml, gboolean smooth);
00383 
00391 void gtk_imhtml_delete(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end);
00392 
00398 #define gtk_imhtml_clear(imhtml) \
00399  gtk_imhtml_delete(imhtml, NULL, NULL)
00400 
00406 void gtk_imhtml_page_up(GtkIMHtml *imhtml);
00407 
00413 void gtk_imhtml_page_down(GtkIMHtml *imhtml);
00414 
00420 GtkIMHtmlScalable *gtk_imhtml_scalable_new(void);
00421 
00431 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename, int id);
00432 
00443 /*
00444  * TODO: All this animation code could be combined much better with
00445  *       the image code.  It couldn't be done when it was written
00446  *       because it requires breaking backward compatibility.  It
00447  *       would be good to do it for 3.0.0.
00448  */
00449 GtkIMHtmlScalable *gtk_imhtml_animation_new(GdkPixbufAnimation *img, const gchar *filename, int id);
00450 
00456 /* TODO: Is there any reason this isn't private? */
00457 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale);
00458 
00464 /* TODO: Is there any reason this isn't private? */
00465 void gtk_imhtml_animation_free(GtkIMHtmlScalable *scale);
00466 
00474 /* TODO: Is there any reason this isn't private? */
00475 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height);
00476 
00484 /* TODO: Is there any reason this isn't private? */
00485 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter);
00486 
00492 GtkIMHtmlScalable *gtk_imhtml_hr_new(void);
00493 
00499 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale);
00500 
00508 void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height);
00509 
00518 void gtk_imhtml_hr_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter);
00519 
00528 gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text);
00529 
00535 void gtk_imhtml_search_clear(GtkIMHtml *imhtml);
00536 
00543 void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable);
00544 
00553 void gtk_imhtml_set_whole_buffer_formatting_only(GtkIMHtml *imhtml, gboolean wbfo);
00554 
00561 void gtk_imhtml_set_format_functions(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons);
00562 
00570 GtkIMHtmlButtons gtk_imhtml_get_format_functions(GtkIMHtml *imhtml);
00571 
00581 void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gboolean *bold, gboolean *italic, gboolean *underline);
00582 
00591 char *gtk_imhtml_get_current_fontface(GtkIMHtml *imhtml);
00592 
00601 char *gtk_imhtml_get_current_forecolor(GtkIMHtml *imhtml);
00602 
00611 char *gtk_imhtml_get_current_backcolor(GtkIMHtml *imhtml);
00612 
00621 char *gtk_imhtml_get_current_background(GtkIMHtml *imhtml);
00622 
00631 gint gtk_imhtml_get_current_fontsize(GtkIMHtml *imhtml);
00632 
00640 gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml);
00641 
00647 void gtk_imhtml_clear_formatting(GtkIMHtml *imhtml);
00648 
00654 void gtk_imhtml_toggle_bold(GtkIMHtml *imhtml);
00655 
00661 void gtk_imhtml_toggle_italic(GtkIMHtml *imhtml);
00662 
00668 void gtk_imhtml_toggle_underline(GtkIMHtml *imhtml);
00669 
00675 void gtk_imhtml_toggle_strike(GtkIMHtml *imhtml);
00676 
00686 gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color);
00687 
00697 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color);
00698 
00708 gboolean gtk_imhtml_toggle_background(GtkIMHtml *imhtml, const char *color);
00709 
00718 gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face);
00719 
00727 void gtk_imhtml_toggle_link(GtkIMHtml *imhtml, const char *url);
00728 
00737 void gtk_imhtml_insert_link(GtkIMHtml *imhtml, GtkTextMark *mark, const char *url, const char *text);
00738 
00746 void gtk_imhtml_insert_smiley(GtkIMHtml *imhtml, const char *sml, char *smiley);
00755 void gtk_imhtml_insert_smiley_at_iter(GtkIMHtml *imhtml, const char *sml, char *smiley, GtkTextIter *iter);
00756 
00765 void gtk_imhtml_insert_image_at_iter(GtkIMHtml *imhtml, int id, GtkTextIter *iter);
00766 
00773 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size);
00774 
00781 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml);
00782 
00789 void gtk_imhtml_font_grow(GtkIMHtml *imhtml);
00790 
00800 char *gtk_imhtml_get_markup_range(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end);
00801 
00809 char *gtk_imhtml_get_markup(GtkIMHtml *imhtml);
00810 
00819 char **gtk_imhtml_get_markup_lines(GtkIMHtml *imhtml);
00820 
00831 char *gtk_imhtml_get_text(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *stop);
00832 
00839 void gtk_imhtml_setup_entry(GtkIMHtml *imhtml, PurpleConnectionFlags flags);
00840 
00843 #ifdef __cplusplus
00844 }
00845 #endif
00846 
00847 #endif /* _PIDGINIMHTML_H_ */