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
18 #pragma implementation
22 #include "ControlToc.h"
25 #include "helper_funcs.h" // getStringFromVector
26 #include "support/lstrings.h" // frontStrip, strip
31 typedef FormCB<ControlToc, FormDB<FD_form_toc> > base_class;
33 FormToc::FormToc(ControlToc & c)
34 : base_class(c, _("Table of Contents"))
40 dialog_.reset(build_toc());
43 " " + getStringFromVector(controller().getTypes(), " | ") + " ";
44 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
46 // Manage the cancel/close button
47 bc().setCancel(dialog_->button_cancel);
51 void FormToc::update()
58 ButtonPolicy::SMInput FormToc::input(FL_OBJECT *, long)
62 unsigned int const choice = fl_get_browser( dialog_->browser_toc );
64 if (choice - 1 < toclist_.size() && choice >= 1) {
65 controller().Goto(toclist_[choice - 1].par->id());
68 return ButtonPolicy::SMI_VALID;
72 void FormToc::updateType()
74 // Update the choice list from scratch
75 fl_clear_choice(dialog_->choice_toc_type);
77 " " + getStringFromVector(controller().getTypes(), " | ") + " ";
78 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
80 // And select the correct one
81 string const type = toc::getType(controller().params().getCmdName());
83 fl_set_choice(dialog_->choice_toc_type, 1);
85 i <= fl_get_choice_maxitems(dialog_->choice_toc_type); ++i) {
87 fl_get_choice_item_text(dialog_->choice_toc_type, i);
90 fl_set_choice(dialog_->choice_toc_type, i);
97 void FormToc::updateContents()
100 frontStrip(strip(fl_get_choice_text(dialog_->choice_toc_type)));
102 Buffer::SingleList const contents = controller().getContents(type);
104 if (contents.empty()) {
105 fl_clear_browser(dialog_->browser_toc);
106 fl_add_browser_line(dialog_->browser_toc,
107 _("*** No Lists ***"));
110 // Check if all elements are the same.
111 if (toclist_ == contents) {
115 // List has changed. Update browser
118 unsigned int const topline =
119 fl_get_browser_topline(dialog_->browser_toc);
120 unsigned int const line = fl_get_browser(dialog_->browser_toc);
122 fl_clear_browser( dialog_->browser_toc );
124 Buffer::SingleList::const_iterator cit = toclist_.begin();
125 Buffer::SingleList::const_iterator end = toclist_.end();
127 for (; cit != end; ++cit) {
128 string const line = string(4 * cit->depth, ' ') + cit->str;
129 fl_add_browser_line(dialog_->browser_toc, line.c_str());
132 fl_set_browser_topline(dialog_->browser_toc, topline);
133 fl_select_browser_line(dialog_->browser_toc, line);