]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/FormUrl.C
Added FormCredits dialog (MVC version) by Michael Koziarski.
[lyx.git] / src / frontends / gnome / FormUrl.C
1 // -*- C++ -*-
2 /* This file is part of
3  * =================================================
4  * 
5  *          LyX, The Document Processor
6  *          Copyright 1995-2000 The LyX Team.
7  *
8  * ================================================= 
9  *
10  * \author Baruch Even
11  */
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include <config.h>
18
19 #include "gnomeBC.h"
20 #include "FormUrl.h"
21
22 #include <gnome--/dialog.h>
23 #include <gtk--/entry.h>
24 #include <gtk--/checkbutton.h>
25
26 FormUrl::FormUrl(ControlUrl & c)
27         : FormCB<ControlUrl>(c, "diainserturl.glade", "DiaInsertUrl")
28         , dialog_(0)
29 {}
30
31
32 FormUrl::~FormUrl()
33 {
34         // Note that there is no need to destroy the class itself, it seems
35         // like everything is managed inside it. Deleting the class itself will
36         // a crash at the end of the program.
37         //dialog_->destroy();
38 }
39
40
41 void FormUrl::build()
42 {
43         // Make sure the dialog is loaded.
44         dialog_ = dialog();
45
46         // Connect the buttons.
47         ok_btn()->clicked.connect(SigC::slot(this, &FormUrl::OKClicked));
48         cancel_btn()->clicked.connect(SigC::slot(this, &FormUrl::CancelClicked));
49         apply_btn()->clicked.connect(SigC::slot(this, &FormUrl::ApplyClicked));
50         restore_btn()->clicked.connect(SigC::slot(this, &FormUrl::RestoreClicked));
51
52         // Manage the buttons state
53         bc().setOK(ok_btn());
54         bc().setCancel(cancel_btn());
55         bc().setApply(apply_btn());
56         bc().setUndoAll(restore_btn());
57
58         // Make sure everything is in the correct state.
59         bc().refresh();
60         
61         // Manage the read-only aware widgets.
62         bc().addReadOnly(html());
63         bc().addReadOnly(name());
64         bc().addReadOnly(url());
65 }
66
67
68 void FormUrl::connect_signals()
69 {
70         // Get notifications on input change
71         slot_url_ = url()->changed.connect(SigC::slot(this, &FormUrl::InputChanged));
72         slot_name_ = name()->changed.connect(SigC::slot(this, &FormUrl::InputChanged));
73         slot_html_ = html()->toggled.connect(SigC::slot(this, &FormUrl::InputChanged));
74 }
75
76
77 void FormUrl::disconnect_signals()
78 {
79         slot_url_.disconnect();
80         slot_name_.disconnect();
81         slot_html_.disconnect();
82 }
83
84
85 void FormUrl::show()
86 {
87         if (!dialog_)
88                 build();
89         
90         update();
91         dialog_->show();
92 }
93
94
95 void FormUrl::hide()
96 {
97         dialog_->hide();
98 }
99
100
101 void FormUrl::apply()
102 {
103         controller().params().setContents(url()->get_text());
104         controller().params().setOptions(name()->get_text());
105
106         string cmdname("url");
107         if (html()->get_active())
108                 cmdname = "htmlurl";
109
110         controller().params().setCmdName(cmdname);
111 }
112
113
114 void FormUrl::update()
115 {
116         // Disconnect signals so we dont trigger the input changed state.
117         // This avoids the problem of having the buttons enabled when the dialog
118         // starts.
119         disconnect_signals();
120         
121         url()->set_text(controller().params().getContents());
122         name()->set_text(controller().params().getOptions());
123
124         html()->set_active("url" != controller().params().getCmdName());
125
126         // Reconnect the signals.
127         connect_signals();
128 }
129
130
131 bool FormUrl::validate() const
132 {
133         // Always valid! (not really so, needs fixing).
134         return true;
135 }
136
137
138 Gnome::Dialog * FormUrl::dialog()
139 {
140         return getWidget<Gnome::Dialog>("DiaInsertUrl");
141 }
142
143 Gtk::Entry * FormUrl::url() const
144 {
145         return getWidget<Gtk::Entry>("url");
146 }
147
148 Gtk::Entry * FormUrl::name() const
149 {
150         return getWidget<Gtk::Entry>("name");
151 }
152
153 Gtk::CheckButton * FormUrl::html() const
154 {
155         return getWidget<Gtk::CheckButton>("html_type");
156 }
157
158
159 Gtk::Button * FormUrl::ok_btn() const
160 {
161         return getWidget<Gtk::Button>("button_ok");
162 }
163
164
165 Gtk::Button * FormUrl::cancel_btn() const
166 {
167         return getWidget<Gtk::Button>("button_cancel");
168 }
169
170
171 Gtk::Button * FormUrl::apply_btn() const
172 {
173         return getWidget<Gtk::Button>("button_apply");
174 }
175
176
177 Gtk::Button * FormUrl::restore_btn() const
178 {
179         return getWidget<Gtk::Button>("button_restore");
180 }