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(bool switched)
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_->button_go, _("Goto reference"));
116 refs = lv_->buffer()->getLabelList();
117 updateBrowser( refs );
122 bc_.readOnly( lv_->buffer()->isReadonly() );
126 void FormRef::updateBrowser( vector<string> keys ) const
128 if ( fl_get_button( dialog_->sort ) )
129 sort( keys.begin(), keys.end() );
131 fl_clear_browser( dialog_->browser );
132 for( vector<string>::const_iterator it = keys.begin();
133 it != keys.end(); ++it )
134 fl_add_browser_line( dialog_->browser, (*it).c_str());
136 if ( keys.empty() ) {
137 fl_add_browser_line( dialog_->browser,
138 _("*** No labels found in document ***"));
140 fl_deactivate_object( dialog_->browser );
141 fl_deactivate_object( dialog_->button_update );
142 fl_deactivate_object( dialog_->sort );
143 fl_set_object_lcol( dialog_->browser, FL_INACTIVE );
144 fl_set_object_lcol( dialog_->button_update, FL_INACTIVE );
145 fl_set_object_lcol( dialog_->sort, FL_INACTIVE );
147 fl_set_browser_topline( dialog_->browser, 1 );
148 fl_activate_object( dialog_->browser );
149 fl_set_object_lcol( dialog_->browser, FL_BLACK );
150 fl_activate_object( dialog_->button_update );
151 fl_set_object_lcol( dialog_->button_update, FL_BLACK );
152 fl_activate_object( dialog_->sort );
153 fl_set_object_lcol( dialog_->sort, FL_BLACK );
158 void FormRef::showBrowser() const
160 fl_show_object( dialog_->browser );
161 fl_show_object( dialog_->button_update );
162 fl_show_object( dialog_->sort );
164 setSize( minw_, minh_, 0 );
166 fl_deactivate_object( dialog_->type );
167 fl_set_object_lcol( dialog_->type, FL_INACTIVE );
168 fl_deactivate_object( dialog_->button_go );
169 fl_set_object_lcol( dialog_->button_go, FL_INACTIVE );
170 fl_set_object_lcol( dialog_->ref, FL_INACTIVE );
175 void FormRef::hideBrowser() const
177 fl_hide_object( dialog_->browser );
178 fl_hide_object( dialog_->button_update );
179 fl_hide_object( dialog_->sort );
181 setSize( 250, minh_, 280 );
183 fl_activate_object( dialog_->type );
184 fl_set_object_lcol( dialog_->type, FL_BLACK );
185 fl_activate_object( dialog_->button_go );
186 fl_set_object_lcol( dialog_->button_go, FL_BLACK );
187 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_->button_go->x;
201 static int y4 = dialog_->button_go->y;
202 static int x5 = dialog_->button_ok->x;
203 static int y5 = dialog_->button_ok->y;
204 static int x6 = dialog_->button_cancel->x;
205 static int y6 = dialog_->button_cancel->y;
207 if ( form()->w != w ) {
210 fl_set_form_size( form(), minw_, minh_ );
214 fl_set_object_position( dialog_->name, x1-dx, y1 );
215 fl_set_object_position( dialog_->ref, x2-dx, y2 );
216 fl_set_object_position( dialog_->type, x3-dx, y3 );
217 fl_set_object_position( dialog_->button_go, x4-dx, y4 );
218 fl_set_object_position( dialog_->button_ok, x5-dx, y5 );
219 fl_set_object_position( dialog_->button_cancel, x6-dx, y6 );
221 // These two must be reset apparently
222 // Name is irrelevant to LaTeX documents
223 if ( lv_->buffer()->isLatex() ) {
224 fl_deactivate_object( dialog_->name );
225 fl_set_object_lcol( dialog_->name, FL_INACTIVE );
228 // Can change reference only through browser
229 fl_deactivate_object( dialog_->ref );
233 void FormRef::apply()
235 if (!lv_->view()->available())
238 Type const type = static_cast<Type>(fl_get_choice(dialog_->type) - 1);
239 params.setCmdName(getName(type));
241 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());
257 #warning check use of buttoncontroller
258 // Seems okay except that goref and goback shouldn't
259 // affect the status of ok.
261 bool FormRef::input( FL_OBJECT *, long data )
263 bool activate( true );
265 // goto reference / go back
268 toggle = static_cast<Goto>(toggle + 1);
269 if ( toggle == GOFIRST ) toggle = GOREF;
275 Dispatch(LFUN_REF_GOTO,
276 params.getContents());
277 fl_set_object_label(dialog_->button_go, _("Go back"));
283 lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK);
284 fl_set_object_label(dialog_->button_go,
285 _("Goto reference"));
295 // choose browser key
298 unsigned int sel = fl_get_browser( dialog_->browser );
299 if ( sel < 1 || sel > refs.size() ) break;
301 string s = fl_get_browser_line( dialog_->browser, sel );
302 fl_set_input( dialog_->ref, s.c_str());
303 params.setContents( s );
306 lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK);
307 fl_set_object_label(dialog_->button_go, _("Goto reference"));
309 fl_activate_object( dialog_->type );
310 fl_set_object_lcol( dialog_->type, FL_BLACK );
311 fl_activate_object( dialog_->button_go );
312 fl_set_object_lcol( dialog_->button_go, FL_BLACK );
313 fl_set_object_lcol( dialog_->ref, FL_BLACK );
320 fl_freeze_form( form() );
321 updateBrowser( refs );
322 fl_unfreeze_form( form() );
326 // changed reference type
329 Type type = static_cast<Type>(
330 fl_get_choice(dialog_->type) - 1 );
331 if ( params.getCmdName() == getName( type )
345 FormRef::Type FormRef::getType() const
349 if ( params.getCmdName() == "ref" )
352 else if ( params.getCmdName() == "pageref" )
355 else if ( params.getCmdName() == "vref" )
358 else if ( params.getCmdName() == "vpageref" )
368 string FormRef::getName( Type type ) const