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"
19 #include "helper_funcs.h" // getStringFromVector
20 #include "support/lstrings.h" // frontStrip, strip
29 typedef FormCB<ControlToc, FormDB<FD_form_toc> > base_class;
31 FormToc::FormToc(ControlToc & c)
32 : base_class(c, _("Table of Contents"))
38 dialog_.reset(build_toc());
41 " " + getStringFromVector(controller().getTypes(), " | ") + " ";
42 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
44 // Manage the cancel/close button
45 bc().setCancel(dialog_->button_cancel);
49 void FormToc::update()
56 ButtonPolicy::SMInput FormToc::input(FL_OBJECT * ob, long)
58 if (ob == dialog_->browser_toc) {
59 unsigned int const choice = fl_get_browser(dialog_->browser_toc);
61 if (choice - 1 < toclist_.size() && choice >= 1) {
62 controller().Goto(toclist_[choice - 1].par->id());
64 return ButtonPolicy::SMI_VALID;
67 if (ob != dialog_->choice_toc_type) {
73 return ButtonPolicy::SMI_VALID;
77 void FormToc::updateType()
79 // Update the choice list from scratch
80 fl_clear_choice(dialog_->choice_toc_type);
81 string const choice = getStringFromVector(controller().getTypes(), "|");
82 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
84 // And select the correct one
85 string const type = toc::getType(controller().params().getCmdName());
87 fl_set_choice(dialog_->choice_toc_type, 1);
89 i <= fl_get_choice_maxitems(dialog_->choice_toc_type); ++i) {
91 fl_get_choice_item_text(dialog_->choice_toc_type, i);
94 fl_set_choice(dialog_->choice_toc_type, i);
101 void FormToc::updateContents()
103 char const * tmp = fl_get_choice_text(dialog_->choice_toc_type);
106 fl_clear_browser(dialog_->browser_toc);
107 fl_add_browser_line(dialog_->browser_toc,
108 _("*** No Lists ***"));
112 string const type = frontStrip(strip(tmp));
114 Buffer::SingleList const contents = controller().getContents(type);
116 if (contents.empty()) {
117 fl_clear_browser(dialog_->browser_toc);
118 fl_add_browser_line(dialog_->browser_toc,
119 _("*** No Lists ***"));
122 // Check if all elements are the same.
123 if (toclist_ == contents) {
127 // List has changed. Update browser
130 unsigned int const topline =
131 fl_get_browser_topline(dialog_->browser_toc);
132 unsigned int const line = fl_get_browser(dialog_->browser_toc);
134 fl_clear_browser(dialog_->browser_toc);
136 Buffer::SingleList::const_iterator cit = toclist_.begin();
137 Buffer::SingleList::const_iterator end = toclist_.end();
139 for (; cit != end; ++cit) {
140 string const line = string(4 * cit->depth, ' ') + cit->str;
141 fl_add_browser_line(dialog_->browser_toc, line.c_str());
144 fl_set_browser_topline(dialog_->browser_toc, topline);
145 fl_select_browser_line(dialog_->browser_toc, line);