From 90343c7ade8fb41afe6c50d4902b7a15bfa8c4e6 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Mon, 20 Mar 2000 16:37:50 +0000 Subject: [PATCH] One third of Andre' no-gui patch. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@622 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 17 +++++++ src/FontInfo.C | 4 +- src/FontLoader.C | 34 ++++++++++++-- src/insets/figinset.C | 55 ++++++++++++----------- src/lyx_cb.C | 101 +++++++++++++++++++++--------------------- src/lyx_main.C | 27 +++++++---- src/lyx_main.h | 2 +- src/lyxfont.C | 25 ++++++----- src/lyxrc.C | 15 +++++-- src/lyxrc.h | 2 + 10 files changed, 179 insertions(+), 103 deletions(-) diff --git a/ChangeLog b/ChangeLog index cf1f3e0957..c429e6ef49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2000-03-09 André Pönitz + + * 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 * src/LColor.C: made the command inset background a bit lighter. diff --git a/src/FontInfo.C b/src/FontInfo.C index c4ec36d9dc..4daf1d86aa 100644 --- a/src/FontInfo.C +++ b/src/FontInfo.C @@ -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 diff --git a/src/FontLoader.C b/src/FontLoader.C index b81c0a6116..cbf3bd5c45 100644 --- a/src/FontLoader.C +++ b/src/FontLoader.C @@ -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,11 +242,12 @@ 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") { lyxerr << "We're doomed. Can't get 'fixed' font." << endl; diff --git a/src/insets/figinset.C b/src/insets/figinset.C index 1d5e955245..379109db92 100644 --- a/src/insets/figinset.C +++ b/src/insets/figinset.C @@ -397,36 +397,38 @@ 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; - local_gc_copy = createGC(); + if (lyxrc.use_gui) { + fl_add_canvas_handler(figinset_canvas, ClientMessage, + GhostscriptMsg, current_view->owner()->getMainForm()); - Visual * vi = DefaultVisual(fl_display, DefaultScreen(fl_display)); - if (lyxerr.debugging()) { - printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n", - vi->visualid, vi->c_class, - vi->bits_per_rgb, vi->map_entries); - } - color_visual = ( (vi->c_class == StaticColor) || - (vi->c_class == PseudoColor) || - (vi->c_class == TrueColor) || - (vi->c_class == DirectColor) ); - if ((vi->c_class & 1) == 0) return; - // now allocate colors - if (vi->c_class == GrayScale) { - // allocate grayscale - AllocGrays(vi->map_entries/2); - } else { - // allocate normal color - int i = 5; - while (i * i * i * 2 > vi->map_entries) --i; - AllocColors(i); + local_gc_copy = createGC(); + + Visual * vi = DefaultVisual(fl_display, DefaultScreen(fl_display)); + if (lyxerr.debugging()) { + printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n", + vi->visualid, vi->c_class, + vi->bits_per_rgb, vi->map_entries); + } + color_visual = ( (vi->c_class == StaticColor) || + (vi->c_class == PseudoColor) || + (vi->c_class == TrueColor) || + (vi->c_class == DirectColor) ); + if ((vi->c_class & 1) == 0) return; + // now allocate colors + if (vi->c_class == GrayScale) { + // allocate grayscale + AllocGrays(vi->map_entries/2); + } else { + // allocate normal color + int i = 5; + while (i * i * i * 2 > vi->map_entries) --i; + AllocColors(i); + } + gs_allcolors = vi->map_entries; } - gs_allcolors = vi->map_entries; } @@ -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, diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 48ac8b47bb..a52d5fbd7e 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -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")); - return; - } + 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(); } } @@ -818,22 +836,16 @@ void MenuMakeLinuxDoc(Buffer * buffer) // Get LinuxDoc-Filename 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)); } @@ -852,22 +864,16 @@ void MenuMakeDocBook(Buffer * buffer) // Get DocBook-Filename 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); } } diff --git a/src/lyx_main.C b/src/lyx_main.C index cf616fbc6b..6964d415ba 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -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,7 +114,8 @@ LyX::LyX(int * argc, char * argv[]) if (last_loaded != 0) { lyxerr.debug() << "Yes we loaded some files." << endl; - lyxGUI->regBuf(last_loaded); + if (lyxrc.use_gui) + lyxGUI->regBuf(last_loaded); } // Execute batch commands if available @@ -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: - 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; + // 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; } diff --git a/src/lyx_main.h b/src/lyx_main.h index a9976c1721..381a1674c3 100644 --- a/src/lyx_main.h +++ b/src/lyx_main.h @@ -74,7 +74,7 @@ private: /// void runtime(); /// - void init(int * argc, char * argv[]); + void init(int * argc, char * argv[], bool); /// void queryUserLyXDir(); /// diff --git a/src/lyxfont.C b/src/lyxfont.C index e586c8b94a..e793b80ea2 100644 --- a/src/lyxfont.C +++ b/src/lyxfont.C @@ -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 { diff --git a/src/lyxrc.C b/src/lyxrc.C index 9b71b5f7f2..6fb564ed0c 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -147,6 +147,7 @@ enum LyXRCTags { RC_DVI_TO_PS_COMMAND, RC_DATE_INSERT_FORMAT, RC_SHOW_BANNER, + RC_USE_GUI, RC_LAST }; @@ -165,8 +166,8 @@ keyword_item lyxrcTags[] = { { "\\begin_toolbar", RC_BEGINTOOLBAR }, { "\\bind", RC_BIND }, { "\\bind_file", RC_BINDFILE }, - { "\\build_command", RC_BUILD_COMMAND }, - { "\\build_error_filter", RC_BUILD_ERROR_FILTER }, + { "\\build_command", RC_BUILD_COMMAND }, + { "\\build_error_filter", RC_BUILD_ERROR_FILTER }, { "\\check_lastfiles", RC_CHECKLASTFILES }, { "\\chktex_command", RC_CHKTEX_COMMAND }, { "\\cursor_follows_scrollbar", RC_CURSOR_FOLLOWS_SCROLLBAR }, @@ -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 }, @@ -281,7 +283,7 @@ void LyXRC::setDefaults() { print_to_printer = "-P"; print_to_file = "-o "; print_file_extension = ".ps"; - print_paper_flag = "-t"; + print_paper_flag = "-t"; print_paper_dimension_flag = "-T"; document_path = GetEnvPath("HOME"); tempdir_path = "/tmp"; @@ -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(); } diff --git a/src/lyxrc.h b/src/lyxrc.h index fffbdccf46..11d680324d 100644 --- a/src/lyxrc.h +++ b/src/lyxrc.h @@ -226,6 +226,8 @@ public: string auto_mathmode; /// bool show_banner; + /// Do we have to use a GUI? + bool use_gui; /// typedef map Bindings; /// -- 2.39.2