2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000 The LyX Team.
9 * ======================================================
14 #include FORMS_H_LOCATION
15 #include "BufferView.h"
22 #include "xform_macros.h"
23 #include "insets/insetcommand.h"
24 #include "insets/inseturl.h"
25 #include "support/filetools.h"
28 #pragma implementation
31 C_RETURNCB(FormUrl, WMHideCB)
32 C_GENERICCB(FormUrl, OKCB)
33 C_GENERICCB(FormUrl, CancelCB)
35 FormUrl::FormUrl(LyXView * lv, Dialogs * d)
36 : dialog_(0), lv_(lv), d_(d), u_(0), h_(0), ih_(0),
37 inset_(0), dialogIsOpen(false)
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->showUrl.connect(slot(this, &FormUrl::showInset));
43 d->createUrl.connect(slot(this, &FormUrl::createInset));
44 params = new InsetCommandParams();
57 dialog_ = build_url();
61 void FormUrl::showInset( InsetUrl * inset )
63 if( dialogIsOpen || inset == 0 ) return;
66 ih_ = inset_->hide.connect(slot(this, &FormUrl::hide));
68 (*params) = inset->params();
73 void FormUrl::createInset( string const & arg )
75 if( dialogIsOpen ) return;
77 params->setFromString( arg );
86 fl_set_form_atclose(dialog_->form_url,
87 C_FormUrlWMHideCB, 0);
90 update(); // make sure its up-to-date
93 if (dialog_->form_url->visible) {
94 fl_raise_form(dialog_->form_url);
96 fl_show_form(dialog_->form_url,
97 FL_PLACE_MOUSE | FL_FREE_SIZE,
100 u_ = d_->updateBufferDependent.
101 connect(slot(this, &FormUrl::update));
102 h_ = d_->hideBufferDependent.
103 connect(slot(this, &FormUrl::hide));
108 void FormUrl::update()
110 fl_set_input(dialog_->url, params->getContents().c_str());
111 fl_set_input(dialog_->name, params->getOptions().c_str());
113 if ( params->getCmdName() == "url" )
114 fl_set_button(dialog_->radio_html, 0);
116 fl_set_button(dialog_->radio_html, 1);
118 static int ow = -1, oh;
121 ow = dialog_->form_url->w;
122 oh = dialog_->form_url->h;
125 fl_set_form_minsize(dialog_->form_url, ow, oh);
126 fl_set_form_maxsize(dialog_->form_url, 2*ow, oh);
130 void FormUrl::apply()
132 if( lv_->buffer()->isReadonly() ) return;
134 params->setContents( fl_get_input(dialog_->url) );
135 params->setOptions( fl_get_input(dialog_->name) );
137 if (fl_get_button(dialog_->radio_html))
138 params->setCmdName("htmlurl");
140 params->setCmdName("url");
144 inset_->setParams( *params );
145 lv_->view()->updateInset( inset_, true );
147 lv_->getLyXFunc()->Dispatch( LFUN_INSERT_URL,
148 params->getAsString().c_str() );
157 && dialog_->form_url->visible) {
158 fl_hide_form(dialog_->form_url);
163 // free up the dialog for another inset
166 dialogIsOpen = false;
172 // we don't need to delete u and h here because
173 // hide() does that after disconnecting.
175 if (dialog_->form_url
176 && dialog_->form_url->visible) {
179 fl_free_form(dialog_->form_url);
186 int FormUrl::WMHideCB(FL_FORM * form, void *)
188 // Ensure that the signals (u and h) are disconnected even if the
189 // window manager is used to close the dialog.
190 FormUrl * pre = static_cast<FormUrl*>(form->u_vdata);
196 void FormUrl::OKCB(FL_OBJECT * ob, long)
198 FormUrl * pre = static_cast<FormUrl*>(ob->form->u_vdata);
204 void FormUrl::CancelCB(FL_OBJECT * ob, long)
206 FormUrl * pre = static_cast<FormUrl*>(ob->form->u_vdata);