1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
17 #include "bufferview_funcs.h"
18 #include "frontends/LyXView.h"
19 #include "BufferView.h"
20 #include "paragraph.h"
27 #include "ParagraphParameters.h"
29 #include "frontends/Alert.h"
31 #include "support/lstrings.h"
33 void emph(BufferView * bv)
35 LyXFont font(LyXFont::ALL_IGNORE);
36 font.setEmph(LyXFont::TOGGLE);
37 toggleAndShow(bv, font);
41 void bold(BufferView * bv)
43 LyXFont font(LyXFont::ALL_IGNORE);
44 font.setSeries(LyXFont::BOLD_SERIES);
45 toggleAndShow(bv, font);
49 void noun(BufferView * bv)
51 LyXFont font(LyXFont::ALL_IGNORE);
52 font.setNoun(LyXFont::TOGGLE);
53 toggleAndShow(bv, font);
57 void number(BufferView * bv)
59 LyXFont font(LyXFont::ALL_IGNORE);
60 font.setNumber(LyXFont::TOGGLE);
61 toggleAndShow(bv, font);
64 void lang(BufferView * bv, string const & l)
66 LyXFont font(LyXFont::ALL_IGNORE);
67 Language const * lang = languages.getLanguage(l);
69 font.setLanguage(lang);
70 toggleAndShow(bv, font);
72 Alert::alert(_("Error! unknown language"),l);
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)
81 if (!bv->available() || !text)
85 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
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 bv->owner()->message(_("Changed environment depth "
94 "(in possible range, maybe not)"));
98 void code(BufferView * bv)
100 LyXFont font(LyXFont::ALL_IGNORE);
101 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
102 toggleAndShow(bv, font);
106 void sans(BufferView * bv)
108 LyXFont font(LyXFont::ALL_IGNORE);
109 font.setFamily(LyXFont::SANS_FAMILY);
110 toggleAndShow(bv, font);
114 void roman(BufferView * bv)
116 LyXFont font(LyXFont::ALL_IGNORE);
117 font.setFamily(LyXFont::ROMAN_FAMILY);
118 toggleAndShow(bv, font);
122 void styleReset(BufferView * bv)
125 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
127 LyXFont font(LyXFont::ALL_INHERIT);
129 toggleAndShow(bv, font);
133 void underline(BufferView * bv)
135 LyXFont font(LyXFont::ALL_IGNORE);
136 font.setUnderbar(LyXFont::TOGGLE);
137 toggleAndShow(bv, font);
141 void fontSize(BufferView * bv, string const & size)
143 LyXFont font(LyXFont::ALL_IGNORE);
144 font.setLyXSize(size);
145 toggleAndShow(bv, font);
149 // Returns the current font and depth as a message.
150 string const currentState(BufferView * bv)
154 if (!bv->available())
157 // I think we should only show changes from the default
159 LyXText * text = bv->getLyXText();
160 Buffer * buffer = bv->buffer();
161 LyXFont font = text->real_current_font;
162 LyXFont const & defaultfont =
163 buffer->params.getLyXTextClass().defaultfont();
164 font.reduce(defaultfont);
166 state << _("Font:") << ' ' << font.stateText(&buffer->params);
168 // The paragraph depth
169 int depth = text->getDepth();
171 state << _(", Depth: ") << depth;
173 // The paragraph spacing, but only if different from
175 if (!text->cursor.par()->params().spacing().isDefault()) {
176 Spacing::Space cur_space =
177 text->cursor.par()->params().spacing().getSpace();
178 state << _(", Spacing: ");
181 case Spacing::Single:
182 state << _("Single");
184 case Spacing::Onehalf:
185 state << _("Onehalf");
187 case Spacing::Double:
188 state << _("Double");
191 state << _("Other (")
192 << text->cursor.par()->params().spacing().getValue()
195 case Spacing::Default:
196 // should never happen, do nothing
201 state << _(", Paragraph: ") << text->cursor.par()->id();
203 return state.str().c_str();
207 /* Does the actual toggle job of the calls above.
208 * Also shows the current font state.
210 void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
212 if (!bv->available())
215 if (bv->theLockingInset()) {
216 bv->theLockingInset()->setFont(bv, font, toggleall);
220 LyXText * text = bv->getLyXText();
221 // FIXME: can this happen ??
226 bv->update(text, BufferView::SELECT | BufferView::FITCUR);
227 text->toggleFree(bv, font, toggleall);
228 bv->update(text, BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
230 if (font.language() != ignore_language ||
231 font.number() != LyXFont::IGNORE) {
232 LyXCursor & cursor = text->cursor;
233 text->computeBidiTables(bv->buffer(), cursor.row());
234 if (cursor.boundary() !=
235 text->isBoundary(bv->buffer(), cursor.par(), cursor.pos(),
236 text->real_current_font))
237 text->setCursor(bv, cursor.par(), cursor.pos(),
238 false, !cursor.boundary());