]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormUrl.C
bfcf7008385e840273a6b434ffb726754e0118bb
[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 #include "Dialogs.h"
21 #include "FormUrl.h"
22 #include "LyXView.h"
23 #include "buffer.h"
24 #include "form_url.h"
25 #include "lyxfunc.h"
26
27 using SigC::slot;
28
29 FormUrl::FormUrl(LyXView * lv, Dialogs * d)
30         : FormCommand(lv, d, _("Url"))
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 FL_FORM * FormUrl::form() const
41 {
42         if (dialog_.get()) return dialog_->form;
43         return 0;
44 }
45
46
47 void FormUrl::connect()
48 {
49         fl_set_form_maxsize(form(), 2 * minw_, minh_);
50         FormCommand::connect();
51 }
52         
53
54 void FormUrl::build()
55 {
56         dialog_.reset(build_url());
57
58         // Workaround dumb xforms sizing bug
59         minw_ = form()->w;
60         minh_ = form()->h;
61
62         fl_set_input_return(dialog_->name, FL_RETURN_CHANGED);
63         fl_set_input_return(dialog_->url,  FL_RETURN_CHANGED);
64
65         // Manage the ok, apply, restore and cancel/close buttons
66         bc().setOK(dialog_->button_ok);
67         bc().setApply(dialog_->button_apply);
68         bc().setCancel(dialog_->button_cancel);
69         bc().setUndoAll(dialog_->button_restore);
70         bc().refresh();
71
72         bc().addReadOnly(dialog_->name);
73         bc().addReadOnly(dialog_->url);
74         bc().addReadOnly(dialog_->radio_html);
75 }
76
77
78 void FormUrl::update()
79 {
80         fl_set_input(dialog_->url,  params.getContents().c_str());
81         fl_set_input(dialog_->name, params.getOptions().c_str());
82
83         if (params.getCmdName() == "url")
84                 fl_set_button(dialog_->radio_html, 0);
85         else
86                 fl_set_button(dialog_->radio_html, 1);
87
88         bc().readOnly(lv_->buffer()->isReadonly());
89 }
90
91
92 void FormUrl::apply()
93 {
94         if (lv_->buffer()->isReadonly()) return;
95
96         params.setContents(fl_get_input(dialog_->url));
97         params.setOptions(fl_get_input(dialog_->name));
98
99         if (fl_get_button(dialog_->radio_html))
100                 params.setCmdName("htmlurl");
101         else
102                 params.setCmdName("url");
103
104         if (inset_ != 0) {
105                 // Only update if contents have changed
106                 if (params != inset_->params()) {
107                         inset_->setParams(params);
108                         lv_->view()->updateInset(inset_, true);
109                 }
110         } else {
111                 lv_->getLyXFunc()->Dispatch(LFUN_INSERT_URL,
112                                             params.getAsString());
113         }
114 }