]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormUrl.C
Merging BRANCH_MVC back into HEAD.
[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 FormUrl::FormUrl(LyXView * lv, Dialogs * d)
28         : FormCommand(lv, d, _("Url"))
29 {
30         // let the dialog be shown
31         // These are permanent connections so we won't bother
32         // storing a copy because we won't be disconnecting.
33         d->showUrl.connect(slot(this, &FormUrl::showInset));
34         d->createUrl.connect(slot(this, &FormUrl::createInset));
35 }
36
37
38 FL_FORM * FormUrl::form() const
39 {
40         if (dialog_.get()) return dialog_->form;
41         return 0;
42 }
43
44
45 void FormUrl::connect()
46 {
47         fl_set_form_maxsize(form(), 2 * minw_, minh_);
48         FormCommand::connect();
49 }
50         
51
52 void FormUrl::build()
53 {
54         dialog_.reset(build_url());
55
56         // Workaround dumb xforms sizing bug
57         minw_ = form()->w;
58         minh_ = form()->h;
59
60         fl_set_input_return(dialog_->name, FL_RETURN_CHANGED);
61         fl_set_input_return(dialog_->url,  FL_RETURN_CHANGED);
62
63         // Manage the ok, apply, restore and cancel/close buttons
64         bc().setOK(dialog_->button_ok);
65         bc().setApply(dialog_->button_apply);
66         bc().setCancel(dialog_->button_cancel);
67         bc().setUndoAll(dialog_->button_restore);
68         bc().refresh();
69
70         bc().addReadOnly(dialog_->name);
71         bc().addReadOnly(dialog_->url);
72         bc().addReadOnly(dialog_->radio_html);
73 }
74
75
76 void FormUrl::update()
77 {
78         fl_set_input(dialog_->url,  params.getContents().c_str());
79         fl_set_input(dialog_->name, params.getOptions().c_str());
80
81         if (params.getCmdName() == "url")
82                 fl_set_button(dialog_->radio_html, 0);
83         else
84                 fl_set_button(dialog_->radio_html, 1);
85
86         bc().readOnly(lv_->buffer()->isReadonly());
87 }
88
89
90 void FormUrl::apply()
91 {
92         if (lv_->buffer()->isReadonly()) return;
93
94         params.setContents(fl_get_input(dialog_->url));
95         params.setOptions(fl_get_input(dialog_->name));
96
97         if (fl_get_button(dialog_->radio_html))
98                 params.setCmdName("htmlurl");
99         else
100                 params.setCmdName("url");
101
102         if (inset_ != 0) {
103                 // Only update if contents have changed
104                 if (params != inset_->params()) {
105                         inset_->setParams(params);
106                         lv_->view()->updateInset(inset_, true);
107                 }
108         } else {
109                 lv_->getLyXFunc()->Dispatch(LFUN_INSERT_URL,
110                                             params.getAsString());
111         }
112 }