gtkimhtml.h

Go to the documentation of this file.
00001 
00006 /* Pidgin is the legal property of its developers, whose names are too numerous
00007  * to list here.  Please refer to the COPYRIGHT file distributed with this
00008  * source distribution.
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
00023  */
00024 #ifndef _PIDGINIMHTML_H_
00025 #define _PIDGINIMHTML_H_
00026 
00027 #include <gdk/gdk.h>
00028 #include <gtk/gtktextview.h>
00029 #include <gtk/gtktooltips.h>
00030 #include <gtk/gtkimage.h>
00031 #include "gtksourceundomanager.h"
00032 
00033 #include "connection.h"
00034 
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038 
00039 /**************************************************************************
00040  * @name Structures
00041  **************************************************************************/
00044 #define GTK_TYPE_IMHTML            (gtk_imhtml_get_type ())
00045 #define GTK_IMHTML(obj)            (GTK_CHECK_CAST ((obj), GTK_TYPE_IMHTML, GtkIMHtml))
00046 #define GTK_IMHTML_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_IMHTML, GtkIMHtmlClass))
00047 #define GTK_IS_IMHTML(obj)         (GTK_CHECK_TYPE ((obj), GTK_TYPE_IMHTML))
00048 #define GTK_IS_IMHTML_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_IMHTML))
00049 #define GTK_IMHTML_SCALABLE(obj)   ((GtkIMHtmlScalable *)obj)
00050 #define GTK_IMHTML_ANIMATION(obj)   ((GtkIMHtmlAnimation *)obj)
00051 
00052 typedef struct _GtkIMHtml           GtkIMHtml;
00053 typedef struct _GtkIMHtmlClass      GtkIMHtmlClass;
00054 typedef struct _GtkIMHtmlFontDetail GtkIMHtmlFontDetail;    /* The five elements contained in a FONT tag */
00055 typedef struct _GtkSmileyTree       GtkSmileyTree;
00056 typedef struct _GtkIMHtmlSmiley     GtkIMHtmlSmiley;
00057 typedef struct _GtkIMHtmlScalable   GtkIMHtmlScalable;
00058 typedef struct _GtkIMHtmlImage      GtkIMHtmlImage;
00059 typedef struct _GtkIMHtmlAnimation  GtkIMHtmlAnimation;
00060 typedef struct _GtkIMHtmlHr         GtkIMHtmlHr;
00061 typedef struct _GtkIMHtmlFuncs      GtkIMHtmlFuncs;
00062 
00063 typedef enum {
00064     GTK_IMHTML_BOLD =       1 << 0,
00065     GTK_IMHTML_ITALIC =     1 << 1,
00066     GTK_IMHTML_UNDERLINE =  1 << 2,
00067     GTK_IMHTML_GROW =       1 << 3,
00068     GTK_IMHTML_SHRINK =     1 << 4,
00069     GTK_IMHTML_FACE =       1 << 5,
00070     GTK_IMHTML_FORECOLOR =  1 << 6,
00071     GTK_IMHTML_BACKCOLOR =  1 << 7,
00072     GTK_IMHTML_BACKGROUND = 1 << 8,
00073     GTK_IMHTML_LINK =       1 << 9,
00074     GTK_IMHTML_IMAGE =      1 << 10,
00075     GTK_IMHTML_SMILEY =     1 << 11,
00076     GTK_IMHTML_LINKDESC =   1 << 12,
00077     GTK_IMHTML_STRIKE =     1 << 13,
00078     GTK_IMHTML_ALL =       -1
00079 } GtkIMHtmlButtons;
00080 
00081 typedef enum {
00082     GTK_IMHTML_SMILEY_CUSTOM =  1 << 0
00083 } GtkIMHtmlSmileyFlags;
00084 
00085 struct _GtkIMHtml {
00086     GtkTextView text_view;
00087     GtkTextBuffer *text_buffer;
00088     GdkCursor *hand_cursor;
00089     GdkCursor *arrow_cursor;
00090     GdkCursor *text_cursor;
00091     GHashTable *smiley_data;
00092     GtkSmileyTree *default_smilies;
00093     char *protocol_name;
00094     guint scroll_src;
00095     GTimer *scroll_time;
00096     GQueue *animations;
00097     int num_animations;
00098 
00099     gboolean show_comments;
00100 
00101     GtkWidget *tip_window;
00102     char *tip;
00103     guint tip_timer;
00104     GtkTextTag *prelit_tag;
00105 
00106     GList *scalables;
00107     GdkRectangle old_rect;
00108 
00109     gchar *search_string;
00110 
00111     gboolean editable;
00112     GtkIMHtmlButtons format_functions;
00113     gboolean wbfo;  /* Whole buffer formatting only. */
00114 
00115     gint insert_offset;
00116 
00117     struct {
00118         gboolean bold:1;
00119         gboolean italic:1;
00120         gboolean underline:1;
00121         gboolean strike:1;
00122         gchar *forecolor;
00123         gchar *backcolor;
00124         gchar *background;
00125         gchar *fontface;
00126         int fontsize;
00127         GtkTextTag *link;
00128     } edit;
00129 
00130     char *clipboard_text_string;
00131     char *clipboard_html_string;
00132 
00133     GSList *im_images;
00134     GtkIMHtmlFuncs *funcs;
00135     GtkSourceUndoManager *undo_manager;
00136 };
00137 
00138 struct _GtkIMHtmlClass {
00139     GtkTextViewClass parent_class;
00140 
00141     void (*url_clicked)(GtkIMHtml *, const gchar *);
00142     void (*buttons_update)(GtkIMHtml *, GtkIMHtmlButtons);
00143     void (*toggle_format)(GtkIMHtml *, GtkIMHtmlButtons);
00144     void (*clear_format)(GtkIMHtml *);
00145     void (*update_format)(GtkIMHtml *);
00146     gboolean (*message_send)(GtkIMHtml *);
00147     void (*undo)(GtkIMHtml *);
00148     void (*redo)(GtkIMHtml *);
00149 };
00150 
00151 struct _GtkIMHtmlFontDetail {
00152     gushort size;
00153     gchar *face;
00154     gchar *fore;
00155     gchar *back;
00156     gchar *bg;
00157     gchar *sml;
00158     gboolean underline;
00159     gshort bold;
00160 };
00161 
00162 struct _GtkSmileyTree {
00163     GString *values;
00164     GtkSmileyTree **children;
00165     GtkIMHtmlSmiley *image;
00166 };
00167 
00168 struct _GtkIMHtmlSmiley {
00169     gchar *smile;
00170     gchar *file;
00171     GdkPixbufAnimation *icon;
00172     gboolean hidden;
00173     GdkPixbufLoader *loader;
00174     GSList *anchors;
00175     GtkIMHtmlSmileyFlags flags;
00176     GtkIMHtml *imhtml;
00177 };
00178 
00179 struct _GtkIMHtmlScalable {
00180     void (*scale)(struct _GtkIMHtmlScalable *, int, int);
00181     void (*add_to)(struct _GtkIMHtmlScalable *, GtkIMHtml *, GtkTextIter *);
00182     void (*free)(struct _GtkIMHtmlScalable *);
00183 };
00184 
00185 struct _GtkIMHtmlImage {
00186     GtkIMHtmlScalable scalable;
00187     GtkImage *image; 
00188     GdkPixbuf *pixbuf; 
00189     GtkTextMark *mark;
00190     gchar *filename;
00191     int width;
00192     int height;
00193     int id;
00194     GtkWidget *filesel;
00195 };
00196 
00197 struct _GtkIMHtmlAnimation {
00198     GtkIMHtmlImage imhtmlimage;
00199     GdkPixbufAnimation *anim; 
00200     GdkPixbufAnimationIter *iter;
00201     guint timer;
00202 };
00203 
00204 struct _GtkIMHtmlHr {
00205     GtkIMHtmlScalable scalable;
00206     GtkWidget *sep;
00207 };
00208 
00209 typedef enum {
00210     GTK_IMHTML_NO_COLOURS          = 1 << 0,
00211     GTK_IMHTML_NO_FONTS            = 1 << 1,
00212     GTK_IMHTML_NO_COMMENTS         = 1 << 2, /* Remove */
00213     GTK_IMHTML_NO_TITLE            = 1 << 3,
00214     GTK_IMHTML_NO_NEWLINE          = 1 << 4,
00215     GTK_IMHTML_NO_SIZES            = 1 << 5,
00216     GTK_IMHTML_NO_SCROLL           = 1 << 6,
00217     GTK_IMHTML_RETURN_LOG          = 1 << 7,
00218     GTK_IMHTML_USE_POINTSIZE       = 1 << 8,
00219     GTK_IMHTML_NO_FORMATTING       = 1 << 9,
00220     GTK_IMHTML_USE_SMOOTHSCROLLING = 1 << 10
00221 } GtkIMHtmlOptions;
00222 
00223 enum {
00224     GTK_IMHTML_DRAG_URL = 0,
00225     GTK_IMHTML_DRAG_HTML,
00226     GTK_IMHTML_DRAG_UTF8_STRING,
00227     GTK_IMHTML_DRAG_COMPOUND_TEXT,
00228     GTK_IMHTML_DRAG_STRING,
00229     GTK_IMHTML_DRAG_TEXT,
00230     GTK_IMHTML_DRAG_NUM
00231 };
00232 
00233 #define GTK_IMHTML_DND_TARGETS  \
00234     { "text/uri-list", 0, GTK_IMHTML_DRAG_URL }, \
00235     { "_NETSCAPE_URL", 0, GTK_IMHTML_DRAG_URL }, \
00236     { "text/html", 0, GTK_IMHTML_DRAG_HTML }, \
00237     { "x-url/ftp", 0, GTK_IMHTML_DRAG_URL }, \
00238     { "x-url/http", 0, GTK_IMHTML_DRAG_URL }, \
00239     { "UTF8_STRING", 0, GTK_IMHTML_DRAG_UTF8_STRING }, \
00240     { "COMPOUND_TEXT", 0, GTK_IMHTML_DRAG_COMPOUND_TEXT }, \
00241     { "STRING", 0, GTK_IMHTML_DRAG_STRING }, \
00242     { "text/plain", 0, GTK_IMHTML_DRAG_TEXT }, \
00243     { "TEXT", 0, GTK_IMHTML_DRAG_TEXT }
00244 
00245 typedef gpointer    (*GtkIMHtmlGetImageFunc)        (int id);
00246 typedef gpointer    (*GtkIMHtmlGetImageDataFunc)    (gpointer i);
00247 typedef size_t      (*GtkIMHtmlGetImageSizeFunc)    (gpointer i);
00248 typedef const char *(*GtkIMHtmlGetImageFilenameFunc)(gpointer i);
00249 typedef void        (*GtkIMHtmlImageRefFunc)        (int id);
00250 typedef void        (*GtkIMHtmlImageUnrefFunc)      (int id);
00251 
00252 struct _GtkIMHtmlFuncs {
00253     GtkIMHtmlGetImageFunc image_get;
00254     GtkIMHtmlGetImageDataFunc image_get_data;
00255     GtkIMHtmlGetImageSizeFunc image_get_size;
00256     GtkIMHtmlGetImageFilenameFunc image_get_filename;
00257     GtkIMHtmlImageRefFunc image_ref;
00258     GtkIMHtmlImageUnrefFunc image_unref;
00259 };
00260 
00263 /**************************************************************************
00264  * @name GTK+ IM/HTML rendering component API
00265  **************************************************************************/
00273 GType gtk_imhtml_get_type(void);
00274 
00280 GtkWidget *gtk_imhtml_new(void *, void *);
00281 
00290 GtkIMHtmlSmiley *gtk_imhtml_smiley_get(GtkIMHtml * imhtml,
00291                                         const gchar * sml, const gchar * text);
00292 
00293 
00301 void gtk_imhtml_associate_smiley(GtkIMHtml *imhtml, const gchar *sml, GtkIMHtmlSmiley *smiley);
00302 
00308 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml);
00309 
00316 void gtk_imhtml_set_funcs(GtkIMHtml *imhtml, GtkIMHtmlFuncs *f);
00317 
00324 void gtk_imhtml_show_comments(GtkIMHtml *imhtml, gboolean show);
00325 
00331 const char *gtk_imhtml_get_protocol_name(GtkIMHtml *imhtml);
00332 
00339 void gtk_imhtml_set_protocol_name(GtkIMHtml *imhtml, const gchar *protocol_name);
00340 
00348 #define gtk_imhtml_append_text(imhtml, text, options) \
00349  gtk_imhtml_append_text_with_images(imhtml, text, options, NULL)
00350 
00359 void gtk_imhtml_append_text_with_images(GtkIMHtml *imhtml,
00360                                          const gchar *text,
00361                                          GtkIMHtmlOptions options,
00362                                          GSList *unused);
00363 
00372 void gtk_imhtml_insert_html_at_iter(GtkIMHtml        *imhtml,
00373                                     const gchar      *text,
00374                                     GtkIMHtmlOptions  options,
00375                                     GtkTextIter      *iter);
00376 
00383 void gtk_imhtml_scroll_to_end(GtkIMHtml *imhtml, gboolean smooth);
00384 
00392 void gtk_imhtml_delete(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end);
00393 
00399 #define gtk_imhtml_clear(imhtml) \
00400  gtk_imhtml_delete(imhtml, NULL, NULL)
00401 
00407 void gtk_imhtml_page_up(GtkIMHtml *imhtml);
00408 
00414 void gtk_imhtml_page_down(GtkIMHtml *imhtml);
00415 
00421 GtkIMHtmlScalable *gtk_imhtml_scalable_new(void);
00422 
00432 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename, int id);
00433 
00444 /*
00445  * TODO: All this animation code could be combined much better with
00446  *       the image code.  It couldn't be done when it was written
00447  *       because it requires breaking backward compatibility.  It
00448  *       would be good to do it for 3.0.0.
00449  */
00450 GtkIMHtmlScalable *gtk_imhtml_animation_new(GdkPixbufAnimation *img, const gchar *filename, int id);
00451 
00457 /* TODO: Is there any reason this isn't private? */
00458 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale);
00459 
00465 /* TODO: Is there any reason this isn't private? */
00466 void gtk_imhtml_animation_free(GtkIMHtmlScalable *scale);
00467 
00475 /* TODO: Is there any reason this isn't private? */
00476 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height);
00477 
00485 /* TODO: Is there any reason this isn't private? */
00486 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter);
00487 
00493 GtkIMHtmlScalable *gtk_imhtml_hr_new(void);
00494 
00500 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale);
00501 
00509 void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height);
00510 
00519 void gtk_imhtml_hr_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter);
00520 
00529 gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text);
00530 
00536 void gtk_imhtml_search_clear(GtkIMHtml *imhtml);
00537 
00544 void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable);
00545 
00554 void gtk_imhtml_set_whole_buffer_formatting_only(GtkIMHtml *imhtml, gboolean wbfo);
00555 
00562 void gtk_imhtml_set_format_functions(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons);
00563 
00571 GtkIMHtmlButtons gtk_imhtml_get_format_functions(GtkIMHtml *imhtml);
00572 
00582 void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gboolean *bold, gboolean *italic, gboolean *underline);
00583 
00592 char *gtk_imhtml_get_current_fontface(GtkIMHtml *imhtml);
00593 
00602 char *gtk_imhtml_get_current_forecolor(GtkIMHtml *imhtml);
00603 
00612 char *gtk_imhtml_get_current_backcolor(GtkIMHtml *imhtml);
00613 
00622 char *gtk_imhtml_get_current_background(GtkIMHtml *imhtml);
00623 
00632 gint gtk_imhtml_get_current_fontsize(GtkIMHtml *imhtml);
00633 
00641 gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml);
00642 
00648 void gtk_imhtml_clear_formatting(GtkIMHtml *imhtml);
00649 
00655 void gtk_imhtml_toggle_bold(GtkIMHtml *imhtml);
00656 
00662 void gtk_imhtml_toggle_italic(GtkIMHtml *imhtml);
00663 
00669 void gtk_imhtml_toggle_underline(GtkIMHtml *imhtml);
00670 
00676 void gtk_imhtml_toggle_strike(GtkIMHtml *imhtml);
00677 
00687 gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color);
00688 
00698 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color);
00699 
00709 gboolean gtk_imhtml_toggle_background(GtkIMHtml *imhtml, const char *color);
00710 
00719 gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face);
00720 
00728 void gtk_imhtml_toggle_link(GtkIMHtml *imhtml, const char *url);
00729 
00738 void gtk_imhtml_insert_link(GtkIMHtml *imhtml, GtkTextMark *mark, const char *url, const char *text);
00739 
00747 void gtk_imhtml_insert_smiley(GtkIMHtml *imhtml, const char *sml, char *smiley);
00756 void gtk_imhtml_insert_smiley_at_iter(GtkIMHtml *imhtml, const char *sml, char *smiley, GtkTextIter *iter);
00757 
00766 void gtk_imhtml_insert_image_at_iter(GtkIMHtml *imhtml, int id, GtkTextIter *iter);
00767 
00774 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size);
00775 
00782 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml);
00783 
00790 void gtk_imhtml_font_grow(GtkIMHtml *imhtml);
00791 
00801 char *gtk_imhtml_get_markup_range(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end);
00802 
00810 char *gtk_imhtml_get_markup(GtkIMHtml *imhtml);
00811 
00820 char **gtk_imhtml_get_markup_lines(GtkIMHtml *imhtml);
00821 
00832 char *gtk_imhtml_get_text(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *stop);
00833 
00840 void gtk_imhtml_setup_entry(GtkIMHtml *imhtml, PurpleConnectionFlags flags);
00841 
00844 #ifdef __cplusplus
00845 }
00846 #endif
00847 
00848 #endif /* _PIDGINIMHTML_H_ */