2002-03-11 17:00:41 +00:00
|
|
|
/**
|
2002-03-11 22:47:41 +00:00
|
|
|
* \file xforms/FormRef.C
|
2002-03-11 17:00:41 +00:00
|
|
|
* Copyright 2000-2001 The LyX Team.
|
|
|
|
* See the file COPYING.
|
|
|
|
*
|
|
|
|
* \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"
|
2001-09-13 09:57:06 +00:00
|
|
|
#include "helper_funcs.h" // getStringFromVector
|
|
|
|
#include "support/lstrings.h" // frontStrip, strip
|
2001-03-26 13:16:57 +00:00
|
|
|
|
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
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
for (int i = 0; !InsetRef::types[i].latex_name.empty(); ++i)
|
2001-09-24 16:37:24 +00:00
|
|
|
fl_addto_choice(dialog_->choice_type,
|
2001-01-21 21:41:35 +00:00
|
|
|
_(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.
|
2001-09-24 16:37:24 +00:00
|
|
|
fl_deactivate_object(dialog_->input_ref);
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2002-03-11 18:24:31 +00:00
|
|
|
fl_set_input_return(dialog_->input_name, FL_RETURN_CHANGED);
|
|
|
|
fl_set_input_return(dialog_->input_ref, FL_RETURN_CHANGED);
|
|
|
|
|
|
|
|
setPrehandler(dialog_->input_name);
|
|
|
|
setPrehandler(dialog_->input_ref);
|
|
|
|
|
|
|
|
// 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);
|
2002-03-12 14:11:15 +00:00
|
|
|
bc().setCancel(dialog_->button_close);
|
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);
|
2001-09-24 16:37:24 +00:00
|
|
|
bc().addReadOnly(dialog_->input_name);
|
|
|
|
bc().addReadOnly(dialog_->input_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-09-24 16:37:24 +00:00
|
|
|
fl_set_input(dialog_->input_ref,
|
2001-03-26 13:16:57 +00:00
|
|
|
controller().params().getContents().c_str());
|
2001-09-24 16:37:24 +00:00
|
|
|
fl_set_input(dialog_->input_name,
|
2001-03-26 13:16:57 +00:00
|
|
|
controller().params().getOptions().c_str());
|
2002-03-21 21:21:28 +00:00
|
|
|
fl_set_choice(dialog_->choice_type,
|
2001-03-26 13:16:57 +00:00
|
|
|
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-09-24 16:37:24 +00:00
|
|
|
setEnabled(dialog_->input_name, false);
|
2001-01-21 20:10:48 +00:00
|
|
|
} else {
|
2001-09-24 16:37:24 +00:00
|
|
|
setEnabled(dialog_->input_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) {
|
2001-09-24 16:37:24 +00:00
|
|
|
fl_set_choice(dialog_->choice_type, 1);
|
|
|
|
setEnabled(dialog_->choice_type, false);
|
2001-03-26 13:16:57 +00:00
|
|
|
} else {
|
2001-09-24 16:37:24 +00:00
|
|
|
setEnabled(dialog_->choice_type, true);
|
2001-03-26 13:16:57 +00:00
|
|
|
}
|
2000-11-29 15:06:42 +00:00
|
|
|
|
2001-09-24 16:37:24 +00:00
|
|
|
// Get the available buffers
|
|
|
|
vector<string> const buffers = controller().getBufferList();
|
|
|
|
vector<string> const choice_buffers =
|
|
|
|
getVectorFromChoice(dialog_->choice_buffer);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-09-24 16:37:24 +00:00
|
|
|
// If different from the current contents of the choice, then update it
|
|
|
|
if (buffers != choice_buffers) {
|
|
|
|
// create a string of entries " entry1 | entry2 | entry3 "
|
|
|
|
// with which to initialise the xforms choice object.
|
|
|
|
string const choice =
|
|
|
|
" " + getStringFromVector(buffers, " | ") + " ";
|
|
|
|
|
|
|
|
fl_clear_choice(dialog_->choice_buffer);
|
|
|
|
fl_addto_choice(dialog_->choice_buffer, choice.c_str());
|
|
|
|
|
|
|
|
fl_set_choice(dialog_->choice_buffer,
|
|
|
|
controller().getBufferNum() + 1);
|
|
|
|
}
|
2001-09-13 09:57:06 +00:00
|
|
|
|
|
|
|
refs_ = controller().getLabelList(string());
|
2001-03-26 13:16:57 +00:00
|
|
|
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);
|
2001-09-24 16:37:24 +00:00
|
|
|
if (fl_get_button(dialog_->check_sort))
|
2000-11-14 02:01:57 +00:00
|
|
|
sort(keys.begin(), keys.end());
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2001-09-24 16:37:24 +00:00
|
|
|
vector<string> browser_keys =
|
|
|
|
getVectorFromBrowser(dialog_->browser_refs);
|
|
|
|
|
|
|
|
if (browser_keys == keys)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fl_clear_browser(dialog_->browser_refs);
|
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-09-24 16:37:24 +00:00
|
|
|
fl_add_browser_line(dialog_->browser_refs, it->c_str());
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
if (keys.empty()) {
|
2001-09-24 16:37:24 +00:00
|
|
|
fl_add_browser_line(dialog_->browser_refs,
|
2000-11-14 02:01:57 +00:00
|
|
|
_("*** No labels found in document ***"));
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-09-24 16:37:24 +00:00
|
|
|
setEnabled(dialog_->browser_refs, false);
|
|
|
|
setEnabled(dialog_->check_sort, false);
|
2000-11-14 02:01:57 +00:00
|
|
|
|
2001-09-24 16:37:24 +00:00
|
|
|
fl_set_input(dialog_->input_ref, "");
|
2000-08-08 15:36:25 +00:00
|
|
|
} else {
|
2001-09-24 16:37:24 +00:00
|
|
|
setEnabled(dialog_->browser_refs, true);
|
|
|
|
setEnabled(dialog_->check_sort, true);
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2001-09-24 16:37:24 +00:00
|
|
|
string ref = fl_get_input(dialog_->input_ref);
|
2001-09-13 09:57:06 +00:00
|
|
|
vector<string>::const_iterator cit = (ref.empty())
|
|
|
|
? keys.begin()
|
|
|
|
: find(keys.begin(), keys.end(), ref);
|
2001-01-28 18:31:36 +00:00
|
|
|
if (cit == keys.end()) {
|
2001-09-24 16:37:24 +00:00
|
|
|
fl_deselect_browser(dialog_->browser_refs);
|
2001-09-13 09:57:06 +00:00
|
|
|
} else {
|
|
|
|
if (ref.empty())
|
2001-09-24 16:37:24 +00:00
|
|
|
fl_set_input(dialog_->input_ref, cit->c_str());
|
2001-09-13 09:57:06 +00:00
|
|
|
|
|
|
|
int const i = static_cast<int>(cit - keys.begin());
|
2001-09-24 16:37:24 +00:00
|
|
|
fl_set_browser_topline(dialog_->browser_refs, max(i-5, 1));
|
|
|
|
fl_select_browser_line(dialog_->browser_refs, i+1);
|
2001-09-13 09:57:06 +00:00
|
|
|
}
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormRef::apply()
|
|
|
|
{
|
2001-09-24 16:37:24 +00:00
|
|
|
int const type = fl_get_choice(dialog_->choice_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-09-24 16:37:24 +00:00
|
|
|
controller().params().setOptions(fl_get_input(dialog_->input_name));
|
|
|
|
controller().params().setContents(fl_get_input(dialog_->input_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_) {
|
2001-09-24 16:37:24 +00:00
|
|
|
controller().gotoRef(fl_get_input(dialog_->input_ref));
|
2002-03-21 21:21:28 +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-09-24 16:37:24 +00:00
|
|
|
} else if (ob == dialog_->browser_refs) {
|
2001-03-26 13:16:57 +00:00
|
|
|
|
2001-09-24 16:37:24 +00:00
|
|
|
unsigned int sel = fl_get_browser(dialog_->browser_refs);
|
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()) {
|
2001-09-24 16:37:24 +00:00
|
|
|
string s = fl_get_browser_line(dialog_->browser_refs, sel);
|
|
|
|
fl_set_input(dialog_->input_ref, s.c_str());
|
2000-11-29 15:06:42 +00:00
|
|
|
}
|
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-09-24 16:37:24 +00:00
|
|
|
setEnabled(dialog_->choice_type, true);
|
2001-03-05 19:02:40 +00:00
|
|
|
setEnabled(dialog_->button_go, true);
|
2001-09-24 16:37:24 +00:00
|
|
|
fl_set_object_lcol(dialog_->input_ref, FL_BLACK);
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
} else if (ob == dialog_->button_update ||
|
2001-09-24 16:37:24 +00:00
|
|
|
ob == dialog_->check_sort ||
|
|
|
|
ob == dialog_->choice_buffer) {
|
2001-09-13 09:57:06 +00:00
|
|
|
|
|
|
|
if (ob == dialog_->button_update ||
|
2001-09-24 16:37:24 +00:00
|
|
|
ob == dialog_->choice_buffer) {
|
2001-09-13 09:57:06 +00:00
|
|
|
string const name =
|
2002-02-06 15:12:40 +00:00
|
|
|
controller().getBufferName(fl_get_choice(dialog_->choice_buffer) - 1);
|
2001-09-13 09:57:06 +00:00
|
|
|
refs_ = controller().getLabelList(name);
|
|
|
|
}
|
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-09-24 16:37:24 +00:00
|
|
|
} else if (ob == dialog_->choice_type) {
|
2001-03-26 13:16:57 +00:00
|
|
|
|
2001-09-24 16:37:24 +00:00
|
|
|
int const type = fl_get_choice(dialog_->choice_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
|
|
|
}
|