]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormUrl.C
Rewrote the maths panel so that ALL the popups now derive from FormBaseBD,
[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         fl_set_input_return(dialog_->name, FL_RETURN_CHANGED);
59         fl_set_input_return(dialog_->url,  FL_RETURN_CHANGED);
60
61         // Manage the ok, apply, restore and cancel/close buttons
62         bc().setOK(dialog_->button_ok);
63         bc().setApply(dialog_->button_apply);
64         bc().setCancel(dialog_->button_cancel);
65         bc().setUndoAll(dialog_->button_restore);
66         bc().refresh();
67
68         bc().addReadOnly(dialog_->name);
69         bc().addReadOnly(dialog_->url);
70         bc().addReadOnly(dialog_->radio_html);
71 }
72
73
74 void FormUrl::update()
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         bc().readOnly(lv_->buffer()->isReadonly());
85 }
86
87
88 void FormUrl::apply()
89 {
90         if (lv_->buffer()->isReadonly()) return;
91
92         params.setContents(fl_get_input(dialog_->url));
93         params.setOptions(fl_get_input(dialog_->name));
94
95         if (fl_get_button(dialog_->radio_html))
96                 params.setCmdName("htmlurl");
97         else
98                 params.setCmdName("url");
99
100         if (inset_ != 0) {
101                 // Only update if contents have changed
102                 if (params != inset_->params()) {
103                         inset_->setParams(params);
104                         lv_->view()->updateInset(inset_, true);
105                 }
106         } else {
107                 lv_->getLyXFunc()->Dispatch(LFUN_INSERT_URL,
108                                             params.getAsString());
109         }
110 }