]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/GUrl.C
Left out these four glade files last time, plus Fix for Preamble resizing problems
[lyx.git] / src / frontends / gnome / GUrl.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  * \author Michael Koziarski
11  */
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include <config.h>
18
19 #include "gnomeBC.h"
20 #include "GUrl.h"
21
22 #include <gtk--/entry.h>
23 #include <gtk--/checkbutton.h>
24
25 GUrl::GUrl(ControlUrl & c)
26         : FormCB<ControlUrl>(c, "GUrl")
27 {}
28
29
30 GUrl::~GUrl()
31 {}
32
33
34 void GUrl::build()
35 {
36         // Connect the buttons.
37         ok_btn()->clicked.connect(SigC::slot(this, &GUrl::OKClicked));
38         cancel_btn()->clicked.connect(SigC::slot(this, &GUrl::CancelClicked));
39         apply_btn()->clicked.connect(SigC::slot(this, &GUrl::ApplyClicked));
40         restore_btn()->clicked.connect(SigC::slot(this, &GUrl::RestoreClicked));
41
42         // Manage the buttons state
43         bc().setOK(ok_btn());
44         bc().setCancel(cancel_btn());
45         bc().setApply(apply_btn());
46         bc().setRestore(restore_btn());
47
48         // Manage the read-only aware widgets.
49         bc().addReadOnly(html_cb());
50         bc().addReadOnly(name());
51         bc().addReadOnly(url());
52
53         // Make sure everything is in the correct state.
54         bc().refresh();
55 }
56
57
58 void GUrl::connect_signals()
59 {
60         // Get notifications on input change
61         slot_url_ = url()->changed.connect(SigC::slot(this, &GUrl::InputChanged));
62         slot_name_ = name()->changed.connect(SigC::slot(this, &GUrl::InputChanged));
63         slot_html_ = html_cb()->toggled.connect(SigC::slot(this, &GUrl::InputChanged));
64 }
65
66
67 void GUrl::disconnect_signals()
68 {
69         slot_url_.disconnect();
70         slot_name_.disconnect();
71         slot_html_.disconnect();
72 }
73
74
75 void GUrl::apply()
76 {
77         disconnect_signals();
78         controller().params().setContents(url()->get_text());
79         controller().params().setOptions(name()->get_text());
80
81         string cmdname("url");
82         if (html_cb()->get_active())
83                 cmdname = "htmlurl";
84
85         controller().params().setCmdName(cmdname);
86         connect_signals();
87 }
88
89
90 void GUrl::update()
91 {
92         disconnect_signals();
93         
94         url()->set_text(controller().params().getContents());
95         name()->set_text(controller().params().getOptions());
96
97         html_cb()->set_active("url" != controller().params().getCmdName());
98
99         connect_signals();
100 }
101
102
103 bool GUrl::validate() const
104 {
105         return !url()->get_text().empty() && !name()->get_text().empty();
106 }
107
108 Gtk::Button * GUrl::restore_btn() const 
109 {
110         return getWidget<Gtk::Button>("r_restore_btn");
111 }
112 Gtk::Button * GUrl::ok_btn() const 
113 {
114         return getWidget<Gtk::Button>("r_ok_btn");
115 }
116 Gtk::Button * GUrl::apply_btn() const 
117 {
118         return getWidget<Gtk::Button>("r_apply_btn");
119 }
120 Gtk::Button * GUrl::cancel_btn() const 
121 {
122         return getWidget<Gtk::Button>("r_cancel_btn");
123 }
124 Gtk::Entry * GUrl::url() const 
125 {
126         return getWidget<Gtk::Entry>("r_url");
127 }
128 Gtk::Entry * GUrl::name() const 
129 {
130         return getWidget<Gtk::Entry>("r_name");
131 }
132 Gtk::CheckButton * GUrl::html_cb() const 
133 {
134         return getWidget<Gtk::CheckButton>("r_html_cb");
135 }
136
137