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);
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)
196 if (bv->available()) {
197 // I think we should only show changes from the default
199 LyXText * text = bv->getLyXText();
200 Buffer * buffer = bv->buffer();
201 LyXFont font = text->real_current_font;
202 LyXFont const & defaultfont =
204 .TextClass(buffer->params.textclass)
206 font.reduce(defaultfont);
208 state << _("Font:") << ' '
209 << font.stateText(&buffer->params);
211 // The paragraph depth
212 int depth = text->getDepth();
214 state << _(", Depth: ") << depth;
216 // The paragraph spacing, but only if different from
218 if (!text->cursor.par()->params().spacing().isDefault()) {
219 Spacing::Space cur_space =
220 text->cursor.par()->params().spacing().getSpace();
221 state << _(", Spacing: ");
224 case Spacing::Single:
225 state << _("Single");
228 case Spacing::Onehalf:
229 state << _("Onehalf");
231 case Spacing::Double:
232 state << _("Double");
235 state << _("Other (")
236 << text->cursor.par()->params().spacing().getValue()
239 case Spacing::Default:
240 // should never happen, do nothing
245 return state.str().c_str();
249 /* -------> Does the actual toggle job of the XxxCB() calls above.
250 * Also shows the current font state.
252 void ToggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
254 if (bv->available()) {
255 if (bv->theLockingInset()) {
256 bv->theLockingInset()->SetFont(bv, font, toggleall);
259 LyXText * text = bv->getLyXText();
264 bv->update(text, BufferView::SELECT|BufferView::FITCUR);
265 text->toggleFree(bv, font, toggleall);
266 bv->update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
268 if (font.language() != ignore_language ||
269 font.latex() != LyXFont::IGNORE ||
270 font.number() != LyXFont::IGNORE)
272 LyXCursor & cursor = text->cursor;
273 text->computeBidiTables(bv->buffer(), cursor.row());
274 if (cursor.boundary() !=
275 text->isBoundary(bv->buffer(), cursor.par(), cursor.pos(),
276 text->real_current_font) )
277 text->setCursor(bv, cursor.par(), cursor.pos(),
278 false, !cursor.boundary());