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 #include FORMS_H_LOCATION
19 #if FL_VERSION < 1 && (FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5))
20 #include "frontends/xforms/lyxlookup.h"
22 #include "frontends/MiniBuffer.h"
23 #include "frontends/xforms/XMiniBuffer.h"
27 #include "support/filetools.h" // OnlyFilename()
28 #include "frontends/Toolbar.h"
29 #include "frontends/Menubar.h"
30 #include "frontends/Timeout.h"
31 #include "frontends/Dialogs.h"
32 #include "MenuBackend.h"
33 #include "ToolbarDefaults.h"
35 #include "BufferView.h"
37 #include <boost/bind.hpp>
42 //extern void AutoSave(BufferView *);
43 extern void QuitLyX();
45 // This is very temporary
46 BufferView * current_view;
51 int C_XFormsView_atCloseMainFormCB(FL_FORM * form, void * p)
53 return XFormsView::atCloseMainFormCB(form, p);
59 XFormsView::XFormsView(int width, int height)
62 create_form_form_main(*getDialogs(), width, height);
63 fl_set_form_atclose(getForm(), C_XFormsView_atCloseMainFormCB, 0);
65 // Connect the minibuffer signals
66 minibuffer_->inputReady.connect(boost::bind(&LyXFunc::miniDispatch, getLyXFunc(), _1));
67 minibuffer_->timeout.connect(boost::bind(&LyXFunc::initMiniBuffer, getLyXFunc()));
69 // Make sure the buttons are disabled if needed.
71 getDialogs()->redrawGUI.connect(boost::bind(&XFormsView::redraw, this));
75 XFormsView::~XFormsView()
82 /// Redraw the main form.
83 void XFormsView::redraw()
85 lyxerr[Debug::INFO] << "XFormsView::redraw()" << endl;
86 fl_redraw_form(getForm());
87 // This is dangerous, but we know it is safe
88 XMiniBuffer * m = static_cast<XMiniBuffer *>(getMiniBuffer());
93 FL_FORM * XFormsView::getForm() const
99 // Callback for close main form from window manager
100 int XFormsView::atCloseMainFormCB(FL_FORM *, void *)
107 void XFormsView::show(int x, int y, string const & title)
109 FL_FORM * form = getForm();
111 fl_set_form_minsize(form, form->w, form->h);
113 int placement = FL_PLACE_CENTER | FL_FREE_SIZE;
115 // Did we get a valid geometry position ?
116 if (x >= 0 && y >= 0) {
117 fl_set_form_position(form, x, y);
118 placement = FL_PLACE_POSITION;
121 fl_show_form(form, placement, FL_FULLBORDER, title.c_str());
123 getLyXFunc()->initMiniBuffer();
124 #if FL_VERSION < 1 && (FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5))
125 InitLyXLookup(fl_get_display(), form_->window);
130 void XFormsView::create_form_form_main(Dialogs & dia, int width, int height)
131 /* to make this work as it should, .lyxrc should have been
132 * read first; OR maybe this one should be made dynamic.
134 * We will probably not have lyxrc before the main form is
135 * initialized, because error messages from lyxrc parsing
136 * are presented (and rightly so) in GUI popups. Asger.
140 form_ = fl_bgn_form(FL_NO_BOX, width, height);
141 getForm()->u_vdata = this;
142 FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
143 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
145 // Parameters for the appearance of the main form
147 int const bw = abs(fl_get_border_width());
149 menubar_.reset(new Menubar(this, menubackend));
151 toolbar_.reset(new Toolbar(this, dia,
152 air, 30 + air + bw, toolbardefaults));
155 int const ywork = 60 + 2 * air + bw;
156 int const workheight = height - ywork - (25 + 2 * air);
158 bufferview_.reset(new BufferView(this, air, ywork,
159 width - 3 * air, workheight));
160 ::current_view = bufferview_.get();
162 minibuffer_.reset(new XMiniBuffer(this, air, height - (25 + air),
163 width - (2 * air), 25));
165 // FIXME: why do this in xforms/ ?
166 autosave_timeout_->timeout.connect(boost::bind(&XFormsView::autoSave, this));
168 // assign an icon to main form
169 string iconname = LibFileSearch("images", "lyx", "xpm");
170 if (!iconname.empty()) {
172 Pixmap lyx_p, lyx_mask;
173 lyx_p = fl_read_pixmapfile(fl_root,
181 fl_set_form_icon(getForm(), lyx_p, lyx_mask);
185 fl_set_form_minsize(getForm(), 50, 50);
189 // This is dangerous, but we know it is safe in this situation
190 static_cast<XMiniBuffer *>(minibuffer_.get())->dd_init();
194 void XFormsView::setWindowTitle(string const & title, string const & icon_title)
196 fl_set_form_title(getForm(), title.c_str());
197 fl_winicontitle(form_->window, icon_title.c_str());
201 // How should this actually work? Should it prohibit input in all BufferViews,
202 // or just in the current one? If "just the current one", then it should be
203 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
204 // run "prohibitInput" on all LyXViews which will run prohibitInput on all
205 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
206 // current LyxView that should be prohibited (Lgb) (This applies to
207 // "allowInput" as well.)
208 void XFormsView::prohibitInput() const
210 view()->hideCursor();
212 static Cursor cursor;
213 static bool cursor_undefined = true;
215 if (cursor_undefined) {
216 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
217 XFlush(fl_get_display());
218 cursor_undefined = false;
221 /* set the cursor to the watch for all forms and the canvas */
222 XDefineCursor(fl_get_display(), getForm()->window, cursor);
224 XFlush(fl_get_display());
225 fl_deactivate_all_forms();
229 void XFormsView::allowInput() const
231 /* reset the cursor from the watch for all forms and the canvas */
233 XUndefineCursor(fl_get_display(), getForm()->window);
235 XFlush(fl_get_display());
236 fl_activate_all_forms();