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 <sys/time.h>
21 #include "XFormsView.h"
22 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
23 #include "lyxlookup.h"
25 #include "minibuffer.h"
29 #include "support/filetools.h" // OnlyFilename()
30 #include "frontends/Toolbar.h"
31 #include "frontends/Menubar.h"
32 #include "MenuBackend.h"
33 #include "ToolbarDefaults.h"
35 #include "BufferView.h"
39 //extern void AutoSave(BufferView *);
40 extern void QuitLyX();
42 // This is very temporary
43 BufferView * current_view;
45 extern "C" int C_XFormsView_atCloseMainFormCB(FL_FORM *, void *);
48 XFormsView::XFormsView(int width, int height)
51 create_form_form_main(width, height);
52 fl_set_form_atclose(form_, C_XFormsView_atCloseMainFormCB, 0);
54 // Connect the minibuffer signals
55 minibuffer->stringReady.connect(SigC::slot(getLyXFunc(),
56 &LyXFunc::miniDispatch));
57 minibuffer->timeout.connect(SigC::slot(getLyXFunc(),
58 &LyXFunc::initMiniBuffer));
60 // Make sure the buttons are disabled if needed.
65 XFormsView::~XFormsView() {}
68 /// Redraw the main form.
69 void XFormsView::redraw() {
70 lyxerr[Debug::INFO] << "XFormsView::redraw()" << endl;
71 fl_redraw_form(form_);
72 getMiniBuffer()->redraw();
76 FL_FORM * XFormsView::getForm() const
82 // Callback for close main form from window manager
83 int XFormsView::atCloseMainFormCB(FL_FORM *, void *)
90 // Wrapper for the above
92 int C_XFormsView_atCloseMainFormCB(FL_FORM * form, void * p)
94 return XFormsView::atCloseMainFormCB(form, p);
98 void XFormsView::setPosition(int x, int y)
100 fl_set_form_position(form_, x, y);
104 void XFormsView::show(int place, int border, string const & title)
106 fl_show_form(form_, place, border, title.c_str());
107 getLyXFunc()->initMiniBuffer();
108 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
109 InitLyXLookup(fl_get_display(), form_->window);
114 void XFormsView::create_form_form_main(int width, int height)
115 /* to make this work as it should, .lyxrc should have been
116 * read first; OR maybe this one should be made dynamic.
118 * We will probably not have lyxrc before the main form is
119 * initialized, because error messages from lyxrc parsing
120 * are presented (and rightly so) in GUI popups. Asger.
124 form_ = fl_bgn_form(FL_NO_BOX, width, height);
125 form_->u_vdata = this;
126 FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
127 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
129 // Parameters for the appearance of the main form
131 int const bw = abs(fl_get_border_width());
136 menubar = new Menubar(this, menubackend);
142 toolbar = new Toolbar(this, air, 30 + air + bw, toolbardefaults);
151 int const ywork = 60 + 2 * air + bw;
152 int const workheight = height - ywork - (25 + 2 * air);
154 ::current_view = bufferview = new BufferView(this, air, ywork,
162 minibuffer = new MiniBuffer(this, air, height - (25 + air),
163 width - (2 * air), 25);
169 autosave_timeout.timeout.connect(SigC::slot(this, &XFormsView::AutoSave));
175 // assign an icon to main form
176 string iconname = LibFileSearch("images", "lyx", "xpm");
177 if (!iconname.empty()) {
179 Pixmap lyx_p, lyx_mask;
180 lyx_p = fl_read_pixmapfile(fl_root,
188 fl_set_form_icon(form_, lyx_p, lyx_mask);
192 fl_set_form_minsize(form_, 50, 50);
198 void XFormsView::init()
200 // Set the textclass choice
201 invalidateLayoutChoice();
202 updateLayoutChoice();
205 // Start autosave timer
206 if (lyxrc.autosave) {
207 autosave_timeout.setTimeout(lyxrc.autosave * 1000);
208 autosave_timeout.start();
211 intl->InitKeyMapper(lyxrc.use_kbmap);
215 void XFormsView::setWindowTitle(string const & title)
217 fl_set_form_title(form_, title.c_str());
221 // How should this actually work? Should it prohibit input in all BufferViews,
222 // or just in the current one? If "just the current one", then it should be
223 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
224 // run "prohibitInput" on all LyXViews which will run prohibitInput on all
225 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
226 // current LyxView that should be prohibited (Lgb) (This applies to
227 // "allowInput" as well.)
228 void XFormsView::prohibitInput() const
230 view()->hideCursor();
232 static Cursor cursor;
233 static bool cursor_undefined = true;
235 if (cursor_undefined){
236 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
237 XFlush(fl_get_display());
238 cursor_undefined = false;
241 /* set the cursor to the watch for all forms and the canvas */
242 XDefineCursor(fl_get_display(), getForm()->window, cursor);
244 XFlush(fl_get_display());
245 fl_deactivate_all_forms();
249 void XFormsView::allowInput() const
251 /* reset the cursor from the watch for all forms and the canvas */
253 XUndefineCursor(fl_get_display(), getForm()->window);
255 XFlush(fl_get_display());
256 fl_activate_all_forms();