2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000 The LyX Team.
9 * ======================================================
15 #include FORMS_H_LOCATION
18 #pragma implementation
28 #include "support/lstrings.h"
30 // The current code uses the apply() for handling the Update button and the
31 // type-of-table selection and cancel() for the close button. This is a little
32 // confusing to the button controller so I've made an IgnorantPolicy to cover
33 // this situation since the dialog doesn't care about buttons. ARRae 20001013
34 FormToc::FormToc(LyXView * lv, Dialogs * d)
35 : FormCommand(lv, d, _("Table of Contents"), new OkCancelPolicy),
38 // let the dialog be shown
39 // These are permanent connections so we won't bother
40 // storing a copy because we won't be disconnecting.
41 d->showTOC.connect(slot(this, &FormToc::showInset));
42 d->createTOC.connect(slot(this, &FormToc::createInset));
52 FL_FORM * FormToc::form() const
54 if (dialog_ ) return dialog_->form;
59 void FormToc::disconnect()
62 FormCommand::disconnect();
68 dialog_ = build_toc();
71 fl_addto_choice(dialog_->choice_toc_type,
72 _(" TOC | LOF | LOT | LOA "));
74 map<string, vector<Buffer::TocItem> > tmp =
75 lv_->view()->buffer()->getTocList();
77 map<string, vector<Buffer::TocItem> >::const_iterator cit = tmp.begin();
78 map<string, vector<Buffer::TocItem> >::const_iterator end = tmp.end();
79 for (; cit != end; ++cit) {
80 fl_addto_choice(dialog_->choice_toc_type, cit->first.c_str());
83 // Don't need to limit size of this dialog
84 // (but fixing min size is a GOOD thing).
85 // Workaround dumb xforms sizing bug
89 // Manage the cancel/close button
90 bc_.setCancel(dialog_->button_cancel);
95 void FormToc::update()
100 if (params.getCmdName() == "tableofcontents" )
101 type = Buffer::TOC_TOC;
103 else if (params.getCmdName() == "listofalgorithms" )
104 type = Buffer::TOC_LOA;
106 else if (params.getCmdName() == "listoffigures" )
107 type = Buffer::TOC_LOF;
110 type = Buffer::TOC_LOT;
112 fl_set_choice( dialog_->choice_toc_type, type+1 );
114 #warning Reimplement (Lgb)
120 void FormToc::updateToc()
123 if (!lv_->view()->available()) {
125 fl_clear_browser( dialog_->browser_toc );
126 fl_add_browser_line( dialog_->browser_toc,
127 _("*** No Document ***"));
131 vector<vector<Buffer::TocItem> > tmp =
132 lv_->view()->buffer()->getTocList();
133 int type = fl_get_choice( dialog_->choice_toc_type ) - 1;
135 // Check if all elements are the same.
136 if (toclist.size() == tmp[type].size()) {
138 for (; i < toclist.size(); ++i) {
139 if (toclist[i] != tmp[type][i])
142 if (i >= toclist.size()) return;
145 // List has changed. Update browser
148 static Buffer * buffer = 0;
151 if (buffer == lv_->view()->buffer()) {
152 topline = fl_get_browser_topline( dialog_->browser_toc );
153 line = fl_get_browser( dialog_->browser_toc );
155 buffer = lv_->view()->buffer();
157 fl_clear_browser( dialog_->browser_toc );
159 for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
160 it != toclist.end(); ++it)
161 fl_add_browser_line( dialog_->browser_toc,
162 (string(4 * (*it).depth, ' ')
163 + (*it).str).c_str());
165 fl_set_browser_topline( dialog_->browser_toc, topline );
166 fl_select_browser_line( dialog_->browser_toc, line );
168 #warning Fix Me! (Lgb)
169 if (!lv_->view()->available()) {
171 fl_clear_browser( dialog_->browser_toc );
172 fl_add_browser_line( dialog_->browser_toc,
173 _("*** No Document ***"));
177 map<string, vector<Buffer::TocItem> > tmp =
178 lv_->view()->buffer()->getTocList();
179 //int type = fl_get_choice( dialog_->choice_toc_type ) - 1;
180 string type = fl_get_choice_item_text(dialog_->choice_toc_type,
181 fl_get_choice(dialog_->choice_toc_type));
183 map<string, vector<Buffer::TocItem> >::iterator it = tmp.find(type);
185 if (it != tmp.end()) {
186 // Check if all elements are the same.
187 if (toclist == it->second) {
190 } else if (it == tmp.end()) {
192 fl_clear_browser(dialog_->browser_toc);
193 fl_add_browser_line(dialog_->browser_toc,
194 _("*** No Lists ***"));
198 // List has changed. Update browser
199 toclist = it->second;
201 static Buffer * buffer = 0;
204 if (buffer == lv_->view()->buffer()) {
205 topline = fl_get_browser_topline(dialog_->browser_toc);
206 line = fl_get_browser( dialog_->browser_toc );
208 buffer = lv_->view()->buffer();
210 fl_clear_browser(dialog_->browser_toc);
212 vector<Buffer::TocItem>::const_iterator cit = toclist.begin();
213 vector<Buffer::TocItem>::const_iterator end = toclist.end();
215 for (; cit != end; ++cit) {
216 string const line = string(4 * cit->depth, ' ') + cit->str;
217 fl_add_browser_line(dialog_->browser_toc, line.c_str());
220 fl_set_browser_topline(dialog_->browser_toc, topline);
221 fl_select_browser_line(dialog_->browser_toc, line);
226 bool FormToc::input(FL_OBJECT *, long)
230 unsigned int const choice = fl_get_browser( dialog_->browser_toc );
231 if (0 < choice && choice - 1 < toclist.size()) {
232 string const tmp = tostr(toclist[choice-1].par->id());
233 lv_->getLyXFunc()->Dispatch(LFUN_GOTO_PARAGRAPH, tmp);