]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormErrorList.C
Introduce LFUN_PRINT.
[lyx.git] / src / frontends / xforms / FormErrorList.C
1 /**
2  * \file FormErrorList.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alfredo Braunstein
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "FormErrorList.h"
14 #include "ControlErrorList.h"
15 #include "forms/form_errorlist.h"
16
17 #include "xformsBC.h"
18 #include "xforms_helpers.h"
19 #include "lyx_forms.h"
20
21
22 typedef FormController<ControlErrorList, FormView<FD_errorlist> > base_class;
23
24 FormErrorList::FormErrorList(Dialog & parent)
25         : base_class(parent, "")
26 {}
27
28
29 int dumb_validator(FL_OBJECT *, const char *, const char *, int)
30 {
31         return FL_INVALID;
32 }
33
34
35 void FormErrorList::build()
36 {
37         dialog_.reset(build_errorlist(this));
38         fl_set_input_filter(dialog_->input_description, dumb_validator);
39 }
40
41
42 void FormErrorList::update()
43 {
44         setTitle(controller().name());
45         updateContents();
46 }
47
48
49 ButtonPolicy::SMInput FormErrorList::input(FL_OBJECT * ob, long)
50 {
51         if (ob == dialog_->browser_errors) {
52                 //xforms return values 1..n
53                 int const choice = int(fl_get_browser(dialog_->browser_errors)) - 1;
54                 goTo(choice);
55         }
56
57         return ButtonPolicy::SMI_VALID;
58 }
59
60
61 void FormErrorList::goTo(int where)
62 {
63         ErrorList const & errors = controller().errorList();
64
65         if (0 <= where && where < int(errors.size())) {
66                 controller().goTo(where);
67                 fl_set_input(dialog_->input_description,
68                              errors[where].description.c_str());
69                 fl_set_input_topline(dialog_->input_description, 1);
70         }
71 }
72
73
74 void FormErrorList::updateContents()
75 {
76         fl_clear_browser(dialog_->browser_errors);
77
78         ErrorList const & errors = controller().errorList();
79         if (errors.empty()) {
80                 fl_add_browser_line(dialog_->browser_errors,
81                                     _("*** No Lists ***").c_str());
82                 setEnabled(dialog_->browser_errors, false);
83                 return;
84         }
85
86         setEnabled(dialog_->browser_errors, true);
87
88         ErrorList::const_iterator cit = errors.begin();
89         ErrorList::const_iterator end = errors.end();
90
91         for (; cit != end; ++cit) {
92                 fl_add_browser_line(dialog_->browser_errors,
93                                     cit->error.c_str());
94         }
95
96         fl_select_browser_line(dialog_->browser_errors, 1);
97         goTo(0);
98 }