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 "ControlToc.h"
18 #include "forms/form_toc.h"
19 #include "helper_funcs.h" // getStringFromVector
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));
42 " " + getStringFromVector(controller().getTypes(), " | ") + " ";
43 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
45 // Manage the cancel/close button
46 bc().setCancel(dialog_->button_close);
50 void FormToc::update()
57 ButtonPolicy::SMInput FormToc::input(FL_OBJECT * ob, long)
59 if (ob == dialog_->browser_toc) {
60 unsigned int const choice = fl_get_browser(dialog_->browser_toc);
62 if (choice - 1 < toclist_.size() && choice >= 1) {
63 controller().Goto(toclist_[choice - 1].par->id());
65 return ButtonPolicy::SMI_VALID;
68 if (ob != dialog_->choice_toc_type) {
74 return ButtonPolicy::SMI_VALID;
78 void FormToc::updateType()
80 // Update the choice list from scratch
81 fl_clear_choice(dialog_->choice_toc_type);
82 string const choice = getStringFromVector(controller().getTypes(), "|");
83 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
85 // And select the correct one
86 string const type = toc::getType(controller().params().getCmdName());
88 fl_set_choice(dialog_->choice_toc_type, 1);
90 i <= fl_get_choice_maxitems(dialog_->choice_toc_type); ++i) {
92 fl_get_choice_item_text(dialog_->choice_toc_type, i);
95 fl_set_choice(dialog_->choice_toc_type, i);
102 void FormToc::updateContents()
104 char const * tmp = fl_get_choice_text(dialog_->choice_toc_type);
107 fl_clear_browser(dialog_->browser_toc);
108 fl_add_browser_line(dialog_->browser_toc,
109 _("*** No Lists ***"));
113 string const type = frontStrip(strip(tmp));
115 Buffer::SingleList const contents = controller().getContents(type);
117 if (contents.empty()) {
118 fl_clear_browser(dialog_->browser_toc);
119 fl_add_browser_line(dialog_->browser_toc,
120 _("*** No Lists ***"));
123 // Check if all elements are the same.
124 if (toclist_ == contents) {
128 // List has changed. Update browser
131 unsigned int const topline =
132 fl_get_browser_topline(dialog_->browser_toc);
133 unsigned int const line = fl_get_browser(dialog_->browser_toc);
135 fl_clear_browser(dialog_->browser_toc);
137 Buffer::SingleList::const_iterator cit = toclist_.begin();
138 Buffer::SingleList::const_iterator end = toclist_.end();
140 for (; cit != end; ++cit) {
141 string const line = string(4 * cit->depth, ' ') + cit->str;
142 fl_add_browser_line(dialog_->browser_toc, line.c_str());
145 fl_set_browser_topline(dialog_->browser_toc, topline);
146 fl_select_browser_line(dialog_->browser_toc, line);