changeset 32450:0d50155445fd

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.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Wed, 04 Jan 2012 09:20:44 +0000
parents 692d5408983d
children a803139fc875
files pidgin/gtkwebview.c pidgin/gtkwebview.h
diffstat 2 files changed, 437 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkwebview.c	Wed Jan 04 06:30:51 2012 +0000
+++ b/pidgin/gtkwebview.c	Wed Jan 04 09:20:44 2012 +0000
@@ -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 @@
 	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 @@
 	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);
+}
+
--- a/pidgin/gtkwebview.h	Wed Jan 04 06:30:51 2012 +0000
+++ b/pidgin/gtkwebview.h	Wed Jan 04 09:20:44 2012 +0000
@@ -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 *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_ */