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 "lyxparagraph.h"
22 #include "lyx_gui_misc.h"
25 #include "support/lstrings.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);
74 void Tex(BufferView * bv)
76 LyXFont font(LyXFont::ALL_IGNORE);
77 font.setLatex (LyXFont::TOGGLE);
78 ToggleAndShow(bv, font);
82 // Change environment depth.
83 // if decInc >= 0, increment depth
84 // if decInc < 0, decrement depth
85 void changeDepth(BufferView * bv, LyXText * text, int decInc)
87 if (!bv->available() || !text)
91 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
96 if (text->inset_owner)
97 bv->updateInset((Inset *)text->inset_owner, true);
98 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
99 bv->owner()->message(_("Changed environment depth "
100 "(in possible range, maybe not)"));
104 // How should this actually work? Should it prohibit input in all BufferViews,
105 // or just in the current one? If "just the current one", then it should be
106 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
107 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
108 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
109 // current LyxView that should be prohibited (Lgb) (This applies to
110 // "AllowInput" as well.)
111 void ProhibitInput(BufferView * bv)
115 static Cursor cursor;
116 static bool cursor_undefined = true;
118 if (cursor_undefined){
119 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
120 XFlush(fl_get_display());
121 cursor_undefined = false;
124 /* set the cursor to the watch for all forms and the canvas */
125 XDefineCursor(fl_get_display(), bv->owner()->getForm()->window,
128 XFlush(fl_get_display());
129 fl_deactivate_all_forms();
133 void AllowInput(BufferView * bv)
135 /* reset the cursor from the watch for all forms and the canvas */
137 XUndefineCursor(fl_get_display(), bv->owner()->getForm()->window);
139 XFlush(fl_get_display());
140 fl_activate_all_forms();
144 void Code(BufferView * bv)
146 LyXFont font(LyXFont::ALL_IGNORE);
147 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
148 ToggleAndShow(bv, font);
152 void Sans(BufferView * bv)
154 LyXFont font(LyXFont::ALL_IGNORE);
155 font.setFamily(LyXFont::SANS_FAMILY);
156 ToggleAndShow(bv, font);
160 void Roman(BufferView * bv)
162 LyXFont font(LyXFont::ALL_IGNORE);
163 font.setFamily(LyXFont::ROMAN_FAMILY);
164 ToggleAndShow(bv, font);
168 void StyleReset(BufferView * bv)
170 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
171 ToggleAndShow(bv, font);
175 void Underline(BufferView * bv)
177 LyXFont font(LyXFont::ALL_IGNORE);
178 font.setUnderbar(LyXFont::TOGGLE);
179 ToggleAndShow(bv, font);
183 void FontSize(BufferView * bv, string const & size)
185 LyXFont font(LyXFont::ALL_IGNORE);
186 font.setLyXSize(size);
187 ToggleAndShow(bv, font);
191 // Returns the current font and depth as a message.
192 string const CurrentState(BufferView * bv)
195 if (bv->available()) {
196 // I think we should only show changes from the default
198 LyXText * text = bv->getLyXText();
199 Buffer * buffer = bv->buffer();
200 LyXFont font = text->real_current_font;
201 LyXFont const & defaultfont =
203 .TextClass(buffer->params.textclass)
205 font.reduce(defaultfont);
206 state = _("Font: ") + font.stateText(&buffer->params);
207 // The paragraph depth
208 int depth = text->GetDepth();
210 state += string(_(", Depth: ")) + tostr(depth);
211 // The paragraph spacing, but only if different from
213 if (!text->cursor.par()->params.spacing().isDefault()) {
214 Spacing::Space cur_space =
215 text->cursor.par()->params.spacing().getSpace();
216 state += _(", Spacing: ");
218 case Spacing::Single:
219 state += _("Single");
221 case Spacing::Onehalf:
222 state += _("Onehalf");
224 case Spacing::Double:
225 state += _("Double");
228 state += _("Other (");
229 state += tostr(text->cursor.par()->params.spacing().getValue());
232 case Spacing::Default:
233 // should never happen, do nothing
242 /* -------> Does the actual toggle job of the XxxCB() calls above.
243 * Also shows the current font state.
245 void ToggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
247 if (bv->available()) {
248 if (bv->theLockingInset()) {
249 bv->theLockingInset()->SetFont(bv, font, toggleall);
252 LyXText * text = bv->getLyXText();
257 bv->update(text, BufferView::SELECT|BufferView::FITCUR);
258 text->ToggleFree(bv, font, toggleall);
259 bv->update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
261 if (font.language() != ignore_language ||
262 font.latex() != LyXFont::IGNORE ||
263 font.number() != LyXFont::IGNORE)
265 LyXCursor & cursor = text->cursor;
266 text->ComputeBidiTables(bv->buffer(), cursor.row());
267 if (cursor.boundary() !=
268 text->IsBoundary(bv->buffer(), cursor.par(), cursor.pos(),
269 text->real_current_font) )
270 text->SetCursor(bv, cursor.par(), cursor.pos(),
271 false, !cursor.boundary());