1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 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"
32 void Foot(BufferView * bv)
37 bv->owner()->getMiniBuffer()
38 ->Set(_("Inserting Footnote..."));
40 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
41 bv->text->InsertFootnoteEnvironment(bv, LyXParagraph::FOOTNOTE);
42 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
47 void Emph(BufferView * bv)
49 LyXFont font(LyXFont::ALL_IGNORE);
50 font.setEmph(LyXFont::TOGGLE);
51 ToggleAndShow(bv, font);
55 void Bold(BufferView * bv)
57 LyXFont font(LyXFont::ALL_IGNORE);
58 font.setSeries(LyXFont::BOLD_SERIES);
59 ToggleAndShow(bv, font);
63 void Noun(BufferView * bv)
65 LyXFont font(LyXFont::ALL_IGNORE);
66 font.setNoun(LyXFont::TOGGLE);
67 ToggleAndShow(bv, font);
72 void Margin(BufferView * bv)
74 if (bv->available()) {
75 bv->owner()->getLyXFunc()->Dispatch(LFUN_MESSAGE, _("Inserting margin note...");
77 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
78 bv->text->InsertFootnoteEnvironment(bv, LyXParagraph::MARGIN);
79 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
84 void Number(BufferView * bv)
86 LyXFont font(LyXFont::ALL_IGNORE);
87 font.setNumber(LyXFont::TOGGLE);
88 ToggleAndShow(bv, font);
91 void Lang(BufferView * bv, string const & l)
93 LyXFont font(LyXFont::ALL_IGNORE);
94 Language const * lang = languages.getLanguage(l);
96 font.setLanguage(lang);
97 ToggleAndShow(bv, font);
99 WriteAlert(_("Error! unknown language"),l);
104 void Melt(BufferView * bv)
106 if (!bv->available()) return;
108 bv->owner()->getLyXFunc()->Dispatch(LFUN_MESSAGE, _("Melt"));
110 bv->beforeChange(bv->text);
111 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
112 bv->text->MeltFootnoteEnvironment(bv);
113 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
118 void Tex(BufferView * bv)
120 LyXFont font(LyXFont::ALL_IGNORE);
121 font.setLatex (LyXFont::TOGGLE);
122 ToggleAndShow(bv, font);
126 // Change environment depth.
127 // if decInc >= 0, increment depth
128 // if decInc < 0, decrement depth
129 void changeDepth(BufferView * bv, LyXText * text, int decInc)
131 if (!bv->available() || !text)
135 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
140 if (text->inset_owner)
141 bv->updateInset((Inset *)text->inset_owner, true);
142 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
143 bv->owner()->getLyXFunc()
144 ->Dispatch(LFUN_MESSAGE,
145 _("Changed environment depth "
146 "(in possible range, maybe not)"));
150 // How should this actually work? Should it prohibit input in all BufferViews,
151 // or just in the current one? If "just the current one", then it should be
152 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
153 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
154 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
155 // current LyxView that should be prohibited (Lgb) (This applies to
156 // "AllowInput" as well.)
157 void ProhibitInput(BufferView * bv)
161 static Cursor cursor;
162 static bool cursor_undefined = true;
164 if (cursor_undefined){
165 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
166 XFlush(fl_get_display());
167 cursor_undefined = false;
170 /* set the cursor to the watch for all forms and the canvas */
171 XDefineCursor(fl_get_display(), bv->owner()->getForm()->window,
174 XFlush(fl_get_display());
175 fl_deactivate_all_forms();
179 void AllowInput(BufferView * bv)
181 /* reset the cursor from the watch for all forms and the canvas */
183 XUndefineCursor(fl_get_display(), bv->owner()->getForm()->window);
185 XFlush(fl_get_display());
186 fl_activate_all_forms();
190 void Code(BufferView * bv)
192 LyXFont font(LyXFont::ALL_IGNORE);
193 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
194 ToggleAndShow(bv, font);
198 void Sans(BufferView * bv)
200 LyXFont font(LyXFont::ALL_IGNORE);
201 font.setFamily(LyXFont::SANS_FAMILY);
202 ToggleAndShow(bv, font);
206 void Roman(BufferView * bv)
208 LyXFont font(LyXFont::ALL_IGNORE);
209 font.setFamily(LyXFont::ROMAN_FAMILY);
210 ToggleAndShow(bv, font);
214 void StyleReset(BufferView * bv)
216 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
217 ToggleAndShow(bv, font);
221 void Underline(BufferView * bv)
223 LyXFont font(LyXFont::ALL_IGNORE);
224 font.setUnderbar(LyXFont::TOGGLE);
225 ToggleAndShow(bv, font);
229 void FontSize(BufferView * bv, string const & size)
231 LyXFont font(LyXFont::ALL_IGNORE);
232 font.setLyXSize(size);
233 ToggleAndShow(bv, font);
237 // Returns the current font and depth as a message.
238 string const CurrentState(BufferView * bv)
241 if (bv->available()) {
242 // I think we should only show changes from the default
244 LyXText * text = bv->getLyXText();
245 Buffer * buffer = bv->buffer();
246 LyXFont font = text->real_current_font;
247 LyXFont const & defaultfont =
249 .TextClass(buffer->params.textclass)
251 font.reduce(defaultfont);
252 state = _("Font: ") + font.stateText(&buffer->params);
253 // The paragraph depth
254 int depth = text->GetDepth();
256 state += string(_(", Depth: ")) + tostr(depth);
257 // The paragraph spacing, but only if different from
259 if (!text->cursor.par()->params.spacing().isDefault()) {
260 Spacing::Space cur_space =
261 text->cursor.par()->params.spacing().getSpace();
262 state += _(", Spacing: ");
264 case Spacing::Single:
265 state += _("Single");
267 case Spacing::Onehalf:
268 state += _("Onehalf");
270 case Spacing::Double:
271 state += _("Double");
274 state += _("Other (");
275 state += tostr(text->cursor.par()->params.spacing().getValue());
278 case Spacing::Default:
279 // should never happen, do nothing
288 /* -------> Does the actual toggle job of the XxxCB() calls above.
289 * Also shows the current font state.
291 void ToggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
293 if (bv->available()) {
294 LyXText * text = bv->getLyXText();
297 bv->update(text, BufferView::SELECT|BufferView::FITCUR);
298 text->ToggleFree(bv, font, toggleall);
299 bv->update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
301 if (font.language() != ignore_language ||
302 font.latex() != LyXFont::IGNORE ||
303 font.number() != LyXFont::IGNORE) {
304 LyXCursor & cursor = text->cursor;
305 text->ComputeBidiTables(bv->buffer(), cursor.row());
306 if (cursor.boundary() !=
307 text->IsBoundary(bv->buffer(), cursor.par(), cursor.pos(),
308 text->real_current_font) )
309 text->SetCursor(bv, cursor.par(), cursor.pos(),
310 false, !cursor.boundary());