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"
31 void Emph(BufferView * bv)
33 LyXFont font(LyXFont::ALL_IGNORE);
34 font.setEmph(LyXFont::TOGGLE);
35 ToggleAndShow(bv, font);
39 void Bold(BufferView * bv)
41 LyXFont font(LyXFont::ALL_IGNORE);
42 font.setSeries(LyXFont::BOLD_SERIES);
43 ToggleAndShow(bv, font);
47 void Noun(BufferView * bv)
49 LyXFont font(LyXFont::ALL_IGNORE);
50 font.setNoun(LyXFont::TOGGLE);
51 ToggleAndShow(bv, font);
55 void Number(BufferView * bv)
57 LyXFont font(LyXFont::ALL_IGNORE);
58 font.setNumber(LyXFont::TOGGLE);
59 ToggleAndShow(bv, font);
62 void Lang(BufferView * bv, string const & l)
64 LyXFont font(LyXFont::ALL_IGNORE);
65 Language const * lang = languages.getLanguage(l);
67 font.setLanguage(lang);
68 ToggleAndShow(bv, font);
70 WriteAlert(_("Error! unknown language"),l);
75 void Tex(BufferView * bv)
77 LyXFont font(LyXFont::ALL_IGNORE);
78 font.setLatex (LyXFont::TOGGLE);
79 ToggleAndShow(bv, font);
84 // Change environment depth.
85 // if decInc >= 0, increment depth
86 // if decInc < 0, decrement depth
87 void changeDepth(BufferView * bv, LyXText * text, int decInc)
89 if (!bv->available() || !text)
93 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
98 if (text->inset_owner)
99 bv->updateInset((Inset *)text->inset_owner, true);
100 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
101 bv->owner()->message(_("Changed environment depth "
102 "(in possible range, maybe not)"));
106 void Code(BufferView * bv)
108 LyXFont font(LyXFont::ALL_IGNORE);
109 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
110 ToggleAndShow(bv, font);
114 void Sans(BufferView * bv)
116 LyXFont font(LyXFont::ALL_IGNORE);
117 font.setFamily(LyXFont::SANS_FAMILY);
118 ToggleAndShow(bv, font);
122 void Roman(BufferView * bv)
124 LyXFont font(LyXFont::ALL_IGNORE);
125 font.setFamily(LyXFont::ROMAN_FAMILY);
126 ToggleAndShow(bv, font);
130 void StyleReset(BufferView * bv)
132 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
133 ToggleAndShow(bv, font);
137 void Underline(BufferView * bv)
139 LyXFont font(LyXFont::ALL_IGNORE);
140 font.setUnderbar(LyXFont::TOGGLE);
141 ToggleAndShow(bv, font);
145 void FontSize(BufferView * bv, string const & size)
147 LyXFont font(LyXFont::ALL_IGNORE);
148 font.setLyXSize(size);
149 ToggleAndShow(bv, font);
153 // Returns the current font and depth as a message.
154 string const CurrentState(BufferView * bv)
158 if (bv->available()) {
159 // I think we should only show changes from the default
161 LyXText * text = bv->getLyXText();
162 Buffer * buffer = bv->buffer();
163 LyXFont font = text->real_current_font;
164 LyXFont const & defaultfont =
166 .TextClass(buffer->params.textclass)
168 font.reduce(defaultfont);
170 state << _("Font:") << ' '
171 << font.stateText(&buffer->params);
173 // The paragraph depth
174 int depth = text->getDepth();
176 state << _(", Depth: ") << depth;
178 // The paragraph spacing, but only if different from
180 if (!text->cursor.par()->params().spacing().isDefault()) {
181 Spacing::Space cur_space =
182 text->cursor.par()->params().spacing().getSpace();
183 state << _(", Spacing: ");
186 case Spacing::Single:
187 state << _("Single");
190 case Spacing::Onehalf:
191 state << _("Onehalf");
193 case Spacing::Double:
194 state << _("Double");
197 state << _("Other (")
198 << text->cursor.par()->params().spacing().getValue()
201 case Spacing::Default:
202 // should never happen, do nothing
207 return state.str().c_str();
211 /* -------> Does the actual toggle job of the XxxCB() calls above.
212 * Also shows the current font state.
214 void ToggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
216 if (bv->available()) {
217 if (bv->theLockingInset()) {
218 bv->theLockingInset()->setFont(bv, font, toggleall);
221 LyXText * text = bv->getLyXText();
226 bv->update(text, BufferView::SELECT|BufferView::FITCUR);
227 text->toggleFree(bv, font, toggleall);
228 bv->update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
230 if (font.language() != ignore_language ||
232 font.latex() != LyXFont::IGNORE ||
234 font.number() != LyXFont::IGNORE)
236 LyXCursor & cursor = text->cursor;
237 text->computeBidiTables(bv->buffer(), cursor.row());
238 if (cursor.boundary() !=
239 text->isBoundary(bv->buffer(), cursor.par(), cursor.pos(),
240 text->real_current_font) )
241 text->setCursor(bv, cursor.par(), cursor.pos(),
242 false, !cursor.boundary());