2 * \file xforms/FormToc.C
3 * See the file COPYING.
5 * \author Angus Leeming
7 * Full author contact details are available in file CREDITS
13 #pragma implementation
18 #include "xforms_helpers.h"
19 #include "ControlToc.h"
20 #include "forms/form_toc.h"
21 #include "support/lstrings.h" // frontStrip, strip
24 #include FORMS_H_LOCATION
32 typedef FormCB<ControlToc, FormDB<FD_toc> > base_class;
35 : base_class(_("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 bc().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 = 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 ***"));
103 setEnabled(dialog_->browser_toc, false);
107 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 ***"));
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 toc::Toc::const_iterator cit = contents.begin();
133 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);