2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000-2001 The LyX Team.
9 * ======================================================
12 * \author Angus Leeming, a.leeming@ic.ac.uk
19 #pragma implementation
23 #include "ControlToc.h"
26 #include "helper_funcs.h" // getStringFromVector
27 #include "support/lstrings.h" // frontStrip, strip
32 typedef FormCB<ControlToc, FormDB<FD_form_toc> > base_class;
34 FormToc::FormToc(ControlToc & c)
35 : base_class(c, _("Table of Contents"))
41 dialog_.reset(build_toc());
44 " " + getStringFromVector(controller().getTypes(), " | ") + " ";
45 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
47 // Manage the cancel/close button
48 bc().setCancel(dialog_->button_cancel);
52 void FormToc::update()
59 ButtonPolicy::SMInput FormToc::input(FL_OBJECT *, long)
63 unsigned int const choice = fl_get_browser( dialog_->browser_toc );
65 if (choice - 1 < toclist_.size() && choice >= 1) {
66 controller().Goto(toclist_[choice - 1].par->id());
69 return ButtonPolicy::SMI_VALID;
73 void FormToc::updateType()
75 string const type = toc::getType(controller().params().getCmdName());
77 fl_set_choice(dialog_->choice_toc_type, 1);
79 i <= fl_get_choice_maxitems(dialog_->choice_toc_type); ++i) {
81 fl_get_choice_item_text(dialog_->choice_toc_type, i);
84 fl_set_choice(dialog_->choice_toc_type, i);
91 void FormToc::updateContents()
94 frontStrip(strip(fl_get_choice_text(dialog_->choice_toc_type)));
96 Buffer::SingleList const contents = controller().getContents(type);
98 if (contents.empty()) {
99 fl_clear_browser(dialog_->browser_toc);
100 fl_add_browser_line(dialog_->browser_toc,
101 _("*** No Lists ***"));
104 // Check if all elements are the same.
105 if (toclist_ == contents) {
109 // List has changed. Update browser
112 unsigned int const topline =
113 fl_get_browser_topline(dialog_->browser_toc);
114 unsigned int const line = fl_get_browser(dialog_->browser_toc);
116 fl_clear_browser( dialog_->browser_toc );
118 Buffer::SingleList::const_iterator cit = toclist_.begin();
119 Buffer::SingleList::const_iterator end = toclist_.end();
121 for (; cit != end; ++cit) {
122 string const line = string(4 * cit->depth, ' ') + cit->str;
123 fl_add_browser_line(dialog_->browser_toc, line.c_str());
126 fl_set_browser_topline(dialog_->browser_toc, topline);
127 fl_select_browser_line(dialog_->browser_toc, line);