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")), toggle(GOBACK), dialog_(0)
40 // let the dialog be shown
41 // These are permanent connections so we won't bother
42 // storing a copy because we won't be disconnecting.
43 d->showRef.connect(slot(this, &FormRef::showInset));
44 d->createRef.connect(slot(this, &FormRef::createInset));
54 void FormRef::clearStore()
62 dialog_ = build_ref();
64 fl_addto_choice(dialog_->type,
65 _(" Ref | Page | TextRef | TextPage | PrettyRef "));
67 // XFORMS bug workaround
68 // Define the min/max dimensions. Actually applied in update()
69 formw = form()->w, formh = form()->h;
71 // Name is irrelevant to LaTeX documents
72 if( lv_->buffer()->isLatex() ) {
73 fl_deactivate_object( dialog_->name );
74 fl_set_object_lcol( dialog_->name, FL_INACTIVE );
77 // Can change reference only through browser
78 fl_deactivate_object( dialog_->ref );
80 if( lv_->buffer()->isReadonly() ) {
81 fl_deactivate_object( dialog_->type );
82 fl_deactivate_object( dialog_->ok );
83 fl_set_object_lcol( dialog_->ok, FL_INACTIVE );
85 fl_activate_object( dialog_->type );
86 fl_activate_object( dialog_->ok );
87 fl_set_object_lcol( dialog_->ok, FL_BLACK );
92 FL_FORM * const FormRef::form() const
94 if ( dialog_ ) // no need to test for dialog_->form_ref
101 void FormRef::update()
103 fl_set_input(dialog_->ref, params.getContents().c_str());
104 fl_set_input(dialog_->name, params.getOptions().c_str());
106 Type type = getType();
107 fl_set_choice( dialog_->type, type+1 );
110 fl_set_object_label(dialog_->go, _("Goto reference"));
114 refs = lv_->buffer()->getLabelList();
115 updateBrowser( refs );
122 void FormRef::updateBrowser( vector<string> keys ) const
124 if( fl_get_button( dialog_->sort ) )
125 sort( keys.begin(), keys.end() );
127 fl_clear_browser( dialog_->browser );
128 for( vector<string>::const_iterator it = keys.begin();
129 it != keys.end(); ++it )
130 fl_add_browser_line( dialog_->browser, (*it).c_str());
133 fl_add_browser_line( dialog_->browser,
134 _("*** No labels found in document ***"));
136 fl_deactivate_object( dialog_->browser );
137 fl_deactivate_object( dialog_->update );
138 fl_deactivate_object( dialog_->sort );
139 fl_set_object_lcol( dialog_->browser, FL_INACTIVE );
140 fl_set_object_lcol( dialog_->update, FL_INACTIVE );
141 fl_set_object_lcol( dialog_->sort, FL_INACTIVE );
143 fl_set_browser_topline( dialog_->browser, 1 );
144 fl_activate_object( dialog_->browser );
145 fl_set_object_lcol( dialog_->browser, FL_BLACK );
146 fl_activate_object( dialog_->update );
147 fl_set_object_lcol( dialog_->update, FL_BLACK );
148 fl_activate_object( dialog_->sort );
149 fl_set_object_lcol( dialog_->sort, FL_BLACK );
154 void FormRef::showBrowser() const
156 fl_show_object( dialog_->browser );
157 fl_show_object( dialog_->update );
158 fl_show_object( dialog_->sort );
160 setSize( formw, formh, 0 );
162 fl_deactivate_object( dialog_->type );
163 fl_set_object_lcol( dialog_->type, FL_INACTIVE );
164 fl_deactivate_object( dialog_->go );
165 fl_set_object_lcol( dialog_->go, FL_INACTIVE );
166 fl_deactivate_object( dialog_->ok );
167 fl_set_object_lcol( dialog_->ok, FL_INACTIVE );
168 fl_set_object_lcol( dialog_->ref, FL_INACTIVE );
172 void FormRef::hideBrowser() const
174 fl_hide_object( dialog_->browser );
175 fl_hide_object( dialog_->update );
176 fl_hide_object( dialog_->sort );
178 setSize( 250, formh, 280 );
180 fl_activate_object( dialog_->type );
181 fl_set_object_lcol( dialog_->type, FL_BLACK );
182 fl_activate_object( dialog_->go );
183 fl_set_object_lcol( dialog_->go, FL_BLACK );
184 fl_deactivate_object( dialog_->ok );
185 fl_set_object_lcol( dialog_->ok, FL_INACTIVE );
186 fl_set_object_lcol( dialog_->ref, FL_BLACK );
190 void FormRef::setSize( int w, int h, int dx ) const
192 static int x1 = dialog_->name->x;
193 static int y1 = dialog_->name->y;
194 static int x2 = dialog_->ref->x;
195 static int y2 = dialog_->ref->y;
196 static int x3 = dialog_->type->x;
197 static int y3 = dialog_->type->y;
198 static int x4 = dialog_->go->x;
199 static int y4 = dialog_->go->y;
200 static int x5 = dialog_->ok->x;
201 static int y5 = dialog_->ok->y;
202 static int x6 = dialog_->cancel->x;
203 static int y6 = dialog_->cancel->y;
206 fl_set_form_size( form(), w, h );
208 fl_set_form_minsize( form(), w, h );
209 fl_set_form_maxsize( form(), 2*w, h );
211 if( form()->w == w ) return;
213 fl_set_object_position( dialog_->name, x1-dx, y1 );
214 fl_set_object_position( dialog_->ref, x2-dx, y2 );
215 fl_set_object_position( dialog_->type, x3-dx, y3 );
216 fl_set_object_position( dialog_->go, x4-dx, y4 );
217 fl_set_object_position( dialog_->ok, x5-dx, y5 );
218 fl_set_object_position( dialog_->cancel, x6-dx, y6 );
220 // These two must be reset apparently
221 // Name is irrelevant to LaTeX documents
222 if( lv_->buffer()->isLatex() ) {
223 fl_deactivate_object( dialog_->name );
224 fl_set_object_lcol( dialog_->name, FL_INACTIVE );
227 // Can change reference only through browser
228 fl_deactivate_object( dialog_->ref );
232 void FormRef::apply()
234 if (!lv_->view()->available())
237 Type type = static_cast<Type>( fl_get_choice(dialog_->type)-1 );
238 params.setCmdName( getName( type ) );
240 params.setOptions( fl_get_input(dialog_->name) );
244 // Only update if contents have changed
245 if( params != inset_->params() ) {
246 inset_->setParams( params );
247 lv_->view()->updateInset( inset_, true );
250 lv_->getLyXFunc()->Dispatch( LFUN_REF_INSERT,
251 params.getAsString().c_str() );
256 void FormRef::input( long data )
259 // goto reference / go back
262 toggle = static_cast<Goto>(toggle + 1);
263 if( toggle == GOFIRST ) toggle = GOREF;
269 Dispatch(LFUN_REF_GOTO,
270 params.getContents().c_str());
271 fl_set_object_label(dialog_->go, _("Go back"));
277 lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK);
278 fl_set_object_label(dialog_->go, _("Goto reference"));
288 // choose browser key
291 unsigned int sel = fl_get_browser( dialog_->browser );
292 if( sel < 1 || sel > refs.size() ) break;
294 string s = fl_get_browser_line( dialog_->browser, sel );
295 fl_set_input( dialog_->ref, s.c_str());
296 params.setContents( s );
299 lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK);
300 fl_set_object_label(dialog_->go, _("Goto reference"));
302 fl_activate_object( dialog_->type );
303 fl_set_object_lcol( dialog_->type, FL_BLACK );
304 fl_activate_object( dialog_->go );
305 fl_set_object_lcol( dialog_->go, FL_BLACK );
306 fl_activate_object( dialog_->ok );
307 fl_set_object_lcol( dialog_->ok, FL_BLACK );
308 fl_set_object_lcol( dialog_->ref, FL_BLACK );
315 fl_freeze_form( form() );
316 updateBrowser( refs );
317 fl_unfreeze_form( form() );
321 // changed reference type
324 Type type = static_cast<Type>( fl_get_choice(dialog_->type)-1 );
325 if( params.getCmdName() != getName( type ) ) {
326 fl_activate_object( dialog_->ok );
327 fl_set_object_lcol( dialog_->ok, FL_BLACK );
328 } else if( inset_ != 0 ) {
329 fl_deactivate_object( dialog_->ok );
330 fl_set_object_lcol( dialog_->ok, FL_INACTIVE );
341 FormRef::Type FormRef::getType() const
345 if( params.getCmdName() == "ref" )
348 else if( params.getCmdName() == "pageref" )
351 else if( params.getCmdName() == "vref" )
354 else if( params.getCmdName() == "vpageref" )
364 string FormRef::getName( Type type ) const