]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/FormUrl.C
Michael's latest batch of new gnome files.
[lyx.git] / src / frontends / gnome / FormUrl.C
1 /* This file is part of
2  * =================================================
3  * 
4  *          LyX, The Document Processor
5  *          Copyright 1995-2000 The LyX Team.
6  *
7  * ================================================= 
8  *
9  * \author Baruch Even
10  */
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include <config.h>
17
18 #include "gnomeBC.h"
19 #include "FormUrl.h"
20
21 #include <gtk--/entry.h>
22 #include <gtk--/checkbutton.h>
23
24 FormUrl::FormUrl(ControlUrl & c)
25         : FormCB<ControlUrl>(c, "FormUrl")
26 {}
27
28
29 FormUrl::~FormUrl()
30 {
31         // Note that there is no need to destroy the class itself, it seems
32         // like everything is managed inside it. Deleting the class itself will
33         // a crash at the end of the program.
34         //dialog_->destroy();
35 }
36
37
38 void FormUrl::build()
39 {
40         // Connect the buttons.
41         ok_btn()->clicked.connect(SigC::slot(this, &FormUrl::OKClicked));
42         cancel_btn()->clicked.connect(SigC::slot(this, &FormUrl::CancelClicked));
43         apply_btn()->clicked.connect(SigC::slot(this, &FormUrl::ApplyClicked));
44         restore_btn()->clicked.connect(SigC::slot(this, &FormUrl::RestoreClicked));
45
46         // Manage the buttons state
47         bc().setOK(ok_btn());
48         bc().setCancel(cancel_btn());
49         bc().setApply(apply_btn());
50         bc().setRestore(restore_btn());
51
52         // Make sure everything is in the correct state.
53         bc().refresh();
54         
55         // Manage the read-only aware widgets.
56         bc().addReadOnly(html_cb());
57         bc().addReadOnly(name());
58         bc().addReadOnly(url());
59 }
60
61
62 void FormUrl::connect_signals()
63 {
64         // Get notifications on input change
65         slot_url_ = url()->changed.connect(SigC::slot(this, &FormUrl::InputChanged));
66         slot_name_ = name()->changed.connect(SigC::slot(this, &FormUrl::InputChanged));
67         slot_html_ = html_cb()->toggled.connect(SigC::slot(this, &FormUrl::InputChanged));
68 }
69
70
71 void FormUrl::disconnect_signals()
72 {
73         slot_url_.disconnect();
74         slot_name_.disconnect();
75         slot_html_.disconnect();
76 }
77
78
79 void FormUrl::apply()
80 {
81         disconnect_signals();
82         controller().params().setContents(url()->get_text());
83         controller().params().setOptions(name()->get_text());
84
85         string cmdname("url");
86         if (html_cb()->get_active())
87                 cmdname = "htmlurl";
88
89         controller().params().setCmdName(cmdname);
90         connect_signals();
91 }
92
93
94 void FormUrl::update()
95 {
96         // Disconnect signals so we dont trigger the input changed state.
97         // This avoids the problem of having the buttons enabled when the dialog
98         // starts.
99         disconnect_signals();
100         
101         url()->set_text(controller().params().getContents());
102         name()->set_text(controller().params().getOptions());
103
104         html_cb()->set_active("url" != controller().params().getCmdName());
105
106         // Reconnect the signals.
107         connect_signals();
108 }
109
110
111 bool FormUrl::validate() const
112 {
113         return !url()->get_text().empty() && !name()->get_text().empty();
114 }
115
116 Gtk::Button * FormUrl::restore_btn() const 
117 {
118         return getWidget<Gtk::Button>("r_restore_btn");
119 }
120 Gtk::Button * FormUrl::ok_btn() const 
121 {
122         return getWidget<Gtk::Button>("r_ok_btn");
123 }
124 Gtk::Button * FormUrl::apply_btn() const 
125 {
126         return getWidget<Gtk::Button>("r_apply_btn");
127 }
128 Gtk::Button * FormUrl::cancel_btn() const 
129 {
130         return getWidget<Gtk::Button>("r_cancel_btn");
131 }
132 Gtk::Entry * FormUrl::url() const 
133 {
134         return getWidget<Gtk::Entry>("r_url");
135 }
136 Gtk::Entry * FormUrl::name() const 
137 {
138         return getWidget<Gtk::Entry>("r_name");
139 }
140 Gtk::CheckButton * FormUrl::html_cb() const 
141 {
142         return getWidget<Gtk::CheckButton>("r_html_cb");
143 }
144
145