]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormThesaurus.C
Change glob() API to accept a dir parameter.
[lyx.git] / src / frontends / xforms / FormThesaurus.C
index b168ee56e1b8cdcd5f18e301e89a9c38836ed2cf..245ea49207123910ebfeed1ecb4a15a2a8c21121 100644 (file)
@@ -1,42 +1,65 @@
 /**
  * \file FormThesaurus.C
- * Copyright 2001 The LyX Team.
- * See the file COPYING.
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
  * \author Edwin Leuven
+ *
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
+#include "FormThesaurus.h"
+#include "ControlThesaurus.h"
+#include "forms/form_thesaurus.h"
 
-#include <cctype>
-#include "support/lstrings.h"
-#include "xformsBC.h"
 #include "xforms_helpers.h"
-#include "ControlThesaurus.h"
-#include "FormThesaurus.h"
-#include "form_thesaurus.h"
-#include "debug.h"
+#include "xformsBC.h"
+
+#include "support/lstrings.h"
+
+#include "lyx_forms.h"
+
+#ifndef CXX_GLOBAL_CSTD
+using std::islower;
+using std::isupper;
+#endif
+
+using std::vector;
+using std::string;
 
-typedef FormCB<ControlThesaurus, FormDB<FD_form_thesaurus> > base_class;
+namespace lyx {
 
-FormThesaurus::FormThesaurus(ControlThesaurus & c)
-       : base_class(c, _("LyX: Thesaurus"), false),
-       clickline_(-1)
+using support::lowercase;
+using support::trim;
+using support::uppercase;
+
+namespace frontend {
+
+typedef FormController<ControlThesaurus, FormView<FD_thesaurus> > base_class;
+
+
+FormThesaurus::FormThesaurus(Dialog & parent)
+       : base_class(parent, _("Thesaurus"), false),
+         clickline_(-1)
 {
 }
 
 
 void FormThesaurus::build()
 {
-       dialog_.reset(build_thesaurus());
+       dialog_.reset(build_thesaurus(this));
+
+       fl_set_input_return(dialog_->input_entry,   FL_RETURN_CHANGED);
+       fl_set_input_return(dialog_->input_replace, FL_RETURN_CHANGED);
+
+       setPrehandler(dialog_->input_entry);
+       setPrehandler(dialog_->input_replace);
+
        // Manage the ok, apply and cancel/close buttons
-       bc().setCancel(dialog_->button_close);
-       bc().addReadOnly(dialog_->input_replace);
+       bcview().setCancel(dialog_->button_close);
+       bcview().addReadOnly(dialog_->input_replace);
 
        fl_set_input_return(dialog_->input_entry, FL_RETURN_END_CHANGED);
 }
@@ -57,7 +80,7 @@ void FormThesaurus::update()
 void FormThesaurus::updateMeanings(string const & str)
 {
        fl_clear_browser(dialog_->browser_meanings);
+
        fl_set_input(dialog_->input_entry, str.c_str());
 
        fl_set_browser_topline(dialog_->browser_meanings, 1);
@@ -65,18 +88,24 @@ void FormThesaurus::updateMeanings(string const & str)
        fl_freeze_form(form());
 
        Thesaurus::Meanings meanings = controller().getMeanings(str);
-       for (Thesaurus::Meanings::const_iterator cit = meanings.begin();
-               cit != meanings.end(); ++cit) {
-                       fl_add_browser_line(dialog_->browser_meanings, cit->first.c_str());
-                       for (std::vector<string>::const_iterator cit2 = cit->second.begin();
-                               cit2 != cit->second.end(); ++cit2) {
-                                       string ent = "   ";
-                                       ent += *cit2;
-                                       fl_add_browser_line(dialog_->browser_meanings, ent.c_str());
-                               }
+
+       Thesaurus::Meanings::const_iterator cit = meanings.begin();
+       Thesaurus::Meanings::const_iterator end = meanings.end();
+       for (; cit != end; ++cit) {
+               fl_add_browser_line(dialog_->browser_meanings,
+                                   cit->first.c_str());
+
+               vector<string> const & tmpvec = cit->second;
+               vector<string>::const_iterator cit2 = tmpvec.begin();
+               vector<string>::const_iterator end2 = tmpvec.end();
+               for (; cit2 != end2; ++cit2) {
+                       string ent = "   ";
+                       ent += *cit2;
+                       fl_add_browser_line(dialog_->browser_meanings,
+                                           ent.c_str());
                }
+       }
+
        fl_unfreeze_form(form());
        fl_redraw_form(form());
 }
@@ -92,10 +121,13 @@ void FormThesaurus::setReplace(string const & templ, string const & nstr)
        bool all_lower = true;
        bool all_upper = true;
 
-       for (string::const_iterator it = templ.begin(); it != templ.end(); ++it) {
-               if (isupper(*it))
+       string::const_iterator beg = templ.begin();
+       string::const_iterator end = templ.end();
+       string::const_iterator cit = beg;
+       for (; cit != end; ++cit) {
+               if (isupper(*cit))
                        all_lower = false;
-               if (islower(*it))
+               if (islower(*cit))
                        all_upper = false;
        }
 
@@ -105,12 +137,13 @@ void FormThesaurus::setReplace(string const & templ, string const & nstr)
                str = uppercase(nstr);
        } else if (templ.size() > 0 && isupper(templ[0])) {
                bool rest_lower = true;
-               for (string::const_iterator it = templ.begin() + 1;
-                       it != templ.end(); ++it) {
-                       if (isupper(*it))
+               string::const_iterator cit2 = beg + 1;
+
+               for (; cit2 != end; ++cit2) {
+                       if (isupper(*cit2))
                                rest_lower = false;
                }
-               
+
                if (rest_lower) {
                        str = lowercase(nstr);
                        str[0] = uppercase(nstr[0]);
@@ -124,8 +157,8 @@ void FormThesaurus::setReplace(string const & templ, string const & nstr)
 ButtonPolicy::SMInput FormThesaurus::input(FL_OBJECT * obj, long)
 {
        if (obj == dialog_->input_entry) {
-               string s = strip(frontStrip(fl_get_input(dialog_->input_entry)));
-                
+               string s = trim(fl_get_input(dialog_->input_entry));
+
                updateMeanings(s);
 
                if (s.empty()) {
@@ -148,7 +181,7 @@ ButtonPolicy::SMInput FormThesaurus::input(FL_OBJECT * obj, long)
        int const line = fl_get_browser(obj);
        if (line > 0) {
                setReplace(fl_get_input(dialog_->input_entry),
-                          strip(frontStrip(fl_get_browser_line(obj, line))));
+                          trim(fl_get_browser_line(obj, line)));
        }
 
        if (clickline_ == fl_get_browser(obj)) {
@@ -160,3 +193,6 @@ ButtonPolicy::SMInput FormThesaurus::input(FL_OBJECT * obj, long)
 
        return ButtonPolicy::SMI_VALID;
 }
+
+} // namespace frontend
+} // namespace lyx