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)
78 if (ob->objclass == FL_INPUT && event == FL_PUSH && key == 2) {
79 // Trigger an input event when pasting in an xforms input object
80 // using the middle mouse button.
83 } else if (ob->objclass == FL_TABFOLDER &&
84 (event == FL_ENTER || event == FL_LEAVE)) {
85 // This prehandler is used to work-around an xforms bug and
86 // ensures that the form->x, form->y coords of the active
87 // tabfolder are up to date.
89 // The tabfolder itself can be very narrow, being just
90 // the visible border to the tabs.
91 // We thus use both FL_ENTER and FL_LEAVE as flags,
92 // in case the FL_ENTER event is not caught.
94 FL_FORM * const folder = fl_get_active_folder(ob);
97 fl_get_wingeometry(folder->window,
98 &(folder->x), &(folder->y), &w, &h);
101 } else if (message_widget_ &&
102 (event == FL_ENTER || event == FL_LEAVE)) {
103 // Post feedback as the mouse enters the object,
104 // remove it as the mouse leaves.
105 MessageCB(ob, event);
110 void FeedbackController::postWarning(string const & warning)
112 warning_posted_ = true;
113 postMessage(warning);
117 void FeedbackController::clearMessage()
119 lyx::Assert(message_widget_);
121 warning_posted_ = false;
123 string const existing = message_widget_->label
124 ? message_widget_->label : string();
125 if (existing.empty())
128 // This trick is needed to get xforms to clear the label...
129 fl_set_object_label(message_widget_, "");
130 fl_hide_object(message_widget_);
134 void FeedbackController::postMessage(string const & message)
136 lyx::Assert(message_widget_);
140 str = _("WARNING! ") + message;
144 str = formatted(str, message_widget_->w-10, FL_SMALL_SIZE);
146 fl_set_object_label(message_widget_, str.c_str());
147 FL_COLOR const label_color = warning_posted_ ? FL_TOMATO : FL_BLACK;
148 fl_set_object_lcol(message_widget_, label_color);
150 if (!message_widget_->visible)
151 fl_show_object(message_widget_);