]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/xforms_helpers.C
get rid of broken_header.h and some unneeded tests
[lyx.git] / src / frontends / xforms / xforms_helpers.C
index 71a656e7547eb837362e1be89cf86522e7135392..50fb6409d4fb85485fd65cbb49a8008bd56552fa 100644 (file)
 
 #include "xforms_helpers.h"
 
-#include "lyxlex.h"
+#include "debug.h"
 #include "gettext.h"
-#include "lyxlength.h"
+#include "lengthcommon.h"
 #include "lyxgluelength.h"
-#include "Lsstream.h"
+#include "lyxlex.h"
 
-#include "support/LAssert.h"
 #include "support/FileInfo.h"
 #include "support/filetools.h"
-#include "support/tostr.h"
 #include "support/lstrings.h" // frontStrip, strip
+#include "support/tostr.h"
 
 #include "lyx_forms.h"
 #include "combox.h"
 
+#include <boost/assert.hpp>
+
 #include <fstream>
 
-using namespace lyx::support;
+using std::make_pair;
 
 using std::ofstream;
-using std::pair;
 using std::vector;
-using std::make_pair;
+using std::string;
+
+namespace lyx {
+
+using support::AbsolutePath;
+using support::FileInfo;
+using support::isStrDbl;
+using support::OnlyPath;
+using support::subst;
+using support::trim;
+
+namespace frontend {
+
+std::string const buildChoiceLengthString()
+{
+       string data;
+       for (int i = 0; i != num_units; ++i) {
+               if (i != 0)
+                       data += "|";
+               data += subst(unit_name_gui[i], "%", "%%");
+       }
+       return data;
+}
 
 
 bool isActive(FL_OBJECT * ob)
@@ -102,7 +124,7 @@ vector<string> const getVector(FL_OBJECT * ob)
                }
                break;
        default:
-               Assert(0);
+               BOOST_ASSERT(false);
        }
 
        return vec;
@@ -113,7 +135,7 @@ vector<string> const getVector(FL_OBJECT * ob)
 string const getString(FL_OBJECT * ob, int line)
 {
        // Negative line value does not make sense.
-       Assert(line >= 0);
+       BOOST_ASSERT(line >= 0);
 
        char const * tmp = 0;
        switch (ob->objclass) {
@@ -142,7 +164,7 @@ string const getString(FL_OBJECT * ob, int line)
                break;
 
        default:
-               Assert(0);
+               BOOST_ASSERT(false);
        }
 
        return tmp ? trim(tmp) : string();
@@ -151,7 +173,7 @@ string const getString(FL_OBJECT * ob, int line)
 string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice)
 {
        // Paranoia check
-       Assert(input  && input->objclass  == FL_INPUT &&
+       BOOST_ASSERT(input  && input->objclass  == FL_INPUT &&
                    choice && choice->objclass == FL_CHOICE);
 
        string const length = trim(fl_get_input(input));
@@ -173,6 +195,10 @@ void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
                                   string const & str,
                                   string const & default_unit)
 {
+       // Paranoia check
+       BOOST_ASSERT(input  && input->objclass  == FL_INPUT &&
+                    choice && choice->objclass == FL_CHOICE);
+
        // use input field only for gluelengths
        if (!isValidLength(str) && !isStrDbl(str)) {
                fl_set_input(input, str.c_str());
@@ -192,8 +218,8 @@ void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
                             string const & default_unit)
 {
        // Paranoia check
-       Assert(input  && input->objclass  == FL_INPUT &&
-                   choice && choice->objclass == FL_CHOICE);
+       BOOST_ASSERT(input  && input->objclass  == FL_INPUT &&
+                    choice && choice->objclass == FL_CHOICE);
 
        if (len.empty()) {
                fl_set_input(input, "");
@@ -310,9 +336,13 @@ const int xformCount = sizeof(xformTags) / sizeof(keyword_item);
 
 bool XformsColor::read(string const & filename)
 {
+       FileInfo const f(filename);
        LyXLex lexrc(xformTags, xformCount);
-       if (!lexrc.setFile(filename))
+       if (f.readable() && !lexrc.setFile(filename)) {
+               lyxerr << "XformsColor::read(" << filename << ")\n"
+                      << _("Failed to open file.") << std::endl;
                return false;
+       }
 
        while (lexrc.isOK()) {
                int const le = lexrc.lex();
@@ -353,8 +383,11 @@ bool XformsColor::read(string const & filename)
 bool XformsColor::write(string const & filename)
 {
        ofstream os(filename.c_str());
-       if (!os)
+       if (!os) {
+               lyxerr << "XformsColor::write(" << filename << ")\n"
+                      << _("Failed to open file.") << std::endl;
                return false;
+       }
 
        os << "###"
           << "### file " << filename << "\n\n"
@@ -527,3 +560,6 @@ bool RWInfo::ReadableFile(string const & name)
 
        return true;
 }
+
+} // namespace frontend
+} // namespace lyx