]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlCharacter.C
The reference dialog now disconnects from the inset on Apply. Its behaviour
[lyx.git] / src / frontends / controllers / ControlCharacter.C
1 /**
2  * \file ControlCharacter.C
3  * Copyright 2001 The LyX Team.
4  * See the file COPYING.
5  *
6  * \author Angus Leeming, a.leeming@ic.ac.uk
7  */
8
9 #include <vector>
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include <config.h>
16
17 #include "ViewBase.h"
18 #include "ButtonControllerBase.h"
19 #include "ControlCharacter.h"
20 #include "buffer.h"
21 #include "Dialogs.h"
22 #include "Liason.h"
23 #include "LyXView.h"
24 #include "bufferview_funcs.h" // ToggleAndShow
25 #include "gettext.h"
26 #include "language.h"
27 #include "BufferView.h"
28
29 using Liason::setMinibuffer;
30 using SigC::slot;
31 using std::vector;
32
33
34 ControlCharacter::ControlCharacter(LyXView & lv, Dialogs & d)
35         : ControlDialog<ControlConnectBD>(lv, d),
36           font_(0), toggleall_(false)
37 {
38         d_.showCharacter.connect(slot(this, &ControlCharacter::show));
39         d_.setUserFreeFont.connect(slot(this, &ControlCharacter::apply));
40 }
41
42
43 void ControlCharacter::setParams()
44 {
45         // Do this the first time only. Used as a flag for whether or not the
46         // view has been built
47         if (!font_.get())
48                 font_.reset(new LyXFont(LyXFont::ALL_IGNORE));
49
50         // so that the user can press Ok
51         if (getFamily()   != LyXFont::IGNORE_FAMILY ||
52             getSeries()   != LyXFont::IGNORE_SERIES ||
53             getShape()    != LyXFont::IGNORE_SHAPE  ||
54             getSize()     != LyXFont::IGNORE_SIZE ||
55             getBar()      != character::IGNORE ||
56             getColor()    != LColor::ignore ||
57             font_->language() != ignore_language)
58                 bc().valid();
59 }
60
61
62 void ControlCharacter::apply()
63 {
64         // Nothing to apply. (Can be called from the Toolbar.)
65         if (!font_.get())
66                 return;
67
68         // Apply from the view if it's visible. Otherwise, use the stored values
69         if (lv_.view()->available())
70                 view().apply();
71
72         toggleAndShow(lv_.view(), *(font_.get()), toggleall_);
73         lv_.view()->setState();
74         lv_.buffer()->markDirty();
75         setMinibuffer(&lv_, _("Character set"));
76 }
77
78
79 LyXFont::FONT_FAMILY ControlCharacter::getFamily() const
80 {
81         if (!font_.get())
82                 return LyXFont::IGNORE_FAMILY;
83         return font_->family();
84 }
85
86
87 void ControlCharacter::setFamily(LyXFont::FONT_FAMILY val)
88 {
89         font_->setFamily(val);
90 }
91
92
93 LyXFont::FONT_SERIES ControlCharacter::getSeries() const
94 {
95         if (!font_.get())
96                 return LyXFont::IGNORE_SERIES;
97         return font_->series();
98 }
99
100
101 void ControlCharacter::setSeries(LyXFont::FONT_SERIES val)
102 {
103         font_->setSeries(val);
104 }
105
106
107 LyXFont::FONT_SHAPE ControlCharacter::getShape() const
108 {
109         if (!font_.get())
110                 return LyXFont::IGNORE_SHAPE;
111         return font_->shape();
112 }
113
114
115 void ControlCharacter::setShape(LyXFont::FONT_SHAPE val)
116 {
117         font_->setShape(val);
118 }
119
120
121 LyXFont::FONT_SIZE ControlCharacter::getSize() const
122 {
123         if (!font_.get())
124                 return LyXFont::IGNORE_SIZE;
125         return font_->size();
126 }
127
128
129 void ControlCharacter::setSize(LyXFont::FONT_SIZE val)
130 {
131         font_->setSize(val);
132 }
133
134
135 character::FONT_STATE ControlCharacter::getBar() const
136 {
137         if (!font_.get())
138                 return character::IGNORE;
139
140         if (font_->emph() == LyXFont::TOGGLE)
141                 return character::EMPH_TOGGLE;
142
143         if (font_->underbar() == LyXFont::TOGGLE)
144                 return character::UNDERBAR_TOGGLE;
145
146         if (font_->noun() == LyXFont::TOGGLE)
147                 return character::NOUN_TOGGLE;
148
149         if (font_->emph() == LyXFont::IGNORE &&
150             font_->underbar() == LyXFont::IGNORE &&
151             font_->noun() == LyXFont::IGNORE)
152                 return character::IGNORE;
153
154         return character::INHERIT;
155 }
156
157
158 void ControlCharacter::setBar(character::FONT_STATE val)
159 {
160         switch (val) {
161         case character::IGNORE:
162                 font_->setEmph(LyXFont::IGNORE);
163                 font_->setUnderbar(LyXFont::IGNORE);
164                 font_->setNoun(LyXFont::IGNORE);
165                 break;
166
167         case character::EMPH_TOGGLE:
168                 font_->setEmph(LyXFont::TOGGLE);
169                 break;
170
171         case character::UNDERBAR_TOGGLE:
172                 font_->setUnderbar(LyXFont::TOGGLE);
173                 break;
174
175         case character::NOUN_TOGGLE:
176                 font_->setNoun(LyXFont::TOGGLE);
177                 break;
178
179         case character::INHERIT:
180                 font_->setEmph(LyXFont::INHERIT);
181                 font_->setUnderbar(LyXFont::INHERIT);
182                 font_->setNoun(LyXFont::INHERIT);
183                 break;
184         }
185 }
186
187
188 LColor::color ControlCharacter::getColor() const
189 {
190         if (!font_.get())
191                 return LColor::ignore;
192
193         return font_->color();
194 }
195
196
197 void ControlCharacter::setColor(LColor::color val)
198 {
199         switch (val) {
200         case LColor::ignore:
201         case LColor::none:
202         case LColor::black:
203         case LColor::white:
204         case LColor::red:
205         case LColor::green:
206         case LColor::blue:
207         case LColor::cyan:
208         case LColor::magenta:
209         case LColor::yellow:
210         case LColor::inherit:
211                 font_->setColor(val);
212                 break;
213         default:
214                 break;
215         }
216 }
217
218
219 string ControlCharacter::getLanguage() const
220 {
221         if (font_.get() && font_->language())
222                 return font_->language()->lang();
223         return _("No change");
224 }
225
226
227 void ControlCharacter::setLanguage(string const & val)
228 {
229         if (val == _("No change"))
230                 font_->setLanguage(ignore_language);
231
232         else if ( val == _("Reset"))
233                 font_->setLanguage(lv_.buffer()->params.language);
234
235         else
236                 font_->setLanguage(languages.getLanguage(val));
237 }
238
239
240 bool ControlCharacter::getToggleAll() const
241 {
242         return toggleall_;
243 }
244
245
246 void ControlCharacter::setToggleAll(bool t)
247 {
248         toggleall_ = t;
249 }