]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormUrl.C
patch from Angus
[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 "BufferView.h"
23 #include "Dialogs.h"
24 #include "FormUrl.h"
25 #include "LyXView.h"
26 #include "buffer.h"
27 #include "form_url.h"
28 #include "lyxfunc.h"
29 #include "xform_macros.h"
30 #include "insets/insetcommand.h"
31 #include "insets/inseturl.h"
32 #include "support/filetools.h"
33
34 FormUrl::FormUrl(LyXView * lv, Dialogs * d)
35         : FormCommand(lv, d, _("Url"))
36 {
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));
42 }
43
44
45 FormUrl::~FormUrl()
46 {
47         free();
48         delete dialog_;
49 }
50
51
52 void FormUrl::build()
53 {
54         dialog_ = build_url();
55 }
56
57
58 FL_FORM * const FormUrl::form() const
59 {
60         if( dialog_ && dialog_->form_url )
61                 return dialog_->form_url;
62         else
63                 return 0;
64 }
65
66
67 void FormUrl::update()
68 {
69         static int ow = -1, oh;
70
71         if (ow < 0) {
72                 ow = dialog_->form_url->w;
73                 oh = dialog_->form_url->h;
74
75                 fl_set_form_minsize(dialog_->form_url, ow, oh);
76                 fl_set_form_maxsize(dialog_->form_url, 2*ow, oh);
77         }
78
79         fl_freeze_form( dialog_->form_url );
80
81         fl_set_input(dialog_->url,  params.getContents().c_str());
82         fl_set_input(dialog_->name, params.getOptions().c_str());
83
84         if ( params.getCmdName() == "url" )
85                 fl_set_button(dialog_->radio_html, 0);
86         else
87                 fl_set_button(dialog_->radio_html, 1);
88
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 );
95         } else {
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 );
101         }
102
103         fl_unfreeze_form( dialog_->form_url );
104 }
105
106
107 void FormUrl::apply()
108 {
109         if( lv_->buffer()->isReadonly() ) return;
110
111         params.setContents( fl_get_input(dialog_->url) );
112         params.setOptions( fl_get_input(dialog_->name) );
113
114         if (fl_get_button(dialog_->radio_html))
115                 params.setCmdName("htmlurl");
116         else
117                 params.setCmdName("url");
118
119         if( inset_ != 0 )
120         {
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 );
127                 }
128         } else {
129                 lv_->getLyXFunc()->Dispatch( LFUN_INSERT_URL,
130                                              params.getAsString().c_str() );
131         }
132 }