2 * \file xforms/FormToc.C
3 * Copyright 2000-2001 The LyX Team.
4 * See the file COPYING.
6 * \author Angus Leeming, a.leeming@ic.ac.uk
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
30 typedef FormCB<ControlToc, FormDB<FD_toc> > base_class;
32 FormToc::FormToc(ControlToc & c, Dialogs & d)
33 : base_class(c, d, _("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 bc().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 ***"));
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 ***"));
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);