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
16 #include "xforms_helpers.h"
17 #include "ControlToc.h"
18 #include "forms/form_toc.h"
19 #include "support/lstrings.h" // frontStrip, strip
22 #include "lyx_forms.h"
30 typedef FormController<ControlToc, FormView<FD_toc> > base_class;
32 FormToc::FormToc(Dialog & parent)
33 : base_class(parent, _("Table of Contents"))
39 dialog_.reset(build_toc(this));
41 vector<string> types = controller().getTypes();
45 ' ' + getStringFromVector(controller().getTypes(), " | ") + ' ';
46 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
48 // Manage the cancel/close button
49 bcview().setCancel(dialog_->button_close);
53 void FormToc::update()
60 ButtonPolicy::SMInput FormToc::input(FL_OBJECT * ob, long)
62 if (ob == dialog_->browser_toc) {
63 unsigned int const choice = fl_get_browser(dialog_->browser_toc);
65 if (choice - 1 < toc_.size() && choice >= 1) {
66 controller().goTo(toc_[choice - 1]);
68 return ButtonPolicy::SMI_VALID;
71 if (ob != dialog_->choice_toc_type) {
77 return ButtonPolicy::SMI_VALID;
81 void FormToc::updateType()
83 // Update the choice list from scratch
84 fl_clear_choice(dialog_->choice_toc_type);
85 string const choice = getStringFromVector(controller().getTypes(), "|");
86 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
88 // And select the correct one
89 string const type = toc::getType(controller().params().getCmdName());
90 fl_set_choice_text(dialog_->choice_toc_type, type.c_str());
94 void FormToc::updateContents()
96 string const type = getString(dialog_->choice_toc_type);
98 fl_clear_browser(dialog_->browser_toc);
99 fl_add_browser_line(dialog_->browser_toc,
100 _("*** No Lists ***").c_str());
101 setEnabled(dialog_->browser_toc, false);
105 toc::Toc const contents = controller().getContents(type);
107 // Check if all elements are the same.
108 if (toc_ == contents) {
112 // List has changed. Update browser
115 if (contents.empty()) {
116 fl_clear_browser(dialog_->browser_toc);
117 fl_add_browser_line(dialog_->browser_toc,
118 _("*** No Lists ***").c_str());
119 setEnabled(dialog_->browser_toc, false);
123 unsigned int const topline =
124 fl_get_browser_topline(dialog_->browser_toc);
125 unsigned int const line = fl_get_browser(dialog_->browser_toc);
127 fl_clear_browser(dialog_->browser_toc);
128 setEnabled(dialog_->browser_toc, true);
130 toc::Toc::const_iterator cit = contents.begin();
131 toc::Toc::const_iterator end = contents.end();
132 for (; cit != end; ++cit) {
133 fl_add_browser_line(dialog_->browser_toc,
134 cit->asString().c_str());
137 fl_set_browser_topline(dialog_->browser_toc, topline);
138 fl_select_browser_line(dialog_->browser_toc, line);