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_paragraph * fd_form_paragraph;
31 extern FD_form_character * fd_form_character;
34 void Foot(BufferView * bv)
39 bv->owner()->getMiniBuffer()
40 ->Set(_("Inserting Footnote..."));
42 bv->update(BufferView::SELECT|BufferView::FITCUR);
43 bv->text->InsertFootnoteEnvironment(bv, LyXParagraph::FOOTNOTE);
44 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
49 void Emph(BufferView * bv)
51 LyXFont font(LyXFont::ALL_IGNORE);
52 font.setEmph(LyXFont::TOGGLE);
53 ToggleAndShow(bv, font);
57 void Bold(BufferView * bv)
59 LyXFont font(LyXFont::ALL_IGNORE);
60 font.setSeries(LyXFont::BOLD_SERIES);
61 ToggleAndShow(bv, font);
65 void Noun(BufferView * bv)
67 LyXFont font(LyXFont::ALL_IGNORE);
68 font.setNoun(LyXFont::TOGGLE);
69 ToggleAndShow(bv, font);
74 void Margin(BufferView * bv)
76 if (bv->available()) {
77 bv->owner()->getMiniBuffer()->Set(_("Inserting margin note..."));
79 bv->update(BufferView::SELECT|BufferView::FITCUR);
80 bv->text->InsertFootnoteEnvironment(bv, LyXParagraph::MARGIN);
81 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
87 void Lang(BufferView * bv, string const & l)
89 LyXFont font(LyXFont::ALL_IGNORE);
90 Languages::iterator lit = languages.find(l);
91 if (lit != languages.end()) {
92 font.setLanguage(&(*lit).second);
93 ToggleAndShow(bv, font);
95 WriteAlert(_("Error! unknown language"),l);
100 void Melt(BufferView * bv)
102 if (!bv->available()) return;
104 bv->owner()->getMiniBuffer()->Set(_("Melt"));
107 bv->update(BufferView::SELECT|BufferView::FITCUR);
108 bv->text->MeltFootnoteEnvironment(bv);
109 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
114 void Tex(BufferView * bv)
116 LyXFont font(LyXFont::ALL_IGNORE);
117 font.setLatex (LyXFont::TOGGLE);
118 ToggleAndShow(bv, font);
122 // Change environment depth.
123 // if decInc >= 0, increment depth
124 // if decInc < 0, decrement depth
125 void changeDepth(BufferView * bv, int decInc)
127 if (!bv->available()) return;
130 bv->update(BufferView::SELECT|BufferView::FITCUR);
132 bv->text->IncDepth(bv);
134 bv->text->DecDepth(bv);
135 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
136 bv->owner()->getMiniBuffer()
137 ->Set(_("Changed environment depth"
138 " (in possible range, maybe not)"));
142 void Free(BufferView * bv)
144 ToggleAndShow(bv, UserFreeFont(bv->buffer()->params));
148 // How should this actually work? Should it prohibit input in all BufferViews,
149 // or just in the current one? If "just the current one", then it should be
150 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
151 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
152 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
153 // current LyxView that should be prohibited (Lgb) (This applies to
154 // "AllowInput" as well.)
155 void ProhibitInput(BufferView * bv)
159 static Cursor cursor;
160 static bool cursor_undefined = true;
162 if (cursor_undefined){
163 cursor = XCreateFontCursor(fl_display, XC_watch);
165 cursor_undefined = false;
168 /* set the cursor to the watch for all forms and the canvas */
169 XDefineCursor(fl_display, bv->owner()->getForm()->window,
171 if (fd_form_paragraph->form_paragraph->visible)
172 XDefineCursor(fl_display,
173 fd_form_paragraph->form_paragraph->window,
175 if (fd_form_character->form_character->visible)
176 XDefineCursor(fl_display,
177 fd_form_character->form_character->window,
181 fl_deactivate_all_forms();
185 void AllowInput(BufferView * bv)
187 /* reset the cursor from the watch for all forms and the canvas */
189 XUndefineCursor(fl_display, bv->owner()->getForm()->window);
190 if (fd_form_paragraph->form_paragraph->visible)
191 XUndefineCursor(fl_display,
192 fd_form_paragraph->form_paragraph->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->the_locking_inset)
259 text = bv->the_locking_inset->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->the_locking_inset)
315 bv->the_locking_inset->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 LyXText * text = bv->text;
323 LyXCursor & cursor = text->cursor;
324 text->ComputeBidiTables(bv->buffer(), cursor.row());
325 if (cursor.boundary() !=
326 text->IsBoundary(bv->buffer(), cursor.par(), cursor.pos(),
327 text->real_current_font) )
328 text->SetCursor(bv, cursor.par(), cursor.pos(),
329 false, !cursor.boundary());