]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormUrl.C
fix a couple of hard crashes, constify local variables, whitespace changes, some...
[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 "Dialogs.h"
22 #include "FormUrl.h"
23 #include "LyXView.h"
24 #include "buffer.h"
25 #include "form_url.h"
26 #include "lyxfunc.h"
27
28 FormUrl::FormUrl(LyXView * lv, Dialogs * d)
29         : FormCommand(lv, d, _("Url"), new OkCancelReadOnlyPolicy),
30           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         delete dialog_;
43 }
44
45
46 FL_FORM * FormUrl::form() const
47 {
48         if (dialog_ ) return dialog_->form;
49         return 0;
50 }
51
52
53 void FormUrl::connect()
54 {
55         fl_set_form_maxsize(form(), 2 * minw_, minh_);
56         FormCommand::connect();
57 }
58         
59
60 void FormUrl::build()
61 {
62         dialog_ = build_url();
63
64 #ifdef WITH_WARNINGS
65 #warning use the buttoncontroller
66 #endif
67         // Workaround dumb xforms sizing bug
68         minw_ = form()->w;
69         minh_ = form()->h;
70 }
71
72
73 void FormUrl::update()
74 {
75         fl_set_input(dialog_->url,  params.getContents().c_str());
76         fl_set_input(dialog_->name, params.getOptions().c_str());
77
78         if (params.getCmdName() == "url")
79                 fl_set_button(dialog_->radio_html, 0);
80         else
81                 fl_set_button(dialog_->radio_html, 1);
82
83         if (lv_->buffer()->isReadonly()) {
84                 fl_deactivate_object(dialog_->url);
85                 fl_deactivate_object(dialog_->name);
86                 fl_deactivate_object(dialog_->radio_html);
87                 fl_deactivate_object(dialog_->button_ok);
88                 fl_set_object_lcol(dialog_->button_ok, FL_INACTIVE);
89         } else {
90                 fl_activate_object(dialog_->url);
91                 fl_activate_object(dialog_->name);
92                 fl_activate_object(dialog_->radio_html);
93                 fl_activate_object(dialog_->button_ok);
94                 fl_set_object_lcol(dialog_->button_ok, FL_BLACK);
95         }
96 }
97
98
99 void FormUrl::apply()
100 {
101         if (lv_->buffer()->isReadonly()) return;
102
103         params.setContents(fl_get_input(dialog_->url));
104         params.setOptions(fl_get_input(dialog_->name));
105
106         if (fl_get_button(dialog_->radio_html))
107                 params.setCmdName("htmlurl");
108         else
109                 params.setCmdName("url");
110
111         if (inset_ != 0) {
112                 // Only update if contents have changed
113                 if (params != inset_->params()) {
114                         inset_->setParams(params);
115                         lv_->view()->updateInset(inset_, true);
116                 }
117         } else {
118                 lv_->getLyXFunc()->Dispatch(LFUN_INSERT_URL,
119                                             params.getAsString());
120         }
121 }