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 FormUrl::FormUrl(LyXView * lv, Dialogs * d)
35 : FormCommand(lv, d, _("Url")), dialog_(0)
37 // let the dialog be shown
38 // These are permanent connections so we won't bother
39 // storing a copy because we won't be disconnecting.
40 d->showUrl.connect(slot(this, &FormUrl::showInset));
41 d->createUrl.connect(slot(this, &FormUrl::createInset));
54 dialog_ = build_url();
58 FL_FORM * const FormUrl::form() const
60 if( dialog_ && dialog_->form_url )
61 return dialog_->form_url;
67 void FormUrl::update()
69 static int ow = -1, oh;
72 ow = dialog_->form_url->w;
73 oh = dialog_->form_url->h;
75 fl_set_form_minsize(dialog_->form_url, ow, oh);
76 fl_set_form_maxsize(dialog_->form_url, 2*ow, oh);
79 fl_freeze_form( dialog_->form_url );
81 fl_set_input(dialog_->url, params.getContents().c_str());
82 fl_set_input(dialog_->name, params.getOptions().c_str());
84 if ( params.getCmdName() == "url" )
85 fl_set_button(dialog_->radio_html, 0);
87 fl_set_button(dialog_->radio_html, 1);
89 if( lv_->buffer()->isReadonly() ) {
90 fl_deactivate_object( dialog_->url );
91 fl_deactivate_object( dialog_->name );
92 fl_deactivate_object( dialog_->radio_html );
93 fl_deactivate_object( dialog_->ok );
94 fl_set_object_lcol( dialog_->ok, FL_INACTIVE );
96 fl_activate_object( dialog_->url );
97 fl_activate_object( dialog_->name );
98 fl_activate_object( dialog_->radio_html );
99 fl_activate_object( dialog_->ok );
100 fl_set_object_lcol( dialog_->ok, FL_BLACK );
103 fl_unfreeze_form( dialog_->form_url );
107 void FormUrl::apply()
109 if( lv_->buffer()->isReadonly() ) return;
111 params.setContents( fl_get_input(dialog_->url) );
112 params.setOptions( fl_get_input(dialog_->name) );
114 if (fl_get_button(dialog_->radio_html))
115 params.setCmdName("htmlurl");
117 params.setCmdName("url");
121 // Only update if contents have changed
122 if( params.getCmdName() != inset_->getCmdName() ||
123 params.getContents() != inset_->getContents() ||
124 params.getOptions() != inset_->getOptions() ) {
125 inset_->setParams( params );
126 lv_->view()->updateInset( inset_, true );
129 lv_->getLyXFunc()->Dispatch( LFUN_INSERT_URL,
130 params.getAsString().c_str() );