1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000-2001 The LyX Team.
8 * ======================================================
11 * \author Angus Leeming, a.leeming@ic.ac.uk
17 #pragma implementation
22 #include "ControlToc.h"
24 #include "helper_funcs.h" // getStringFromVector
25 #include "support/lstrings.h" // frontStrip, strip
34 typedef FormCB<ControlToc, FormDB<FD_form_toc> > base_class;
36 FormToc::FormToc(ControlToc & c)
37 : base_class(c, _("Table of Contents"))
43 dialog_.reset(build_toc());
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_cancel);
54 void FormToc::update()
61 ButtonPolicy::SMInput FormToc::input(FL_OBJECT * ob, long)
63 if (ob != dialog_->choice_toc_type) {
69 unsigned int const choice = fl_get_browser( dialog_->browser_toc );
71 if (choice - 1 < toclist_.size() && choice >= 1) {
72 controller().Goto(toclist_[choice - 1].par->id());
75 return ButtonPolicy::SMI_VALID;
79 void FormToc::updateType()
81 // Update the choice list from scratch
82 fl_clear_choice(dialog_->choice_toc_type);
83 string const choice = getStringFromVector(controller().getTypes(), "|");
84 lyxerr << "choice " << choice << endl;
85 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
87 // And select the correct one
88 string const type = toc::getType(controller().params().getCmdName());
90 fl_set_choice(dialog_->choice_toc_type, 1);
92 i <= fl_get_choice_maxitems(dialog_->choice_toc_type); ++i) {
94 fl_get_choice_item_text(dialog_->choice_toc_type, i);
97 fl_set_choice(dialog_->choice_toc_type, i);
104 void FormToc::updateContents()
106 char const * tmp = fl_get_choice_text(dialog_->choice_toc_type);
109 fl_clear_browser(dialog_->browser_toc);
110 fl_add_browser_line(dialog_->browser_toc,
111 _("*** No Lists ***"));
115 string const type = frontStrip(strip(tmp));
117 Buffer::SingleList const contents = controller().getContents(type);
119 if (contents.empty()) {
120 fl_clear_browser(dialog_->browser_toc);
121 fl_add_browser_line(dialog_->browser_toc,
122 _("*** No Lists ***"));
125 // Check if all elements are the same.
126 if (toclist_ == contents) {
130 // List has changed. Update browser
133 unsigned int const topline =
134 fl_get_browser_topline(dialog_->browser_toc);
135 unsigned int const line = fl_get_browser(dialog_->browser_toc);
137 fl_clear_browser( dialog_->browser_toc );
139 Buffer::SingleList::const_iterator cit = toclist_.begin();
140 Buffer::SingleList::const_iterator end = toclist_.end();
142 for (; cit != end; ++cit) {
143 string const line = string(4 * cit->depth, ' ') + cit->str;
144 fl_add_browser_line(dialog_->browser_toc, line.c_str());
147 fl_set_browser_topline(dialog_->browser_toc, topline);
148 fl_select_browser_line(dialog_->browser_toc, line);