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"
|
2002-07-21 15:51:07 +00:00
|
|
|
#include "xforms_helpers.h"
|
2001-03-30 19:24:28 +00:00
|
|
|
#include "ControlToc.h"
|
2002-06-13 13:43:51 +00:00
|
|
|
#include "forms/form_toc.h"
|
2001-03-30 19:24:28 +00:00
|
|
|
#include "support/lstrings.h" // frontStrip, strip
|
2001-06-11 17:20:17 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "gettext.h"
|
2002-06-13 13:43:51 +00:00
|
|
|
#include FORMS_H_LOCATION
|
2000-08-01 17:33:32 +00:00
|
|
|
|
2001-12-15 16:24:12 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2002-07-21 16:59:01 +00:00
|
|
|
using std::vector;
|
2001-12-15 16:24:12 +00:00
|
|
|
using std::endl;
|
|
|
|
|
2000-10-03 05:53:25 +00:00
|
|
|
|
2002-06-13 13:43:51 +00:00
|
|
|
typedef FormCB<ControlToc, FormDB<FD_toc> > base_class;
|
2000-10-03 05:53:25 +00:00
|
|
|
|
2002-07-02 19:23:10 +00:00
|
|
|
FormToc::FormToc(ControlToc & c, Dialogs & d)
|
|
|
|
: base_class(c, d, _("Table of Contents"))
|
2001-03-30 19:24:28 +00:00
|
|
|
{}
|
2000-08-03 12:56:25 +00:00
|
|
|
|
|
|
|
|
2000-08-01 17:33:32 +00:00
|
|
|
void FormToc::build()
|
|
|
|
{
|
2002-06-13 13:43:51 +00:00
|
|
|
dialog_.reset(build_toc(this));
|
2000-10-20 09:50:09 +00:00
|
|
|
|
2002-07-21 15:51:07 +00:00
|
|
|
vector<string> types = controller().getTypes();
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2002-07-21 15:51:07 +00:00
|
|
|
if (choice - 1 < toc_.size() && choice >= 1) {
|
|
|
|
controller().goTo(toc_[choice - 1]);
|
2002-03-11 11:17:49 +00:00
|
|
|
}
|
|
|
|
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-07-21 15:51:07 +00:00
|
|
|
fl_set_choice_text(dialog_->choice_toc_type, type.c_str());
|
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()
|
|
|
|
{
|
2002-07-21 15:51:07 +00:00
|
|
|
string const type = getString(dialog_->choice_toc_type);
|
|
|
|
if (type.empty()) {
|
2001-12-14 09:16:01 +00:00
|
|
|
fl_clear_browser(dialog_->browser_toc);
|
|
|
|
fl_add_browser_line(dialog_->browser_toc,
|
|
|
|
_("*** No Lists ***"));
|
2002-07-21 15:51:07 +00:00
|
|
|
setEnabled(dialog_->browser_toc, false);
|
2001-12-14 09:16:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-07-21 15:51:07 +00:00
|
|
|
toc::Toc const contents = controller().getContents(type);
|
2001-03-11 18:39:00 +00:00
|
|
|
|
2002-07-21 15:51:07 +00:00
|
|
|
// Check if all elements are the same.
|
|
|
|
if (toc_ == contents) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// List has changed. Update browser
|
|
|
|
toc_ = contents;
|
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-07-21 15:51:07 +00:00
|
|
|
setEnabled(dialog_->browser_toc, false);
|
2001-03-11 18:39:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-03-21 21:21:28 +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);
|
2002-07-21 15:51:07 +00:00
|
|
|
setEnabled(dialog_->browser_toc, true);
|
2001-03-11 18:39:00 +00:00
|
|
|
|
2002-07-21 15:51:07 +00:00
|
|
|
toc::Toc::const_iterator cit = contents.begin();
|
|
|
|
toc::Toc::const_iterator end = contents.end();
|
2001-03-11 18:39:00 +00:00
|
|
|
for (; cit != end; ++cit) {
|
2002-07-21 15:51:07 +00:00
|
|
|
fl_add_browser_line(dialog_->browser_toc,
|
|
|
|
cit->asString().c_str());
|
2001-03-11 18:39:00 +00:00
|
|
|
}
|
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
|
|
|
}
|