]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/xforms_helpers.C
Nothing but a changed email address (trying to factor my tree in in small steps)
[lyx.git] / src / frontends / xforms / xforms_helpers.C
index aec955b472c8116c674a216663c7708576bf77e3..dafce7d8a9342540b76713aefe0e7991a4cd4abe 100644 (file)
@@ -3,12 +3,12 @@
  * Copyright 2000-2002 The LyX Team.
  * See the file COPYING.
  *
- * \author Angus Leeming, a.leeming@ic.ac.uk
+ * \author Angus Leeming <leeming@lyx.org>
  */
 
 #include <config.h>
 
-#ifdef __GNUG_
+#ifdef __GNUG__
 #pragma implementation
 #endif
 
 #include <algorithm>
 #include <fstream>
 #include <vector>
+#include FORMS_H_LOCATION
 
 using std::ofstream;
 using std::pair;
 using std::vector;
 
-// Extract shortcut from <ident>|<shortcut> string
-char const * flyx_shortcut_extract(char const * sc)
-{
-       // Find '|' in the sc and return the string after that.
-       register char const * sd = sc;
-       while (sd[0]!= 0 && sd[0] != '|') ++sd;
-
-       if (sd[0] == '|') {
-               ++sd;
-               return sd;
-       }
-       return "";
-}
-
-
-// Extract identifier from <ident>|<shortcut> string
-char const * flyx_ident_extract(char const * sc)
-{
-       register char const * se = sc;
-       while (se[0]!= 0 && se[0] != '|') ++se;
-
-       if (se[0] == 0) return sc;
-
-       char * sb = new char[se - sc + 1];
-       int index = 0;
-       register char const * sd = sc;
-       while (sd != se) {
-               sb[index] = sd[0];
-               ++index; ++sd;
-       }
-       sb[index] = 0;
-       return sb;
-}
-
-
 // Set an FL_OBJECT to activated or deactivated
 void setEnabled(FL_OBJECT * ob, bool enable)
 {
@@ -80,87 +46,72 @@ void setEnabled(FL_OBJECT * ob, bool enable)
 }
 
 
-// Given an fl_choice, create a vector of its entries
-vector<string> const getVectorFromChoice(FL_OBJECT * ob)
+// Given an fl_choice or an fl_browser, create a vector of its entries
+vector<string> const getVector(FL_OBJECT * ob)
 {
-       vector<string> vec;
-       if (!ob || ob->objclass != FL_CHOICE)
-               return vec;
+       vector <string> vec;
 
-       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)));
+       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(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(trim(text));
+               }
+               break;
+       default:
+               lyx::Assert(0);
        }
 
        return vec;
 }
 
 
-/// Given an fl_input, return its contents.
-string const getStringFromInput(FL_OBJECT * ob)
+///
+string const getString(FL_OBJECT * ob, int line)
 {
-       if (!ob || ob->objclass != FL_INPUT)
-               return string();
-
-       char const * tmp = fl_get_input(ob);
-       return (tmp) ? tmp : string();
-}
-
-
-// Given an fl_browser, return the contents of line
-string const getStringFromBrowser(FL_OBJECT * ob, int line)
-{
-       if (!ob || ob->objclass != FL_BROWSER ||
-           line < 1 || line > fl_get_browser_maxline(ob))
-               return string();
-
-       char const * tmp = fl_get_browser_line(ob, line);
-       return (tmp) ? tmp : string();
-}
-
-// Given an fl_browser, return the contents of the currently
-// highlighted line.
-// If nothing is selected, return an empty string
-string const getSelectedStringFromBrowser(FL_OBJECT * ob)
-{
-       if (!ob || ob->objclass != FL_BROWSER)
-               return string();
-
-       int const line = fl_get_browser(ob);
-       if (line < 1 || line > fl_get_browser_maxline(ob))
-               return string();
-
-       if (!fl_isselected_browser_line(ob, line))
-               return string();
-
-       char const * tmp = fl_get_browser_line(ob, line);
-       return (tmp) ? tmp : string();
-}
-
-
-// Given an fl_browser, create a vector of its entries
-vector<string> const getVectorFromBrowser(FL_OBJECT * ob)
-{
-       vector<string> vec;
-       if (!ob || ob->objclass != FL_BROWSER)
-               return vec;
-
-       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)));
+       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)
+                       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)
+                       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 vec;
+       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();
 
@@ -168,7 +119,7 @@ string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice)
        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;
@@ -213,7 +164,7 @@ void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
                // Else set the choice to the default unit.
                string const unit = subst(stringFromUnit(len.unit()),"%","%%");
 
-               vector<string> const vec = getVectorFromChoice(choice);
+               vector<string> const vec = getVector(choice);
                vector<string>::const_iterator it =
                        std::find(vec.begin(), vec.end(), unit);
                if (it != vec.end()) {
@@ -398,18 +349,18 @@ bool RWInfo::WriteableDir(string const & name)
        error_message.erase();
 
        if (!AbsolutePath(name)) {
-               error_message = N_("The absolute path is required.");
+               error_message = _("The absolute path is required.");
                return false;
        }
 
        FileInfo const tp(name);
        if (!tp.isOK() || !tp.isDir()) {
-               error_message = N_("Directory does not exist.");
+               error_message = _("Directory does not exist.");
                return false;
        }
 
        if (!tp.writable()) {
-               error_message = N_("Cannot write to this directory.");
+               error_message = _("Cannot write to this directory.");
                return false;
        }
 
@@ -422,18 +373,18 @@ bool RWInfo::ReadableDir(string const & name)
        error_message.erase();
 
        if (!AbsolutePath(name)) {
-               error_message = N_("The absolute path is required.");
+               error_message = _("The absolute path is required.");
                return false;
        }
 
        FileInfo const tp(name);
        if (!tp.isOK() || !tp.isDir()) {
-               error_message = N_("Directory does not exist.");
+               error_message = _("Directory does not exist.");
                return false;
        }
 
        if (!tp.readable()) {
-               error_message = N_("Cannot read this directory.");
+               error_message = _("Cannot read this directory.");
                return false;
        }
 
@@ -451,13 +402,13 @@ bool RWInfo::WriteableFile(string const & name)
        error_message.erase();
 
        if (name.empty()) {
-               error_message = N_("No file input.");
+               error_message = _("No file input.");
                return false;
        }
 
        string const dir = OnlyPath(name);
        if (!AbsolutePath(dir)) {
-               error_message = N_("The absolute path is required.");
+               error_message = _("The absolute path is required.");
                return false;
        }
 
@@ -468,23 +419,23 @@ bool RWInfo::WriteableFile(string const & name)
        }
 
        if (!d.isOK() || !d.isDir()) {
-               error_message = N_("Directory does not exist.");
+               error_message = _("Directory does not exist.");
                return false;
        }
 
        if (!d.writable()) {
-               error_message = N_("Cannot write to this directory.");
+               error_message = _("Cannot write to this directory.");
                return false;
        }
 
        FileInfo f(name);
        if (dir == name || (f.isOK() && f.isDir())) {
-               error_message = N_("A file is required, not a directory.");
+               error_message = _("A file is required, not a directory.");
                return false;
        }
 
        if (f.isOK() && f.exist() && !f.writable()) {
-               error_message = N_("Cannot write to this file.");
+               error_message = _("Cannot write to this file.");
                return false;
        }
 
@@ -497,13 +448,13 @@ bool RWInfo::ReadableFile(string const & name)
        error_message.erase();
 
        if (name.empty()) {
-               error_message = N_("No file input.");
+               error_message = _("No file input.");
                return false;
        }
 
        string const dir = OnlyPath(name);
        if (!AbsolutePath(dir)) {
-               error_message = N_("The absolute path is required.");
+               error_message = _("The absolute path is required.");
                return false;
        }
 
@@ -514,28 +465,28 @@ bool RWInfo::ReadableFile(string const & name)
        }
 
        if (!d.isOK() || !d.isDir()) {
-               error_message = N_("Directory does not exist.");
+               error_message = _("Directory does not exist.");
                return false;
        }
 
        if (!d.readable()) {
-               error_message = N_("Cannot read from this directory.");
+               error_message = _("Cannot read from this directory.");
                return false;
        }
 
        FileInfo f(name);
        if (dir == name || (f.isOK() && f.isDir())) {
-               error_message = N_("A file is required, not a directory.");
+               error_message = _("A file is required, not a directory.");
                return false;
        }
 
        if (!f.exist()) {
-               error_message = N_("File does not exist.");
+               error_message = _("File does not exist.");
                return false;
        }
 
        if (!f.readable()) {
-               error_message = N_("Cannot read from this file.");
+               error_message = _("Cannot read from this file.");
                return false;
        }