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"
24 #include "minibuffer.h"
26 #include "support/lstrings.h"
28 #include "layout_forms.h"
30 extern FD_form_character * fd_form_character;
33 void Foot(BufferView * bv)
38 bv->owner()->getMiniBuffer()
39 ->Set(_("Inserting Footnote..."));
41 bv->update(BufferView::SELECT|BufferView::FITCUR);
42 bv->text->InsertFootnoteEnvironment(bv, LyXParagraph::FOOTNOTE);
43 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
48 void Emph(BufferView * bv)
50 LyXFont font(LyXFont::ALL_IGNORE);
51 font.setEmph(LyXFont::TOGGLE);
52 ToggleAndShow(bv, font);
56 void Bold(BufferView * bv)
58 LyXFont font(LyXFont::ALL_IGNORE);
59 font.setSeries(LyXFont::BOLD_SERIES);
60 ToggleAndShow(bv, font);
64 void Noun(BufferView * bv)
66 LyXFont font(LyXFont::ALL_IGNORE);
67 font.setNoun(LyXFont::TOGGLE);
68 ToggleAndShow(bv, font);
73 void Margin(BufferView * bv)
75 if (bv->available()) {
76 bv->owner()->getMiniBuffer()->Set(_("Inserting margin note..."));
78 bv->update(BufferView::SELECT|BufferView::FITCUR);
79 bv->text->InsertFootnoteEnvironment(bv, LyXParagraph::MARGIN);
80 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
85 void Number(BufferView * bv)
87 LyXFont font(LyXFont::ALL_IGNORE);
88 font.setNumber(LyXFont::TOGGLE);
89 ToggleAndShow(bv, font);
92 void Lang(BufferView * bv, string const & l)
94 LyXFont font(LyXFont::ALL_IGNORE);
95 Language const * lang = languages.getLanguage(l);
97 font.setLanguage(lang);
98 ToggleAndShow(bv, font);
100 WriteAlert(_("Error! unknown language"),l);
105 void Melt(BufferView * bv)
107 if (!bv->available()) return;
109 bv->owner()->getMiniBuffer()->Set(_("Melt"));
112 bv->update(BufferView::SELECT|BufferView::FITCUR);
113 bv->text->MeltFootnoteEnvironment(bv);
114 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
119 void Tex(BufferView * bv)
121 LyXFont font(LyXFont::ALL_IGNORE);
122 font.setLatex (LyXFont::TOGGLE);
123 ToggleAndShow(bv, font);
127 // Change environment depth.
128 // if decInc >= 0, increment depth
129 // if decInc < 0, decrement depth
130 void changeDepth(BufferView * bv, LyXText * text, int decInc)
132 if (!bv->available() || !text)
136 bv->update(BufferView::SELECT|BufferView::FITCUR);
141 if (text->inset_owner)
142 bv->updateInset((Inset *)text->inset_owner, true);
143 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
144 bv->owner()->getMiniBuffer()
145 ->Set(_("Changed environment depth"
146 " (in possible range, maybe not)"));
150 void Free(BufferView * bv)
152 ToggleAndShow(bv, UserFreeFont(bv->buffer()->params));
156 // How should this actually work? Should it prohibit input in all BufferViews,
157 // or just in the current one? If "just the current one", then it should be
158 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
159 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
160 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
161 // current LyxView that should be prohibited (Lgb) (This applies to
162 // "AllowInput" as well.)
163 void ProhibitInput(BufferView * bv)
167 static Cursor cursor;
168 static bool cursor_undefined = true;
170 if (cursor_undefined){
171 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
172 XFlush(fl_get_display());
173 cursor_undefined = false;
176 /* set the cursor to the watch for all forms and the canvas */
177 XDefineCursor(fl_get_display(), bv->owner()->getForm()->window,
180 if (fd_form_character->form_character->visible)
181 XDefineCursor(fl_get_display(),
182 fd_form_character->form_character->window,
185 XFlush(fl_get_display());
186 fl_deactivate_all_forms();
190 void AllowInput(BufferView * bv)
192 /* reset the cursor from the watch for all forms and the canvas */
194 XUndefineCursor(fl_get_display(), bv->owner()->getForm()->window);
196 if (fd_form_character->form_character->visible)
197 XUndefineCursor(fl_get_display(),
198 fd_form_character->form_character->window);
200 XFlush(fl_get_display());
201 fl_activate_all_forms();
205 void Code(BufferView * bv)
207 LyXFont font(LyXFont::ALL_IGNORE);
208 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
209 ToggleAndShow(bv, font);
213 void Sans(BufferView * bv)
215 LyXFont font(LyXFont::ALL_IGNORE);
216 font.setFamily(LyXFont::SANS_FAMILY);
217 ToggleAndShow(bv, font);
221 void Roman(BufferView * bv)
223 LyXFont font(LyXFont::ALL_IGNORE);
224 font.setFamily(LyXFont::ROMAN_FAMILY);
225 ToggleAndShow(bv, font);
229 void StyleReset(BufferView * bv)
231 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
232 ToggleAndShow(bv, font);
236 void Underline(BufferView * bv)
238 LyXFont font(LyXFont::ALL_IGNORE);
239 font.setUnderbar(LyXFont::TOGGLE);
240 ToggleAndShow(bv, font);
244 void FontSize(BufferView * bv, string const & size)
246 LyXFont font(LyXFont::ALL_IGNORE);
247 font.setLyXSize(size);
248 ToggleAndShow(bv, font);
252 // Returns the current font and depth as a message.
253 string const CurrentState(BufferView * bv)
256 if (bv->available()) {
257 // I think we should only show changes from the default
259 LyXText * text = bv->getLyXText();
260 Buffer * buffer = bv->buffer();
261 LyXFont font = text->real_current_font;
262 LyXFont const & defaultfont =
264 .TextClass(buffer->params.textclass)
266 font.reduce(defaultfont);
267 state = _("Font: ") + font.stateText(&buffer->params);
268 // The paragraph depth
269 int depth = text->GetDepth();
271 state += string(_(", Depth: ")) + tostr(depth);
272 // The paragraph spacing, but only if different from
274 if (!text->cursor.par()->spacing.isDefault()) {
275 Spacing::Space cur_space =
276 text->cursor.par()->spacing.getSpace();
277 state += _(", Spacing: ");
279 case Spacing::Single:
280 state += _("Single");
282 case Spacing::Onehalf:
283 state += _("Onehalf");
285 case Spacing::Double:
286 state += _("Double");
289 state += _("Other (");
290 state += tostr(text->cursor.par()->spacing.getValue());
293 case Spacing::Default:
294 // should never happen, do nothing
303 /* -------> Does the actual toggle job of the XxxCB() calls above.
304 * Also shows the current font state.
306 void ToggleAndShow(BufferView * bv, LyXFont const & font)
308 if (bv->available()) {
310 bv->update(BufferView::SELECT|BufferView::FITCUR);
311 if (bv->theLockingInset())
312 bv->theLockingInset()->SetFont(bv, font, toggleall);
314 bv->text->ToggleFree(bv, font, toggleall);
315 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
317 if (font.language() != ignore_language ||
318 font.latex() != LyXFont::IGNORE ||
319 font.number() != LyXFont::IGNORE) {
320 LyXText * text = bv->getLyXText();
321 LyXCursor & cursor = text->cursor;
322 text->ComputeBidiTables(bv->buffer(), cursor.row());
323 if (cursor.boundary() !=
324 text->IsBoundary(bv->buffer(), cursor.par(), cursor.pos(),
325 text->real_current_font) )
326 text->SetCursor(bv, cursor.par(), cursor.pos(),
327 false, !cursor.boundary());