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);
86 void Lang(BufferView * bv, string const & l)
88 LyXFont font(LyXFont::ALL_IGNORE);
89 Languages::iterator lit = languages.find(l);
90 if (lit != languages.end()) {
91 font.setLanguage(&(*lit).second);
92 ToggleAndShow(bv, font);
94 WriteAlert(_("Error! unknown language"),l);
99 void Melt(BufferView * bv)
101 if (!bv->available()) return;
103 bv->owner()->getMiniBuffer()->Set(_("Melt"));
106 bv->update(BufferView::SELECT|BufferView::FITCUR);
107 bv->text->MeltFootnoteEnvironment(bv);
108 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
113 void Tex(BufferView * bv)
115 LyXFont font(LyXFont::ALL_IGNORE);
116 font.setLatex (LyXFont::TOGGLE);
117 ToggleAndShow(bv, font);
121 // Change environment depth.
122 // if decInc >= 0, increment depth
123 // if decInc < 0, decrement depth
124 void changeDepth(BufferView * bv, int decInc)
126 if (!bv->available()) return;
129 bv->update(BufferView::SELECT|BufferView::FITCUR);
131 bv->text->IncDepth(bv);
133 bv->text->DecDepth(bv);
134 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
135 bv->owner()->getMiniBuffer()
136 ->Set(_("Changed environment depth"
137 " (in possible range, maybe not)"));
141 void Free(BufferView * bv)
143 ToggleAndShow(bv, UserFreeFont(bv->buffer()->params));
147 // How should this actually work? Should it prohibit input in all BufferViews,
148 // or just in the current one? If "just the current one", then it should be
149 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
150 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
151 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
152 // current LyxView that should be prohibited (Lgb) (This applies to
153 // "AllowInput" as well.)
154 void ProhibitInput(BufferView * bv)
158 static Cursor cursor;
159 static bool cursor_undefined = true;
161 if (cursor_undefined){
162 cursor = XCreateFontCursor(fl_display, XC_watch);
164 cursor_undefined = false;
167 /* set the cursor to the watch for all forms and the canvas */
168 XDefineCursor(fl_display, bv->owner()->getForm()->window,
171 if (fd_form_character->form_character->visible)
172 XDefineCursor(fl_display,
173 fd_form_character->form_character->window,
177 fl_deactivate_all_forms();
181 void AllowInput(BufferView * bv)
183 /* reset the cursor from the watch for all forms and the canvas */
185 XUndefineCursor(fl_display, bv->owner()->getForm()->window);
187 if (fd_form_character->form_character->visible)
188 XUndefineCursor(fl_display,
189 fd_form_character->form_character->window);
192 fl_activate_all_forms();
196 void Code(BufferView * bv)
198 LyXFont font(LyXFont::ALL_IGNORE);
199 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
200 ToggleAndShow(bv, font);
204 void Sans(BufferView * bv)
206 LyXFont font(LyXFont::ALL_IGNORE);
207 font.setFamily(LyXFont::SANS_FAMILY);
208 ToggleAndShow(bv, font);
212 void Roman(BufferView * bv)
214 LyXFont font(LyXFont::ALL_IGNORE);
215 font.setFamily(LyXFont::ROMAN_FAMILY);
216 ToggleAndShow(bv, font);
220 void StyleReset(BufferView * bv)
222 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
223 ToggleAndShow(bv, font);
227 void Underline(BufferView * bv)
229 LyXFont font(LyXFont::ALL_IGNORE);
230 font.setUnderbar(LyXFont::TOGGLE);
231 ToggleAndShow(bv, font);
235 void FontSize(BufferView * bv, string const & size)
237 LyXFont font(LyXFont::ALL_IGNORE);
238 font.setGUISize(size);
239 ToggleAndShow(bv, font);
243 // Returns the current font and depth as a message.
244 string const CurrentState(BufferView * bv)
247 if (bv->available()) {
248 // I think we should only show changes from the default
252 if (bv->the_locking_inset)
253 text = bv->the_locking_inset->getLyXText(bv);
257 Buffer * buffer = bv->buffer();
258 LyXFont font = text->real_current_font;
259 LyXFont const & defaultfont =
261 .TextClass(buffer->params.textclass)
263 font.reduce(defaultfont);
264 state = _("Font: ") + font.stateText(&buffer->params);
265 // The paragraph depth
266 int depth = text->GetDepth();
268 state += string(_(", Depth: ")) + tostr(depth);
269 // The paragraph spacing, but only if different from
271 if (!text->cursor.par()->spacing.isDefault()) {
272 Spacing::Space cur_space =
273 text->cursor.par()->spacing.getSpace();
274 state += _(", Spacing: ");
276 case Spacing::Single:
277 state += _("Single");
279 case Spacing::Onehalf:
280 state += _("Onehalf");
282 case Spacing::Double:
283 state += _("Double");
286 state += _("Other (");
287 state += tostr(text->cursor.par()->spacing.getValue());
290 case Spacing::Default:
291 // should never happen, do nothing
300 /* -------> Does the actual toggle job of the XxxCB() calls above.
301 * Also shows the current font state.
303 void ToggleAndShow(BufferView * bv, LyXFont const & font)
305 if (bv->available()) {
307 bv->update(BufferView::SELECT|BufferView::FITCUR);
308 if (bv->the_locking_inset)
309 bv->the_locking_inset->SetFont(bv, font, toggleall);
311 bv->text->ToggleFree(bv, font, toggleall);
312 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
314 if (font.language() != ignore_language ||
315 font.latex() != LyXFont::IGNORE) {
316 LyXText * text = bv->text;
317 LyXCursor & cursor = text->cursor;
318 text->ComputeBidiTables(bv->buffer(), cursor.row());
319 if (cursor.boundary() !=
320 text->IsBoundary(bv->buffer(), cursor.par(), cursor.pos(),
321 text->real_current_font) )
322 text->SetCursor(bv, cursor.par(), cursor.pos(),
323 false, !cursor.boundary());