gtkimhtml.h
Go to the documentation of this file.
00001 
00007 /* Pidgin is the legal property of its developers, whose names are too numerous
00008  * to list here.  Please refer to the COPYRIGHT file distributed with this
00009  * source distribution.
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
00024  */
00025 #ifndef _PIDGINIMHTML_H_
00026 #define _PIDGINIMHTML_H_
00027 
00028 #include <gdk/gdk.h>
00029 #include <gtk/gtk.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)            (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_IMHTML, GtkIMHtml))
00045 #define GTK_IMHTML_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_IMHTML, GtkIMHtmlClass))
00046 #define GTK_IS_IMHTML(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_IMHTML))
00047 #define GTK_IS_IMHTML_CLASS(klass) (G_TYPE_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 #if !(defined PIDGIN_DISABLE_DEPRECATED) && !(defined _PIDGIN_GTKIMHTML_C_)
00054 typedef struct _GtkIMHtmlFontDetail GtkIMHtmlFontDetail;    /* The five elements contained in a FONT tag */
00055 #endif
00056 typedef struct _GtkSmileyTree       GtkSmileyTree;
00057 typedef struct _GtkIMHtmlSmiley     GtkIMHtmlSmiley;
00058 typedef struct _GtkIMHtmlScalable   GtkIMHtmlScalable;
00059 typedef struct _GtkIMHtmlImage      GtkIMHtmlImage;
00060 typedef struct _GtkIMHtmlAnimation  GtkIMHtmlAnimation;
00061 typedef struct _GtkIMHtmlHr         GtkIMHtmlHr;
00062 typedef struct _GtkIMHtmlFuncs      GtkIMHtmlFuncs;
00063 
00067 typedef struct _GtkIMHtmlLink       GtkIMHtmlLink;
00068 
00069 typedef enum {
00070     GTK_IMHTML_BOLD =       1 << 0,
00071     GTK_IMHTML_ITALIC =     1 << 1,
00072     GTK_IMHTML_UNDERLINE =  1 << 2,
00073     GTK_IMHTML_GROW =       1 << 3,
00074     GTK_IMHTML_SHRINK =     1 << 4,
00075     GTK_IMHTML_FACE =       1 << 5,
00076     GTK_IMHTML_FORECOLOR =  1 << 6,
00077     GTK_IMHTML_BACKCOLOR =  1 << 7,
00078     GTK_IMHTML_BACKGROUND = 1 << 8,
00079     GTK_IMHTML_LINK =       1 << 9,
00080     GTK_IMHTML_IMAGE =      1 << 10,
00081     GTK_IMHTML_SMILEY =     1 << 11,
00082     GTK_IMHTML_LINKDESC =   1 << 12,
00083     GTK_IMHTML_STRIKE =     1 << 13,
00085     GTK_IMHTML_CUSTOM_SMILEY = 1 << 14,
00086     GTK_IMHTML_ALL =       -1
00087 } GtkIMHtmlButtons;
00088 
00089 typedef enum {
00090     GTK_IMHTML_SMILEY_CUSTOM =  1 << 0
00091 } GtkIMHtmlSmileyFlags;
00092 
00093 struct _GtkIMHtml {
00094     GtkTextView text_view;
00095     GtkTextBuffer *text_buffer;
00096     GdkCursor *hand_cursor;
00097     GdkCursor *arrow_cursor;
00098     GdkCursor *text_cursor;
00099     GHashTable *smiley_data;
00100     GtkSmileyTree *default_smilies;
00101     char *protocol_name;
00102     guint scroll_src;
00103     GTimer *scroll_time;
00104     GQueue *animations;
00105     int num_animations;
00106 
00107     gboolean show_comments;
00108 
00109     GtkWidget *tip_window;
00110     char *tip;
00111     guint tip_timer;
00112     GtkTextTag *prelit_tag;
00113 
00114     GList *scalables;
00115     GdkRectangle old_rect;
00116 
00117     gchar *search_string;
00118 
00119     gboolean editable;
00120     GtkIMHtmlButtons format_functions;
00121     gboolean wbfo;  /* Whole buffer formatting only. */
00122 
00123     gint insert_offset;
00124 
00125     struct {
00126         gboolean bold:1;
00127         gboolean italic:1;
00128         gboolean underline:1;
00129         gboolean strike:1;
00130         gchar *forecolor;
00131         gchar *backcolor;
00132         gchar *background;
00133         gchar *fontface;
00134         int fontsize;
00135         GtkTextTag *link;
00136     } edit;
00137 
00138 #if !(defined PIDGIN_DISABLE_DEPRECATED) || (defined _PIDGIN_GTKIMHTML_C_)
00139 
00140     char *clipboard_text_string;
00142     char *clipboard_html_string;
00143 #else
00144     char *depr1;
00145     char *depr2;
00146 #endif
00147 
00148     GSList *im_images;
00149     GtkIMHtmlFuncs *funcs;
00150     GtkSourceUndoManager *undo_manager;
00151 };
00152 
00153 struct _GtkIMHtmlClass {
00154     GtkTextViewClass parent_class;
00155 
00156     void (*url_clicked)(GtkIMHtml *, const gchar *);
00157     void (*buttons_update)(GtkIMHtml *, GtkIMHtmlButtons);
00158     void (*toggle_format)(GtkIMHtml *, GtkIMHtmlButtons);
00159     void (*clear_format)(GtkIMHtml *);
00160     void (*update_format)(GtkIMHtml *);
00161     gboolean (*message_send)(GtkIMHtml *);
00162     void (*undo)(GtkIMHtml *);
00163     void (*redo)(GtkIMHtml *);
00164     GList *protocols; /* List of GtkIMHtmlProtocol's */
00165 };
00166 
00167 #if !(defined PIDGIN_DISABLE_DEPRECATED) && !(defined _PIDGIN_GTKIMHTML_C_)
00168 
00169 struct _GtkIMHtmlFontDetail {
00170     gushort size;
00171     gchar *face;
00172     gchar *fore;
00173     gchar *back;
00174     gchar *bg;
00175     gchar *sml;
00176     gboolean underline;
00177     gshort bold;
00178 };
00179 #endif
00180 
00181 struct _GtkSmileyTree {
00182     GString *values;
00183     GtkSmileyTree **children;
00184     GtkIMHtmlSmiley *image;
00185 };
00186 
00187 struct _GtkIMHtmlSmiley {
00188     gchar *smile;
00189     gchar *file;
00190     GdkPixbufAnimation *icon;
00191     gboolean hidden;
00192     GdkPixbufLoader *loader;
00193     GSList *anchors;
00194     GtkIMHtmlSmileyFlags flags;
00195     GtkIMHtml *imhtml;
00196     gpointer data;       
00197     gsize datasize;      
00198 };
00199 
00200 struct _GtkIMHtmlScalable {
00201     void (*scale)(struct _GtkIMHtmlScalable *, int, int);
00202     void (*add_to)(struct _GtkIMHtmlScalable *, GtkIMHtml *, GtkTextIter *);
00203     void (*free)(struct _GtkIMHtmlScalable *);
00204 };
00205 
00206 struct _GtkIMHtmlImage {
00207     GtkIMHtmlScalable scalable;
00208     GtkImage *image; 
00209     GdkPixbuf *pixbuf; 
00210     GtkTextMark *mark;
00211     gchar *filename;
00212     int width;
00213     int height;
00214     int id;
00215     GtkWidget *filesel;
00216 };
00217 
00218 struct _GtkIMHtmlAnimation {
00219     GtkIMHtmlImage imhtmlimage;
00220     GdkPixbufAnimation *anim; 
00221     GdkPixbufAnimationIter *iter;
00222     guint timer;
00223 };
00224 
00225 struct _GtkIMHtmlHr {
00226     GtkIMHtmlScalable scalable;
00227     GtkWidget *sep;
00228 };
00229 
00230 typedef enum {
00231     GTK_IMHTML_NO_COLOURS          = 1 << 0,
00232     GTK_IMHTML_NO_FONTS            = 1 << 1,
00233     GTK_IMHTML_NO_COMMENTS         = 1 << 2, /* Remove */
00234     GTK_IMHTML_NO_TITLE            = 1 << 3,
00235     GTK_IMHTML_NO_NEWLINE          = 1 << 4,
00236     GTK_IMHTML_NO_SIZES            = 1 << 5,
00237     GTK_IMHTML_NO_SCROLL           = 1 << 6,
00238     GTK_IMHTML_RETURN_LOG          = 1 << 7,
00239     GTK_IMHTML_USE_POINTSIZE       = 1 << 8,
00240     GTK_IMHTML_NO_FORMATTING       = 1 << 9,
00241     GTK_IMHTML_USE_SMOOTHSCROLLING = 1 << 10,
00242     GTK_IMHTML_NO_SMILEY           = 1 << 11,
00243 } GtkIMHtmlOptions;
00244 
00245 enum {
00246     GTK_IMHTML_DRAG_URL = 0,
00247     GTK_IMHTML_DRAG_HTML,
00248     GTK_IMHTML_DRAG_UTF8_STRING,
00249     GTK_IMHTML_DRAG_COMPOUND_TEXT,
00250     GTK_IMHTML_DRAG_STRING,
00251     GTK_IMHTML_DRAG_TEXT,
00252     GTK_IMHTML_DRAG_NUM
00253 };
00254 
00255 #define GTK_IMHTML_DND_TARGETS  \
00256     { "text/uri-list", 0, GTK_IMHTML_DRAG_URL }, \
00257     { "_NETSCAPE_URL", 0, GTK_IMHTML_DRAG_URL }, \
00258     { "text/html", 0, GTK_IMHTML_DRAG_HTML }, \
00259     { "x-url/ftp", 0, GTK_IMHTML_DRAG_URL }, \
00260     { "x-url/http", 0, GTK_IMHTML_DRAG_URL }, \
00261     { "UTF8_STRING", 0, GTK_IMHTML_DRAG_UTF8_STRING }, \
00262     { "COMPOUND_TEXT", 0, GTK_IMHTML_DRAG_COMPOUND_TEXT }, \
00263     { "STRING", 0, GTK_IMHTML_DRAG_STRING }, \
00264     { "text/plain", 0, GTK_IMHTML_DRAG_TEXT }, \
00265     { "TEXT", 0, GTK_IMHTML_DRAG_TEXT }
00266 
00267 typedef gpointer    (*GtkIMHtmlGetImageFunc)        (int id);
00268 typedef gpointer    (*GtkIMHtmlGetImageDataFunc)    (gpointer i);
00269 typedef size_t      (*GtkIMHtmlGetImageSizeFunc)    (gpointer i);
00270 typedef const char *(*GtkIMHtmlGetImageFilenameFunc)(gpointer i);
00271 typedef void        (*GtkIMHtmlImageRefFunc)        (int id);
00272 typedef void        (*GtkIMHtmlImageUnrefFunc)      (int id);
00273 
00274 struct _GtkIMHtmlFuncs {
00275     GtkIMHtmlGetImageFunc image_get;
00276     GtkIMHtmlGetImageDataFunc image_get_data;
00277     GtkIMHtmlGetImageSizeFunc image_get_size;
00278     GtkIMHtmlGetImageFilenameFunc image_get_filename;
00279     GtkIMHtmlImageRefFunc image_ref;
00280     GtkIMHtmlImageUnrefFunc image_unref;
00281 };
00282 
00285 /**************************************************************************
00286  * @name GTK+ IM/HTML rendering component API
00287  **************************************************************************/
00295 GType gtk_imhtml_get_type(void);
00296 
00302 GtkWidget *gtk_imhtml_new(void *, void *);
00303 
00312 GtkIMHtmlSmiley *gtk_imhtml_smiley_get(GtkIMHtml * imhtml,
00313                                         const gchar * sml, const gchar * text);
00314 
00315 
00323 void gtk_imhtml_associate_smiley(GtkIMHtml *imhtml, const gchar *sml, GtkIMHtmlSmiley *smiley);
00324 
00330 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml);
00331 
00338 void gtk_imhtml_set_funcs(GtkIMHtml *imhtml, GtkIMHtmlFuncs *f);
00339 
00346 void gtk_imhtml_show_comments(GtkIMHtml *imhtml, gboolean show);
00347 
00353 const char *gtk_imhtml_get_protocol_name(GtkIMHtml *imhtml);
00354 
00361 void gtk_imhtml_set_protocol_name(GtkIMHtml *imhtml, const gchar *protocol_name);
00362 
00370 #define gtk_imhtml_append_text(imhtml, text, options) \
00371  gtk_imhtml_append_text_with_images(imhtml, text, options, NULL)
00372 
00381 void gtk_imhtml_append_text_with_images(GtkIMHtml *imhtml,
00382                                          const gchar *text,
00383                                          GtkIMHtmlOptions options,
00384                                          GSList *unused);
00385 
00394 void gtk_imhtml_insert_html_at_iter(GtkIMHtml        *imhtml,
00395                                     const gchar      *text,
00396                                     GtkIMHtmlOptions  options,
00397                                     GtkTextIter      *iter);
00398 
00405 void gtk_imhtml_scroll_to_end(GtkIMHtml *imhtml, gboolean smooth);
00406 
00414 void gtk_imhtml_delete(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end);
00415 
00421 #define gtk_imhtml_clear(imhtml) \
00422  gtk_imhtml_delete(imhtml, NULL, NULL)
00423 
00429 void gtk_imhtml_page_up(GtkIMHtml *imhtml);
00430 
00436 void gtk_imhtml_page_down(GtkIMHtml *imhtml);
00437 
00443 GtkIMHtmlScalable *gtk_imhtml_scalable_new(void);
00444 
00454 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename, int id);
00455 
00468 /*
00469  * TODO: All this animation code could be combined much better with
00470  *       the image code.  It couldn't be done when it was written
00471  *       because it requires breaking backward compatibility.  It
00472  *       would be good to do it for 3.0.0.
00473  */
00474 GtkIMHtmlScalable *gtk_imhtml_animation_new(GdkPixbufAnimation *img, const gchar *filename, int id);
00475 
00481 /* TODO: Is there any reason this isn't private? */
00482 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale);
00483 
00489 /* TODO: Is there any reason this isn't private? */
00490 void gtk_imhtml_animation_free(GtkIMHtmlScalable *scale);
00491 
00499 /* TODO: Is there any reason this isn't private? */
00500 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height);
00501 
00509 /* TODO: Is there any reason this isn't private? */
00510 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter);
00511 
00517 GtkIMHtmlScalable *gtk_imhtml_hr_new(void);
00518 
00524 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale);
00525 
00533 void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height);
00534 
00543 void gtk_imhtml_hr_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter);
00544 
00553 gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text);
00554 
00560 void gtk_imhtml_search_clear(GtkIMHtml *imhtml);
00561 
00568 void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable);
00569 
00578 void gtk_imhtml_set_whole_buffer_formatting_only(GtkIMHtml *imhtml, gboolean wbfo);
00579 
00586 void gtk_imhtml_set_format_functions(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons);
00587 
00595 GtkIMHtmlButtons gtk_imhtml_get_format_functions(GtkIMHtml *imhtml);
00596 
00606 void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gboolean *bold, gboolean *italic, gboolean *underline);
00607 
00616 char *gtk_imhtml_get_current_fontface(GtkIMHtml *imhtml);
00617 
00626 char *gtk_imhtml_get_current_forecolor(GtkIMHtml *imhtml);
00627 
00636 char *gtk_imhtml_get_current_backcolor(GtkIMHtml *imhtml);
00637 
00646 char *gtk_imhtml_get_current_background(GtkIMHtml *imhtml);
00647 
00656 gint gtk_imhtml_get_current_fontsize(GtkIMHtml *imhtml);
00657 
00665 gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml);
00666 
00672 void gtk_imhtml_clear_formatting(GtkIMHtml *imhtml);
00673 
00679 void gtk_imhtml_toggle_bold(GtkIMHtml *imhtml);
00680 
00686 void gtk_imhtml_toggle_italic(GtkIMHtml *imhtml);
00687 
00693 void gtk_imhtml_toggle_underline(GtkIMHtml *imhtml);
00694 
00700 void gtk_imhtml_toggle_strike(GtkIMHtml *imhtml);
00701 
00711 gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color);
00712 
00722 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color);
00723 
00733 gboolean gtk_imhtml_toggle_background(GtkIMHtml *imhtml, const char *color);
00734 
00743 gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face);
00744 
00752 void gtk_imhtml_toggle_link(GtkIMHtml *imhtml, const char *url);
00753 
00762 void gtk_imhtml_insert_link(GtkIMHtml *imhtml, GtkTextMark *mark, const char *url, const char *text);
00763 
00771 void gtk_imhtml_insert_smiley(GtkIMHtml *imhtml, const char *sml, char *smiley);
00780 void gtk_imhtml_insert_smiley_at_iter(GtkIMHtml *imhtml, const char *sml, char *smiley, GtkTextIter *iter);
00781 
00790 void gtk_imhtml_insert_image_at_iter(GtkIMHtml *imhtml, int id, GtkTextIter *iter);
00791 
00798 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size);
00799 
00806 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml);
00807 
00814 void gtk_imhtml_font_grow(GtkIMHtml *imhtml);
00815 
00825 char *gtk_imhtml_get_markup_range(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end);
00826 
00834 char *gtk_imhtml_get_markup(GtkIMHtml *imhtml);
00835 
00844 char **gtk_imhtml_get_markup_lines(GtkIMHtml *imhtml);
00845 
00856 char *gtk_imhtml_get_text(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *stop);
00857 
00866 void gtk_imhtml_setup_entry(GtkIMHtml *imhtml, PurpleConnectionFlags flags);
00867 
00879 GtkIMHtmlSmiley *gtk_imhtml_smiley_create(const char *file, const char *shortcut, gboolean hide,
00880         GtkIMHtmlSmileyFlags flags);
00881 
00889 void gtk_imhtml_smiley_reload(GtkIMHtmlSmiley *smiley);
00890 
00898 void gtk_imhtml_smiley_destroy(GtkIMHtmlSmiley *smiley);
00899 
00918 gboolean gtk_imhtml_class_register_protocol(const char *name,
00919         gboolean (*activate)(GtkIMHtml *imhtml, GtkIMHtmlLink *link),
00920         gboolean (*context_menu)(GtkIMHtml *imhtml, GtkIMHtmlLink *link, GtkWidget *menu));
00921 
00931 const char *gtk_imhtml_link_get_url(GtkIMHtmlLink *link);
00932 
00942 const GtkTextTag *gtk_imhtml_link_get_text_tag(GtkIMHtmlLink *link);
00943 
00954 gboolean gtk_imhtml_link_activate(GtkIMHtmlLink *link);
00955 
00965 void gtk_imhtml_set_return_inserts_newline(GtkIMHtml *imhtml);
00966 
00975 void gtk_imhtml_set_populate_primary_clipboard(GtkIMHtml *imhtml, gboolean populate);
00976 
00979 #ifdef __cplusplus
00980 }
00981 #endif
00982 
00983 #endif /* _PIDGINIMHTML_H_ */