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_->browser_toc) {
64 unsigned int const choice = fl_get_browser(dialog_->browser_toc);
66 if (choice - 1 < toclist_.size() && choice >= 1) {
67 controller().Goto(toclist_[choice - 1].par->id());
69 return ButtonPolicy::SMI_VALID;
72 if (ob != dialog_->choice_toc_type) {
78 return ButtonPolicy::SMI_VALID;
82 void FormToc::updateType()
84 // Update the choice list from scratch
85 fl_clear_choice(dialog_->choice_toc_type);
86 string const choice = getStringFromVector(controller().getTypes(), "|");
87 lyxerr << "choice " << choice << endl;
88 fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
90 // And select the correct one
91 string const type = toc::getType(controller().params().getCmdName());
93 fl_set_choice(dialog_->choice_toc_type, 1);
95 i <= fl_get_choice_maxitems(dialog_->choice_toc_type); ++i) {
97 fl_get_choice_item_text(dialog_->choice_toc_type, i);
100 fl_set_choice(dialog_->choice_toc_type, i);
107 void FormToc::updateContents()
109 char const * tmp = fl_get_choice_text(dialog_->choice_toc_type);
112 fl_clear_browser(dialog_->browser_toc);
113 fl_add_browser_line(dialog_->browser_toc,
114 _("*** No Lists ***"));
118 string const type = frontStrip(strip(tmp));
120 Buffer::SingleList const contents = controller().getContents(type);
122 if (contents.empty()) {
123 fl_clear_browser(dialog_->browser_toc);
124 fl_add_browser_line(dialog_->browser_toc,
125 _("*** No Lists ***"));
128 // Check if all elements are the same.
129 if (toclist_ == contents) {
133 // List has changed. Update browser
136 unsigned int const topline =
137 fl_get_browser_topline(dialog_->browser_toc);
138 unsigned int const line = fl_get_browser(dialog_->browser_toc);
140 fl_clear_browser(dialog_->browser_toc);
142 Buffer::SingleList::const_iterator cit = toclist_.begin();
143 Buffer::SingleList::const_iterator end = toclist_.end();
145 for (; cit != end; ++cit) {
146 string const line = string(4 * cit->depth, ' ') + cit->str;
147 fl_add_browser_line(dialog_->browser_toc, line.c_str());
150 fl_set_browser_topline(dialog_->browser_toc, topline);
151 fl_select_browser_line(dialog_->browser_toc, line);