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 FormRef::FormRef(LyXView * lv, Dialogs * d)
34 : FormCommand(lv, d, _("Reference")), toggle(GOBACK), dialog_(0)
36 // let the dialog be shown
37 // These are permanent connections so we won't bother
38 // storing a copy because we won't be disconnecting.
39 d->showRef.connect(slot(this, &FormRef::showInset));
40 d->createRef.connect(slot(this, &FormRef::createInset));
50 FL_FORM * FormRef::form() const
52 if ( dialog_ ) return dialog_->form;
57 void FormRef::connect()
59 fl_set_form_maxsize( form(), 2*minw_, minh_ );
60 FormCommand::connect();
64 void FormRef::disconnect()
67 FormCommand::disconnect();
73 dialog_ = build_ref();
75 fl_addto_choice(dialog_->type,
76 _(" Ref | Page | TextRef | TextPage | PrettyRef "));
78 // Workaround dumb xforms sizing bug
82 // Name is irrelevant to LaTeX documents
83 if ( lv_->buffer()->isLatex() ) {
84 fl_deactivate_object( dialog_->name );
85 fl_set_object_lcol( dialog_->name, FL_INACTIVE );
88 // Can change reference only through browser
89 fl_deactivate_object( dialog_->ref );
91 bc_.setOK( dialog_->button_ok );
92 bc_.setCancel( dialog_->button_cancel );
93 bc_.addReadOnly( dialog_->type );
98 void FormRef::update()
100 fl_set_input(dialog_->ref, params.getContents().c_str());
101 fl_set_input(dialog_->name, params.getOptions().c_str());
103 Type type = getType();
104 fl_set_choice( dialog_->type, type+1 );
107 fl_set_object_label(dialog_->button_go, _("Goto reference"));
111 refs = lv_->buffer()->getLabelList();
112 updateBrowser( refs );
117 bc_.readOnly( lv_->buffer()->isReadonly() );
121 void FormRef::updateBrowser( vector<string> keys ) const
123 if ( fl_get_button( dialog_->sort ) )
124 sort( keys.begin(), keys.end() );
126 fl_clear_browser( dialog_->browser );
127 for( vector<string>::const_iterator it = keys.begin();
128 it != keys.end(); ++it )
129 fl_add_browser_line( dialog_->browser, (*it).c_str());
131 if ( keys.empty() ) {
132 fl_add_browser_line( dialog_->browser,
133 _("*** No labels found in document ***"));
135 fl_deactivate_object( dialog_->browser );
136 fl_deactivate_object( dialog_->button_update );
137 fl_deactivate_object( dialog_->sort );
138 fl_set_object_lcol( dialog_->browser, FL_INACTIVE );
139 fl_set_object_lcol( dialog_->button_update, FL_INACTIVE );
140 fl_set_object_lcol( dialog_->sort, FL_INACTIVE );
142 fl_set_browser_topline( dialog_->browser, 1 );
143 fl_activate_object( dialog_->browser );
144 fl_set_object_lcol( dialog_->browser, FL_BLACK );
145 fl_activate_object( dialog_->button_update );
146 fl_set_object_lcol( dialog_->button_update, FL_BLACK );
147 fl_activate_object( dialog_->sort );
148 fl_set_object_lcol( dialog_->sort, FL_BLACK );
153 void FormRef::showBrowser() const
155 fl_show_object( dialog_->browser );
156 fl_show_object( dialog_->button_update );
157 fl_show_object( dialog_->sort );
159 setSize( minw_, minh_, 0 );
161 fl_deactivate_object( dialog_->type );
162 fl_set_object_lcol( dialog_->type, FL_INACTIVE );
163 fl_deactivate_object( dialog_->button_go );
164 fl_set_object_lcol( dialog_->button_go, FL_INACTIVE );
165 fl_set_object_lcol( dialog_->ref, FL_INACTIVE );
170 void FormRef::hideBrowser() const
172 fl_hide_object( dialog_->browser );
173 fl_hide_object( dialog_->button_update );
174 fl_hide_object( dialog_->sort );
176 setSize( 250, minh_, 280 );
178 fl_activate_object( dialog_->type );
179 fl_set_object_lcol( dialog_->type, FL_BLACK );
180 fl_activate_object( dialog_->button_go );
181 fl_set_object_lcol( dialog_->button_go, FL_BLACK );
182 fl_set_object_lcol( dialog_->ref, FL_BLACK );
187 void FormRef::setSize( int w, int h, int dx ) const
189 static int x1 = dialog_->name->x;
190 static int y1 = dialog_->name->y;
191 static int x2 = dialog_->ref->x;
192 static int y2 = dialog_->ref->y;
193 static int x3 = dialog_->type->x;
194 static int y3 = dialog_->type->y;
195 static int x4 = dialog_->button_go->x;
196 static int y4 = dialog_->button_go->y;
197 static int x5 = dialog_->button_ok->x;
198 static int y5 = dialog_->button_ok->y;
199 static int x6 = dialog_->button_cancel->x;
200 static int y6 = dialog_->button_cancel->y;
202 if ( form()->w != w ) {
205 fl_set_form_size( form(), minw_, minh_ );
209 fl_set_object_position( dialog_->name, x1-dx, y1 );
210 fl_set_object_position( dialog_->ref, x2-dx, y2 );
211 fl_set_object_position( dialog_->type, x3-dx, y3 );
212 fl_set_object_position( dialog_->button_go, x4-dx, y4 );
213 fl_set_object_position( dialog_->button_ok, x5-dx, y5 );
214 fl_set_object_position( dialog_->button_cancel, x6-dx, y6 );
216 // These two must be reset apparently
217 // Name is irrelevant to LaTeX documents
218 if ( lv_->buffer()->isLatex() ) {
219 fl_deactivate_object( dialog_->name );
220 fl_set_object_lcol( dialog_->name, FL_INACTIVE );
223 // Can change reference only through browser
224 fl_deactivate_object( dialog_->ref );
228 void FormRef::apply()
230 if (!lv_->view()->available())
233 Type const type = static_cast<Type>(fl_get_choice(dialog_->type) - 1);
234 params.setCmdName(getName(type));
236 params.setOptions(fl_get_input(dialog_->name));
239 // Only update if contents have changed
240 if (params != inset_->params()) {
241 inset_->setParams(params);
242 lv_->view()->updateInset(inset_, true);
245 lv_->getLyXFunc()->Dispatch(LFUN_REF_INSERT,
246 params.getAsString());
252 #warning check use of buttoncontroller
253 // Seems okay except that goref and goback shouldn't
254 // affect the status of ok.
256 bool FormRef::input( FL_OBJECT *, long data )
258 bool activate( true );
260 // goto reference / go back
263 toggle = static_cast<Goto>(toggle + 1);
264 if ( toggle == GOFIRST ) toggle = GOREF;
270 Dispatch(LFUN_REF_GOTO,
271 params.getContents());
272 fl_set_object_label(dialog_->button_go, _("Go back"));
278 lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK);
279 fl_set_object_label(dialog_->button_go,
280 _("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_->button_go, _("Goto reference"));
304 fl_activate_object( dialog_->type );
305 fl_set_object_lcol( dialog_->type, FL_BLACK );
306 fl_activate_object( dialog_->button_go );
307 fl_set_object_lcol( dialog_->button_go, 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>(
325 fl_get_choice(dialog_->type) - 1 );
326 if ( params.getCmdName() == getName( type )
340 FormRef::Type FormRef::getType() const
344 if ( params.getCmdName() == "ref" )
347 else if ( params.getCmdName() == "pageref" )
350 else if ( params.getCmdName() == "vref" )
353 else if ( params.getCmdName() == "vpageref" )
363 string FormRef::getName( Type type ) const