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 CurrentState(BufferView * bv)
253 if (bv->available()) {
254 // I think we should only show changes from the default
256 Buffer * buffer = bv->buffer();
257 LyXFont font = bv->text->real_current_font;
258 LyXFont const & defaultfont =
260 .TextClass(buffer->params.textclass)
262 font.reduce(defaultfont);
263 state = _("Font: ") + font.stateText(&buffer->params);
264 // The paragraph depth
265 int depth = bv->text->GetDepth();
267 state += string(_(", Depth: ")) + tostr(depth);
268 // The paragraph spacing, but only if different from
270 if (!bv->text->cursor.par()->spacing.isDefault()) {
271 Spacing::Space cur_space =
272 bv->text->cursor.par()->spacing.getSpace();
273 state += _(", Spacing: ");
275 case Spacing::Single:
276 state += _("Single");
278 case Spacing::Onehalf:
279 state += _("Onehalf");
281 case Spacing::Double:
282 state += _("Double");
285 state += _("Other (");
286 state += tostr(bv->text->cursor.par()->spacing.getValue());
289 case Spacing::Default:
290 // should never happen, do nothing
299 /* -------> Does the actual toggle job of the XxxCB() calls above.
300 * Also shows the current font state.
302 void ToggleAndShow(BufferView * bv, LyXFont const & font)
304 if (bv->available()) {
306 bv->update(BufferView::SELECT|BufferView::FITCUR);
307 if (bv->the_locking_inset)
308 bv->the_locking_inset->SetFont(bv, font, toggleall);
310 bv->text->ToggleFree(bv, font, toggleall);
311 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
313 if (font.language() != ignore_language ||
314 font.latex() != LyXFont::IGNORE) {
315 LyXText * text = bv->text;
316 LyXCursor & cursor = text->cursor;
317 text->ComputeBidiTables(bv->buffer(), cursor.row());
318 if (cursor.boundary() !=
319 text->IsBoundary(bv->buffer(), cursor.par(), cursor.pos(),
320 text->real_current_font) )
321 text->SetCursor(bv, cursor.par(), cursor.pos(),
322 false, !cursor.boundary());