static void editor_replace_all_cb (GtkhtmlEditor *editor, const gchar *correction, GtkhtmlSpellDialog *dialog) { GtkHTML *html; gchar *misspelled; html = gtkhtml_editor_get_html (editor); /* Replace this occurrence. */ misspelled = html_engine_get_spell_word (html->engine); html_engine_replace_spell_word_with (html->engine, correction); /* Replace all subsequent occurrences. */ while (gtkhtml_editor_next_spell_error (editor)) { gchar *word; word = html_engine_get_spell_word (html->engine); if (g_str_equal (word, misspelled)) html_engine_replace_spell_word_with ( html->engine, correction); g_free (word); } /* Jump to beginning of document (XXX is this right?) */ html_engine_beginning_of_document (html->engine); gtkhtml_spell_dialog_next_word (dialog); g_free (misspelled); }
static void editor_recheck_cb (GtkhtmlEditor *editor, GtkhtmlSpellDialog *dialog) { GtkHTML *html; html = gtkhtml_editor_get_html (editor); html_engine_spell_check (html->engine); }
static void editor_replace_cb (GtkhtmlEditor *editor, const gchar *correction, GtkhtmlSpellDialog *dialog) { GtkHTML *html; html = gtkhtml_editor_get_html (editor); html_engine_replace_spell_word_with (html->engine, correction); gtkhtml_spell_dialog_next_word (dialog); }
/* Action callback for context menu spelling suggestions. * XXX This should really be in gtkhtml-editor-actions.c */ static void action_context_spell_suggest_cb (GtkAction *action, GtkhtmlEditor *editor) { GtkHTML *html; const gchar *word; html = gtkhtml_editor_get_html (editor); word = g_object_get_data (G_OBJECT (action), "word"); g_return_if_fail (word != NULL); html_engine_replace_spell_word_with (html->engine, word); }
static void _save_book(EDITOR *e) { GString *string; string = g_string_sized_new(4096); gtk_html_export(gtkhtml_editor_get_html(GTKHTML_EDITOR(e->window)), "text/html", (GtkHTMLSaveReceiverFn)_save_receiver, string); main_treekey_save_book_text(e->module, e->key, string->str); g_string_free(string, TRUE); gtkhtml_editor_drop_undo(GTKHTML_EDITOR(e->window)); gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window), FALSE); }
static void editor_set_word (GtkhtmlEditor *editor, GtkhtmlSpellDialog *dialog) { GtkHTML *html; gchar *word; html = gtkhtml_editor_get_html (editor); html_engine_select_spell_word_editable (html->engine); word = html_engine_get_spell_word (html->engine); gtkhtml_spell_dialog_set_word (dialog, word); g_free (word); }
gboolean gtkhtml_editor_next_spell_error (GtkhtmlEditor *editor) { GtkHTML *html; gboolean found = FALSE; g_return_val_if_fail (GTKHTML_IS_EDITOR (editor), FALSE); html = gtkhtml_editor_get_html (editor); html_engine_disable_selection (html->engine); while (!found && html_engine_forward_word (html->engine)) found = !html_engine_spell_word_is_valid (html->engine); return found; }
static GtkPrintOperationResult print(GtkhtmlEditor *editor, GtkPrintOperationAction action) { GtkPrintOperation *operation; GtkPrintOperationResult result; GError *error = NULL; operation = gtk_print_operation_new(); result = gtk_html_print_operation_run(gtkhtml_editor_get_html(editor), operation, action, GTK_WINDOW(editor), NULL, NULL, NULL, NULL, NULL, &error); g_object_unref(operation); handle_error(&error); return result; }
static gpointer external_editor_thread (gpointer user_data) { EMsgComposer *composer = user_data; gchar *filename = NULL; gint status = 0; GSettings *settings; gchar *editor_cmd_line = NULL, *editor_cmd = NULL, *content; gint fd, position = -1, offset = -1; /* prefix temp files with evo so .*vimrc can be setup to recognize them */ fd = g_file_open_tmp ("evoXXXXXX", &filename, NULL); if (fd > 0) { gsize length = 0; close (fd); d (printf ("\n\aTemporary-file Name is : [%s] \n\a", filename)); /* Push the text (if there is one) from the composer to the file */ content = gtkhtml_editor_get_text_plain (GTKHTML_EDITOR (composer), &length); g_file_set_contents (filename, content, length, NULL); } else { struct run_error_dialog_data *data; data = g_new0 (struct run_error_dialog_data, 1); data->composer = composer; data->text = "org.gnome.evolution.plugins.external-editor:no-temp-file"; g_warning ("Temporary file fd is null"); /* run_error_dialog also calls enable_composer */ g_idle_add ((GSourceFunc) run_error_dialog, data); goto finished; } settings = g_settings_new ("org.gnome.evolution.plugin.external-editor"); editor_cmd = g_settings_get_string (settings, "command"); if (!editor_cmd) { if (!(editor_cmd = g_strdup (g_getenv ("EDITOR")))) /* Make gedit the default external editor, * if the default schemas are not installed * and no $EDITOR is set. */ editor_cmd = g_strdup ("gedit"); } g_object_unref (settings); if (g_strrstr (editor_cmd, "vim") != NULL && gtk_html_get_cursor_pos ( gtkhtml_editor_get_html ( GTKHTML_EDITOR (composer)), &position, &offset) && position >= 0 && offset >= 0) { gchar *tmp = editor_cmd; gint lineno; gboolean set_nofork; set_nofork = g_strrstr (editor_cmd, "gvim") != NULL; /* Increment 1 so that entering vim insert mode places you * in the same entry position you were at in the html. */ offset++; /* calculate the line number that the cursor is in */ lineno = numlines (content, position); editor_cmd = g_strdup_printf ( "%s \"+call cursor(%d,%d)\"%s%s", tmp, lineno, offset, set_nofork ? " " : "", set_nofork ? "--nofork" : ""); g_free (tmp); } g_free (content); editor_cmd_line = g_strconcat (editor_cmd, " ", filename, NULL); if (!g_spawn_command_line_sync (editor_cmd_line, NULL, NULL, &status, NULL)) { struct run_error_dialog_data *data; g_warning ("Unable to launch %s: ", editor_cmd_line); data = g_new0 (struct run_error_dialog_data, 1); data->composer = composer; data->text = "org.gnome.evolution.plugins.external-editor:editor-not-launchable"; /* run_error_dialog also calls enable_composer */ g_idle_add ((GSourceFunc) run_error_dialog, data); g_free (filename); g_free (editor_cmd_line); g_free (editor_cmd); goto finished; } g_free (editor_cmd_line); g_free (editor_cmd); #ifdef HAVE_SYS_WAIT_H if (WEXITSTATUS (status) != 0) { #else if (status) { #endif d (printf ("\n\nsome problem here with external editor\n\n")); g_idle_add ((GSourceFunc) enable_composer, composer); goto finished; } else { gchar *buf; if (g_file_get_contents (filename, &buf, NULL, NULL)) { gchar *htmltext; GArray *array; htmltext = camel_text_to_html ( buf, CAMEL_MIME_FILTER_TOHTML_PRE, 0); array = g_array_sized_new ( TRUE, TRUE, sizeof (gpointer), 2 * sizeof (gpointer)); array = g_array_append_val (array, composer); array = g_array_append_val (array, htmltext); g_idle_add ((GSourceFunc) update_composer_text, array); /* We no longer need that temporary file */ if (g_remove (filename) == -1) g_warning ( "%s: Failed to remove file '%s': %s", G_STRFUNC, filename, g_strerror (errno)); g_free (filename); } } finished: g_mutex_lock (&external_editor_running_lock); external_editor_running = FALSE; g_mutex_unlock (&external_editor_running_lock); return NULL; } static void launch_editor (GtkAction *action, EMsgComposer *composer) { d (printf ("\n\nexternal_editor plugin is launched \n\n")); if (editor_running ()) { d (printf ("not opening editor, because it's still running\n")); return; } disable_composer (composer); g_mutex_lock (&external_editor_running_lock); external_editor_running = TRUE; g_mutex_unlock (&external_editor_running_lock); editor_thread = g_thread_new ( NULL, external_editor_thread, composer); g_thread_unref (editor_thread); }
GtkWidget *editor_new(const gchar *title, EDITOR *e) { GtkActionGroup *action_group; GtkUIManager *manager; GtkWidget *editor; GError *error = NULL; editor = gtkhtml_editor_new(); e->window = editor; e->html_widget = GTK_WIDGET(gtkhtml_editor_get_html(GTKHTML_EDITOR(editor))); gtk_window_set_title(GTK_WINDOW(editor), title); set_window_icon(GTK_WINDOW(editor)); manager = gtkhtml_editor_get_ui_manager(GTKHTML_EDITOR(editor)); if (e->type == STUDYPAD_EDITOR) gtk_ui_manager_add_ui_from_string(manager, file_ui, -1, &error); else gtk_ui_manager_add_ui_from_string(manager, note_file_ui, -1, &error); handle_error(&error); gtk_ui_manager_add_ui_from_string(manager, view_ui, -1, &error); handle_error(&error); if (e->type == STUDYPAD_EDITOR) gtk_ui_manager_add_ui_from_string(manager, main_ui_studypad, -1, &error); else gtk_ui_manager_add_ui_from_string(manager, main_ui_note, -1, &error); handle_error(&error); action_group = gtk_action_group_new("file"); gtk_action_group_set_translation_domain(action_group, GETTEXT_PACKAGE); gtk_action_group_add_actions(action_group, file_entries, G_N_ELEMENTS(file_entries), e); gtk_ui_manager_insert_action_group(manager, action_group, 0); action_group = gtk_action_group_new("view"); gtk_action_group_set_translation_domain(action_group, GETTEXT_PACKAGE); gtk_action_group_add_actions(action_group, view_entries, G_N_ELEMENTS(view_entries), editor); gtk_ui_manager_insert_action_group(manager, action_group, 0); action_group = gtk_action_group_new("main"); gtk_action_group_set_translation_domain(action_group, GETTEXT_PACKAGE); gtk_action_group_add_actions(action_group, main_entries, G_N_ELEMENTS(main_entries), e); gtk_ui_manager_insert_action_group(manager, action_group, 0); action_group = gtk_action_group_new("context-menu"); gtk_action_group_set_translation_domain(action_group, GETTEXT_PACKAGE); gtk_action_group_add_actions(action_group, test_entries, G_N_ELEMENTS(test_entries), e); gtk_ui_manager_insert_action_group(manager, action_group, 0); gtk_ui_manager_ensure_update(manager); gtk_widget_show(editor); gtkhtml_editor_drop_undo(GTKHTML_EDITOR(e->window)); gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window), FALSE); g_signal_connect(editor, "delete-event", G_CALLBACK(app_delete_cb), (EDITOR *)e); return editor; }
static void view_source_dialog(GtkhtmlEditor *editor, const gchar *title, const gchar *content_type, gboolean show_output) { GtkWidget *dialog; GtkWidget *content; GtkWidget *scrolled_window; GString *string; dialog = gtk_dialog_new_with_buttons(title, GTK_WINDOW(editor), GTK_DIALOG_DESTROY_WITH_PARENT, #ifdef HAVE_GTK_310 "_Close", GTK_RESPONSE_CLOSE, #else GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, #endif NULL); scrolled_window = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), scrolled_window, TRUE, TRUE, 0); gtk_container_set_border_width(GTK_CONTAINER(dialog), 6); gtk_container_set_border_width(GTK_CONTAINER(scrolled_window), 6); gtk_window_set_default_size(GTK_WINDOW(dialog), 400, 300); string = g_string_sized_new(4096); gtk_html_export(gtkhtml_editor_get_html(editor), content_type, (GtkHTMLSaveReceiverFn) view_source_dialog_receiver, string); if (show_output) { GtkHTMLStream *stream; content = gtk_html_new(); stream = gtk_html_begin(GTK_HTML(content)); gtk_html_stream_write(stream, string->str, string->len); gtk_html_stream_close(stream, GTK_HTML_STREAM_OK); } else { GtkTextBuffer *buffer; content = gtk_text_view_new(); buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(content)); gtk_text_buffer_set_text(buffer, string->str, string->len); gtk_text_view_set_editable(GTK_TEXT_VIEW(content), FALSE); } g_string_free(string, TRUE); gtk_container_add(GTK_CONTAINER(scrolled_window), content); gtk_widget_show_all(scrolled_window); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); }
void gtkhtml_editor_update_context (GtkhtmlEditor *editor) { GtkHTML *html; HTMLType type; HTMLObject *object; GtkUIManager *manager; GtkActionGroup *action_group; GList *list; gboolean visible; guint merge_id; html = gtkhtml_editor_get_html (editor); manager = gtkhtml_editor_get_ui_manager (editor); gtk_html_update_styles (html); /* Update context menu item visibility. */ object = html->engine->cursor->object; if (object != NULL) type = HTML_OBJECT_TYPE (object); else type = HTML_TYPE_NONE; visible = (type == HTML_TYPE_IMAGE); gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_IMAGE), visible); visible = (type == HTML_TYPE_LINKTEXT); gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_LINK), visible); visible = (type == HTML_TYPE_RULE); gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_RULE), visible); visible = (type == HTML_TYPE_TEXT); gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_TEXT), visible); visible = gtk_action_get_visible (ACTION (CONTEXT_PROPERTIES_IMAGE)) || gtk_action_get_visible (ACTION (CONTEXT_PROPERTIES_LINK)) || gtk_action_get_visible (ACTION (CONTEXT_PROPERTIES_TEXT)); gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_PARAGRAPH), visible); /* Set to visible if any of these are true: * - Selection is active and contains a link. * - Cursor is on a link. * - Cursor is on an image that has a URL or target. */ visible = (html_engine_is_selection_active (html->engine) && html_engine_selection_contains_link (html->engine)) || (type == HTML_TYPE_LINKTEXT) || (type == HTML_TYPE_IMAGE && (HTML_IMAGE (object)->url != NULL || HTML_IMAGE (object)->target != NULL)); gtk_action_set_visible (ACTION (CONTEXT_REMOVE_LINK), visible); /* Get the parent object. */ object = (object != NULL) ? object->parent : NULL; /* Get the grandparent object. */ object = (object != NULL) ? object->parent : NULL; if (object != NULL) type = HTML_OBJECT_TYPE (object); else type = HTML_TYPE_NONE; visible = (type == HTML_TYPE_TABLECELL); gtk_action_set_visible (ACTION (CONTEXT_DELETE_CELL), visible); gtk_action_set_visible (ACTION (CONTEXT_DELETE_COLUMN), visible); gtk_action_set_visible (ACTION (CONTEXT_DELETE_ROW), visible); gtk_action_set_visible (ACTION (CONTEXT_DELETE_TABLE), visible); gtk_action_set_visible (ACTION (CONTEXT_INSERT_COLUMN_AFTER), visible); gtk_action_set_visible (ACTION (CONTEXT_INSERT_COLUMN_BEFORE), visible); gtk_action_set_visible (ACTION (CONTEXT_INSERT_ROW_ABOVE), visible); gtk_action_set_visible (ACTION (CONTEXT_INSERT_ROW_BELOW), visible); gtk_action_set_visible (ACTION (CONTEXT_INSERT_TABLE), visible); gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_CELL), visible); /* Get the great grandparent object. */ object = (object != NULL) ? object->parent : NULL; if (object != NULL) type = HTML_OBJECT_TYPE (object); else type = HTML_TYPE_NONE; /* Note the |= (cursor must be in a table cell). */ visible |= (type == HTML_TYPE_TABLE); gtk_action_set_visible (ACTION (CONTEXT_PROPERTIES_TABLE), visible); /********************** Spell Check Suggestions **********************/ object = html->engine->cursor->object; action_group = editor->priv->suggestion_actions; /* Remove the old content from the context menu. */ merge_id = editor->priv->spell_suggestions_merge_id; if (merge_id > 0) { gtk_ui_manager_remove_ui (manager, merge_id); editor->priv->spell_suggestions_merge_id = 0; } /* Clear the action group for spelling suggestions. */ list = gtk_action_group_list_actions (action_group); while (list != NULL) { GtkAction *action = list->data; gtk_action_group_remove_action (action_group, action); list = g_list_delete_link (list, list); } /* Decide if we should show spell checking items. */ visible = !html_engine_is_selection_active (html->engine) && object != NULL && html_object_is_text (object) && !html_engine_spell_word_is_valid (html->engine); action_group = editor->priv->spell_check_actions; gtk_action_group_set_visible (action_group, visible); /* Exit early if spell checking items are invisible. */ if (!visible) return; list = editor->priv->active_spell_checkers; merge_id = gtk_ui_manager_new_merge_id (manager); editor->priv->spell_suggestions_merge_id = merge_id; /* Handle a single active language as a special case. */ if (g_list_length (list) == 1) { editor_inline_spelling_suggestions (editor, list->data); return; } /* Add actions and context menu content for active languages. */ g_list_foreach (list, (GFunc) editor_spell_checkers_foreach, editor); }
/* Helper for gtkhtml_editor_update_context() */ static void editor_spell_checkers_foreach (GtkhtmlSpellChecker *checker, GtkhtmlEditor *editor) { const GtkhtmlSpellLanguage *language; const gchar *language_code; GtkActionGroup *action_group; GtkUIManager *manager; GtkHTML *html; GList *list; gchar *path; gchar *word; gint count = 0; guint merge_id; language = gtkhtml_spell_checker_get_language (checker); language_code = gtkhtml_spell_language_get_code (language); html = gtkhtml_editor_get_html (editor); word = html_engine_get_spell_word (html->engine); list = gtkhtml_spell_checker_get_suggestions (checker, word, -1); manager = gtkhtml_editor_get_ui_manager (editor); action_group = editor->priv->suggestion_actions; merge_id = editor->priv->spell_suggestions_merge_id; path = g_strdup_printf ( "/context-menu/context-spell-suggest/" "context-spell-suggest-%s-menu", language_code); while (list != NULL) { gchar *suggestion = list->data; gchar *action_name; gchar *action_label; GtkAction *action; GtkWidget *child; GSList *proxies; /* Action name just needs to be unique. */ action_name = g_strdup_printf ( "suggest-%s-%d", language_code, count++); action_label = g_markup_printf_escaped ( "<b>%s</b>", suggestion); action = gtk_action_new ( action_name, action_label, NULL, NULL); g_object_set_data_full ( G_OBJECT (action), "word", g_strdup (suggestion), g_free); g_signal_connect ( action, "activate", G_CALLBACK ( action_context_spell_suggest_cb), editor); gtk_action_group_add_action (action_group, action); gtk_ui_manager_add_ui ( manager, merge_id, path, action_name, action_name, GTK_UI_MANAGER_AUTO, FALSE); /* XXX GtkAction offers no supports for Pango markup, * so we have to manually set "use-markup" on the * child of the proxy widget. */ gtk_ui_manager_ensure_update (manager); proxies = gtk_action_get_proxies (action); child = gtk_bin_get_child (proxies->data); g_object_set (child, "use-markup", TRUE, NULL); g_free (suggestion); g_free (action_name); g_free (action_label); list = g_list_delete_link (list, list); } g_free (path); g_free (word); }
static void editor_inline_spelling_suggestions (GtkhtmlEditor *editor, GtkhtmlSpellChecker *checker) { GtkActionGroup *action_group; GtkUIManager *manager; GtkHTML *html; GList *list; const gchar *path; gchar *word; guint count = 0; guint length; guint merge_id; guint threshold; html = gtkhtml_editor_get_html (editor); word = html_engine_get_spell_word (html->engine); list = gtkhtml_spell_checker_get_suggestions (checker, word, -1); path = "/context-menu/context-spell-suggest/"; manager = gtkhtml_editor_get_ui_manager (editor); action_group = editor->priv->suggestion_actions; merge_id = editor->priv->spell_suggestions_merge_id; /* Calculate how many suggestions to put directly in the * context menu. The rest will go in a secondary menu. */ length = g_list_length (list); if (length <= MAX_LEVEL1_SUGGESTIONS) threshold = length; else if (length - MAX_LEVEL1_SUGGESTIONS < MIN_LEVEL2_SUGGESTIONS) threshold = length; else threshold = MAX_LEVEL1_SUGGESTIONS; while (list != NULL) { gchar *suggestion = list->data; gchar *action_name; gchar *action_label; GtkAction *action; GtkWidget *child; GSList *proxies; /* Once we reach the threshold, put all subsequent * spelling suggestions in a secondary menu. */ if (count == threshold) path = "/context-menu/context-more-suggestions-menu/"; /* Action name just needs to be unique. */ action_name = g_strdup_printf ("suggest-%d", count++); action_label = g_markup_printf_escaped ( "<b>%s</b>", suggestion); action = gtk_action_new ( action_name, action_label, NULL, NULL); g_object_set_data_full ( G_OBJECT (action), "word", g_strdup (suggestion), g_free); g_signal_connect ( action, "activate", G_CALLBACK ( action_context_spell_suggest_cb), editor); gtk_action_group_add_action (action_group, action); gtk_ui_manager_add_ui ( manager, merge_id, path, action_name, action_name, GTK_UI_MANAGER_AUTO, FALSE); /* XXX GtkAction offers no support for Pango markup, * so we have to manually set "use-markup" on the * child of the proxy widget. */ gtk_ui_manager_ensure_update (manager); proxies = gtk_action_get_proxies (action); child = gtk_bin_get_child (proxies->data); g_object_set (child, "use-markup", TRUE, NULL); g_free (suggestion); g_free (action_name); g_free (action_label); list = g_list_delete_link (list, list); } g_free (word); }
void gtkhtml_editor_spell_check (GtkhtmlEditor *editor, gboolean whole_document) { GtkHTML *html; gboolean spelling_errors; g_return_if_fail (GTKHTML_IS_EDITOR (editor)); html = gtkhtml_editor_get_html (editor); if (whole_document) { html_engine_disable_selection (html->engine); html_engine_beginning_of_document (html->engine); gtk_html_set_inline_spelling (html, TRUE); } spelling_errors = !html_engine_spell_word_is_valid (html->engine) || gtkhtml_editor_next_spell_error (editor); if (spelling_errors) { GtkWidget *dialog; dialog = gtkhtml_spell_dialog_new (GTK_WINDOW (editor)); gtkhtml_spell_dialog_set_spell_checkers ( GTKHTML_SPELL_DIALOG (dialog), editor->priv->active_spell_checkers); editor_set_word (editor, GTKHTML_SPELL_DIALOG (dialog)); g_signal_connect_swapped ( dialog, "added", G_CALLBACK (editor_recheck_cb), editor); g_signal_connect_swapped ( dialog, "ignored", G_CALLBACK (editor_recheck_cb), editor); g_signal_connect_swapped ( dialog, "next-word", G_CALLBACK (editor_next_word_cb), editor); g_signal_connect_swapped ( dialog, "prev-word", G_CALLBACK (editor_prev_word_cb), editor); g_signal_connect_swapped ( dialog, "replace", G_CALLBACK (editor_replace_cb), editor); g_signal_connect_swapped ( dialog, "replace-all", G_CALLBACK (editor_replace_all_cb), editor); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } /* XXX Restore original inline spelling value. */ }
void gtkhtml_editor_private_constructed (GtkhtmlEditor *editor) { GtkhtmlEditorPrivate *priv = editor->priv; GtkHTML *html; GtkWidget *widget; GtkToolbar *toolbar; GtkToolItem *tool_item; /* Construct main window widgets. */ widget = gtkhtml_editor_get_managed_widget (editor, "/main-menu"); gtk_box_pack_start (GTK_BOX (editor->vbox), widget, FALSE, FALSE, 0); priv->main_menu = g_object_ref (widget); gtk_widget_show (widget); widget = gtkhtml_editor_get_managed_widget (editor, "/main-toolbar"); gtk_box_pack_start (GTK_BOX (editor->vbox), widget, FALSE, FALSE, 0); priv->main_toolbar = g_object_ref (widget); gtk_widget_show (widget); widget = gtkhtml_editor_get_managed_widget (editor, "/edit-toolbar"); gtk_toolbar_set_style (GTK_TOOLBAR (widget), GTK_TOOLBAR_BOTH_HORIZ); gtk_box_pack_start (GTK_BOX (editor->vbox), widget, FALSE, FALSE, 0); priv->edit_toolbar = g_object_ref (widget); gtk_widget_show (widget); widget = gtkhtml_editor_get_managed_widget (editor, "/html-toolbar"); gtk_toolbar_set_style (GTK_TOOLBAR (widget), GTK_TOOLBAR_BOTH_HORIZ); gtk_box_pack_start (GTK_BOX (editor->vbox), widget, FALSE, FALSE, 0); priv->html_toolbar = g_object_ref (widget); gtk_widget_show (widget); widget = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW (widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type ( GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN); gtk_box_pack_start (GTK_BOX (editor->vbox), widget, TRUE, TRUE, 0); priv->scrolled_window = g_object_ref (widget); gtk_widget_show (widget); widget = GTK_WIDGET (gtkhtml_editor_get_html (editor)); gtk_container_add (GTK_CONTAINER (priv->scrolled_window), widget); gtk_widget_show (widget); /* Add some combo boxes to the "edit" toolbar. */ toolbar = GTK_TOOLBAR (priv->edit_toolbar); tool_item = gtk_tool_item_new (); widget = gtkhtml_combo_box_new_with_action ( GTK_RADIO_ACTION (ACTION (STYLE_NORMAL))); gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (widget), FALSE); gtk_container_add (GTK_CONTAINER (tool_item), widget); gtk_widget_set_tooltip_text (widget, _("Paragraph Style")); gtk_toolbar_insert (toolbar, tool_item, 0); priv->style_combo_box = g_object_ref (widget); gtk_widget_show_all (GTK_WIDGET (tool_item)); tool_item = gtk_separator_tool_item_new (); gtk_toolbar_insert (toolbar, tool_item, 0); gtk_widget_show_all (GTK_WIDGET (tool_item)); tool_item = gtk_tool_item_new (); widget = gtkhtml_combo_box_new_with_action ( GTK_RADIO_ACTION (ACTION (MODE_HTML))); gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (widget), FALSE); gtk_container_add (GTK_CONTAINER (tool_item), widget); gtk_widget_set_tooltip_text (widget, _("Editing Mode")); gtk_toolbar_insert (toolbar, tool_item, 0); priv->mode_combo_box = g_object_ref (widget); gtk_widget_show_all (GTK_WIDGET (tool_item)); /* Add some combo boxes to the "html" toolbar. */ toolbar = GTK_TOOLBAR (priv->html_toolbar); tool_item = gtk_tool_item_new (); widget = gtkhtml_color_combo_new (); gtk_container_add (GTK_CONTAINER (tool_item), widget); gtk_widget_set_tooltip_text (widget, _("Font Color")); gtk_toolbar_insert (toolbar, tool_item, 0); priv->color_combo_box = g_object_ref (widget); gtk_widget_show_all (GTK_WIDGET (tool_item)); tool_item = gtk_tool_item_new (); widget = gtkhtml_combo_box_new_with_action ( GTK_RADIO_ACTION (ACTION (SIZE_PLUS_ZERO))); gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (widget), FALSE); gtk_container_add (GTK_CONTAINER (tool_item), widget); gtk_widget_set_tooltip_text (widget, _("Font Size")); gtk_toolbar_insert (toolbar, tool_item, 0); priv->size_combo_box = g_object_ref (widget); gtk_widget_show_all (GTK_WIDGET (tool_item)); /* Initialize painters (requires "edit_area"). */ html = gtkhtml_editor_get_html (editor); gtk_widget_ensure_style (GTK_WIDGET (html)); priv->html_painter = g_object_ref (html->engine->painter); priv->plain_painter = html_plain_painter_new (priv->edit_area, TRUE); /* Add input methods to the context menu. */ widget = gtkhtml_editor_get_managed_widget ( editor, "/context-menu/context-input-methods-menu"); widget = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); gtk_im_multicontext_append_menuitems ( GTK_IM_MULTICONTEXT (html->priv->im_context), GTK_MENU_SHELL (widget)); /* Configure color stuff. */ priv->palette = gtkhtml_color_palette_new (); priv->text_color = gtkhtml_color_state_new (); gtkhtml_color_state_set_default_label ( priv->text_color, _("Automatic")); gtkhtml_color_state_set_palette ( priv->text_color, priv->palette); /* Text color widgets share state. */ widget = priv->color_combo_box; gtkhtml_color_combo_set_state ( GTKHTML_COLOR_COMBO (widget), priv->text_color); widget = WIDGET (TEXT_PROPERTIES_COLOR_COMBO); gtkhtml_color_combo_set_state ( GTKHTML_COLOR_COMBO (widget), priv->text_color); /* These color widgets share a custom color palette. */ widget = WIDGET (CELL_PROPERTIES_COLOR_COMBO); gtkhtml_color_combo_set_palette ( GTKHTML_COLOR_COMBO (widget), priv->palette); widget = WIDGET (PAGE_PROPERTIES_BACKGROUND_COLOR_COMBO); gtkhtml_color_combo_set_palette ( GTKHTML_COLOR_COMBO (widget), priv->palette); widget = WIDGET (PAGE_PROPERTIES_LINK_COLOR_COMBO); gtkhtml_color_combo_set_palette ( GTKHTML_COLOR_COMBO (widget), priv->palette); widget = WIDGET (TABLE_PROPERTIES_COLOR_COMBO); gtkhtml_color_combo_set_palette ( GTKHTML_COLOR_COMBO (widget), priv->palette); }