2 * \file xforms/FormToc.C
3 * Copyright 2000-2001 The LyX Team.
4 * See the file COPYING.
6 * \author Angus Leeming <leeming@lyx.org>
12 #pragma implementation
17 #include "xforms_helpers.h"
18 #include "ControlToc.h"
19 #include "forms/form_toc.h"
20 #include "support/lstrings.h" // frontStrip, strip
23 #include FORMS_H_LOCATION
31 typedef FormCB<ControlToc, FormDB<FD_toc> > base_class;
34 : base_class(_("Table of Contents"))
40 dialog_.reset(build_toc(this));
42 vector<string> types = controller().getTypes();
46 " " + getStringFromVector(controller().getTypes(), " | ") + " ";
47 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
49 // Manage the cancel/close button
50 bc().setCancel(dialog_->button_close);
54 void FormToc::update()
61 ButtonPolicy::SMInput FormToc::input(FL_OBJECT * ob, long)
63 if (ob == dialog_->browser_toc) {
64 unsigned int const choice = fl_get_browser(dialog_->browser_toc);
66 if (choice - 1 < toc_.size() && choice >= 1) {
67 controller().goTo(toc_[choice - 1]);
69 return ButtonPolicy::SMI_VALID;
72 if (ob != dialog_->choice_toc_type) {
78 return ButtonPolicy::SMI_VALID;
82 void FormToc::updateType()
84 // Update the choice list from scratch
85 fl_clear_choice(dialog_->choice_toc_type);
86 string const choice = getStringFromVector(controller().getTypes(), "|");
87 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
89 // And select the correct one
90 string const type = toc::getType(controller().params().getCmdName());
91 fl_set_choice_text(dialog_->choice_toc_type, type.c_str());
95 void FormToc::updateContents()
97 string const type = getString(dialog_->choice_toc_type);
99 fl_clear_browser(dialog_->browser_toc);
100 fl_add_browser_line(dialog_->browser_toc,
101 _("*** No Lists ***"));
102 setEnabled(dialog_->browser_toc, false);
106 toc::Toc const contents = controller().getContents(type);
108 // Check if all elements are the same.
109 if (toc_ == contents) {
113 // List has changed. Update browser
116 if (contents.empty()) {
117 fl_clear_browser(dialog_->browser_toc);
118 fl_add_browser_line(dialog_->browser_toc,
119 _("*** No Lists ***"));
120 setEnabled(dialog_->browser_toc, false);
124 unsigned int const topline =
125 fl_get_browser_topline(dialog_->browser_toc);
126 unsigned int const line = fl_get_browser(dialog_->browser_toc);
128 fl_clear_browser(dialog_->browser_toc);
129 setEnabled(dialog_->browser_toc, true);
131 toc::Toc::const_iterator cit = contents.begin();
132 toc::Toc::const_iterator end = contents.end();
133 for (; cit != end; ++cit) {
134 fl_add_browser_line(dialog_->browser_toc,
135 cit->asString().c_str());
138 fl_set_browser_topline(dialog_->browser_toc, topline);
139 fl_select_browser_line(dialog_->browser_toc, line);