]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FeedbackController.C
Remove redundant files.
[lyx.git] / src / frontends / xforms / FeedbackController.C
1 /**
2  * \file FeedbackController.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming 
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 /* A common interface for posting feedback messages to a message widget in
12  * xforms.
13  * Derive FormBase and FormBaseDeprecated from it, so daughter classes of
14  * either can use the same interface.
15  */
16
17 #include <config.h>
18
19 #ifdef __GNUG__
20 #pragma implementation
21 #endif
22
23 #include "FeedbackController.h"
24 #include "gettext.h"        // _()
25 #include "xforms_helpers.h" // formatted
26 #include "support/LAssert.h"
27 #include FORMS_H_LOCATION
28
29 FeedbackController::FeedbackController()
30         : warning_posted_(false), message_widget_(0)
31 {}
32
33
34 FeedbackController::~FeedbackController()
35 {}
36
37
38 void FeedbackController::setMessageWidget(FL_OBJECT * ob)
39 {
40         lyx::Assert(ob && ob->objclass == FL_TEXT);
41         message_widget_ = ob;
42         fl_set_object_lsize(message_widget_, FL_NORMAL_SIZE);
43 }
44
45
46 // preemptive handler for feedback messages
47 void FeedbackController::MessageCB(FL_OBJECT * ob, int event)
48 {
49         lyx::Assert(ob);
50
51         switch (event) {
52         case FL_ENTER:
53         {
54                 string const feedback = getFeedback(ob);
55                 if (feedback.empty() && warning_posted_)
56                         break;
57
58                 warning_posted_ = false;
59                 postMessage(getFeedback(ob));
60                 break;
61         }
62
63         case FL_LEAVE:
64                 if (!warning_posted_)
65                         clearMessage();
66                 break;
67
68         default:
69                 break;
70         }
71 }
72
73 #if FL_VERSION > 0 || FL_REVISION >= 89
74 extern "C" {
75
76 void fl_show_tooltip(const char *, int, int);
77
78 void fl_hide_tooltip();
79
80 }
81 #endif
82
83 void FeedbackController::PrehandlerCB(FL_OBJECT * ob, int event, int key)
84 {
85         lyx::Assert(ob);
86
87         if (ob->objclass == FL_INPUT && event == FL_PUSH && key == 2) {
88                 // Trigger an input event when pasting in an xforms input object
89                 // using the middle mouse button.
90                 InputCB(ob, 0);
91                 return;
92         }
93
94
95         if (event != FL_ENTER && event != FL_LEAVE)
96                 return;
97
98         if (ob->objclass == FL_TABFOLDER) {
99                 // This prehandler is used to work-around an xforms bug and
100                 // ensures that the form->x, form->y coords of the active
101                 // tabfolder are up to date.
102
103                 // The tabfolder itself can be very narrow, being just
104                 // the visible border to the tabs.
105                 // We thus use both FL_ENTER and FL_LEAVE as flags,
106                 // in case the FL_ENTER event is not caught.
107
108                 FL_FORM * const folder = fl_get_active_folder(ob);
109                 if (folder && folder->window) {
110                         fl_get_winorigin(folder->window,
111                                          &(folder->x), &(folder->y));
112                 }
113                 
114         }
115
116         if (message_widget_) {
117                 // Post feedback as the mouse enters the object,
118                 // remove it as the mouse leaves.
119                 MessageCB(ob, event);
120         }
121
122 #if FL_VERSION > 0 || FL_REVISION >= 89
123         // Tooltips are not displayed on browser widgets due to an xforms' bug.
124         // This is a work-around:
125         if (ob->objclass == FL_BROWSER) {
126                 if (event == FL_ENTER && ob->tooltip && *(ob->tooltip)) {
127                         fl_show_tooltip(ob->tooltip, ob->form->x + ob->x,
128                                         ob->form->y + ob->y + ob->h + 1);
129                 } else if (event == FL_LEAVE) {
130                         fl_hide_tooltip();
131                 }
132         }
133 #endif
134 }
135
136
137 void FeedbackController::postWarning(string const & warning)
138 {
139         warning_posted_ = true;
140         postMessage(warning);
141 }
142
143
144 void FeedbackController::clearMessage()
145 {
146         lyx::Assert(message_widget_);
147
148         warning_posted_ = false;
149
150         string const existing = message_widget_->label
151                 ? message_widget_->label : string();
152         if (existing.empty())
153                 return;
154
155         // This trick is needed to get xforms to clear the label...
156         fl_set_object_label(message_widget_, "");
157         fl_hide_object(message_widget_);
158 }
159
160
161 void FeedbackController::postMessage(string const & message)
162 {
163         lyx::Assert(message_widget_);
164
165         string str;
166         if (warning_posted_)
167                 str = _("WARNING! ") + message;
168         else
169                 str = message;
170
171         int const width = message_widget_->w - 10;
172         str = formatted(str, width, FL_NORMAL_SIZE);
173
174         fl_set_object_label(message_widget_, str.c_str());
175         FL_COLOR const label_color = warning_posted_ ? FL_RED : FL_LCOL;
176         fl_set_object_lcol(message_widget_, label_color);
177
178         if (!message_widget_->visible)
179                 fl_show_object(message_widget_);
180 }