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
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);
50 void FormToc::update()
57 ButtonPolicy::SMInput FormToc::input(FL_OBJECT *, long)
61 unsigned int const choice = fl_get_browser( dialog_->browser_toc );
62 if (0 < choice && choice - 1 < toclist_.size()) {
63 controller().Goto(toclist_[choice-1].par->id());
66 return ButtonPolicy::SMI_VALID;
70 void FormToc::updateType()
72 string const type = toc::getType(controller().params().getCmdName());
74 fl_set_choice(dialog_->choice_toc_type, 1);
76 i <= fl_get_choice_maxitems(dialog_->choice_toc_type); ++i) {
78 fl_get_choice_item_text(dialog_->choice_toc_type, i);
81 fl_set_choice(dialog_->choice_toc_type, i);
88 void FormToc::updateContents()
91 frontStrip(strip(fl_get_choice_text(dialog_->choice_toc_type)));
93 Buffer::SingleList const contents = controller().getContents(type);
95 // Check if all elements are the same.
96 if (toclist_ == contents) {
100 // List has changed. Update browser
103 unsigned int const topline =
104 fl_get_browser_topline(dialog_->browser_toc);
105 unsigned int const line = fl_get_browser(dialog_->browser_toc);
107 fl_clear_browser( dialog_->browser_toc );
109 Buffer::SingleList::const_iterator cit = toclist_.begin();
110 Buffer::SingleList::const_iterator end = toclist_.end();
112 for (; cit != end; ++cit) {
113 string const line = string(4 * cit->depth, ' ') + cit->str;
114 fl_add_browser_line(dialog_->browser_toc, line.c_str());
117 fl_set_browser_topline(dialog_->browser_toc, topline);
118 fl_select_browser_line(dialog_->browser_toc, line);