3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
14 #include "ControlToc.h"
15 #include "forms/form_toc.h"
17 #include "xforms_helpers.h"
20 #include "support/lstrings.h" // frontStrip, strip
22 #include "lyx_forms.h"
29 using support::getStringFromVector;
33 typedef FormController<ControlToc, FormView<FD_toc> > base_class;
35 FormToc::FormToc(Dialog & parent)
36 : base_class(parent, _("Table of Contents"))
42 dialog_.reset(build_toc(this));
44 vector<string> types = controller().getTypes();
48 ' ' + getStringFromVector(controller().getTypes(), " | ") + ' ';
49 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
51 // Manage the cancel/close button
52 bcview().setCancel(dialog_->button_close);
56 void FormToc::update()
63 ButtonPolicy::SMInput FormToc::input(FL_OBJECT * ob, long)
65 if (ob == dialog_->browser_toc) {
66 unsigned int const choice = fl_get_browser(dialog_->browser_toc);
68 if (choice - 1 < toc_.size() && choice >= 1) {
69 controller().goTo(toc_[choice - 1]);
71 return ButtonPolicy::SMI_VALID;
74 if (ob != dialog_->choice_toc_type) {
80 return ButtonPolicy::SMI_VALID;
84 void FormToc::updateType()
86 // Update the choice list from scratch
87 fl_clear_choice(dialog_->choice_toc_type);
88 string const choice = getStringFromVector(controller().getTypes(), "|");
89 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
91 // And select the correct one
92 string const type = toc::getType(controller().params().getCmdName());
93 fl_set_choice_text(dialog_->choice_toc_type, type.c_str());
97 void FormToc::updateContents()
99 string const type = getString(dialog_->choice_toc_type);
101 fl_clear_browser(dialog_->browser_toc);
102 fl_add_browser_line(dialog_->browser_toc,
103 _("*** No Lists ***").c_str());
104 setEnabled(dialog_->browser_toc, false);
108 toc::Toc const contents = controller().getContents(type);
110 // Check if all elements are the same.
111 if (toc_ == contents) {
115 // List has changed. Update browser
118 if (contents.empty()) {
119 fl_clear_browser(dialog_->browser_toc);
120 fl_add_browser_line(dialog_->browser_toc,
121 _("*** No Lists ***").c_str());
122 setEnabled(dialog_->browser_toc, false);
126 unsigned int const topline =
127 fl_get_browser_topline(dialog_->browser_toc);
128 unsigned int const line = fl_get_browser(dialog_->browser_toc);
130 fl_clear_browser(dialog_->browser_toc);
131 setEnabled(dialog_->browser_toc, true);
133 toc::Toc::const_iterator cit = contents.begin();
134 toc::Toc::const_iterator end = contents.end();
135 for (; cit != end; ++cit) {
136 fl_add_browser_line(dialog_->browser_toc,
137 cit->asString().c_str());
140 fl_set_browser_topline(dialog_->browser_toc, topline);
141 fl_select_browser_line(dialog_->browser_toc, line);
144 } // namespace frontend