1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
1999-10-02 16:21:10 +00:00
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* 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>
|
1999-10-02 16:21:10 +00:00
|
|
|
#include <cstdlib>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "lyx_gui.h"
|
2000-06-12 11:27:15 +00:00
|
|
|
#include FORMS_H_LOCATION
|
2000-07-19 10:22:12 +00:00
|
|
|
#include "support/filetools.h"
|
2001-05-17 15:11:01 +00:00
|
|
|
#include "support/os.h"
|
2001-03-28 14:51:25 +00:00
|
|
|
#include "figure_form.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "print_form.h"
|
|
|
|
#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"
|
|
|
|
#include "LyXView.h"
|
|
|
|
#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"
|
|
|
|
#include "lyx_gui_misc.h"
|
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
|
|
|
#include "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-02-12 14:09:09 +00:00
|
|
|
#include "frontends/Dialogs.h"
|
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
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
FD_form_sendto * fd_form_sendto;
|
|
|
|
FD_form_figure * fd_form_figure;
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-08-16 23:48:48 +00:00
|
|
|
extern "C"
|
|
|
|
int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// emergency save
|
1999-11-05 06:02:34 +00:00
|
|
|
if (!bufferlist.empty())
|
1999-09-27 18:44:28 +00:00
|
|
|
bufferlist.emergencyWriteAll();
|
|
|
|
|
|
|
|
// Get the reason for the crash.
|
|
|
|
char etxt[513];
|
|
|
|
XGetErrorText(display, xeev->error_code, etxt, 512);
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << etxt << 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();
|
1999-09-27 18:44:28 +00:00
|
|
|
return 0; // Solaris CC wants us to return something
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2000-09-18 19:41:52 +00:00
|
|
|
//
|
1999-09-27 18:44:28 +00:00
|
|
|
setDefaults();
|
|
|
|
|
|
|
|
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();
|
2001-01-24 11:08:32 +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 =
|
|
|
|
XParseGeometry( geometry,
|
|
|
|
&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
|
|
|
|
// src/lyx.C
|
|
|
|
if (width < 590) width = 590;
|
|
|
|
if (height < 400) height = 400;
|
|
|
|
|
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)) {
|
2000-10-11 21:06:43 +00:00
|
|
|
Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
|
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)) {
|
2000-10-11 21:06:43 +00:00
|
|
|
Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); //DefaultScreen(fl_get_display());
|
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)
|
2000-10-11 21:06:43 +00:00
|
|
|
xpos += WidthOfScreen(ScreenOfDisplay(fl_get_display(), fl_screen)) - width; //DefaultScreen(fl_get_display())) - width;
|
2000-07-05 20:16:38 +00:00
|
|
|
|
|
|
|
// Recalculate ypos if it's negative
|
|
|
|
if (geometryBitmask & 32)
|
2000-10-11 21:06:43 +00:00
|
|
|
ypos += HeightOfScreen(ScreenOfDisplay(fl_get_display(), fl_screen)) - height; //DefaultScreen(fl_get_display())) - 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()
|
|
|
|
{
|
1999-09-27 18:44:28 +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
|
|
|
|
2000-03-12 10:35:05 +00:00
|
|
|
if (lyxrc.font_norm_menu.empty())
|
|
|
|
lyxrc.font_norm_menu = lyxrc.font_norm;
|
1999-09-27 18:44:28 +00:00
|
|
|
// Set the font name for popups and menus
|
2000-10-16 13:27:56 +00:00
|
|
|
string boldfontname = lyxrc.menu_font_name
|
1999-09-27 18:44:28 +00:00
|
|
|
+ "-*-*-*-?-*-*-*-*-"
|
2000-03-12 10:35:05 +00:00
|
|
|
+ lyxrc.font_norm_menu;
|
1999-09-27 18:44:28 +00:00
|
|
|
// "?" means "scale that font"
|
2000-10-16 13:27:56 +00:00
|
|
|
string fontname = lyxrc.popup_font_name
|
1999-09-27 18:44:28 +00:00
|
|
|
+ "-*-*-*-?-*-*-*-*-"
|
2000-03-12 10:35:05 +00:00
|
|
|
+ lyxrc.font_norm_menu;
|
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());
|
2000-05-22 16:56:05 +00:00
|
|
|
if (bold < 0)
|
1999-10-07 18:44:17 +00:00
|
|
|
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
|
|
|
|
2000-05-22 16:56:05 +00:00
|
|
|
if (normal < 0)
|
1999-10-07 18:44:17 +00:00
|
|
|
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
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// 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);
|
1999-11-15 12:01:38 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
// all lyxrc settings has to be done here as lyxrc has not yet
|
|
|
|
// been read when the GUI is created (Jug)
|
|
|
|
|
|
|
|
// the sendto form
|
2000-03-12 10:35:05 +00:00
|
|
|
if (!lyxrc.custom_export_command.empty())
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_input(fd_form_sendto->input_cmd,
|
2000-03-12 10:35:05 +00:00
|
|
|
lyxrc.custom_export_command.c_str());
|
|
|
|
if (lyxrc.custom_export_format == "lyx")
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_button(fd_form_sendto->radio_ftype_lyx, 1);
|
2000-03-12 10:35:05 +00:00
|
|
|
else if (lyxrc.custom_export_format == "tex")
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_button(fd_form_sendto->radio_ftype_latex, 1);
|
2000-03-12 10:35:05 +00:00
|
|
|
else if (lyxrc.custom_export_format == "dvi")
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_button(fd_form_sendto->radio_ftype_dvi, 1);
|
2000-03-12 10:35:05 +00:00
|
|
|
else if (lyxrc.custom_export_format == "ps")
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_button(fd_form_sendto->radio_ftype_ps, 1);
|
2000-03-12 10:35:05 +00:00
|
|
|
else if (lyxrc.custom_export_format == "ascii")
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_button(fd_form_sendto->radio_ftype_ascii, 1);
|
|
|
|
|
|
|
|
// Update parameters.
|
|
|
|
lyxViews->redraw();
|
|
|
|
|
|
|
|
// Initialize the views.
|
|
|
|
lyxViews->init();
|
|
|
|
|
|
|
|
// in 0.12 the initialisation of the LyXServer must be done here
|
|
|
|
// 0.13 it should be moved again...
|
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)
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create forms
|
|
|
|
//
|
|
|
|
|
|
|
|
// the sendto form
|
|
|
|
fd_form_sendto = create_form_form_sendto();
|
1999-11-15 12:01:38 +00:00
|
|
|
fl_set_form_atclose(fd_form_sendto->form_sendto, CancelCloseBoxCB, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// the figure form
|
|
|
|
fd_form_figure = create_form_form_figure();
|
|
|
|
fl_set_form_atclose(fd_form_figure->form_figure,
|
1999-10-02 16:21:10 +00:00
|
|
|
CancelCloseBoxCB, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_button(fd_form_figure->radio_postscript, 1);
|
|
|
|
|
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.
|
|
|
|
{
|
2000-11-15 18:02:45 +00:00
|
|
|
string filename = AddName(user_lyxdir, "preferences.xform");
|
2001-03-05 19:05:57 +00:00
|
|
|
XformsColor::read( filename );
|
2000-11-13 10:35:02 +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");
|
2001-02-12 14:09:09 +00:00
|
|
|
|
|
|
|
if (lyxrc.show_banner)
|
|
|
|
lyxViews->getDialogs()->showSplash();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|