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);
34 void Emph(BufferView * bv)
36 LyXFont font(LyXFont::ALL_IGNORE);
37 font.setEmph(LyXFont::TOGGLE);
38 ToggleAndShow(bv, font);
42 void Bold(BufferView * bv)
44 LyXFont font(LyXFont::ALL_IGNORE);
45 font.setSeries(LyXFont::BOLD_SERIES);
46 ToggleAndShow(bv, font);
50 void Noun(BufferView * bv)
52 LyXFont font(LyXFont::ALL_IGNORE);
53 font.setNoun(LyXFont::TOGGLE);
54 ToggleAndShow(bv, font);
58 void Margin(BufferView * bv)
60 if (bv->available()) {
61 bv->owner()->getMiniBuffer()->Set(_("Inserting margin note..."));
63 bv->update(BufferView::SELECT|BufferView::FITCUR);
64 bv->text->InsertFootnoteEnvironment(bv, LyXParagraph::MARGIN);
65 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
70 void Lang(BufferView * bv, string const & l)
72 LyXFont font(LyXFont::ALL_IGNORE);
73 Languages::iterator lit = languages.find(l);
74 if (lit != languages.end()) {
75 font.setLanguage(&(*lit).second);
76 ToggleAndShow(bv, font);
78 WriteAlert(_("Error! unknown language"),l);
82 void Melt(BufferView * bv)
84 if (!bv->available()) return;
86 bv->owner()->getMiniBuffer()->Set(_("Melt"));
89 bv->update(BufferView::SELECT|BufferView::FITCUR);
90 bv->text->MeltFootnoteEnvironment(bv);
91 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
95 void Tex(BufferView * bv)
97 LyXFont font(LyXFont::ALL_IGNORE);
98 font.setLatex (LyXFont::TOGGLE);
99 ToggleAndShow(bv, font);
103 // Change environment depth.
104 // if decInc >= 0, increment depth
105 // if decInc < 0, decrement depth
106 void changeDepth(BufferView * bv, int decInc)
108 if (!bv->available()) return;
111 bv->update(BufferView::SELECT|BufferView::FITCUR);
113 bv->text->IncDepth(bv);
115 bv->text->DecDepth(bv);
116 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
117 bv->owner()->getMiniBuffer()
118 ->Set(_("Changed environment depth"
119 " (in possible range, maybe not)"));
123 void Free(BufferView * bv)
125 ToggleAndShow(bv, UserFreeFont(bv->buffer()->params));
129 // How should this actually work? Should it prohibit input in all BufferViews,
130 // or just in the current one? If "just the current one", then it should be
131 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
132 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
133 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
134 // current LyxView that should be prohibited (Lgb) (This applies to
135 // "AllowInput" as well.)
136 void ProhibitInput(BufferView * bv)
140 static Cursor cursor;
141 static bool cursor_undefined = true;
143 if (cursor_undefined){
144 cursor = XCreateFontCursor(fl_display, XC_watch);
146 cursor_undefined = false;
149 /* set the cursor to the watch for all forms and the canvas */
150 XDefineCursor(fl_display, bv->owner()->getForm()->window,
152 if (fd_form_paragraph->form_paragraph->visible)
153 XDefineCursor(fl_display,
154 fd_form_paragraph->form_paragraph->window,
156 if (fd_form_character->form_character->visible)
157 XDefineCursor(fl_display,
158 fd_form_character->form_character->window,
162 fl_deactivate_all_forms();
166 void AllowInput(BufferView * bv)
168 /* reset the cursor from the watch for all forms and the canvas */
170 XUndefineCursor(fl_display, bv->owner()->getForm()->window);
171 if (fd_form_paragraph->form_paragraph->visible)
172 XUndefineCursor(fl_display,
173 fd_form_paragraph->form_paragraph->window);
174 if (fd_form_character->form_character->visible)
175 XUndefineCursor(fl_display,
176 fd_form_character->form_character->window);
179 fl_activate_all_forms();
183 void Code(BufferView * bv)
185 LyXFont font(LyXFont::ALL_IGNORE);
186 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
187 ToggleAndShow(bv, font);
191 void Sans(BufferView * bv)
193 LyXFont font(LyXFont::ALL_IGNORE);
194 font.setFamily(LyXFont::SANS_FAMILY);
195 ToggleAndShow(bv, font);
199 void Roman(BufferView * bv)
201 LyXFont font(LyXFont::ALL_IGNORE);
202 font.setFamily(LyXFont::ROMAN_FAMILY);
203 ToggleAndShow(bv, font);
207 void StyleReset(BufferView * bv)
209 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
210 ToggleAndShow(bv, font);
214 void Underline(BufferView * bv)
216 LyXFont font(LyXFont::ALL_IGNORE);
217 font.setUnderbar(LyXFont::TOGGLE);
218 ToggleAndShow(bv, font);
222 void FontSize(BufferView * bv, string const & size)
224 LyXFont font(LyXFont::ALL_IGNORE);
225 font.setGUISize(size);
226 ToggleAndShow(bv, font);
230 /* -------> Returns the current font and depth by printing a message. In the
231 * future perhaps we could try to implement a callback to the button-bar.
232 * That is, `light' the bold button when the font is currently bold, etc.
234 string CurrentState(BufferView * bv)
237 if (bv->available()) {
238 // I think we should only show changes from the default
240 Buffer * buffer = bv->buffer();
241 LyXFont font = bv->text->real_current_font;
242 LyXFont const & defaultfont =
244 .TextClass(buffer->params.textclass)
246 font.reduce(defaultfont);
247 state = _("Font: ") + font.stateText(&buffer->params);
248 // The paragraph depth
249 int depth = bv->text->GetDepth();
251 state += string(_(", Depth: ")) + tostr(depth);
252 // The paragraph spacing, but only if different from
254 if (!bv->text->cursor.par()->spacing.isDefault()) {
255 Spacing::Space cur_space =
256 bv->text->cursor.par()->spacing.getSpace();
257 state += _(", Spacing: ");
259 case Spacing::Single:
260 state += _("Single");
262 case Spacing::Onehalf:
263 state += _("Onehalf");
265 case Spacing::Double:
266 state += _("Double");
269 state += _("Other (");
270 state += tostr(bv->text->cursor.par()->spacing.getValue());
273 case Spacing::Default:
274 // should never happen, do nothing
283 /* -------> Does the actual toggle job of the XxxCB() calls above.
284 * Also shows the current font state.
286 void ToggleAndShow(BufferView * bv, LyXFont const & font)
288 if (bv->available()) {
290 bv->update(BufferView::SELECT|BufferView::FITCUR);
291 if (bv->the_locking_inset)
292 bv->the_locking_inset->SetFont(bv, font, toggleall);
294 bv->text->ToggleFree(bv, font, toggleall);
295 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
297 if (font.language() != ignore_language ||
298 font.latex() != LyXFont::IGNORE) {
299 LyXText * text = bv->text;
300 LyXCursor & cursor = text->cursor;
301 text->ComputeBidiTables(bv->buffer(), cursor.row());
302 if (cursor.boundary() !=
303 text->IsBoundary(bv->buffer(), cursor.par(), cursor.pos(),
304 text->real_current_font) )
305 text->SetCursor(bv, cursor.par(), cursor.pos(),
306 false, !cursor.boundary());