]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FeedbackController.C
Give people a rational basis to describe what they dislike about tooltips!!!
[lyx.git] / src / frontends / xforms / FeedbackController.C
1 /*
2  * \file FeedbackController.C
3  * Copyright 2002 the LyX Team
4  * Read the file COPYING
5  *
6  * \author Angus Leeming, a.leeming@ic.ac.uk
7  *
8  * A common interface for posting feedback messages to a message widget in
9  * xforms.
10  * Derive FormBase and FormBaseDeprecated from it, so daughter classes of
11  * either can interface tooltips in the same way.
12  */
13
14 #include <config.h>
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20 #include "FeedbackController.h"
21 #include "gettext.h"        // _()
22 #include "xforms_helpers.h" // formatted
23 #include "support/LAssert.h"
24
25 FeedbackController::FeedbackController()
26         : warning_posted_(false)
27 {}
28
29
30 FeedbackController::~FeedbackController()
31 {}
32
33
34 void FeedbackController::setMessageWidget(FL_OBJECT * ob)
35 {
36         lyx::Assert(ob && ob->objclass  == FL_TEXT);
37         message_widget_ = ob;
38 }
39
40
41 // preemptive handler for feedback messages
42 void FeedbackController::MessageCB(FL_OBJECT * ob, int event)
43 {
44         lyx::Assert(ob && message_widget_);
45
46         switch (event) {
47         case FL_ENTER:
48                 warning_posted_ = false;
49                 postMessage(getFeedback(ob));
50                 break;
51
52         case FL_LEAVE:
53                 if (!warning_posted_)
54                         fl_set_object_label(message_widget_, "");
55                 break;
56
57         default:
58                 break;
59         }
60 }
61
62
63 void FeedbackController::PrehandlerCB(FL_OBJECT * ob, int event, int key)
64 {
65         if (event == FL_PUSH && key == 2 && ob->objclass == FL_INPUT) {
66                 // Trigger an input event when pasting in an xforms input object
67                 // using the middle mouse button.
68                 InputCB(ob, 0);
69
70         } else if (event == FL_ENTER || event == FL_LEAVE){
71                 // Post feedback as the mouse enters the object,
72                 // remove it as the mouse leaves.
73                 MessageCB(ob, event);
74         }
75 }
76
77
78 void FeedbackController::postWarning(string const & warning)
79 {
80         lyx::Assert(message_widget_);
81
82         warning_posted_ = true;
83
84         string const str = _("WARNING! ") + warning;
85         postMessage(str);
86 }
87
88
89 void FeedbackController::postMessage(string const & message)
90 {
91         string const str = formatted(message,
92                                      message_widget_->w-10, FL_SMALL_SIZE);
93
94         fl_set_object_label(message_widget_, str.c_str());
95         fl_set_object_lsize(message_widget_, FL_SMALL_SIZE);
96 }