pidgin: 682b715d: Copy some editing functions from GtkIMHt...
qulogic at pidgin.im
qulogic at pidgin.im
Thu Jan 5 23:00:56 EST 2012
----------------------------------------------------------------------
Revision: 682b715d714a9d2ff56cd63776cc92365ecadf4b
Parent: 3afac25cbbb20ab81fe5ab388a8e529090591d60
Author: qulogic at pidgin.im
Date: 01/04/12 04:20:44
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/682b715d714a9d2ff56cd63776cc92365ecadf4b
Changelog:
Copy some editing functions from GtkIMHtml. These are incomplete.
They are mostly just stubs that change private variables, but don't
actually modify the WebView.
Changes against parent 3afac25cbbb20ab81fe5ab388a8e529090591d60
patched pidgin/gtkwebview.c
patched pidgin/gtkwebview.h
-------------- next part --------------
============================================================
--- pidgin/gtkwebview.c 90960b5b8406d873b4325b9f309682436ce0a73b
+++ pidgin/gtkwebview.c c677e914c56ca30e3489c48811a68fa578afe36b
@@ -30,6 +30,7 @@
#include "gtkwebview.h"
+#define MAX_FONT_SIZE 7
#define MAX_SCROLL_TIME 0.4 /* seconds */
#define SCROLL_DELAY 33 /* milliseconds */
@@ -52,6 +53,23 @@ typedef struct _GtkWebViewPriv {
GtkAdjustment *vadj;
guint scroll_src;
GTimer *scroll_time;
+
+ /* Format options */
+ GtkWebViewButtons format_functions;
+ struct {
+ gboolean wbfo:1; /* Whole buffer formatting only. */
+ gboolean bold:1;
+ gboolean italic:1;
+ gboolean underline:1;
+ gboolean strike:1;
+ gchar *forecolor;
+ gchar *backcolor;
+ gchar *background;
+ gchar *fontface;
+ int fontsize;
+ /*GtkTextTag *link;*/
+ } edit;
+
} GtkWebViewPriv;
/******************************************************************************
@@ -503,3 +521,190 @@ void gtk_webview_page_down(GtkWebView *w
gtk_adjustment_set_value(vadj, scroll_val);
}
+void
+gtk_webview_set_editable(GtkWebView *webview, gboolean editable)
+{
+ webkit_web_view_set_editable(WEBKIT_WEB_VIEW(webview), editable);
+}
+
+void
+gtk_webview_set_whole_buffer_formatting_only(GtkWebView *webview, gboolean wbfo)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ priv->edit.wbfo = wbfo;
+}
+
+void
+gtk_webview_set_format_functions(GtkWebView *webview, GtkWebViewButtons buttons)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ priv->format_functions = buttons;
+}
+
+GtkWebViewButtons
+gtk_webview_get_format_functions(GtkWebView *webview)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ return priv->format_functions;
+}
+
+void
+gtk_webview_get_current_format(GtkWebView *webview, gboolean *bold,
+ gboolean *italic, gboolean *underline,
+ gboolean *strike)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ if (bold)
+ *bold = priv->edit.bold;
+ if (italic)
+ *italic = priv->edit.italic;
+ if (underline)
+ *underline = priv->edit.underline;
+ if (strike)
+ *strike = priv->edit.strike;
+}
+
+const char *
+gtk_webview_get_current_fontface(GtkWebView *webview)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ return priv->edit.fontface;
+}
+
+const char *
+gtk_webview_get_current_forecolor(GtkWebView *webview)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ return priv->edit.forecolor;
+}
+
+const char *
+gtk_webview_get_current_backcolor(GtkWebView *webview)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ return priv->edit.backcolor;
+}
+
+const char *
+gtk_webview_get_current_background(GtkWebView *webview)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ return priv->edit.background;
+}
+
+gint
+gtk_webview_get_current_fontsize(GtkWebView *webview)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ return priv->edit.fontsize;
+}
+
+gboolean
+gtk_webview_get_editable(GtkWebView *webview)
+{
+ return webkit_web_view_get_editable(WEBKIT_WEB_VIEW(webview));
+}
+
+void
+gtk_webview_clear_formatting(GtkWebView *webview)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ priv->edit.bold = FALSE;
+ priv->edit.italic = FALSE;
+ priv->edit.underline = FALSE;
+ priv->edit.strike = FALSE;
+}
+
+void
+gtk_webview_toggle_bold(GtkWebView *webview)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ priv->edit.bold = !priv->edit.bold;
+}
+
+void
+gtk_webview_toggle_italic(GtkWebView *webview)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ priv->edit.italic = !priv->edit.italic;
+}
+
+void
+gtk_webview_toggle_underline(GtkWebView *webview)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ priv->edit.underline = !priv->edit.underline;
+}
+
+void
+gtk_webview_toggle_strike(GtkWebView *webview)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ priv->edit.strike = !priv->edit.strike;
+}
+
+gboolean
+gtk_webview_toggle_forecolor(GtkWebView *webview, const char *color)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+
+ g_free(priv->edit.forecolor);
+ priv->edit.forecolor = g_strdup(color);
+
+ return FALSE;
+}
+
+gboolean
+gtk_webview_toggle_backcolor(GtkWebView *webview, const char *color)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+
+ g_free(priv->edit.backcolor);
+ priv->edit.backcolor = g_strdup(color);
+
+ return FALSE;
+}
+
+gboolean
+gtk_webview_toggle_background(GtkWebView *webview, const char *color)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+
+ g_free(priv->edit.background);
+ priv->edit.background = g_strdup(color);
+
+ return FALSE;
+}
+
+gboolean
+gtk_webview_toggle_fontface(GtkWebView *webview, const char *face)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+
+ g_free(priv->edit.fontface);
+ priv->edit.fontface = g_strdup(face);
+
+ return FALSE;
+}
+
+void
+gtk_webview_font_set_size(GtkWebView *webview, gint size)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ priv->edit.fontsize = size;
+}
+
+void
+gtk_webview_font_shrink(GtkWebView *webview)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ priv->edit.fontsize = MAX(priv->edit.fontsize - 1, 1);
+}
+
+void
+gtk_webview_font_grow(GtkWebView *webview)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ priv->edit.fontsize = MIN(priv->edit.fontsize + 1, MAX_FONT_SIZE);
+}
+
============================================================
--- pidgin/gtkwebview.h 1419217d5b039d03b732682b34cea810c31d1b9b
+++ pidgin/gtkwebview.h f2b42ee6878efc969ec1702091b1ac1b1c23fe07
@@ -39,6 +39,26 @@
#define GTK_IS_WEBVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_WEBVIEW))
#define GTK_WEBVIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_WEBVIEW, GtkWebViewClass))
+typedef enum {
+ GTK_WEBVIEW_BOLD = 1 << 0,
+ GTK_WEBVIEW_ITALIC = 1 << 1,
+ GTK_WEBVIEW_UNDERLINE = 1 << 2,
+ GTK_WEBVIEW_GROW = 1 << 3,
+ GTK_WEBVIEW_SHRINK = 1 << 4,
+ GTK_WEBVIEW_FACE = 1 << 5,
+ GTK_WEBVIEW_FORECOLOR = 1 << 6,
+ GTK_WEBVIEW_BACKCOLOR = 1 << 7,
+ GTK_WEBVIEW_BACKGROUND = 1 << 8,
+ GTK_WEBVIEW_LINK = 1 << 9,
+ GTK_WEBVIEW_IMAGE = 1 << 10,
+ GTK_WEBVIEW_SMILEY = 1 << 11,
+ GTK_WEBVIEW_LINKDESC = 1 << 12,
+ GTK_WEBVIEW_STRIKE = 1 << 13,
+ /** Show custom smileys when appropriate. */
+ GTK_WEBVIEW_CUSTOM_SMILEY = 1 << 14,
+ GTK_WEBVIEW_ALL = -1
+} GtkWebViewButtons;
+
typedef struct _GtkWebView GtkWebView;
typedef struct _GtkWebViewClass GtkWebViewClass;
@@ -150,6 +170,218 @@ void gtk_webview_page_down(GtkWebView *w
*/
void gtk_webview_page_down(GtkWebView *webview);
+/**
+ * Enables or disables editing in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ * @param editable @c TRUE to make the widget editable, or @c FALSE otherwise.
+ */
+void gtk_webview_set_editable(GtkWebView *webview, gboolean editable);
+
+/**
+ * Enables or disables whole buffer formatting only (wbfo) in a GtkWebView.
+ * In this mode formatting options to the buffer take effect for the entire
+ * buffer instead of specific text.
+ *
+ * @param webview The GtkWebView
+ * @param wbfo @c TRUE to enable the mode, or @c FALSE otherwise.
+ */
+void gtk_webview_set_whole_buffer_formatting_only(GtkWebView *webview,
+ gboolean wbfo);
+
+/**
+ * Indicates which formatting functions to enable and disable in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ * @param buttons A GtkWebViewButtons bitmask indicating which functions to use
+ */
+void gtk_webview_set_format_functions(GtkWebView *webview,
+ GtkWebViewButtons buttons);
+
+/**
+ * Returns which formatting functions are enabled in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ *
+ * @return A GtkWebViewButtons bitmask indicating which functions to are enabled
+ */
+GtkWebViewButtons gtk_webview_get_format_functions(GtkWebView *webview);
+
+/**
+ * Sets each boolean to @c TRUE or @c FALSE to indicate if that formatting
+ * option is enabled at the current position in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ * @param bold The boolean to set for bold or @c NULL.
+ * @param italic The boolean to set for italic or @c NULL.
+ * @param underline The boolean to set for underline or @c NULL.
+ * @param strikethrough The boolean to set for strikethrough or @c NULL.
+ */
+void gtk_webview_get_current_format(GtkWebView *webview, gboolean *bold,
+ gboolean *italic, gboolean *underline,
+ gboolean *strike);
+
+/**
+ * Returns a string containing the selected font face at the current position
+ * in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ *
+ * @return A string containing the font face or @c NULL if none is set.
+ */
+const char *gtk_webview_get_current_fontface(GtkWebView *webview);
+
+/**
+ * Returns a string containing the selected foreground color at the current
+ * position in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ *
+ * @return A string containing the foreground color or @c NULL if none is set.
+ */
+const char *gtk_webview_get_current_forecolor(GtkWebView *webview);
+
+/**
+ * Returns a string containing the selected font background color at the current
+ * position in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ *
+ * @return A string containing the background color or @c NULL if none is set.
+ */
+const char *gtk_webview_get_current_backcolor(GtkWebView *webview);
+
+/**
+ * Returns a string containing the selected background color at the current
+ * position in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ *
+ * @return A string containg the background color or @c NULL if none is set.
+ */
+const char *gtk_webview_get_current_background(GtkWebView *webview);
+
+/**
+ * Returns a integer containing the selected HTML font size at the current
+ * position in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ *
+ * @return The HTML font size.
+ */
+gint gtk_webview_get_current_fontsize(GtkWebView *webview);
+
+/**
+ * Checks whether a GtkWebView is marked as editable.
+ *
+ * @param webview The GtkWebView
+ *
+ * @return @c TRUE if the IM/HTML is editable, or @c FALSE otherwise.
+ */
+gboolean gtk_webview_get_editable(GtkWebView *webview);
+
+/**
+ * Clear all the formatting on a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ */
+void gtk_webview_clear_formatting(GtkWebView *webview);
+
+/**
+ * Toggles bold at the cursor location or selection in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ */
+void gtk_webview_toggle_bold(GtkWebView *webview);
+
+/**
+ * Toggles italic at the cursor location or selection in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ */
+void gtk_webview_toggle_italic(GtkWebView *webview);
+
+/**
+ * Toggles underline at the cursor location or selection in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ */
+void gtk_webview_toggle_underline(GtkWebView *webview);
+
+/**
+ * Toggles strikethrough at the cursor location or selection in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ */
+void gtk_webview_toggle_strike(GtkWebView *webview);
+
+/**
+ * Toggles a foreground color at the current location or selection in a
+ * GtkWebView.
+ *
+ * @param webview The GtkWebView
+ * @param color The HTML-style color, or @c NULL or "" to clear the color.
+ *
+ * @return @c TRUE if a color was set, or @c FALSE if it was cleared.
+ */
+gboolean gtk_webview_toggle_forecolor(GtkWebView *webview, const char *color);
+
+/**
+ * Toggles a background color at the current location or selection in a
+ * GtkWebView.
+ *
+ * @param webview The GtkWebView
+ * @param color The HTML-style color, or @c NULL or "" to clear the color.
+ *
+ * @return @c TRUE if a color was set, or @c FALSE if it was cleared.
+ */
+gboolean gtk_webview_toggle_backcolor(GtkWebView *webview, const char *color);
+
+/**
+ * Toggles a background color at the current location or selection in a
+ * GtkWebView.
+ *
+ * @param webview The GtkWebView
+ * @param color The HTML-style color, or @c NULL or "" to clear the color.
+ *
+ * @return @c TRUE if a color was set, or @c FALSE if it was cleared.
+ */
+gboolean gtk_webview_toggle_background(GtkWebView *webview, const char *color);
+
+/**
+ * Toggles a font face at the current location or selection in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ * @param face The font face name, or @c NULL or "" to clear the font.
+ *
+ * @return @c TRUE if a font name was set, or @c FALSE if it was cleared.
+ */
+gboolean gtk_webview_toggle_fontface(GtkWebView *webview, const char *face);
+
+/**
+ * Sets the font size at the current location or selection in a GtkWebView.
+ *
+ * @param webview The GtkWebView
+ * @param size The HTML font size to use.
+ */
+void gtk_webview_font_set_size(GtkWebView *webview, gint size);
+
+/**
+ * Decreases the font size by 1 at the current location or selection in a
+ * GtkWebView.
+ *
+ * @param webview The GtkWebView
+ */
+void gtk_webview_font_shrink(GtkWebView *webview);
+
+/**
+ * Increases the font size by 1 at the current location or selection in a
+ * GtkWebView.
+ *
+ * @param webview The GtkWebView
+ */
+void gtk_webview_font_grow(GtkWebView *webview);
+
G_END_DECLS
#endif /* _PIDGIN_WEBVIEW_H_ */
More information about the Commits
mailing list