]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/GFloat.C
the string -> char patch
[lyx.git] / src / frontends / gnome / GFloat.C
1 /**
2  * \file GFloat.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Michael Koziarski
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include <config.h>
16
17 #include "gnomeBC.h"
18 #include "GFloat.h"
19 #include "support/lstrings.h"
20
21 #include <gtkmm/button.h>
22 #include <gtkmm/checkbutton.h>
23 #include <gtkmm/radiobutton.h>
24 #include <gtkmm/box.h>
25
26 GFloat::GFloat(ControlFloat & c)
27         : GnomeCB<ControlFloat>(c, "GFloat")
28 {}
29
30
31 GFloat::~GFloat()
32 {}
33
34
35 void GFloat::build()
36 {
37         // Connect the buttons.
38         close_btn()->signal_clicked().connect(SigC::slot(*this, &GFloat::OKClicked));
39         // Manage the buttons state
40         bc().setCancel(close_btn());
41         bc().refresh();
42         connect_signals();
43 }
44
45 void GFloat::apply()
46 {
47         string placement;
48         if (here_definitely()->get_active()) {
49                 placement += 'H';
50         } else {
51                 if (top_of_page()->get_active()) {
52                         placement += 't';
53                 }
54                 if (bottom_of_page()->get_active()) {
55                         placement += 'b';
56                 }
57                 if (page_of_floats()->get_active()) {
58                         placement += 'p';
59                 }
60                 if (here_if_possible()->get_active()) {
61                         placement += 'h';
62                 }
63         }
64         controller().params().placement = placement;
65 }
66
67
68 void GFloat::update()
69 {
70         disconnect_signals();
71         bool top = false;
72         bool bottom = false;
73         bool page = false;
74         bool here = false;
75         bool forcehere = false;
76
77         string placement(controller().params().placement);
78
79         if (contains(placement, "H")) {
80                 forcehere = true;
81         } else {
82                 if (contains(placement, "t")) {
83                         top = true;
84                 }
85                 if (contains(placement, "b")) {
86                         bottom = true;
87                 }
88                 if (contains(placement, "p")) {
89                         page = true;
90                 }
91                 if (contains(placement, "h")) {
92                         here = true;
93                 }
94         }
95
96         top_of_page()->set_active(top);
97         page_of_floats()->set_active(page);
98         bottom_of_page()->set_active(bottom);
99         here_if_possible()->set_active(here);
100         here_definitely()->set_active(forcehere);
101         connect_signals();
102 }
103
104 void GFloat::connect_signals()
105 {
106         conn_top_        = top_of_page()->signal_toggled().connect(
107                 SigC::slot(*this, &GFloat::ApplyClicked)
108                 );
109         conn_bottom_     = bottom_of_page()->signal_toggled().connect(
110                 SigC::slot(*this, &GFloat::ApplyClicked)
111                 );
112         conn_page_       = page_of_floats()->signal_toggled().connect(
113                 SigC::slot(*this, &GFloat::ApplyClicked)
114                 );
115         conn_ifposs_     = here_if_possible()->signal_toggled().connect(
116                 SigC::slot(*this, &GFloat::ApplyClicked)
117                 );
118         conn_definitely_ = here_definitely()->signal_toggled().connect(
119                 SigC::slot(*this, &GFloat::ApplyClicked)
120                 );
121         conn_disable_    = here_definitely()->signal_toggled().connect(
122                 SigC::slot(*this, &GFloat::update_sensitive)
123                 );
124 }
125
126 void GFloat::disconnect_signals()
127 {
128         conn_top_.disconnect();
129         conn_bottom_.disconnect();
130         conn_page_.disconnect();
131         conn_ifposs_.disconnect();
132         conn_definitely_.disconnect();
133         conn_disable_.disconnect();
134 }
135
136 void GFloat::update_sensitive()
137 {
138         if (here_definitely()->get_active())
139                 other_options()->set_sensitive(false);
140         else
141                 other_options()->set_sensitive(true);
142
143 }
144
145 Gtk::HBox * GFloat::other_options() const
146 {
147         return getWidget<Gtk::HBox>("r_other_options");
148 }
149 Gtk::CheckButton * GFloat::page_of_floats() const
150 {
151         return getWidget<Gtk::CheckButton>("r_page_of_floats");
152 }
153 Gtk::CheckButton * GFloat::top_of_page() const
154 {
155         return getWidget<Gtk::CheckButton>("r_top_of_page");
156 }
157 Gtk::CheckButton * GFloat::bottom_of_page() const
158 {
159         return getWidget<Gtk::CheckButton>("r_bottom_of_page");
160 }
161 Gtk::CheckButton * GFloat::here_if_possible() const
162 {
163         return getWidget<Gtk::CheckButton>("r_here_if_possible");
164 }
165 Gtk::RadioButton * GFloat::here_definitely() const
166 {
167         return getWidget<Gtk::RadioButton>("r_here_definitely");
168 }
169
170 Gtk::Button * GFloat::close_btn() const
171 {
172         return getWidget<Gtk::Button>("r_close_btn");
173 }