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"
25 #include FORMS_H_LOCATION
27 FeedbackController::FeedbackController()
28 : warning_posted_(false), message_widget_(0)
32 FeedbackController::~FeedbackController()
36 void FeedbackController::setMessageWidget(FL_OBJECT * ob)
38 lyx::Assert(ob && ob->objclass == FL_TEXT);
40 fl_set_object_lsize(message_widget_, FL_SMALL_SIZE);
44 // preemptive handler for feedback messages
45 void FeedbackController::MessageCB(FL_OBJECT * ob, int event)
52 string const feedback = getFeedback(ob);
53 if (feedback.empty() && warning_posted_)
56 warning_posted_ = false;
57 postMessage(getFeedback(ob));
72 void FeedbackController::PrehandlerCB(FL_OBJECT * ob, int event, int key)
74 if (event == FL_PUSH && key == 2 && ob->objclass == FL_INPUT) {
75 // Trigger an input event when pasting in an xforms input object
76 // using the middle mouse button.
79 } else if (message_widget_ &&
80 (event == FL_ENTER || event == FL_LEAVE)) {
81 // Post feedback as the mouse enters the object,
82 // remove it as the mouse leaves.
88 void FeedbackController::postWarning(string const & warning)
90 warning_posted_ = true;
95 void FeedbackController::clearMessage()
97 lyx::Assert(message_widget_);
99 warning_posted_ = false;
101 string const existing = message_widget_->label
102 ? message_widget_->label : string();
103 if (existing.empty())
106 // This trick is needed to get xforms to clear the label...
107 fl_set_object_label(message_widget_, "");
108 fl_hide_object(message_widget_);
112 void FeedbackController::postMessage(string const & message)
114 lyx::Assert(message_widget_);
118 str = _("WARNING! ") + message;
122 str = formatted(str, message_widget_->w-10, FL_SMALL_SIZE);
124 fl_set_object_label(message_widget_, str.c_str());
125 FL_COLOR const label_color = warning_posted_ ? FL_TOMATO : FL_BLACK;
126 fl_set_object_lcol(message_widget_, label_color);
128 if (!message_widget_->visible)
129 fl_show_object(message_widget_);