1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
17 #include "XFormsView.h"
18 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
19 #include "frontends/xforms/lyxlookup.h"
21 #include "minibuffer.h"
25 #include "support/filetools.h" // OnlyFilename()
26 #include "frontends/Toolbar.h"
27 #include "frontends/Menubar.h"
28 #include "frontends/Timeout.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_set_form_minsize(form_, form_->w, form_->h);
104 fl_show_form(form_, place, border, title.c_str());
105 getLyXFunc()->initMiniBuffer();
106 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
107 InitLyXLookup(fl_get_display(), form_->window);
112 void XFormsView::create_form_form_main(int width, int height)
113 /* to make this work as it should, .lyxrc should have been
114 * read first; OR maybe this one should be made dynamic.
116 * We will probably not have lyxrc before the main form is
117 * initialized, because error messages from lyxrc parsing
118 * are presented (and rightly so) in GUI popups. Asger.
122 form_ = fl_bgn_form(FL_NO_BOX, width, height);
123 form_->u_vdata = this;
124 FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
125 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
127 // Parameters for the appearance of the main form
129 int const bw = abs(fl_get_border_width());
134 menubar = new Menubar(this, menubackend);
140 toolbar = new Toolbar(this, air, 30 + air + bw, toolbardefaults);
149 int const ywork = 60 + 2 * air + bw;
150 int const workheight = height - ywork - (25 + 2 * air);
152 ::current_view = bufferview = new BufferView(this, air, ywork,
160 minibuffer = new MiniBuffer(this, air, height - (25 + air),
161 width - (2 * air), 25);
167 autosave_timeout->timeout.connect(SigC::slot(this, &XFormsView::AutoSave));
173 // assign an icon to main form
174 string iconname = LibFileSearch("images", "lyx", "xpm");
175 if (!iconname.empty()) {
177 Pixmap lyx_p, lyx_mask;
178 lyx_p = fl_read_pixmapfile(fl_root,
186 fl_set_form_icon(form_, lyx_p, lyx_mask);
190 fl_set_form_minsize(form_, 50, 50);
194 minibuffer->dd_init();
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, string const & icon_title)
217 fl_set_form_title(form_, title.c_str());
218 fl_winicontitle(form_->window, icon_title.c_str());
222 // How should this actually work? Should it prohibit input in all BufferViews,
223 // or just in the current one? If "just the current one", then it should be
224 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
225 // run "prohibitInput" on all LyXViews which will run prohibitInput on all
226 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
227 // current LyxView that should be prohibited (Lgb) (This applies to
228 // "allowInput" as well.)
229 void XFormsView::prohibitInput() const
231 view()->hideCursor();
233 static Cursor cursor;
234 static bool cursor_undefined = true;
236 if (cursor_undefined) {
237 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
238 XFlush(fl_get_display());
239 cursor_undefined = false;
242 /* set the cursor to the watch for all forms and the canvas */
243 XDefineCursor(fl_get_display(), getForm()->window, cursor);
245 XFlush(fl_get_display());
246 fl_deactivate_all_forms();
250 void XFormsView::allowInput() const
252 /* reset the cursor from the watch for all forms and the canvas */
254 XUndefineCursor(fl_get_display(), getForm()->window);
256 XFlush(fl_get_display());
257 fl_activate_all_forms();