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 #include "BoostFormat.h"
35 void emph(BufferView * bv)
37 LyXFont font(LyXFont::ALL_IGNORE);
38 font.setEmph(LyXFont::TOGGLE);
39 toggleAndShow(bv, font);
43 void bold(BufferView * bv)
45 LyXFont font(LyXFont::ALL_IGNORE);
46 font.setSeries(LyXFont::BOLD_SERIES);
47 toggleAndShow(bv, font);
51 void noun(BufferView * bv)
53 LyXFont font(LyXFont::ALL_IGNORE);
54 font.setNoun(LyXFont::TOGGLE);
55 toggleAndShow(bv, font);
59 void number(BufferView * bv)
61 LyXFont font(LyXFont::ALL_IGNORE);
62 font.setNumber(LyXFont::TOGGLE);
63 toggleAndShow(bv, font);
66 void lang(BufferView * bv, string const & l)
68 LyXFont font(LyXFont::ALL_IGNORE);
69 Language const * lang = languages.getLanguage(l);
71 font.setLanguage(lang);
72 toggleAndShow(bv, font);
74 Alert::alert(_("Error! unknown language"),l);
78 // Change environment depth.
79 // if decInc >= 0, increment depth
80 // if decInc < 0, decrement depth
81 void changeDepth(BufferView * bv, LyXText * text, int decInc)
83 if (!bv->available() || !text)
87 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
92 if (text->inset_owner)
93 bv->updateInset((Inset *)text->inset_owner, true);
94 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
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)
124 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
125 toggleAndShow(bv, font);
129 void underline(BufferView * bv)
131 LyXFont font(LyXFont::ALL_IGNORE);
132 font.setUnderbar(LyXFont::TOGGLE);
133 toggleAndShow(bv, font);
137 void fontSize(BufferView * bv, string const & size)
139 LyXFont font(LyXFont::ALL_IGNORE);
140 font.setLyXSize(size);
141 toggleAndShow(bv, font);
145 // Returns the current font and depth as a message.
146 string const currentState(BufferView * bv)
150 if (!bv->available())
153 // I think we should only show changes from the default
155 LyXText * text = bv->getLyXText();
156 Buffer * buffer = bv->buffer();
157 LyXFont font = text->real_current_font;
158 LyXFont const & defaultfont =
159 buffer->params.getLyXTextClass().defaultfont();
160 font.reduce(defaultfont);
162 state << boost::format(_("Font: %1$s")) % font.stateText(&buffer->params);
164 // The paragraph depth
165 int depth = text->getDepth();
167 state << boost::format(_(", Depth: %1$d")) % depth;
169 // The paragraph spacing, but only if different from
171 if (!text->cursor.par()->params().spacing().isDefault()) {
172 Spacing::Space cur_space =
173 text->cursor.par()->params().spacing().getSpace();
174 state << _(", Spacing: ");
177 case Spacing::Single:
178 state << _("Single");
180 case Spacing::Onehalf:
181 state << _("Onehalf");
183 case Spacing::Double:
184 state << _("Double");
187 state << _("Other (")
188 << text->cursor.par()->params().spacing().getValue()
191 case Spacing::Default:
192 // should never happen, do nothing
197 state << _(", Paragraph: ") << text->cursor.par()->id();
199 return STRCONV(state.str());
203 /* Does the actual toggle job of the calls above.
204 * Also shows the current font state.
206 void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
208 if (!bv->available())
211 if (bv->theLockingInset()) {
212 bv->theLockingInset()->setFont(bv, font, toggleall);
216 LyXText * text = bv->getLyXText();
217 // FIXME: can this happen ??
222 bv->update(text, BufferView::SELECT | BufferView::FITCUR);
223 text->toggleFree(bv, font, toggleall);
224 bv->update(text, BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
226 if (font.language() != ignore_language ||
227 font.number() != LyXFont::IGNORE) {
228 LyXCursor & cursor = text->cursor;
229 text->computeBidiTables(bv->buffer(), cursor.row());
230 if (cursor.boundary() !=
231 text->isBoundary(bv->buffer(), cursor.par(), cursor.pos(),
232 text->real_current_font))
233 text->setCursor(bv, cursor.par(), cursor.pos(),
234 false, !cursor.boundary());