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"
25 #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()->message(_("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()->message(_("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()->message(_("Changed environment depth "
143 "(in possible range, maybe not)"));
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_get_display(), XC_watch);
163 XFlush(fl_get_display());
164 cursor_undefined = false;
167 /* set the cursor to the watch for all forms and the canvas */
168 XDefineCursor(fl_get_display(), bv->owner()->getForm()->window,
171 XFlush(fl_get_display());
172 fl_deactivate_all_forms();
176 void AllowInput(BufferView * bv)
178 /* reset the cursor from the watch for all forms and the canvas */
180 XUndefineCursor(fl_get_display(), bv->owner()->getForm()->window);
182 XFlush(fl_get_display());
183 fl_activate_all_forms();
187 void Code(BufferView * bv)
189 LyXFont font(LyXFont::ALL_IGNORE);
190 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
191 ToggleAndShow(bv, font);
195 void Sans(BufferView * bv)
197 LyXFont font(LyXFont::ALL_IGNORE);
198 font.setFamily(LyXFont::SANS_FAMILY);
199 ToggleAndShow(bv, font);
203 void Roman(BufferView * bv)
205 LyXFont font(LyXFont::ALL_IGNORE);
206 font.setFamily(LyXFont::ROMAN_FAMILY);
207 ToggleAndShow(bv, font);
211 void StyleReset(BufferView * bv)
213 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
214 ToggleAndShow(bv, font);
218 void Underline(BufferView * bv)
220 LyXFont font(LyXFont::ALL_IGNORE);
221 font.setUnderbar(LyXFont::TOGGLE);
222 ToggleAndShow(bv, font);
226 void FontSize(BufferView * bv, string const & size)
228 LyXFont font(LyXFont::ALL_IGNORE);
229 font.setLyXSize(size);
230 ToggleAndShow(bv, font);
234 // Returns the current font and depth as a message.
235 string const CurrentState(BufferView * bv)
238 if (bv->available()) {
239 // I think we should only show changes from the default
241 LyXText * text = bv->getLyXText();
242 Buffer * buffer = bv->buffer();
243 LyXFont font = text->real_current_font;
244 LyXFont const & defaultfont =
246 .TextClass(buffer->params.textclass)
248 font.reduce(defaultfont);
249 state = _("Font: ") + font.stateText(&buffer->params);
250 // The paragraph depth
251 int depth = text->GetDepth();
253 state += string(_(", Depth: ")) + tostr(depth);
254 // The paragraph spacing, but only if different from
256 if (!text->cursor.par()->params.spacing().isDefault()) {
257 Spacing::Space cur_space =
258 text->cursor.par()->params.spacing().getSpace();
259 state += _(", Spacing: ");
261 case Spacing::Single:
262 state += _("Single");
264 case Spacing::Onehalf:
265 state += _("Onehalf");
267 case Spacing::Double:
268 state += _("Double");
271 state += _("Other (");
272 state += tostr(text->cursor.par()->params.spacing().getValue());
275 case Spacing::Default:
276 // should never happen, do nothing
285 /* -------> Does the actual toggle job of the XxxCB() calls above.
286 * Also shows the current font state.
288 void ToggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
290 if (bv->available()) {
291 LyXText * text = bv->getLyXText();
294 bv->update(text, BufferView::SELECT|BufferView::FITCUR);
295 text->ToggleFree(bv, font, toggleall);
296 bv->update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
298 if (font.language() != ignore_language ||
299 font.latex() != LyXFont::IGNORE ||
300 font.number() != LyXFont::IGNORE) {
301 LyXCursor & cursor = text->cursor;
302 text->ComputeBidiTables(bv->buffer(), cursor.row());
303 if (cursor.boundary() !=
304 text->IsBoundary(bv->buffer(), cursor.par(), cursor.pos(),
305 text->real_current_font) )
306 text->SetCursor(bv, cursor.par(), cursor.pos(),
307 false, !cursor.boundary());