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
37 FormRef::FormRef(LyXView * lv, Dialogs * d)
38 : FormCommand(lv, d, _("Reference")), dialog_(0),
41 // let the dialog be shown
42 // These are permanent connections so we won't bother
43 // storing a copy because we won't be disconnecting.
44 d->showRef.connect(slot(this, &FormRef::showInset));
45 d->createRef.connect(slot(this, &FormRef::createInset));
56 void FormRef::clearStore()
64 dialog_ = build_ref();
66 fl_addto_choice(dialog_->type,
67 _(" Ref | Page | TextRef | TextPage | PrettyRef "));
69 // XFORMS bug workaround
70 // Define the min/max dimensions. Actually applied in update()
71 formw = form()->w, formh = form()->h;
73 // Name is irrelevant to LaTeX documents
74 if( lv_->buffer()->isLatex() ) {
75 fl_deactivate_object( dialog_->name );
76 fl_set_object_lcol( dialog_->name, FL_INACTIVE );
79 // Can change reference only through browser
80 fl_deactivate_object( dialog_->ref );
82 if( lv_->buffer()->isReadonly() ) {
83 fl_deactivate_object( dialog_->type );
84 fl_deactivate_object( dialog_->ok );
85 fl_set_object_lcol( dialog_->ok, FL_INACTIVE );
87 fl_activate_object( dialog_->type );
88 fl_activate_object( dialog_->ok );
89 fl_set_object_lcol( dialog_->ok, FL_BLACK );
94 FL_FORM * const FormRef::form() const
96 if( dialog_ ) // no need to test for dialog_->form_ref
97 return dialog_->form_ref;
103 void FormRef::update()
105 fl_set_input(dialog_->ref, params.getContents().c_str());
106 fl_set_input(dialog_->name, params.getOptions().c_str());
108 Type type = getType();
109 fl_set_choice( dialog_->type, type+1 );
112 fl_set_object_label(dialog_->go, _("Goto reference"));
116 refs = lv_->buffer()->getLabelList();
117 updateBrowser( refs );
124 void FormRef::updateBrowser( vector<string> keys ) const
126 if( fl_get_button( dialog_->sort ) )
127 sort( keys.begin(), keys.end() );
129 fl_clear_browser( dialog_->browser );
130 for( vector<string>::const_iterator it = keys.begin();
131 it != keys.end(); ++it )
132 fl_add_browser_line( dialog_->browser, (*it).c_str());
135 fl_add_browser_line( dialog_->browser,
136 _("*** No labels found in document ***"));
138 fl_deactivate_object( dialog_->browser );
139 fl_deactivate_object( dialog_->update );
140 fl_deactivate_object( dialog_->sort );
141 fl_set_object_lcol( dialog_->browser, FL_INACTIVE );
142 fl_set_object_lcol( dialog_->update, FL_INACTIVE );
143 fl_set_object_lcol( dialog_->sort, FL_INACTIVE );
145 fl_set_browser_topline( dialog_->browser, 1 );
146 fl_activate_object( dialog_->browser );
147 fl_set_object_lcol( dialog_->browser, FL_BLACK );
148 fl_activate_object( dialog_->update );
149 fl_set_object_lcol( dialog_->update, FL_BLACK );
150 fl_activate_object( dialog_->sort );
151 fl_set_object_lcol( dialog_->sort, FL_BLACK );
156 void FormRef::showBrowser() const
158 fl_show_object( dialog_->browser );
159 fl_show_object( dialog_->update );
160 fl_show_object( dialog_->sort );
162 setSize( formw, formh, 0 );
164 fl_deactivate_object( dialog_->type );
165 fl_set_object_lcol( dialog_->type, FL_INACTIVE );
166 fl_deactivate_object( dialog_->go );
167 fl_set_object_lcol( dialog_->go, FL_INACTIVE );
168 fl_deactivate_object( dialog_->ok );
169 fl_set_object_lcol( dialog_->ok, FL_INACTIVE );
170 fl_set_object_lcol( dialog_->ref, FL_INACTIVE );
174 void FormRef::hideBrowser() const
176 fl_hide_object( dialog_->browser );
177 fl_hide_object( dialog_->update );
178 fl_hide_object( dialog_->sort );
180 setSize( 250, formh, 280 );
182 fl_activate_object( dialog_->type );
183 fl_set_object_lcol( dialog_->type, FL_BLACK );
184 fl_activate_object( dialog_->go );
185 fl_set_object_lcol( dialog_->go, FL_BLACK );
186 fl_deactivate_object( dialog_->ok );
187 fl_set_object_lcol( dialog_->ok, FL_INACTIVE );
188 fl_set_object_lcol( dialog_->ref, FL_BLACK );
192 void FormRef::setSize( int w, int h, int dx ) const
194 static int x1 = dialog_->name->x;
195 static int y1 = dialog_->name->y;
196 static int x2 = dialog_->ref->x;
197 static int y2 = dialog_->ref->y;
198 static int x3 = dialog_->type->x;
199 static int y3 = dialog_->type->y;
200 static int x4 = dialog_->go->x;
201 static int y4 = dialog_->go->y;
202 static int x5 = dialog_->ok->x;
203 static int y5 = dialog_->ok->y;
204 static int x6 = dialog_->cancel->x;
205 static int y6 = dialog_->cancel->y;
208 fl_set_form_size( form(), w, h );
210 fl_set_form_minsize( form(), w, h );
211 fl_set_form_maxsize( form(), 2*w, h );
213 if( form()->w == w ) return;
215 fl_set_object_position( dialog_->name, x1-dx, y1 );
216 fl_set_object_position( dialog_->ref, x2-dx, y2 );
217 fl_set_object_position( dialog_->type, x3-dx, y3 );
218 fl_set_object_position( dialog_->go, x4-dx, y4 );
219 fl_set_object_position( dialog_->ok, x5-dx, y5 );
220 fl_set_object_position( dialog_->cancel, x6-dx, y6 );
222 // These two must be reset apparently
223 // Name is irrelevant to LaTeX documents
224 if( lv_->buffer()->isLatex() ) {
225 fl_deactivate_object( dialog_->name );
226 fl_set_object_lcol( dialog_->name, FL_INACTIVE );
229 // Can change reference only through browser
230 fl_deactivate_object( dialog_->ref );
234 void FormRef::apply()
236 if (!lv_->view()->available())
239 Type type = static_cast<Type>( fl_get_choice(dialog_->type)-1 );
240 params.setCmdName( getName( type ) );
242 params.setOptions( fl_get_input(dialog_->name) );
246 // Only update if contents have changed
247 if( params != inset_->params() ) {
248 inset_->setParams( params );
249 lv_->view()->updateInset( inset_, true );
252 lv_->getLyXFunc()->Dispatch( LFUN_REF_INSERT,
253 params.getAsString().c_str() );
258 void FormRef::input( long data )
261 // goto reference / go back
264 toggle = static_cast<Goto>(toggle + 1);
265 if( toggle == GOFIRST ) toggle = GOREF;
271 Dispatch(LFUN_REF_GOTO,
272 params.getContents().c_str());
273 fl_set_object_label(dialog_->go, _("Go back"));
279 lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK);
280 fl_set_object_label(dialog_->go, _("Goto reference"));
290 // choose browser key
293 unsigned int sel = fl_get_browser( dialog_->browser );
294 if( sel < 1 || sel > refs.size() ) break;
296 string s = fl_get_browser_line( dialog_->browser, sel );
297 fl_set_input( dialog_->ref, s.c_str());
298 params.setContents( s );
301 lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK);
302 fl_set_object_label(dialog_->go, _("Goto reference"));
304 fl_activate_object( dialog_->type );
305 fl_set_object_lcol( dialog_->type, FL_BLACK );
306 fl_activate_object( dialog_->go );
307 fl_set_object_lcol( dialog_->go, FL_BLACK );
308 fl_activate_object( dialog_->ok );
309 fl_set_object_lcol( dialog_->ok, FL_BLACK );
310 fl_set_object_lcol( dialog_->ref, FL_BLACK );
317 fl_freeze_form( form() );
318 updateBrowser( refs );
319 fl_unfreeze_form( form() );
323 // changed reference type
326 Type type = static_cast<Type>( fl_get_choice(dialog_->type)-1 );
327 if( params.getCmdName() != getName( type ) ) {
328 fl_activate_object( dialog_->ok );
329 fl_set_object_lcol( dialog_->ok, FL_BLACK );
330 } else if( inset_ != 0 ) {
331 fl_deactivate_object( dialog_->ok );
332 fl_set_object_lcol( dialog_->ok, FL_INACTIVE );
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