]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/FormUrl.C
Remove unneeded files, we have switched to use the libglade and there is no
[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 <gtk--/entry.h>
23 #include <gtk--/checkbutton.h>
24
25 FormUrl::FormUrl(ControlUrl & c)
26         : FormCB<ControlUrl>(c, "diainserturl.glade", "DiaInsertUrl")
27 {}
28
29
30 FormUrl::~FormUrl()
31 {
32         // Note that there is no need to destroy the class itself, it seems
33         // like everything is managed inside it. Deleting the class itself will
34         // a crash at the end of the program.
35         //dialog_->destroy();
36 }
37
38
39 void FormUrl::build()
40 {
41         // Connect the buttons.
42         ok_btn()->clicked.connect(SigC::slot(this, &FormUrl::OKClicked));
43         cancel_btn()->clicked.connect(SigC::slot(this, &FormUrl::CancelClicked));
44         apply_btn()->clicked.connect(SigC::slot(this, &FormUrl::ApplyClicked));
45         restore_btn()->clicked.connect(SigC::slot(this, &FormUrl::RestoreClicked));
46
47         // Manage the buttons state
48         bc().setOK(ok_btn());
49         bc().setCancel(cancel_btn());
50         bc().setApply(apply_btn());
51         bc().setUndoAll(restore_btn());
52
53         // Make sure everything is in the correct state.
54         bc().refresh();
55         
56         // Manage the read-only aware widgets.
57         bc().addReadOnly(html());
58         bc().addReadOnly(name());
59         bc().addReadOnly(url());
60 }
61
62
63 void FormUrl::connect_signals()
64 {
65         // Get notifications on input change
66         slot_url_ = url()->changed.connect(SigC::slot(this, &FormUrl::InputChanged));
67         slot_name_ = name()->changed.connect(SigC::slot(this, &FormUrl::InputChanged));
68         slot_html_ = html()->toggled.connect(SigC::slot(this, &FormUrl::InputChanged));
69 }
70
71
72 void FormUrl::disconnect_signals()
73 {
74         slot_url_.disconnect();
75         slot_name_.disconnect();
76         slot_html_.disconnect();
77 }
78
79
80 void FormUrl::apply()
81 {
82         controller().params().setContents(url()->get_text());
83         controller().params().setOptions(name()->get_text());
84
85         string cmdname("url");
86         if (html()->get_active())
87                 cmdname = "htmlurl";
88
89         controller().params().setCmdName(cmdname);
90 }
91
92
93 void FormUrl::update()
94 {
95         // Disconnect signals so we dont trigger the input changed state.
96         // This avoids the problem of having the buttons enabled when the dialog
97         // starts.
98         disconnect_signals();
99         
100         url()->set_text(controller().params().getContents());
101         name()->set_text(controller().params().getOptions());
102
103         html()->set_active("url" != controller().params().getCmdName());
104
105         // Reconnect the signals.
106         connect_signals();
107 }
108
109
110 bool FormUrl::validate() const
111 {
112         // Always valid! (not really so, needs fixing).
113         return true;
114 }
115
116
117 Gtk::Entry * FormUrl::url() const
118 {
119         return getWidget<Gtk::Entry>("url");
120 }
121
122 Gtk::Entry * FormUrl::name() const
123 {
124         return getWidget<Gtk::Entry>("name");
125 }
126
127 Gtk::CheckButton * FormUrl::html() const
128 {
129         return getWidget<Gtk::CheckButton>("html_type");
130 }
131
132
133 Gtk::Button * FormUrl::ok_btn() const
134 {
135         return getWidget<Gtk::Button>("button_ok");
136 }
137
138
139 Gtk::Button * FormUrl::cancel_btn() const
140 {
141         return getWidget<Gtk::Button>("button_cancel");
142 }
143
144
145 Gtk::Button * FormUrl::apply_btn() const
146 {
147         return getWidget<Gtk::Button>("button_apply");
148 }
149
150
151 Gtk::Button * FormUrl::restore_btn() const
152 {
153         return getWidget<Gtk::Button>("button_restore");
154 }