]> git.lyx.org Git - lyx.git/blobdiff - src/spellchecker.C
more keyboard/keysym changes
[lyx.git] / src / spellchecker.C
index aa75ae403f610853fff29541efa81f4eef6679ad..04a578affd791a636bf98aca837ba5c9bff223dd 100644 (file)
 
 #include <config.h>
 
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
 #include <unistd.h>
 #include <fcntl.h>
 #include <cstdlib>
 #endif
 
 #ifdef HAVE_SYS_SELECT_H
+# ifdef HAVE_STRINGS_H
+   // <strings.h> is needed at least on AIX because FD_ZERO uses bzero().
+# include <strings.h> 
+# endif
 #include <sys/select.h>
 #endif
 
+#include <algorithm>
+
 #include "LString.h"
 #include "sp_form.h"
 #include "spellchecker.h"
@@ -48,8 +58,9 @@
 #include "lyx_gui_misc.h"
 #include "debug.h"
 #include "support/lstrings.h"
+#include "encoding.h"
 
-
+using std::reverse;
 using std::endl;
 
 // Spellchecker status
@@ -325,13 +336,17 @@ void create_ispell_pipe(BufferParams const & params, string const & lang)
                        argv[argc++] = tmp;
                }
                if (lyxrc.isp_use_input_encoding &&
-                   params.inputenc != "default") {
+                   params.inputenc != "default") {
+                       string enc = (params.inputenc == "auto")
+                               ? params.language_info->encoding()->LatexName()
+                               : params.inputenc;
+                       string::size_type n = enc.length();
                        tmp = new char[3];
                        string("-T").copy(tmp, 2); tmp[2] = '\0';
                        argv[argc++] = tmp; // Input encoding
-                       tmp = new char[params.inputenc.length() + 1];
-                       params.inputenc.copy(tmp, params.inputenc.length());
-                       tmp[params.inputenc.length()] = '\0';
+                       tmp = new char[n + 1];
+                       enc.copy(tmp, n);
+                       tmp[n] = '\0';
                        argv[argc++] = tmp;
                }
 
@@ -532,7 +547,8 @@ void ShowSpellChecker(BufferView * bv)
        if (fd_form_spell_check == 0) {
                fd_form_spell_check = create_form_form_spell_check();
                // Make sure pressing the close box does not kill LyX. (RvdK)
-               fl_set_form_atclose(fd_form_spell_check->form_spell_check, IgnoreCloseBoxCB, 0);
+               fl_set_form_atclose(fd_form_spell_check->form_spell_check, 
+                                   CancelCloseBoxCB, 0);
        }
 
        // Clear form
@@ -643,6 +659,7 @@ bool RunSpellChecker(BufferView * bv)
        FL_OBJECT * obj;
 
        string tmp = (lyxrc.isp_use_alt_lang) ? lyxrc.isp_alt_lang : bv->buffer()->GetLanguage();
+       bool rtl = tmp == "hebrew" || tmp == "arabic";
 
        int oldval = 0;  /* used for updating slider only when needed */
        float newval = 0.0;
@@ -659,7 +676,7 @@ bool RunSpellChecker(BufferView * bv)
                          "Check /usr/lib/ispell or set another\n"
                          "dictionary in the Spellchecker Options menu."), "", "");
                fclose(out);
-               return true;
+               return false;
        }
 
        // Put ispell in terse mode to improve speed
@@ -676,38 +693,49 @@ bool RunSpellChecker(BufferView * bv)
                if(newvalue!= oldval) {
                        oldval = newvalue;
                        fl_set_slider_value(fd_form_spell_check->slider, oldval);
+               }
+
+               if (word_count%1000 == 0) {
+                       obj =  fl_check_forms();
+                       if (obj == fd_form_spell_check->stop) {
+                               delete[] word;
+                               ispell_terminate();
+                               return true;
+                       }
+                       if (obj == fd_form_spell_check->done) {
+                               delete[] word;
+                               ispell_terminate(); 
+                               return false;
+                       }
                }
 
                result = ispell_check_word(word);
                if (isp_pid == -1) {
+                       delete result;
                        delete[] word;
                        break;
                }
 
-               obj =  fl_check_forms();
-               if (obj == fd_form_spell_check->stop) {
-                       delete result;
-                       delete[] word;
-                       ispell_terminate();
-                       return true;
-               }
-               if (obj == fd_form_spell_check->done) {
-                       delete result;
-                       delete[] word;
-                       ispell_terminate(); 
-                       return false;
-               }
-    
                switch (result->flag) {
                case ISP_UNKNOWN:
                case ISP_MISSED:
                {
                        bv->selectLastWord();
-                       fl_set_object_label(fd_form_spell_check->text, word);
+                       if (rtl) {
+                               string tmp = word;
+                               reverse(tmp.begin(),tmp.end());
+                               fl_set_object_label(fd_form_spell_check->text, tmp.c_str());
+                       } else
+                               fl_set_object_label(fd_form_spell_check->text, word);
                        fl_set_input(fd_form_spell_check->input, word);
                        fl_clear_browser(fd_form_spell_check->browser);
                        for (i = 0; i < result->count; ++i) {
-                               fl_add_browser_line(fd_form_spell_check->browser, result->misses[i]);
+                               if (rtl) {
+                                       string tmp = result->misses[i];
+                                       reverse(tmp.begin(),tmp.end());
+                                       fl_add_browser_line(fd_form_spell_check->browser, tmp.c_str());
+                               } else
+                                       fl_add_browser_line(fd_form_spell_check->browser, result->misses[i]);
                        }
 
                        int clickline = -1;
@@ -740,10 +768,17 @@ bool RunSpellChecker(BufferView * bv)
                                                break;
                                        }
                                        clickline = fl_get_browser(fd_form_spell_check->browser);
-                                       fl_set_input(fd_form_spell_check->input, 
-                                                    fl_get_browser_line(fd_form_spell_check->browser,
-                                                                        fl_get_browser(fd_form_spell_check->browser)));
-                                                    
+                                       /// Why not use
+                                       /// fl_set_input(fd_form_spell_check->input, result->misses[clickline-1]); ?
+                                       if (rtl) {
+                                               string tmp = fl_get_browser_line(fd_form_spell_check->browser,
+                                                                                clickline);
+                                               reverse(tmp.begin(),tmp.end());
+                                               fl_set_input(fd_form_spell_check->input, tmp.c_str());
+                                       } else
+                                               fl_set_input(fd_form_spell_check->input,
+                                                            fl_get_browser_line(fd_form_spell_check->browser,
+                                                                                clickline));
                                }
                                if (obj == fd_form_spell_check->stop) {
                                        delete result;