]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FeedbackController.C
Nothing but a changed email address (trying to factor my tree in in small steps)
[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 <leeming@lyx.org>
7  */
8
9 /* A common interface for posting feedback messages to a message widget in
10  * xforms.
11  * Derive FormBase and FormBaseDeprecated from it, so daughter classes of
12  * either can use the same interface.
13  */
14
15 #include <config.h>
16
17 #ifdef __GNUG__
18 #pragma implementation
19 #endif
20
21 #include "FeedbackController.h"
22 #include "gettext.h"        // _()
23 #include "xforms_helpers.h" // formatted
24 #include "support/LAssert.h"
25 #include FORMS_H_LOCATION
26
27 FeedbackController::FeedbackController()
28         : warning_posted_(false), message_widget_(0)
29 {}
30
31
32 FeedbackController::~FeedbackController()
33 {}
34
35
36 void FeedbackController::setMessageWidget(FL_OBJECT * ob)
37 {
38         lyx::Assert(ob && ob->objclass == FL_TEXT);
39         message_widget_ = ob;
40         fl_set_object_lsize(message_widget_, FL_SMALL_SIZE);
41 }
42
43
44 // preemptive handler for feedback messages
45 void FeedbackController::MessageCB(FL_OBJECT * ob, int event)
46 {
47         lyx::Assert(ob);
48
49         switch (event) {
50         case FL_ENTER:
51         {
52                 string const feedback = getFeedback(ob);
53                 if (feedback.empty() && warning_posted_)
54                         break;
55
56                 warning_posted_ = false;
57                 postMessage(getFeedback(ob));
58                 break;
59         }
60
61         case FL_LEAVE:
62                 if (!warning_posted_)
63                         clearMessage();
64                 break;
65
66         default:
67                 break;
68         }
69 }
70
71
72 void FeedbackController::PrehandlerCB(FL_OBJECT * ob, int event, int key)
73 {
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.
77                 InputCB(ob, 0);
78
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.
83                 MessageCB(ob, event);
84         }
85 }
86
87
88 void FeedbackController::postWarning(string const & warning)
89 {
90         warning_posted_ = true;
91         postMessage(warning);
92 }
93
94
95 void FeedbackController::clearMessage()
96 {
97         lyx::Assert(message_widget_);
98
99         warning_posted_ = false;
100
101         string const existing = message_widget_->label
102                 ? message_widget_->label : string();
103         if (existing.empty())
104                 return;
105
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_);
109 }
110
111
112 void FeedbackController::postMessage(string const & message)
113 {
114         lyx::Assert(message_widget_);
115
116         string str;
117         if (warning_posted_)
118                 str = _("WARNING! ") + message;
119         else
120                 str = message;
121
122         str = formatted(str, message_widget_->w-10, FL_SMALL_SIZE);
123
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);
127
128         if (!message_widget_->visible)
129                 fl_show_object(message_widget_);
130 }