2002-03-11 17:00:41 +00:00
|
|
|
/**
|
|
|
|
* \file xforms_helpers.C
|
|
|
|
* Copyright 2000-2002 The LyX Team.
|
|
|
|
* See the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming, a.leeming@ic.ac.uk
|
2000-11-02 14:47:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include FORMS_H_LOCATION
|
|
|
|
|
2000-12-29 12:48:02 +00:00
|
|
|
#include <fstream> // ofstream
|
|
|
|
#include <vector>
|
|
|
|
|
2000-11-02 14:47:47 +00:00
|
|
|
#ifdef __GNUG_
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
2001-03-07 14:25:31 +00:00
|
|
|
|
2001-03-05 19:02:40 +00:00
|
|
|
#include "xforms_helpers.h"
|
2000-11-15 18:02:45 +00:00
|
|
|
#include "lyxlex.h"
|
|
|
|
#include "gettext.h"
|
2001-12-12 09:56:03 +00:00
|
|
|
#include "lyxlength.h"
|
2002-01-16 16:34:03 +00:00
|
|
|
#include "lyxgluelength.h"
|
2002-03-13 11:26:36 +00:00
|
|
|
#include "support/LAssert.h"
|
|
|
|
#include "support/FileInfo.h"
|
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "support/lstrings.h" // frontStrip, strip
|
2000-11-02 14:47:47 +00:00
|
|
|
|
2000-11-15 18:02:45 +00:00
|
|
|
using std::ofstream;
|
|
|
|
using std::pair;
|
2000-11-02 14:47:47 +00:00
|
|
|
using std::vector;
|
|
|
|
|
2001-11-26 10:19:58 +00:00
|
|
|
// 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;
|
2001-12-05 08:04:20 +00:00
|
|
|
while (sd[0]!= 0 && sd[0] != '|') ++sd;
|
2001-11-26 10:19:58 +00:00
|
|
|
|
|
|
|
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;
|
2001-12-05 08:04:20 +00:00
|
|
|
while (se[0]!= 0 && se[0] != '|') ++se;
|
2001-11-26 10:19:58 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-05 19:02:40 +00:00
|
|
|
// 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);
|
|
|
|
} else {
|
|
|
|
fl_deactivate_object(ob);
|
|
|
|
fl_set_object_lcol(ob, FL_INACTIVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-24 16:37:24 +00:00
|
|
|
// Given an fl_choice, create a vector of its entries
|
|
|
|
vector<string> const getVectorFromChoice(FL_OBJECT * ob)
|
|
|
|
{
|
|
|
|
vector<string> vec;
|
|
|
|
if (!ob || ob->objclass != FL_CHOICE)
|
|
|
|
return 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)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-15 15:31:19 +00:00
|
|
|
/// 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-14 12:47:17 +00:00
|
|
|
// Given an fl_browser, return the contents of line
|
2002-01-08 10:05:53 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2002-01-14 12:47:17 +00:00
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-24 16:37:24 +00:00
|
|
|
// 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)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-09 12:36:36 +00:00
|
|
|
string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice)
|
|
|
|
{
|
|
|
|
// Paranoia check
|
|
|
|
lyx::Assert(input && input->objclass == FL_INPUT &&
|
|
|
|
choice && choice->objclass == FL_CHOICE);
|
|
|
|
|
2001-10-11 17:28:28 +00:00
|
|
|
string const length = strip(frontStrip(fl_get_input(input)));
|
2001-10-09 15:20:10 +00:00
|
|
|
if (length.empty())
|
2001-10-11 17:28:28 +00:00
|
|
|
return string();
|
2001-10-09 12:36:36 +00:00
|
|
|
|
2002-01-16 16:34:03 +00:00
|
|
|
//don't return unit-from-choice if the input(field) contains a unit
|
|
|
|
if (isValidGlueLength(length))
|
|
|
|
return length;
|
|
|
|
|
2001-10-15 10:28:31 +00:00
|
|
|
string unit = strip(frontStrip(fl_get_choice_text(choice)));
|
|
|
|
unit = subst(unit, "%%", "%");
|
2001-10-09 12:36:36 +00:00
|
|
|
|
2001-10-15 10:28:31 +00:00
|
|
|
return length + unit;
|
2001-10-09 12:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-11 18:57:30 +00:00
|
|
|
#if 0
|
|
|
|
// old code which can be deleted if the new one, now enabled,
|
|
|
|
// works satisfyingly (JSpitzm, 11/02/2002)
|
2001-12-11 17:26:52 +00:00
|
|
|
// this should definitely be the other way around!!!
|
|
|
|
void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
|
|
|
|
LyXLength const & len,
|
|
|
|
string const & default_unit)
|
|
|
|
{
|
|
|
|
if (len.zero())
|
|
|
|
updateWidgetsFromLengthString(input, choice,
|
|
|
|
string(), default_unit);
|
2002-02-11 18:57:30 +00:00
|
|
|
// use input field only for gluelengths
|
|
|
|
else if (!isValidLength(len) && !isStrDbl(len)) {
|
|
|
|
fl_set_input(input, len.c_str());
|
|
|
|
fl_set_choice_text(choice, default_unit.c_str());
|
|
|
|
}
|
2001-12-11 17:26:52 +00:00
|
|
|
else
|
|
|
|
updateWidgetsFromLengthString(input, choice,
|
|
|
|
len.asString(), default_unit);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Most of the code here is a poor duplication of the parser code
|
|
|
|
// which is in LyXLength. Use that instead
|
2001-10-09 12:36:36 +00:00
|
|
|
void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
|
2001-10-15 10:28:31 +00:00
|
|
|
string const & str,
|
|
|
|
string const & default_unit)
|
2001-10-09 12:36:36 +00:00
|
|
|
{
|
|
|
|
// Paranoia check
|
|
|
|
lyx::Assert(input && input->objclass == FL_INPUT &&
|
|
|
|
choice && choice->objclass == FL_CHOICE);
|
|
|
|
|
2001-10-11 17:28:28 +00:00
|
|
|
if (str.empty()) {
|
|
|
|
fl_set_input(input, "");
|
2001-10-15 10:28:31 +00:00
|
|
|
int unitpos = 1; // xforms has Fortran-style indexing
|
|
|
|
for(int i = 0; i < fl_get_choice_maxitems(choice); ++i) {
|
|
|
|
string const text = fl_get_choice_item_text(choice,i+1);
|
|
|
|
if (default_unit ==
|
|
|
|
lowercase(strip(frontStrip(text)))) {
|
|
|
|
unitpos = i+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fl_set_choice(choice, unitpos);
|
2001-10-11 17:28:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-10-09 12:36:36 +00:00
|
|
|
// The unit is presumed to begin at the first char a-z
|
2002-02-04 15:36:45 +00:00
|
|
|
// or with the char '%'
|
2001-10-09 12:36:36 +00:00
|
|
|
string const tmp = lowercase(strip(frontStrip(str)));
|
|
|
|
|
|
|
|
string::const_iterator p = tmp.begin();
|
|
|
|
for (; p != tmp.end(); ++p) {
|
2002-02-04 15:36:45 +00:00
|
|
|
if ((*p >= 'a' && *p <= 'z') || *p == '%')
|
2001-10-09 12:36:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
string len = "0";
|
|
|
|
int unitpos = 1; // xforms has Fortran-style indexing
|
|
|
|
|
|
|
|
if (p == tmp.end()) {
|
|
|
|
if (isStrDbl(tmp))
|
|
|
|
len = tmp;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
string tmplen = string(tmp.begin(), p);
|
|
|
|
if (isStrDbl(tmplen))
|
|
|
|
len = tmplen;
|
2001-10-15 10:28:31 +00:00
|
|
|
string unit = string(p, tmp.end());
|
|
|
|
unit = subst(unit, "%", "%%");
|
2001-10-09 12:36:36 +00:00
|
|
|
|
|
|
|
for(int i = 0; i < fl_get_choice_maxitems(choice); ++i) {
|
|
|
|
string const text = fl_get_choice_item_text(choice,i+1);
|
|
|
|
if (unit == lowercase(strip(frontStrip(text)))) {
|
|
|
|
unitpos = i+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fl_set_input(input, len.c_str());
|
|
|
|
fl_set_choice(choice, unitpos);
|
|
|
|
}
|
2001-12-11 17:26:52 +00:00
|
|
|
#else
|
|
|
|
void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
|
|
|
|
string const & str,
|
|
|
|
string const & default_unit)
|
|
|
|
{
|
2002-02-11 18:57:30 +00:00
|
|
|
// use input field only for gluelengths
|
|
|
|
if (!isValidLength(str) && !isStrDbl(str)) {
|
|
|
|
fl_set_input(input, str.c_str());
|
|
|
|
fl_set_choice_text(choice, default_unit.c_str());
|
|
|
|
} else {
|
|
|
|
updateWidgetsFromLength(input, choice,
|
2001-12-11 17:26:52 +00:00
|
|
|
LyXLength(str), default_unit);
|
2002-02-11 18:57:30 +00:00
|
|
|
}
|
2001-12-11 17:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
|
|
|
|
LyXLength const & len,
|
|
|
|
string const & default_unit)
|
|
|
|
{
|
|
|
|
// Paranoia check
|
|
|
|
lyx::Assert(input && input->objclass == FL_INPUT &&
|
|
|
|
choice && choice->objclass == FL_CHOICE);
|
|
|
|
|
|
|
|
if (len.zero()) {
|
|
|
|
fl_set_input(input, "");
|
|
|
|
fl_set_choice_text(choice, default_unit.c_str());
|
|
|
|
} else {
|
|
|
|
ostringstream buffer;
|
|
|
|
buffer << len.value();
|
|
|
|
fl_set_input(input, buffer.str().c_str());
|
2002-02-14 17:43:53 +00:00
|
|
|
fl_set_choice_text(choice,
|
|
|
|
subst(stringFromUnit(len.unit()),"%","%%").c_str());
|
2001-12-11 17:26:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2000-11-02 14:47:47 +00:00
|
|
|
// Take a string and add breaks so that it fits into a desired label width, w
|
2000-12-29 12:48:02 +00:00
|
|
|
string formatted(string const & sin, int w, int size, int style)
|
2000-11-02 14:47:47 +00:00
|
|
|
{
|
|
|
|
string sout;
|
2000-12-29 12:48:02 +00:00
|
|
|
if (sin.empty()) return sout;
|
2000-11-02 14:47:47 +00:00
|
|
|
|
2002-03-18 15:56:00 +00:00
|
|
|
#if 0
|
|
|
|
// FIX: Q: Why cant this be done by a one pass algo? (Lgb)
|
|
|
|
|
2001-09-24 16:37:24 +00:00
|
|
|
// breaks in up into a vector of individual words
|
2000-11-02 14:47:47 +00:00
|
|
|
vector<string> sentence;
|
|
|
|
string word;
|
2000-11-04 10:00:12 +00:00
|
|
|
for (string::const_iterator sit = sin.begin();
|
|
|
|
sit != sin.end(); ++sit) {
|
|
|
|
if ((*sit) == ' ' || (*sit) == '\n') {
|
2001-04-24 06:34:13 +00:00
|
|
|
if (!word.empty()) {
|
|
|
|
sentence.push_back(word);
|
|
|
|
word.erase();
|
|
|
|
}
|
2001-03-22 11:24:36 +00:00
|
|
|
if ((*sit) == '\n') word += '\n';
|
|
|
|
|
2000-11-02 14:47:47 +00:00
|
|
|
} else {
|
|
|
|
word += (*sit);
|
|
|
|
}
|
|
|
|
}
|
2001-03-22 11:24:36 +00:00
|
|
|
|
2000-11-02 14:47:47 +00:00
|
|
|
// Flush remaining contents of word
|
2002-02-16 15:59:55 +00:00
|
|
|
if (!word.empty()) sentence.push_back(word);
|
2000-11-02 14:47:47 +00:00
|
|
|
|
2001-04-04 21:58:35 +00:00
|
|
|
string line;
|
|
|
|
string line_plus_word;
|
2000-11-04 10:00:12 +00:00
|
|
|
for (vector<string>::const_iterator vit = sentence.begin();
|
|
|
|
vit != sentence.end(); ++vit) {
|
2001-04-04 21:58:35 +00:00
|
|
|
string word(*vit);
|
2001-03-22 11:24:36 +00:00
|
|
|
|
|
|
|
char c = word[0];
|
|
|
|
if (c == '\n') {
|
|
|
|
sout += line + '\n';
|
2001-04-20 13:18:09 +00:00
|
|
|
word.erase(0,1);
|
2001-03-22 11:24:36 +00:00
|
|
|
line_plus_word.erase();
|
|
|
|
line.erase();
|
|
|
|
}
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
if (!line_plus_word.empty()) line_plus_word += ' ';
|
2001-03-22 11:24:36 +00:00
|
|
|
line_plus_word += word;
|
|
|
|
|
2001-04-04 21:58:35 +00:00
|
|
|
int const length = fl_get_string_width(style, size,
|
|
|
|
line_plus_word.c_str(),
|
|
|
|
int(line_plus_word.length()));
|
2000-11-04 10:00:12 +00:00
|
|
|
if (length >= w) {
|
2001-03-22 11:24:36 +00:00
|
|
|
sout += line + '\n';
|
|
|
|
line_plus_word = word;
|
2000-11-02 14:47:47 +00:00
|
|
|
}
|
|
|
|
|
2001-03-22 11:24:36 +00:00
|
|
|
line = line_plus_word;
|
2000-11-02 14:47:47 +00:00
|
|
|
}
|
|
|
|
// Flush remaining contents of line
|
2000-11-04 10:00:12 +00:00
|
|
|
if (!line.empty()) {
|
2000-11-02 14:47:47 +00:00
|
|
|
sout += line;
|
|
|
|
}
|
2001-03-22 11:24:36 +00:00
|
|
|
|
2001-04-04 21:58:35 +00:00
|
|
|
if (sout[sout.length() - 1] == '\n')
|
|
|
|
sout.erase(sout.length() - 1);
|
2001-03-22 11:24:36 +00:00
|
|
|
|
2002-03-18 15:56:00 +00:00
|
|
|
#else
|
|
|
|
string::size_type curpos = 0;
|
|
|
|
string line;
|
|
|
|
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 const word = nxtpos == string::npos ?
|
|
|
|
sin.substr(curpos) : sin.substr(curpos, nxtpos-curpos);
|
|
|
|
|
|
|
|
bool const newline = (nxtpos2 != string::npos &&
|
|
|
|
nxtpos2 < nxtpos1);
|
|
|
|
|
|
|
|
string const line_plus_word =
|
|
|
|
line.empty() ? word : line + ' ' + word;
|
|
|
|
|
|
|
|
int const length =
|
|
|
|
fl_get_string_width(style, size,
|
|
|
|
line_plus_word.c_str(),
|
|
|
|
int(line_plus_word.length()));
|
|
|
|
|
|
|
|
if (length >= w) {
|
|
|
|
sout += line + '\n';
|
|
|
|
if (newline) {
|
|
|
|
sout += word + '\n';
|
|
|
|
line.erase();
|
|
|
|
} else {
|
|
|
|
line = word;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (newline) {
|
|
|
|
sout += line_plus_word + '\n';
|
|
|
|
line.erase();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (!line.empty())
|
|
|
|
line += ' ';
|
|
|
|
line += word;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nxtpos == string::npos) {
|
|
|
|
if (!line.empty())
|
|
|
|
sout += line;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
curpos = nxtpos+1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-11-02 14:47:47 +00:00
|
|
|
return sout;
|
|
|
|
}
|
2000-11-15 18:02:45 +00:00
|
|
|
|
|
|
|
|
2002-03-13 11:26:36 +00:00
|
|
|
void setCursorColor(int color)
|
|
|
|
{
|
|
|
|
fl_set_cursor_color(FL_DEFAULT_CURSOR, color, FL_WHITE);
|
|
|
|
fl_set_cursor_color(XC_xterm, color, FL_WHITE);
|
|
|
|
fl_set_cursor_color(XC_watch, color, FL_WHITE);
|
|
|
|
fl_set_cursor_color(XC_sb_right_arrow, color, FL_WHITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
2000-11-15 18:02:45 +00:00
|
|
|
// sorted by hand to prevent LyXLex from complaining on read().
|
|
|
|
keyword_item xformTags[] = {
|
2002-03-11 09:54:42 +00:00
|
|
|
{ "\\gui_background", FL_COL1 },
|
2000-11-15 18:02:45 +00:00
|
|
|
{ "\\gui_buttonbottom", FL_BOTTOM_BCOL },
|
2002-03-11 09:54:42 +00:00
|
|
|
{ "\\gui_buttonleft", FL_LEFT_BCOL },
|
|
|
|
{ "\\gui_buttonright", FL_RIGHT_BCOL },
|
|
|
|
{ "\\gui_buttontop", FL_TOP_BCOL },
|
|
|
|
{ "\\gui_inactive", FL_INACTIVE },
|
|
|
|
{ "\\gui_pointer", FL_FREE_COL16 },
|
|
|
|
{ "\\gui_push_button", FL_YELLOW },
|
|
|
|
{ "\\gui_selected", FL_MCOL },
|
|
|
|
{ "\\gui_text", FL_BLACK }
|
2000-11-15 18:02:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
const int xformCount = sizeof(xformTags) / sizeof(keyword_item);
|
|
|
|
|
|
|
|
} // namespace anon
|
2000-11-15 18:02:45 +00:00
|
|
|
|
|
|
|
|
2001-03-05 19:02:40 +00:00
|
|
|
bool XformsColor::read(string const & filename)
|
2000-11-15 18:02:45 +00:00
|
|
|
{
|
|
|
|
LyXLex lexrc(xformTags, xformCount);
|
|
|
|
if (!lexrc.setFile(filename))
|
|
|
|
return false;
|
|
|
|
|
2001-08-06 19:13:25 +00:00
|
|
|
while (lexrc.isOK()) {
|
2000-11-15 18:02:45 +00:00
|
|
|
int const le = lexrc.lex();
|
|
|
|
|
|
|
|
switch (le) {
|
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
lexrc.printError("Unknown tag `$$Token'");
|
|
|
|
continue;
|
|
|
|
case LyXLex::LEX_FEOF:
|
|
|
|
continue;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2002-03-11 09:54:42 +00:00
|
|
|
string const tag = lexrc.getString();
|
|
|
|
|
2000-11-15 18:02:45 +00:00
|
|
|
RGBColor col;
|
|
|
|
|
|
|
|
if (!lexrc.next()) break;
|
2001-08-06 19:13:25 +00:00
|
|
|
col.r = lexrc.getInteger();
|
2000-11-15 18:02:45 +00:00
|
|
|
|
|
|
|
if (!lexrc.next()) break;
|
2001-08-06 19:13:25 +00:00
|
|
|
col.g = lexrc.getInteger();
|
2000-11-15 18:02:45 +00:00
|
|
|
|
|
|
|
if (!lexrc.next()) break;
|
2001-08-06 19:13:25 +00:00
|
|
|
col.b = lexrc.getInteger();
|
2000-11-15 18:02:45 +00:00
|
|
|
|
|
|
|
fl_mapcolor(le, col.r, col.g, col.b);
|
2002-03-11 09:54:42 +00:00
|
|
|
|
|
|
|
if (tag == "\\gui_pointer") {
|
2002-03-13 11:26:36 +00:00
|
|
|
setCursorColor(FL_FREE_COL16);
|
2002-03-11 09:54:42 +00:00
|
|
|
}
|
2000-11-15 18:02:45 +00:00
|
|
|
}
|
2002-03-13 11:26:36 +00:00
|
|
|
|
2000-11-15 18:02:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-05 19:02:40 +00:00
|
|
|
bool XformsColor::write(string const & filename)
|
2000-11-15 18:02:45 +00:00
|
|
|
{
|
|
|
|
ofstream os(filename.c_str());
|
|
|
|
if (!os)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
os << "### This file is part of\n"
|
|
|
|
<< "### ========================================================\n"
|
|
|
|
<< "### LyX, The Document Processor\n"
|
|
|
|
<< "###\n"
|
|
|
|
<< "### Copyright 1995 Matthias Ettrich\n"
|
2002-03-11 09:54:42 +00:00
|
|
|
<< "### Copyright 1995-2002 The LyX Team.\n"
|
2000-11-15 18:02:45 +00:00
|
|
|
<< "###\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"
|
|
|
|
<< "\n";
|
|
|
|
|
|
|
|
for (int i = 0; i < xformCount; ++i) {
|
|
|
|
string const tag = xformTags[i].tag;
|
|
|
|
int const colorID = xformTags[i].code;
|
|
|
|
RGBColor color;
|
|
|
|
|
|
|
|
fl_getmcolor(colorID, &color.r, &color.g, &color.b);
|
|
|
|
|
|
|
|
os << tag << " "
|
|
|
|
<< color.r << " " << color.g << " " << color.b << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2000-11-21 15:46:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
string RWInfo::error_message;
|
|
|
|
|
|
|
|
bool RWInfo::WriteableDir(string const & name)
|
|
|
|
{
|
|
|
|
error_message.erase();
|
|
|
|
|
|
|
|
if (!AbsolutePath(name)) {
|
|
|
|
error_message = N_("The absolute path is required.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileInfo const tp(name);
|
2002-01-07 10:17:44 +00:00
|
|
|
if (!tp.isOK() || !tp.isDir()) {
|
2000-11-21 15:46:13 +00:00
|
|
|
error_message = N_("Directory does not exist.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tp.writable()) {
|
|
|
|
error_message = N_("Cannot write to this directory.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RWInfo::ReadableDir(string const & name)
|
|
|
|
{
|
|
|
|
error_message.erase();
|
|
|
|
|
|
|
|
if (!AbsolutePath(name)) {
|
|
|
|
error_message = N_("The absolute path is required.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileInfo const tp(name);
|
2002-01-07 10:17:44 +00:00
|
|
|
if (!tp.isOK() || !tp.isDir()) {
|
2000-11-21 15:46:13 +00:00
|
|
|
error_message = N_("Directory does not exist.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tp.readable()) {
|
|
|
|
error_message = N_("Cannot read this directory.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RWInfo::WriteableFile(string const & name)
|
|
|
|
{
|
|
|
|
// A writeable file is either:
|
|
|
|
// * An existing file to which we have write access, or
|
|
|
|
// * A file that doesn't yet exist but that would exist in a writeable
|
|
|
|
// directory.
|
|
|
|
|
|
|
|
error_message.erase();
|
|
|
|
|
|
|
|
if (name.empty()) {
|
|
|
|
error_message = N_("No file input.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
string const dir = OnlyPath(name);
|
|
|
|
if (!AbsolutePath(dir)) {
|
|
|
|
error_message = N_("The absolute path is required.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileInfo d(name);
|
2002-01-07 10:17:44 +00:00
|
|
|
|
|
|
|
if (!d.isOK() || !d.isDir()) {
|
2000-11-21 15:46:13 +00:00
|
|
|
d.newFile(dir);
|
|
|
|
}
|
|
|
|
|
2002-01-07 17:57:21 +00:00
|
|
|
if (!d.isOK() || !d.isDir()) {
|
2000-11-21 15:46:13 +00:00
|
|
|
error_message = N_("Directory does not exist.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!d.writable()) {
|
|
|
|
error_message = N_("Cannot write to this directory.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileInfo f(name);
|
2002-01-07 10:17:44 +00:00
|
|
|
if (dir == name || (f.isOK() && f.isDir())) {
|
2000-11-21 15:46:13 +00:00
|
|
|
error_message = N_("A file is required, not a directory.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-01-07 10:17:44 +00:00
|
|
|
if (f.isOK() && f.exist() && !f.writable()) {
|
2000-11-21 15:46:13 +00:00
|
|
|
error_message = N_("Cannot write to this file.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RWInfo::ReadableFile(string const & name)
|
|
|
|
{
|
|
|
|
error_message.erase();
|
|
|
|
|
|
|
|
if (name.empty()) {
|
|
|
|
error_message = N_("No file input.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
string const dir = OnlyPath(name);
|
|
|
|
if (!AbsolutePath(dir)) {
|
|
|
|
error_message = N_("The absolute path is required.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileInfo d(name);
|
2002-01-07 17:57:21 +00:00
|
|
|
|
2002-01-07 10:17:44 +00:00
|
|
|
if (!d.isOK() && !d.isDir()) {
|
2000-11-21 15:46:13 +00:00
|
|
|
d.newFile(dir);
|
|
|
|
}
|
|
|
|
|
2002-01-07 17:57:21 +00:00
|
|
|
if (!d.isOK() || !d.isDir()) {
|
2000-11-21 15:46:13 +00:00
|
|
|
error_message = N_("Directory does not exist.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!d.readable()) {
|
|
|
|
error_message = N_("Cannot read from this directory.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileInfo f(name);
|
2002-01-07 10:17:44 +00:00
|
|
|
if (dir == name || (f.isOK() && f.isDir())) {
|
2000-11-21 15:46:13 +00:00
|
|
|
error_message = N_("A file is required, not a directory.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!f.exist()) {
|
|
|
|
error_message = N_("File does not exist.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!f.readable()) {
|
|
|
|
error_message = N_("Cannot read from this file.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|