]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FeedbackController.C
Really dull and boring header shit
[lyx.git] / src / frontends / xforms / FeedbackController.C
1 /**
2  * \file FeedbackController.C
3  * Read the file COPYING
4  *
5  * \author Angus Leeming 
6  *
7  * Full author contact details are available in file CREDITS
8  */
9
10 /* A common interface for posting feedback messages to a message widget in
11  * xforms.
12  * Derive FormBase and FormBaseDeprecated from it, so daughter classes of
13  * either can use the same interface.
14  */
15
16 #include <config.h>
17
18 #ifdef __GNUG__
19 #pragma implementation
20 #endif
21
22 #include "FeedbackController.h"
23 #include "gettext.h"        // _()
24 #include "xforms_helpers.h" // formatted
25 #include "support/LAssert.h"
26 #include FORMS_H_LOCATION
27
28 FeedbackController::FeedbackController()
29         : warning_posted_(false), message_widget_(0)
30 {}
31
32
33 FeedbackController::~FeedbackController()
34 {}
35
36
37 void FeedbackController::setMessageWidget(FL_OBJECT * ob)
38 {
39         lyx::Assert(ob && ob->objclass == FL_TEXT);
40         message_widget_ = ob;
41         fl_set_object_lsize(message_widget_, FL_SMALL_SIZE);
42 }
43
44
45 // preemptive handler for feedback messages
46 void FeedbackController::MessageCB(FL_OBJECT * ob, int event)
47 {
48         lyx::Assert(ob);
49
50         switch (event) {
51         case FL_ENTER:
52         {
53                 string const feedback = getFeedback(ob);
54                 if (feedback.empty() && warning_posted_)
55                         break;
56
57                 warning_posted_ = false;
58                 postMessage(getFeedback(ob));
59                 break;
60         }
61
62         case FL_LEAVE:
63                 if (!warning_posted_)
64                         clearMessage();
65                 break;
66
67         default:
68                 break;
69         }
70 }
71
72
73 void FeedbackController::PrehandlerCB(FL_OBJECT * ob, int event, int key)
74 {
75         if (event == FL_PUSH && key == 2 && ob->objclass == FL_INPUT) {
76                 // Trigger an input event when pasting in an xforms input object
77                 // using the middle mouse button.
78                 InputCB(ob, 0);
79
80         } else if (message_widget_ &&
81                    (event == FL_ENTER || event == FL_LEAVE)) {
82                 // Post feedback as the mouse enters the object,
83                 // remove it as the mouse leaves.
84                 MessageCB(ob, event);
85         }
86 }
87
88
89 void FeedbackController::postWarning(string const & warning)
90 {
91         warning_posted_ = true;
92         postMessage(warning);
93 }
94
95
96 void FeedbackController::clearMessage()
97 {
98         lyx::Assert(message_widget_);
99
100         warning_posted_ = false;
101
102         string const existing = message_widget_->label
103                 ? message_widget_->label : string();
104         if (existing.empty())
105                 return;
106
107         // This trick is needed to get xforms to clear the label...
108         fl_set_object_label(message_widget_, "");
109         fl_hide_object(message_widget_);
110 }
111
112
113 void FeedbackController::postMessage(string const & message)
114 {
115         lyx::Assert(message_widget_);
116
117         string str;
118         if (warning_posted_)
119                 str = _("WARNING! ") + message;
120         else
121                 str = message;
122
123         str = formatted(str, message_widget_->w-10, FL_SMALL_SIZE);
124
125         fl_set_object_label(message_widget_, str.c_str());
126         FL_COLOR const label_color = warning_posted_ ? FL_TOMATO : FL_BLACK;
127         fl_set_object_lcol(message_widget_, label_color);
128
129         if (!message_widget_->visible)
130                 fl_show_object(message_widget_);
131 }