]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/xforms_helpers.C
fix crash with "save as"
[lyx.git] / src / frontends / xforms / xforms_helpers.C
index e4f20f6234b0299b6327cfacf3cd1dae0c903db6..fab98d9d8d704ed4687613ab726da3918fc93d3f 100644 (file)
@@ -1,9 +1,11 @@
 /**
  * \file xforms_helpers.C
- * Copyright 2000-2002 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 Angus Leeming, a.leeming@ic.ac.uk
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
 #include <algorithm>
 #include <fstream>
 #include <vector>
+
 #include FORMS_H_LOCATION
 
 using std::ofstream;
 using std::pair;
 using std::vector;
 
+bool isActive(FL_OBJECT * ob)
+{
+       return ob && ob->active > 0;
+}
+
+
 // Set an FL_OBJECT to activated or deactivated
 void setEnabled(FL_OBJECT * ob, bool enable)
 {
        if (enable) {
                fl_activate_object(ob);
-               fl_set_object_lcol(ob, FL_BLACK);
+               fl_set_object_lcol(ob, FL_LCOL);
        } else {
                fl_deactivate_object(ob);
                fl_set_object_lcol(ob, FL_INACTIVE);
@@ -50,24 +59,24 @@ void setEnabled(FL_OBJECT * ob, bool enable)
 vector<string> const getVector(FL_OBJECT * ob)
 {
        vector <string> vec;
-       
+
        switch (ob->objclass) {
        case FL_CHOICE:
                for(int i = 0; i < fl_get_choice_maxitems(ob); ++i) {
                        string const text = fl_get_choice_item_text(ob, i+1);
-                       vec.push_back(strip(frontStrip(text)));
+                       vec.push_back(trim(text));
                }
                break;
        case FL_BROWSER:
                for(int i = 0; i < fl_get_browser_maxline(ob); ++i) {
                        string const text = fl_get_browser_line(ob, i+1);
-                       vec.push_back(strip(frontStrip(text)));
+                       vec.push_back(trim(text));
                }
                break;
        default:
                lyx::Assert(0);
        }
-       
+
        return vec;
 }
 
@@ -75,51 +84,53 @@ vector<string> const getVector(FL_OBJECT * ob)
 ///
 string const getString(FL_OBJECT * ob, int line)
 {
-       char const * tmp = 0;
+       // Negative line value does not make sense.
+       lyx::Assert(line >= 0);
 
+       char const * tmp = 0;
        switch (ob->objclass) {
        case FL_INPUT:
-               lyx::Assert(line == -1);
                tmp = fl_get_input(ob);
                break;
+
        case FL_BROWSER:
-               if (line == -1)
+               if (line == 0)
                        line = fl_get_browser(ob);
-                       
+
                if (line >= 1 && line <= fl_get_browser_maxline(ob))
                        tmp = fl_get_browser_line(ob, line);
                break;
-                       
+
        case FL_CHOICE:
-               if (line == -1)
+               if (line == 0)
                        line = fl_get_choice(ob);
-                       
+
                if (line >= 1 && line <= fl_get_choice_maxitems(ob))
                        tmp = fl_get_choice_item_text(ob, line);
                break;
-                       
+
        default:
                lyx::Assert(0);
-       }               
+       }
 
-       return (tmp) ? frontStrip(strip(tmp)) : string();
+       return tmp ? trim(tmp) : string();
 }
-       
+
 string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice)
 {
        // Paranoia check
        lyx::Assert(input  && input->objclass  == FL_INPUT &&
                    choice && choice->objclass == FL_CHOICE);
 
-       string const length = strip(frontStrip(fl_get_input(input)));
+       string const length = trim(fl_get_input(input));
        if (length.empty())
                return string();
 
-       //don't return unit-from-choice if the input(field) contains a unit
+       // don't return unit-from-choice if the input(field) contains a unit
        if (isValidGlueLength(length))
                return length;
 
-       string unit = strip(frontStrip(fl_get_choice_text(choice)));
+       string unit = trim(fl_get_choice_text(choice));
        unit = subst(unit, "%%", "%");
 
        return length + unit;
@@ -135,7 +146,7 @@ void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
                fl_set_input(input, str.c_str());
                // we assume that "default_unit" is in the choice as "we"
                // have control over that!
-               // No need to check for it's precence in the choice, therefore.
+               // No need to check for its presence in the choice, therefore.
                fl_set_choice_text(choice, default_unit.c_str());
        } else {
                updateWidgetsFromLength(input, choice,
@@ -187,7 +198,7 @@ string formatted(string const & sin, int w, int size, int style)
        for(;;) {
                string::size_type const nxtpos1 = sin.find(' ',  curpos);
                string::size_type const nxtpos2 = sin.find('\n', curpos);
-               string::size_type const nxtpos = std::min(nxtpos1, nxtpos1);
+               string::size_type const nxtpos = std::min(nxtpos1, nxtpos2);
 
                string const word = nxtpos == string::npos ?
                        sin.substr(curpos) : sin.substr(curpos, nxtpos-curpos);
@@ -314,17 +325,10 @@ bool XformsColor::write(string const & filename)
        if (!os)
                return false;
 
-       os << "### This file is part of\n"
-          << "### ========================================================\n"
-          << "###          LyX, The Document Processor\n"
-          << "###\n"
-          << "###          Copyright 1995 Matthias Ettrich\n"
-          << "###          Copyright 1995-2002 The LyX Team.\n"
-          << "###\n"
-          << "### ========================================================\n"
-          << "\n"
-          << "# This file is written by LyX, if you want to make your own\n"
-          << "# modifications you should do them from inside LyX and save\n"
+       os << "###"
+          << "### file " << filename << "\n\n"
+          << "### This file is written by LyX, if you want to make your own\n"
+          << "### modifications you should do them from inside LyX and save\n"
           << "\n";
 
        for (int i = 0; i < xformCount; ++i) {