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
22 #include "BufferView.h"
29 #include "xform_macros.h"
30 #include "insets/insetcommand.h"
31 #include "insets/inseturl.h"
32 #include "support/filetools.h"
34 C_RETURNCB(FormUrl, WMHideCB)
35 C_GENERICCB(FormUrl, OKCB)
36 C_GENERICCB(FormUrl, CancelCB)
38 FormUrl::FormUrl(LyXView * lv, Dialogs * d)
39 : dialog_(0), lv_(lv), d_(d), u_(0), h_(0), ih_(0),
40 inset_(0), dialogIsOpen(false)
42 // let the dialog be shown
43 // These are permanent connections so we won't bother
44 // storing a copy because we won't be disconnecting.
45 d->showUrl.connect(slot(this, &FormUrl::showInset));
46 d->createUrl.connect(slot(this, &FormUrl::createInset));
47 params = new InsetCommandParams();
60 dialog_ = build_url();
64 void FormUrl::showInset( InsetUrl * inset )
66 if( dialogIsOpen || inset == 0 ) return;
69 ih_ = inset_->hide.connect(slot(this, &FormUrl::hide));
71 (*params) = inset->params();
76 void FormUrl::createInset( string const & arg )
78 if( dialogIsOpen ) return;
80 params->setFromString( arg );
89 fl_set_form_atclose(dialog_->form_url,
90 C_FormUrlWMHideCB, 0);
93 update(); // make sure its up-to-date
96 if (dialog_->form_url->visible) {
97 fl_raise_form(dialog_->form_url);
99 fl_show_form(dialog_->form_url,
100 FL_PLACE_MOUSE | FL_FREE_SIZE,
103 u_ = d_->updateBufferDependent.
104 connect(slot(this, &FormUrl::update));
105 h_ = d_->hideBufferDependent.
106 connect(slot(this, &FormUrl::hide));
111 void FormUrl::update()
113 fl_set_input(dialog_->url, params->getContents().c_str());
114 fl_set_input(dialog_->name, params->getOptions().c_str());
116 if ( params->getCmdName() == "url" )
117 fl_set_button(dialog_->radio_html, 0);
119 fl_set_button(dialog_->radio_html, 1);
121 static int ow = -1, oh;
124 ow = dialog_->form_url->w;
125 oh = dialog_->form_url->h;
128 fl_set_form_minsize(dialog_->form_url, ow, oh);
129 fl_set_form_maxsize(dialog_->form_url, 2*ow, oh);
133 void FormUrl::apply()
135 if( lv_->buffer()->isReadonly() ) return;
137 params->setContents( fl_get_input(dialog_->url) );
138 params->setOptions( fl_get_input(dialog_->name) );
140 if (fl_get_button(dialog_->radio_html))
141 params->setCmdName("htmlurl");
143 params->setCmdName("url");
147 inset_->setParams( *params );
148 lv_->view()->updateInset( inset_, true );
150 lv_->getLyXFunc()->Dispatch( LFUN_INSERT_URL,
151 params->getAsString().c_str() );
160 && dialog_->form_url->visible) {
161 fl_hide_form(dialog_->form_url);
166 // free up the dialog for another inset
169 dialogIsOpen = false;
175 // we don't need to delete u and h here because
176 // hide() does that after disconnecting.
178 if (dialog_->form_url
179 && dialog_->form_url->visible) {
182 fl_free_form(dialog_->form_url);
189 int FormUrl::WMHideCB(FL_FORM * form, void *)
191 // Ensure that the signals (u and h) are disconnected even if the
192 // window manager is used to close the dialog.
193 FormUrl * pre = static_cast<FormUrl*>(form->u_vdata);
199 void FormUrl::OKCB(FL_OBJECT * ob, long)
201 FormUrl * pre = static_cast<FormUrl*>(ob->form->u_vdata);
207 void FormUrl::CancelCB(FL_OBJECT * ob, long)
209 FormUrl * pre = static_cast<FormUrl*>(ob->form->u_vdata);