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"
31 void Foot(BufferView * bv)
36 bv->owner()->getMiniBuffer()
37 ->Set(_("Inserting Footnote..."));
39 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
40 bv->text->InsertFootnoteEnvironment(bv, LyXParagraph::FOOTNOTE);
41 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
46 void Emph(BufferView * bv)
48 LyXFont font(LyXFont::ALL_IGNORE);
49 font.setEmph(LyXFont::TOGGLE);
50 ToggleAndShow(bv, font);
54 void Bold(BufferView * bv)
56 LyXFont font(LyXFont::ALL_IGNORE);
57 font.setSeries(LyXFont::BOLD_SERIES);
58 ToggleAndShow(bv, font);
62 void Noun(BufferView * bv)
64 LyXFont font(LyXFont::ALL_IGNORE);
65 font.setNoun(LyXFont::TOGGLE);
66 ToggleAndShow(bv, font);
71 void Margin(BufferView * bv)
73 if (bv->available()) {
74 bv->owner()->getMiniBuffer()->Set(_("Inserting margin note..."));
76 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
77 bv->text->InsertFootnoteEnvironment(bv, LyXParagraph::MARGIN);
78 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
83 void Number(BufferView * bv)
85 LyXFont font(LyXFont::ALL_IGNORE);
86 font.setNumber(LyXFont::TOGGLE);
87 ToggleAndShow(bv, font);
90 void Lang(BufferView * bv, string const & l)
92 LyXFont font(LyXFont::ALL_IGNORE);
93 Language const * lang = languages.getLanguage(l);
95 font.setLanguage(lang);
96 ToggleAndShow(bv, font);
98 WriteAlert(_("Error! unknown language"),l);
103 void Melt(BufferView * bv)
105 if (!bv->available()) return;
107 bv->owner()->getMiniBuffer()->Set(_("Melt"));
109 bv->beforeChange(bv->text);
110 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
111 bv->text->MeltFootnoteEnvironment(bv);
112 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
117 void Tex(BufferView * bv)
119 LyXFont font(LyXFont::ALL_IGNORE);
120 font.setLatex (LyXFont::TOGGLE);
121 ToggleAndShow(bv, font);
125 // Change environment depth.
126 // if decInc >= 0, increment depth
127 // if decInc < 0, decrement depth
128 void changeDepth(BufferView * bv, LyXText * text, int decInc)
130 if (!bv->available() || !text)
134 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
139 if (text->inset_owner)
140 bv->updateInset((Inset *)text->inset_owner, true);
141 bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
142 bv->owner()->getMiniBuffer()
143 ->Set(_("Changed environment depth"
144 " (in possible range, maybe not)"));
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_get_display(), XC_watch);
164 XFlush(fl_get_display());
165 cursor_undefined = false;
168 /* set the cursor to the watch for all forms and the canvas */
169 XDefineCursor(fl_get_display(), bv->owner()->getForm()->window,
172 XFlush(fl_get_display());
173 fl_deactivate_all_forms();
177 void AllowInput(BufferView * bv)
179 /* reset the cursor from the watch for all forms and the canvas */
181 XUndefineCursor(fl_get_display(), bv->owner()->getForm()->window);
183 XFlush(fl_get_display());
184 fl_activate_all_forms();
188 void Code(BufferView * bv)
190 LyXFont font(LyXFont::ALL_IGNORE);
191 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
192 ToggleAndShow(bv, font);
196 void Sans(BufferView * bv)
198 LyXFont font(LyXFont::ALL_IGNORE);
199 font.setFamily(LyXFont::SANS_FAMILY);
200 ToggleAndShow(bv, font);
204 void Roman(BufferView * bv)
206 LyXFont font(LyXFont::ALL_IGNORE);
207 font.setFamily(LyXFont::ROMAN_FAMILY);
208 ToggleAndShow(bv, font);
212 void StyleReset(BufferView * bv)
214 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
215 ToggleAndShow(bv, font);
219 void Underline(BufferView * bv)
221 LyXFont font(LyXFont::ALL_IGNORE);
222 font.setUnderbar(LyXFont::TOGGLE);
223 ToggleAndShow(bv, font);
227 void FontSize(BufferView * bv, string const & size)
229 LyXFont font(LyXFont::ALL_IGNORE);
230 font.setLyXSize(size);
231 ToggleAndShow(bv, font);
235 // Returns the current font and depth as a message.
236 string const CurrentState(BufferView * bv)
239 if (bv->available()) {
240 // I think we should only show changes from the default
242 LyXText * text = bv->getLyXText();
243 Buffer * buffer = bv->buffer();
244 LyXFont font = text->real_current_font;
245 LyXFont const & defaultfont =
247 .TextClass(buffer->params.textclass)
249 font.reduce(defaultfont);
250 state = _("Font: ") + font.stateText(&buffer->params);
251 // The paragraph depth
252 int depth = text->GetDepth();
254 state += string(_(", Depth: ")) + tostr(depth);
255 // The paragraph spacing, but only if different from
257 if (!text->cursor.par()->spacing.isDefault()) {
258 Spacing::Space cur_space =
259 text->cursor.par()->spacing.getSpace();
260 state += _(", Spacing: ");
262 case Spacing::Single:
263 state += _("Single");
265 case Spacing::Onehalf:
266 state += _("Onehalf");
268 case Spacing::Double:
269 state += _("Double");
272 state += _("Other (");
273 state += tostr(text->cursor.par()->spacing.getValue());
276 case Spacing::Default:
277 // should never happen, do nothing
286 /* -------> Does the actual toggle job of the XxxCB() calls above.
287 * Also shows the current font state.
289 void ToggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
291 if (bv->available()) {
292 LyXText * text = bv->getLyXText();
295 bv->update(text, BufferView::SELECT|BufferView::FITCUR);
296 text->ToggleFree(bv, font, toggleall);
297 bv->update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
299 if (font.language() != ignore_language ||
300 font.latex() != LyXFont::IGNORE ||
301 font.number() != LyXFont::IGNORE) {
302 LyXCursor & cursor = text->cursor;
303 text->ComputeBidiTables(bv->buffer(), cursor.row());
304 if (cursor.boundary() !=
305 text->IsBoundary(bv->buffer(), cursor.par(), cursor.pos(),
306 text->real_current_font) )
307 text->SetCursor(bv, cursor.par(), cursor.pos(),
308 false, !cursor.boundary());