2 * \file FeedbackController.C
3 * Read the file COPYING
5 * \author Angus Leeming
7 * Full author contact details are available in file CREDITS
10 /* A common interface for posting feedback messages to a message widget in
12 * Derive FormBase and FormBaseDeprecated from it, so daughter classes of
13 * either can use the same interface.
19 #pragma implementation
22 #include "FeedbackController.h"
23 #include "gettext.h" // _()
24 #include "xforms_helpers.h" // formatted
25 #include "support/LAssert.h"
26 #include FORMS_H_LOCATION
28 FeedbackController::FeedbackController()
29 : warning_posted_(false), message_widget_(0)
33 FeedbackController::~FeedbackController()
37 void FeedbackController::setMessageWidget(FL_OBJECT * ob)
39 lyx::Assert(ob && ob->objclass == FL_TEXT);
41 fl_set_object_lsize(message_widget_, FL_SMALL_SIZE);
45 // preemptive handler for feedback messages
46 void FeedbackController::MessageCB(FL_OBJECT * ob, int event)
53 string const feedback = getFeedback(ob);
54 if (feedback.empty() && warning_posted_)
57 warning_posted_ = false;
58 postMessage(getFeedback(ob));
73 void FeedbackController::PrehandlerCB(FL_OBJECT * ob, int event, int key)
75 if (event == FL_PUSH && key == 2 && ob->objclass == FL_INPUT) {
76 // Trigger an input event when pasting in an xforms input object
77 // using the middle mouse button.
80 } else if (message_widget_ &&
81 (event == FL_ENTER || event == FL_LEAVE)) {
82 // Post feedback as the mouse enters the object,
83 // remove it as the mouse leaves.
89 void FeedbackController::postWarning(string const & warning)
91 warning_posted_ = true;
96 void FeedbackController::clearMessage()
98 lyx::Assert(message_widget_);
100 warning_posted_ = false;
102 string const existing = message_widget_->label
103 ? message_widget_->label : string();
104 if (existing.empty())
107 // This trick is needed to get xforms to clear the label...
108 fl_set_object_label(message_widget_, "");
109 fl_hide_object(message_widget_);
113 void FeedbackController::postMessage(string const & message)
115 lyx::Assert(message_widget_);
119 str = _("WARNING! ") + message;
123 str = formatted(str, message_widget_->w-10, FL_SMALL_SIZE);
125 fl_set_object_label(message_widget_, str.c_str());
126 FL_COLOR const label_color = warning_posted_ ? FL_TOMATO : FL_BLACK;
127 fl_set_object_lcol(message_widget_, label_color);
129 if (!message_widget_->visible)
130 fl_show_object(message_widget_);