/**
* \file FormToc.C
- * Copyright 2000-2001 The LyX Team.
- * See the file COPYING.
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * \author Angus Leeming, a.leeming@ic.ac.uk
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
#include "FormToc.h"
-#include "xformsBC.h"
#include "ControlToc.h"
-#include "form_toc.h"
-#include "helper_funcs.h" // getStringFromVector
+#include "forms/form_toc.h"
+
+#include "xforms_helpers.h"
+#include "xformsBC.h"
+
#include "support/lstrings.h" // frontStrip, strip
-#include "debug.h"
-#include "gettext.h"
-#include <vector>
+#include "lyx_forms.h"
+
+using std::vector;
+using std::string;
-using std::endl;
+namespace lyx {
+using support::getStringFromVector;
-typedef FormCB<ControlToc, FormDB<FD_form_toc> > base_class;
+namespace frontend {
-FormToc::FormToc(ControlToc & c)
- : base_class(c, _("Table of Contents"))
+typedef FormController<ControlToc, FormView<FD_toc> > base_class;
+
+FormToc::FormToc(Dialog & parent)
+ : base_class(parent, _("Table of Contents"))
{}
void FormToc::build()
{
- dialog_.reset(build_toc());
+ dialog_.reset(build_toc(this));
+
+ vector<string> types = controller().getTypes();
+
string const choice =
- " " + getStringFromVector(controller().getTypes(), " | ") + " ";
+ ' ' + getStringFromVector(controller().getTypes(), " | ") + ' ';
fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
- // Manage the cancel/close button
- bc().setCancel(dialog_->button_cancel);
+ // Manage the cancel/close button
+ bcview().setCancel(dialog_->button_close);
}
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());
+ if (choice - 1 < toc_.size() && choice >= 1) {
+ controller().goTo(toc_[choice - 1]);
}
return ButtonPolicy::SMI_VALID;
}
if (ob != dialog_->choice_toc_type) {
updateType();
}
-
+
updateContents();
return ButtonPolicy::SMI_VALID;
// And select the correct one
string const type = toc::getType(controller().params().getCmdName());
-
- 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;
- }
- }
+ fl_set_choice_text(dialog_->choice_toc_type, type.c_str());
}
void FormToc::updateContents()
{
- char const * tmp = fl_get_choice_text(dialog_->choice_toc_type);
-
- if (!tmp) {
+ string const type = getString(dialog_->choice_toc_type);
+ if (type.empty()) {
fl_clear_browser(dialog_->browser_toc);
fl_add_browser_line(dialog_->browser_toc,
- _("*** No Lists ***"));
+ _("*** No Lists ***").c_str());
+ setEnabled(dialog_->browser_toc, false);
return;
}
-
- string const type = frontStrip(strip(tmp));
- Buffer::SingleList const contents = controller().getContents(type);
+ toc::Toc const contents = controller().getContents(type);
+
+ // Check if all elements are the same.
+ if (toc_ == contents) {
+ return;
+ }
+
+ // List has changed. Update browser
+ toc_ = contents;
if (contents.empty()) {
fl_clear_browser(dialog_->browser_toc);
fl_add_browser_line(dialog_->browser_toc,
- _("*** No Lists ***"));
- }
-
- // Check if all elements are the same.
- if (toclist_ == contents) {
+ _("*** No Lists ***").c_str());
+ setEnabled(dialog_->browser_toc, false);
return;
}
-
- // List has changed. Update browser
- toclist_ = contents;
unsigned int const topline =
fl_get_browser_topline(dialog_->browser_toc);
unsigned int const line = fl_get_browser(dialog_->browser_toc);
fl_clear_browser(dialog_->browser_toc);
+ setEnabled(dialog_->browser_toc, true);
- Buffer::SingleList::const_iterator cit = toclist_.begin();
- Buffer::SingleList::const_iterator end = toclist_.end();
-
+ toc::Toc::const_iterator cit = contents.begin();
+ toc::Toc::const_iterator end = contents.end();
for (; cit != end; ++cit) {
- string const line = string(4 * cit->depth, ' ') + cit->str;
- fl_add_browser_line(dialog_->browser_toc, line.c_str());
+ fl_add_browser_line(dialog_->browser_toc,
+ cit->asString().c_str());
}
-
+
fl_set_browser_topline(dialog_->browser_toc, topline);
fl_select_browser_line(dialog_->browser_toc, line);
}
+
+} // namespace frontend
+} // namespace lyx