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, int decInc)
132 if (!bv->available()) return;
135 bv->update(BufferView::SELECT|BufferView::FITCUR);
137 bv->text->IncDepth(bv);
139 bv->text->DecDepth(bv);
140 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
141 bv->owner()->getMiniBuffer()
142 ->Set(_("Changed environment depth"
143 " (in possible range, maybe not)"));
147 void Free(BufferView * bv)
149 ToggleAndShow(bv, UserFreeFont(bv->buffer()->params));
153 // How should this actually work? Should it prohibit input in all BufferViews,
154 // or just in the current one? If "just the current one", then it should be
155 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
156 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
157 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
158 // current LyxView that should be prohibited (Lgb) (This applies to
159 // "AllowInput" as well.)
160 void ProhibitInput(BufferView * bv)
164 static Cursor cursor;
165 static bool cursor_undefined = true;
167 if (cursor_undefined){
168 cursor = XCreateFontCursor(fl_display, XC_watch);
170 cursor_undefined = false;
173 /* set the cursor to the watch for all forms and the canvas */
174 XDefineCursor(fl_display, bv->owner()->getForm()->window,
177 if (fd_form_character->form_character->visible)
178 XDefineCursor(fl_display,
179 fd_form_character->form_character->window,
183 fl_deactivate_all_forms();
187 void AllowInput(BufferView * bv)
189 /* reset the cursor from the watch for all forms and the canvas */
191 XUndefineCursor(fl_display, bv->owner()->getForm()->window);
193 if (fd_form_character->form_character->visible)
194 XUndefineCursor(fl_display,
195 fd_form_character->form_character->window);
198 fl_activate_all_forms();
202 void Code(BufferView * bv)
204 LyXFont font(LyXFont::ALL_IGNORE);
205 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
206 ToggleAndShow(bv, font);
210 void Sans(BufferView * bv)
212 LyXFont font(LyXFont::ALL_IGNORE);
213 font.setFamily(LyXFont::SANS_FAMILY);
214 ToggleAndShow(bv, font);
218 void Roman(BufferView * bv)
220 LyXFont font(LyXFont::ALL_IGNORE);
221 font.setFamily(LyXFont::ROMAN_FAMILY);
222 ToggleAndShow(bv, font);
226 void StyleReset(BufferView * bv)
228 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
229 ToggleAndShow(bv, font);
233 void Underline(BufferView * bv)
235 LyXFont font(LyXFont::ALL_IGNORE);
236 font.setUnderbar(LyXFont::TOGGLE);
237 ToggleAndShow(bv, font);
241 void FontSize(BufferView * bv, string const & size)
243 LyXFont font(LyXFont::ALL_IGNORE);
244 font.setGUISize(size);
245 ToggleAndShow(bv, font);
249 // Returns the current font and depth as a message.
250 string const CurrentState(BufferView * bv)
253 if (bv->available()) {
254 // I think we should only show changes from the default
258 if (bv->theLockingInset())
259 text = bv->theLockingInset()->getLyXText(bv);
263 Buffer * buffer = bv->buffer();
264 LyXFont font = text->real_current_font;
265 LyXFont const & defaultfont =
267 .TextClass(buffer->params.textclass)
269 font.reduce(defaultfont);
270 state = _("Font: ") + font.stateText(&buffer->params);
271 // The paragraph depth
272 int depth = text->GetDepth();
274 state += string(_(", Depth: ")) + tostr(depth);
275 // The paragraph spacing, but only if different from
277 if (!text->cursor.par()->spacing.isDefault()) {
278 Spacing::Space cur_space =
279 text->cursor.par()->spacing.getSpace();
280 state += _(", Spacing: ");
282 case Spacing::Single:
283 state += _("Single");
285 case Spacing::Onehalf:
286 state += _("Onehalf");
288 case Spacing::Double:
289 state += _("Double");
292 state += _("Other (");
293 state += tostr(text->cursor.par()->spacing.getValue());
296 case Spacing::Default:
297 // should never happen, do nothing
306 /* -------> Does the actual toggle job of the XxxCB() calls above.
307 * Also shows the current font state.
309 void ToggleAndShow(BufferView * bv, LyXFont const & font)
311 if (bv->available()) {
313 bv->update(BufferView::SELECT|BufferView::FITCUR);
314 if (bv->theLockingInset())
315 bv->theLockingInset()->SetFont(bv, font, toggleall);
317 bv->text->ToggleFree(bv, font, toggleall);
318 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
320 if (font.language() != ignore_language ||
321 font.latex() != LyXFont::IGNORE ||
322 font.number() != LyXFont::IGNORE) {
323 LyXText * text = bv->text;
324 LyXCursor & cursor = text->cursor;
325 text->ComputeBidiTables(bv->buffer(), cursor.row());
326 if (cursor.boundary() !=
327 text->IsBoundary(bv->buffer(), cursor.par(), cursor.pos(),
328 text->real_current_font) )
329 text->SetCursor(bv, cursor.par(), cursor.pos(),
330 false, !cursor.boundary());