2001-07-03 15:19:04 +00:00
|
|
|
/* This file is part of
|
2002-03-21 17:27:08 +00:00
|
|
|
* ======================================================
|
|
|
|
*
|
2001-07-03 15:19:04 +00:00
|
|
|
* LyX, The Document Processor
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2001-07-03 15:19:04 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-2001 The LyX Team.
|
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "XFormsView.h"
|
2002-06-13 13:43:51 +00:00
|
|
|
#include FORMS_H_LOCATION
|
2002-06-02 18:58:19 +00:00
|
|
|
#if FL_VERSION < 1 && (FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5))
|
2002-05-23 15:43:25 +00:00
|
|
|
#include "frontends/xforms/lyxlookup.h"
|
2001-07-03 15:19:04 +00:00
|
|
|
#endif
|
2002-06-24 22:24:57 +00:00
|
|
|
#include "frontends/MiniBuffer.h"
|
|
|
|
#include "frontends/xforms/XMiniBuffer.h"
|
2001-07-03 15:19:04 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "intl.h"
|
|
|
|
#include "lyxrc.h"
|
|
|
|
#include "support/filetools.h" // OnlyFilename()
|
|
|
|
#include "frontends/Toolbar.h"
|
|
|
|
#include "frontends/Menubar.h"
|
2002-02-18 19:13:48 +00:00
|
|
|
#include "frontends/Timeout.h"
|
2002-06-12 11:34:13 +00:00
|
|
|
#include "frontends/Dialogs.h"
|
2001-07-03 15:19:04 +00:00
|
|
|
#include "MenuBackend.h"
|
|
|
|
#include "ToolbarDefaults.h"
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
2002-06-10 07:57:39 +00:00
|
|
|
using std::abs;
|
2001-07-03 15:19:04 +00:00
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
//extern void AutoSave(BufferView *);
|
|
|
|
extern void QuitLyX();
|
|
|
|
|
|
|
|
// This is very temporary
|
|
|
|
BufferView * current_view;
|
|
|
|
|
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
|
|
|
|
int C_XFormsView_atCloseMainFormCB(FL_FORM * form, void * p)
|
|
|
|
{
|
|
|
|
return XFormsView::atCloseMainFormCB(form, p);
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-09-09 22:02:19 +00:00
|
|
|
}
|
2001-07-03 15:19:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
XFormsView::XFormsView(int width, int height)
|
|
|
|
: LyXView()
|
|
|
|
{
|
2002-07-02 19:23:10 +00:00
|
|
|
create_form_form_main(*getDialogs(), width, height);
|
2002-06-12 02:54:19 +00:00
|
|
|
fl_set_form_atclose(getForm(), C_XFormsView_atCloseMainFormCB, 0);
|
2001-07-03 15:19:04 +00:00
|
|
|
|
|
|
|
// Connect the minibuffer signals
|
2002-06-24 22:24:57 +00:00
|
|
|
minibuffer_->inputReady.connect(boost::bind(&LyXFunc::miniDispatch, getLyXFunc(), _1));
|
2002-06-12 02:54:19 +00:00
|
|
|
minibuffer_->timeout.connect(boost::bind(&LyXFunc::initMiniBuffer, getLyXFunc()));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-07-17 04:13:41 +00:00
|
|
|
view_state_changed.connect(boost::bind(&XFormsView::update_view_state, this));
|
|
|
|
|
2001-07-03 15:19:04 +00:00
|
|
|
// Make sure the buttons are disabled if needed.
|
|
|
|
updateToolbar();
|
2002-07-02 19:23:10 +00:00
|
|
|
getDialogs()->redrawGUI.connect(boost::bind(&XFormsView::redraw, this));
|
2001-07-03 15:19:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-04 17:45:35 +00:00
|
|
|
XFormsView::~XFormsView()
|
|
|
|
{
|
|
|
|
fl_hide_form(form_);
|
|
|
|
fl_free_form(form_);
|
|
|
|
}
|
2001-07-03 15:19:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// Redraw the main form.
|
2002-06-24 22:24:57 +00:00
|
|
|
void XFormsView::redraw()
|
|
|
|
{
|
2001-07-03 15:19:04 +00:00
|
|
|
lyxerr[Debug::INFO] << "XFormsView::redraw()" << endl;
|
2002-06-12 02:54:19 +00:00
|
|
|
fl_redraw_form(getForm());
|
2002-06-24 22:24:57 +00:00
|
|
|
// This is dangerous, but we know it is safe
|
|
|
|
XMiniBuffer * m = static_cast<XMiniBuffer *>(getMiniBuffer());
|
|
|
|
m->redraw();
|
2001-07-03 15:19:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FL_FORM * XFormsView::getForm() const
|
|
|
|
{
|
2002-07-04 17:45:35 +00:00
|
|
|
return form_;
|
2001-07-03 15:19:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Callback for close main form from window manager
|
|
|
|
int XFormsView::atCloseMainFormCB(FL_FORM *, void *)
|
|
|
|
{
|
|
|
|
QuitLyX();
|
|
|
|
return FL_IGNORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-12 09:47:10 +00:00
|
|
|
void XFormsView::show(int x, int y, string const & title)
|
2001-07-03 15:19:04 +00:00
|
|
|
{
|
2002-06-12 09:47:10 +00:00
|
|
|
FL_FORM * form = getForm();
|
2002-06-24 22:24:57 +00:00
|
|
|
|
2002-06-12 09:47:10 +00:00
|
|
|
fl_set_form_minsize(form, form->w, form->h);
|
2002-06-24 22:24:57 +00:00
|
|
|
|
2002-06-12 09:47:10 +00:00
|
|
|
int placement = FL_PLACE_CENTER | FL_FREE_SIZE;
|
2002-06-24 22:24:57 +00:00
|
|
|
|
2002-06-12 09:47:10 +00:00
|
|
|
// Did we get a valid geometry position ?
|
|
|
|
if (x >= 0 && y >= 0) {
|
|
|
|
fl_set_form_position(form, x, y);
|
|
|
|
placement = FL_PLACE_POSITION;
|
|
|
|
}
|
2002-06-24 22:24:57 +00:00
|
|
|
|
2002-06-12 09:47:10 +00:00
|
|
|
fl_show_form(form, placement, FL_FULLBORDER, title.c_str());
|
2002-06-24 22:24:57 +00:00
|
|
|
|
2001-07-03 15:19:04 +00:00
|
|
|
getLyXFunc()->initMiniBuffer();
|
2002-06-02 18:58:19 +00:00
|
|
|
#if FL_VERSION < 1 && (FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5))
|
2002-06-12 09:47:10 +00:00
|
|
|
InitLyXLookup(fl_get_display(), form_->window);
|
2002-06-24 22:24:57 +00:00
|
|
|
#endif
|
2001-07-03 15:19:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-02 19:23:10 +00:00
|
|
|
void XFormsView::create_form_form_main(Dialogs & dia, int width, int height)
|
2001-07-03 15:19:04 +00:00
|
|
|
/* to make this work as it should, .lyxrc should have been
|
|
|
|
* read first; OR maybe this one should be made dynamic.
|
2002-03-21 17:27:08 +00:00
|
|
|
* Hmmmm. Lgb.
|
2001-07-03 15:19:04 +00:00
|
|
|
* We will probably not have lyxrc before the main form is
|
2002-03-21 17:27:08 +00:00
|
|
|
* initialized, because error messages from lyxrc parsing
|
|
|
|
* are presented (and rightly so) in GUI popups. Asger.
|
2001-07-03 15:19:04 +00:00
|
|
|
*/
|
|
|
|
{
|
|
|
|
// the main form
|
2002-07-04 17:45:35 +00:00
|
|
|
form_ = fl_bgn_form(FL_NO_BOX, width, height);
|
2002-06-12 02:54:19 +00:00
|
|
|
getForm()->u_vdata = this;
|
2001-07-03 15:19:04 +00:00
|
|
|
FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
|
|
|
|
fl_set_object_color(obj, FL_MCOL, FL_MCOL);
|
|
|
|
|
|
|
|
// Parameters for the appearance of the main form
|
|
|
|
int const air = 2;
|
|
|
|
int const bw = abs(fl_get_border_width());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-06-12 02:54:19 +00:00
|
|
|
menubar_.reset(new Menubar(this, menubackend));
|
2001-07-03 15:19:04 +00:00
|
|
|
|
2002-07-02 19:23:10 +00:00
|
|
|
toolbar_.reset(new Toolbar(this, dia,
|
|
|
|
air, 30 + air + bw, toolbardefaults));
|
2002-06-12 02:54:19 +00:00
|
|
|
toolbar_->set(true);
|
2001-07-03 15:19:04 +00:00
|
|
|
|
|
|
|
int const ywork = 60 + 2 * air + bw;
|
|
|
|
int const workheight = height - ywork - (25 + 2 * air);
|
|
|
|
|
2002-06-12 02:54:19 +00:00
|
|
|
bufferview_.reset(new BufferView(this, air, ywork,
|
|
|
|
width - 3 * air, workheight));
|
|
|
|
::current_view = bufferview_.get();
|
2001-07-03 15:19:04 +00:00
|
|
|
|
2002-06-24 22:24:57 +00:00
|
|
|
minibuffer_.reset(new XMiniBuffer(this, air, height - (25 + air),
|
2002-06-12 02:54:19 +00:00
|
|
|
width - (2 * air), 25));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-06-12 02:54:19 +00:00
|
|
|
// FIXME: why do this in xforms/ ?
|
2002-06-12 11:34:13 +00:00
|
|
|
autosave_timeout_->timeout.connect(boost::bind(&XFormsView::autoSave, this));
|
2001-07-03 15:19:04 +00:00
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
// assign an icon to main form
|
2001-07-03 15:19:04 +00:00
|
|
|
string iconname = LibFileSearch("images", "lyx", "xpm");
|
|
|
|
if (!iconname.empty()) {
|
|
|
|
unsigned int w, h;
|
|
|
|
Pixmap lyx_p, lyx_mask;
|
|
|
|
lyx_p = fl_read_pixmapfile(fl_root,
|
|
|
|
iconname.c_str(),
|
|
|
|
&w,
|
|
|
|
&h,
|
|
|
|
&lyx_mask,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0); // this leaks
|
2002-06-12 02:54:19 +00:00
|
|
|
fl_set_form_icon(getForm(), lyx_p, lyx_mask);
|
2001-07-03 15:19:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// set min size
|
2002-06-12 02:54:19 +00:00
|
|
|
fl_set_form_minsize(getForm(), 50, 50);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-07-03 15:19:04 +00:00
|
|
|
fl_end_form();
|
2001-11-05 17:07:23 +00:00
|
|
|
|
2002-06-24 22:24:57 +00:00
|
|
|
// This is dangerous, but we know it is safe in this situation
|
|
|
|
static_cast<XMiniBuffer *>(minibuffer_.get())->dd_init();
|
2001-07-03 15:19:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-03 03:14:40 +00:00
|
|
|
void XFormsView::setWindowTitle(string const & title, string const & icon_title)
|
2001-07-03 15:19:04 +00:00
|
|
|
{
|
2002-06-12 02:54:19 +00:00
|
|
|
fl_set_form_title(getForm(), title.c_str());
|
2002-01-03 03:14:40 +00:00
|
|
|
fl_winicontitle(form_->window, icon_title.c_str());
|
2001-07-03 15:19:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-17 04:13:41 +00:00
|
|
|
void XFormsView::update_view_state()
|
|
|
|
{
|
|
|
|
minibuffer_->message(currentState(view()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-03 15:19:04 +00:00
|
|
|
// 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
|
|
|
|
// run "prohibitInput" on all LyXViews which will run prohibitInput on all
|
|
|
|
// BufferViews. Or is it perhaps just the (input in) BufferViews in the
|
|
|
|
// current LyxView that should be prohibited (Lgb) (This applies to
|
|
|
|
// "allowInput" as well.)
|
|
|
|
void XFormsView::prohibitInput() const
|
|
|
|
{
|
|
|
|
view()->hideCursor();
|
|
|
|
|
|
|
|
static Cursor cursor;
|
|
|
|
static bool cursor_undefined = true;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
if (cursor_undefined) {
|
2001-07-03 15:19:04 +00:00
|
|
|
cursor = XCreateFontCursor(fl_get_display(), XC_watch);
|
|
|
|
XFlush(fl_get_display());
|
|
|
|
cursor_undefined = false;
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
|
|
/* set the cursor to the watch for all forms and the canvas */
|
2001-07-03 15:19:04 +00:00
|
|
|
XDefineCursor(fl_get_display(), getForm()->window, cursor);
|
|
|
|
|
|
|
|
XFlush(fl_get_display());
|
|
|
|
fl_deactivate_all_forms();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XFormsView::allowInput() const
|
|
|
|
{
|
|
|
|
/* reset the cursor from the watch for all forms and the canvas */
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-07-03 15:19:04 +00:00
|
|
|
XUndefineCursor(fl_get_display(), getForm()->window);
|
|
|
|
|
|
|
|
XFlush(fl_get_display());
|
|
|
|
fl_activate_all_forms();
|
|
|
|
}
|