2002-09-05 14:10:50 +00:00
|
|
|
/**
|
|
|
|
* \file XFormsView.C
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2002-09-05 14:10:50 +00:00
|
|
|
* \author unknown
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-05 14:10:50 +00:00
|
|
|
*/
|
2001-07-03 15:19:04 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "XFormsView.h"
|
2002-12-16 11:38:21 +00:00
|
|
|
|
2003-07-25 21:34:45 +00:00
|
|
|
#include "XFormsMenubar.h"
|
2003-07-25 18:10:34 +00:00
|
|
|
#include "XFormsToolbar.h"
|
2003-09-05 13:15:43 +00:00
|
|
|
#include "XMiniBuffer.h"
|
|
|
|
|
|
|
|
#include "BufferView.h"
|
2001-07-03 15:19:04 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "lyxfunc.h"
|
2003-09-05 13:15:43 +00:00
|
|
|
#include "MenuBackend.h"
|
|
|
|
|
|
|
|
#include "frontends/Dialogs.h"
|
|
|
|
|
|
|
|
#include "support/filetools.h" // OnlyFilename()
|
2001-07-03 15:19:04 +00:00
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
#include <boost/bind.hpp>
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
using lyx::support::LibFileSearch;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2002-06-10 07:57:39 +00:00
|
|
|
using std::abs;
|
2001-07-03 15:19:04 +00:00
|
|
|
using std::endl;
|
|
|
|
|
2003-09-05 13:15:43 +00:00
|
|
|
|
2001-07-03 15:19:04 +00:00
|
|
|
//extern void AutoSave(BufferView *);
|
|
|
|
extern void QuitLyX();
|
|
|
|
|
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)
|
2002-09-30 20:00:42 +00:00
|
|
|
: LyXView(),
|
|
|
|
icon_pixmap_(0), icon_mask_(0)
|
2001-07-03 15:19:04 +00:00
|
|
|
{
|
2002-08-12 14:28:43 +00:00
|
|
|
create_form_form_main(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
|
|
|
|
2002-07-22 20:57:58 +00:00
|
|
|
view_state_con = view_state_changed.connect(boost::bind(&XFormsView::show_view_state, this));
|
|
|
|
focus_con = focus_command_buffer.connect(boost::bind(&XMiniBuffer::focus, minibuffer_.get()));
|
|
|
|
|
2001-07-03 15:19:04 +00:00
|
|
|
// Make sure the buttons are disabled if needed.
|
|
|
|
updateToolbar();
|
2002-08-15 17:48:53 +00:00
|
|
|
redraw_con = 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()
|
|
|
|
{
|
2002-09-30 20:00:42 +00:00
|
|
|
if (icon_pixmap_)
|
|
|
|
XFreePixmap(fl_get_display(), icon_pixmap_);
|
|
|
|
|
2002-07-19 20:56:31 +00:00
|
|
|
minibuffer_->freeze();
|
2002-07-04 17:45:35 +00:00
|
|
|
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-07-19 20:56:31 +00:00
|
|
|
minibuffer_->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
|
|
|
|
2002-07-18 20:15:29 +00:00
|
|
|
show_view_state();
|
2001-07-03 15:19:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-12 14:28:43 +00:00
|
|
|
void XFormsView::create_form_form_main(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
|
|
|
|
2003-07-25 21:34:45 +00:00
|
|
|
menubar_.reset(new XFormsMenubar(this, menubackend));
|
2001-07-03 15:19:04 +00:00
|
|
|
|
2003-07-25 18:10:34 +00:00
|
|
|
toolbar_.reset(new XFormsToolbar(this, air, 30 + air + bw));
|
|
|
|
toolbar_->init();
|
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));
|
2001-07-03 15:19:04 +00:00
|
|
|
|
2003-04-02 09:23:24 +00:00
|
|
|
minibuffer_.reset(new XMiniBuffer(*controlcommand_,
|
2002-07-19 20:56:31 +00:00
|
|
|
air, height - (25 + air), width - (2 * air), 25));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
|
|
// assign an icon to main form
|
2002-09-30 20:00:42 +00:00
|
|
|
string const iconname = LibFileSearch("images", "lyx", "xpm");
|
2001-07-03 15:19:04 +00:00
|
|
|
if (!iconname.empty()) {
|
|
|
|
unsigned int w, h;
|
2002-09-30 20:00:42 +00:00
|
|
|
icon_pixmap_ = fl_read_pixmapfile(fl_root,
|
2001-07-03 15:19:04 +00:00
|
|
|
iconname.c_str(),
|
|
|
|
&w,
|
|
|
|
&h,
|
2002-09-30 20:00:42 +00:00
|
|
|
&icon_mask_,
|
2001-07-03 15:19:04 +00:00
|
|
|
0,
|
|
|
|
0,
|
2002-09-30 20:00:42 +00:00
|
|
|
0);
|
|
|
|
fl_set_form_icon(getForm(), icon_pixmap_, icon_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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-19 20:56:31 +00:00
|
|
|
void XFormsView::message(string const & str)
|
|
|
|
{
|
|
|
|
minibuffer_->message(str);
|
|
|
|
}
|
|
|
|
|
2002-07-22 20:57:58 +00:00
|
|
|
|
2003-04-07 16:57:38 +00:00
|
|
|
void XFormsView::clearMessage()
|
|
|
|
{
|
|
|
|
message(getLyXFunc().view_status_message());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-18 20:15:29 +00:00
|
|
|
void XFormsView::show_view_state()
|
2002-07-17 04:13:41 +00:00
|
|
|
{
|
2002-08-13 14:40:38 +00:00
|
|
|
message(getLyXFunc().view_status_message());
|
2002-07-17 04:13:41 +00:00
|
|
|
}
|
2002-07-22 20:57:58 +00:00
|
|
|
|
|
|
|
|
2003-02-14 14:49:51 +00:00
|
|
|
void XFormsView::busy(bool yes) const
|
2001-07-03 15:19:04 +00:00
|
|
|
{
|
2003-02-14 14:49:51 +00:00
|
|
|
if (yes) {
|
|
|
|
view()->hideCursor();
|
2001-07-03 15:19:04 +00:00
|
|
|
|
2003-02-14 14:49:51 +00:00
|
|
|
static Cursor cursor;
|
|
|
|
static bool cursor_undefined = true;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-02-14 14:49:51 +00:00
|
|
|
if (cursor_undefined) {
|
|
|
|
cursor = XCreateFontCursor(fl_get_display(), XC_watch);
|
|
|
|
XFlush(fl_get_display());
|
|
|
|
cursor_undefined = false;
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-02-14 14:49:51 +00:00
|
|
|
/// set the cursor to the watch for all forms and the canvas
|
|
|
|
XDefineCursor(fl_get_display(), getForm()->window, cursor);
|
2001-07-03 15:19:04 +00:00
|
|
|
|
2003-02-14 14:49:51 +00:00
|
|
|
XFlush(fl_get_display());
|
2001-07-03 15:19:04 +00:00
|
|
|
|
2003-02-14 14:49:51 +00:00
|
|
|
/// we only need to deactivate to prevent resetting the cursor
|
|
|
|
/// to I-beam over the workarea
|
|
|
|
fl_deactivate_all_forms();
|
|
|
|
} else {
|
|
|
|
/// reset the cursor from the watch for all forms and the canvas
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-02-14 14:49:51 +00:00
|
|
|
XUndefineCursor(fl_get_display(), getForm()->window);
|
2001-07-03 15:19:04 +00:00
|
|
|
|
2003-02-14 14:49:51 +00:00
|
|
|
XFlush(fl_get_display());
|
|
|
|
fl_activate_all_forms();
|
|
|
|
}
|
2001-07-03 15:19:04 +00:00
|
|
|
}
|