X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fxforms%2Fxforms_helpers.C;h=67055a5c1a5425e78446ff0ce11ee70d4a986a95;hb=e8c9544a2d74248d6b64d4833f01874893aca2ee;hp=eccfa54a185968e333e9630b873aa1904000bc8f;hpb=1eb8155fa0d2253d9504a8d660cb3d666c1224f6;p=lyx.git diff --git a/src/frontends/xforms/xforms_helpers.C b/src/frontends/xforms/xforms_helpers.C index eccfa54a18..67055a5c1a 100644 --- a/src/frontends/xforms/xforms_helpers.C +++ b/src/frontends/xforms/xforms_helpers.C @@ -10,9 +10,6 @@ #include -#ifdef __GNUG__ -#pragma implementation -#endif #include "xforms_helpers.h" @@ -26,21 +23,53 @@ #include "support/filetools.h" #include "support/lstrings.h" // frontStrip, strip -#include #include -#include + #include FORMS_H_LOCATION using std::ofstream; using std::pair; using std::vector; +using std::make_pair; + +bool isActive(FL_OBJECT * ob) +{ + return ob && ob->active > 0; +} + +std::pair parse_shortcut(string const & str) +{ + string::size_type i = str.find_first_of("&"); + if (i == string::npos || i == str.length() - 1) + return make_pair(str, string()); + + // FIXME: handle && + + string::value_type c = str[i + 1]; + return make_pair(str.substr(0, i) + str.substr(i + 1), + string("#") + c); +} + + +// A wrapper for the xforms routine, but this one accepts uint args +unsigned long fl_getmcolor(int i, + unsigned int * r, unsigned int * g, unsigned int * b) +{ + int r2, g2, b2; + unsigned long ret_val = ::fl_getmcolor(i, &r2, &g2, &b2); + *r = r2; + *g = g2; + *b = b2; + return ret_val; +} + // 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); @@ -77,15 +106,17 @@ vector 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)) @@ -93,7 +124,7 @@ string const getString(FL_OBJECT * ob, int 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)) @@ -104,7 +135,7 @@ string const getString(FL_OBJECT * ob, int line) lyx::Assert(0); } - return (tmp) ? trim(tmp) : string(); + return tmp ? trim(tmp) : string(); } string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice) @@ -117,7 +148,7 @@ 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 + // don't return unit-from-choice if the input(field) contains a unit if (isValidGlueLength(length)) return length; @@ -137,7 +168,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, @@ -154,7 +185,7 @@ void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice, lyx::Assert(input && input->objclass == FL_INPUT && choice && choice->objclass == FL_CHOICE); - if (len.zero()) { + if (len.empty()) { fl_set_input(input, ""); fl_set_choice_text(choice, default_unit.c_str()); } else { @@ -189,7 +220,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); @@ -320,7 +351,7 @@ bool XformsColor::write(string const & filename) << "### 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"; + << '\n'; for (int i = 0; i < xformCount; ++i) { string const tag = xformTags[i].tag; @@ -329,8 +360,8 @@ bool XformsColor::write(string const & filename) fl_getmcolor(colorID, &color.r, &color.g, &color.b); - os << tag << " " - << color.r << " " << color.g << " " << color.b << "\n"; + os << tag << ' ' + << color.r << ' ' << color.g << ' ' << color.b << '\n'; } return true;