2000-08-08 15:36:25 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 2000 The LyX Team.
|
|
|
|
*
|
|
|
|
* ======================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include FORMS_H_LOCATION
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include "Dialogs.h"
|
|
|
|
#include "FormRef.h"
|
|
|
|
#include "LyXView.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "form_ref.h"
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using std::sort;
|
|
|
|
using std::vector;
|
|
|
|
|
2000-10-27 10:04:51 +00:00
|
|
|
static int const minw_hb = 250;
|
|
|
|
static int minw_sb;
|
|
|
|
|
2000-08-08 15:36:25 +00:00
|
|
|
FormRef::FormRef(LyXView * lv, Dialogs * d)
|
2000-11-14 02:01:57 +00:00
|
|
|
: FormCommand(lv, d, _("Reference"), new OkCancelReadOnlyPolicy),
|
|
|
|
toggle(GOBACK), dialog_(0)
|
2000-08-08 15:36:25 +00:00
|
|
|
{
|
|
|
|
// let the dialog be shown
|
|
|
|
// These are permanent connections so we won't bother
|
|
|
|
// storing a copy because we won't be disconnecting.
|
|
|
|
d->showRef.connect(slot(this, &FormRef::showInset));
|
|
|
|
d->createRef.connect(slot(this, &FormRef::createInset));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FormRef::~FormRef()
|
|
|
|
{
|
|
|
|
delete dialog_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-03 05:53:25 +00:00
|
|
|
FL_FORM * FormRef::form() const
|
|
|
|
{
|
2000-11-14 02:01:57 +00:00
|
|
|
if (dialog_) return dialog_->form;
|
2000-10-03 05:53:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-20 09:50:09 +00:00
|
|
|
void FormRef::connect()
|
|
|
|
{
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_set_form_maxsize(form(), 2 * minw_, minh_);
|
2000-10-20 09:50:09 +00:00
|
|
|
FormCommand::connect();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-13 05:57:05 +00:00
|
|
|
void FormRef::disconnect()
|
2000-08-08 15:36:25 +00:00
|
|
|
{
|
|
|
|
refs.clear();
|
2000-10-13 05:57:05 +00:00
|
|
|
FormCommand::disconnect();
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormRef::build()
|
|
|
|
{
|
|
|
|
dialog_ = build_ref();
|
|
|
|
|
|
|
|
fl_addto_choice(dialog_->type,
|
|
|
|
_(" Ref | Page | TextRef | TextPage | PrettyRef "));
|
|
|
|
|
2000-10-20 09:50:09 +00:00
|
|
|
// Workaround dumb xforms sizing bug
|
|
|
|
minw_ = form()->w;
|
|
|
|
minh_ = form()->h;
|
2000-10-27 10:04:51 +00:00
|
|
|
minw_sb = minw_;
|
2000-08-08 15:36:25 +00:00
|
|
|
|
|
|
|
// Name is irrelevant to LaTeX documents
|
2000-11-04 10:00:12 +00:00
|
|
|
if (lv_->buffer()->isLatex()) {
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_deactivate_object(dialog_->name);
|
|
|
|
fl_set_object_lcol(dialog_->name, FL_INACTIVE);
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Can change reference only through browser
|
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
|
2000-11-14 02:01:57 +00:00
|
|
|
bc_.setOK(dialog_->button_ok);
|
|
|
|
bc_.setCancel(dialog_->button_cancel);
|
2000-10-02 00:10:25 +00:00
|
|
|
bc_.refresh();
|
2000-11-28 06:46:06 +00:00
|
|
|
|
|
|
|
bc_.addReadOnly(dialog_->type);
|
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
|
|
|
{
|
|
|
|
fl_set_input(dialog_->ref, params.getContents().c_str());
|
|
|
|
fl_set_input(dialog_->name, params.getOptions().c_str());
|
|
|
|
|
|
|
|
Type type = getType();
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_set_choice(dialog_->type, type + 1);
|
2000-08-08 15:36:25 +00:00
|
|
|
|
|
|
|
toggle = GOBACK;
|
2000-10-03 05:53:25 +00:00
|
|
|
fl_set_object_label(dialog_->button_go, _("Goto reference"));
|
2000-08-08 15:36:25 +00:00
|
|
|
|
|
|
|
refs.clear();
|
2000-11-04 10:00:12 +00:00
|
|
|
if (inset_ == 0) {
|
2000-08-08 15:36:25 +00:00
|
|
|
refs = lv_->buffer()->getLabelList();
|
2000-11-14 02:01:57 +00:00
|
|
|
updateBrowser(refs);
|
2000-08-08 15:36:25 +00:00
|
|
|
showBrowser();
|
2000-10-02 00:10:25 +00:00
|
|
|
} else {
|
2000-08-08 15:36:25 +00:00
|
|
|
hideBrowser();
|
2000-10-02 00:10:25 +00:00
|
|
|
}
|
2000-11-14 02:01:57 +00:00
|
|
|
bc_.readOnly(lv_->buffer()->isReadonly());
|
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);
|
|
|
|
if (fl_get_button( dialog_->sort))
|
|
|
|
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)
|
|
|
|
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 ***"));
|
|
|
|
|
|
|
|
fl_deactivate_object(dialog_->browser);
|
|
|
|
fl_deactivate_object(dialog_->button_update);
|
|
|
|
fl_deactivate_object(dialog_->sort);
|
|
|
|
fl_set_object_lcol(dialog_->browser, FL_INACTIVE);
|
|
|
|
fl_set_object_lcol(dialog_->button_update, FL_INACTIVE);
|
|
|
|
fl_set_object_lcol(dialog_->sort, FL_INACTIVE);
|
2000-08-08 15:36:25 +00:00
|
|
|
} else {
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_set_browser_topline(dialog_->browser, 1);
|
|
|
|
fl_activate_object(dialog_->browser);
|
|
|
|
fl_set_object_lcol(dialog_->browser, FL_BLACK);
|
|
|
|
fl_activate_object(dialog_->button_update);
|
|
|
|
fl_set_object_lcol(dialog_->button_update, FL_BLACK);
|
|
|
|
fl_activate_object(dialog_->sort);
|
|
|
|
fl_set_object_lcol(dialog_->sort, FL_BLACK);
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormRef::showBrowser() const
|
|
|
|
{
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_show_object(dialog_->browser);
|
|
|
|
fl_show_object(dialog_->button_update);
|
|
|
|
fl_show_object(dialog_->sort);
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
setSize(minw_sb, 0);
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_deactivate_object(dialog_->type);
|
|
|
|
fl_set_object_lcol(dialog_->type, FL_INACTIVE);
|
|
|
|
fl_deactivate_object(dialog_->button_go);
|
|
|
|
fl_set_object_lcol(dialog_->button_go, FL_INACTIVE);
|
|
|
|
fl_set_object_lcol(dialog_->ref, FL_INACTIVE);
|
2000-10-02 00:10:25 +00:00
|
|
|
bc_.valid(false);
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormRef::hideBrowser() const
|
|
|
|
{
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_hide_object(dialog_->browser);
|
|
|
|
fl_hide_object(dialog_->button_update);
|
|
|
|
fl_hide_object(dialog_->sort);
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
setSize(minw_hb, 280);
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_activate_object(dialog_->type);
|
|
|
|
fl_set_object_lcol(dialog_->type, FL_BLACK);
|
|
|
|
fl_activate_object(dialog_->button_go);
|
|
|
|
fl_set_object_lcol(dialog_->button_go, FL_BLACK);
|
|
|
|
fl_set_object_lcol(dialog_->ref, FL_BLACK);
|
2000-10-02 00:10:25 +00:00
|
|
|
bc_.invalid();
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
void FormRef::setSize(int w, int dx) const
|
2000-08-08 15:36:25 +00:00
|
|
|
{
|
|
|
|
static int x1 = dialog_->name->x;
|
|
|
|
static int y1 = dialog_->name->y;
|
|
|
|
static int x2 = dialog_->ref->x;
|
|
|
|
static int y2 = dialog_->ref->y;
|
|
|
|
static int x3 = dialog_->type->x;
|
|
|
|
static int y3 = dialog_->type->y;
|
2000-10-03 05:53:25 +00:00
|
|
|
static int x4 = dialog_->button_go->x;
|
|
|
|
static int y4 = dialog_->button_go->y;
|
|
|
|
static int x5 = dialog_->button_ok->x;
|
|
|
|
static int y5 = dialog_->button_ok->y;
|
|
|
|
static int x6 = dialog_->button_cancel->x;
|
|
|
|
static int y6 = dialog_->button_cancel->y;
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
if (form()->w != w) {
|
2000-10-20 09:50:09 +00:00
|
|
|
minw_ = w;
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_set_form_size(form(), minw_, minh_);
|
2000-10-20 09:50:09 +00:00
|
|
|
} else
|
|
|
|
return;
|
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_set_object_position(dialog_->name, x1 - dx, y1);
|
|
|
|
fl_set_object_position(dialog_->ref, x2 - dx, y2);
|
|
|
|
fl_set_object_position(dialog_->type, x3 - dx, y3);
|
|
|
|
fl_set_object_position(dialog_->button_go, x4 - dx, y4);
|
|
|
|
fl_set_object_position(dialog_->button_ok, x5 - dx, y5);
|
|
|
|
fl_set_object_position(dialog_->button_cancel, x6 - dx, y6);
|
2000-08-08 15:36:25 +00:00
|
|
|
|
|
|
|
// These two must be reset apparently
|
|
|
|
// Name is irrelevant to LaTeX documents
|
2000-11-04 10:00:12 +00:00
|
|
|
if (lv_->buffer()->isLatex()) {
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_deactivate_object(dialog_->name);
|
|
|
|
fl_set_object_lcol(dialog_->name, FL_INACTIVE);
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Can change reference only through browser
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_deactivate_object(dialog_->ref);
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormRef::apply()
|
|
|
|
{
|
|
|
|
if (!lv_->view()->available())
|
|
|
|
return;
|
|
|
|
|
2000-09-19 11:18:35 +00:00
|
|
|
Type const type = static_cast<Type>(fl_get_choice(dialog_->type) - 1);
|
|
|
|
params.setCmdName(getName(type));
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-09-19 11:18:35 +00:00
|
|
|
params.setOptions(fl_get_input(dialog_->name));
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-09-19 11:18:35 +00:00
|
|
|
if (inset_ != 0) {
|
2000-08-08 15:36:25 +00:00
|
|
|
// Only update if contents have changed
|
2000-10-03 05:53:25 +00:00
|
|
|
if (params != inset_->params()) {
|
2000-09-19 11:18:35 +00:00
|
|
|
inset_->setParams(params);
|
|
|
|
lv_->view()->updateInset(inset_, true);
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
2000-09-19 11:18:35 +00:00
|
|
|
lv_->getLyXFunc()->Dispatch(LFUN_REF_INSERT,
|
|
|
|
params.getAsString());
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-02 00:10:25 +00:00
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
#warning check use of buttoncontroller
|
|
|
|
// Seems okay except that goref and goback shouldn't
|
|
|
|
// affect the status of ok.
|
|
|
|
#endif
|
2000-11-14 02:01:57 +00:00
|
|
|
bool FormRef::input(FL_OBJECT *, long data)
|
2000-08-08 15:36:25 +00:00
|
|
|
{
|
2000-11-14 02:01:57 +00:00
|
|
|
bool activate(true);
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (data) {
|
2000-08-08 15:36:25 +00:00
|
|
|
// goto reference / go back
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
toggle = static_cast<Goto>(toggle + 1);
|
2000-11-04 10:00:12 +00:00
|
|
|
if (toggle == GOFIRST ) toggle = GOREF;
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-09-19 11:18:35 +00:00
|
|
|
switch (toggle) {
|
2000-08-08 15:36:25 +00:00
|
|
|
case GOREF:
|
|
|
|
{
|
|
|
|
lv_->getLyXFunc()->
|
|
|
|
Dispatch(LFUN_REF_GOTO,
|
2000-09-19 11:18:35 +00:00
|
|
|
params.getContents());
|
2000-10-03 05:53:25 +00:00
|
|
|
fl_set_object_label(dialog_->button_go, _("Go back"));
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GOBACK:
|
|
|
|
{
|
|
|
|
lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK);
|
2000-10-13 05:57:05 +00:00
|
|
|
fl_set_object_label(dialog_->button_go,
|
|
|
|
_("Goto reference"));
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// choose browser key
|
|
|
|
case 2:
|
|
|
|
{
|
2000-11-14 02:01:57 +00:00
|
|
|
unsigned int sel = fl_get_browser(dialog_->browser);
|
|
|
|
if (sel < 1 || sel > refs.size()) break;
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
string s = fl_get_browser_line(dialog_->browser, sel);
|
|
|
|
fl_set_input(dialog_->ref, s.c_str());
|
|
|
|
params.setContents(s);
|
2000-08-08 15:36:25 +00:00
|
|
|
|
|
|
|
toggle = GOBACK;
|
|
|
|
lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK);
|
2000-10-03 05:53:25 +00:00
|
|
|
fl_set_object_label(dialog_->button_go, _("Goto reference"));
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_activate_object(dialog_->type);
|
|
|
|
fl_set_object_lcol(dialog_->type, FL_BLACK);
|
|
|
|
fl_activate_object(dialog_->button_go);
|
|
|
|
fl_set_object_lcol(dialog_->button_go, FL_BLACK);
|
|
|
|
fl_set_object_lcol(dialog_->ref, FL_BLACK);
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// update or sort
|
|
|
|
case 3:
|
|
|
|
{
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_freeze_form(form());
|
|
|
|
updateBrowser(refs);
|
|
|
|
fl_unfreeze_form(form());
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// changed reference type
|
|
|
|
case 4:
|
|
|
|
{
|
2000-10-13 05:57:05 +00:00
|
|
|
Type type = static_cast<Type>(
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_get_choice(dialog_->type) - 1);
|
|
|
|
if (params.getCmdName() == getName(type)
|
2000-11-04 10:00:12 +00:00
|
|
|
&& inset_) {
|
2000-10-02 00:10:25 +00:00
|
|
|
activate = false;
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2000-10-02 00:10:25 +00:00
|
|
|
return activate;
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FormRef::Type FormRef::getType() const
|
|
|
|
{
|
|
|
|
Type type;
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
if (params.getCmdName() == "ref" )
|
2000-08-08 15:36:25 +00:00
|
|
|
type = REF;
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
else if (params.getCmdName() == "pageref" )
|
2000-08-08 15:36:25 +00:00
|
|
|
type = PAGEREF;
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
else if (params.getCmdName() == "vref" )
|
2000-08-08 15:36:25 +00:00
|
|
|
type = VREF;
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
else if (params.getCmdName() == "vpageref" )
|
2000-08-08 15:36:25 +00:00
|
|
|
type = VPAGEREF;
|
|
|
|
|
|
|
|
else
|
|
|
|
type = PRETTYREF;
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
string const FormRef::getName(Type type) const
|
2000-08-08 15:36:25 +00:00
|
|
|
{
|
|
|
|
string name;
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (type) {
|
2000-08-08 15:36:25 +00:00
|
|
|
case REF:
|
|
|
|
name = "ref";
|
|
|
|
break;
|
|
|
|
case PAGEREF:
|
|
|
|
name = "pageref";
|
|
|
|
break;
|
|
|
|
case VREF:
|
|
|
|
name = "vref";
|
|
|
|
break;
|
|
|
|
case VPAGEREF:
|
|
|
|
name = "vpageref";
|
|
|
|
break;
|
|
|
|
case PRETTYREF:
|
|
|
|
name = "prettyref";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|