]> git.lyx.org Git - features.git/blobdiff - src/spellchecker.C
clear()->erase() ; lots of using directives for cxx
[features.git] / src / spellchecker.C
index 0ab8ac74bebe0dfae1d4f4759ebc2fa5d22a6c5f..f7536cb74953051a861d64fb70f4eaacde9e8b5a 100644 (file)
@@ -37,6 +37,8 @@
 #include <sys/select.h>
 #endif
 
+#include <algorithm>
+
 #include "LString.h"
 #include "sp_form.h"
 #include "spellchecker.h"
@@ -49,6 +51,8 @@
 #include "debug.h"
 #include "support/lstrings.h"
 
+using std::reverse;
+using std::endl;
 
 // Spellchecker status
 enum {
@@ -335,7 +339,7 @@ void create_ispell_pipe(BufferParams const & params, string const & lang)
 
                argv[argc++] = 0;
 
-               execvp("ispell", const_cast<char * const *>(argv));
+               execvp(argv[0], const_cast<char * const *>(argv));
 
                // free the memory used by string::copy in the
                // setup of argv
@@ -641,6 +645,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;
@@ -674,38 +679,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;
@@ -738,10 +754,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;