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 as a message.
236 string CurrentState(BufferView * bv)
239 if (bv->available()) {
240 // I think we should only show changes from the default
242 Buffer * buffer = bv->buffer();
243 LyXFont font = bv->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 = bv->text->GetDepth();
253 state += string(_(", Depth: ")) + tostr(depth);
254 // The paragraph spacing, but only if different from
256 if (!bv->text->cursor.par()->spacing.isDefault()) {
257 Spacing::Space cur_space =
258 bv->text->cursor.par()->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(bv->text->cursor.par()->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)
290 if (bv->available()) {
292 bv->update(BufferView::SELECT|BufferView::FITCUR);
293 if (bv->the_locking_inset)
294 bv->the_locking_inset->SetFont(bv, font, toggleall);
296 bv->text->ToggleFree(bv, font, toggleall);
297 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
299 if (font.language() != ignore_language ||
300 font.latex() != LyXFont::IGNORE) {
301 LyXText * text = bv->text;
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());