2002-03-11 17:00:41 +00:00
|
|
|
/**
|
2002-03-11 09:54:42 +00:00
|
|
|
* \file FeedbackController.C
|
|
|
|
* Copyright 2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author Angus Leeming, a.leeming@ic.ac.uk
|
2002-03-11 17:00:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* A common interface for posting feedback messages to a message widget in
|
2002-03-11 09:54:42 +00:00
|
|
|
* xforms.
|
|
|
|
* Derive FormBase and FormBaseDeprecated from it, so daughter classes of
|
2002-03-11 18:24:31 +00:00
|
|
|
* either can use the same interface.
|
2002-03-11 09:54:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "FeedbackController.h"
|
|
|
|
#include "gettext.h" // _()
|
|
|
|
#include "xforms_helpers.h" // formatted
|
|
|
|
#include "support/LAssert.h"
|
|
|
|
|
|
|
|
FeedbackController::FeedbackController()
|
2002-03-11 17:39:58 +00:00
|
|
|
: warning_posted_(false), message_widget_(0)
|
2002-03-11 09:54:42 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
FeedbackController::~FeedbackController()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void FeedbackController::setMessageWidget(FL_OBJECT * ob)
|
|
|
|
{
|
2002-03-20 17:53:39 +00:00
|
|
|
lyx::Assert(ob && ob->objclass == FL_TEXT);
|
2002-03-11 09:54:42 +00:00
|
|
|
message_widget_ = ob;
|
2002-03-20 17:53:39 +00:00
|
|
|
fl_set_object_lsize(message_widget_, FL_SMALL_SIZE);
|
2002-03-11 09:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// preemptive handler for feedback messages
|
|
|
|
void FeedbackController::MessageCB(FL_OBJECT * ob, int event)
|
|
|
|
{
|
2002-03-11 17:31:07 +00:00
|
|
|
lyx::Assert(ob);
|
2002-03-11 09:54:42 +00:00
|
|
|
|
|
|
|
switch (event) {
|
2002-03-21 21:21:28 +00:00
|
|
|
case FL_ENTER:
|
2002-03-20 17:53:39 +00:00
|
|
|
{
|
|
|
|
string const feedback = getFeedback(ob);
|
|
|
|
if (feedback.empty() && warning_posted_)
|
|
|
|
break;
|
|
|
|
|
2002-03-11 09:54:42 +00:00
|
|
|
warning_posted_ = false;
|
|
|
|
postMessage(getFeedback(ob));
|
|
|
|
break;
|
2002-03-21 21:21:28 +00:00
|
|
|
}
|
2002-03-11 09:54:42 +00:00
|
|
|
|
|
|
|
case FL_LEAVE:
|
|
|
|
if (!warning_posted_)
|
2002-03-20 17:53:39 +00:00
|
|
|
clearMessage();
|
2002-03-11 09:54:42 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FeedbackController::PrehandlerCB(FL_OBJECT * ob, int event, int key)
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
InputCB(ob, 0);
|
|
|
|
|
2002-03-11 17:39:58 +00:00
|
|
|
} else if (message_widget_ &&
|
|
|
|
(event == FL_ENTER || event == FL_LEAVE)) {
|
2002-03-11 09:54:42 +00:00
|
|
|
// Post feedback as the mouse enters the object,
|
|
|
|
// remove it as the mouse leaves.
|
|
|
|
MessageCB(ob, event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FeedbackController::postWarning(string const & warning)
|
|
|
|
{
|
|
|
|
warning_posted_ = true;
|
2002-04-02 17:04:23 +00:00
|
|
|
postMessage(warning);
|
2002-03-11 09:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-20 17:53:39 +00:00
|
|
|
void FeedbackController::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_, "");
|
2002-04-02 17:04:23 +00:00
|
|
|
fl_hide_object(message_widget_);
|
2002-03-20 17:53:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-11 09:54:42 +00:00
|
|
|
void FeedbackController::postMessage(string const & message)
|
|
|
|
{
|
2002-03-11 17:39:58 +00:00
|
|
|
lyx::Assert(message_widget_);
|
|
|
|
|
2002-04-02 17:04:23 +00:00
|
|
|
string str;
|
|
|
|
if (warning_posted_)
|
|
|
|
str = _("WARNING! ") + message;
|
|
|
|
else
|
|
|
|
str = message;
|
|
|
|
|
|
|
|
str = formatted(str, message_widget_->w-10, FL_SMALL_SIZE);
|
2002-03-11 09:54:42 +00:00
|
|
|
|
|
|
|
fl_set_object_label(message_widget_, str.c_str());
|
2002-03-20 17:53:39 +00:00
|
|
|
FL_COLOR const label_color = warning_posted_ ? FL_TOMATO : FL_BLACK;
|
|
|
|
fl_set_object_lcol(message_widget_, label_color);
|
2002-04-02 17:04:23 +00:00
|
|
|
|
|
|
|
if (!message_widget_->visible)
|
|
|
|
fl_show_object(message_widget_);
|
2002-03-11 09:54:42 +00:00
|
|
|
}
|