2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2001 The LyX Team.
10 * ====================================================== */
15 #pragma implementation
18 #include "XFormsView.h"
19 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
20 #include "lyxlookup.h"
22 #include "minibuffer.h"
26 #include "support/filetools.h" // OnlyFilename()
27 #include "frontends/Toolbar.h"
28 #include "frontends/Menubar.h"
29 #include "MenuBackend.h"
30 #include "ToolbarDefaults.h"
32 #include "BufferView.h"
36 //extern void AutoSave(BufferView *);
37 extern void QuitLyX();
39 // This is very temporary
40 BufferView * current_view;
45 int C_XFormsView_atCloseMainFormCB(FL_FORM * form, void * p)
47 return XFormsView::atCloseMainFormCB(form, p);
53 XFormsView::XFormsView(int width, int height)
56 create_form_form_main(width, height);
57 fl_set_form_atclose(form_, C_XFormsView_atCloseMainFormCB, 0);
59 // Connect the minibuffer signals
60 minibuffer->stringReady.connect(SigC::slot(getLyXFunc(),
61 &LyXFunc::miniDispatch));
62 minibuffer->timeout.connect(SigC::slot(getLyXFunc(),
63 &LyXFunc::initMiniBuffer));
65 // Make sure the buttons are disabled if needed.
70 XFormsView::~XFormsView() {}
73 /// Redraw the main form.
74 void XFormsView::redraw() {
75 lyxerr[Debug::INFO] << "XFormsView::redraw()" << endl;
76 fl_redraw_form(form_);
77 getMiniBuffer()->redraw();
81 FL_FORM * XFormsView::getForm() const
87 // Callback for close main form from window manager
88 int XFormsView::atCloseMainFormCB(FL_FORM *, void *)
95 void XFormsView::setPosition(int x, int y)
97 fl_set_form_position(form_, x, y);
101 void XFormsView::show(int place, int border, string const & title)
103 fl_show_form(form_, place, border, title.c_str());
104 getLyXFunc()->initMiniBuffer();
105 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
106 InitLyXLookup(fl_get_display(), form_->window);
111 void XFormsView::create_form_form_main(int width, int height)
112 /* to make this work as it should, .lyxrc should have been
113 * read first; OR maybe this one should be made dynamic.
115 * We will probably not have lyxrc before the main form is
116 * initialized, because error messages from lyxrc parsing
117 * are presented (and rightly so) in GUI popups. Asger.
121 form_ = fl_bgn_form(FL_NO_BOX, width, height);
122 form_->u_vdata = this;
123 FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
124 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
126 // Parameters for the appearance of the main form
128 int const bw = abs(fl_get_border_width());
133 menubar = new Menubar(this, menubackend);
139 toolbar = new Toolbar(this, air, 30 + air + bw, toolbardefaults);
148 int const ywork = 60 + 2 * air + bw;
149 int const workheight = height - ywork - (25 + 2 * air);
151 ::current_view = bufferview = new BufferView(this, air, ywork,
159 minibuffer = new MiniBuffer(this, air, height - (25 + air),
160 width - (2 * air), 25);
166 autosave_timeout.timeout.connect(SigC::slot(this, &XFormsView::AutoSave));
172 // assign an icon to main form
173 string iconname = LibFileSearch("images", "lyx", "xpm");
174 if (!iconname.empty()) {
176 Pixmap lyx_p, lyx_mask;
177 lyx_p = fl_read_pixmapfile(fl_root,
185 fl_set_form_icon(form_, lyx_p, lyx_mask);
189 fl_set_form_minsize(form_, 50, 50);
195 void XFormsView::init()
197 // Set the textclass choice
198 invalidateLayoutChoice();
199 updateLayoutChoice();
202 // Start autosave timer
203 if (lyxrc.autosave) {
204 autosave_timeout.setTimeout(lyxrc.autosave * 1000);
205 autosave_timeout.start();
208 intl->InitKeyMapper(lyxrc.use_kbmap);
212 void XFormsView::setWindowTitle(string const & title)
214 fl_set_form_title(form_, title.c_str());
218 // How should this actually work? Should it prohibit input in all BufferViews,
219 // or just in the current one? If "just the current one", then it should be
220 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
221 // run "prohibitInput" on all LyXViews which will run prohibitInput on all
222 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
223 // current LyxView that should be prohibited (Lgb) (This applies to
224 // "allowInput" as well.)
225 void XFormsView::prohibitInput() const
227 view()->hideCursor();
229 static Cursor cursor;
230 static bool cursor_undefined = true;
232 if (cursor_undefined){
233 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
234 XFlush(fl_get_display());
235 cursor_undefined = false;
238 /* set the cursor to the watch for all forms and the canvas */
239 XDefineCursor(fl_get_display(), getForm()->window, cursor);
241 XFlush(fl_get_display());
242 fl_deactivate_all_forms();
246 void XFormsView::allowInput() const
248 /* reset the cursor from the watch for all forms and the canvas */
250 XUndefineCursor(fl_get_display(), getForm()->window);
252 XFlush(fl_get_display());
253 fl_activate_all_forms();