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_NORMAL_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));
73 #if FL_VERSION > 0 || FL_REVISION >= 89
76 void fl_show_tooltip(const char *, int, int);
78 void fl_hide_tooltip();
83 void FeedbackController::PrehandlerCB(FL_OBJECT * ob, int event, int key)
87 if (ob->objclass == FL_INPUT && event == FL_PUSH && key == 2) {
88 // Trigger an input event when pasting in an xforms input object
89 // using the middle mouse button.
95 if (event != FL_ENTER && event != FL_LEAVE)
98 if (ob->objclass == FL_TABFOLDER) {
99 // This prehandler is used to work-around an xforms bug and
100 // ensures that the form->x, form->y coords of the active
101 // tabfolder are up to date.
103 // The tabfolder itself can be very narrow, being just
104 // the visible border to the tabs.
105 // We thus use both FL_ENTER and FL_LEAVE as flags,
106 // in case the FL_ENTER event is not caught.
108 FL_FORM * const folder = fl_get_active_folder(ob);
109 if (folder && folder->window) {
110 fl_get_winorigin(folder->window,
111 &(folder->x), &(folder->y));
116 if (message_widget_) {
117 // Post feedback as the mouse enters the object,
118 // remove it as the mouse leaves.
119 MessageCB(ob, event);
122 #if FL_VERSION > 0 || FL_REVISION >= 89
123 // Tooltips are not displayed on browser widgets due to an xforms' bug.
124 // This is a work-around:
125 if (ob->objclass == FL_BROWSER) {
126 if (event == FL_ENTER && ob->tooltip && *(ob->tooltip)) {
127 fl_show_tooltip(ob->tooltip, ob->form->x + ob->x,
128 ob->form->y + ob->y + ob->h + 1);
129 } else if (event == FL_LEAVE) {
137 void FeedbackController::postWarning(string const & warning)
139 warning_posted_ = true;
140 postMessage(warning);
144 void FeedbackController::clearMessage()
146 lyx::Assert(message_widget_);
148 warning_posted_ = false;
150 string const existing = message_widget_->label
151 ? message_widget_->label : string();
152 if (existing.empty())
155 // This trick is needed to get xforms to clear the label...
156 fl_set_object_label(message_widget_, "");
157 fl_hide_object(message_widget_);
161 void FeedbackController::postMessage(string const & message)
163 lyx::Assert(message_widget_);
167 str = _("WARNING! ") + message;
171 int const width = message_widget_->w - 10;
172 str = formatted(str, width, FL_NORMAL_SIZE);
174 fl_set_object_label(message_widget_, str.c_str());
175 FL_COLOR const label_color = warning_posted_ ? FL_RED : FL_LCOL;
176 fl_set_object_lcol(message_widget_, label_color);
178 if (!message_widget_->visible)
179 fl_show_object(message_widget_);