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
36 FormRef::FormRef(LyXView * lv, Dialogs * d)
37 : FormCommand(lv, d, _("Reference"), HIDE), 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::clearStore()
68 dialog_ = build_ref();
70 fl_addto_choice(dialog_->type,
71 _(" Ref | Page | TextRef | TextPage | PrettyRef "));
73 // XFORMS bug workaround
74 // Define the min/max dimensions. Actually applied in update()
75 formw = form()->w, formh = form()->h;
77 // Name is irrelevant to LaTeX documents
78 if ( lv_->buffer()->isLatex() ) {
79 fl_deactivate_object( dialog_->name );
80 fl_set_object_lcol( dialog_->name, FL_INACTIVE );
83 // Can change reference only through browser
84 fl_deactivate_object( dialog_->ref );
86 bc_.setOK( dialog_->button_ok );
87 bc_.setCancel( dialog_->button_cancel );
88 bc_.addReadOnly( dialog_->type );
93 void FormRef::update()
95 fl_set_input(dialog_->ref, params.getContents().c_str());
96 fl_set_input(dialog_->name, params.getOptions().c_str());
98 Type type = getType();
99 fl_set_choice( dialog_->type, type+1 );
102 fl_set_object_label(dialog_->button_go, _("Goto reference"));
106 refs = lv_->buffer()->getLabelList();
107 updateBrowser( refs );
112 bc_.readOnly( lv_->buffer()->isReadonly() );
116 void FormRef::updateBrowser( vector<string> keys ) const
118 if ( fl_get_button( dialog_->sort ) )
119 sort( keys.begin(), keys.end() );
121 fl_clear_browser( dialog_->browser );
122 for( vector<string>::const_iterator it = keys.begin();
123 it != keys.end(); ++it )
124 fl_add_browser_line( dialog_->browser, (*it).c_str());
126 if ( keys.empty() ) {
127 fl_add_browser_line( dialog_->browser,
128 _("*** No labels found in document ***"));
130 fl_deactivate_object( dialog_->browser );
131 fl_deactivate_object( dialog_->button_update );
132 fl_deactivate_object( dialog_->sort );
133 fl_set_object_lcol( dialog_->browser, FL_INACTIVE );
134 fl_set_object_lcol( dialog_->button_update, FL_INACTIVE );
135 fl_set_object_lcol( dialog_->sort, FL_INACTIVE );
137 fl_set_browser_topline( dialog_->browser, 1 );
138 fl_activate_object( dialog_->browser );
139 fl_set_object_lcol( dialog_->browser, FL_BLACK );
140 fl_activate_object( dialog_->button_update );
141 fl_set_object_lcol( dialog_->button_update, FL_BLACK );
142 fl_activate_object( dialog_->sort );
143 fl_set_object_lcol( dialog_->sort, FL_BLACK );
148 void FormRef::showBrowser() const
150 fl_show_object( dialog_->browser );
151 fl_show_object( dialog_->button_update );
152 fl_show_object( dialog_->sort );
154 setSize( formw, formh, 0 );
156 fl_deactivate_object( dialog_->type );
157 fl_set_object_lcol( dialog_->type, FL_INACTIVE );
158 fl_deactivate_object( dialog_->button_go );
159 fl_set_object_lcol( dialog_->button_go, FL_INACTIVE );
160 fl_set_object_lcol( dialog_->ref, FL_INACTIVE );
165 void FormRef::hideBrowser() const
167 fl_hide_object( dialog_->browser );
168 fl_hide_object( dialog_->button_update );
169 fl_hide_object( dialog_->sort );
171 setSize( 250, formh, 280 );
173 fl_activate_object( dialog_->type );
174 fl_set_object_lcol( dialog_->type, FL_BLACK );
175 fl_activate_object( dialog_->button_go );
176 fl_set_object_lcol( dialog_->button_go, FL_BLACK );
177 fl_set_object_lcol( dialog_->ref, FL_BLACK );
182 void FormRef::setSize( int w, int h, int dx ) const
184 static int x1 = dialog_->name->x;
185 static int y1 = dialog_->name->y;
186 static int x2 = dialog_->ref->x;
187 static int y2 = dialog_->ref->y;
188 static int x3 = dialog_->type->x;
189 static int y3 = dialog_->type->y;
190 static int x4 = dialog_->button_go->x;
191 static int y4 = dialog_->button_go->y;
192 static int x5 = dialog_->button_ok->x;
193 static int y5 = dialog_->button_ok->y;
194 static int x6 = dialog_->button_cancel->x;
195 static int y6 = dialog_->button_cancel->y;
197 if ( form()->w != w )
198 fl_set_form_size( form(), w, h );
200 fl_set_form_minsize( form(), w, h );
201 fl_set_form_maxsize( form(), 2*w, h );
203 if ( form()->w == w ) return;
205 fl_set_object_position( dialog_->name, x1-dx, y1 );
206 fl_set_object_position( dialog_->ref, x2-dx, y2 );
207 fl_set_object_position( dialog_->type, x3-dx, y3 );
208 fl_set_object_position( dialog_->button_go, x4-dx, y4 );
209 fl_set_object_position( dialog_->button_ok, x5-dx, y5 );
210 fl_set_object_position( dialog_->button_cancel, x6-dx, y6 );
212 // These two must be reset apparently
213 // Name is irrelevant to LaTeX documents
214 if ( lv_->buffer()->isLatex() ) {
215 fl_deactivate_object( dialog_->name );
216 fl_set_object_lcol( dialog_->name, FL_INACTIVE );
219 // Can change reference only through browser
220 fl_deactivate_object( dialog_->ref );
224 void FormRef::apply()
226 if (!lv_->view()->available())
229 Type const type = static_cast<Type>(fl_get_choice(dialog_->type) - 1);
230 params.setCmdName(getName(type));
232 params.setOptions(fl_get_input(dialog_->name));
235 // Only update if contents have changed
236 if (params != inset_->params()) {
237 inset_->setParams(params);
238 lv_->view()->updateInset(inset_, true);
241 lv_->getLyXFunc()->Dispatch(LFUN_REF_INSERT,
242 params.getAsString());
248 #warning check use of buttoncontroller
249 // Seems okay except that goref and goback shouldn't
250 // affect the status of ok.
252 bool FormRef::input( FL_OBJECT *, long data )
254 bool activate( true );
256 // goto reference / go back
259 toggle = static_cast<Goto>(toggle + 1);
260 if ( toggle == GOFIRST ) toggle = GOREF;
266 Dispatch(LFUN_REF_GOTO,
267 params.getContents());
268 fl_set_object_label(dialog_->button_go, _("Go back"));
274 lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK);
275 fl_set_object_label(dialog_->button_go, _("Goto reference"));
285 // choose browser key
288 unsigned int sel = fl_get_browser( dialog_->browser );
289 if ( sel < 1 || sel > refs.size() ) break;
291 string s = fl_get_browser_line( dialog_->browser, sel );
292 fl_set_input( dialog_->ref, s.c_str());
293 params.setContents( s );
296 lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK);
297 fl_set_object_label(dialog_->button_go, _("Goto reference"));
299 fl_activate_object( dialog_->type );
300 fl_set_object_lcol( dialog_->type, FL_BLACK );
301 fl_activate_object( dialog_->button_go );
302 fl_set_object_lcol( dialog_->button_go, FL_BLACK );
303 fl_set_object_lcol( dialog_->ref, FL_BLACK );
310 fl_freeze_form( form() );
311 updateBrowser( refs );
312 fl_unfreeze_form( form() );
316 // changed reference type
319 Type type = static_cast<Type>( fl_get_choice(dialog_->type)-1 );
320 if ( params.getCmdName() == getName( type )
334 FormRef::Type FormRef::getType() const
338 if ( params.getCmdName() == "ref" )
341 else if ( params.getCmdName() == "pageref" )
344 else if ( params.getCmdName() == "vref" )
347 else if ( params.getCmdName() == "vpageref" )
357 string FormRef::getName( Type type ) const