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