2 * \file FeedbackController.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS
11 /* A common interface for posting feedback messages to a message widget in
13 * Derive FormBase and FormBaseDeprecated from it, so daughter classes of
14 * either can use the same interface.
20 #pragma implementation
23 #include "FeedbackController.h"
24 #include "gettext.h" // _()
25 #include "xforms_helpers.h" // formatted
26 #include "support/LAssert.h"
27 #include FORMS_H_LOCATION
29 FeedbackController::FeedbackController()
30 : warning_posted_(false), message_widget_(0)
34 FeedbackController::~FeedbackController()
38 void FeedbackController::setMessageWidget(FL_OBJECT * ob)
40 lyx::Assert(ob && ob->objclass == FL_TEXT);
42 fl_set_object_lsize(message_widget_, FL_SMALL_SIZE);
46 // preemptive handler for feedback messages
47 void FeedbackController::MessageCB(FL_OBJECT * ob, int event)
54 string const feedback = getFeedback(ob);
55 if (feedback.empty() && warning_posted_)
58 warning_posted_ = false;
59 postMessage(getFeedback(ob));
74 void FeedbackController::PrehandlerCB(FL_OBJECT * ob, int event, int key)
76 if (event == FL_PUSH && key == 2 && ob->objclass == FL_INPUT) {
77 // Trigger an input event when pasting in an xforms input object
78 // using the middle mouse button.
81 } else if (message_widget_ &&
82 (event == FL_ENTER || event == FL_LEAVE)) {
83 // Post feedback as the mouse enters the object,
84 // remove it as the mouse leaves.
90 void FeedbackController::postWarning(string const & warning)
92 warning_posted_ = true;
97 void FeedbackController::clearMessage()
99 lyx::Assert(message_widget_);
101 warning_posted_ = false;
103 string const existing = message_widget_->label
104 ? message_widget_->label : string();
105 if (existing.empty())
108 // This trick is needed to get xforms to clear the label...
109 fl_set_object_label(message_widget_, "");
110 fl_hide_object(message_widget_);
114 void FeedbackController::postMessage(string const & message)
116 lyx::Assert(message_widget_);
120 str = _("WARNING! ") + message;
124 str = formatted(str, message_widget_->w-10, FL_SMALL_SIZE);
126 fl_set_object_label(message_widget_, str.c_str());
127 FL_COLOR const label_color = warning_posted_ ? FL_TOMATO : FL_BLACK;
128 fl_set_object_lcol(message_widget_, label_color);
130 if (!message_widget_->visible)
131 fl_show_object(message_widget_);