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_VERSION < 1 && (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"
34 #include <boost/bind.hpp>
39 //extern void AutoSave(BufferView *);
40 extern void QuitLyX();
42 // This is very temporary
43 BufferView * current_view;
48 int C_XFormsView_atCloseMainFormCB(FL_FORM * form, void * p)
50 return XFormsView::atCloseMainFormCB(form, p);
56 XFormsView::XFormsView(int width, int height)
59 create_form_form_main(width, height);
60 fl_set_form_atclose(getForm(), C_XFormsView_atCloseMainFormCB, 0);
62 // Connect the minibuffer signals
63 minibuffer_->stringReady.connect(boost::bind(&LyXFunc::miniDispatch, getLyXFunc(), _1));
64 minibuffer_->timeout.connect(boost::bind(&LyXFunc::initMiniBuffer, getLyXFunc()));
66 // Make sure the buttons are disabled if needed.
71 XFormsView::~XFormsView() {}
74 /// Redraw the main form.
75 void XFormsView::redraw() {
76 lyxerr[Debug::INFO] << "XFormsView::redraw()" << endl;
77 fl_redraw_form(getForm());
78 getMiniBuffer()->redraw();
82 FL_FORM * XFormsView::getForm() const
88 // Callback for close main form from window manager
89 int XFormsView::atCloseMainFormCB(FL_FORM *, void *)
96 void XFormsView::show(int x, int y, string const & title)
98 FL_FORM * form = getForm();
100 fl_set_form_minsize(form, form->w, form->h);
102 int placement = FL_PLACE_CENTER | FL_FREE_SIZE;
104 // Did we get a valid geometry position ?
105 if (x >= 0 && y >= 0) {
106 fl_set_form_position(form, x, y);
107 placement = FL_PLACE_POSITION;
110 fl_show_form(form, placement, FL_FULLBORDER, title.c_str());
112 getLyXFunc()->initMiniBuffer();
113 #if FL_VERSION < 1 && (FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5))
114 InitLyXLookup(fl_get_display(), form_->window);
119 void XFormsView::create_form_form_main(int width, int height)
120 /* to make this work as it should, .lyxrc should have been
121 * read first; OR maybe this one should be made dynamic.
123 * We will probably not have lyxrc before the main form is
124 * initialized, because error messages from lyxrc parsing
125 * are presented (and rightly so) in GUI popups. Asger.
129 form_.reset(fl_bgn_form(FL_NO_BOX, width, height));
130 getForm()->u_vdata = this;
131 FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
132 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
134 // Parameters for the appearance of the main form
136 int const bw = abs(fl_get_border_width());
138 menubar_.reset(new Menubar(this, menubackend));
140 toolbar_.reset(new Toolbar(this, air, 30 + air + bw, toolbardefaults));
143 int const ywork = 60 + 2 * air + bw;
144 int const workheight = height - ywork - (25 + 2 * air);
146 bufferview_.reset(new BufferView(this, air, ywork,
147 width - 3 * air, workheight));
148 ::current_view = bufferview_.get();
150 minibuffer_.reset(new MiniBuffer(this, air, height - (25 + air),
151 width - (2 * air), 25));
153 // FIXME: why do this in xforms/ ?
154 autosave_timeout_->timeout.connect(boost::bind(&XFormsView::AutoSave, this));
156 // assign an icon to main form
157 string iconname = LibFileSearch("images", "lyx", "xpm");
158 if (!iconname.empty()) {
160 Pixmap lyx_p, lyx_mask;
161 lyx_p = fl_read_pixmapfile(fl_root,
169 fl_set_form_icon(getForm(), lyx_p, lyx_mask);
173 fl_set_form_minsize(getForm(), 50, 50);
177 minibuffer_->dd_init();
181 void XFormsView::init()
183 // Set the textclass choice
184 invalidateLayoutChoice();
185 updateLayoutChoice();
188 // Start autosave timer
189 if (lyxrc.autosave) {
190 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
191 autosave_timeout_->start();
194 intl_->InitKeyMapper(lyxrc.use_kbmap);
198 void XFormsView::setWindowTitle(string const & title, string const & icon_title)
200 fl_set_form_title(getForm(), title.c_str());
201 fl_winicontitle(form_->window, icon_title.c_str());
205 // How should this actually work? Should it prohibit input in all BufferViews,
206 // or just in the current one? If "just the current one", then it should be
207 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
208 // run "prohibitInput" on all LyXViews which will run prohibitInput on all
209 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
210 // current LyxView that should be prohibited (Lgb) (This applies to
211 // "allowInput" as well.)
212 void XFormsView::prohibitInput() const
214 view()->hideCursor();
216 static Cursor cursor;
217 static bool cursor_undefined = true;
219 if (cursor_undefined) {
220 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
221 XFlush(fl_get_display());
222 cursor_undefined = false;
225 /* set the cursor to the watch for all forms and the canvas */
226 XDefineCursor(fl_get_display(), getForm()->window, cursor);
228 XFlush(fl_get_display());
229 fl_deactivate_all_forms();
233 void XFormsView::allowInput() const
235 /* reset the cursor from the watch for all forms and the canvas */
237 XUndefineCursor(fl_get_display(), getForm()->window);
239 XFlush(fl_get_display());
240 fl_activate_all_forms();