2002-03-11 17:00:41 +00:00
|
|
|
/**
|
2002-03-11 22:47:41 +00:00
|
|
|
* \file xforms/FormToc.C
|
2002-03-11 17:00:41 +00:00
|
|
|
* Copyright 2000-2001 The LyX Team.
|
|
|
|
* See the file COPYING.
|
|
|
|
*
|
2001-03-30 19:24:28 +00:00
|
|
|
* \author Angus Leeming, a.leeming@ic.ac.uk
|
2000-08-01 17:33:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-12-15 16:24:12 +00:00
|
|
|
#include "FormToc.h"
|
2001-03-30 19:24:28 +00:00
|
|
|
#include "xformsBC.h"
|
|
|
|
#include "ControlToc.h"
|
2000-08-01 17:33:32 +00:00
|
|
|
#include "form_toc.h"
|
2001-03-30 19:24:28 +00:00
|
|
|
#include "helper_funcs.h" // getStringFromVector
|
|
|
|
#include "support/lstrings.h" // frontStrip, strip
|
2001-06-11 17:20:17 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "gettext.h"
|
2000-08-01 17:33:32 +00:00
|
|
|
|
2001-12-15 16:24:12 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using std::endl;
|
|
|
|
|
2000-10-03 05:53:25 +00:00
|
|
|
|
2001-03-30 19:24:28 +00:00
|
|
|
typedef FormCB<ControlToc, FormDB<FD_form_toc> > base_class;
|
2000-10-03 05:53:25 +00:00
|
|
|
|
2001-03-30 19:24:28 +00:00
|
|
|
FormToc::FormToc(ControlToc & c)
|
|
|
|
: base_class(c, _("Table of Contents"))
|
|
|
|
{}
|
2000-08-03 12:56:25 +00:00
|
|
|
|
|
|
|
|
2000-08-01 17:33:32 +00:00
|
|
|
void FormToc::build()
|
|
|
|
{
|
2001-03-15 13:37:04 +00:00
|
|
|
dialog_.reset(build_toc());
|
2000-10-20 09:50:09 +00:00
|
|
|
|
2001-03-30 19:24:28 +00:00
|
|
|
string const choice =
|
|
|
|
" " + getStringFromVector(controller().getTypes(), " | ") + " ";
|
|
|
|
fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
|
2000-11-28 06:46:06 +00:00
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
// Manage the cancel/close button
|
2002-03-12 14:11:15 +00:00
|
|
|
bc().setCancel(dialog_->button_close);
|
2000-08-01 17:33:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-24 13:13:59 +00:00
|
|
|
void FormToc::update()
|
2000-08-01 17:33:32 +00:00
|
|
|
{
|
2001-03-30 19:24:28 +00:00
|
|
|
updateType();
|
|
|
|
updateContents();
|
|
|
|
}
|
2000-08-01 17:33:32 +00:00
|
|
|
|
|
|
|
|
2001-12-14 09:16:01 +00:00
|
|
|
ButtonPolicy::SMInput FormToc::input(FL_OBJECT * ob, long)
|
2001-03-30 19:24:28 +00:00
|
|
|
{
|
2002-03-11 11:17:49 +00:00
|
|
|
if (ob == dialog_->browser_toc) {
|
|
|
|
unsigned int const choice = fl_get_browser(dialog_->browser_toc);
|
|
|
|
|
|
|
|
if (choice - 1 < toclist_.size() && choice >= 1) {
|
|
|
|
controller().Goto(toclist_[choice - 1].par->id());
|
|
|
|
}
|
|
|
|
return ButtonPolicy::SMI_VALID;
|
|
|
|
}
|
|
|
|
|
2001-12-14 09:16:01 +00:00
|
|
|
if (ob != dialog_->choice_toc_type) {
|
|
|
|
updateType();
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-30 19:24:28 +00:00
|
|
|
updateContents();
|
2000-08-01 17:33:32 +00:00
|
|
|
|
2001-03-30 19:24:28 +00:00
|
|
|
return ButtonPolicy::SMI_VALID;
|
2000-08-01 17:33:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-30 19:24:28 +00:00
|
|
|
void FormToc::updateType()
|
2000-08-01 17:33:32 +00:00
|
|
|
{
|
2001-07-29 11:57:09 +00:00
|
|
|
// Update the choice list from scratch
|
|
|
|
fl_clear_choice(dialog_->choice_toc_type);
|
2001-11-27 10:56:14 +00:00
|
|
|
string const choice = getStringFromVector(controller().getTypes(), "|");
|
2001-07-29 11:57:09 +00:00
|
|
|
fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
|
|
|
|
|
|
|
|
// And select the correct one
|
2001-03-30 19:24:28 +00:00
|
|
|
string const type = toc::getType(controller().params().getCmdName());
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-30 19:24:28 +00:00
|
|
|
fl_set_choice(dialog_->choice_toc_type, 1);
|
|
|
|
for (int i = 1;
|
|
|
|
i <= fl_get_choice_maxitems(dialog_->choice_toc_type); ++i) {
|
|
|
|
string const choice =
|
|
|
|
fl_get_choice_item_text(dialog_->choice_toc_type, i);
|
|
|
|
|
|
|
|
if (choice == type) {
|
|
|
|
fl_set_choice(dialog_->choice_toc_type, i);
|
|
|
|
break;
|
2000-08-01 17:33:32 +00:00
|
|
|
}
|
|
|
|
}
|
2001-03-30 19:24:28 +00:00
|
|
|
}
|
2000-08-01 17:33:32 +00:00
|
|
|
|
2001-03-11 18:39:00 +00:00
|
|
|
|
2001-03-30 19:24:28 +00:00
|
|
|
void FormToc::updateContents()
|
|
|
|
{
|
2001-12-14 09:16:01 +00:00
|
|
|
char const * tmp = fl_get_choice_text(dialog_->choice_toc_type);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-12-14 09:16:01 +00:00
|
|
|
if (!tmp) {
|
|
|
|
fl_clear_browser(dialog_->browser_toc);
|
|
|
|
fl_add_browser_line(dialog_->browser_toc,
|
|
|
|
_("*** No Lists ***"));
|
|
|
|
return;
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-12-14 09:16:01 +00:00
|
|
|
string const type = frontStrip(strip(tmp));
|
2001-03-11 18:39:00 +00:00
|
|
|
|
2001-03-30 19:24:28 +00:00
|
|
|
Buffer::SingleList const contents = controller().getContents(type);
|
2001-03-11 18:39:00 +00:00
|
|
|
|
2001-06-11 17:20:17 +00:00
|
|
|
if (contents.empty()) {
|
|
|
|
fl_clear_browser(dialog_->browser_toc);
|
|
|
|
fl_add_browser_line(dialog_->browser_toc,
|
|
|
|
_("*** No Lists ***"));
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-30 19:24:28 +00:00
|
|
|
// Check if all elements are the same.
|
|
|
|
if (toclist_ == contents) {
|
2001-03-11 18:39:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-11 18:39:00 +00:00
|
|
|
// List has changed. Update browser
|
2001-03-30 19:24:28 +00:00
|
|
|
toclist_ = contents;
|
2001-03-11 18:39:00 +00:00
|
|
|
|
2001-03-30 19:24:28 +00:00
|
|
|
unsigned int const topline =
|
|
|
|
fl_get_browser_topline(dialog_->browser_toc);
|
|
|
|
unsigned int const line = fl_get_browser(dialog_->browser_toc);
|
2001-03-11 18:39:00 +00:00
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
fl_clear_browser(dialog_->browser_toc);
|
2001-03-11 18:39:00 +00:00
|
|
|
|
2001-03-30 19:24:28 +00:00
|
|
|
Buffer::SingleList::const_iterator cit = toclist_.begin();
|
|
|
|
Buffer::SingleList::const_iterator end = toclist_.end();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-11 18:39:00 +00:00
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
string const line = string(4 * cit->depth, ' ') + cit->str;
|
|
|
|
fl_add_browser_line(dialog_->browser_toc, line.c_str());
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-11 18:39:00 +00:00
|
|
|
fl_set_browser_topline(dialog_->browser_toc, topline);
|
|
|
|
fl_select_browser_line(dialog_->browser_toc, line);
|
2000-08-01 17:33:32 +00:00
|
|
|
}
|