]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormToc.C
Replace 'using namespace abc;' with 'using abc::xyz;'
[lyx.git] / src / frontends / xforms / FormToc.C
1 /**
2  * \file FormToc.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 #include <config.h>
12
13 #include "FormToc.h"
14 #include "ControlToc.h"
15 #include "forms/form_toc.h"
16
17 #include "xforms_helpers.h"
18 #include "xformsBC.h"
19
20 #include "support/lstrings.h" // frontStrip, strip
21
22 #include "lyx_forms.h"
23
24 using lyx::support::getStringFromVector;
25
26 using std::vector;
27
28
29 typedef FormController<ControlToc, FormView<FD_toc> > base_class;
30
31 FormToc::FormToc(Dialog & parent)
32         : base_class(parent, _("Table of Contents"))
33 {}
34
35
36 void FormToc::build()
37 {
38         dialog_.reset(build_toc(this));
39
40         vector<string> types = controller().getTypes();
41
42
43         string const choice =
44                 ' ' + getStringFromVector(controller().getTypes(), " | ") + ' ';
45         fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
46
47         // Manage the cancel/close button
48         bcview().setCancel(dialog_->button_close);
49 }
50
51
52 void FormToc::update()
53 {
54         updateType();
55         updateContents();
56 }
57
58
59 ButtonPolicy::SMInput FormToc::input(FL_OBJECT * ob, long)
60 {
61         if (ob == dialog_->browser_toc) {
62                 unsigned int const choice = fl_get_browser(dialog_->browser_toc);
63
64                 if (choice - 1 < toc_.size() && choice >= 1) {
65                         controller().goTo(toc_[choice - 1]);
66                 }
67                 return ButtonPolicy::SMI_VALID;
68         }
69
70         if (ob != dialog_->choice_toc_type) {
71                 updateType();
72         }
73
74         updateContents();
75
76         return ButtonPolicy::SMI_VALID;
77 }
78
79
80 void FormToc::updateType()
81 {
82         // Update the choice list from scratch
83         fl_clear_choice(dialog_->choice_toc_type);
84         string const choice = getStringFromVector(controller().getTypes(), "|");
85         fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
86
87         // And select the correct one
88         string const type = lyx::toc::getType(controller().params().getCmdName());
89         fl_set_choice_text(dialog_->choice_toc_type, type.c_str());
90 }
91
92
93 void FormToc::updateContents()
94 {
95         string const type = getString(dialog_->choice_toc_type);
96         if (type.empty()) {
97                 fl_clear_browser(dialog_->browser_toc);
98                 fl_add_browser_line(dialog_->browser_toc,
99                                     _("*** No Lists ***").c_str());
100                 setEnabled(dialog_->browser_toc, false);
101                 return;
102         }
103
104         lyx::toc::Toc const contents = controller().getContents(type);
105
106         // Check if all elements are the same.
107         if (toc_ == contents) {
108                 return;
109         }
110
111         // List has changed. Update browser
112         toc_ = contents;
113
114         if (contents.empty()) {
115                 fl_clear_browser(dialog_->browser_toc);
116                 fl_add_browser_line(dialog_->browser_toc,
117                                     _("*** No Lists ***").c_str());
118                 setEnabled(dialog_->browser_toc, false);
119                 return;
120         }
121
122         unsigned int const topline =
123                 fl_get_browser_topline(dialog_->browser_toc);
124         unsigned int const line = fl_get_browser(dialog_->browser_toc);
125
126         fl_clear_browser(dialog_->browser_toc);
127         setEnabled(dialog_->browser_toc, true);
128
129         lyx::toc::Toc::const_iterator cit = contents.begin();
130         lyx::toc::Toc::const_iterator end = contents.end();
131         for (; cit != end; ++cit) {
132                 fl_add_browser_line(dialog_->browser_toc,
133                                     cit->asString().c_str());
134         }
135
136         fl_set_browser_topline(dialog_->browser_toc, topline);
137         fl_select_browser_line(dialog_->browser_toc, line);
138 }