2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000 The LyX Team.
9 * ======================================================
14 #include FORMS_H_LOCATION
17 #pragma implementation
33 static int const minw_hb = 250;
36 FormRef::FormRef(LyXView * lv, Dialogs * d)
37 : FormCommand(lv, d, _("Reference")), toggle(GOBACK), dialog_(0)
39 // let the dialog be shown
40 // These are permanent connections so we won't bother
41 // storing a copy because we won't be disconnecting.
42 d->showRef.connect(slot(this, &FormRef::showInset));
43 d->createRef.connect(slot(this, &FormRef::createInset));
53 FL_FORM * FormRef::form() const
55 if (dialog_ ) return dialog_->form;
60 void FormRef::connect()
62 fl_set_form_maxsize( form(), 2*minw_, minh_ );
63 FormCommand::connect();
67 void FormRef::disconnect()
70 FormCommand::disconnect();
76 dialog_ = build_ref();
78 fl_addto_choice(dialog_->type,
79 _(" Ref | Page | TextRef | TextPage | PrettyRef "));
81 // Workaround dumb xforms sizing bug
86 // Name is irrelevant to LaTeX documents
87 if (lv_->buffer()->isLatex()) {
88 fl_deactivate_object( dialog_->name );
89 fl_set_object_lcol( dialog_->name, FL_INACTIVE );
92 // Can change reference only through browser
93 fl_deactivate_object( dialog_->ref );
95 bc_.setOK( dialog_->button_ok );
96 bc_.setCancel( dialog_->button_cancel );
97 bc_.addReadOnly( dialog_->type );
102 void FormRef::update()
104 fl_set_input(dialog_->ref, params.getContents().c_str());
105 fl_set_input(dialog_->name, params.getOptions().c_str());
107 Type type = getType();
108 fl_set_choice( dialog_->type, type+1 );
111 fl_set_object_label(dialog_->button_go, _("Goto reference"));
115 refs = lv_->buffer()->getLabelList();
116 updateBrowser( refs );
121 bc_.readOnly( lv_->buffer()->isReadonly() );
125 void FormRef::updateBrowser( vector<string> keys ) const
127 if (fl_get_button( dialog_->sort ) )
128 sort( keys.begin(), keys.end() );
130 fl_clear_browser( dialog_->browser );
131 for (vector<string>::const_iterator it = keys.begin();
132 it != keys.end(); ++it )
133 fl_add_browser_line( dialog_->browser, (*it).c_str());
136 fl_add_browser_line( dialog_->browser,
137 _("*** No labels found in document ***"));
139 fl_deactivate_object( dialog_->browser );
140 fl_deactivate_object( dialog_->button_update );
141 fl_deactivate_object( dialog_->sort );
142 fl_set_object_lcol( dialog_->browser, FL_INACTIVE );
143 fl_set_object_lcol( dialog_->button_update, FL_INACTIVE );
144 fl_set_object_lcol( dialog_->sort, FL_INACTIVE );
146 fl_set_browser_topline( dialog_->browser, 1 );
147 fl_activate_object( dialog_->browser );
148 fl_set_object_lcol( dialog_->browser, FL_BLACK );
149 fl_activate_object( dialog_->button_update );
150 fl_set_object_lcol( dialog_->button_update, FL_BLACK );
151 fl_activate_object( dialog_->sort );
152 fl_set_object_lcol( dialog_->sort, FL_BLACK );
157 void FormRef::showBrowser() const
159 fl_show_object( dialog_->browser );
160 fl_show_object( dialog_->button_update );
161 fl_show_object( dialog_->sort );
163 setSize( minw_sb, 0 );
165 fl_deactivate_object( dialog_->type );
166 fl_set_object_lcol( dialog_->type, FL_INACTIVE );
167 fl_deactivate_object( dialog_->button_go );
168 fl_set_object_lcol( dialog_->button_go, FL_INACTIVE );
169 fl_set_object_lcol( dialog_->ref, FL_INACTIVE );
174 void FormRef::hideBrowser() const
176 fl_hide_object( dialog_->browser );
177 fl_hide_object( dialog_->button_update );
178 fl_hide_object( dialog_->sort );
180 setSize( minw_hb, 280 );
182 fl_activate_object( dialog_->type );
183 fl_set_object_lcol( dialog_->type, FL_BLACK );
184 fl_activate_object( dialog_->button_go );
185 fl_set_object_lcol( dialog_->button_go, FL_BLACK );
186 fl_set_object_lcol( dialog_->ref, FL_BLACK );
191 void FormRef::setSize( int w, int dx ) const
193 static int x1 = dialog_->name->x;
194 static int y1 = dialog_->name->y;
195 static int x2 = dialog_->ref->x;
196 static int y2 = dialog_->ref->y;
197 static int x3 = dialog_->type->x;
198 static int y3 = dialog_->type->y;
199 static int x4 = dialog_->button_go->x;
200 static int y4 = dialog_->button_go->y;
201 static int x5 = dialog_->button_ok->x;
202 static int y5 = dialog_->button_ok->y;
203 static int x6 = dialog_->button_cancel->x;
204 static int y6 = dialog_->button_cancel->y;
206 if (form()->w != w) {
208 fl_set_form_size( form(), minw_, minh_ );
212 fl_set_object_position( dialog_->name, x1-dx, y1 );
213 fl_set_object_position( dialog_->ref, x2-dx, y2 );
214 fl_set_object_position( dialog_->type, x3-dx, y3 );
215 fl_set_object_position( dialog_->button_go, x4-dx, y4 );
216 fl_set_object_position( dialog_->button_ok, x5-dx, y5 );
217 fl_set_object_position( dialog_->button_cancel, x6-dx, y6 );
219 // These two must be reset apparently
220 // Name is irrelevant to LaTeX documents
221 if (lv_->buffer()->isLatex()) {
222 fl_deactivate_object( dialog_->name );
223 fl_set_object_lcol( dialog_->name, FL_INACTIVE );
226 // Can change reference only through browser
227 fl_deactivate_object( dialog_->ref );
231 void FormRef::apply()
233 if (!lv_->view()->available())
236 Type const type = static_cast<Type>(fl_get_choice(dialog_->type) - 1);
237 params.setCmdName(getName(type));
239 params.setOptions(fl_get_input(dialog_->name));
242 // Only update if contents have changed
243 if (params != inset_->params()) {
244 inset_->setParams(params);
245 lv_->view()->updateInset(inset_, true);
248 lv_->getLyXFunc()->Dispatch(LFUN_REF_INSERT,
249 params.getAsString());
255 #warning check use of buttoncontroller
256 // Seems okay except that goref and goback shouldn't
257 // affect the status of ok.
259 bool FormRef::input( FL_OBJECT *, long data )
261 bool activate( true );
263 // goto reference / go back
266 toggle = static_cast<Goto>(toggle + 1);
267 if (toggle == GOFIRST ) toggle = GOREF;
273 Dispatch(LFUN_REF_GOTO,
274 params.getContents());
275 fl_set_object_label(dialog_->button_go, _("Go back"));
281 lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK);
282 fl_set_object_label(dialog_->button_go,
283 _("Goto reference"));
293 // choose browser key
296 unsigned int sel = fl_get_browser( dialog_->browser );
297 if (sel < 1 || sel > refs.size() ) break;
299 string s = fl_get_browser_line( dialog_->browser, sel );
300 fl_set_input( dialog_->ref, s.c_str());
301 params.setContents( s );
304 lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK);
305 fl_set_object_label(dialog_->button_go, _("Goto reference"));
307 fl_activate_object( dialog_->type );
308 fl_set_object_lcol( dialog_->type, FL_BLACK );
309 fl_activate_object( dialog_->button_go );
310 fl_set_object_lcol( dialog_->button_go, FL_BLACK );
311 fl_set_object_lcol( dialog_->ref, FL_BLACK );
318 fl_freeze_form( form() );
319 updateBrowser( refs );
320 fl_unfreeze_form( form() );
324 // changed reference type
327 Type type = static_cast<Type>(
328 fl_get_choice(dialog_->type) - 1 );
329 if (params.getCmdName() == getName( type )
343 FormRef::Type FormRef::getType() const
347 if (params.getCmdName() == "ref" )
350 else if (params.getCmdName() == "pageref" )
353 else if (params.getCmdName() == "vref" )
356 else if (params.getCmdName() == "vpageref" )
366 string FormRef::getName( Type type ) const