2000-08-08 15:36:25 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
2001-03-26 13:16:57 +00:00
|
|
|
* Copyright 2000-2001 The LyX Team.
|
2000-08-08 15:36:25 +00:00
|
|
|
*
|
|
|
|
* ======================================================
|
2001-03-26 13:16:57 +00:00
|
|
|
*
|
|
|
|
* \file FormRef.C
|
|
|
|
* \author Angus Leeming, a.leeming@ic.ac.uk
|
2000-08-08 15:36:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2001-03-05 19:02:40 +00:00
|
|
|
#include <algorithm>
|
2000-08-08 15:36:25 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-03-26 13:16:57 +00:00
|
|
|
#include "xformsBC.h"
|
|
|
|
#include "ControlRef.h"
|
|
|
|
#include "FormRef.h"
|
|
|
|
#include "form_ref.h"
|
|
|
|
#include "xforms_helpers.h"
|
|
|
|
#include "insets/insetref.h"
|
|
|
|
|
2000-11-29 15:06:42 +00:00
|
|
|
using std::find;
|
|
|
|
using std::max;
|
2000-08-08 15:36:25 +00:00
|
|
|
using std::sort;
|
|
|
|
using std::vector;
|
2001-02-27 12:32:01 +00:00
|
|
|
|
2001-03-26 13:16:57 +00:00
|
|
|
typedef FormCB<ControlRef, FormDB<FD_form_ref> > base_class;
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2001-03-26 13:16:57 +00:00
|
|
|
FormRef::FormRef(ControlRef & c)
|
|
|
|
: base_class(c, _("Reference")),
|
|
|
|
at_ref_(false)
|
|
|
|
{}
|
2000-08-08 15:36:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
void FormRef::build()
|
|
|
|
{
|
2001-03-15 13:37:04 +00:00
|
|
|
dialog_.reset(build_ref());
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2001-01-21 21:41:35 +00:00
|
|
|
for (int i = 0; !InsetRef::types[i].latex_name.empty(); ++i)
|
|
|
|
fl_addto_choice(dialog_->type,
|
|
|
|
_(InsetRef::types[i].gui_name.c_str()));
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-29 15:06:42 +00:00
|
|
|
// Force the user to use the browser to change refs.
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_deactivate_object(dialog_->ref);
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-28 06:46:06 +00:00
|
|
|
// Manage the ok and cancel/close buttons
|
2001-03-15 13:37:04 +00:00
|
|
|
bc().setOK(dialog_->button_ok);
|
|
|
|
bc().setApply(dialog_->button_apply);
|
|
|
|
bc().setCancel(dialog_->button_cancel);
|
2001-04-03 14:30:58 +00:00
|
|
|
bc().setRestore(dialog_->button_restore);
|
2001-08-09 15:10:24 +00:00
|
|
|
|
|
|
|
bc().addReadOnly(dialog_->button_update);
|
|
|
|
bc().addReadOnly(dialog_->name);
|
|
|
|
bc().addReadOnly(dialog_->ref);
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-24 13:13:59 +00:00
|
|
|
void FormRef::update()
|
2000-08-08 15:36:25 +00:00
|
|
|
{
|
2001-03-26 13:16:57 +00:00
|
|
|
fl_set_input(dialog_->ref,
|
|
|
|
controller().params().getContents().c_str());
|
|
|
|
fl_set_input(dialog_->name,
|
|
|
|
controller().params().getOptions().c_str());
|
|
|
|
fl_set_choice(dialog_->type,
|
|
|
|
InsetRef::getType(controller().params().getCmdName()) + 1);
|
|
|
|
|
|
|
|
at_ref_ = false;
|
2001-08-01 10:08:53 +00:00
|
|
|
fl_set_object_label(dialog_->button_go, _("Go to reference"));
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2001-03-26 13:16:57 +00:00
|
|
|
// Name is irrelevant to LaTeX/Literate documents
|
|
|
|
if (controller().docType() == ControlRef::LATEX ||
|
|
|
|
controller().docType() == ControlRef::LITERATE) {
|
2001-03-05 19:02:40 +00:00
|
|
|
setEnabled(dialog_->name, false);
|
2001-01-21 20:10:48 +00:00
|
|
|
} else {
|
2001-03-05 19:02:40 +00:00
|
|
|
setEnabled(dialog_->name, true);
|
2000-11-29 15:06:42 +00:00
|
|
|
}
|
2000-11-29 19:27:43 +00:00
|
|
|
|
2001-03-26 13:16:57 +00:00
|
|
|
// type is irrelevant to LinuxDoc/DocBook.
|
|
|
|
if (controller().docType() == ControlRef::LINUXDOC ||
|
|
|
|
controller().docType() == ControlRef::DOCBOOK) {
|
|
|
|
fl_set_choice(dialog_->type, 1);
|
|
|
|
setEnabled(dialog_->type, false);
|
|
|
|
} else {
|
|
|
|
setEnabled(dialog_->type, true);
|
|
|
|
}
|
2000-11-29 15:06:42 +00:00
|
|
|
|
2001-03-26 13:16:57 +00:00
|
|
|
refs_ = controller().getLabelList();
|
|
|
|
updateBrowser(refs_);
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
void FormRef::updateBrowser(vector<string> const & akeys) const
|
2000-08-08 15:36:25 +00:00
|
|
|
{
|
2000-11-14 02:01:57 +00:00
|
|
|
vector<string> keys(akeys);
|
2000-11-29 19:27:43 +00:00
|
|
|
if (fl_get_button(dialog_->sort))
|
2000-11-14 02:01:57 +00:00
|
|
|
sort(keys.begin(), keys.end());
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_clear_browser(dialog_->browser);
|
2000-11-04 10:00:12 +00:00
|
|
|
for (vector<string>::const_iterator it = keys.begin();
|
2000-11-14 02:01:57 +00:00
|
|
|
it != keys.end(); ++it)
|
2001-03-26 13:16:57 +00:00
|
|
|
fl_add_browser_line(dialog_->browser, it->c_str());
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
if (keys.empty()) {
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_add_browser_line(dialog_->browser,
|
|
|
|
_("*** No labels found in document ***"));
|
2001-03-05 19:02:40 +00:00
|
|
|
|
|
|
|
setEnabled(dialog_->browser, false);
|
|
|
|
setEnabled(dialog_->sort, false);
|
2000-11-14 02:01:57 +00:00
|
|
|
|
2001-01-21 21:41:35 +00:00
|
|
|
fl_set_input(dialog_->ref, "");
|
2000-08-08 15:36:25 +00:00
|
|
|
} else {
|
2001-03-05 19:02:40 +00:00
|
|
|
setEnabled(dialog_->browser, true);
|
|
|
|
setEnabled(dialog_->sort, true);
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-29 15:06:42 +00:00
|
|
|
string ref = fl_get_input(dialog_->ref);
|
|
|
|
vector<string>::const_iterator cit =
|
2000-11-29 19:27:43 +00:00
|
|
|
find(keys.begin(), keys.end(), ref);
|
2001-01-28 18:31:36 +00:00
|
|
|
if (cit == keys.end()) {
|
2001-01-21 20:10:48 +00:00
|
|
|
cit = keys.begin();
|
2001-03-26 13:16:57 +00:00
|
|
|
fl_set_input(dialog_->ref, cit->c_str());
|
2001-01-28 18:31:36 +00:00
|
|
|
} else if (ref.empty())
|
2001-03-26 13:16:57 +00:00
|
|
|
fl_set_input(dialog_->ref, cit->c_str());
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2001-01-21 20:10:48 +00:00
|
|
|
int const i = static_cast<int>(cit - keys.begin());
|
|
|
|
fl_set_browser_topline(dialog_->browser, max(i-5, 1));
|
|
|
|
fl_select_browser_line(dialog_->browser, i+1);
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormRef::apply()
|
|
|
|
{
|
2001-01-21 21:41:35 +00:00
|
|
|
int const type = fl_get_choice(dialog_->type) - 1;
|
2001-03-26 13:16:57 +00:00
|
|
|
controller().params().setCmdName(InsetRef::getName(type));
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2001-03-26 13:16:57 +00:00
|
|
|
controller().params().setOptions(fl_get_input(dialog_->name));
|
|
|
|
controller().params().setContents(fl_get_input(dialog_->ref));
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-26 13:16:57 +00:00
|
|
|
ButtonPolicy::SMInput FormRef::input(FL_OBJECT * ob, long)
|
2000-08-08 15:36:25 +00:00
|
|
|
{
|
2001-03-26 13:16:57 +00:00
|
|
|
ButtonPolicy::SMInput activate(ButtonPolicy::SMI_VALID);
|
|
|
|
|
|
|
|
if (ob == dialog_->button_go) {
|
|
|
|
// goto reference / go back
|
|
|
|
|
2000-11-29 15:06:42 +00:00
|
|
|
// No change to data
|
2001-03-26 13:16:57 +00:00
|
|
|
activate = ButtonPolicy::SMI_NOOP;
|
|
|
|
|
|
|
|
at_ref_ = !at_ref_;
|
|
|
|
if (at_ref_) {
|
|
|
|
controller().gotoRef(fl_get_input(dialog_->ref));
|
2000-10-03 05:53:25 +00:00
|
|
|
fl_set_object_label(dialog_->button_go, _("Go back"));
|
2001-02-27 12:32:01 +00:00
|
|
|
} else {
|
2001-03-26 13:16:57 +00:00
|
|
|
controller().gotoBookmark();
|
2000-10-13 05:57:05 +00:00
|
|
|
fl_set_object_label(dialog_->button_go,
|
2001-08-01 10:08:53 +00:00
|
|
|
_("Go to reference"));
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
2001-03-26 13:16:57 +00:00
|
|
|
} else if (ob == dialog_->browser) {
|
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
unsigned int sel = fl_get_browser(dialog_->browser);
|
2001-03-26 13:16:57 +00:00
|
|
|
if (sel < 1 || sel > refs_.size())
|
|
|
|
return ButtonPolicy::SMI_NOOP;
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2001-03-26 13:16:57 +00:00
|
|
|
if (!controller().isReadonly()) {
|
2000-11-29 15:06:42 +00:00
|
|
|
string s = fl_get_browser_line(dialog_->browser, sel);
|
|
|
|
fl_set_input(dialog_->ref, s.c_str());
|
|
|
|
}
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2001-03-26 13:16:57 +00:00
|
|
|
if (at_ref_)
|
|
|
|
controller().gotoBookmark();
|
|
|
|
at_ref_ = false;
|
2001-08-01 10:08:53 +00:00
|
|
|
fl_set_object_label(dialog_->button_go, _("Go to reference"));
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2001-03-05 19:02:40 +00:00
|
|
|
setEnabled(dialog_->type, true);
|
|
|
|
setEnabled(dialog_->button_go, true);
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_set_object_lcol(dialog_->ref, FL_BLACK);
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2001-03-26 13:16:57 +00:00
|
|
|
} else if (ob == dialog_->button_update ||
|
|
|
|
ob == dialog_->sort) {
|
|
|
|
|
|
|
|
if (ob == dialog_->button_update)
|
|
|
|
refs_ = controller().getLabelList();
|
2000-11-29 19:27:43 +00:00
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_freeze_form(form());
|
2001-03-26 13:16:57 +00:00
|
|
|
updateBrowser(refs_);
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_unfreeze_form(form());
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2001-03-26 13:16:57 +00:00
|
|
|
} else if (ob == dialog_->type) {
|
|
|
|
|
2001-01-21 21:41:35 +00:00
|
|
|
int const type = fl_get_choice(dialog_->type) - 1;
|
2001-03-26 13:16:57 +00:00
|
|
|
if (controller().params().getCmdName() ==
|
|
|
|
InsetRef::getName(type)) {
|
|
|
|
activate = ButtonPolicy::SMI_NOOP;
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
}
|
2000-11-29 15:06:42 +00:00
|
|
|
|
2000-10-02 00:10:25 +00:00
|
|
|
return activate;
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|