3 #include "bufferview_funcs.h"
5 #include "BufferView.h"
6 #include "lyxparagraph.h"
8 #include "lyx_gui_misc.h"
10 #include "minibuffer.h"
12 #include "support/lstrings.h"
14 #include "layout_forms.h"
16 extern FD_form_paragraph * fd_form_paragraph;
17 extern FD_form_character * fd_form_character;
20 void Foot(BufferView * bv)
25 bv->owner()->getMiniBuffer()
26 ->Set(_("Inserting Footnote..."));
28 bv->update(BufferView::SELECT|BufferView::FITCUR);
29 bv->text->InsertFootnoteEnvironment(bv, LyXParagraph::FOOTNOTE);
30 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
35 void Emph(BufferView * bv)
37 LyXFont font(LyXFont::ALL_IGNORE);
38 font.setEmph(LyXFont::TOGGLE);
39 ToggleAndShow(bv, font);
43 void Bold(BufferView * bv)
45 LyXFont font(LyXFont::ALL_IGNORE);
46 font.setSeries(LyXFont::BOLD_SERIES);
47 ToggleAndShow(bv, font);
51 void Noun(BufferView * bv)
53 LyXFont font(LyXFont::ALL_IGNORE);
54 font.setNoun(LyXFont::TOGGLE);
55 ToggleAndShow(bv, font);
60 void Margin(BufferView * bv)
62 if (bv->available()) {
63 bv->owner()->getMiniBuffer()->Set(_("Inserting margin note..."));
65 bv->update(BufferView::SELECT|BufferView::FITCUR);
66 bv->text->InsertFootnoteEnvironment(bv, LyXParagraph::MARGIN);
67 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
73 void Lang(BufferView * bv, string const & l)
75 LyXFont font(LyXFont::ALL_IGNORE);
76 Languages::iterator lit = languages.find(l);
77 if (lit != languages.end()) {
78 font.setLanguage(&(*lit).second);
79 ToggleAndShow(bv, font);
81 WriteAlert(_("Error! unknown language"),l);
86 void Melt(BufferView * bv)
88 if (!bv->available()) return;
90 bv->owner()->getMiniBuffer()->Set(_("Melt"));
93 bv->update(BufferView::SELECT|BufferView::FITCUR);
94 bv->text->MeltFootnoteEnvironment(bv);
95 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
100 void Tex(BufferView * bv)
102 LyXFont font(LyXFont::ALL_IGNORE);
103 font.setLatex (LyXFont::TOGGLE);
104 ToggleAndShow(bv, font);
108 // Change environment depth.
109 // if decInc >= 0, increment depth
110 // if decInc < 0, decrement depth
111 void changeDepth(BufferView * bv, int decInc)
113 if (!bv->available()) return;
116 bv->update(BufferView::SELECT|BufferView::FITCUR);
118 bv->text->IncDepth(bv);
120 bv->text->DecDepth(bv);
121 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
122 bv->owner()->getMiniBuffer()
123 ->Set(_("Changed environment depth"
124 " (in possible range, maybe not)"));
128 void Free(BufferView * bv)
130 ToggleAndShow(bv, UserFreeFont(bv->buffer()->params));
134 // How should this actually work? Should it prohibit input in all BufferViews,
135 // or just in the current one? If "just the current one", then it should be
136 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
137 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
138 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
139 // current LyxView that should be prohibited (Lgb) (This applies to
140 // "AllowInput" as well.)
141 void ProhibitInput(BufferView * bv)
145 static Cursor cursor;
146 static bool cursor_undefined = true;
148 if (cursor_undefined){
149 cursor = XCreateFontCursor(fl_display, XC_watch);
151 cursor_undefined = false;
154 /* set the cursor to the watch for all forms and the canvas */
155 XDefineCursor(fl_display, bv->owner()->getForm()->window,
157 if (fd_form_paragraph->form_paragraph->visible)
158 XDefineCursor(fl_display,
159 fd_form_paragraph->form_paragraph->window,
161 if (fd_form_character->form_character->visible)
162 XDefineCursor(fl_display,
163 fd_form_character->form_character->window,
167 fl_deactivate_all_forms();
171 void AllowInput(BufferView * bv)
173 /* reset the cursor from the watch for all forms and the canvas */
175 XUndefineCursor(fl_display, bv->owner()->getForm()->window);
176 if (fd_form_paragraph->form_paragraph->visible)
177 XUndefineCursor(fl_display,
178 fd_form_paragraph->form_paragraph->window);
179 if (fd_form_character->form_character->visible)
180 XUndefineCursor(fl_display,
181 fd_form_character->form_character->window);
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.setGUISize(size);
231 ToggleAndShow(bv, font);
235 /* -------> Returns the current font and depth by printing a message. In the
236 * future perhaps we could try to implement a callback to the button-bar.
237 * That is, `light' the bold button when the font is currently bold, etc.
239 string CurrentState(BufferView * bv)
242 if (bv->available()) {
243 // I think we should only show changes from the default
245 Buffer * buffer = bv->buffer();
246 LyXFont font = bv->text->real_current_font;
247 LyXFont const & defaultfont =
249 .TextClass(buffer->params.textclass)
251 font.reduce(defaultfont);
252 state = _("Font: ") + font.stateText(&buffer->params);
253 // The paragraph depth
254 int depth = bv->text->GetDepth();
256 state += string(_(", Depth: ")) + tostr(depth);
257 // The paragraph spacing, but only if different from
259 if (!bv->text->cursor.par()->spacing.isDefault()) {
260 Spacing::Space cur_space =
261 bv->text->cursor.par()->spacing.getSpace();
262 state += _(", Spacing: ");
264 case Spacing::Single:
265 state += _("Single");
267 case Spacing::Onehalf:
268 state += _("Onehalf");
270 case Spacing::Double:
271 state += _("Double");
274 state += _("Other (");
275 state += tostr(bv->text->cursor.par()->spacing.getValue());
278 case Spacing::Default:
279 // should never happen, do nothing
288 /* -------> Does the actual toggle job of the XxxCB() calls above.
289 * Also shows the current font state.
291 void ToggleAndShow(BufferView * bv, LyXFont const & font)
293 if (bv->available()) {
295 bv->update(BufferView::SELECT|BufferView::FITCUR);
296 if (bv->the_locking_inset)
297 bv->the_locking_inset->SetFont(bv, font, toggleall);
299 bv->text->ToggleFree(bv, font, toggleall);
300 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
302 if (font.language() != ignore_language ||
303 font.latex() != LyXFont::IGNORE) {
304 LyXText * text = bv->text;
305 LyXCursor & cursor = text->cursor;
306 text->ComputeBidiTables(bv->buffer(), cursor.row());
307 if (cursor.boundary() !=
308 text->IsBoundary(bv->buffer(), cursor.par(), cursor.pos(),
309 text->real_current_font) )
310 text->SetCursor(bv, cursor.par(), cursor.pos(),
311 false, !cursor.boundary());