[anjal] Composer : Crude formatting toobar.



commit 1a1296267a2240ead842172715b1f5a3f222ebef
Author: Johnny Jacob <jjohnny novell com>
Date:   Mon Mar 23 19:59:51 2009 +0530

    Composer : Crude formatting toobar.
---
 src/simple-editor.c |  172 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 168 insertions(+), 4 deletions(-)

diff --git a/src/simple-editor.c b/src/simple-editor.c
index 9d823b4..410c6c0 100644
--- a/src/simple-editor.c
+++ b/src/simple-editor.c
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /*
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -86,37 +87,200 @@ simple_editor_class_init(SimpleEditorClass *klass)
 	g_type_class_add_private (object_class, sizeof(SimpleEditorPrivate));
 }
 
+static void
+tb_bold_cb (GtkToggleToolButton *button, SimpleEditor *editor)
+{
+	SimpleEditorPrivate *priv;
+	WebKitWebFrame *frame;
+
+	g_return_if_fail (IS_SIMPLE_EDITOR (editor));
+	priv = SIMPLE_EDITOR_GET_PRIVATE (editor);
+
+	frame = webkit_web_view_get_focused_frame (priv->editor);
+
+	if (!frame)
+		frame = webkit_web_view_get_main_frame (priv->editor);
+
+	g_return_if_fail (frame != NULL);
+
+	webkit_web_frame_execute_command (frame, "ToggleBold");
+}
+
+static void
+tb_underline_cb (GtkToggleToolButton *button, SimpleEditor *editor)
+{
+	SimpleEditorPrivate *priv;
+	WebKitWebFrame *frame;
+
+	g_return_if_fail (IS_SIMPLE_EDITOR (editor));
+	priv = SIMPLE_EDITOR_GET_PRIVATE (editor);
+
+	frame = webkit_web_view_get_focused_frame (priv->editor);
+
+	if (!frame)
+		frame = webkit_web_view_get_main_frame (priv->editor);
+
+	g_return_if_fail (frame != NULL);
+
+	webkit_web_frame_execute_command (frame, "ToggleUnderline");
+}
+
+static void
+tb_italics_cb (GtkToggleToolButton *button, SimpleEditor *editor)
+{
+	SimpleEditorPrivate *priv;
+	WebKitWebFrame *frame;
+
+	g_return_if_fail (IS_SIMPLE_EDITOR (editor));
+	priv = SIMPLE_EDITOR_GET_PRIVATE (editor);
+
+	frame = webkit_web_view_get_focused_frame (priv->editor);
+
+	if (!frame)
+		frame = webkit_web_view_get_main_frame (priv->editor);
+
+	g_return_if_fail (frame != NULL);
+
+	webkit_web_frame_execute_command (frame, "ToggleItalic");
+}
+
+static void
+tb_justify_left_cb (GtkToggleToolButton *button, SimpleEditor *editor)
+{
+	SimpleEditorPrivate *priv;
+	WebKitWebFrame *frame;
+
+	g_return_if_fail (IS_SIMPLE_EDITOR (editor));
+	priv = SIMPLE_EDITOR_GET_PRIVATE (editor);
+
+	frame = webkit_web_view_get_focused_frame (priv->editor);
+
+	if (!frame)
+		frame = webkit_web_view_get_main_frame (priv->editor);
+
+	g_return_if_fail (frame != NULL);
+
+	webkit_web_frame_execute_command (frame, "JustifyLeft");
+}
+
+static void
+tb_justify_center_cb (GtkToggleToolButton *button, SimpleEditor *editor)
+{
+	SimpleEditorPrivate *priv;
+	WebKitWebFrame *frame;
+
+	g_return_if_fail (IS_SIMPLE_EDITOR (editor));
+	priv = SIMPLE_EDITOR_GET_PRIVATE (editor);
+
+	frame = webkit_web_view_get_focused_frame (priv->editor);
+
+	if (!frame)
+		frame = webkit_web_view_get_main_frame (priv->editor);
+
+	g_return_if_fail (frame != NULL);
+
+	webkit_web_frame_execute_command (frame, "JustifyCenter");
+}
+
+static void
+tb_justify_right_cb (GtkToggleToolButton *button, SimpleEditor *editor)
+{
+	SimpleEditorPrivate *priv;
+	WebKitWebFrame *frame;
+
+	g_return_if_fail (IS_SIMPLE_EDITOR (editor));
+	priv = SIMPLE_EDITOR_GET_PRIVATE (editor);
+
+	frame = webkit_web_view_get_focused_frame (priv->editor);
+
+	if (!frame)
+		frame = webkit_web_view_get_main_frame (priv->editor);
+
+	g_return_if_fail (frame != NULL);
+
+	webkit_web_frame_execute_command (frame, "JustifyRight");
+}
+
+static void
+tb_indent_cb (GtkToggleToolButton *button, SimpleEditor *editor)
+{
+	SimpleEditorPrivate *priv;
+	WebKitWebFrame *frame;
+
+	g_return_if_fail (IS_SIMPLE_EDITOR (editor));
+	priv = SIMPLE_EDITOR_GET_PRIVATE (editor);
+
+	frame = webkit_web_view_get_focused_frame (priv->editor);
+
+	if (!frame)
+		frame = webkit_web_view_get_main_frame (priv->editor);
+
+	g_return_if_fail (frame != NULL);
+
+	webkit_web_frame_execute_command (frame, "Indent");
+}
+
+static void
+tb_outdent_cb (GtkToggleToolButton *button, SimpleEditor *editor)
+{
+	SimpleEditorPrivate *priv;
+	WebKitWebFrame *frame;
+
+	g_return_if_fail (IS_SIMPLE_EDITOR (editor));
+	priv = SIMPLE_EDITOR_GET_PRIVATE (editor);
+
+	frame = webkit_web_view_get_focused_frame (priv->editor);
+
+	if (!frame)
+		frame = webkit_web_view_get_main_frame (priv->editor);
+
+	g_return_if_fail (frame != NULL);
+
+	webkit_web_frame_execute_command (frame, "Outdent");
+}
+
 static GtkToolbar*
-simple_editor_construct_html_toolbar ()
+simple_editor_construct_html_toolbar (SimpleEditor *editor)
 {
 	GtkToolbar *toolbar;
 	GtkToolItem *item;
 
+	SimpleEditorPrivate *priv;
+
 	toolbar = gtk_toolbar_new ();
+	priv = SIMPLE_EDITOR_GET_PRIVATE (editor);
 
 	/*Create items.*/
 	item = gtk_tool_button_new_from_stock (GTK_STOCK_INDENT);
 	gtk_toolbar_insert (toolbar, item, 0);
+	g_signal_connect (item, "clicked", G_CALLBACK(tb_indent_cb), editor);
 
 	item = gtk_tool_button_new_from_stock (GTK_STOCK_UNINDENT);
 	gtk_toolbar_insert (toolbar, item, 0);
+	g_signal_connect (item, "clicked", G_CALLBACK(tb_outdent_cb), editor);
 
-	item = gtk_tool_button_new_from_stock (GTK_STOCK_JUSTIFY_LEFT);
+	item = gtk_tool_button_new_from_stock (GTK_STOCK_JUSTIFY_RIGHT);
 	gtk_toolbar_insert (toolbar, item, 0);
+	g_signal_connect (item, "clicked", G_CALLBACK(tb_justify_right_cb), editor);
 
 	item = gtk_tool_button_new_from_stock (GTK_STOCK_JUSTIFY_CENTER);
 	gtk_toolbar_insert (toolbar, item, 0);
+	g_signal_connect (item, "clicked", G_CALLBACK(tb_justify_center_cb), editor);
 
-	item = gtk_tool_button_new_from_stock (GTK_STOCK_JUSTIFY_RIGHT);
+	item = gtk_tool_button_new_from_stock (GTK_STOCK_JUSTIFY_LEFT);
 	gtk_toolbar_insert (toolbar, item, 0);
+	g_signal_connect (item, "clicked", G_CALLBACK(tb_justify_left_cb), editor);
 
 	item = gtk_tool_button_new_from_stock (GTK_STOCK_BOLD);
 	gtk_toolbar_insert (toolbar, item, 0);
+	g_signal_connect (item, "clicked", G_CALLBACK(tb_bold_cb), editor);
 
 	item = gtk_tool_button_new_from_stock (GTK_STOCK_UNDERLINE);
 	gtk_toolbar_insert (toolbar, item, 0);
+	g_signal_connect (item, "clicked", G_CALLBACK(tb_underline_cb), editor);
 
 	item = gtk_tool_button_new_from_stock (GTK_STOCK_ITALIC);
+	g_signal_connect (item, "clicked", G_CALLBACK(tb_italics_cb), editor);
 	gtk_toolbar_insert (toolbar, item, 0);
 
 	return toolbar;
@@ -147,7 +311,7 @@ simple_editor_init(SimpleEditor *editor)
 
 	gtk_widget_show (priv->editor);
 
-	priv->toolbar = simple_editor_construct_html_toolbar ();
+	priv->toolbar = simple_editor_construct_html_toolbar (editor);
 	gtk_widget_show_all (priv->toolbar);
 
 	gtk_box_pack_start (GTK_CONTAINER (editor), priv->toolbar, FALSE, TRUE, 6);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]