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")), 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::disconnect()
63 FormCommand::disconnect();
69 dialog_ = build_ref();
71 fl_addto_choice(dialog_->type,
72 _(" Ref | Page | TextRef | TextPage | PrettyRef "));
74 // XFORMS bug workaround
75 // Define the min/max dimensions. Actually applied in update()
76 formw = form()->w, formh = form()->h;
78 // Name is irrelevant to LaTeX documents
79 if ( lv_->buffer()->isLatex() ) {
80 fl_deactivate_object( dialog_->name );
81 fl_set_object_lcol( dialog_->name, FL_INACTIVE );
84 // Can change reference only through browser
85 fl_deactivate_object( dialog_->ref );
87 bc_.setOK( dialog_->button_ok );
88 bc_.setCancel( dialog_->button_cancel );
89 bc_.addReadOnly( dialog_->type );
94 void FormRef::update(bool switched)
101 fl_set_input(dialog_->ref, params.getContents().c_str());
102 fl_set_input(dialog_->name, params.getOptions().c_str());
104 Type type = getType();
105 fl_set_choice( dialog_->type, type+1 );
108 fl_set_object_label(dialog_->button_go, _("Goto reference"));
112 refs = lv_->buffer()->getLabelList();
113 updateBrowser( refs );
118 bc_.readOnly( lv_->buffer()->isReadonly() );
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());
132 if ( keys.empty() ) {
133 fl_add_browser_line( dialog_->browser,
134 _("*** No labels found in document ***"));
136 fl_deactivate_object( dialog_->browser );
137 fl_deactivate_object( dialog_->button_update );
138 fl_deactivate_object( dialog_->sort );
139 fl_set_object_lcol( dialog_->browser, FL_INACTIVE );
140 fl_set_object_lcol( dialog_->button_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_->button_update );
147 fl_set_object_lcol( dialog_->button_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_->button_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_->button_go );
165 fl_set_object_lcol( dialog_->button_go, FL_INACTIVE );
166 fl_set_object_lcol( dialog_->ref, FL_INACTIVE );
171 void FormRef::hideBrowser() const
173 fl_hide_object( dialog_->browser );
174 fl_hide_object( dialog_->button_update );
175 fl_hide_object( dialog_->sort );
177 setSize( 250, formh, 280 );
179 fl_activate_object( dialog_->type );
180 fl_set_object_lcol( dialog_->type, FL_BLACK );
181 fl_activate_object( dialog_->button_go );
182 fl_set_object_lcol( dialog_->button_go, FL_BLACK );
183 fl_set_object_lcol( dialog_->ref, FL_BLACK );
188 void FormRef::setSize( int w, int h, int dx ) const
190 static int x1 = dialog_->name->x;
191 static int y1 = dialog_->name->y;
192 static int x2 = dialog_->ref->x;
193 static int y2 = dialog_->ref->y;
194 static int x3 = dialog_->type->x;
195 static int y3 = dialog_->type->y;
196 static int x4 = dialog_->button_go->x;
197 static int y4 = dialog_->button_go->y;
198 static int x5 = dialog_->button_ok->x;
199 static int y5 = dialog_->button_ok->y;
200 static int x6 = dialog_->button_cancel->x;
201 static int y6 = dialog_->button_cancel->y;
203 if ( form()->w != w )
204 fl_set_form_size( form(), w, h );
206 fl_set_form_minsize( form(), w, h );
207 fl_set_form_maxsize( form(), 2*w, h );
209 if ( form()->w == w ) return;
211 fl_set_object_position( dialog_->name, x1-dx, y1 );
212 fl_set_object_position( dialog_->ref, x2-dx, y2 );
213 fl_set_object_position( dialog_->type, x3-dx, y3 );
214 fl_set_object_position( dialog_->button_go, x4-dx, y4 );
215 fl_set_object_position( dialog_->button_ok, x5-dx, y5 );
216 fl_set_object_position( dialog_->button_cancel, x6-dx, y6 );
218 // These two must be reset apparently
219 // Name is irrelevant to LaTeX documents
220 if ( lv_->buffer()->isLatex() ) {
221 fl_deactivate_object( dialog_->name );
222 fl_set_object_lcol( dialog_->name, FL_INACTIVE );
225 // Can change reference only through browser
226 fl_deactivate_object( dialog_->ref );
230 void FormRef::apply()
232 if (!lv_->view()->available())
235 Type const type = static_cast<Type>(fl_get_choice(dialog_->type) - 1);
236 params.setCmdName(getName(type));
238 params.setOptions(fl_get_input(dialog_->name));
241 // Only update if contents have changed
242 if (params != inset_->params()) {
243 inset_->setParams(params);
244 lv_->view()->updateInset(inset_, true);
247 lv_->getLyXFunc()->Dispatch(LFUN_REF_INSERT,
248 params.getAsString());
254 #warning check use of buttoncontroller
255 // Seems okay except that goref and goback shouldn't
256 // affect the status of ok.
258 bool FormRef::input( FL_OBJECT *, long data )
260 bool activate( true );
262 // goto reference / go back
265 toggle = static_cast<Goto>(toggle + 1);
266 if ( toggle == GOFIRST ) toggle = GOREF;
272 Dispatch(LFUN_REF_GOTO,
273 params.getContents());
274 fl_set_object_label(dialog_->button_go, _("Go back"));
280 lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK);
281 fl_set_object_label(dialog_->button_go,
282 _("Goto reference"));
292 // choose browser key
295 unsigned int sel = fl_get_browser( dialog_->browser );
296 if ( sel < 1 || sel > refs.size() ) break;
298 string s = fl_get_browser_line( dialog_->browser, sel );
299 fl_set_input( dialog_->ref, s.c_str());
300 params.setContents( s );
303 lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK);
304 fl_set_object_label(dialog_->button_go, _("Goto reference"));
306 fl_activate_object( dialog_->type );
307 fl_set_object_lcol( dialog_->type, FL_BLACK );
308 fl_activate_object( dialog_->button_go );
309 fl_set_object_lcol( dialog_->button_go, 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>(
327 fl_get_choice(dialog_->type) - 1 );
328 if ( params.getCmdName() == getName( type )
342 FormRef::Type FormRef::getType() const
346 if ( params.getCmdName() == "ref" )
349 else if ( params.getCmdName() == "pageref" )
352 else if ( params.getCmdName() == "vref" )
355 else if ( params.getCmdName() == "vpageref" )
365 string FormRef::getName( Type type ) const