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 "minibuffer.h"
26 #include "support/filetools.h" // OnlyFilename()
27 #include "frontends/Toolbar.h"
28 #include "frontends/Menubar.h"
29 #include "frontends/Timeout.h"
30 #include "frontends/Dialogs.h"
31 #include "MenuBackend.h"
32 #include "ToolbarDefaults.h"
34 #include "BufferView.h"
36 #include <boost/bind.hpp>
41 //extern void AutoSave(BufferView *);
42 extern void QuitLyX();
44 // This is very temporary
45 BufferView * current_view;
50 int C_XFormsView_atCloseMainFormCB(FL_FORM * form, void * p)
52 return XFormsView::atCloseMainFormCB(form, p);
58 XFormsView::XFormsView(int width, int height)
61 create_form_form_main(width, height);
62 fl_set_form_atclose(getForm(), C_XFormsView_atCloseMainFormCB, 0);
64 // Connect the minibuffer signals
65 minibuffer_->stringReady.connect(boost::bind(&LyXFunc::miniDispatch, getLyXFunc(), _1));
66 minibuffer_->timeout.connect(boost::bind(&LyXFunc::initMiniBuffer, getLyXFunc()));
68 // Make sure the buttons are disabled if needed.
70 Dialogs::redrawGUI.connect(boost::bind(&XFormsView::redraw, this));
74 XFormsView::~XFormsView() {}
77 /// Redraw the main form.
78 void XFormsView::redraw() {
79 lyxerr[Debug::INFO] << "XFormsView::redraw()" << endl;
80 fl_redraw_form(getForm());
81 getMiniBuffer()->redraw();
85 FL_FORM * XFormsView::getForm() const
91 // Callback for close main form from window manager
92 int XFormsView::atCloseMainFormCB(FL_FORM *, void *)
99 void XFormsView::show(int x, int y, string const & title)
101 FL_FORM * form = getForm();
103 fl_set_form_minsize(form, form->w, form->h);
105 int placement = FL_PLACE_CENTER | FL_FREE_SIZE;
107 // Did we get a valid geometry position ?
108 if (x >= 0 && y >= 0) {
109 fl_set_form_position(form, x, y);
110 placement = FL_PLACE_POSITION;
113 fl_show_form(form, placement, FL_FULLBORDER, title.c_str());
115 getLyXFunc()->initMiniBuffer();
116 #if FL_VERSION < 1 && (FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5))
117 InitLyXLookup(fl_get_display(), form_->window);
122 void XFormsView::create_form_form_main(int width, int height)
123 /* to make this work as it should, .lyxrc should have been
124 * read first; OR maybe this one should be made dynamic.
126 * We will probably not have lyxrc before the main form is
127 * initialized, because error messages from lyxrc parsing
128 * are presented (and rightly so) in GUI popups. Asger.
132 form_.reset(fl_bgn_form(FL_NO_BOX, width, height));
133 getForm()->u_vdata = this;
134 FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
135 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
137 // Parameters for the appearance of the main form
139 int const bw = abs(fl_get_border_width());
141 menubar_.reset(new Menubar(this, menubackend));
143 toolbar_.reset(new Toolbar(this, air, 30 + air + bw, toolbardefaults));
146 int const ywork = 60 + 2 * air + bw;
147 int const workheight = height - ywork - (25 + 2 * air);
149 bufferview_.reset(new BufferView(this, air, ywork,
150 width - 3 * air, workheight));
151 ::current_view = bufferview_.get();
153 minibuffer_.reset(new MiniBuffer(this, air, height - (25 + air),
154 width - (2 * air), 25));
156 // FIXME: why do this in xforms/ ?
157 autosave_timeout_->timeout.connect(boost::bind(&XFormsView::autoSave, this));
159 // assign an icon to main form
160 string iconname = LibFileSearch("images", "lyx", "xpm");
161 if (!iconname.empty()) {
163 Pixmap lyx_p, lyx_mask;
164 lyx_p = fl_read_pixmapfile(fl_root,
172 fl_set_form_icon(getForm(), lyx_p, lyx_mask);
176 fl_set_form_minsize(getForm(), 50, 50);
180 minibuffer_->dd_init();
184 void XFormsView::setWindowTitle(string const & title, string const & icon_title)
186 fl_set_form_title(getForm(), title.c_str());
187 fl_winicontitle(form_->window, icon_title.c_str());
191 // How should this actually work? Should it prohibit input in all BufferViews,
192 // or just in the current one? If "just the current one", then it should be
193 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
194 // run "prohibitInput" on all LyXViews which will run prohibitInput on all
195 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
196 // current LyxView that should be prohibited (Lgb) (This applies to
197 // "allowInput" as well.)
198 void XFormsView::prohibitInput() const
200 view()->hideCursor();
202 static Cursor cursor;
203 static bool cursor_undefined = true;
205 if (cursor_undefined) {
206 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
207 XFlush(fl_get_display());
208 cursor_undefined = false;
211 /* set the cursor to the watch for all forms and the canvas */
212 XDefineCursor(fl_get_display(), getForm()->window, cursor);
214 XFlush(fl_get_display());
215 fl_deactivate_all_forms();
219 void XFormsView::allowInput() const
221 /* reset the cursor from the watch for all forms and the canvas */
223 XUndefineCursor(fl_get_display(), getForm()->window);
225 XFlush(fl_get_display());
226 fl_activate_all_forms();