2 * \file FeedbackController.C
3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
6 * \author Angus Leeming, a.leeming@ic.ac.uk
9 /* A common interface for posting feedback messages to a message widget in
11 * Derive FormBase and FormBaseDeprecated from it, so daughter classes of
12 * either can use the same interface.
18 #pragma implementation
21 #include "FeedbackController.h"
22 #include "gettext.h" // _()
23 #include "xforms_helpers.h" // formatted
24 #include "support/LAssert.h"
26 FeedbackController::FeedbackController()
27 : warning_posted_(false), message_widget_(0)
31 FeedbackController::~FeedbackController()
35 void FeedbackController::setMessageWidget(FL_OBJECT * ob)
37 lyx::Assert(ob && ob->objclass == FL_TEXT);
39 fl_set_object_lsize(message_widget_, FL_SMALL_SIZE);
43 // preemptive handler for feedback messages
44 void FeedbackController::MessageCB(FL_OBJECT * ob, int event)
51 string const feedback = getFeedback(ob);
52 if (feedback.empty() && warning_posted_)
55 warning_posted_ = false;
56 postMessage(getFeedback(ob));
71 void FeedbackController::PrehandlerCB(FL_OBJECT * ob, int event, int key)
73 if (event == FL_PUSH && key == 2 && ob->objclass == FL_INPUT) {
74 // Trigger an input event when pasting in an xforms input object
75 // using the middle mouse button.
78 } else if (message_widget_ &&
79 (event == FL_ENTER || event == FL_LEAVE)) {
80 // Post feedback as the mouse enters the object,
81 // remove it as the mouse leaves.
87 void FeedbackController::postWarning(string const & warning)
89 warning_posted_ = true;
94 void FeedbackController::clearMessage()
96 lyx::Assert(message_widget_);
98 warning_posted_ = false;
100 string const existing = message_widget_->label
101 ? message_widget_->label : string();
102 if (existing.empty())
105 // This trick is needed to get xforms to clear the label...
106 fl_set_object_label(message_widget_, "");
107 fl_hide_object(message_widget_);
111 void FeedbackController::postMessage(string const & message)
113 lyx::Assert(message_widget_);
117 str = _("WARNING! ") + message;
121 str = formatted(str, message_widget_->w-10, FL_SMALL_SIZE);
123 fl_set_object_label(message_widget_, str.c_str());
124 FL_COLOR const label_color = warning_posted_ ? FL_TOMATO : FL_BLACK;
125 fl_set_object_lcol(message_widget_, label_color);
127 if (!message_widget_->visible)
128 fl_show_object(message_widget_);