* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; If not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Stuphead: (C) 2000,2001 Grigroy Bakunov, Sergey Pinaev
#include "alertpanel.h"
#include "gtkaspell.h"
#include "gtk/gtkutils.h"
+#include "gtk/combobox.h"
#define ASPELL_FASTMODE 1
#define ASPELL_NORMALMODE 2
RETURN_FALSE_IF_CONFIG_ERROR(); \
}
+enum {
+ SET_GTKASPELL_NAME = 0,
+ SET_GTKASPELL_FULLNAME = 1,
+ SET_GTKASPELL_SIZE
+};
+
typedef struct _GtkAspellCheckers {
GSList *checkers;
GSList *dictionary_list;
dlist = get_aspell_dict_info_list(config);
delete_aspell_config(config);
- debug_print("Aspell: checking for dictionaries in %s\n", aspell_path);
+ debug_print("Aspell: checking for dictionaries in %s\n", aspell_path?aspell_path:"(null)");
dels = aspell_dict_info_list_elements(dlist);
while ( (entry = aspell_dict_info_enumeration_next(dels)) != 0)
{
g_slist_free(list);
}
-/* FIXME */
-GtkWidget *gtkaspell_dictionary_option_menu_new_with_refresh(const gchar *aspell_path,
+GtkTreeModel *gtkaspell_dictionary_store_new_with_refresh(const gchar *aspell_path,
gboolean refresh)
{
GSList *dict_list, *tmp;
- GtkWidget *item;
- GtkWidget *menu;
+ GtkListStore *store;
+ GtkTreeIter iter;
Dictionary *dict;
dict_list = gtkaspell_get_dictionary_list(aspell_path, refresh);
g_return_val_if_fail(dict_list, NULL);
- menu = gtk_menu_new();
+ store = gtk_list_store_new(SET_GTKASPELL_SIZE,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ -1);
for (tmp = dict_list; tmp != NULL; tmp = g_slist_next(tmp)) {
dict = (Dictionary *) tmp->data;
- item = gtk_menu_item_new_with_label(dict->dictname);
- g_object_set_data(G_OBJECT(item), "dict_name",
- dict->fullname);
-
- gtk_menu_append(GTK_MENU(menu), item);
- gtk_widget_show(item);
+
+ gtk_list_store_append(store, &iter);
+ gtk_list_store_set(store, &iter,
+ SET_GTKASPELL_NAME, dict->dictname,
+ SET_GTKASPELL_FULLNAME, dict->fullname,
+ -1);
}
- gtk_widget_show(menu);
-
- return menu;
+ return GTK_TREE_MODEL(store);
}
-GtkWidget *gtkaspell_dictionary_option_menu_new(const gchar *aspell_path)
+GtkTreeModel *gtkaspell_dictionary_store_new(const gchar *aspell_path)
{
- return gtkaspell_dictionary_option_menu_new_with_refresh
+ return gtkaspell_dictionary_store_new_with_refresh
(aspell_path, TRUE);
-
}
-gchar *gtkaspell_get_dictionary_menu_active_item(GtkWidget *menu)
+GtkWidget *gtkaspell_dictionary_combo_new(const gchar *aspell_path,
+ const gboolean refresh)
{
- GtkWidget *menuitem;
- gchar *dict_fullname;
- gchar *label;
-
- g_return_val_if_fail(GTK_IS_MENU(menu), NULL);
+ GtkWidget *combo;
+ GtkCellRenderer *renderer;
- menuitem = gtk_menu_get_active(GTK_MENU(menu));
- dict_fullname = (gchar *) g_object_get_data(G_OBJECT(menuitem),
- "dict_name");
- g_return_val_if_fail(dict_fullname, NULL);
+ combo = gtk_combo_box_new_with_model(
+ gtkaspell_dictionary_store_new_with_refresh(aspell_path, refresh));
+ gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
+ gtk_widget_show(combo);
+
+ renderer = gtk_cell_renderer_text_new();
+ gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, TRUE);
+ gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo),renderer,
+ "text", SET_GTKASPELL_NAME, NULL);
+
+ return combo;
+}
- label = g_strdup(dict_fullname);
+gchar *gtkaspell_get_dictionary_menu_active_item(GtkComboBox *combo)
+{
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ gchar *dict_fullname = NULL;
+
+ g_return_val_if_fail(GTK_IS_COMBO_BOX(combo), NULL);
+ g_return_val_if_fail(gtk_combo_box_get_active_iter(combo, &iter), NULL);
+
+ model = gtk_combo_box_get_model(combo);
+ if(model == NULL)
+ return NULL;
+
+ gtk_tree_model_get(model, &iter,
+ SET_GTKASPELL_FULLNAME, &dict_fullname,
+ -1);
- return label;
-
+ return dict_fullname;
}
-gint gtkaspell_set_dictionary_menu_active_item(GtkWidget *menu,
+gint gtkaspell_set_dictionary_menu_active_item(GtkComboBox *combo,
const gchar *dictionary)
{
- GList *cur;
- gint n;
-
- g_return_val_if_fail(menu != NULL, 0);
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gchar *dict_name = NULL;
+
+ g_return_val_if_fail(combo != NULL, 0);
g_return_val_if_fail(dictionary != NULL, 0);
- g_return_val_if_fail(GTK_IS_OPTION_MENU(menu), 0);
-
- n = 0;
- for (cur = GTK_MENU_SHELL(gtk_option_menu_get_menu(
- GTK_OPTION_MENU(menu)))->children;
- cur != NULL; cur = cur->next) {
- GtkWidget *menuitem;
- gchar *dict_name;
-
- menuitem = GTK_WIDGET(cur->data);
- dict_name = g_object_get_data(G_OBJECT(menuitem),
- "dict_name");
- if ((dict_name != NULL) && !strcmp2(dict_name, dictionary)) {
- gtk_option_menu_set_history(GTK_OPTION_MENU(menu), n);
+ g_return_val_if_fail(GTK_IS_COMBO_BOX(combo), 0);
+ if((model = gtk_combo_box_get_model(combo)) == NULL)
+ return 0;
+ if((gtk_tree_model_get_iter_first(model, &iter)) == FALSE)
+ return 0;
+
+ do {
+ gtk_tree_model_get(model, &iter,
+ SET_GTKASPELL_FULLNAME, &dict_name,
+ -1);
+
+ if ((dict_name != NULL) && !strcmp2(dict_name, dictionary)) {
+ gtk_combo_box_set_active_iter(combo, &iter);
+ g_free(dict_name);
return 1;
}
- n++;
- }
-
+
+ g_free(dict_name);
+
+ } while ((gtk_tree_model_iter_next(model, &iter)) == TRUE);
+
return 0;
}
-/* FIXME */
-GtkWidget *gtkaspell_sugmode_option_menu_new(gint sugmode)
+GtkWidget *gtkaspell_sugmode_combo_new(gint sugmode)
{
- GtkWidget *menu;
- GtkWidget *item;
-
- menu = gtk_menu_new();
- gtk_widget_show(menu);
-
- item = gtk_menu_item_new_with_label(_("Fast Mode"));
- gtk_widget_show(item);
- gtk_menu_append(GTK_MENU(menu), item);
- g_object_set_data(G_OBJECT(item), "sugmode",
- GINT_TO_POINTER(ASPELL_FASTMODE));
-
- item = gtk_menu_item_new_with_label(_("Normal Mode"));
- gtk_widget_show(item);
- gtk_menu_append(GTK_MENU(menu), item);
- g_object_set_data(G_OBJECT(item), "sugmode",
- GINT_TO_POINTER(ASPELL_NORMALMODE));
+ GtkWidget *combo = gtkut_sc_combobox_create(NULL, FALSE);
+ GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model(
+ GTK_COMBO_BOX(combo)));
+ GtkTreeIter iter;
- item = gtk_menu_item_new_with_label(_("Bad Spellers Mode"));
- gtk_widget_show(item);
- gtk_menu_append(GTK_MENU(menu), item);
- g_object_set_data(G_OBJECT(item), "sugmode",
- GINT_TO_POINTER(ASPELL_BADSPELLERMODE));
-
- return menu;
-}
+ g_return_val_if_fail(store != NULL, NULL);
-void gtkaspell_sugmode_option_menu_set(GtkOptionMenu *optmenu, gint sugmode)
-{
- g_return_if_fail(GTK_IS_OPTION_MENU(optmenu));
-
- g_return_if_fail(sugmode == ASPELL_FASTMODE ||
- sugmode == ASPELL_NORMALMODE ||
- sugmode == ASPELL_BADSPELLERMODE);
+ COMBOBOX_ADD(store, _("Fast Mode"), ASPELL_FASTMODE);
+ COMBOBOX_ADD(store, _("Normal Mode"), ASPELL_NORMALMODE);
+ COMBOBOX_ADD(store, _("Bad Spellers Mode"), ASPELL_BADSPELLERMODE);
- gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), sugmode - 1);
-}
-
-gint gtkaspell_get_sugmode_from_option_menu(GtkOptionMenu *optmenu)
-{
- gint sugmode;
- GtkWidget *item;
+ gtk_combo_box_set_active(GTK_COMBO_BOX(combo), sugmode - 1);
+ gtk_widget_show(combo);
- g_return_val_if_fail(GTK_IS_OPTION_MENU(optmenu), -1);
-
- item = gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(optmenu)));
-
- sugmode = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(item),
- "sugmode"));
-
- return sugmode;
+ return combo;
}
static void use_alternate_dict(GtkAspell *gtkaspell)
gtkaspeller = gtkaspeller_new(dict);
if (!gtkaspeller) {
- gchar *message;
- message = g_strdup_printf(_("The spell checker could not change dictionary.\n%s"),
+ alertpanel_warning(_("The spell checker could not change dictionary.\n%s"),
gtkaspellcheckers->error_message);
-
- alertpanel_warning(message);
- g_free(message);
} else {
if (gtkaspell->use_alternate) {
if (gtkaspell->alternate_speller) {
gtkaspeller = gtkaspeller_new(dict);
if (!gtkaspeller) {
- gchar *message;
- message = g_strdup_printf(_("The spell checker could not change the alternate dictionary.\n%s"),
+ alertpanel_warning(_("The spell checker could not change the alternate dictionary.\n%s"),
gtkaspellcheckers->error_message);
-
- alertpanel_warning(message);
- g_free(message);
} else {
if (gtkaspell->alternate_speller)
gtkaspeller_delete(gtkaspell->alternate_speller);
return 1;
}
+
+gchar *gtkaspell_get_default_dictionary(GtkAspell *gtkaspell)
+{
+ if (gtkaspell && gtkaspell->gtkaspeller &&
+ gtkaspell->gtkaspeller->dictionary)
+ return gtkaspell->gtkaspeller->dictionary->dictname;
+ else
+ return NULL;
+}
#endif