]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GWrap.C
Extracted from r14281
[lyx.git] / src / frontends / gtk / GWrap.C
1 /**
2  * \file GWrap.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Spray
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
16 #endif
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
19 #endif
20
21 #include "GWrap.h"
22 #include "ControlWrap.h"
23 #include "insets/insetwrap.h"
24
25 #include "ghelpers.h"
26
27 #include <libglademm.h>
28
29 using std::string;
30
31 namespace lyx {
32 namespace frontend {
33
34 GWrap::GWrap(Dialog & parent)
35         : GViewCB<ControlWrap, GViewGladeB>(parent, _("Text Wrap Settings"), false)
36 {}
37
38
39 void GWrap::doBuild()
40 {
41         string const gladeName = findGladeFile("wrap");
42         xml_ = Gnome::Glade::Xml::create(gladeName);
43
44         Gtk::Button * cancelbutton;
45         xml_->get_widget("Close", cancelbutton);
46         setCancel(cancelbutton);
47
48         xml_->get_widget_derived ("Width", widthlengthentry_);
49         xml_->get_widget ("Placement", placementcombo_);
50
51         widthlengthentry_->signal_changed().connect(
52                 sigc::mem_fun(*this, &GWrap::apply));
53         placementcombo_->signal_changed().connect(
54                 sigc::mem_fun(*this, &GWrap::apply));
55
56         bcview().addReadOnly(widthlengthentry_);
57         bcview().addReadOnly(placementcombo_);
58 }
59
60
61 void GWrap::update()
62 {
63         applylock_ = true;
64
65         InsetWrapParams & params = controller().params();
66
67         widthlengthentry_->set_length (params.width);
68
69         int item;
70         if (params.placement == "l")
71                 item = 1;
72         else if (params.placement == "r")
73                 item = 2;
74         else if (params.placement == "p")
75                 item = 3;
76         else
77                 item = 0; // default
78
79         placementcombo_->set_active (item);
80
81         bc().refreshReadOnly();
82
83         applylock_ = false;
84 }
85
86
87 void GWrap::apply()
88 {
89         if (applylock_)
90                 return;
91
92         InsetWrapParams & params = controller().params();
93
94         params.width = widthlengthentry_->get_length();
95
96         int const placementrow = placementcombo_->get_active_row_number();
97         BOOST_ASSERT (0 <= placementrow <= 3);
98         switch (placementrow) {
99                 case 1:
100                         params.placement = 'l';
101                         break;
102                 case 2:
103                         params.placement = 'r';
104                         break;
105                 case 3:
106                         params.placement = 'p';
107                         break;
108                 case 0:
109                 default:
110                         params.placement.erase();
111                         break;
112         }
113
114         controller().dispatchParams();
115 }
116
117 } // namespace frontend
118 } // namespace lyx