]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/xforms_helpers.C
Bugfixes: checkboxes to radiobuttons (from J�rgen S) and remove a little
[lyx.git] / src / frontends / xforms / xforms_helpers.C
index 5675c285bd3417acc7b3b3e1e488a874477905b2..4525e091482db11009691a2be37e657b19b949f5 100644 (file)
@@ -20,6 +20,7 @@
 #include "gettext.h"
 #include "support/LAssert.h"
 #include "lyxlength.h"
+#include "lyxgluelength.h"
 
 using std::ofstream;
 using std::pair;
@@ -90,6 +91,48 @@ vector<string> const getVectorFromChoice(FL_OBJECT * ob)
 }
 
 
+/// Given an fl_input, return its contents.
+string const getStringFromInput(FL_OBJECT * ob)
+{
+       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)
 {
@@ -116,6 +159,10 @@ string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice)
        if (length.empty())
                return string();
 
+       //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)));
        unit = subst(unit, "%%", "%");
 
@@ -460,13 +507,11 @@ bool RWInfo::WriteableFile(string const & name)
 
        FileInfo d(name);
 
-       // FIXME: what is this supposed to do ?
-       // .newFile doesn't do what you think it does ... 
        if (!d.isOK() || !d.isDir()) {
                d.newFile(dir);
        }
 
-       if (!d.isDir()) {
+       if (!d.isOK() || !d.isDir()) {
                error_message = N_("Directory does not exist.");
                return false;
        }
@@ -507,12 +552,12 @@ bool RWInfo::ReadableFile(string const & name)
        }
 
        FileInfo d(name);
-       // FIXME: what is this supposed to do ?
+
        if (!d.isOK() && !d.isDir()) {
                d.newFile(dir);
        }
 
-       if (!d.isDir()) {
+       if (!d.isOK() || !d.isDir()) {
                error_message = N_("Directory does not exist.");
                return false;
        }