One third of Andre' no-gui patch.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@622 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2000-03-20 16:37:50 +00:00
parent db0716f666
commit 90343c7ade
10 changed files with 179 additions and 103 deletions

View File

@ -1,3 +1,20 @@
2000-03-09 André Pönitz <poenitz@mathematik.tu-chemnitz.de>
* src/lyxrc.*: Added support for running without Gui
(\use_gui false)
* src/FontLoader.C: sensible defaults if no fonts are needed
* src/lyx_cb.C: New function ShowMessage (writes either to the
minibuffer or cout in case of no gui
New function AskOverwrite for common stuff
Consequently various changes to call these functions
* src/lyx_main.C: allow gui = false and handle lyxrc \use_gui false
wild guess at sensible screen resolution when having no gui
* src/lyxfont.C: no gui, no fonts... set some defaults
2000-03-20 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* src/LColor.C: made the command inset background a bit lighter.

View File

@ -112,7 +112,9 @@ void FontInfo::query()
return;
}
char ** list = XListFonts(fl_display, pattern.c_str(), 100, &matches);
char ** list = 0;
if (lyxrc.use_gui)
list = XListFonts(fl_display, pattern.c_str(), 100, &matches);
if (list == 0) {
// No fonts matched

View File

@ -197,12 +197,39 @@ void FontLoader::getFontinfo(LyXFont::FONT_FAMILY family,
}
}
// A dummy fontstruct used when there is no gui. Only the last 3 have
// well-thought values...
static XFontStruct dummyXFontStruct = {
/*XExtData *ext_data; */ 0,
/* Font fid; */ 0,
/* unsigned direction; */ FontLeftToRight,
/* unsigned min_char_or_byte2; */ 0,
/* unsigned max_char_or_byte2; */ 0,
/* unsigned min_byte1; */ 0,
/* unsigned max_byte1; */ 0,
/* Bool all_chars_exist; */ 0,
/* unsigned default_char; */ 0,
/* int n_properties; */ 0,
/* XFontProp *properties; */ 0,
/* XCharStruct min_bounds; */ 0,
/* XCharStruct max_bounds; */ 0,
/* XCharStruct *per_char; */ 0, // no character specific info
/* int ascent; */ 1, // unit ascent on character displays
/* int descent; */ 0, // no descent on character displays
};
/// Do load font
XFontStruct * FontLoader::doLoad(LyXFont::FONT_FAMILY family,
LyXFont::FONT_SERIES series,
LyXFont::FONT_SHAPE shape,
LyXFont::FONT_SIZE size)
{
if (!lyxrc.use_gui) {
return &dummyXFontStruct;
}
getFontinfo(family, series, shape);
int fsize = int( (lyxrc.font_sizes[size] * lyxrc.dpi *
(lyxrc.zoom/100.0) ) / 72.27 + 0.5 );
@ -215,10 +242,11 @@ XFontStruct * FontLoader::doLoad(LyXFont::FONT_FAMILY family,
font = "fixed";
}
XFontStruct * fs = 0;
current_view->owner()->getMiniBuffer()->Store();
current_view->owner()->getMiniBuffer()->Set(_("Loading font into X-Server..."));
XFontStruct * fs = XLoadQueryFont(fl_display, font.c_str());
fs = XLoadQueryFont(fl_display, font.c_str());
if (fs == 0) {
if (font == "fixed") {

View File

@ -397,12 +397,13 @@ void InitFigures()
bittable[i] = char(~k);
}
fl_add_canvas_handler(figinset_canvas, ClientMessage,
GhostscriptMsg, current_view->owner()->getMainForm());
// allocate color cube on pseudo-color display
// first get visual
gs_color = false;
if (lyxrc.use_gui) {
fl_add_canvas_handler(figinset_canvas, ClientMessage,
GhostscriptMsg, current_view->owner()->getMainForm());
local_gc_copy = createGC();
Visual * vi = DefaultVisual(fl_display, DefaultScreen(fl_display));
@ -428,6 +429,7 @@ void InitFigures()
}
gs_allcolors = vi->map_entries;
}
}
static
@ -1240,7 +1242,8 @@ Inset * InsetFig::Clone() const
tmp->pswid = pswid;
tmp->pshgh = pshgh;
tmp->fname = fname;
if (!fname.empty() && (flags & 3) && !lyxrc.ps_command.empty()) {
if (!fname.empty() && (flags & 3) && !lyxrc.ps_command.empty()
&& lyxrc.use_gui) {
// do not display if there is
// "do not display" chosen (Matthias 260696)
tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,

View File

@ -175,6 +175,18 @@ void MenuReload(Buffer * buf);
void MenuLayoutSave();
void ShowMessage(Buffer * buf, string const & msg1,
string const & msg2 = string(), string const & msg3 = string(), int delay=6)
{
if (lyxrc.use_gui) {
buf->getUser()->owner()->getMiniBuffer()->Set(msg1, msg2, msg3, delay);
}
else {
// can somebody think of something more clever? cerr?
cout << msg1 << msg2 << msg3 << endl;
}
}
// How should this actually work? Should it prohibit input in all BufferViews,
// or just in the current one? If "just the current one", then it should be
// placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
@ -345,9 +357,8 @@ void MenuWriteAs(Buffer * buffer)
buffer->fileName(s);
buffer->markDirty();
buffer->getUser()->owner()->getMiniBuffer()->Set(_("Document renamed to '"),
MakeDisplayPath(s),
_("', but not saved..."));
ShowMessage(buffer, _("Document renamed to '"),
MakeDisplayPath(s), _("', but not saved..."));
}
return;
} // Check whether the file exists
@ -549,12 +560,10 @@ bool RunScript(Buffer * buffer, bool wait,
#ifdef WITH_WARNINGS
#warning What should we do here?
#endif
buffer->getUser()->owner()->getMiniBuffer()->Set(
_("Executing command:"), cmd);
ShowMessage(buffer, _("Executing command:"), cmd);
result = one.startscript(Systemcalls::System, cmd);
} else {
buffer->getUser()->owner()->getMiniBuffer()->Set(
_("Executing command:"), cmd);
ShowMessage(buffer, _("Executing command:"), cmd);
result = one.startscript(wait ? Systemcalls::Wait
: Systemcalls::DontWait, cmd);
}
@ -772,6 +781,22 @@ bool PreviewDVI(Buffer * buffer)
}
bool AskOverwrite(Buffer * buffer, string const & s)
{
if (lyxrc.use_gui) {
// be friendly if there is a gui
FileInfo fi(s);
if (fi.readable() &&
!AskQuestion(_("File already exists:"),
MakeDisplayPath(s, 50),
_("Do you want to overwrite the file?"))) {
ShowMessage(buffer, _("Canceled"));
return false;
}
}
return true;
}
void MenuMakeLaTeX(Buffer * buffer)
{
// Why care about this?
@ -781,25 +806,18 @@ void MenuMakeLaTeX(Buffer * buffer)
// Get LaTeX-Filename
string s = buffer->getLatexName(false);
FileInfo fi(s);
if (fi.readable() &&
!AskQuestion(_("File already exists:"),
MakeDisplayPath(s, 50),
_("Do you want to overwrite the file?"))) {
buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
if (!AskOverwrite(buffer, s))
return;
}
if (buffer->isDocBook())
buffer->getUser()->owner()->getMiniBuffer()->Set(
_("DocBook does not have a latex backend"));
ShowMessage(buffer, _("DocBook does not have a latex backend"));
else {
if (buffer->isLinuxDoc())
RunLinuxDoc(buffer->getUser(), 0, buffer->fileName());
else
buffer->makeLaTeXFile(s, string(), true);
buffer->getUser()->owner()->getMiniBuffer()->Set(
_("Nice LaTeX file saved as"), MakeDisplayPath(s));
ShowMessage(buffer, _("Nice LaTeX file saved as"),
MakeDisplayPath(s));
buffer->markDviDirty();
}
}
@ -819,21 +837,15 @@ void MenuMakeLinuxDoc(Buffer * buffer)
string s = ChangeExtension(buffer->fileName(),
".sgml", false);
FileInfo fi(s);
if (fi.readable() &&
!AskQuestion(_("File already exists:"),
MakeDisplayPath(s, 50),
_("Do you want to overwrite the file?"))) {
buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
if (!AskOverwrite(buffer, s))
return;
}
buffer->getUser()->owner()->getMiniBuffer()->Set(_("Building LinuxDoc SGML file `"),
ShowMessage(buffer, _("Building LinuxDoc SGML file `"),
MakeDisplayPath(s),"'...");
buffer->makeLinuxDocFile(s, 65);
buffer->redraw();
buffer->getUser()->owner()->getMiniBuffer()->Set(_("LinuxDoc SGML file save as"),
ShowMessage(buffer, _("LinuxDoc SGML file save as"),
MakeDisplayPath(s));
}
@ -853,21 +865,15 @@ void MenuMakeDocBook(Buffer * buffer)
string s = ChangeExtension(buffer->fileName(),
".sgml", false);
FileInfo fi(s);
if (fi.readable() &&
!AskQuestion(_("File already exists:"),
MakeDisplayPath(s, 50),
_("Do you want to overwrite the file?"))) {
buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
if (!AskOverwrite(buffer, s))
return;
}
buffer->getUser()->owner()->getMiniBuffer()->Set(_("Building DocBook SGML file `"),
ShowMessage(buffer, _("Building DocBook SGML file `"),
MakeDisplayPath(s), "'...");
buffer->makeDocBookFile(s, 65);
buffer->redraw();
buffer->getUser()->owner()->getMiniBuffer()->Set(_("DocBook SGML file save as"),
ShowMessage(buffer, _("DocBook SGML file save as"),
MakeDisplayPath(s));
}
@ -881,18 +887,13 @@ void MenuMakeAscii(Buffer * buffer)
string s = ChangeExtension (buffer->fileName(),
".txt", false);
FileInfo fi(s);
if (fi.readable() &&
!AskQuestion(_("File already exists:"),
MakeDisplayPath(s, 50),
_("Do you want to overwrite the file?"))) {
buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
if (!AskOverwrite(buffer, s))
return;
}
buffer->writeFileAscii(s, lyxrc.ascii_linelen);
buffer->getUser()->owner()->getMiniBuffer()->Set(_("Ascii file saved as"), MakeDisplayPath(s));
ShowMessage(buffer, _("Ascii file saved as"), MakeDisplayPath(s));
}
@ -936,10 +937,10 @@ void MenuMakeHTML(Buffer * buffer)
Systemcalls one;
int res = one.startscript(Systemcalls::System, tmp);
if (res == 0) {
buffer->getUser()->owner()->getMiniBuffer()->Set(_("Document exported as HTML to file `")
ShowMessage(buffer, _("Document exported as HTML to file `")
+ MakeDisplayPath(result) +'\'');
} else {
buffer->getUser()->owner()->getMiniBuffer()->Set(_("Unable to convert to HTML the file `")
ShowMessage(buffer, _("Unable to convert to HTML the file `")
+ MakeDisplayPath(infile)
+ '\'');
}
@ -996,7 +997,7 @@ void MenuExport(Buffer * buffer, string const & extyp)
MenuMakeHTML(buffer);
}
else {
buffer->getUser()->owner()->getMiniBuffer()->Set(_("Unknown export type: ") + extyp);
ShowMessage(buffer, _("Unknown export type: ") + extyp);
}
}

View File

@ -79,7 +79,7 @@ LyX::LyX(int * argc, char * argv[])
// Initialization of LyX (reads lyxrc and more)
lyxerr[Debug::INIT] << "Initializing LyX::init..." << endl;
init(argc, argv);
init(argc, argv, gui);
lyxerr[Debug::INIT] << "Initializing LyX::init...done" << endl;
lyxGUI->init();
@ -114,6 +114,7 @@ LyX::LyX(int * argc, char * argv[])
if (last_loaded != 0) {
lyxerr.debug() << "Yes we loaded some files." << endl;
if (lyxrc.use_gui)
lyxGUI->regBuf(last_loaded);
}
@ -142,7 +143,7 @@ LyX::~LyX()
extern "C" void error_handler(int err_sig);
void LyX::init(int */*argc*/, char **argv)
void LyX::init(int */*argc*/, char **argv, bool gui)
{
// Install the signal handlers
signal(SIGHUP, error_handler);
@ -334,11 +335,20 @@ void LyX::init(int */*argc*/, char **argv)
}
// Calculate screen dpi as average of x-DPI and y-DPI:
// Disable gui when either lyxrc or easyparse says so
if (!gui)
lyxrc.use_gui = false;
// Calculate screen dpi as average of x-DPI and y-DPI:
if (lyxrc.use_gui) {
Screen * scr = DefaultScreenOfDisplay(fl_get_display());
lyxrc.dpi = ((HeightOfScreen(scr)* 25.4 / HeightMMOfScreen(scr)) +
(WidthOfScreen(scr)* 25.4 / WidthMMOfScreen(scr))) / 2;
lyxerr[Debug::INFO] << "DPI setting detected to be "
<< lyxrc.dpi + 0.5 << endl;
} else {
lyxrc.dpi = 1; // I hope this is safe
}
//
// Read configuration files
@ -565,6 +575,7 @@ bool LyX::easyParse(int * argc, char * argv[])
"ps...] after ")
<< arg << _(" switch!") << endl;
}
gui = false;
}
return gui;
}

View File

@ -74,7 +74,7 @@ private:
///
void runtime();
///
void init(int * argc, char * argv[]);
void init(int * argc, char * argv[], bool);
///
void queryUserLyXDir();
///

View File

@ -855,17 +855,6 @@ int LyXFont::descent(char c) const
}
// Specialized after profiling. (Asger)
int LyXFont::width(char c) const
{
if (realShape() != LyXFont::SMALLCAPS_SHAPE){
return XTextWidth(getXFontstruct(), &c, 1);
} else {
return textWidth(&c, 1);
}
}
int LyXFont::lbearing(char c) const
{
XFontStruct * finfo = getXFontstruct();
@ -892,8 +881,22 @@ int LyXFont::rbearing(char c) const
}
// Specialized after profiling. (Asger)
int LyXFont::width(char c) const
{
if (realShape() != LyXFont::SMALLCAPS_SHAPE){
return lyxrc.use_gui ? XTextWidth(getXFontstruct(), &c, 1) : 1;
} else {
return textWidth(&c, 1);
}
}
int LyXFont::textWidth(char const * s, int n) const
{
if (!lyxrc.use_gui)
return n;
if (realShape() != LyXFont::SMALLCAPS_SHAPE){
return XTextWidth(getXFontstruct(), s, n);
} else {

View File

@ -147,6 +147,7 @@ enum LyXRCTags {
RC_DVI_TO_PS_COMMAND,
RC_DATE_INSERT_FORMAT,
RC_SHOW_BANNER,
RC_USE_GUI,
RC_LAST
};
@ -245,6 +246,7 @@ keyword_item lyxrcTags[] = {
{ "\\template_path", RC_TEMPLATEPATH },
{ "\\use_alt_language", RC_USE_ALT_LANG },
{ "\\use_escape_chars", RC_USE_ESC_CHARS },
{ "\\use_gui", RC_USE_GUI },
{ "\\use_input_encoding", RC_USE_INP_ENC },
{ "\\use_personal_dictionary", RC_USE_PERS_DICT },
{ "\\use_tempdir", RC_USETEMPDIR },
@ -359,6 +361,7 @@ void LyXRC::setDefaults() {
///
date_insert_format = "%A, %e %B %Y";
show_banner = true;
use_gui = true;
//
defaultKeyBindings();
}
@ -990,6 +993,10 @@ int LyXRC::read(string const & filename)
if (lexrc.next())
show_banner = lexrc.GetBool();
break;
case RC_USE_GUI:
if (lexrc.next())
use_gui = lexrc.GetBool();
break;
case RC_LAST: break; // this is just a dummy
}
}
@ -1307,6 +1314,8 @@ void LyXRC::output(ostream & os) const
<< "\"\n";
case RC_SHOW_BANNER:
os << "\\show_banner " << tostr(show_banner) << "\n";
case RC_USE_GUI:
os << "\\use_gui " << tostr(show_banner) << "\n";
}
os.flush();
}

View File

@ -226,6 +226,8 @@ public:
string auto_mathmode;
///
bool show_banner;
/// Do we have to use a GUI?
bool use_gui;
///
typedef map<string, int> Bindings;
///