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,
00079     GTK_IMHTML_ALL =       -1
00080 } GtkIMHtmlButtons;
00081 
00082 typedef enum {
00083     GTK_IMHTML_SMILEY_CUSTOM =  1 << 0
00084 } GtkIMHtmlSmileyFlags;
00085 
00086 struct _GtkIMHtml {
00087     GtkTextView text_view;
00088     GtkTextBuffer *text_buffer;
00089     GdkCursor *hand_cursor;
00090     GdkCursor *arrow_cursor;
00091     GdkCursor *text_cursor;
00092     GHashTable *smiley_data;
00093     GtkSmileyTree *default_smilies;
00094     char *protocol_name;
00095     guint scroll_src;
00096     GTimer *scroll_time;
00097     GQueue *animations;
00098     int num_animations;
00099 
00100     gboolean show_comments;
00101 
00102     GtkWidget *tip_window;
00103     char *tip;
00104     guint tip_timer;
00105     GtkTextTag *prelit_tag;
00106 
00107     GList *scalables;
00108     GdkRectangle old_rect;
00109 
00110     gchar *search_string;
00111 
00112     gboolean editable;
00113     GtkIMHtmlButtons format_functions;
00114     gboolean wbfo;  /* Whole buffer formatting only. */
00115 
00116     gint insert_offset;
00117 
00118     struct {
00119         gboolean bold:1;
00120         gboolean italic:1;
00121         gboolean underline:1;
00122         gboolean strike:1;
00123         gchar *forecolor;
00124         gchar *backcolor;
00125         gchar *background;
00126         gchar *fontface;
00127         int fontsize;
00128         GtkTextTag *link;
00129     } edit;
00130 
00131 #ifndef PIDGIN_DISABLE_DEPRECATED
00132 
00133     char *clipboard_text_string;
00135     char *clipboard_html_string;
00136 #else
00137     char *depr1;
00138     char *depr2;
00139 #endif
00140 
00141     GSList *im_images;
00142     GtkIMHtmlFuncs *funcs;
00143     GtkSourceUndoManager *undo_manager;
00144 };
00145 
00146 struct _GtkIMHtmlClass {
00147     GtkTextViewClass parent_class;
00148 
00149     void (*url_clicked)(GtkIMHtml *, const gchar *);
00150     void (*buttons_update)(GtkIMHtml *, GtkIMHtmlButtons);
00151     void (*toggle_format)(GtkIMHtml *, GtkIMHtmlButtons);
00152     void (*clear_format)(GtkIMHtml *);
00153     void (*update_format)(GtkIMHtml *);
00154     gboolean (*message_send)(GtkIMHtml *);
00155     void (*undo)(GtkIMHtml *);
00156     void (*redo)(GtkIMHtml *);
00157 };
00158 
00159 struct _GtkIMHtmlFontDetail {
00160     gushort size;
00161     gchar *face;
00162     gchar *fore;
00163     gchar *back;
00164     gchar *bg;
00165     gchar *sml;
00166     gboolean underline;
00167     gshort bold;
00168 };
00169 
00170 struct _GtkSmileyTree {
00171     GString *values;
00172     GtkSmileyTree **children;
00173     GtkIMHtmlSmiley *image;
00174 };
00175 
00176 struct _GtkIMHtmlSmiley {
00177     gchar *smile;
00178     gchar *file;
00179     GdkPixbufAnimation *icon;
00180     gboolean hidden;
00181     GdkPixbufLoader *loader;
00182     GSList *anchors;
00183     GtkIMHtmlSmileyFlags flags;
00184     GtkIMHtml *imhtml;
00185 };
00186 
00187 struct _GtkIMHtmlScalable {
00188     void (*scale)(struct _GtkIMHtmlScalable *, int, int);
00189     void (*add_to)(struct _GtkIMHtmlScalable *, GtkIMHtml *, GtkTextIter *);
00190     void (*free)(struct _GtkIMHtmlScalable *);
00191 };
00192 
00193 struct _GtkIMHtmlImage {
00194     GtkIMHtmlScalable scalable;
00195     GtkImage *image; 
00196     GdkPixbuf *pixbuf; 
00197     GtkTextMark *mark;
00198     gchar *filename;
00199     int width;
00200     int height;
00201     int id;
00202     GtkWidget *filesel;
00203 };
00204 
00205 struct _GtkIMHtmlAnimation {
00206     GtkIMHtmlImage imhtmlimage;
00207     GdkPixbufAnimation *anim; 
00208     GdkPixbufAnimationIter *iter;
00209     guint timer;
00210 };
00211 
00212 struct _GtkIMHtmlHr {
00213     GtkIMHtmlScalable scalable;
00214     GtkWidget *sep;
00215 };
00216 
00217 typedef enum {
00218     GTK_IMHTML_NO_COLOURS          = 1 << 0,
00219     GTK_IMHTML_NO_FONTS            = 1 << 1,
00220     GTK_IMHTML_NO_COMMENTS         = 1 << 2, /* Remove */
00221     GTK_IMHTML_NO_TITLE            = 1 << 3,
00222     GTK_IMHTML_NO_NEWLINE          = 1 << 4,
00223     GTK_IMHTML_NO_SIZES            = 1 << 5,
00224     GTK_IMHTML_NO_SCROLL           = 1 << 6,
00225     GTK_IMHTML_RETURN_LOG          = 1 << 7,
00226     GTK_IMHTML_USE_POINTSIZE       = 1 << 8,
00227     GTK_IMHTML_NO_FORMATTING       = 1 << 9,
00228     GTK_IMHTML_USE_SMOOTHSCROLLING = 1 << 10,
00229     GTK_IMHTML_NO_SMILEY           = 1 << 11,
00230 } GtkIMHtmlOptions;
00231 
00232 enum {
00233     GTK_IMHTML_DRAG_URL = 0,
00234     GTK_IMHTML_DRAG_HTML,
00235     GTK_IMHTML_DRAG_UTF8_STRING,
00236     GTK_IMHTML_DRAG_COMPOUND_TEXT,
00237     GTK_IMHTML_DRAG_STRING,
00238     GTK_IMHTML_DRAG_TEXT,
00239     GTK_IMHTML_DRAG_NUM
00240 };
00241 
00242 #define GTK_IMHTML_DND_TARGETS  \
00243     { "text/uri-list", 0, GTK_IMHTML_DRAG_URL }, \
00244     { "_NETSCAPE_URL", 0, GTK_IMHTML_DRAG_URL }, \
00245     { "text/html", 0, GTK_IMHTML_DRAG_HTML }, \
00246     { "x-url/ftp", 0, GTK_IMHTML_DRAG_URL }, \
00247     { "x-url/http", 0, GTK_IMHTML_DRAG_URL }, \
00248     { "UTF8_STRING", 0, GTK_IMHTML_DRAG_UTF8_STRING }, \
00249     { "COMPOUND_TEXT", 0, GTK_IMHTML_DRAG_COMPOUND_TEXT }, \
00250     { "STRING", 0, GTK_IMHTML_DRAG_STRING }, \
00251     { "text/plain", 0, GTK_IMHTML_DRAG_TEXT }, \
00252     { "TEXT", 0, GTK_IMHTML_DRAG_TEXT }
00253 
00254 typedef gpointer    (*GtkIMHtmlGetImageFunc)        (int id);
00255 typedef gpointer    (*GtkIMHtmlGetImageDataFunc)    (gpointer i);
00256 typedef size_t      (*GtkIMHtmlGetImageSizeFunc)    (gpointer i);
00257 typedef const char *(*GtkIMHtmlGetImageFilenameFunc)(gpointer i);
00258 typedef void        (*GtkIMHtmlImageRefFunc)        (int id);
00259 typedef void        (*GtkIMHtmlImageUnrefFunc)      (int id);
00260 
00261 struct _GtkIMHtmlFuncs {
00262     GtkIMHtmlGetImageFunc image_get;
00263     GtkIMHtmlGetImageDataFunc image_get_data;
00264     GtkIMHtmlGetImageSizeFunc image_get_size;
00265     GtkIMHtmlGetImageFilenameFunc image_get_filename;
00266     GtkIMHtmlImageRefFunc image_ref;
00267     GtkIMHtmlImageUnrefFunc image_unref;
00268 };
00269 
00272 /**************************************************************************
00273  * @name GTK+ IM/HTML rendering component API
00274  **************************************************************************/
00282 GType gtk_imhtml_get_type(void);
00283 
00289 GtkWidget *gtk_imhtml_new(void *, void *);
00290 
00299 GtkIMHtmlSmiley *gtk_imhtml_smiley_get(GtkIMHtml * imhtml,
00300                                         const gchar * sml, const gchar * text);
00301 
00302 
00310 void gtk_imhtml_associate_smiley(GtkIMHtml *imhtml, const gchar *sml, GtkIMHtmlSmiley *smiley);
00311 
00317 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml);
00318 
00325 void gtk_imhtml_set_funcs(GtkIMHtml *imhtml, GtkIMHtmlFuncs *f);
00326 
00333 void gtk_imhtml_show_comments(GtkIMHtml *imhtml, gboolean show);
00334 
00340 const char *gtk_imhtml_get_protocol_name(GtkIMHtml *imhtml);
00341 
00348 void gtk_imhtml_set_protocol_name(GtkIMHtml *imhtml, const gchar *protocol_name);
00349 
00357 #define gtk_imhtml_append_text(imhtml, text, options) \
00358  gtk_imhtml_append_text_with_images(imhtml, text, options, NULL)
00359 
00368 void gtk_imhtml_append_text_with_images(GtkIMHtml *imhtml,
00369                                          const gchar *text,
00370                                          GtkIMHtmlOptions options,
00371                                          GSList *unused);
00372 
00381 void gtk_imhtml_insert_html_at_iter(GtkIMHtml        *imhtml,
00382                                     const gchar      *text,
00383                                     GtkIMHtmlOptions  options,
00384                                     GtkTextIter      *iter);
00385 
00392 void gtk_imhtml_scroll_to_end(GtkIMHtml *imhtml, gboolean smooth);
00393 
00401 void gtk_imhtml_delete(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end);
00402 
00408 #define gtk_imhtml_clear(imhtml) \
00409  gtk_imhtml_delete(imhtml, NULL, NULL)
00410 
00416 void gtk_imhtml_page_up(GtkIMHtml *imhtml);
00417 
00423 void gtk_imhtml_page_down(GtkIMHtml *imhtml);
00424 
00430 GtkIMHtmlScalable *gtk_imhtml_scalable_new(void);
00431 
00441 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename, int id);
00442 
00455 /*
00456  * TODO: All this animation code could be combined much better with
00457  *       the image code.  It couldn't be done when it was written
00458  *       because it requires breaking backward compatibility.  It
00459  *       would be good to do it for 3.0.0.
00460  */
00461 GtkIMHtmlScalable *gtk_imhtml_animation_new(GdkPixbufAnimation *img, const gchar *filename, int id);
00462 
00468 /* TODO: Is there any reason this isn't private? */
00469 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale);
00470 
00476 /* TODO: Is there any reason this isn't private? */
00477 void gtk_imhtml_animation_free(GtkIMHtmlScalable *scale);
00478 
00486 /* TODO: Is there any reason this isn't private? */
00487 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height);
00488 
00496 /* TODO: Is there any reason this isn't private? */
00497 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter);
00498 
00504 GtkIMHtmlScalable *gtk_imhtml_hr_new(void);
00505 
00511 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale);
00512 
00520 void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height);
00521 
00530 void gtk_imhtml_hr_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter);
00531 
00540 gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text);
00541 
00547 void gtk_imhtml_search_clear(GtkIMHtml *imhtml);
00548 
00555 void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable);
00556 
00565 void gtk_imhtml_set_whole_buffer_formatting_only(GtkIMHtml *imhtml, gboolean wbfo);
00566 
00573 void gtk_imhtml_set_format_functions(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons);
00574 
00582 GtkIMHtmlButtons gtk_imhtml_get_format_functions(GtkIMHtml *imhtml);
00583 
00593 void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gboolean *bold, gboolean *italic, gboolean *underline);
00594 
00603 char *gtk_imhtml_get_current_fontface(GtkIMHtml *imhtml);
00604 
00613 char *gtk_imhtml_get_current_forecolor(GtkIMHtml *imhtml);
00614 
00623 char *gtk_imhtml_get_current_backcolor(GtkIMHtml *imhtml);
00624 
00633 char *gtk_imhtml_get_current_background(GtkIMHtml *imhtml);
00634 
00643 gint gtk_imhtml_get_current_fontsize(GtkIMHtml *imhtml);
00644 
00652 gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml);
00653 
00659 void gtk_imhtml_clear_formatting(GtkIMHtml *imhtml);
00660 
00666 void gtk_imhtml_toggle_bold(GtkIMHtml *imhtml);
00667 
00673 void gtk_imhtml_toggle_italic(GtkIMHtml *imhtml);
00674 
00680 void gtk_imhtml_toggle_underline(GtkIMHtml *imhtml);
00681 
00687 void gtk_imhtml_toggle_strike(GtkIMHtml *imhtml);
00688 
00698 gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color);
00699 
00709 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color);
00710 
00720 gboolean gtk_imhtml_toggle_background(GtkIMHtml *imhtml, const char *color);
00721 
00730 gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face);
00731 
00739 void gtk_imhtml_toggle_link(GtkIMHtml *imhtml, const char *url);
00740 
00749 void gtk_imhtml_insert_link(GtkIMHtml *imhtml, GtkTextMark *mark, const char *url, const char *text);
00750 
00758 void gtk_imhtml_insert_smiley(GtkIMHtml *imhtml, const char *sml, char *smiley);
00767 void gtk_imhtml_insert_smiley_at_iter(GtkIMHtml *imhtml, const char *sml, char *smiley, GtkTextIter *iter);
00768 
00777 void gtk_imhtml_insert_image_at_iter(GtkIMHtml *imhtml, int id, GtkTextIter *iter);
00778 
00785 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size);
00786 
00793 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml);
00794 
00801 void gtk_imhtml_font_grow(GtkIMHtml *imhtml);
00802 
00812 char *gtk_imhtml_get_markup_range(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end);
00813 
00821 char *gtk_imhtml_get_markup(GtkIMHtml *imhtml);
00822 
00831 char **gtk_imhtml_get_markup_lines(GtkIMHtml *imhtml);
00832 
00843 char *gtk_imhtml_get_text(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *stop);
00844 
00853 void gtk_imhtml_setup_entry(GtkIMHtml *imhtml, PurpleConnectionFlags flags);
00854 
00857 #ifdef __cplusplus
00858 }
00859 #endif
00860 
00861 #endif /* _PIDGINIMHTML_H_ */