* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
- * \author Angus Leeming
+ * \author Angus Leeming
*
* Full author contact details are available in file CREDITS
*/
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
#include "FormBase.h"
#include "ControlButtons.h"
#include "xformsBC.h"
+#include "ButtonController.h"
#include "xforms_resize.h"
#include "Tooltips.h"
+#include "xforms_helpers.h" // formatted
+
+#include "gettext.h" // _()
+#include "support/BoostFormat.h"
#include "support/LAssert.h"
#include "support/filetools.h" // LibFileSearch
extern "C" {
-#if FL_VERSION > 0 || FL_REVISION >= 89
-// This should be in forms.h but isn't
+// These should be in forms.h but aren't
+void fl_show_tooltip(const char *, int, int);
+
void fl_hide_tooltip();
-#endif
// Callback function invoked by xforms when the dialog is closed by the
-// window manager
+// window manager.
static int C_WMHideCB(FL_FORM * form, void *);
-// Callback function invoked by the xforms pre- and post-handler routines
+// Callback function invoked by the xforms pre-handler routine.
static int C_PrehandlerCB(FL_OBJECT *, int, FL_Coord, FL_Coord, int, void *);
} // extern "C"
FormBase::FormBase(string const & t, bool allowResize)
- : ViewBase(), minw_(0), minh_(0), allow_resize_(allowResize),
+ : ViewBase(),
+ warning_posted_(false), message_widget_(0),
+ minw_(0), minh_(0), allow_resize_(allowResize),
title_(t), icon_pixmap_(0), icon_mask_(0),
tooltips_(new Tooltips())
{}
}
+bool FormBase::isVisible() const
+{
+ return form() && form()->visible;
+}
+
+
Tooltips & FormBase::tooltips()
{
return *tooltips_;
}
-xformsBC & FormBase::bc()
+xformsBC & FormBase::bcview()
{
- return static_cast<xformsBC &>(getController().bc());
- // return dynamic_cast<GUIbc &>(controller_ptr_->bc());
+ return static_cast<xformsBC &>(bc().view());
}
void FormBase::prepare_to_show()
{
- double const scale = scale_to_fit_tabs(form());
+ double const scale = get_scale_to_fit(form());
if (scale > 1.001)
- scale_form(form(), scale);
-
- bc().refresh();
+ scale_form_horizontally(form(), scale);
// work around dumb xforms sizing bug
minw_ = form()->w;
iconify_policy,
maximize_title.c_str());
}
-
- // For some strange reason known only to xforms, the tooltips can only
- // be set on a form that is already visible...
- tooltips().set();
}
void FormBase::hide()
{
-#if FL_VERSION > 0 || FL_REVISION >= 89
- // Does no harm if none is visible and ensures that the tooltip form
- // is hidden should the dialog be closed from the keyboard.
- fl_hide_tooltip();
-#endif
-
// 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
}
+void FormBase::setMessageWidget(FL_OBJECT * ob)
+{
+ lyx::Assert(ob && ob->objclass == FL_TEXT);
+ message_widget_ = ob;
+ fl_set_object_lsize(message_widget_, FL_NORMAL_SIZE);
+}
+
+
void FormBase::InputCB(FL_OBJECT * ob, long data)
{
// It is possible to set the choice to 0 when using the
}
+// preemptive handler for feedback messages
+void FormBase::MessageCB(FL_OBJECT * ob, int event)
+{
+ lyx::Assert(ob);
+
+ switch (event) {
+ case FL_ENTER:
+ {
+ string const feedback = getFeedback(ob);
+ if (feedback.empty() && warning_posted_)
+ break;
+
+ warning_posted_ = false;
+ postMessage(getFeedback(ob));
+ break;
+ }
+
+ case FL_LEAVE:
+ if (!warning_posted_)
+ clearMessage();
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+void FormBase::PrehandlerCB(FL_OBJECT * ob, int event, int key)
+{
+ lyx::Assert(ob);
+
+ if (ob->objclass == FL_INPUT && event == FL_PUSH && key == 2) {
+ // Trigger an input event when pasting in an xforms input object
+ // using the middle mouse button.
+ InputCB(ob, 0);
+ return;
+ }
+
+ if (message_widget_) {
+ switch (event) {
+ case FL_ENTER:
+ case FL_LEAVE:
+ // Post feedback as the mouse enters the object,
+ // remove it as the mouse leaves.
+ MessageCB(ob, event);
+ break;
+ }
+ }
+
+ // Tooltips are not displayed on browser widgets due to an xforms' bug.
+ // I have a fix, but it's not yet in the xforms sources.
+ // This is a work-around:
+ if (ob->objclass == FL_BROWSER) {
+ switch (event) {
+ case FL_ENTER:
+ if (ob->tooltip && *(ob->tooltip)) {
+ int const x = ob->form->x + ob->x;
+ int const y = ob->form->y + ob->y + ob->h + 1;
+ fl_show_tooltip(ob->tooltip, x, y);
+ }
+ break;
+ case FL_LEAVE:
+ case FL_PUSH:
+ case FL_KEYPRESS:
+ fl_hide_tooltip();
+ break;
+ }
+ }
+}
+
+
+void FormBase::postWarning(string const & warning)
+{
+ warning_posted_ = true;
+ postMessage(warning);
+}
+
+
+void FormBase::clearMessage()
+{
+ lyx::Assert(message_widget_);
+
+ warning_posted_ = false;
+
+ string const existing = message_widget_->label
+ ? message_widget_->label : string();
+ if (existing.empty())
+ return;
+
+ // This trick is needed to get xforms to clear the label...
+ fl_set_object_label(message_widget_, "");
+ fl_hide_object(message_widget_);
+}
+
+
+void FormBase::postMessage(string const & message)
+{
+ lyx::Assert(message_widget_);
+
+ int const width = message_widget_->w - 10;
+#if USE_BOOST_FORMAT
+ boost::format fmter = warning_posted_ ?
+ boost::format(_("WARNING! %1$s")) :
+ boost::format("%1$s");
+
+ string const str = formatted(boost::io::str(fmter % message),
+ width, FL_NORMAL_SIZE);
+#else
+ string const tmp = warning_posted_ ?
+ _("WARNING!") + string(" ") + message :
+ message;
+
+ string const str = formatted(tmp, width, FL_NORMAL_SIZE);
+#endif
+
+ fl_set_object_label(message_widget_, str.c_str());
+ FL_COLOR const label_color = warning_posted_ ? FL_RED : FL_LCOL;
+ fl_set_object_lcol(message_widget_, label_color);
+
+ if (!message_widget_->visible)
+ fl_show_object(message_widget_);
+}
+
+
namespace {
FormBase * GetForm(FL_OBJECT * ob)