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;
21 void SetXtermCursor(Window win)
24 static bool cursor_undefined = true;
25 if (cursor_undefined){
26 cursor = XCreateFontCursor(fl_display, XC_xterm);
28 cursor_undefined = false;
30 XDefineCursor(fl_display, win, cursor);
35 void Foot(BufferView * bv)
40 bv->owner()->getMiniBuffer()
41 ->Set(_("Inserting Footnote..."));
44 bv->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
49 void Emph(BufferView * bv)
51 LyXFont font(LyXFont::ALL_IGNORE);
52 font.setEmph(LyXFont::TOGGLE);
53 ToggleAndShow(bv, font);
57 void Bold(BufferView * bv)
59 LyXFont font(LyXFont::ALL_IGNORE);
60 font.setSeries(LyXFont::BOLD_SERIES);
61 ToggleAndShow(bv, font);
65 void Noun(BufferView * bv)
67 LyXFont font(LyXFont::ALL_IGNORE);
68 font.setNoun(LyXFont::TOGGLE);
69 ToggleAndShow(bv, font);
73 void Margin(BufferView * bv)
75 if (bv->available()) {
76 bv->owner()->getMiniBuffer()->Set(_("Inserting margin note..."));
79 bv->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
85 void Lang(BufferView * bv, string const & l)
87 LyXFont font(LyXFont::ALL_IGNORE);
88 Languages::iterator lit = languages.find(l);
89 if (lit != languages.end()) {
90 font.setLanguage(&(*lit).second);
91 ToggleAndShow(bv, font);
93 WriteAlert(_("Error! unknown language"),l);
97 void Melt(BufferView * bv)
99 if (!bv->available()) return;
101 bv->owner()->getMiniBuffer()->Set(_("Melt"));
105 bv->text->MeltFootnoteEnvironment();
110 void Tex(BufferView * bv)
112 LyXFont font(LyXFont::ALL_IGNORE);
113 font.setLatex (LyXFont::TOGGLE);
114 ToggleAndShow(bv, font);
118 // Change environment depth.
119 // if decInc >= 0, increment depth
120 // if decInc < 0, decrement depth
121 void changeDepth(BufferView * bv, int decInc)
123 if (!bv->available()) return;
128 bv->text->IncDepth();
130 bv->text->DecDepth();
132 bv->owner()->getMiniBuffer()
133 ->Set(_("Changed environment depth"
134 " (in possible range, maybe not)"));
138 void Free(BufferView * bv)
140 ToggleAndShow(bv, UserFreeFont());
144 // How should this actually work? Should it prohibit input in all BufferViews,
145 // or just in the current one? If "just the current one", then it should be
146 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
147 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
148 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
149 // current LyxView that should be prohibited (Lgb) (This applies to
150 // "AllowInput" as well.)
151 void ProhibitInput(BufferView * bv)
155 static Cursor cursor;
156 static bool cursor_undefined = true;
158 if (cursor_undefined){
159 cursor = XCreateFontCursor(fl_display, XC_watch);
161 cursor_undefined = false;
164 /* set the cursor to the watch for all forms and the canvas */
165 XDefineCursor(fl_display, bv->owner()->getForm()->window,
167 if (fd_form_paragraph->form_paragraph->visible)
168 XDefineCursor(fl_display,
169 fd_form_paragraph->form_paragraph->window,
171 if (fd_form_character->form_character->visible)
172 XDefineCursor(fl_display,
173 fd_form_character->form_character->window,
177 fl_deactivate_all_forms();
181 void AllowInput(BufferView * bv)
183 /* reset the cursor from the watch for all forms and the canvas */
185 XUndefineCursor(fl_display, bv->owner()->getForm()->window);
186 if (fd_form_paragraph->form_paragraph->visible)
187 XUndefineCursor(fl_display,
188 fd_form_paragraph->form_paragraph->window);
189 if (fd_form_character->form_character->visible)
190 XUndefineCursor(fl_display,
191 fd_form_character->form_character->window);
193 // What to do about this? (Lgb)
194 if (bv->belowMouse())
195 SetXtermCursor(bv->owner()->getForm()->window);
198 fl_activate_all_forms();
202 void Code(BufferView * bv)
204 LyXFont font(LyXFont::ALL_IGNORE);
205 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
206 ToggleAndShow(bv, font);
210 void Sans(BufferView * bv)
212 LyXFont font(LyXFont::ALL_IGNORE);
213 font.setFamily(LyXFont::SANS_FAMILY);
214 ToggleAndShow(bv, font);
218 void Roman(BufferView * bv)
220 LyXFont font(LyXFont::ALL_IGNORE);
221 font.setFamily(LyXFont::ROMAN_FAMILY);
222 ToggleAndShow(bv, font);
226 void StyleReset(BufferView * bv)
228 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
229 ToggleAndShow(bv, font);
233 void Underline(BufferView * bv)
235 LyXFont font(LyXFont::ALL_IGNORE);
236 font.setUnderbar(LyXFont::TOGGLE);
237 ToggleAndShow(bv, font);
241 void FontSize(BufferView * bv, string const & size)
243 LyXFont font(LyXFont::ALL_IGNORE);
244 font.setGUISize(size);
245 ToggleAndShow(bv, font);
249 /* -------> Returns the current font and depth by printing a message. In the
250 * future perhaps we could try to implement a callback to the button-bar.
251 * That is, `light' the bold button when the font is currently bold, etc.
253 string CurrentState(BufferView * bv)
256 if (bv->available()) {
257 // I think we should only show changes from the default
259 Buffer * buffer = bv->buffer();
260 LyXFont font = bv->text->real_current_font;
261 LyXFont defaultfont = textclasslist.TextClass(buffer->
262 params.textclass).defaultfont();
263 font.reduce(defaultfont);
264 state = _("Font: ") + font.stateText();
265 // The paragraph depth
266 int depth = bv->text->GetDepth();
268 state += string(_(", Depth: ")) + tostr(depth);
269 // The paragraph spacing, but only if different from
271 if (!bv->text->cursor.par->spacing.isDefault()) {
272 Spacing::Space cur_space =
273 bv->text->cursor.par->spacing.getSpace();
274 state += _(", Spacing: ");
276 case Spacing::Single:
277 state += _("Single");
279 case Spacing::Onehalf:
280 state += _("Onehalf");
282 case Spacing::Double:
283 state += _("Double");
286 state += _("Other (");
287 state += tostr(bv->text->cursor.par->spacing.getValue());
290 case Spacing::Default:
291 // should never happen, do nothing
300 // candidate for move to BufferView
301 /* -------> Does the actual toggle job of the XxxCB() calls above.
302 * Also shows the current font state.
304 void ToggleAndShow(BufferView * bv, LyXFont const & font)
306 if (bv->available()) {
309 if (bv->the_locking_inset)
310 bv->the_locking_inset->SetFont(bv, font, toggleall);
312 bv->text->ToggleFree(font, toggleall);