]> git.lyx.org Git - lyx.git/commitdiff
One third of Andre' no-gui patch.
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 20 Mar 2000 16:37:50 +0000 (16:37 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 20 Mar 2000 16:37:50 +0000 (16:37 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@622 a592a061-630c-0410-9148-cb99ea01b6c8

ChangeLog
src/FontInfo.C
src/FontLoader.C
src/insets/figinset.C
src/lyx_cb.C
src/lyx_main.C
src/lyx_main.h
src/lyxfont.C
src/lyxrc.C
src/lyxrc.h

index cf1f3e095743f4237966e738ab29ceddee483983..c429e6ef49443b7bf29d15cf90ca216f1d299fa1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index c4ec36d9dc1a29d32bf54c15cfb6a662a82fabcf..4daf1d86aa52371496e0ab983dd2f7eed462c4a5 100644 (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
index b81c0a61167262d2731bde152e39aec207963d80..cbf3bd5c456e6adc272f8b93480c038e03edf8e3 100644 (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,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;
index 1d5e95524510c1793dbb57208cb35292da3fd962..379109db928f253c9d01473dd727704bf775d288 100644 (file)
@@ -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,
index 48ac8b47bb9da79074e077b6120a463f608e5d5c..a52d5fbd7ebe2981e49a85175f1282decc36415a 100644 (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"));
-               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);
        }
 }
 
index cf616fbc6b9a1ca8e64571648effdbe3c7460076..6964d415ba1cf4d216cadbc5a190c275825a27b6 100644 (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,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;
 }
index a9976c17214e54c052a71a10f663d8977bff194e..381a1674c3fd0379d02045e117312806b94c775d 100644 (file)
@@ -74,7 +74,7 @@ private:
        ///
        void runtime();
        ///
-       void init(int * argc, char * argv[]);
+       void init(int * argc, char * argv[], bool);
        ///
        void queryUserLyXDir();
        ///
index e586c8b94aefbec490f27c7f1b07319af555ed2a..e793b80ea23f441071c642938eea558b0e376af1 100644 (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 {
index 9b71b5f7f206460c95b904468f97296e3cee565f..6fb564ed0cf77a5ae66ee533fd2bda59ee040dc5 100644 (file)
@@ -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();
 }
index fffbdccf464ac651101ab511f4135713e4234283..11d680324d972bff68252d08e357d0c68e7d6da8 100644 (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;
        ///