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 // How should this actually work? Should it prohibit input in all BufferViews,
107 // or just in the current one? If "just the current one", then it should be
108 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
109 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
110 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
111 // current LyxView that should be prohibited (Lgb) (This applies to
112 // "AllowInput" as well.)
113 void ProhibitInput(BufferView * bv)
117 static Cursor cursor;
118 static bool cursor_undefined = true;
120 if (cursor_undefined){
121 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
122 XFlush(fl_get_display());
123 cursor_undefined = false;
126 /* set the cursor to the watch for all forms and the canvas */
127 XDefineCursor(fl_get_display(), bv->owner()->getForm()->window,
130 XFlush(fl_get_display());
131 fl_deactivate_all_forms();
135 void AllowInput(BufferView * bv)
137 /* reset the cursor from the watch for all forms and the canvas */
139 XUndefineCursor(fl_get_display(), bv->owner()->getForm()->window);
141 XFlush(fl_get_display());
142 fl_activate_all_forms();
146 void Code(BufferView * bv)
148 LyXFont font(LyXFont::ALL_IGNORE);
149 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
150 ToggleAndShow(bv, font);
154 void Sans(BufferView * bv)
156 LyXFont font(LyXFont::ALL_IGNORE);
157 font.setFamily(LyXFont::SANS_FAMILY);
158 ToggleAndShow(bv, font);
162 void Roman(BufferView * bv)
164 LyXFont font(LyXFont::ALL_IGNORE);
165 font.setFamily(LyXFont::ROMAN_FAMILY);
166 ToggleAndShow(bv, font);
170 void StyleReset(BufferView * bv)
172 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
173 ToggleAndShow(bv, font);
177 void Underline(BufferView * bv)
179 LyXFont font(LyXFont::ALL_IGNORE);
180 font.setUnderbar(LyXFont::TOGGLE);
181 ToggleAndShow(bv, font);
185 void FontSize(BufferView * bv, string const & size)
187 LyXFont font(LyXFont::ALL_IGNORE);
188 font.setLyXSize(size);
189 ToggleAndShow(bv, font);
193 // Returns the current font and depth as a message.
194 string const CurrentState(BufferView * bv)
198 if (bv->available()) {
199 // I think we should only show changes from the default
201 LyXText * text = bv->getLyXText();
202 Buffer * buffer = bv->buffer();
203 LyXFont font = text->real_current_font;
204 LyXFont const & defaultfont =
206 .TextClass(buffer->params.textclass)
208 font.reduce(defaultfont);
210 state << _("Font:") << ' '
211 << font.stateText(&buffer->params);
213 // The paragraph depth
214 int depth = text->getDepth();
216 state << _(", Depth: ") << depth;
218 // The paragraph spacing, but only if different from
220 if (!text->cursor.par()->params().spacing().isDefault()) {
221 Spacing::Space cur_space =
222 text->cursor.par()->params().spacing().getSpace();
223 state << _(", Spacing: ");
226 case Spacing::Single:
227 state << _("Single");
230 case Spacing::Onehalf:
231 state << _("Onehalf");
233 case Spacing::Double:
234 state << _("Double");
237 state << _("Other (")
238 << text->cursor.par()->params().spacing().getValue()
241 case Spacing::Default:
242 // should never happen, do nothing
247 return state.str().c_str();
251 /* -------> Does the actual toggle job of the XxxCB() calls above.
252 * Also shows the current font state.
254 void ToggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
256 if (bv->available()) {
257 if (bv->theLockingInset()) {
258 bv->theLockingInset()->SetFont(bv, font, toggleall);
261 LyXText * text = bv->getLyXText();
266 bv->update(text, BufferView::SELECT|BufferView::FITCUR);
267 text->toggleFree(bv, font, toggleall);
268 bv->update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
270 if (font.language() != ignore_language ||
272 font.latex() != LyXFont::IGNORE ||
274 font.number() != LyXFont::IGNORE)
276 LyXCursor & cursor = text->cursor;
277 text->computeBidiTables(bv->buffer(), cursor.row());
278 if (cursor.boundary() !=
279 text->isBoundary(bv->buffer(), cursor.par(), cursor.pos(),
280 text->real_current_font) )
281 text->setCursor(bv, cursor.par(), cursor.pos(),
282 false, !cursor.boundary());