]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FeedbackController.C
Fix crash by removing unjustified Assert.
[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         if (!message_widget_) {
46                 // fail silently.
47                 return;
48         }
49
50         lyx::Assert(ob);
51
52         switch (event) {
53         case FL_ENTER:
54                 warning_posted_ = false;
55                 postMessage(getFeedback(ob));
56                 break;
57
58         case FL_LEAVE:
59                 if (!warning_posted_)
60                         fl_set_object_label(message_widget_, "");
61                 break;
62
63         default:
64                 break;
65         }
66 }
67
68
69 void FeedbackController::PrehandlerCB(FL_OBJECT * ob, int event, int key)
70 {
71         if (event == FL_PUSH && key == 2 && ob->objclass == FL_INPUT) {
72                 // Trigger an input event when pasting in an xforms input object
73                 // using the middle mouse button.
74                 InputCB(ob, 0);
75
76         } else if (event == FL_ENTER || event == FL_LEAVE){
77                 // Post feedback as the mouse enters the object,
78                 // remove it as the mouse leaves.
79                 MessageCB(ob, event);
80         }
81 }
82
83
84 void FeedbackController::postWarning(string const & warning)
85 {
86         lyx::Assert(message_widget_);
87
88         warning_posted_ = true;
89
90         string const str = _("WARNING! ") + warning;
91         postMessage(str);
92 }
93
94
95 void FeedbackController::postMessage(string const & message)
96 {
97         string const str = formatted(message,
98                                      message_widget_->w-10, FL_SMALL_SIZE);
99
100         fl_set_object_label(message_widget_, str.c_str());
101         fl_set_object_lsize(message_widget_, FL_SMALL_SIZE);
102 }