]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormUrl.C
Angus insetindex patch + protect patch from Dekel
[lyx.git] / src / frontends / xforms / FormUrl.C
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2000 The LyX Team.
8  *
9  * ======================================================
10  */
11
12 #include <config.h>
13
14 #include FORMS_H_LOCATION
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20
21 #include "gettext.h"
22 #include "Dialogs.h"
23 #include "FormUrl.h"
24 #include "LyXView.h"
25 #include "buffer.h"
26 #include "form_url.h"
27 #include "lyxfunc.h"
28
29 FormUrl::FormUrl(LyXView * lv, Dialogs * d)
30         : FormCommand(lv, d, _("Url")), dialog_(0)
31 {
32         // let the dialog be shown
33         // These are permanent connections so we won't bother
34         // storing a copy because we won't be disconnecting.
35         d->showUrl.connect(slot(this, &FormUrl::showInset));
36         d->createUrl.connect(slot(this, &FormUrl::createInset));
37 }
38
39
40 FormUrl::~FormUrl()
41 {
42         delete dialog_;
43 }
44
45
46 void FormUrl::build()
47 {
48         dialog_ = build_url();
49 }
50
51
52 FL_FORM * const FormUrl::form() const
53 {
54         if( dialog_ && dialog_->form_url )
55                 return dialog_->form_url;
56         else
57                 return 0;
58 }
59
60
61 void FormUrl::update()
62 {
63         static int ow = -1, oh;
64
65         if (ow < 0) {
66                 ow = dialog_->form_url->w;
67                 oh = dialog_->form_url->h;
68
69                 fl_set_form_minsize(dialog_->form_url, ow, oh);
70                 fl_set_form_maxsize(dialog_->form_url, 2*ow, oh);
71         }
72
73         fl_freeze_form( dialog_->form_url );
74
75         fl_set_input(dialog_->url,  params.getContents().c_str());
76         fl_set_input(dialog_->name, params.getOptions().c_str());
77
78         if ( params.getCmdName() == "url" )
79                 fl_set_button(dialog_->radio_html, 0);
80         else
81                 fl_set_button(dialog_->radio_html, 1);
82
83         if( lv_->buffer()->isReadonly() ) {
84                 fl_deactivate_object( dialog_->url );
85                 fl_deactivate_object( dialog_->name );
86                 fl_deactivate_object( dialog_->radio_html );
87                 fl_deactivate_object( dialog_->ok );
88                 fl_set_object_lcol( dialog_->ok, FL_INACTIVE );
89         } else {
90                 fl_activate_object( dialog_->url );
91                 fl_activate_object( dialog_->name );
92                 fl_activate_object( dialog_->radio_html );
93                 fl_activate_object( dialog_->ok );
94                 fl_set_object_lcol( dialog_->ok, FL_BLACK );
95         }
96
97         fl_unfreeze_form( dialog_->form_url );
98 }
99
100
101 void FormUrl::apply()
102 {
103         if( lv_->buffer()->isReadonly() ) return;
104
105         params.setContents( fl_get_input(dialog_->url) );
106         params.setOptions( fl_get_input(dialog_->name) );
107
108         if (fl_get_button(dialog_->radio_html))
109                 params.setCmdName("htmlurl");
110         else
111                 params.setCmdName("url");
112
113         if( inset_ != 0 )
114         {
115                 // Only update if contents have changed
116                 if( params.getCmdName()  != inset_->getCmdName()  ||
117                     params.getContents() != inset_->getContents() ||
118                     params.getOptions()  != inset_->getOptions() ) {
119                         inset_->setParams( params );
120                         lv_->view()->updateInset( inset_, true );
121                 }
122         } else {
123                 lv_->getLyXFunc()->Dispatch( LFUN_INSERT_URL,
124                                              params.getAsString().c_str() );
125         }
126 }