]> git.lyx.org Git - lyx.git/blob - src/bufferview_funcs.C
partial framebox support
[lyx.git] / src / bufferview_funcs.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2001 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "bufferview_funcs.h"
18 #include "frontends/LyXView.h"
19 #include "BufferView.h"
20 #include "paragraph.h"
21 #include "lyxfont.h"
22 #include "lyxtext.h"
23 #include "buffer.h"
24 #include "lyx_cb.h"
25 #include "language.h"
26 #include "gettext.h"
27 #include "ParagraphParameters.h"
28
29 #include "frontends/Alert.h"
30
31 #include "support/lstrings.h"
32
33 void emph(BufferView * bv)
34 {
35         LyXFont font(LyXFont::ALL_IGNORE);
36         font.setEmph(LyXFont::TOGGLE);
37         toggleAndShow(bv, font);
38 }
39
40
41 void bold(BufferView * bv)
42 {
43         LyXFont font(LyXFont::ALL_IGNORE);
44         font.setSeries(LyXFont::BOLD_SERIES);
45         toggleAndShow(bv, font);
46 }
47
48
49 void noun(BufferView * bv)
50 {
51         LyXFont font(LyXFont::ALL_IGNORE);
52         font.setNoun(LyXFont::TOGGLE);
53         toggleAndShow(bv, font);
54 }
55
56
57 void number(BufferView * bv)
58 {
59         LyXFont font(LyXFont::ALL_IGNORE);
60         font.setNumber(LyXFont::TOGGLE);
61         toggleAndShow(bv, font);
62 }
63
64 void lang(BufferView * bv, string const & l)
65 {
66         LyXFont font(LyXFont::ALL_IGNORE);
67         Language const * lang = languages.getLanguage(l);
68         if (lang) {
69                 font.setLanguage(lang);
70                 toggleAndShow(bv, font);
71         } else
72                 Alert::alert(_("Error! unknown language"),l);
73 }
74
75
76 // Change environment depth.
77 // if decInc >= 0, increment depth
78 // if decInc <  0, decrement depth
79 void changeDepth(BufferView * bv, LyXText * text, int decInc)
80 {
81         if (!bv->available() || !text)
82             return;
83
84         bv->hideCursor();
85         bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
86         if (decInc >= 0)
87                 text->incDepth(bv);
88         else
89                 text->decDepth(bv);
90         if (text->inset_owner)
91                 bv->updateInset((Inset *)text->inset_owner, true);
92         bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
93 }
94
95
96 void code(BufferView * bv)
97 {
98         LyXFont font(LyXFont::ALL_IGNORE);
99         font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
100         toggleAndShow(bv, font);
101 }
102
103
104 void sans(BufferView * bv)
105 {
106         LyXFont font(LyXFont::ALL_IGNORE);
107         font.setFamily(LyXFont::SANS_FAMILY);
108         toggleAndShow(bv, font);
109 }
110
111
112 void roman(BufferView * bv)
113 {
114         LyXFont font(LyXFont::ALL_IGNORE);
115         font.setFamily(LyXFont::ROMAN_FAMILY);
116         toggleAndShow(bv, font);
117 }
118
119
120 void styleReset(BufferView * bv)
121 {
122 #ifndef INHERIT_LANG
123         LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
124 #else
125         LyXFont font(LyXFont::ALL_INHERIT);
126 #endif
127         toggleAndShow(bv, font);
128 }
129
130
131 void underline(BufferView * bv)
132 {
133         LyXFont font(LyXFont::ALL_IGNORE);
134         font.setUnderbar(LyXFont::TOGGLE);
135         toggleAndShow(bv, font);
136 }
137
138
139 void fontSize(BufferView * bv, string const & size)
140 {
141         LyXFont font(LyXFont::ALL_IGNORE);
142         font.setLyXSize(size);
143         toggleAndShow(bv, font);
144 }
145
146
147 // Returns the current font and depth as a message.
148 string const currentState(BufferView * bv)
149 {
150         ostringstream state;
151
152         if (!bv->available())
153                 return "";
154  
155         // I think we should only show changes from the default
156         // font. (Asger)
157         LyXText * text = bv->getLyXText();
158         Buffer * buffer = bv->buffer();
159         LyXFont font = text->real_current_font;
160         LyXFont const & defaultfont =
161                 buffer->params.getLyXTextClass().defaultfont();
162         font.reduce(defaultfont);
163
164         state << _("Font:") << ' ' << font.stateText(&buffer->params);
165
166         // The paragraph depth
167         int depth = text->getDepth();
168         if (depth > 0)
169                 state << _(", Depth: ") << depth;
170
171         // The paragraph spacing, but only if different from
172         // buffer spacing.
173         if (!text->cursor.par()->params().spacing().isDefault()) {
174                 Spacing::Space cur_space =
175                         text->cursor.par()->params().spacing().getSpace();
176                 state << _(", Spacing: ");
177
178                 switch (cur_space) {
179                 case Spacing::Single:
180                         state << _("Single");
181                         break;
182                 case Spacing::Onehalf:
183                         state << _("Onehalf");
184                         break;
185                 case Spacing::Double:
186                         state << _("Double");
187                         break;
188                 case Spacing::Other:
189                         state << _("Other (")
190                               << text->cursor.par()->params().spacing().getValue()
191                               << ")";
192                         break;
193                 case Spacing::Default:
194                         // should never happen, do nothing
195                         break;
196                 }
197         }
198 #ifdef DEVEL_VERSION
199         state << _(", Paragraph: ") << text->cursor.par()->id();
200 #endif
201         return state.str().c_str();
202 }
203
204
205 /* Does the actual toggle job of the calls above.
206  * Also shows the current font state.
207  */
208 void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
209 {
210         if (!bv->available())
211                 return;
212  
213         if (bv->theLockingInset()) {
214                 bv->theLockingInset()->setFont(bv, font, toggleall);
215                 return;
216         }
217  
218         LyXText * text = bv->getLyXText();
219         // FIXME: can this happen ?? 
220         if (!text)
221                 return;
222
223         bv->hideCursor();
224         bv->update(text, BufferView::SELECT | BufferView::FITCUR);
225         text->toggleFree(bv, font, toggleall);
226         bv->update(text, BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
227
228         if (font.language() != ignore_language ||
229             font.number() != LyXFont::IGNORE) {
230                 LyXCursor & cursor = text->cursor;
231                 text->computeBidiTables(bv->buffer(), cursor.row());
232                 if (cursor.boundary() !=
233                     text->isBoundary(bv->buffer(), cursor.par(), cursor.pos(),
234                                      text->real_current_font))
235                         text->setCursor(bv, cursor.par(), cursor.pos(),
236                                         false, !cursor.boundary());
237         }
238 }