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"
19 #include "BufferView.h"
20 #include "paragraph.h"
22 #include "lyx_gui_misc.h"
25 #include "support/lstrings.h"
29 #include "ParagraphParameters.h"
32 void emph(BufferView * bv)
34 LyXFont font(LyXFont::ALL_IGNORE);
35 font.setEmph(LyXFont::TOGGLE);
36 toggleAndShow(bv, font);
40 void bold(BufferView * bv)
42 LyXFont font(LyXFont::ALL_IGNORE);
43 font.setSeries(LyXFont::BOLD_SERIES);
44 toggleAndShow(bv, font);
48 void noun(BufferView * bv)
50 LyXFont font(LyXFont::ALL_IGNORE);
51 font.setNoun(LyXFont::TOGGLE);
52 toggleAndShow(bv, font);
56 void number(BufferView * bv)
58 LyXFont font(LyXFont::ALL_IGNORE);
59 font.setNumber(LyXFont::TOGGLE);
60 toggleAndShow(bv, font);
63 void lang(BufferView * bv, string const & l)
65 LyXFont font(LyXFont::ALL_IGNORE);
66 Language const * lang = languages.getLanguage(l);
68 font.setLanguage(lang);
69 toggleAndShow(bv, font);
71 WriteAlert(_("Error! unknown language"),l);
76 void tex(BufferView * bv)
78 LyXFont font(LyXFont::ALL_IGNORE);
79 font.setLatex (LyXFont::TOGGLE);
80 toggleAndShow(bv, font);
85 // Change environment depth.
86 // if decInc >= 0, increment depth
87 // if decInc < 0, decrement depth
88 void changeDepth(BufferView * bv, LyXText * text, int decInc)
90 if (!bv->available() || !text)
94 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
99 if (text->inset_owner)
100 bv->updateInset((Inset *)text->inset_owner, true);
101 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
102 bv->owner()->message(_("Changed environment depth "
103 "(in possible range, maybe not)"));
107 void code(BufferView * bv)
109 LyXFont font(LyXFont::ALL_IGNORE);
110 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
111 toggleAndShow(bv, font);
115 void sans(BufferView * bv)
117 LyXFont font(LyXFont::ALL_IGNORE);
118 font.setFamily(LyXFont::SANS_FAMILY);
119 toggleAndShow(bv, font);
123 void roman(BufferView * bv)
125 LyXFont font(LyXFont::ALL_IGNORE);
126 font.setFamily(LyXFont::ROMAN_FAMILY);
127 toggleAndShow(bv, font);
131 void styleReset(BufferView * bv)
133 LyXFont font(LyXFont::ALL_INHERIT);
134 toggleAndShow(bv, font);
138 void underline(BufferView * bv)
140 LyXFont font(LyXFont::ALL_IGNORE);
141 font.setUnderbar(LyXFont::TOGGLE);
142 toggleAndShow(bv, font);
146 void fontSize(BufferView * bv, string const & size)
148 LyXFont font(LyXFont::ALL_IGNORE);
149 font.setLyXSize(size);
150 toggleAndShow(bv, font);
154 // Returns the current font and depth as a message.
155 string const currentState(BufferView * bv)
159 if (bv->available()) {
160 // I think we should only show changes from the default
162 LyXText * text = bv->getLyXText();
163 Buffer * buffer = bv->buffer();
164 LyXFont font = text->real_current_font;
165 LyXFont const & defaultfont =
167 .TextClass(buffer->params.textclass)
169 font.reduce(defaultfont);
171 state << _("Font:") << ' '
172 << font.stateText(&buffer->params);
174 // The paragraph depth
175 int depth = text->getDepth();
177 state << _(", Depth: ") << depth;
179 // The paragraph spacing, but only if different from
181 if (!text->cursor.par()->params().spacing().isDefault()) {
182 Spacing::Space cur_space =
183 text->cursor.par()->params().spacing().getSpace();
184 state << _(", Spacing: ");
187 case Spacing::Single:
188 state << _("Single");
191 case Spacing::Onehalf:
192 state << _("Onehalf");
194 case Spacing::Double:
195 state << _("Double");
198 state << _("Other (")
199 << text->cursor.par()->params().spacing().getValue()
202 case Spacing::Default:
203 // should never happen, do nothing
208 return state.str().c_str();
212 /* -------> Does the actual toggle job of the XxxCB() calls above.
213 * Also shows the current font state.
215 void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
217 if (bv->available()) {
218 if (bv->theLockingInset()) {
219 bv->theLockingInset()->setFont(bv, font, toggleall);
222 LyXText * text = bv->getLyXText();
227 bv->update(text, BufferView::SELECT|BufferView::FITCUR);
228 text->toggleFree(bv, font, toggleall);
229 bv->update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
231 if (font.language() != ignore_language ||
233 font.latex() != LyXFont::IGNORE ||
235 font.number() != LyXFont::IGNORE)
237 LyXCursor & cursor = text->cursor;
238 text->computeBidiTables(bv->buffer(), cursor.row());
239 if (cursor.boundary() !=
240 text->isBoundary(bv->buffer(), cursor.par(), cursor.pos(),
241 text->real_current_font) )
242 text->setCursor(bv, cursor.par(), cursor.pos(),
243 false, !cursor.boundary());