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);
75 // Change environment depth.
76 // if decInc >= 0, increment depth
77 // if decInc < 0, decrement depth
78 void changeDepth(BufferView * bv, LyXText * text, int decInc)
80 if (!bv->available() || !text)
84 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
89 if (text->inset_owner)
90 bv->updateInset((Inset *)text->inset_owner, true);
91 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
92 bv->owner()->message(_("Changed environment depth "
93 "(in possible range, maybe not)"));
97 void code(BufferView * bv)
99 LyXFont font(LyXFont::ALL_IGNORE);
100 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
101 toggleAndShow(bv, font);
105 void sans(BufferView * bv)
107 LyXFont font(LyXFont::ALL_IGNORE);
108 font.setFamily(LyXFont::SANS_FAMILY);
109 toggleAndShow(bv, font);
113 void roman(BufferView * bv)
115 LyXFont font(LyXFont::ALL_IGNORE);
116 font.setFamily(LyXFont::ROMAN_FAMILY);
117 toggleAndShow(bv, font);
121 void styleReset(BufferView * bv)
124 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
126 LyXFont font(LyXFont::ALL_INHERIT);
128 toggleAndShow(bv, font);
132 void underline(BufferView * bv)
134 LyXFont font(LyXFont::ALL_IGNORE);
135 font.setUnderbar(LyXFont::TOGGLE);
136 toggleAndShow(bv, font);
140 void fontSize(BufferView * bv, string const & size)
142 LyXFont font(LyXFont::ALL_IGNORE);
143 font.setLyXSize(size);
144 toggleAndShow(bv, font);
148 // Returns the current font and depth as a message.
149 string const currentState(BufferView * bv)
153 if (bv->available()) {
154 // I think we should only show changes from the default
156 LyXText * text = bv->getLyXText();
157 Buffer * buffer = bv->buffer();
158 LyXFont font = text->real_current_font;
159 LyXFont const & defaultfont =
161 .TextClass(buffer->params.textclass)
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 XxxCB() 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)
231 LyXCursor & cursor = text->cursor;
232 text->computeBidiTables(bv->buffer(), cursor.row());
233 if (cursor.boundary() !=
234 text->isBoundary(bv->buffer(), cursor.par(), cursor.pos(),
235 text->real_current_font) )
236 text->setCursor(bv, cursor.par(), cursor.pos(),
237 false, !cursor.boundary());