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"
26 using namespace lyx::support;
32 typedef FormController<ControlToc, FormView<FD_toc> > base_class;
34 FormToc::FormToc(Dialog & parent)
35 : base_class(parent, _("Table of Contents"))
41 dialog_.reset(build_toc(this));
43 vector<string> types = controller().getTypes();
47 ' ' + getStringFromVector(controller().getTypes(), " | ") + ' ';
48 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
50 // Manage the cancel/close button
51 bcview().setCancel(dialog_->button_close);
55 void FormToc::update()
62 ButtonPolicy::SMInput FormToc::input(FL_OBJECT * ob, long)
64 if (ob == dialog_->browser_toc) {
65 unsigned int const choice = fl_get_browser(dialog_->browser_toc);
67 if (choice - 1 < toc_.size() && choice >= 1) {
68 controller().goTo(toc_[choice - 1]);
70 return ButtonPolicy::SMI_VALID;
73 if (ob != dialog_->choice_toc_type) {
79 return ButtonPolicy::SMI_VALID;
83 void FormToc::updateType()
85 // Update the choice list from scratch
86 fl_clear_choice(dialog_->choice_toc_type);
87 string const choice = getStringFromVector(controller().getTypes(), "|");
88 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
90 // And select the correct one
91 string const type = lyx::toc::getType(controller().params().getCmdName());
92 fl_set_choice_text(dialog_->choice_toc_type, type.c_str());
96 void FormToc::updateContents()
98 string const type = getString(dialog_->choice_toc_type);
100 fl_clear_browser(dialog_->browser_toc);
101 fl_add_browser_line(dialog_->browser_toc,
102 _("*** No Lists ***").c_str());
103 setEnabled(dialog_->browser_toc, false);
107 lyx::toc::Toc const contents = controller().getContents(type);
109 // Check if all elements are the same.
110 if (toc_ == contents) {
114 // List has changed. Update browser
117 if (contents.empty()) {
118 fl_clear_browser(dialog_->browser_toc);
119 fl_add_browser_line(dialog_->browser_toc,
120 _("*** No Lists ***").c_str());
121 setEnabled(dialog_->browser_toc, false);
125 unsigned int const topline =
126 fl_get_browser_topline(dialog_->browser_toc);
127 unsigned int const line = fl_get_browser(dialog_->browser_toc);
129 fl_clear_browser(dialog_->browser_toc);
130 setEnabled(dialog_->browser_toc, true);
132 lyx::toc::Toc::const_iterator cit = contents.begin();
133 lyx::toc::Toc::const_iterator end = contents.end();
134 for (; cit != end; ++cit) {
135 fl_add_browser_line(dialog_->browser_toc,
136 cit->asString().c_str());
139 fl_set_browser_topline(dialog_->browser_toc, topline);
140 fl_select_browser_line(dialog_->browser_toc, line);