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);
49 void FormToc::update()
56 ButtonPolicy::SMInput FormToc::input(FL_OBJECT *, long)
60 unsigned int const choice = fl_get_browser( dialog_->browser_toc );
61 if (0 < choice && choice - 1 < toclist_.size()) {
62 controller().Goto(toclist_[choice-1].par->id());
65 return ButtonPolicy::SMI_VALID;
69 void FormToc::updateType()
71 string const type = toc::getType(controller().params().getCmdName());
73 fl_set_choice(dialog_->choice_toc_type, 1);
75 i <= fl_get_choice_maxitems(dialog_->choice_toc_type); ++i) {
77 fl_get_choice_item_text(dialog_->choice_toc_type, i);
80 fl_set_choice(dialog_->choice_toc_type, i);
87 void FormToc::updateContents()
90 frontStrip(strip(fl_get_choice_text(dialog_->choice_toc_type)));
92 Buffer::SingleList const contents = controller().getContents(type);
94 // Check if all elements are the same.
95 if (toclist_ == contents) {
99 // List has changed. Update browser
102 unsigned int const topline =
103 fl_get_browser_topline(dialog_->browser_toc);
104 unsigned int const line = fl_get_browser(dialog_->browser_toc);
106 fl_clear_browser( dialog_->browser_toc );
108 Buffer::SingleList::const_iterator cit = toclist_.begin();
109 Buffer::SingleList::const_iterator end = toclist_.end();
111 for (; cit != end; ++cit) {
112 string const line = string(4 * cit->depth, ' ') + cit->str;
113 fl_add_browser_line(dialog_->browser_toc, line.c_str());
116 fl_set_browser_topline(dialog_->browser_toc, topline);
117 fl_select_browser_line(dialog_->browser_toc, line);