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);
96 void code(BufferView * bv)
98 LyXFont font(LyXFont::ALL_IGNORE);
99 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
100 toggleAndShow(bv, font);
104 void sans(BufferView * bv)
106 LyXFont font(LyXFont::ALL_IGNORE);
107 font.setFamily(LyXFont::SANS_FAMILY);
108 toggleAndShow(bv, font);
112 void roman(BufferView * bv)
114 LyXFont font(LyXFont::ALL_IGNORE);
115 font.setFamily(LyXFont::ROMAN_FAMILY);
116 toggleAndShow(bv, font);
120 void styleReset(BufferView * bv)
122 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
123 toggleAndShow(bv, font);
127 void underline(BufferView * bv)
129 LyXFont font(LyXFont::ALL_IGNORE);
130 font.setUnderbar(LyXFont::TOGGLE);
131 toggleAndShow(bv, font);
135 void fontSize(BufferView * bv, string const & size)
137 LyXFont font(LyXFont::ALL_IGNORE);
138 font.setLyXSize(size);
139 toggleAndShow(bv, font);
143 // Returns the current font and depth as a message.
144 string const currentState(BufferView * bv)
148 if (!bv->available())
151 // I think we should only show changes from the default
153 LyXText * text = bv->getLyXText();
154 Buffer * buffer = bv->buffer();
155 LyXFont font = text->real_current_font;
156 LyXFont const & defaultfont =
157 buffer->params.getLyXTextClass().defaultfont();
158 font.reduce(defaultfont);
160 state << _("Font:") << ' ' << font.stateText(&buffer->params);
162 // The paragraph depth
163 int depth = text->getDepth();
165 state << _(", Depth: ") << depth;
167 // The paragraph spacing, but only if different from
169 if (!text->cursor.par()->params().spacing().isDefault()) {
170 Spacing::Space cur_space =
171 text->cursor.par()->params().spacing().getSpace();
172 state << _(", Spacing: ");
175 case Spacing::Single:
176 state << _("Single");
178 case Spacing::Onehalf:
179 state << _("Onehalf");
181 case Spacing::Double:
182 state << _("Double");
185 state << _("Other (")
186 << text->cursor.par()->params().spacing().getValue()
189 case Spacing::Default:
190 // should never happen, do nothing
195 state << _(", Paragraph: ") << text->cursor.par()->id();
197 return state.str().c_str();
201 /* Does the actual toggle job of the calls above.
202 * Also shows the current font state.
204 void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
206 if (!bv->available())
209 if (bv->theLockingInset()) {
210 bv->theLockingInset()->setFont(bv, font, toggleall);
214 LyXText * text = bv->getLyXText();
215 // FIXME: can this happen ??
220 bv->update(text, BufferView::SELECT | BufferView::FITCUR);
221 text->toggleFree(bv, font, toggleall);
222 bv->update(text, BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
224 if (font.language() != ignore_language ||
225 font.number() != LyXFont::IGNORE) {
226 LyXCursor & cursor = text->cursor;
227 text->computeBidiTables(bv->buffer(), cursor.row());
228 if (cursor.boundary() !=
229 text->isBoundary(bv->buffer(), cursor.par(), cursor.pos(),
230 text->real_current_font))
231 text->setCursor(bv, cursor.par(), cursor.pos(),
232 false, !cursor.boundary());