/**
- * \file lyx_gui.C
- * Copyright 2002 the LyX Team
- * Read the file COPYING
+ * \file xforms/lyx_gui.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * \author unknown
- * \author John Levon <moz@compsoc.man.ac.uk>
+ * \author Lars Gullik Bjønnes
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
-
+
#include "lyx_gui.h"
-
-#include "support/lyxlib.h"
-#include "support/os.h"
-#include "support/filetools.h"
-
+#include "ColorHandler.h"
+#include "xfont_loader.h"
+#include "xforms_helpers.h"
+#include "xformsImage.h"
+#include "XFormsView.h"
+
+#include "bufferlist.h"
+#include "BufferView.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 "lyxrc.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 "graphics/LoaderQueue.h"
+
+#include "support/lyxlib.h"
+#include "support/os.h"
+#include "support/filetools.h"
+#include "support/path_defines.h"
+
+#include "lyx_forms.h"
#include <boost/bind.hpp>
-
-using std::vector;
-using std::hex;
+
+#include "support/std_sstream.h"
+#include <iomanip>
+#include <fcntl.h>
+
+using namespace lyx::support;
+
+#ifndef CXX_GLOBAL_CSTD
+using std::exit;
+#endif
+
+using std::dec;
using std::endl;
-
-extern bool finished;
+using std::hex;
+using std::setbase;
+using std::setfill;
+using std::setw;
+using std::vector;
+
+
extern BufferList bufferlist;
-
+
// FIXME: wrong place !
LyXServer * lyxserver;
-
+
namespace {
-
+
+/// quit lyx
+bool finished = false;
+
+/// estimate DPI from X server
+float getDPI()
+{
+ Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
+ return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
+ (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2;
+}
+
+
/// set default GUI configuration
void setDefaults()
{
| FL_PDBorderWidth, &cntl);
}
-
+
extern "C" {
int LyX_XErrHandler(Display * display, XErrorEvent * xeev) {
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();
+ lyx::support::abort();
return 0;
}
-
+
}
-
+
/// read in geometry specification
char geometry[40];
-
+
} // namespace anon
-
-void lyx_gui::parse_init(int & argc, char * argv[])
+
+namespace lyx_gui {
+
+bool use_gui = true;
+
+
+void parse_init(int & argc, char * argv[])
{
setDefaults();
-
+
FL_CMD_OPT cmdopt[] = {
{"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
};
};
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);
+ ::exit(1);
}
-
+
fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
-
+
XSetErrorHandler(LyX_XErrHandler);
lyxColorHandler.reset(new LyXColorHandler());
+
+ using namespace lyx::graphics;
+
+ // connect the image loader based on the xforms library
+ Image::newImage = boost::bind(&xformsImage::newImage);
+ Image::loadableFormats = boost::bind(&xformsImage::loadableFormats);
+
+ // must do this /before/ lyxrc gets read
+ lyxrc.dpi = getDPI();
+
+ LoaderQueue::setPriority(10,100);
}
-
-void lyx_gui::parse_lyxrc()
+
+void parse_lyxrc()
{
- // FIXME !!!!
- lyxrc.dpi = 95;
-
- XformsColor::read(AddName(user_lyxdir, "preferences.xform"));
+ XformsColor::read(AddName(user_lyxdir(), "preferences.xform"));
if (lyxrc.popup_font_encoding.empty())
lyxrc.popup_font_encoding = lyxrc.font_norm;
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)
+
+void start(string const & batch, vector<string> const & files)
{
// initial geometry
int xpos = -1;
int ypos = -1;
unsigned int width = 690;
unsigned int height = 510;
-
- static const int geometryBitmask =
+
+ int const geometryBitmask =
XParseGeometry(geometry,
- &xpos, &ypos, &width, &height);
+ &xpos, &ypos, &width, &height);
// if width is not set by geometry, check it against monitor width
- if (!(geometryBitmask & 4)) {
+ if (!(geometryBitmask & WidthValue)) {
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)) {
+ if (!(geometryBitmask & HeightValue)) {
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;
if (ypos == -1)
ypos = (HeightOfScreen(s) - height) / 2;
- lyxerr[Debug::GUI] << "Creating view: " << width << "x" << height
- << "+" << xpos << "+" << ypos << endl;
-
+ 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);
-
+ 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);
- }
+ for (; cit != end; ++cit)
+ view.view()->loadLyXFile(*cit, true);
// handle the batch commands the user asked for
- if (!batch.empty()) {
- view.getLyXFunc()->verboseDispatch(batch, false);
- }
+ if (!batch.empty())
+ view.getLyXFunc().dispatch(batch);
- // enter the event loop
+ // 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;
+ lyxerr[Debug::GUI]
+ << "Received unhandled X11 event" << endl
+ << "Type: " << ev.xany.type
+ << " Target: 0x" << hex << ev.xany.window
+ << dec << endl;
}
}
- // FIXME
+ // FIXME: breaks emergencyCleanup
delete lyxserver;
}
-
-
-// Called by the graphics cache to connect the appropriate frontend
-// image loading routines to the LyX kernel.
-void lyx_gui::init_graphics()
+
+
+void exit()
{
- using namespace grfx;
+ finished = true;
+}
-#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
+
+void sync_events()
+{
+ // FIXME
+}
+
+
+FuncStatus getStatus(FuncRequest const & /*ev*/)
+{
+ // Nothing interesting to do here
+ return FuncStatus();
+}
+
+string const hexname(LColor::color col)
+{
+ unsigned int r, g, b;
+ bool const success = getRGBColor(col, r, g, b);
+ if (!success) {
+ lyxerr << "X can't find color for \"" << lcolor.getLyXName(col)
+ << '"' << endl;
+ return string();
+ }
+
+ ostringstream os;
+
+ os << setbase(16) << setfill('0')
+ << setw(2) << r
+ << setw(2) << g
+ << setw(2) << b;
+
+ return STRCONV(os.str());
+}
+
+
+void update_color(LColor::color col)
+{
+ lyxColorHandler->updateColor(col);
+}
+
+
+void update_fonts()
+{
+ fontloader.update();
}
+
+
+bool font_available(LyXFont const & font)
+{
+ return fontloader.available(font);
+}
+
+namespace {
+
+extern "C"
+void C_read_callback(int, void * data)
+{
+ LyXComm * comm = static_cast<LyXComm *>(data);
+ comm->read_ready();
+}
+
+}
+
+void set_read_callback(int fd, LyXComm * comm)
+{
+ fl_add_io_callback(fd, FL_READ, C_read_callback, comm);
+}
+
+
+void remove_read_callback(int fd)
+{
+ fl_remove_io_callback(fd, FL_READ, C_read_callback);
+}
+
+
+string const roman_font_name()
+{
+ return "times";
+}
+
+
+string const sans_font_name()
+{
+ return "helvetica";
+}
+
+
+string const typewriter_font_name()
+{
+ return "courier";
+}
+
+}; // namespace lyx_gui