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"
31 #include "frontends/Alert.h"
33 #include "support/lstrings.h"
35 #include "BoostFormat.h"
37 void emph(BufferView * bv)
39 LyXFont font(LyXFont::ALL_IGNORE);
40 font.setEmph(LyXFont::TOGGLE);
41 toggleAndShow(bv, font);
45 void bold(BufferView * bv)
47 LyXFont font(LyXFont::ALL_IGNORE);
48 font.setSeries(LyXFont::BOLD_SERIES);
49 toggleAndShow(bv, font);
53 void noun(BufferView * bv)
55 LyXFont font(LyXFont::ALL_IGNORE);
56 font.setNoun(LyXFont::TOGGLE);
57 toggleAndShow(bv, font);
61 void number(BufferView * bv)
63 LyXFont font(LyXFont::ALL_IGNORE);
64 font.setNumber(LyXFont::TOGGLE);
65 toggleAndShow(bv, font);
68 void lang(BufferView * bv, string const & l)
70 LyXFont font(LyXFont::ALL_IGNORE);
71 Language const * lang = languages.getLanguage(l);
73 font.setLanguage(lang);
74 toggleAndShow(bv, font);
76 Alert::alert(_("Error! unknown language"),l);
80 // Change environment depth.
81 // if decInc >= 0, increment depth
82 // if decInc < 0, decrement depth
83 void changeDepth(BufferView * bv, LyXText * text, int decInc)
85 if (!bv->available() || !text)
89 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
94 if (text->inset_owner)
95 bv->updateInset((Inset *)text->inset_owner, true);
96 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
100 void code(BufferView * bv)
102 LyXFont font(LyXFont::ALL_IGNORE);
103 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
104 toggleAndShow(bv, font);
108 void sans(BufferView * bv)
110 LyXFont font(LyXFont::ALL_IGNORE);
111 font.setFamily(LyXFont::SANS_FAMILY);
112 toggleAndShow(bv, font);
116 void roman(BufferView * bv)
118 LyXFont font(LyXFont::ALL_IGNORE);
119 font.setFamily(LyXFont::ROMAN_FAMILY);
120 toggleAndShow(bv, font);
124 void styleReset(BufferView * bv)
126 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
127 toggleAndShow(bv, font);
131 void underline(BufferView * bv)
133 LyXFont font(LyXFont::ALL_IGNORE);
134 font.setUnderbar(LyXFont::TOGGLE);
135 toggleAndShow(bv, font);
139 void fontSize(BufferView * bv, string const & size)
141 LyXFont font(LyXFont::ALL_IGNORE);
142 font.setLyXSize(size);
143 toggleAndShow(bv, font);
147 // Returns the current font and depth as a message.
148 string const currentState(BufferView * bv)
152 if (!bv->available())
155 LyXText * text = bv->getLyXText();
156 Buffer * buffer = bv->buffer();
157 LyXCursor const & c(text->cursor);
159 bool const show_change = buffer->params.tracking_changes
160 && c.pos() != c.par()->size()
161 && c.par()->lookupChange(c.pos()) != Change::UNCHANGED;
164 Change change(c.par()->lookupChangeFull(c.pos()));
165 Author const & a(bv->buffer()->authors().get(change.author));
166 state << _("Change: ") << a.name();
167 if (!a.email().empty()) {
168 state << " (" << a.email() << ")";
170 if (change.changetime)
171 state << _(" at ") << ctime(&change.changetime);
175 // I think we should only show changes from the default
177 LyXFont font = text->real_current_font;
178 LyXFont const & defaultfont =
179 buffer->params.getLyXTextClass().defaultfont();
180 font.reduce(defaultfont);
183 state << boost::format(_("Font: %1$s")) % font.stateText(&buffer->params);
185 state << _("Font: ") << font.stateText(&buffer->params);
188 // The paragraph depth
189 int depth = text->getDepth();
192 state << boost::format(_(", Depth: %1$d")) % depth;
194 state << _(", Depth: ") << depth;
199 // The paragraph spacing, but only if different from
201 if (!text->cursor.par()->params().spacing().isDefault()) {
202 Spacing::Space cur_space =
203 text->cursor.par()->params().spacing().getSpace();
204 state << _(", Spacing: ");
207 case Spacing::Single:
208 state << _("Single");
210 case Spacing::Onehalf:
211 state << _("OneHalf");
213 case Spacing::Double:
214 state << _("Double");
217 state << _("Other (")
218 << text->cursor.par()->params().spacing().getValue()
221 case Spacing::Default:
222 // should never happen, do nothing
227 state << _(", Paragraph: ") << text->cursor.par()->id();
229 return STRCONV(state.str());
233 /* Does the actual toggle job of the calls above.
234 * Also shows the current font state.
236 void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
238 if (!bv->available())
241 if (bv->theLockingInset()) {
242 bv->theLockingInset()->setFont(bv, font, toggleall);
246 LyXText * text = bv->getLyXText();
247 // FIXME: can this happen ??
252 bv->update(text, BufferView::SELECT | BufferView::FITCUR);
253 text->toggleFree(bv, font, toggleall);
254 bv->update(text, BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
256 if (font.language() != ignore_language ||
257 font.number() != LyXFont::IGNORE) {
258 LyXCursor & cursor = text->cursor;
259 text->computeBidiTables(bv->buffer(), cursor.row());
260 if (cursor.boundary() !=
261 text->isBoundary(bv->buffer(), cursor.par(), cursor.pos(),
262 text->real_current_font))
263 text->setCursor(bv, cursor.par(), cursor.pos(),
264 false, !cursor.boundary());