2000-09-22 15:09:51 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 2000-2001 The LyX Team.
|
2000-09-22 15:09:51 +00:00
|
|
|
*
|
|
|
|
* ======================================================
|
2001-03-20 10:14:03 +00:00
|
|
|
*
|
|
|
|
* \author Angus Leeming <a.leeming@ic.ac.uk>
|
2000-09-22 15:09:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Dialogs.h"
|
|
|
|
#include "FormBase.h"
|
2001-03-15 13:37:04 +00:00
|
|
|
#include "xformsBC.h"
|
2002-02-28 14:36:23 +00:00
|
|
|
#include "GUIRunTime.h"
|
2000-11-08 09:39:46 +00:00
|
|
|
#include "support/LAssert.h"
|
2002-02-06 17:15:28 +00:00
|
|
|
#include "Tooltips.h"
|
2002-02-06 12:12:04 +00:00
|
|
|
#include "xforms_helpers.h" // formatted
|
2000-12-04 14:10:44 +00:00
|
|
|
|
2001-09-09 22:02:19 +00:00
|
|
|
extern "C" {
|
2002-02-05 14:59:26 +00:00
|
|
|
|
|
|
|
// Callback function invoked by xforms when the dialog is closed by the
|
|
|
|
// window manager
|
|
|
|
static int C_FormBaseWMHideCB(FL_FORM * form, void *);
|
|
|
|
|
|
|
|
// Use this to diaplay feedback messages or to trigger an input event on paste
|
|
|
|
// with the middle mouse button
|
|
|
|
static int C_FormBasePrehandler(FL_OBJECT * ob, int event,
|
|
|
|
FL_Coord, FL_Coord, int key, void *);
|
|
|
|
|
|
|
|
} // extern "C"
|
2001-08-29 11:01:05 +00:00
|
|
|
|
2000-10-02 00:10:25 +00:00
|
|
|
|
2001-08-28 13:48:40 +00:00
|
|
|
FormBase::FormBase(ControlButtons & c, string const & t, bool allowResize)
|
|
|
|
: ViewBC<xformsBC>(c), minw_(0), minh_(0), allow_resize_(allowResize),
|
2002-02-06 17:15:28 +00:00
|
|
|
title_(t), warning_posted_(false), tooltip_level_(NO_TOOLTIP)
|
2002-02-05 14:59:26 +00:00
|
|
|
|
2002-02-05 17:25:16 +00:00
|
|
|
{
|
2002-02-06 17:15:28 +00:00
|
|
|
tooltip_ = new Tooltips;
|
|
|
|
tooltip_->getTooltip.connect(SigC::slot(this, &FormBase::getTooltip));
|
2002-02-05 17:25:16 +00:00
|
|
|
}
|
2000-10-02 00:10:25 +00:00
|
|
|
|
|
|
|
|
2002-02-06 17:15:28 +00:00
|
|
|
FormBase::~FormBase()
|
|
|
|
{
|
|
|
|
delete tooltip_;
|
|
|
|
}
|
|
|
|
|
2000-11-10 17:29:47 +00:00
|
|
|
void FormBase::redraw()
|
|
|
|
{
|
2000-11-14 02:01:57 +00:00
|
|
|
if (form() && form()->visible)
|
|
|
|
fl_redraw_form(form());
|
2000-11-10 17:29:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-22 15:09:51 +00:00
|
|
|
void FormBase::show()
|
|
|
|
{
|
|
|
|
if (!form()) {
|
|
|
|
build();
|
2001-08-28 13:48:40 +00:00
|
|
|
}
|
2002-01-28 18:42:37 +00:00
|
|
|
|
2001-08-28 13:48:40 +00:00
|
|
|
// use minw_ to flag whether the dialog has ever been shown
|
|
|
|
// (Needed now that build() is/should be called from the controller)
|
|
|
|
if (minw_ == 0) {
|
2001-04-03 14:30:58 +00:00
|
|
|
bc().refresh();
|
2002-01-28 18:42:37 +00:00
|
|
|
|
2001-03-19 15:38:22 +00:00
|
|
|
// work around dumb xforms sizing bug
|
|
|
|
minw_ = form()->w;
|
|
|
|
minh_ = form()->h;
|
|
|
|
|
2001-05-29 14:54:25 +00:00
|
|
|
fl_set_form_atclose(form(), C_FormBaseWMHideCB, 0);
|
2000-09-22 15:09:51 +00:00
|
|
|
}
|
2002-01-28 18:42:37 +00:00
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_freeze_form(form());
|
2000-09-22 15:09:51 +00:00
|
|
|
update(); // make sure its up-to-date
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_unfreeze_form(form());
|
2000-09-22 15:09:51 +00:00
|
|
|
|
|
|
|
if (form()->visible) {
|
|
|
|
fl_raise_form(form());
|
2002-01-28 18:42:37 +00:00
|
|
|
/* This XMapWindow() will hopefully ensure that
|
|
|
|
* iconified dialogs are de-iconified. Mad props
|
|
|
|
* out to those crazy Xlib guys for forgetting a
|
|
|
|
* XDeiconifyWindow(). At least WindowMaker, when
|
|
|
|
* being notified of the redirected MapRequest will
|
|
|
|
* specifically de-iconify. From source, fvwm2 seems
|
|
|
|
* to do the same.
|
|
|
|
*/
|
|
|
|
XMapWindow(fl_get_display(), form()->window);
|
2000-09-22 15:09:51 +00:00
|
|
|
} else {
|
2000-10-20 09:50:09 +00:00
|
|
|
// calls to fl_set_form_minsize/maxsize apply only to the next
|
2001-03-15 13:37:04 +00:00
|
|
|
// fl_show_form(), so this comes first.
|
|
|
|
fl_set_form_minsize(form(), minw_, minh_);
|
2001-08-28 13:48:40 +00:00
|
|
|
if (!allow_resize_)
|
|
|
|
fl_set_form_maxsize(form(), minw_, minh_);
|
|
|
|
|
2000-09-22 15:09:51 +00:00
|
|
|
fl_show_form(form(),
|
2001-09-07 10:11:02 +00:00
|
|
|
FL_PLACE_MOUSE | FL_FREE_SIZE,
|
|
|
|
(controller_.IconifyWithMain() ? FL_TRANSIENT : 0),
|
|
|
|
title_.c_str());
|
2000-09-22 15:09:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormBase::hide()
|
|
|
|
{
|
2002-02-28 14:36:23 +00:00
|
|
|
// xforms sometimes tries to process a hint-type MotionNotify, and
|
|
|
|
// use XQueryPointer, without verifying if the window still exists.
|
|
|
|
// So we try to clear out motion events in the queue before the
|
|
|
|
// DestroyNotify
|
|
|
|
XSync(fl_get_display(), false);
|
|
|
|
GUIRunTime::processEvents();
|
|
|
|
|
2001-03-15 13:37:04 +00:00
|
|
|
if (form() && form()->visible)
|
2000-10-13 05:57:05 +00:00
|
|
|
fl_hide_form(form());
|
2000-09-29 06:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-15 13:37:04 +00:00
|
|
|
void FormBase::InputCB(FL_OBJECT * ob, long data)
|
2000-09-22 15:09:51 +00:00
|
|
|
{
|
2001-09-24 10:49:55 +00:00
|
|
|
// It is possible to set the choice to 0 when using the
|
|
|
|
// keyboard shortcuts. This work-around deals with the problem.
|
|
|
|
if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
|
|
|
|
fl_set_choice(ob, 1);
|
|
|
|
}
|
|
|
|
|
2001-03-15 13:37:04 +00:00
|
|
|
bc().input(input(ob, data));
|
2000-09-22 15:09:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-20 10:14:03 +00:00
|
|
|
ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
|
|
|
|
{
|
2001-03-21 13:27:03 +00:00
|
|
|
return ButtonPolicy::SMI_VALID;
|
2001-03-20 10:14:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-05 14:59:26 +00:00
|
|
|
// preemptive handler for feedback messages
|
|
|
|
void FormBase::FeedbackCB(FL_OBJECT * ob, int event)
|
|
|
|
{
|
|
|
|
lyx::Assert(ob);
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case FL_ENTER:
|
|
|
|
warning_posted_ = false;
|
|
|
|
feedback(ob);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FL_LEAVE:
|
|
|
|
if (!warning_posted_)
|
|
|
|
clear_feedback();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-05 17:25:16 +00:00
|
|
|
void FormBase::setTooltipHandler(FL_OBJECT * ob)
|
|
|
|
{
|
2002-02-06 17:15:28 +00:00
|
|
|
tooltip_->activateTooltip(ob);
|
2002-02-05 17:25:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-06 17:15:28 +00:00
|
|
|
string FormBase::getTooltip(FL_OBJECT const * ob)
|
2002-02-05 14:59:26 +00:00
|
|
|
{
|
|
|
|
lyx::Assert(ob);
|
|
|
|
|
2002-02-06 12:12:04 +00:00
|
|
|
switch (tooltip_level_) {
|
|
|
|
case VERBOSE_TOOLTIP:
|
|
|
|
{
|
|
|
|
string str = getVerboseTooltip(ob);
|
|
|
|
if (!str.empty())
|
|
|
|
return formatted(_(str), 400);
|
|
|
|
// else, fall through
|
|
|
|
}
|
|
|
|
|
|
|
|
case MINIMAL_TOOLTIP:
|
|
|
|
return getMinimalTooltip(ob);
|
|
|
|
|
|
|
|
case NO_TOOLTIP:
|
|
|
|
default:
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-02-05 14:59:26 +00:00
|
|
|
|
2002-02-06 17:15:28 +00:00
|
|
|
/// Fill the tooltips chooser with the standard descriptions
|
|
|
|
void FormBase::fillTooltipChoice(FL_OBJECT * ob)
|
|
|
|
{
|
|
|
|
lyx::Assert(ob && ob->objclass == FL_CHOICE);
|
|
|
|
|
|
|
|
fl_clear_choice(ob);
|
|
|
|
fl_addto_choice(ob, _(" None | Normal | Verbose "));
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
switch (tooltip_level_) {
|
2002-02-06 17:15:28 +00:00
|
|
|
case NO_TOOLTIP:
|
|
|
|
fl_set_choice(ob, 1);
|
|
|
|
break;
|
|
|
|
case MINIMAL_TOOLTIP:
|
|
|
|
fl_set_choice(ob, 2);
|
|
|
|
break;
|
|
|
|
case VERBOSE_TOOLTIP:
|
|
|
|
fl_set_choice(ob, 3);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormBase::setTooltipLevel(FL_OBJECT * ob)
|
2002-02-05 14:59:26 +00:00
|
|
|
{
|
2002-02-06 17:15:28 +00:00
|
|
|
lyx::Assert(ob && ob->objclass == FL_CHOICE &&
|
|
|
|
fl_get_choice_maxitems(ob) == 3);
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
switch (fl_get_choice(ob)) {
|
2002-02-06 17:15:28 +00:00
|
|
|
case 1:
|
|
|
|
tooltip_level_ = NO_TOOLTIP;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
tooltip_level_ = MINIMAL_TOOLTIP;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
tooltip_level_ = VERBOSE_TOOLTIP;
|
|
|
|
break;
|
|
|
|
}
|
2002-02-05 14:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-06 12:12:04 +00:00
|
|
|
void FormBase::setPrehandler(FL_OBJECT * ob)
|
2002-02-05 17:25:16 +00:00
|
|
|
{
|
2002-02-06 12:12:04 +00:00
|
|
|
lyx::Assert(ob);
|
|
|
|
fl_set_object_prehandler(ob, C_FormBasePrehandler);
|
2002-02-05 17:25:16 +00:00
|
|
|
}
|
|
|
|
|
2002-02-06 12:12:04 +00:00
|
|
|
|
|
|
|
void FormBase::setWarningPosted(bool warning)
|
|
|
|
{
|
|
|
|
warning_posted_ = warning;
|
|
|
|
}
|
2002-02-05 17:25:16 +00:00
|
|
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
FormBase * GetForm(FL_OBJECT * ob)
|
2000-09-22 15:09:51 +00:00
|
|
|
{
|
2001-04-24 15:25:26 +00:00
|
|
|
lyx::Assert(ob && ob->form && ob->form->u_vdata);
|
2001-03-15 13:37:04 +00:00
|
|
|
FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
|
|
|
|
return pre;
|
2000-09-22 15:09:51 +00:00
|
|
|
}
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
2000-09-22 15:09:51 +00:00
|
|
|
|
2001-09-09 22:02:19 +00:00
|
|
|
extern "C" {
|
2002-01-28 18:42:37 +00:00
|
|
|
|
2002-02-05 14:59:26 +00:00
|
|
|
void C_FormBaseApplyCB(FL_OBJECT * ob, long)
|
|
|
|
{
|
|
|
|
GetForm(ob)->ApplyButton();
|
|
|
|
}
|
2000-09-22 15:09:51 +00:00
|
|
|
|
|
|
|
|
2002-02-05 14:59:26 +00:00
|
|
|
void C_FormBaseOKCB(FL_OBJECT * ob, long)
|
|
|
|
{
|
|
|
|
GetForm(ob)->OKButton();
|
|
|
|
}
|
2000-10-13 05:57:05 +00:00
|
|
|
|
|
|
|
|
2002-02-05 14:59:26 +00:00
|
|
|
void C_FormBaseCancelCB(FL_OBJECT * ob, long)
|
|
|
|
{
|
|
|
|
FormBase * form = GetForm(ob);
|
|
|
|
form->CancelButton();
|
|
|
|
}
|
2000-10-13 05:57:05 +00:00
|
|
|
|
|
|
|
|
2002-02-05 14:59:26 +00:00
|
|
|
void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
|
|
|
|
{
|
|
|
|
GetForm(ob)->RestoreButton();
|
|
|
|
}
|
2000-10-13 05:57:05 +00:00
|
|
|
|
|
|
|
|
2002-02-05 14:59:26 +00:00
|
|
|
void C_FormBaseInputCB(FL_OBJECT * ob, long d)
|
|
|
|
{
|
|
|
|
GetForm(ob)->InputCB(ob, d);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-05 17:25:16 +00:00
|
|
|
static int C_FormBaseWMHideCB(FL_FORM * form, void *)
|
|
|
|
{
|
|
|
|
// Close the dialog cleanly, even if the WM is used to do so.
|
|
|
|
lyx::Assert(form && form->u_vdata);
|
|
|
|
FormBase * pre = static_cast<FormBase *>(form->u_vdata);
|
|
|
|
pre->CancelButton();
|
|
|
|
return FL_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-05 14:59:26 +00:00
|
|
|
static int C_FormBasePrehandler(FL_OBJECT * ob, int event,
|
|
|
|
FL_Coord, FL_Coord, int key, void *)
|
|
|
|
{
|
|
|
|
// Note that the return value is important in the pre-emptive handler.
|
|
|
|
// Don't return anything other than 0.
|
|
|
|
lyx::Assert(ob);
|
|
|
|
|
|
|
|
// Don't Assert this one, as it can happen quite naturally when things
|
|
|
|
// are being deleted in the d-tor.
|
|
|
|
//Assert(ob->form);
|
|
|
|
if (!ob->form) return 0;
|
|
|
|
|
|
|
|
FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
|
|
|
|
if (!pre) return 0;
|
2001-08-29 11:01:05 +00:00
|
|
|
|
2002-02-05 14:59:26 +00:00
|
|
|
if (event == FL_PUSH && key == 2 && ob->objclass == FL_INPUT) {
|
|
|
|
// Trigger an input event when pasting in an xforms input object
|
|
|
|
// using the middle mouse button.
|
|
|
|
pre->InputCB(ob, 0);
|
2001-08-29 11:01:05 +00:00
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
} else if (event == FL_ENTER || event == FL_LEAVE) {
|
2002-02-05 14:59:26 +00:00
|
|
|
// Post feedback as the mouse enters the object,
|
|
|
|
// remove it as the mouse leaves.
|
|
|
|
pre->FeedbackCB(ob, event);
|
2001-08-29 11:01:05 +00:00
|
|
|
}
|
|
|
|
|
2002-02-05 14:59:26 +00:00
|
|
|
return 0;
|
2001-08-29 11:01:05 +00:00
|
|
|
}
|
2002-02-05 17:25:16 +00:00
|
|
|
|
2002-02-05 14:59:26 +00:00
|
|
|
} // extern "C"
|