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/gtktextview.h>
00030 #include <gtk/gtktooltips.h>
00031 #include <gtk/gtkimage.h>
00032 #include "gtksourceundomanager.h"
00033 
00034 #include "connection.h"
00035 
00036 #ifdef __cplusplus
00037 extern "C" {
00038 #endif
00039 
00040 /**************************************************************************
00041  * @name Structures
00042  **************************************************************************/
00045 #define GTK_TYPE_IMHTML            (gtk_imhtml_get_type ())
00046 #define GTK_IMHTML(obj)            (GTK_CHECK_CAST ((obj), GTK_TYPE_IMHTML, GtkIMHtml))
00047 #define GTK_IMHTML_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_IMHTML, GtkIMHtmlClass))
00048 #define GTK_IS_IMHTML(obj)         (GTK_CHECK_TYPE ((obj), GTK_TYPE_IMHTML))
00049 #define GTK_IS_IMHTML_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_IMHTML))
00050 #define GTK_IMHTML_SCALABLE(obj)   ((GtkIMHtmlScalable *)obj)
00051 #define GTK_IMHTML_ANIMATION(obj)   ((GtkIMHtmlAnimation *)obj)
00052 
00053 typedef struct _GtkIMHtml           GtkIMHtml;
00054 typedef struct _GtkIMHtmlClass      GtkIMHtmlClass;
00055 typedef struct _GtkIMHtmlFontDetail GtkIMHtmlFontDetail;    /* The five elements contained in a FONT tag */
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 
00064 typedef enum {
00065     GTK_IMHTML_BOLD =       1 << 0,
00066     GTK_IMHTML_ITALIC =     1 << 1,
00067     GTK_IMHTML_UNDERLINE =  1 << 2,
00068     GTK_IMHTML_GROW =       1 << 3,
00069     GTK_IMHTML_SHRINK =     1 << 4,
00070     GTK_IMHTML_FACE =       1 << 5,
00071     GTK_IMHTML_FORECOLOR =  1 << 6,
00072     GTK_IMHTML_BACKCOLOR =  1 << 7,
00073     GTK_IMHTML_BACKGROUND = 1 << 8,
00074     GTK_IMHTML_LINK =       1 << 9,
00075     GTK_IMHTML_IMAGE =      1 << 10,
00076     GTK_IMHTML_SMILEY =     1 << 11,
00077     GTK_IMHTML_LINKDESC =   1 << 12,
00078     GTK_IMHTML_STRIKE =     1 << 13,
00080     GTK_IMHTML_CUSTOM_SMILEY = 1 << 14,
00081     GTK_IMHTML_ALL =       -1
00082 } GtkIMHtmlButtons;
00083 
00084 typedef enum {
00085     GTK_IMHTML_SMILEY_CUSTOM =  1 << 0
00086 } GtkIMHtmlSmileyFlags;
00087 
00088 struct _GtkIMHtml {
00089     GtkTextView text_view;
00090     GtkTextBuffer *text_buffer;
00091     GdkCursor *hand_cursor;
00092     GdkCursor *arrow_cursor;
00093     GdkCursor *text_cursor;
00094     GHashTable *smiley_data;
00095     GtkSmileyTree *default_smilies;
00096     char *protocol_name;
00097     guint scroll_src;
00098     GTimer *scroll_time;
00099     GQueue *animations;
00100     int num_animations;
00101 
00102     gboolean show_comments;
00103 
00104     GtkWidget *tip_window;
00105     char *tip;
00106     guint tip_timer;
00107     GtkTextTag *prelit_tag;
00108 
00109     GList *scalables;
00110     GdkRectangle old_rect;
00111 
00112     gchar *search_string;
00113 
00114     gboolean editable;
00115     GtkIMHtmlButtons format_functions;
00116     gboolean wbfo;  /* Whole buffer formatting only. */
00117 
00118     gint insert_offset;
00119 
00120     struct {
00121         gboolean bold:1;
00122         gboolean italic:1;
00123         gboolean underline:1;
00124         gboolean strike:1;
00125         gchar *forecolor;
00126         gchar *backcolor;
00127         gchar *background;
00128         gchar *fontface;
00129         int fontsize;
00130         GtkTextTag *link;
00131     } edit;
00132 
00133 #if !(defined PIDGIN_DISABLE_DEPRECATED) || (defined _PIDGIN_GTKIMHTML_C_)
00134 
00135     char *clipboard_text_string;
00137     char *clipboard_html_string;
00138 #else
00139     char *depr1;
00140     char *depr2;
00141 #endif
00142 
00143     GSList *im_images;
00144     GtkIMHtmlFuncs *funcs;
00145     GtkSourceUndoManager *undo_manager;
00146 };
00147 
00148 struct _GtkIMHtmlClass {
00149     GtkTextViewClass parent_class;
00150 
00151     void (*url_clicked)(GtkIMHtml *, const gchar *);
00152     void (*buttons_update)(GtkIMHtml *, GtkIMHtmlButtons);
00153     void (*toggle_format)(GtkIMHtml *, GtkIMHtmlButtons);
00154     void (*clear_format)(GtkIMHtml *);
00155     void (*update_format)(GtkIMHtml *);
00156     gboolean (*message_send)(GtkIMHtml *);
00157     void (*undo)(GtkIMHtml *);
00158     void (*redo)(GtkIMHtml *);
00159 };
00160 
00161 struct _GtkIMHtmlFontDetail {
00162     gushort size;
00163     gchar *face;
00164     gchar *fore;
00165     gchar *back;
00166     gchar *bg;
00167     gchar *sml;
00168     gboolean underline;
00169     gshort bold;
00170 };
00171 
00172 struct _GtkSmileyTree {
00173     GString *values;
00174     GtkSmileyTree **children;
00175     GtkIMHtmlSmiley *image;
00176 };
00177 
00178 struct _GtkIMHtmlSmiley {
00179     gchar *smile;
00180     gchar *file;
00181     GdkPixbufAnimation *icon;
00182     gboolean hidden;
00183     GdkPixbufLoader *loader;
00184     GSList *anchors;
00185     GtkIMHtmlSmileyFlags flags;
00186     GtkIMHtml *imhtml;
00187 };
00188 
00189 struct _GtkIMHtmlScalable {
00190     void (*scale)(struct _GtkIMHtmlScalable *, int, int);
00191     void (*add_to)(struct _GtkIMHtmlScalable *, GtkIMHtml *, GtkTextIter *);
00192     void (*free)(struct _GtkIMHtmlScalable *);
00193 };
00194 
00195 struct _GtkIMHtmlImage {
00196     GtkIMHtmlScalable scalable;
00197     GtkImage *image; 
00198     GdkPixbuf *pixbuf; 
00199     GtkTextMark *mark;
00200     gchar *filename;
00201     int width;
00202     int height;
00203     int id;
00204     GtkWidget *filesel;
00205 };
00206 
00207 struct _GtkIMHtmlAnimation {
00208     GtkIMHtmlImage imhtmlimage;
00209     GdkPixbufAnimation *anim; 
00210     GdkPixbufAnimationIter *iter;
00211     guint timer;
00212 };
00213 
00214 struct _GtkIMHtmlHr {
00215     GtkIMHtmlScalable scalable;
00216     GtkWidget *sep;
00217 };
00218 
00219 typedef enum {
00220     GTK_IMHTML_NO_COLOURS          = 1 << 0,
00221     GTK_IMHTML_NO_FONTS            = 1 << 1,
00222     GTK_IMHTML_NO_COMMENTS         = 1 << 2, /* Remove */
00223     GTK_IMHTML_NO_TITLE            = 1 << 3,
00224     GTK_IMHTML_NO_NEWLINE          = 1 << 4,
00225     GTK_IMHTML_NO_SIZES            = 1 << 5,
00226     GTK_IMHTML_NO_SCROLL           = 1 << 6,
00227     GTK_IMHTML_RETURN_LOG          = 1 << 7,
00228     GTK_IMHTML_USE_POINTSIZE       = 1 << 8,
00229     GTK_IMHTML_NO_FORMATTING       = 1 << 9,
00230     GTK_IMHTML_USE_SMOOTHSCROLLING = 1 << 10,
00231     GTK_IMHTML_NO_SMILEY           = 1 << 11,
00232 } GtkIMHtmlOptions;
00233 
00234 enum {
00235     GTK_IMHTML_DRAG_URL = 0,
00236     GTK_IMHTML_DRAG_HTML,
00237     GTK_IMHTML_DRAG_UTF8_STRING,
00238     GTK_IMHTML_DRAG_COMPOUND_TEXT,
00239     GTK_IMHTML_DRAG_STRING,
00240     GTK_IMHTML_DRAG_TEXT,
00241     GTK_IMHTML_DRAG_NUM
00242 };
00243 
00244 #define GTK_IMHTML_DND_TARGETS  \
00245     { "text/uri-list", 0, GTK_IMHTML_DRAG_URL }, \
00246     { "_NETSCAPE_URL", 0, GTK_IMHTML_DRAG_URL }, \
00247     { "text/html", 0, GTK_IMHTML_DRAG_HTML }, \
00248     { "x-url/ftp", 0, GTK_IMHTML_DRAG_URL }, \
00249     { "x-url/http", 0, GTK_IMHTML_DRAG_URL }, \
00250     { "UTF8_STRING", 0, GTK_IMHTML_DRAG_UTF8_STRING }, \
00251     { "COMPOUND_TEXT", 0, GTK_IMHTML_DRAG_COMPOUND_TEXT }, \
00252     { "STRING", 0, GTK_IMHTML_DRAG_STRING }, \
00253     { "text/plain", 0, GTK_IMHTML_DRAG_TEXT }, \
00254     { "TEXT", 0, GTK_IMHTML_DRAG_TEXT }
00255 
00256 typedef gpointer    (*GtkIMHtmlGetImageFunc)        (int id);
00257 typedef gpointer    (*GtkIMHtmlGetImageDataFunc)    (gpointer i);
00258 typedef size_t      (*GtkIMHtmlGetImageSizeFunc)    (gpointer i);
00259 typedef const char *(*GtkIMHtmlGetImageFilenameFunc)(gpointer i);
00260 typedef void        (*GtkIMHtmlImageRefFunc)        (int id);
00261 typedef void        (*GtkIMHtmlImageUnrefFunc)      (int id);
00262 
00263 struct _GtkIMHtmlFuncs {
00264     GtkIMHtmlGetImageFunc image_get;
00265     GtkIMHtmlGetImageDataFunc image_get_data;
00266     GtkIMHtmlGetImageSizeFunc image_get_size;
00267     GtkIMHtmlGetImageFilenameFunc image_get_filename;
00268     GtkIMHtmlImageRefFunc image_ref;
00269     GtkIMHtmlImageUnrefFunc image_unref;
00270 };
00271 
00274 /**************************************************************************
00275  * @name GTK+ IM/HTML rendering component API
00276  **************************************************************************/
00284 GType gtk_imhtml_get_type(void);
00285 
00291 GtkWidget *gtk_imhtml_new(void *, void *);
00292 
00301 GtkIMHtmlSmiley *gtk_imhtml_smiley_get(GtkIMHtml * imhtml,
00302                                         const gchar * sml, const gchar * text);
00303 
00304 
00312 void gtk_imhtml_associate_smiley(GtkIMHtml *imhtml, const gchar *sml, GtkIMHtmlSmiley *smiley);
00313 
00319 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml);
00320 
00327 void gtk_imhtml_set_funcs(GtkIMHtml *imhtml, GtkIMHtmlFuncs *f);
00328 
00335 void gtk_imhtml_show_comments(GtkIMHtml *imhtml, gboolean show);
00336 
00342 const char *gtk_imhtml_get_protocol_name(GtkIMHtml *imhtml);
00343 
00350 void gtk_imhtml_set_protocol_name(GtkIMHtml *imhtml, const gchar *protocol_name);
00351 
00359 #define gtk_imhtml_append_text(imhtml, text, options) \
00360  gtk_imhtml_append_text_with_images(imhtml, text, options, NULL)
00361 
00370 void gtk_imhtml_append_text_with_images(GtkIMHtml *imhtml,
00371                                          const gchar *text,
00372                                          GtkIMHtmlOptions options,
00373                                          GSList *unused);
00374 
00383 void gtk_imhtml_insert_html_at_iter(GtkIMHtml        *imhtml,
00384                                     const gchar      *text,
00385                                     GtkIMHtmlOptions  options,
00386                                     GtkTextIter      *iter);
00387 
00394 void gtk_imhtml_scroll_to_end(GtkIMHtml *imhtml, gboolean smooth);
00395 
00403 void gtk_imhtml_delete(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end);
00404 
00410 #define gtk_imhtml_clear(imhtml) \
00411  gtk_imhtml_delete(imhtml, NULL, NULL)
00412 
00418 void gtk_imhtml_page_up(GtkIMHtml *imhtml);
00419 
00425 void gtk_imhtml_page_down(GtkIMHtml *imhtml);
00426 
00432 GtkIMHtmlScalable *gtk_imhtml_scalable_new(void);
00433 
00443 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename, int id);
00444 
00457 /*
00458  * TODO: All this animation code could be combined much better with
00459  *       the image code.  It couldn't be done when it was written
00460  *       because it requires breaking backward compatibility.  It
00461  *       would be good to do it for 3.0.0.
00462  */
00463 GtkIMHtmlScalable *gtk_imhtml_animation_new(GdkPixbufAnimation *img, const gchar *filename, int id);
00464 
00470 /* TODO: Is there any reason this isn't private? */
00471 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale);
00472 
00478 /* TODO: Is there any reason this isn't private? */
00479 void gtk_imhtml_animation_free(GtkIMHtmlScalable *scale);
00480 
00488 /* TODO: Is there any reason this isn't private? */
00489 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height);
00490 
00498 /* TODO: Is there any reason this isn't private? */
00499 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter);
00500 
00506 GtkIMHtmlScalable *gtk_imhtml_hr_new(void);
00507 
00513 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale);
00514 
00522 void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height);
00523 
00532 void gtk_imhtml_hr_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter);
00533 
00542 gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text);
00543 
00549 void gtk_imhtml_search_clear(GtkIMHtml *imhtml);
00550 
00557 void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable);
00558 
00567 void gtk_imhtml_set_whole_buffer_formatting_only(GtkIMHtml *imhtml, gboolean wbfo);
00568 
00575 void gtk_imhtml_set_format_functions(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons);
00576 
00584 GtkIMHtmlButtons gtk_imhtml_get_format_functions(GtkIMHtml *imhtml);
00585 
00595 void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gboolean *bold, gboolean *italic, gboolean *underline);
00596 
00605 char *gtk_imhtml_get_current_fontface(GtkIMHtml *imhtml);
00606 
00615 char *gtk_imhtml_get_current_forecolor(GtkIMHtml *imhtml);
00616 
00625 char *gtk_imhtml_get_current_backcolor(GtkIMHtml *imhtml);
00626 
00635 char *gtk_imhtml_get_current_background(GtkIMHtml *imhtml);
00636 
00645 gint gtk_imhtml_get_current_fontsize(GtkIMHtml *imhtml);
00646 
00654 gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml);
00655 
00661 void gtk_imhtml_clear_formatting(GtkIMHtml *imhtml);
00662 
00668 void gtk_imhtml_toggle_bold(GtkIMHtml *imhtml);
00669 
00675 void gtk_imhtml_toggle_italic(GtkIMHtml *imhtml);
00676 
00682 void gtk_imhtml_toggle_underline(GtkIMHtml *imhtml);
00683 
00689 void gtk_imhtml_toggle_strike(GtkIMHtml *imhtml);
00690 
00700 gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color);
00701 
00711 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color);
00712 
00722 gboolean gtk_imhtml_toggle_background(GtkIMHtml *imhtml, const char *color);
00723 
00732 gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face);
00733 
00741 void gtk_imhtml_toggle_link(GtkIMHtml *imhtml, const char *url);
00742 
00751 void gtk_imhtml_insert_link(GtkIMHtml *imhtml, GtkTextMark *mark, const char *url, const char *text);
00752 
00760 void gtk_imhtml_insert_smiley(GtkIMHtml *imhtml, const char *sml, char *smiley);
00769 void gtk_imhtml_insert_smiley_at_iter(GtkIMHtml *imhtml, const char *sml, char *smiley, GtkTextIter *iter);
00770 
00779 void gtk_imhtml_insert_image_at_iter(GtkIMHtml *imhtml, int id, GtkTextIter *iter);
00780 
00787 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size);
00788 
00795 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml);
00796 
00803 void gtk_imhtml_font_grow(GtkIMHtml *imhtml);
00804 
00814 char *gtk_imhtml_get_markup_range(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end);
00815 
00823 char *gtk_imhtml_get_markup(GtkIMHtml *imhtml);
00824 
00833 char **gtk_imhtml_get_markup_lines(GtkIMHtml *imhtml);
00834 
00845 char *gtk_imhtml_get_text(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *stop);
00846 
00855 void gtk_imhtml_setup_entry(GtkIMHtml *imhtml, PurpleConnectionFlags flags);
00856 
00868 GtkIMHtmlSmiley *gtk_imhtml_smiley_create(const char *file, const char *shortcut, gboolean hide,
00869         GtkIMHtmlSmileyFlags flags);
00870 
00878 void gtk_imhtml_smiley_reload(GtkIMHtmlSmiley *smiley);
00879 
00887 void gtk_imhtml_smiley_destroy(GtkIMHtmlSmiley *smiley);
00890 #ifdef __cplusplus
00891 }
00892 #endif
00893 
00894 #endif /* _PIDGINIMHTML_H_ */