1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
1999-10-02 16:21:10 +00:00
|
|
|
* ======================================================
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
* LyX, The Document Processor
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
1999-10-02 16:21:10 +00:00
|
|
|
*
|
1999-11-15 12:01:38 +00:00
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "lyx_gui.h"
|
2000-06-12 11:27:15 +00:00
|
|
|
#include FORMS_H_LOCATION
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "tex-strings.h"
|
|
|
|
#include "lyx_main.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "version.h"
|
2002-05-23 12:08:47 +00:00
|
|
|
#include "frontends/LyXView.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "buffer.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "BufferView.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lyxserver.h"
|
|
|
|
#include "lyxrc.h"
|
|
|
|
#include "gettext.h"
|
2000-12-05 17:12:47 +00:00
|
|
|
#if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
|
2002-05-23 15:43:25 +00:00
|
|
|
#include "frontends/xforms/lyxlookup.h"
|
2000-11-02 04:48:34 +00:00
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "bufferlist.h"
|
2000-04-16 22:27:30 +00:00
|
|
|
#include "ColorHandler.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
2000-08-16 15:27:11 +00:00
|
|
|
#include "frontends/GUIRunTime.h"
|
2001-03-05 19:05:57 +00:00
|
|
|
#include "frontends/xforms/xforms_helpers.h" // for XformColor
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "support/os.h"
|
|
|
|
#include "support/lyxlib.h"
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
extern LyXServer * lyxserver;
|
1999-09-27 18:44:28 +00:00
|
|
|
extern bool finished; // flag, that we are quitting the program
|
|
|
|
extern BufferList bufferlist;
|
2000-11-13 10:35:02 +00:00
|
|
|
extern string user_lyxdir;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
FL_CMD_OPT cmdopt[] =
|
|
|
|
{
|
2000-07-04 20:32:37 +00:00
|
|
|
{"-geometry", "*.geometry", XrmoptionSepArg, "690x510"}
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
int width = 690;
|
|
|
|
int height = 510;
|
|
|
|
int xpos = -1;
|
|
|
|
int ypos = -1;
|
|
|
|
char geometry[40];
|
|
|
|
|
|
|
|
} // namespace anon
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
FL_resource res[] =
|
|
|
|
{
|
2000-07-05 20:16:38 +00:00
|
|
|
{"geometry", "geometryClass", FL_STRING, geometry, "", 40}
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-09-09 22:02:19 +00:00
|
|
|
extern "C" {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-09-09 22:02:19 +00:00
|
|
|
static
|
2000-08-16 23:48:48 +00:00
|
|
|
int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2002-03-18 22:10:58 +00:00
|
|
|
if (xeev->error_code == BadWindow) {
|
|
|
|
// We don't abort on BadWindow
|
|
|
|
return 0;
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-10-19 15:13:49 +00:00
|
|
|
// emergency cleanup
|
|
|
|
LyX::emergencyCleanup();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// Get the reason for the crash.
|
|
|
|
char etxt[513];
|
|
|
|
XGetErrorText(display, xeev->error_code, etxt, 512);
|
2002-02-26 10:50:48 +00:00
|
|
|
lyxerr << etxt << " id: " << xeev->resourceid << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
// By doing an abort we get a nice backtrace. (hopefully)
|
2000-01-17 21:01:30 +00:00
|
|
|
lyx::abort();
|
2002-05-23 12:08:47 +00:00
|
|
|
return 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-09-09 22:02:19 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI)
|
2000-08-24 23:10:28 +00:00
|
|
|
: _owner(owner), lyxViews(0)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
gui = GUI;
|
|
|
|
if (!gui)
|
|
|
|
return;
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
//
|
1999-09-27 18:44:28 +00:00
|
|
|
setDefaults();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
static const int num_res = sizeof(res)/sizeof(FL_resource);
|
|
|
|
fl_initialize(argc, argv, "LyX", cmdopt, num_res);
|
2001-01-24 11:08:32 +00:00
|
|
|
// It appears that, in xforms >=0.89.5, fl_initialize()
|
|
|
|
// calls setlocale() and ruins our LC_NUMERIC setting.
|
2001-03-08 14:22:43 +00:00
|
|
|
locale_init();
|
2002-03-21 17:27:08 +00:00
|
|
|
fl_get_app_resources(res, num_res);
|
2000-01-21 19:26:42 +00:00
|
|
|
|
2000-08-24 23:10:28 +00:00
|
|
|
static const int geometryBitmask =
|
2002-02-16 15:59:55 +00:00
|
|
|
XParseGeometry(geometry,
|
2000-08-24 23:10:28 +00:00
|
|
|
&xpos,
|
|
|
|
&ypos,
|
|
|
|
reinterpret_cast<unsigned int *>(&width),
|
|
|
|
reinterpret_cast<unsigned int *>(&height));
|
2000-07-04 20:32:37 +00:00
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
Display * display = fl_get_display();
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!display) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "LyX: unable to access X display, exiting" << endl;
|
2001-05-17 15:11:01 +00:00
|
|
|
os::warn("Unable to access X display, exiting");
|
1999-09-27 18:44:28 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC);
|
|
|
|
// X Error handler install goes here
|
|
|
|
XSetErrorHandler(LyX_XErrHandler);
|
2000-07-05 20:16:38 +00:00
|
|
|
|
|
|
|
// A width less than 590 pops up an awkward main window
|
2000-07-17 13:41:20 +00:00
|
|
|
// The minimal values of width/height (590/400) are defined in
|
2002-03-21 17:27:08 +00:00
|
|
|
// src/lyx.C
|
|
|
|
if (width < 590) width = 590;
|
2000-07-17 13:41:20 +00:00
|
|
|
if (height < 400) height = 400;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-07-05 20:16:38 +00:00
|
|
|
// If width is not set by geometry, check it against monitor width
|
2000-11-04 10:00:12 +00:00
|
|
|
if (!(geometryBitmask & 4)) {
|
2001-12-28 13:26:54 +00:00
|
|
|
Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
|
1999-12-13 00:05:34 +00:00
|
|
|
if (WidthOfScreen(scr) - 8 < width)
|
|
|
|
width = WidthOfScreen(scr) - 8;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-07-05 20:16:38 +00:00
|
|
|
// If height is not set by geometry, check it against monitor height
|
2000-11-04 10:00:12 +00:00
|
|
|
if (!(geometryBitmask & 8)) {
|
2001-12-28 13:26:54 +00:00
|
|
|
Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen);
|
2000-07-05 20:16:38 +00:00
|
|
|
if (HeightOfScreen(scr) - 24 < height)
|
|
|
|
height = HeightOfScreen(scr) - 24;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recalculate xpos if it's negative
|
|
|
|
if (geometryBitmask & 16)
|
2001-12-28 13:26:54 +00:00
|
|
|
xpos += WidthOfScreen(ScreenOfDisplay(fl_get_display(),
|
|
|
|
fl_screen)) - width;
|
2000-07-05 20:16:38 +00:00
|
|
|
|
|
|
|
// Recalculate ypos if it's negative
|
|
|
|
if (geometryBitmask & 32)
|
2001-12-28 13:26:54 +00:00
|
|
|
ypos += HeightOfScreen(ScreenOfDisplay(fl_get_display(),
|
|
|
|
fl_screen)) - height;
|
2000-07-05 20:16:38 +00:00
|
|
|
|
2000-04-16 22:27:30 +00:00
|
|
|
// Initialize the LyXColorHandler
|
2001-03-07 16:18:05 +00:00
|
|
|
lyxColorHandler.reset(new LyXColorHandler);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// A destructor is always necessary (asierra-970604)
|
1999-12-21 06:10:21 +00:00
|
|
|
LyXGUI::~LyXGUI()
|
|
|
|
{
|
2002-03-21 17:27:08 +00:00
|
|
|
// Lyxserver was created in this class so should be destroyed
|
|
|
|
// here. asierra-970604
|
2000-02-04 09:38:32 +00:00
|
|
|
delete lyxserver;
|
|
|
|
lyxserver = 0;
|
2000-04-17 14:00:18 +00:00
|
|
|
delete lyxViews;
|
2000-12-05 17:12:47 +00:00
|
|
|
#if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
|
1999-09-27 18:44:28 +00:00
|
|
|
CloseLyXLookup();
|
2000-11-02 04:48:34 +00:00
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXGUI::setDefaults()
|
|
|
|
{
|
2000-09-18 19:41:52 +00:00
|
|
|
GUIRunTime::setDefaults();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This is called after we have parsed lyxrc
|
|
|
|
void LyXGUI::init()
|
|
|
|
{
|
|
|
|
if (!gui)
|
|
|
|
return;
|
|
|
|
|
|
|
|
create_forms();
|
2000-03-10 13:22:20 +00:00
|
|
|
|
2002-01-10 15:14:22 +00:00
|
|
|
if (lyxrc.popup_font_encoding.empty())
|
|
|
|
lyxrc.popup_font_encoding = lyxrc.font_norm;
|
1999-09-27 18:44:28 +00:00
|
|
|
// Set the font name for popups and menus
|
2002-03-21 17:27:08 +00:00
|
|
|
string boldfontname = lyxrc.popup_bold_font
|
|
|
|
+ "-*-*-*-?-*-*-*-*-"
|
|
|
|
+ lyxrc.popup_font_encoding;
|
1999-09-27 18:44:28 +00:00
|
|
|
// "?" means "scale that font"
|
2002-03-21 17:27:08 +00:00
|
|
|
string fontname = lyxrc.popup_normal_font
|
|
|
|
+ "-*-*-*-?-*-*-*-*-"
|
|
|
|
+ lyxrc.popup_font_encoding;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
2000-10-16 13:27:56 +00:00
|
|
|
int bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str());
|
|
|
|
int normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str());
|
2002-03-21 17:27:08 +00:00
|
|
|
if (bold < 0)
|
|
|
|
lyxerr << "Could not set menu font to "
|
2000-10-16 13:27:56 +00:00
|
|
|
<< boldfontname << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
if (normal < 0)
|
|
|
|
lyxerr << "Could not set popup font to "
|
2000-10-16 13:27:56 +00:00
|
|
|
<< fontname << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-05-22 16:56:05 +00:00
|
|
|
if (bold < 0 && normal < 0) {
|
|
|
|
lyxerr << "Using 'helvetica' font for menus" << endl;
|
2000-10-16 13:27:56 +00:00
|
|
|
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());
|
|
|
|
|
2000-05-22 16:56:05 +00:00
|
|
|
if (bold < 0 && normal < 0) {
|
|
|
|
lyxerr << "Could not find helvetica font. Using 'fixed'." << endl;
|
2000-10-16 13:27:56 +00:00
|
|
|
fl_set_font_name(FL_NORMAL_STYLE, "fixed");
|
|
|
|
normal = bold = 0;
|
2000-05-22 16:56:05 +00:00
|
|
|
}
|
|
|
|
}
|
2000-10-16 13:27:56 +00:00
|
|
|
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());
|
2000-05-22 16:56:05 +00:00
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
// put here (after fl_initialize) to avoid segfault. Cannot be done
|
1999-09-27 18:44:28 +00:00
|
|
|
// in setDefaults() (Matthias 140496)
|
2002-03-21 17:27:08 +00:00
|
|
|
// Moved from ::LyXGUI to ::init to allow popup font customization
|
1999-09-27 18:44:28 +00:00
|
|
|
// (petr 120997).
|
2002-03-21 17:27:08 +00:00
|
|
|
fl_setpup_fontstyle(FL_NORMAL_STYLE);
|
|
|
|
fl_setpup_fontsize(FL_NORMAL_SIZE);
|
|
|
|
fl_setpup_color(FL_MCOL, FL_BLACK);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
|
2002-03-21 17:27:08 +00:00
|
|
|
#if FL_REVISION < 89
|
2002-01-20 23:17:17 +00:00
|
|
|
fl_set_oneliner_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
|
|
|
|
#else
|
|
|
|
fl_set_tooltip_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE);
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2002-03-07 15:06:57 +00:00
|
|
|
// all lyxrc settings has to be done here as lyxrc has not yet
|
|
|
|
// been read when the GUI is created (Jug)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// Update parameters.
|
|
|
|
lyxViews->redraw();
|
|
|
|
|
|
|
|
// Initialize the views.
|
|
|
|
lyxViews->init();
|
|
|
|
|
2002-03-19 11:17:46 +00:00
|
|
|
// this should be moved ...
|
2000-03-12 10:35:05 +00:00
|
|
|
lyxserver = new LyXServer(lyxViews->getLyXFunc(), lyxrc.lyxpipes);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXGUI::create_forms()
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
lyxerr[Debug::INIT] << "Initializing LyXView..." << endl;
|
2001-07-03 15:19:04 +00:00
|
|
|
lyxViews = GUIRunTime::createMainView(width, height);
|
1999-11-09 23:52:04 +00:00
|
|
|
lyxerr[Debug::INIT] << "Initializing LyXView...done" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// From here down should be done by somebody else. (Lgb)
|
|
|
|
|
2000-11-13 10:35:02 +00:00
|
|
|
// This is probably as good a time as any to map the xform colours,
|
|
|
|
// should a mapping exist.
|
2001-12-28 13:26:54 +00:00
|
|
|
string const filename = AddName(user_lyxdir, "preferences.xform");
|
2002-02-16 15:59:55 +00:00
|
|
|
XformsColor::read(filename);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Show the main & title form
|
|
|
|
int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE;
|
|
|
|
// Did we get a valid position?
|
2000-08-16 23:48:48 +00:00
|
|
|
if (xpos >= 0 && ypos >= 0) {
|
1999-09-27 18:44:28 +00:00
|
|
|
lyxViews->setPosition(xpos, ypos);
|
2001-02-12 14:09:09 +00:00
|
|
|
main_placement = FL_PLACE_POSITION;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-02-12 14:09:09 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
lyxViews->show(main_placement, FL_FULLBORDER, "LyX");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXGUI::runTime()
|
|
|
|
{
|
2000-08-16 23:48:48 +00:00
|
|
|
if (!gui) return;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-07-03 15:19:04 +00:00
|
|
|
GUIRunTime::runTime();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
void LyXGUI::regBuf(Buffer * b)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-22 16:19:48 +00:00
|
|
|
lyxViews->view()->buffer(b);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2000-04-28 11:18:04 +00:00
|
|
|
|
2000-08-16 23:48:48 +00:00
|
|
|
|
2000-04-28 11:18:04 +00:00
|
|
|
LyXView * LyXGUI::getLyXView() const
|
|
|
|
{
|
|
|
|
return lyxViews;
|
|
|
|
}
|