]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FeedbackController.C
sourcedoc-friendly files.
[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
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 interface tooltips in the same way.
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
26 FeedbackController::FeedbackController()
27         : warning_posted_(false)
28 {}
29
30
31 FeedbackController::~FeedbackController()
32 {}
33
34
35 void FeedbackController::setMessageWidget(FL_OBJECT * ob)
36 {
37         lyx::Assert(ob && ob->objclass  == FL_TEXT);
38         message_widget_ = ob;
39 }
40
41
42 // preemptive handler for feedback messages
43 void FeedbackController::MessageCB(FL_OBJECT * ob, int event)
44 {
45         lyx::Assert(ob && message_widget_);
46
47         switch (event) {
48         case FL_ENTER:
49                 warning_posted_ = false;
50                 postMessage(getFeedback(ob));
51                 break;
52
53         case FL_LEAVE:
54                 if (!warning_posted_)
55                         fl_set_object_label(message_widget_, "");
56                 break;
57
58         default:
59                 break;
60         }
61 }
62
63
64 void FeedbackController::PrehandlerCB(FL_OBJECT * ob, int event, int key)
65 {
66         if (event == FL_PUSH && key == 2 && ob->objclass == FL_INPUT) {
67                 // Trigger an input event when pasting in an xforms input object
68                 // using the middle mouse button.
69                 InputCB(ob, 0);
70
71         } else if (event == FL_ENTER || event == FL_LEAVE){
72                 // Post feedback as the mouse enters the object,
73                 // remove it as the mouse leaves.
74                 MessageCB(ob, event);
75         }
76 }
77
78
79 void FeedbackController::postWarning(string const & warning)
80 {
81         lyx::Assert(message_widget_);
82
83         warning_posted_ = true;
84
85         string const str = _("WARNING! ") + warning;
86         postMessage(str);
87 }
88
89
90 void FeedbackController::postMessage(string const & message)
91 {
92         string const str = formatted(message,
93                                      message_widget_->w-10, FL_SMALL_SIZE);
94
95         fl_set_object_label(message_widget_, str.c_str());
96         fl_set_object_lsize(message_widget_, FL_SMALL_SIZE);
97 }