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"
28 #include "lyxtextclasslist.h"
30 #include "frontends/Alert.h"
32 #include "support/lstrings.h"
34 void emph(BufferView * bv)
36 LyXFont font(LyXFont::ALL_IGNORE);
37 font.setEmph(LyXFont::TOGGLE);
38 toggleAndShow(bv, font);
42 void bold(BufferView * bv)
44 LyXFont font(LyXFont::ALL_IGNORE);
45 font.setSeries(LyXFont::BOLD_SERIES);
46 toggleAndShow(bv, font);
50 void noun(BufferView * bv)
52 LyXFont font(LyXFont::ALL_IGNORE);
53 font.setNoun(LyXFont::TOGGLE);
54 toggleAndShow(bv, font);
58 void number(BufferView * bv)
60 LyXFont font(LyXFont::ALL_IGNORE);
61 font.setNumber(LyXFont::TOGGLE);
62 toggleAndShow(bv, font);
65 void lang(BufferView * bv, string const & l)
67 LyXFont font(LyXFont::ALL_IGNORE);
68 Language const * lang = languages.getLanguage(l);
70 font.setLanguage(lang);
71 toggleAndShow(bv, font);
73 Alert::alert(_("Error! unknown language"),l);
77 // Change environment depth.
78 // if decInc >= 0, increment depth
79 // if decInc < 0, decrement depth
80 void changeDepth(BufferView * bv, LyXText * text, int decInc)
82 if (!bv->available() || !text)
86 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
91 if (text->inset_owner)
92 bv->updateInset((Inset *)text->inset_owner, true);
93 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
94 bv->owner()->message(_("Changed environment depth "
95 "(in possible range, maybe not)"));
99 void code(BufferView * bv)
101 LyXFont font(LyXFont::ALL_IGNORE);
102 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
103 toggleAndShow(bv, font);
107 void sans(BufferView * bv)
109 LyXFont font(LyXFont::ALL_IGNORE);
110 font.setFamily(LyXFont::SANS_FAMILY);
111 toggleAndShow(bv, font);
115 void roman(BufferView * bv)
117 LyXFont font(LyXFont::ALL_IGNORE);
118 font.setFamily(LyXFont::ROMAN_FAMILY);
119 toggleAndShow(bv, font);
123 void styleReset(BufferView * bv)
126 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
128 LyXFont font(LyXFont::ALL_INHERIT);
130 toggleAndShow(bv, font);
134 void underline(BufferView * bv)
136 LyXFont font(LyXFont::ALL_IGNORE);
137 font.setUnderbar(LyXFont::TOGGLE);
138 toggleAndShow(bv, font);
142 void fontSize(BufferView * bv, string const & size)
144 LyXFont font(LyXFont::ALL_IGNORE);
145 font.setLyXSize(size);
146 toggleAndShow(bv, font);
150 // Returns the current font and depth as a message.
151 string const currentState(BufferView * bv)
155 if (bv->available()) {
156 // I think we should only show changes from the default
158 LyXText * text = bv->getLyXText();
159 Buffer * buffer = bv->buffer();
160 LyXFont font = text->real_current_font;
161 LyXFont const & defaultfont =
162 textclasslist[buffer->params.textclass].defaultfont();
163 font.reduce(defaultfont);
165 state << _("Font:") << ' '
166 << 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");
185 case Spacing::Onehalf:
186 state << _("Onehalf");
188 case Spacing::Double:
189 state << _("Double");
192 state << _("Other (")
193 << text->cursor.par()->params().spacing().getValue()
196 case Spacing::Default:
197 // should never happen, do nothing
202 state << _(", Paragraph: ") << text->cursor.par()->id();
205 return state.str().c_str();
209 /* Does the actual toggle job of the calls above.
210 * Also shows the current font state.
212 void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
214 if (bv->available()) {
215 if (bv->theLockingInset()) {
216 bv->theLockingInset()->setFont(bv, font, toggleall);
219 LyXText * text = bv->getLyXText();
224 bv->update(text, BufferView::SELECT|BufferView::FITCUR);
225 text->toggleFree(bv, font, toggleall);
226 bv->update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
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());