]> git.lyx.org Git - lyx.git/blobdiff - src/spellchecker.C
Indentation change + small #ifndef NEW_INSETS fix.
[lyx.git] / src / spellchecker.C
index fa208ce3637a4c23a1e9fa0ffb014bfea7648986..609aa93502e7406cf83ca63ca8df60e15f60a9ec 100644 (file)
 #include "encoding.h"
 #include "support/lstrings.h"
 
-//#define USE_PSPELL 1
-
 #ifdef USE_PSPELL
-
-#include <pspell/pspell.h>
-
+# include <pspell/pspell.h>
 #endif
 
 using std::reverse;
 using std::endl;
 
+namespace {
+
 // Spellchecker status
 enum {
        ISP_OK = 1,
@@ -86,19 +84,20 @@ enum {
        ISP_IGNORE
 };
 
-static bool RunSpellChecker(BufferView * bv);
+bool RunSpellChecker(BufferView * bv);
 
 #ifndef USE_PSPELL
 
-static FILE * in, * out;  /* streams to communicate with ispell */
+FILE * in;
+FILE * out;  /* streams to communicate with ispell */
 pid_t isp_pid = -1; // pid for the `ispell' process. Also used (RO) in
                     // lyx_cb.C
 
 // the true spell checker program being used
 enum ActualSpellChecker {ASC_ISPELL, ASC_ASPELL};
-static ActualSpellChecker actual_spell_checker;
+ActualSpellChecker actual_spell_checker;
 
-static int isp_fd;
+int isp_fd;
 
 #else
 
@@ -106,13 +105,15 @@ PspellManager * sc;
 
 #endif
 
-static FD_form_spell_options *fd_form_spell_options = 0;
+} // namespace anon
+
+
+// Non-static so that it can be redrawn if the xforms colors are re-mapped
+FD_form_spell_options *fd_form_spell_options = 0;
 FD_form_spell_check *fd_form_spell_check = 0;
 
-//void sigchldhandler(int sig);
 void sigchldhandler(pid_t pid, int *status);
 
-//extern void sigchldchecker(int sig);
 extern void sigchldchecker(pid_t pid, int *status);
 
 #ifndef USE_PSPELL
@@ -280,18 +281,19 @@ void SpellCheckerOptions()
                fl_raise_form(fd_form_spell_options->form_spell_options);
        } else {
                fl_show_form(fd_form_spell_options->form_spell_options,
-                            FL_PLACE_MOUSE, FL_FULLBORDER,
+                            FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
                             _("Spellchecker Options"));
        }
 }
 
+namespace {
+
 #ifndef USE_PSPELL
 
 /***** Spellchecker *****/
 
 // Could also use a clean up. (Asger Alstrup)
 
-static
 void init_spell_checker(BufferParams const & params, string const & lang)
 {
        static char o_buf[BUFSIZ];  // jc: it could be smaller
@@ -301,7 +303,7 @@ void init_spell_checker(BufferParams const & params, string const & lang)
 
        isp_pid = -1;
 
-       if(pipe(pipein) == -1 || pipe(pipeout) == -1) {
+       if (pipe(pipein) == -1 || pipe(pipeout) == -1) {
                lyxerr << "LyX: Can't create pipe for spellchecker!" << endl;
                goto END;
        }
@@ -324,13 +326,13 @@ void init_spell_checker(BufferParams const & params, string const & lang)
 
        isp_pid = fork();
 
-       if(isp_pid == -1) {
+       if (isp_pid == -1) {
                lyxerr << "LyX: Can't create child process for spellchecker!"
                       << endl;
                goto END;
        }
        
-       if(isp_pid == 0) {        
+       if (isp_pid == 0) {        
                /* child process */
                dup2(pipein[0], STDIN_FILENO);
                dup2(pipeout[1], STDOUT_FILENO);
@@ -483,19 +485,19 @@ void init_spell_checker(BufferParams const & params, string const & lang)
        }
 }
 
-static
+
 bool sc_still_alive() {
        return isp_pid != -1;
 }
 
-static
+
 void sc_clean_up_after_error() 
 {
        ::fclose(out);
 }
 
+
 // Send word to ispell and get reply
-static
 isp_result * sc_check_word(string const & word)
 {
        //Please rewrite to use string.
@@ -550,7 +552,7 @@ isp_result * sc_check_word(string const & word)
 }
 
 
-static inline 
+inline 
 void close_spell_checker()
 {
         // Note: If you decide to optimize this out when it is not 
@@ -565,7 +567,7 @@ void close_spell_checker()
 }
 
 
-static inline 
+inline 
 void sc_insert_word(string const & word)
 {
        ::fputc('*', out); // Insert word in personal dictionary
@@ -574,7 +576,7 @@ void sc_insert_word(string const & word)
 }
 
 
-static inline 
+inline 
 void sc_accept_word(string const & word) 
 {
        ::fputc('@', out); // Accept in this session
@@ -582,9 +584,10 @@ void sc_accept_word(string const & word)
        ::fputc('\n', out);
 }
 
-static inline
+
+inline
 void sc_store_replacement(string const & mis, string const & cor) {
-        if(actual_spell_checker == ASC_ASPELL) {
+        if (actual_spell_checker == ASC_ASPELL) {
                 ::fputs("$$ra ", out);
                 ::fputs(mis.c_str(), out);
                 ::fputc(',', out);
@@ -597,7 +600,6 @@ void sc_store_replacement(string const & mis, string const & cor) {
 
 PspellCanHaveError * spell_error_object;
 
-static
 void init_spell_checker(BufferParams const &, string const & lang)
 {
        PspellConfig * config = new_pspell_config();
@@ -614,12 +616,12 @@ void init_spell_checker(BufferParams const &, string const & lang)
        }
 }
 
-static 
+
 bool sc_still_alive() {
        return true;
 }
 
-static
+
 void sc_clean_up_after_error() 
 {
        delete_pspell_can_have_error(spell_error_object);
@@ -627,8 +629,7 @@ void sc_clean_up_after_error()
 
 
 
-// Send word to ispell and get reply
-static
+// Send word to pspell and get reply
 isp_result * sc_check_word(string const & word)
 {
        isp_result * result = new isp_result;
@@ -652,28 +653,28 @@ isp_result * sc_check_word(string const & word)
 }
 
 
-static inline 
+inline 
 void close_spell_checker()
 {
        pspell_manager_save_all_word_lists(sc);
 }
 
 
-static inline 
+inline 
 void sc_insert_word(string const & word)
 {
        pspell_manager_add_to_personal(sc, word.c_str());
 }
 
 
-static inline 
+inline 
 void sc_accept_word(string const & word) 
 {
        pspell_manager_add_to_session(sc, word.c_str());
 }
 
 
-static inline 
+inline 
 void sc_store_replacement(string const & mis, string const & cor)
 {
        pspell_manager_store_replacement(sc, mis.c_str(), cor.c_str());
@@ -681,6 +682,9 @@ void sc_store_replacement(string const & mis, string const & cor)
 
 #endif
 
+} // namespace anon
+
+
 void ShowSpellChecker(BufferView * bv)
 {
        FL_OBJECT * obj;
@@ -709,7 +713,7 @@ void ShowSpellChecker(BufferView * bv)
                fl_raise_form(fd_form_spell_check->form_spell_check);
        } else {
                fl_show_form(fd_form_spell_check->form_spell_check,
-                            FL_PLACE_MOUSE, FL_FULLBORDER,
+                            FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
                             _("Spellchecker"));
        }
        fl_deactivate_object(fd_form_spell_check->slider); 
@@ -797,13 +801,20 @@ void ShowSpellChecker(BufferView * bv)
 
 
 // Perform a spell session
-static
+namespace {
+
 bool RunSpellChecker(BufferView * bv)
 {
        isp_result * result;
        int newvalue;
        FL_OBJECT * obj;
 
+#ifndef NEW_INSETS
+       // Open all floats
+        bv->allFloats(1, 0);
+        bv->allFloats(1, 1);
+#endif
+
 #ifdef USE_PSPELL
        string tmp = (lyxrc.isp_use_alt_lang) ?
            lyxrc.isp_alt_lang : bv->buffer()->params.language->code();
@@ -840,7 +851,7 @@ bool RunSpellChecker(BufferView * bv)
                
                // Update slider if and only if value has changed
                newvalue = int(100.0*newval);
-               if(newvalue!= oldval) {
+               if (newvalue!= oldval) {
                        oldval = newvalue;
                        fl_set_slider_value(fd_form_spell_check->slider, oldval);
                }
@@ -946,7 +957,7 @@ bool RunSpellChecker(BufferView * bv)
                }
        }
    
-       if(sc_still_alive()) {
+       if (sc_still_alive()) {
                close_spell_checker();
                string word_msg(tostr(word_count));
                if (word_count != 1) {
@@ -965,11 +976,14 @@ bool RunSpellChecker(BufferView * bv)
        }
 }
 
+} // namespace anon
 
-#ifndef USE_PSPELL
-
+#ifdef WITH_WARNINGS
+#warning should go somewhere more sensible
+#endif
 void sigchldhandler(pid_t pid, int * status)
-{ 
+{
+#ifndef USE_PSPELL
        if (isp_pid > 0)
                if (pid == isp_pid) {
                        isp_pid= -1;
@@ -977,14 +991,8 @@ void sigchldhandler(pid_t pid, int * status)
                                                               to nonblocking so we can 
                                                               continue */
                }
+#endif
        sigchldchecker(pid, status);
 }
 
-#else
 
-void sigchldhandler(pid_t, int *)
-{ 
-       // do nothing
-}
-
-#endif