]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormUrl.C
d5a99291ff1721b5e839821af0b11a0bc8f5f843
[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         free();
43         delete dialog_;
44 }
45
46
47 void FormUrl::build()
48 {
49         dialog_ = build_url();
50 }
51
52
53 FL_FORM * const FormUrl::form() const
54 {
55         if( dialog_ && dialog_->form_url )
56                 return dialog_->form_url;
57         else
58                 return 0;
59 }
60
61
62 void FormUrl::update()
63 {
64         static int ow = -1, oh;
65
66         if (ow < 0) {
67                 ow = dialog_->form_url->w;
68                 oh = dialog_->form_url->h;
69
70                 fl_set_form_minsize(dialog_->form_url, ow, oh);
71                 fl_set_form_maxsize(dialog_->form_url, 2*ow, oh);
72         }
73
74         fl_freeze_form( dialog_->form_url );
75
76         fl_set_input(dialog_->url,  params.getContents().c_str());
77         fl_set_input(dialog_->name, params.getOptions().c_str());
78
79         if ( params.getCmdName() == "url" )
80                 fl_set_button(dialog_->radio_html, 0);
81         else
82                 fl_set_button(dialog_->radio_html, 1);
83
84         if( lv_->buffer()->isReadonly() ) {
85                 fl_deactivate_object( dialog_->url );
86                 fl_deactivate_object( dialog_->name );
87                 fl_deactivate_object( dialog_->radio_html );
88                 fl_deactivate_object( dialog_->ok );
89                 fl_set_object_lcol( dialog_->ok, FL_INACTIVE );
90         } else {
91                 fl_activate_object( dialog_->url );
92                 fl_activate_object( dialog_->name );
93                 fl_activate_object( dialog_->radio_html );
94                 fl_activate_object( dialog_->ok );
95                 fl_set_object_lcol( dialog_->ok, FL_BLACK );
96         }
97
98         fl_unfreeze_form( dialog_->form_url );
99 }
100
101
102 void FormUrl::apply()
103 {
104         if( lv_->buffer()->isReadonly() ) return;
105
106         params.setContents( fl_get_input(dialog_->url) );
107         params.setOptions( fl_get_input(dialog_->name) );
108
109         if (fl_get_button(dialog_->radio_html))
110                 params.setCmdName("htmlurl");
111         else
112                 params.setCmdName("url");
113
114         if( inset_ != 0 )
115         {
116                 // Only update if contents have changed
117                 if( params.getCmdName()  != inset_->getCmdName()  ||
118                     params.getContents() != inset_->getContents() ||
119                     params.getOptions()  != inset_->getOptions() ) {
120                         inset_->setParams( params );
121                         lv_->view()->updateInset( inset_, true );
122                 }
123         } else {
124                 lv_->getLyXFunc()->Dispatch( LFUN_INSERT_URL,
125                                              params.getAsString().c_str() );
126         }
127 }