+2002-06-12 John Levon <moz@compsoc.man.ac.uk>
+
+ * Makefile.am:
+ * lyx_gui.h:
+ * lyx_gui.C: move to frontends/
+
+ * main.C:
+ * lyx_main.h:
+ * lyx_main.C: changes from above
+
2002-06-12 John Levon <moz@compsoc.man.ac.uk>
* intl.C:
lengthcommon.h \
lyx_cb.C \
lyx_cb.h \
- lyx_gui.C \
- lyx_gui.h \
lyx_main.C \
lyx_main.h \
lyx_sty.C \
vspace.C \
vspace.h
-lyx_main.o: lyx_main.C lyx_main.h config.h version.h lyx_gui.h \
+lyx_main.o: lyx_main.C lyx_main.h config.h version.h \
lyxrc.h support/path.h support/filetools.h \
bufferlist.h debug.h support/FileInfo.h lastfiles.h intl.h \
lyxserver.h layout.h gettext.h kbmap.h commandtags.h language.h
$(CXXCOMPILE) -DLYX_DIR=\"$(pkgdatadir)\" \
-DTOP_SRCDIR=\"$(top_srcdir)\" -c $(top_srcdir)/src/lyx_main.C
-main.o: main.C config.h lyx_main.h gettext.h LString.h support/filetools.h \
- support/os.h frontends/GUIRunTime.h
+main.o: main.C config.h lyx_main.h gettext.h LString.h support/filetools.h support/os.h
$(CXXCOMPILE) -DLOCALEDIR=\"$(localedir)\" -c $(top_srcdir)/src/main.C
dist-hook:
* font_metrics.h: remove trailing semi-colon after the brace closing
the namespace.
+2002-06-12 John Levon <moz@compsoc.man.ac.uk>
+
+ * GUIRunTime.h: remove in favour of ...
+
+ * Makefile.am:
+ * lyx_gui.h: ... namespace for GUI start up
+
+ * LyXView.h: remove init(),show(),setPosition()
+
2002-06-12 John Levon <moz@compsoc.man.ac.uk>
* Menubar.C:
+++ /dev/null
-// -*- C++ -*-
-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 2000-2001 The LyX Team.
- *
- * ====================================================== */
-
-#ifndef GUIRUNTIME_H
-#define GUIRUNTIME_H
-
-#ifdef __GNUG__
-#pragma interface
-#endif
-
-#include <X11/Xlib.h>
-class LyXView;
-
-/** The LyX GUI independent guiruntime class
- The GUI interface is implemented in the corresponding
- frontends GUIRunTime.C file.
-*/
-class GUIRunTime {
-public:
- /// initialise the toolkit
- static
- int initApplication(int & argc, char * argv[]);
- /// process pending events
- static
- void processEvents();
- /// enter the permanent event loop until "finished" becomes false
- static
- void runTime();
- /// This is run first in the LyXGUI constructor.
- static
- void setDefaults();
- ///
- static
- LyXView * createMainView(int w, int h);
- /** Called bu the graphics cache to connect the approriate frontend
- * image loading routines to the LyX kernel.
- */
- static void initialiseGraphics();
-
-/* the following entries are X11 specific and should eventually go away */
- /// The display on which LyX is running
- static
- Display * x11Display();
- /// The screen on which LyX is running
- static
- int x11Screen();
- /// The current colormap
- static
- Colormap x11Colormap();
- /// The current visual depth
- static
- int x11VisualDepth();
- /// the server's DPI estimate
- static
- float getScreenDPI();
-};
-#endif
LyXView();
///
virtual ~LyXView();
- ///
- virtual void init() = 0;
- ///
- virtual void setPosition(int, int) = 0;
- ///
- virtual void show(int, int, string const &) = 0;
/// Redraw the main form.
virtual void redraw() = 0;
Dialogs.h \
DialogBase.h \
FileDialog.h \
- GUIRunTime.h \
Liason.C \
Liason.h \
Menubar.C \
font_loader.h \
font_metrics.h \
key_state.h \
+ lyx_gui.h \
mouse_state.h \
screen.C \
screen.h
--- /dev/null
+/**
+ * \file lyx_gui.h
+ * Copyright 2002 the LyX Team
+ * Read the file COPYING
+ *
+ * \author John Levon <moz@compsoc.man.ac.uk>
+ */
+
+#ifndef LYX_GUI_H
+#define LYX_GUI_H
+
+#include <config.h>
+
+#include "LString.h"
+
+#include <vector>
+
+/// GUI interaction
+namespace lyx_gui {
+
+ /// parse command line and do basic initialisation
+ void parse_init(int & argc, char * argv[]);
+
+ /**
+ * set up GUI parameters. At this point lyxrc may
+ * be used.
+ */
+ void parse_lyxrc();
+
+ /**
+ * Start the main event loop, after executing the given
+ * batch commands, and loading the given documents
+ */
+ void start(string const & batch, std::vector<std::string> files);
+
+ /// initialise graphics
+ void init_graphics();
+};
+
+#endif // LYX_GUI_H
+2002-06-12 John Levon <moz@compsoc.man.ac.uk>
+
+ * GUIRunTime.C: remove in favour of ...
+
+ * Makefile.am:
+ * lyx_gui.C: ... GUI startup namespace
+
+ * XFormsView.h:
+ * XFormsView.C: change show() prototype
+
+ * XPainter.C:
+ * xfont_loader.C: don't use GUIRunTime any more
+
2002-06-12 John Levon <moz@compsoc.man.ac.uk>
* ColorHandler.C:
+++ /dev/null
-/**
- * \file xforms/GUIRunTime.C
- * Copyright 2000-2001 The LyX Team.
- * See the file COPYING.
- *
- * \author unknown
- */
-
-#include <config.h>
-
-#include FORMS_H_LOCATION
-
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-#include "GUIRunTime.h"
-#include "XFormsView.h"
-#include "debug.h"
-
-#ifdef USE_XFORMS_IMAGE_LOADER
-#include "xformsGImage.h"
-#else
-#include "graphics/GraphicsImageXPM.h"
-#endif
-
-#include <boost/bind.hpp>
-
-using std::endl;
-using std::hex;
-
-
-extern bool finished;
-
-namespace {
-
-int const xforms_include_version = FL_INCLUDE_VERSION;
-
-} // namespace anon
-
-
-int GUIRunTime::initApplication(int &, char * [])
-{
- // Check the XForms version in the forms.h header against
- // the one in the libforms. If they don't match quit the
- // execution of LyX. Better with a clean fast exit than
- // a strange segfault later.
- // I realize that this check have to be moved when we
- // support several toolkits, but IMO all the toolkits
- // should try to have the same kind of check. This could
- // be done by having a CheckHeaderAndLib function in
- // all the toolkit implementations, this function is
- // responsible for notifing the user.
- // if (!CheckHeaderAndLib()) {
- // // header vs. lib version failed
- // return 1;
- // }
- int xforms_lib_version = fl_library_version(0, 0);
- if (xforms_include_version != xforms_lib_version) {
- lyxerr << "You are either running LyX with wrong "
- "version of a dynamic XForms library\n"
- "or you have build LyX with conflicting header "
- "and library (different\n"
- "versions of XForms). Sorry but there is no point "
- "in continuing executing LyX!" << endl;
- return 1;
- }
- return 0;
-}
-
-
-void GUIRunTime::processEvents()
-{
- if (fl_do_forms() == FL_EVENT) {
- XEvent ev;
- fl_XNextEvent(&ev);
- lyxerr << "Received unhandled X11 event" << endl;
- lyxerr << "Type: 0x" << hex << ev.xany.type <<
- " Target: 0x" << hex << ev.xany.window << endl;
- }
-}
-
-
-void GUIRunTime::runTime()
-{
- while (!finished) {
- if (fl_check_forms() == FL_EVENT) {
- XEvent ev;
- fl_XNextEvent(&ev);
- lyxerr << "Received unhandled X11 event" << endl;
- lyxerr << "Type: 0x" << hex << ev.xany.type <<
- " Target: 0x" << hex << ev.xany.window << endl;
- }
- }
-}
-
-
-void GUIRunTime::setDefaults()
-{
- FL_IOPT cntl;
- cntl.buttonFontSize = FL_NORMAL_SIZE;
- cntl.browserFontSize = FL_NORMAL_SIZE;
- cntl.labelFontSize = FL_NORMAL_SIZE;
- cntl.choiceFontSize = FL_NORMAL_SIZE;
- cntl.inputFontSize = FL_NORMAL_SIZE;
- cntl.menuFontSize = FL_NORMAL_SIZE;
- cntl.borderWidth = -1;
- cntl.vclass = FL_DefaultVisual;
- fl_set_defaults(FL_PDVisual
- | FL_PDButtonFontSize
- | FL_PDBrowserFontSize
- | FL_PDLabelFontSize
- | FL_PDChoiceFontSize
- | FL_PDInputFontSize
- | FL_PDMenuFontSize
- | FL_PDBorderWidth, &cntl);
-}
-
-
-LyXView * GUIRunTime::createMainView(int w, int h)
-{
- return new XFormsView(w, h);
-}
-
-
-
-// Called by the graphics cache to connect the appropriate frontend
-// image loading routines to the LyX kernel.
-void GUIRunTime::initialiseGraphics()
-{
- using namespace grfx;
-
-#ifdef USE_XFORMS_IMAGE_LOADER
- // connect the image loader based on the xforms library
- GImage::newImage.connect(boost::bind(&xformsGImage::newImage));
- GImage::loadableFormats.connect(boost::bind(&xformsGImage::loadableFormats));
-#else
- // connect the image loader based on the XPM library
- GImage::newImage.connect(boost::bind(&GImageXPM::newImage));
- GImage::loadableFormats.connect(boost::bind(&GImageXPM::loadableFormats));
-#endif
-}
-
-
-Display * GUIRunTime::x11Display()
-{
- return fl_get_display();
-}
-
-
-int GUIRunTime::x11Screen()
-{
- return fl_screen;
-}
-
-
-Colormap GUIRunTime::x11Colormap()
-{
- return fl_state[fl_get_vclass()].colormap;
-}
-
-
-int GUIRunTime::x11VisualDepth()
-{
- return fl_get_visual_depth();
-}
-
-float GUIRunTime::getScreenDPI()
-{
- Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
- return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
- (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;
-}
form_url.h \
FormVCLog.C \
FormVCLog.h \
- GUIRunTime.C \
input_validators.C \
input_validators.h \
+ lyx_gui.C \
lyxlookup.C \
lyxlookup.h \
MathsSymbols.C \
$(XFORMSGIMAGE) xformsBC.C \
xformsBC.h
-# These still have to be added. Sooner or later. ARRae-20000411
-# GUI_defaults.C \
-# GUI_initialize.C \
-# GUI_postlyxrc.C \
-# GUI_runtime.C \
-# GUI_applymenu.C
-
libxforms.la: $(libxforms_la_OBJECTS) $(libxforms_la_DEPENDENCIES)
# for convenience only
}
-void XFormsView::setPosition(int x, int y)
+void XFormsView::show(int x, int y, string const & title)
{
- fl_set_form_position(getForm(), x, y);
-}
-
-
-void XFormsView::show(int place, int border, string const & title)
-{
- fl_set_form_minsize(getForm(), getForm()->w, getForm()->h);
- fl_show_form(getForm(), place, border, title.c_str());
+ FL_FORM * form = getForm();
+
+ fl_set_form_minsize(form, form->w, form->h);
+
+ int placement = FL_PLACE_CENTER | FL_FREE_SIZE;
+
+ // Did we get a valid geometry position ?
+ if (x >= 0 && y >= 0) {
+ fl_set_form_position(form, x, y);
+ placement = FL_PLACE_POSITION;
+ }
+
+ fl_show_form(form, placement, FL_FULLBORDER, title.c_str());
+
getLyXFunc()->initMiniBuffer();
#if FL_VERSION < 1 && (FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5))
- InitLyXLookup(fl_get_display(), getForm()->window);
-#endif
+ InitLyXLookup(fl_get_display(), form_->window);
+#endif
}
XFormsView(int w, int h);
~XFormsView();
- /// Where to place the form.
- virtual void setPosition(int, int);
- /// Show the main form.
- virtual void show(int, int, string const & t = string("LyX"));
+
+ /**
+ * show - display the top-level window
+ * @param xpos requested x position (or 0)
+ * @param xpos requested y position (or 0)
+ * @param title window title
+ */
+ void show(int xpos, int ypos, string const & t = string("LyX"));
+
/// init (should probably be removed later) (Lgb)
virtual void init();
/// get the xforms main form
#include "encoding.h"
#include "language.h"
-#include "frontends/GUIRunTime.h"
#include "graphics/GraphicsImage.h"
#include "support/LAssert.h"
inline
Display * display()
{
- return GUIRunTime::x11Display();
+ return fl_get_display();
}
}
--- /dev/null
+/**
+ * \file lyx_gui.C
+ * Copyright 2002 the LyX Team
+ * Read the file COPYING
+ *
+ * \author unknown
+ * \author John Levon <moz@compsoc.man.ac.uk>
+ */
+
+#include <config.h>
+
+#include "lyx_gui.h"
+
+#include "support/lyxlib.h"
+#include "support/os.h"
+#include "support/filetools.h"
+
+#include "debug.h"
+#include "gettext.h"
+
+#include "lyx_main.h"
+#include "lyxrc.h"
+
+// FIXME: move this stuff out again
+#include "bufferlist.h"
+#include "lyxfunc.h"
+#include "lyxserver.h"
+#include "BufferView.h"
+#include "XFormsView.h"
+
+#include FORMS_H_LOCATION
+#include "ColorHandler.h"
+#include "xforms_helpers.h"
+#ifdef USE_XFORMS_IMAGE_LOADER
+#include "xformsGImage.h"
+#else
+#include "graphics/GraphicsImageXPM.h"
+#endif
+
+
+#include <fcntl.h>
+
+#include <boost/bind.hpp>
+
+using std::vector;
+using std::hex;
+using std::endl;
+
+extern bool finished;
+extern BufferList bufferlist;
+
+// FIXME: wrong place !
+LyXServer * lyxserver;
+
+namespace {
+
+/// set default GUI configuration
+void setDefaults()
+{
+ FL_IOPT cntl;
+ cntl.buttonFontSize = FL_NORMAL_SIZE;
+ cntl.browserFontSize = FL_NORMAL_SIZE;
+ cntl.labelFontSize = FL_NORMAL_SIZE;
+ cntl.choiceFontSize = FL_NORMAL_SIZE;
+ cntl.inputFontSize = FL_NORMAL_SIZE;
+ cntl.menuFontSize = FL_NORMAL_SIZE;
+ cntl.borderWidth = -1;
+ cntl.vclass = FL_DefaultVisual;
+ fl_set_defaults(FL_PDVisual
+ | FL_PDButtonFontSize
+ | FL_PDBrowserFontSize
+ | FL_PDLabelFontSize
+ | FL_PDChoiceFontSize
+ | FL_PDInputFontSize
+ | FL_PDMenuFontSize
+ | FL_PDBorderWidth, &cntl);
+}
+
+
+extern "C" {
+
+int LyX_XErrHandler(Display * display, XErrorEvent * xeev) {
+ // We don't abort on BadWindow
+ if (xeev->error_code == BadWindow) {
+ lyxerr << "BadWindow received !" << endl;
+ lyxerr << "If you're using xforms 1.0 or greater, "
+ << " please report this to lyx-devel@lists.lyx.org" << endl;
+ return 0;
+ }
+
+ // emergency cleanup
+ LyX::emergencyCleanup();
+
+ // Get the reason for the crash.
+ char etxt[513];
+ XGetErrorText(display, xeev->error_code, etxt, 512);
+ lyxerr << etxt << " id: " << xeev->resourceid << endl;
+ // By doing an abort we get a nice backtrace. (hopefully)
+ lyx::abort();
+ return 0;
+}
+
+}
+
+/// read in geometry specification
+char geometry[40];
+
+} // namespace anon
+
+
+void lyx_gui::parse_init(int & argc, char * argv[])
+{
+ setDefaults();
+
+ FL_CMD_OPT cmdopt[] = {
+ {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
+ };
+
+ FL_resource res[] = {
+ {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
+ };
+
+ const int num_res = sizeof(res)/sizeof(FL_resource);
+
+ fl_initialize(&argc, argv, "LyX", cmdopt, num_res);
+
+ // It appears that, in xforms >=0.89.5, fl_initialize()
+ // calls setlocale() and ruins our LC_NUMERIC setting.
+ locale_init();
+
+ fl_get_app_resources(res, num_res);
+
+ Display * display = fl_get_display();
+
+ if (!display) {
+ lyxerr << "LyX: unable to access X display, exiting" << endl;
+ os::warn("Unable to access X display, exiting");
+ exit(1);
+ }
+
+ fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
+
+ XSetErrorHandler(LyX_XErrHandler);
+
+ lyxColorHandler.reset(new LyXColorHandler());
+}
+
+
+void lyx_gui::parse_lyxrc()
+{
+ // FIXME !!!!
+ lyxrc.dpi = 95;
+
+ XformsColor::read(AddName(user_lyxdir, "preferences.xform"));
+
+ if (lyxrc.popup_font_encoding.empty())
+ lyxrc.popup_font_encoding = lyxrc.font_norm;
+ // Set the font name for popups and menus
+ string boldfontname = lyxrc.popup_bold_font
+ + "-*-*-*-?-*-*-*-*-"
+ + lyxrc.popup_font_encoding;
+ // "?" means "scale that font"
+ string fontname = lyxrc.popup_normal_font
+ + "-*-*-*-?-*-*-*-*-"
+ + lyxrc.popup_font_encoding;
+
+ int bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
+ int normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
+ if (bold < 0)
+ lyxerr << "Could not set menu font to "
+ << boldfontname << endl;
+
+ if (normal < 0)
+ lyxerr << "Could not set popup font to "
+ << fontname << endl;
+
+ if (bold < 0 && normal < 0) {
+ lyxerr << "Using 'helvetica' font for menus" << endl;
+ boldfontname = "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1";
+ fontname = "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1";
+ bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
+ normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
+
+ if (bold < 0 && normal < 0) {
+ lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
+ fl_set_font_name(FL_NORMAL_STYLE, "fixed");
+ normal = bold = 0;
+ }
+ }
+ if (bold < 0)
+ fl_set_font_name(FL_BOLD_STYLE, fontname.c_str());
+ else if (normal < 0)
+ fl_set_font_name(FL_NORMAL_STYLE, boldfontname.c_str());
+
+ fl_setpup_fontstyle(FL_NORMAL_STYLE);
+ fl_setpup_fontsize(FL_NORMAL_SIZE);
+ fl_setpup_color(FL_MCOL, FL_BLACK);
+ fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
+#if FL_REVISION < 89
+ fl_set_oneliner_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
+#else
+ fl_set_tooltip_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
+#endif
+}
+
+
+void lyx_gui::start(string const & batch, vector<string> files)
+{
+ // initial geometry
+ int xpos = -1;
+ int ypos = -1;
+ unsigned int width = 690;
+ unsigned int height = 510;
+
+ static const int geometryBitmask =
+ XParseGeometry(geometry,
+ &xpos, &ypos, &width, &height);
+
+ // if width is not set by geometry, check it against monitor width
+ if (!(geometryBitmask & 4)) {
+ Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
+ if (WidthOfScreen(scr) - 8 < int(width))
+ width = WidthOfScreen(scr) - 8;
+ }
+
+ // if height is not set by geometry, check it against monitor height
+ if (!(geometryBitmask & 8)) {
+ Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
+ if (HeightOfScreen(scr) - 24 < int(height))
+ height = HeightOfScreen(scr) - 24;
+ }
+
+ Screen * s = ScreenOfDisplay(fl_get_display(), fl_screen);
+
+ // recalculate xpos if it's not set
+ if (xpos == -1)
+ xpos = (WidthOfScreen(s) - width) / 2;
+
+ // recalculate ypos if it's not set
+ if (ypos == -1)
+ ypos = (HeightOfScreen(s) - height) / 2;
+
+ lyxerr[Debug::GUI] << "Creating view: " << width << "x" << height
+ << "+" << xpos << "+" << ypos << endl;
+
+ XFormsView view(width, height);
+ view.show(xpos, ypos, "LyX");
+ view.init();
+
+ Buffer * last = 0;
+
+ // FIXME: some code below needs moving
+
+ lyxserver = new LyXServer(view.getLyXFunc(), lyxrc.lyxpipes);
+
+ vector<string>::const_iterator cit = files.begin();
+ vector<string>::const_iterator end = files.end();
+ for (; cit != end; ++cit) {
+ Buffer * b = bufferlist.loadLyXFile(*cit);
+ if (b) {
+ last = b;
+ }
+ }
+
+ // switch to the last buffer successfully loaded
+ if (last) {
+ view.view()->buffer(last);
+ }
+
+ // handle the batch commands the user asked for
+ if (!batch.empty()) {
+ view.getLyXFunc()->verboseDispatch(batch, false);
+ }
+
+ // enter the event loop
+ while (!finished) {
+ if (fl_check_forms() == FL_EVENT) {
+ XEvent ev;
+ fl_XNextEvent(&ev);
+ lyxerr << "Received unhandled X11 event" << endl;
+ lyxerr << "Type: 0x" << hex << ev.xany.type <<
+ " Target: 0x" << hex << ev.xany.window << endl;
+ }
+ }
+
+ // FIXME
+ delete lyxserver;
+}
+
+
+// Called by the graphics cache to connect the appropriate frontend
+// image loading routines to the LyX kernel.
+void lyx_gui::init_graphics()
+{
+ using namespace grfx;
+
+#ifdef USE_XFORMS_IMAGE_LOADER
+ // connect the image loader based on the xforms library
+ GImage::newImage.connect(boost::bind(&xformsGImage::newImage));
+ GImage::loadableFormats.connect(boost::bind(&xformsGImage::loadableFormats));
+#else
+ // connect the image loader based on the XPM library
+ GImage::newImage.connect(boost::bind(&GImageXPM::newImage));
+ GImage::loadableFormats.connect(boost::bind(&GImageXPM::loadableFormats));
+#endif
+}
#include "lyxrc.h" // lyxrc.font_*
#include "BufferView.h"
#include "frontends/LyXView.h"
-#include "frontends/GUIRunTime.h"
+
+#include FORMS_H_LOCATION
using std::endl;
}
for (int i4 = 0; i4 < 10; ++i4) {
if (fontstruct[i1][i2][i3][i4]) {
- XFreeFont(GUIRunTime::x11Display(), fontstruct[i1][i2][i3][i4]);
+ XFreeFont(fl_get_display(), fontstruct[i1][i2][i3][i4]);
fontstruct[i1][i2][i3][i4] = 0;
}
}
current_view->owner()->messagePush(_("Loading font into X-Server..."));
- fs = XLoadQueryFont(GUIRunTime::x11Display(), font.c_str());
+ fs = XLoadQueryFont(fl_get_display(), font.c_str());
if (fs == 0) {
if (font == "fixed") {
lyxerr << "We're doomed. Can't get 'fixed' font." << endl;
} else {
lyxerr << "Could not get font. Using 'fixed'." << endl;
- fs = XLoadQueryFont(GUIRunTime::x11Display(), "fixed");
+ fs = XLoadQueryFont(fl_get_display(), "fixed");
}
} else if (lyxerr.debugging(Debug::FONT)) {
// Tell user the font matching
+2002-06-12 John Levon <moz@compsoc.man.ac.uk>
+
+ * GraphicsCache.C: use lyx_gui namespace
+
+ * GraphicsImageXPM.C: back down to using xforms
+ directly again
+
2002-06-07 Angus Leeming <leeming@lyx.org>
Fixes needed to compile with Compaq cxx 6.5.
#include "GraphicsImage.h"
#include "GraphicsParams.h"
#include "insets/insetgraphics.h"
-#include "frontends/GUIRunTime.h"
-
+#include "frontends/lyx_gui.h"
namespace grfx {
static bool start = true;
if (start) {
start = false;
- GUIRunTime::initialiseGraphics();
+ lyx_gui::init_graphics();
}
// Now return the cache
#include "GraphicsParams.h"
#include "frontends/xforms/ColorHandler.h"
#include "debug.h"
-#include "frontends/GUIRunTime.h" // x11Display, x11Screen
#include "support/filetools.h" // IsFileReadable
#include "support/lstrings.h"
#include "Lsstream.h"
#include <cmath> // cos, sin
#include <cstdlib> // malloc, free
+#include FORMS_H_LOCATION
+
#ifndef CXX_GLOBAL_CSTD
using std::cos;
using std::sin;
GImageXPM::~GImageXPM()
{
if (pixmap_)
- XFreePixmap(GUIRunTime::x11Display(), pixmap_);
+ XFreePixmap(fl_get_display(), pixmap_);
}
return false;
}
- Display * display = GUIRunTime::x11Display();
+ Display * display = fl_get_display();
if (pixmap_ && pixmap_status_ == PIXMAP_SUCCESS)
XFreePixmap(display, pixmap_);
//(BE 2000-08-05)
// This might be a dirty thing, but I dont know any other solution.
- Screen * screen = ScreenOfDisplay(display, GUIRunTime::x11Screen());
+ Screen * screen = ScreenOfDisplay(display, fl_screen);
Pixmap pixmap;
Pixmap mask;
// Already filled.
return;
- Display * display = GUIRunTime::x11Display();
- Colormap cmap = GUIRunTime::x11Colormap();
+ Display * display = fl_get_display();
+ Colormap cmap = fl_colormap;
XColor xcol;
XColor ccol;
if (XLookupColor(display, cmap, c_color, &xcol, &ccol) == 0)
+++ /dev/null
-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 1995 Matthias Ettrich
- * Copyright 1995-2001 The LyX Team.
- *
- * ====================================================== */
-
-#include <config.h>
-
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-#include "lyx_gui.h"
-#include FORMS_H_LOCATION
-#include "tex-strings.h"
-#include "lyx_main.h"
-#include "debug.h"
-#include "version.h"
-#include "frontends/LyXView.h"
-#include "buffer.h"
-#include "BufferView.h"
-#include "lyxserver.h"
-#include "lyxrc.h"
-#include "gettext.h"
-#if FL_VERSION < 1 && (FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5))
-#include "frontends/xforms/lyxlookup.h"
-#endif
-#include "bufferlist.h"
-#include "frontends/xforms/ColorHandler.h"
-
-#include "frontends/GUIRunTime.h"
-#include "frontends/xforms/xforms_helpers.h" // for XformColor
-
-#include "support/filetools.h"
-#include "support/os.h"
-#include "support/lyxlib.h"
-
-#include <cstdlib>
-#include <fcntl.h>
-
-#ifndef CXX_GLOBAL_CSTD
-using std::exit;
-#endif
-
-using std::endl;
-
-extern LyXServer * lyxserver;
-extern bool finished; // flag, that we are quitting the program
-extern BufferList bufferlist;
-extern string user_lyxdir;
-
-FL_CMD_OPT cmdopt[] =
-{
- {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
-};
-
-namespace {
-
-int width = 690;
-int height = 510;
-int xpos = -1;
-int ypos = -1;
-char geometry[40];
-
-} // namespace anon
-
-
-FL_resource res[] =
-{
- {"geometry", "geometryClass", FL_STRING, geometry, "", 40}
-};
-
-
-extern "C" {
-
-static
-int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
-{
- // We don't abort on BadWindow
- if (xeev->error_code == BadWindow) {
- lyxerr << "BadWindow received !" << endl;
- lyxerr << "If you're using xforms 1.0 or greater, "
- << " please report this to lyx-devel@lists.lyx.org" << endl;
- return 0;
- }
-
- // emergency cleanup
- LyX::emergencyCleanup();
-
- // Get the reason for the crash.
- char etxt[513];
- XGetErrorText(display, xeev->error_code, etxt, 512);
- lyxerr << etxt << " id: " << xeev->resourceid << endl;
- // By doing an abort we get a nice backtrace. (hopefully)
- lyx::abort();
- return 0;
-}
-
-}
-
-
-LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
- : _owner(owner), lyxViews(0)
-{
- gui = GUI;
- if (!gui)
- return;
-
- //
- setDefaults();
-
- static const int num_res = sizeof(res)/sizeof(FL_resource);
- fl_initialize(argc, argv, "LyX", cmdopt, num_res);
- // It appears that, in xforms >=0.89.5, fl_initialize()
- // calls setlocale() and ruins our LC_NUMERIC setting.
- locale_init();
- fl_get_app_resources(res, num_res);
-
- static const int geometryBitmask =
- XParseGeometry(geometry,
- &xpos,
- &ypos,
- reinterpret_cast<unsigned int *>(&width),
- reinterpret_cast<unsigned int *>(&height));
-
- Display * display = fl_get_display();
- if (!display) {
- lyxerr << "LyX: unable to access X display, exiting" << endl;
- os::warn("Unable to access X display, exiting");
- exit(1);
- }
- fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
- // X Error handler install goes here
- XSetErrorHandler(LyX_XErrHandler);
-
- // A width less than 590 pops up an awkward main window
- // The minimal values of width/height (590/400) are defined in
- // src/lyx.C
- if (width < 590) width = 590;
- if (height < 400) height = 400;
-
- // If width is not set by geometry, check it against monitor width
- if (!(geometryBitmask & 4)) {
- Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
- if (WidthOfScreen(scr) - 8 < width)
- width = WidthOfScreen(scr) - 8;
- }
-
- // If height is not set by geometry, check it against monitor height
- if (!(geometryBitmask & 8)) {
- Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
- if (HeightOfScreen(scr) - 24 < height)
- height = HeightOfScreen(scr) - 24;
- }
-
- // Recalculate xpos if it's negative
- if (geometryBitmask & 16)
- xpos += WidthOfScreen(ScreenOfDisplay(fl_get_display(),
- fl_screen)) - width;
-
- // Recalculate ypos if it's negative
- if (geometryBitmask & 32)
- ypos += HeightOfScreen(ScreenOfDisplay(fl_get_display(),
- fl_screen)) - height;
-
- // Initialize the LyXColorHandler
- lyxColorHandler.reset(new LyXColorHandler);
-}
-
-
-// A destructor is always necessary (asierra-970604)
-LyXGUI::~LyXGUI()
-{
- // Lyxserver was created in this class so should be destroyed
- // here. asierra-970604
- delete lyxserver;
- lyxserver = 0;
- delete lyxViews;
-#if FL_VERSION < 1 && (FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5))
- CloseLyXLookup();
-#endif
-}
-
-
-void LyXGUI::setDefaults()
-{
- GUIRunTime::setDefaults();
-}
-
-
-// This is called after we have parsed lyxrc
-void LyXGUI::init()
-{
- if (!gui)
- return;
-
- create_forms();
-
- if (lyxrc.popup_font_encoding.empty())
- lyxrc.popup_font_encoding = lyxrc.font_norm;
- // Set the font name for popups and menus
- string boldfontname = lyxrc.popup_bold_font
- + "-*-*-*-?-*-*-*-*-"
- + lyxrc.popup_font_encoding;
- // "?" means "scale that font"
- string fontname = lyxrc.popup_normal_font
- + "-*-*-*-?-*-*-*-*-"
- + lyxrc.popup_font_encoding;
-
- int bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
- int normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
- if (bold < 0)
- lyxerr << "Could not set menu font to "
- << boldfontname << endl;
-
- if (normal < 0)
- lyxerr << "Could not set popup font to "
- << fontname << endl;
-
- if (bold < 0 && normal < 0) {
- lyxerr << "Using 'helvetica' font for menus" << endl;
- boldfontname = "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1";
- fontname = "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1";
- bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
- normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
-
- if (bold < 0 && normal < 0) {
- lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
- fl_set_font_name(FL_NORMAL_STYLE, "fixed");
- normal = bold = 0;
- }
- }
- if (bold < 0)
- fl_set_font_name(FL_BOLD_STYLE, fontname.c_str());
- else if (normal < 0)
- fl_set_font_name(FL_NORMAL_STYLE, boldfontname.c_str());
-
- // put here (after fl_initialize) to avoid segfault. Cannot be done
- // in setDefaults() (Matthias 140496)
- // Moved from ::LyXGUI to ::init to allow popup font customization
- // (petr 120997).
- fl_setpup_fontstyle(FL_NORMAL_STYLE);
- fl_setpup_fontsize(FL_NORMAL_SIZE);
- fl_setpup_color(FL_MCOL, FL_BLACK);
- fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
-#if FL_VERSION < 1 && FL_REVISION < 89
- fl_set_oneliner_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
-#else
- fl_set_tooltip_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
-#endif
-
- // all lyxrc settings has to be done here as lyxrc has not yet
- // been read when the GUI is created (Jug)
-
- // Update parameters.
- lyxViews->redraw();
-
- // Initialize the views.
- lyxViews->init();
-
- // this should be moved ...
- lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
-}
-
-
-void LyXGUI::create_forms()
-{
- lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
- lyxViews = GUIRunTime::createMainView(width, height);
- lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
-
- // From here down should be done by somebody else. (Lgb)
-
- // This is probably as good a time as any to map the xform colours,
- // should a mapping exist.
- string const filename = AddName(user_lyxdir, "preferences.xform");
- XformsColor::read(filename);
-
- // Show the main & title form
- int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
- // Did we get a valid position?
- if (xpos >= 0 && ypos >= 0) {
- lyxViews->setPosition(xpos, ypos);
- main_placement = FL_PLACE_POSITION;
- }
-
- lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
-}
-
-
-void LyXGUI::runTime()
-{
- if (!gui) return;
-
- GUIRunTime::runTime();
-}
-
-
-void LyXGUI::regBuf(Buffer * b)
-{
- lyxViews->view()->buffer(b);
-}
-
-
-LyXView * LyXGUI::getLyXView() const
-{
- return lyxViews;
-}
+++ /dev/null
-// -*- C++ -*-
-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 1995 Matthias Ettrich
- * Copyright 1995-2001 The LyX Team.
- *
- * ====================================================== */
-
-#ifndef LYX_GUI_H
-#define LYX_GUI_H
-
-#include <boost/utility.hpp>
-
-#ifdef __GNUG__
-#pragma interface
-#endif
-
-class LyXView;
-class LyX;
-class Buffer;
-
-/**
- This class is going to be the entry point to {\em all} GUI funcionality.
- From this object will all the things going on be initiated. However I
- have not clearly figured out how this class is going to be, suggestions
- are welcome. (Lgb)
-*/
-class LyXGUI : boost::noncopyable {
-public:
- /** The only constructor allowed.
- If gui is false, LyX will operate in non-X mode
- */
- LyXGUI(LyX * owner, int * argc, char * argv[], bool gui);
- ///
- ~LyXGUI();
-
- /**
- This functions starts the ball. For XForms it runs a loop of
- fl_check_forms(). For QT this will probably be .exec().
- */
- void runTime();
- /** This will take care of the initializaton done after the
- main initialization.
- */
- void init();
-
- /// Register the buffer with the first found LyXView in lyxViews
- void regBuf(Buffer *);
-
- /// Access to (first?) LyXView
- LyXView * getLyXView() const;
-
-private:
- ///
- void setDefaults();
- ///
- void create_forms();
-
- /// The LyX that owns this GUI.
- LyX * _owner;
- ///
- LyXView * lyxViews; // or something so that several views
- // on the same time can be allowed.
- /// Do we have a gui?
- bool gui;
-};
-
-#endif
#endif
#include "lyx_main.h"
-#include "lyx_gui.h"
-#include "frontends/LyXView.h"
-#include "lyxfunc.h"
-#include "lyxrc.h"
-#include "buffer.h"
-#include "bufferlist.h"
+
+#include "support/filetools.h"
+#include "support/lyxlib.h"
+#include "support/os.h"
+#include "support/FileInfo.h"
+#include "support/path.h"
#include "debug.h"
-#include "lastfiles.h"
-#include "intl.h"
-#include "lyxserver.h"
-//#include "layout.h"
-#include "lyxtextclasslist.h"
#include "gettext.h"
+#include "lyxlex.h"
+
+#include "bufferlist.h"
+#include "lyxtextclasslist.h"
+#include "lyxserver.h"
#include "kbmap.h"
-#include "MenuBackend.h"
+#include "lyxfunc.h"
#include "ToolbarDefaults.h"
-#include "lyxlex.h"
+#include "MenuBackend.h"
+#include "language.h"
+#include "lastfiles.h"
#include "encoding.h"
#include "converter.h"
-#include "language.h"
#include "frontends/Alert.h"
-#include "frontends/GUIRunTime.h"
-
-#include "support/path.h"
-#include "support/filetools.h"
-#include "support/FileInfo.h"
-#include "support/os.h"
+#include "frontends/lyx_gui.h"
#include <cstdlib>
#include <csignal>
+using std::vector;
using std::endl;
#ifndef CXX_GLOBAL_CSTD
extern void LoadLyXFile(string const &);
extern void QuitLyX();
+extern LyXServer * lyxserver;
+
string system_lyxdir;
string build_lyxdir;
string system_tempdir;
// This is the global bufferlist object
BufferList bufferlist;
-LyXServer * lyxserver = 0;
// this should be static, but I need it in buffer.C
bool finished = false; // flag, that we are quitting the program
boost::scoped_ptr<kb_keymap> toplevel_keymap;
-LyX::LyX(int * argc, char * argv[])
+LyX::LyX(int & argc, char * argv[])
{
// Here we need to parse the command line. At least
// we need to parse for "-dbg" and "-help"
- bool gui = easyParse(argc, argv);
+ bool const want_gui = easyParse(argc, argv);
// Global bindings (this must be done as early as possible.) (Lgb)
toplevel_keymap.reset(new kb_keymap);
defaultKeyBindings(toplevel_keymap.get());
- // Make the GUI object, and let it take care of the
- // command line arguments that concerns it.
- lyxerr[Debug::INIT] << "Initializing LyXGUI..." << endl;
- lyxGUI.reset(new LyXGUI(this, argc, argv, gui));
- lyxerr[Debug::INIT] << "Initializing LyXGUI...done" << endl;
+ if (want_gui) {
+ lyx_gui::parse_init(argc, argv);
+ }
- // Now the GUI and LyX have taken care of their arguments, so
- // the only thing left on the command line should be
- // filenames. Let's check anyway.
- for (int argi = 1; argi < *argc ; ++argi) {
+ // check for any spurious extra arguments
+ // other than documents
+ for (int argi = 1; argi < argc ; ++argi) {
if (argv[argi][0] == '-') {
lyxerr << _("Wrong command line option `")
<< argv[argi]
// Initialization of LyX (reads lyxrc and more)
lyxerr[Debug::INIT] << "Initializing LyX::init..." << endl;
- init(gui);
+ init(want_gui);
lyxerr[Debug::INIT] << "Initializing LyX::init...done" << endl;
- lyxGUI->init();
-
- // Load the files specified in the command line.
- if ((*argc) == 2)
- lyxerr[Debug::INFO] << "Opening document..." << endl;
- else if ((*argc) > 2)
- lyxerr[Debug::INFO] << "Opening documents..." << endl;
+ if (want_gui) {
+ lyx_gui::parse_lyxrc();
+ }
- Buffer * last_loaded = 0;
+ vector<string> files;
- for (int argi = (*argc) - 1; argi >= 1; --argi) {
- Buffer * loadb = bufferlist.loadLyXFile(argv[argi]);
- if (loadb != 0) {
- last_loaded = loadb;
- }
+ for (int argi = argc - 1; argi >= 1; --argi) {
+ files.push_back(argv[argi]);
}
if (first_start) {
- string const splash =
- i18nLibFileSearch("examples", "splash.lyx");
- lyxerr[Debug::INIT] << "Opening splash document "
- << splash << "..." << endl;
- Buffer * loadb = bufferlist.loadLyXFile(splash);
- if (loadb != 0) {
- last_loaded = loadb;
- }
- }
-
- if (last_loaded != 0) {
- lyxerr[Debug::INIT] << "Yes we loaded some files." << endl;
- if (lyxrc.use_gui)
- lyxGUI->regBuf(last_loaded);
+ files.push_back(i18nLibFileSearch("examples", "splash.lyx"));
}
-
+
+#if 0 // FIXME: GUII
// Execute batch commands if available
if (!batch_command.empty()) {
- lyxerr << "About to handle -x '"
+ lyxerr[Debug::INIT] << "About to handle -x '"
<< batch_command << "'" << endl;
// no buffer loaded, create one
bool success = false;
// try to dispatch to last loaded buffer first
- bool dispatched = last_loaded->dispatch(batch_command, &success);
+ bool const dispatched = last_loaded->dispatch(batch_command, &success);
- // if this was successful, return.
- // Maybe we could do something more clever than aborting...
+ // if this was successful, finish
if (dispatched) {
QuitLyX();
exit(!success);
}
-
- // otherwise, let the GUI handle the batch command
- lyxGUI->regBuf(last_loaded);
- lyxGUI->getLyXView()->getLyXFunc()->verboseDispatch(batch_command, false);
-
- // fall through...
}
+#endif
- // Let the ball begin...
- lyxGUI->runTime();
+ lyx_gui::start(batch_command, files);
}
-
+
extern "C" {
static
if (!gui)
lyxrc.use_gui = false;
- // Calculate screen dpi as average of x-DPI and y-DPI:
- if (lyxrc.use_gui) {
- lyxrc.dpi = GUIRunTime::getScreenDPI();
- lyxerr[Debug::INIT] << "DPI setting detected to be "
- << lyxrc.dpi + 0.5 << endl;
- } else {
- lyxrc.dpi = 1; // I hope this is safe
- }
-
//
// Read configuration files
//
lastfiles.reset(new LastFiles(lyxrc.lastfiles,
lyxrc.check_lastfiles,
lyxrc.num_lastfiles));
-
- // start up the lyxserver. (is this a bit early?) (Lgb)
- // 0.12 this will be way to early, we need the GUI to be initialized
- // first, so move it for now.
- // lyxserver = new LyXServer;
}
} // namespace anon
-bool LyX::easyParse(int * argc, char * argv[])
+bool LyX::easyParse(int & argc, char * argv[])
{
bool gui = true;
int removeargs = 0; // used when options are read
- for (int i = 1; i < *argc; ++i) {
+ for (int i = 1; i < argc; ++i) {
string arg = argv[i];
// Check for -dbg int
if (arg == "-dbg") {
- if (i + 1 < *argc) {
+ if (i + 1 < argc) {
setDebuggingLevel(argv[i + 1]);
removeargs = 2;
} else {
}
// Check for "-sysdir"
else if (arg == "-sysdir") {
- if (i + 1 < *argc) {
+ if (i + 1 < argc) {
system_lyxdir = argv[i + 1];
removeargs = 2;
} else {
}
// Check for "-userdir"
else if (arg == "-userdir") {
- if (i + 1 < *argc) {
+ if (i + 1 < argc) {
user_lyxdir = argv[i + 1];
removeargs = 2;
} else {
// Check for "-x": Execute commands
else if (arg == "-x" || arg == "--execute") {
- if (i + 1 < *argc) {
+ if (i + 1 < argc) {
batch_command = string(argv[i + 1]);
removeargs = 2;
}
}
else if (arg == "-e" || arg == "--export") {
- if (i + 1 < *argc) {
+ if (i + 1 < argc) {
string type(argv[i+1]);
removeargs = 2;
batch_command = "buffer-export " + type;
}
}
else if (arg == "-i" || arg == "--import") {
- if (i + 1 < *argc) {
+ if (i + 1 < argc) {
if (!argv[i+2]) {
lyxerr << _("Missing filename for --import") << endl;
exit(1);
if (removeargs > 0) {
// Now, remove used arguments by shifting
// the following ones removeargs places down.
- (*argc) -= removeargs;
- for (int j = i; j < (*argc); ++j)
+ argc -= removeargs;
+ for (int j = i; j < argc; ++j)
argv[j] = argv[j + removeargs];
--i; // After shift, check this number again.
removeargs = 0;
#include <csignal>
-class LyXGUI;
class LyXRC;
class LastFiles;
class Buffer;
class kb_keymap;
-
+
///
extern string user_lyxdir;
///
extern string system_tempdir;
///
extern boost::scoped_ptr<LastFiles> lastfiles;
-
+
class LyX : boost::noncopyable {
public:
- LyX(int * argc, char * argv[]);
+ LyX(int & argc, char * argv[]);
/// in the case of failure
static void emergencyCleanup();
private:
- /// Should be a maximum of 1 LyXGUI.
- boost::scoped_ptr<LyXGUI> lyxGUI;
/// does this user start lyx for the first time?
bool first_start;
///
/// Read the encodings file `name'
void readEncodingsFile(string const & name);
///
- bool easyParse(int * argc, char * argv[]);
+ bool easyParse(int & argc, char * argv[]);
};
#endif
-/* This file is part of
- * ======================================================
+/**
+ * \file main.C
+ * Copyright 2002 the LyX Team
+ * Read the file COPYING
*
- * LyX, The Document Processor
- *
- * Copyright 1995 Matthias Ettrich
- * Copyright 1995-2001 The LyX Team.
- *
- * ====================================================== */
+ * \author unknown
+ */
#include <config.h>
#include "lyx_main.h"
#include "gettext.h"
#include "LString.h"
-#include "lyx_gui.h"
#include "support/filetools.h"
#include "support/os.h"
-#include "frontends/GUIRunTime.h"
-
-
+
int main(int argc, char * argv[])
{
os::init(&argc, &argv);
- int const val = GUIRunTime::initApplication(argc, argv);
- if (val)
- return val;
// lyx_localedir is used by gettext_init() is we have
// i18n support built-in
locale_init();
gettext_init(lyx_localedir);
- LyX lyx(&argc, argv);
- return 0; // SUCCESS
+ LyX lyx(argc, argv);
+ return 0;
}