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 "frontends/Dialogs.h"
30 #include "MenuBackend.h"
31 #include "ToolbarDefaults.h"
33 #include "BufferView.h"
35 #include <boost/bind.hpp>
40 //extern void AutoSave(BufferView *);
41 extern void QuitLyX();
43 // This is very temporary
44 BufferView * current_view;
49 int C_XFormsView_atCloseMainFormCB(FL_FORM * form, void * p)
51 return XFormsView::atCloseMainFormCB(form, p);
57 XFormsView::XFormsView(int width, int height)
60 create_form_form_main(width, height);
61 fl_set_form_atclose(getForm(), C_XFormsView_atCloseMainFormCB, 0);
63 // Connect the minibuffer signals
64 minibuffer_->stringReady.connect(boost::bind(&LyXFunc::miniDispatch, getLyXFunc(), _1));
65 minibuffer_->timeout.connect(boost::bind(&LyXFunc::initMiniBuffer, getLyXFunc()));
67 // Make sure the buttons are disabled if needed.
69 Dialogs::redrawGUI.connect(boost::bind(&XFormsView::redraw, this));
73 XFormsView::~XFormsView() {}
76 /// Redraw the main form.
77 void XFormsView::redraw() {
78 lyxerr[Debug::INFO] << "XFormsView::redraw()" << endl;
79 fl_redraw_form(getForm());
80 getMiniBuffer()->redraw();
84 FL_FORM * XFormsView::getForm() const
90 // Callback for close main form from window manager
91 int XFormsView::atCloseMainFormCB(FL_FORM *, void *)
98 void XFormsView::show(int x, int y, string const & title)
100 FL_FORM * form = getForm();
102 fl_set_form_minsize(form, form->w, form->h);
104 int placement = FL_PLACE_CENTER | FL_FREE_SIZE;
106 // Did we get a valid geometry position ?
107 if (x >= 0 && y >= 0) {
108 fl_set_form_position(form, x, y);
109 placement = FL_PLACE_POSITION;
112 fl_show_form(form, placement, FL_FULLBORDER, title.c_str());
114 getLyXFunc()->initMiniBuffer();
115 #if FL_VERSION < 1 && (FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5))
116 InitLyXLookup(fl_get_display(), form_->window);
121 void XFormsView::create_form_form_main(int width, int height)
122 /* to make this work as it should, .lyxrc should have been
123 * read first; OR maybe this one should be made dynamic.
125 * We will probably not have lyxrc before the main form is
126 * initialized, because error messages from lyxrc parsing
127 * are presented (and rightly so) in GUI popups. Asger.
131 form_.reset(fl_bgn_form(FL_NO_BOX, width, height));
132 getForm()->u_vdata = this;
133 FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
134 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
136 // Parameters for the appearance of the main form
138 int const bw = abs(fl_get_border_width());
140 menubar_.reset(new Menubar(this, menubackend));
142 toolbar_.reset(new Toolbar(this, air, 30 + air + bw, toolbardefaults));
145 int const ywork = 60 + 2 * air + bw;
146 int const workheight = height - ywork - (25 + 2 * air);
148 bufferview_.reset(new BufferView(this, air, ywork,
149 width - 3 * air, workheight));
150 ::current_view = bufferview_.get();
152 minibuffer_.reset(new MiniBuffer(this, air, height - (25 + air),
153 width - (2 * air), 25));
155 // FIXME: why do this in xforms/ ?
156 autosave_timeout_->timeout.connect(boost::bind(&XFormsView::autoSave, this));
158 // assign an icon to main form
159 string iconname = LibFileSearch("images", "lyx", "xpm");
160 if (!iconname.empty()) {
162 Pixmap lyx_p, lyx_mask;
163 lyx_p = fl_read_pixmapfile(fl_root,
171 fl_set_form_icon(getForm(), lyx_p, lyx_mask);
175 fl_set_form_minsize(getForm(), 50, 50);
179 minibuffer_->dd_init();
183 void XFormsView::setWindowTitle(string const & title, string const & icon_title)
185 fl_set_form_title(getForm(), title.c_str());
186 fl_winicontitle(form_->window, icon_title.c_str());
190 // How should this actually work? Should it prohibit input in all BufferViews,
191 // or just in the current one? If "just the current one", then it should be
192 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
193 // run "prohibitInput" on all LyXViews which will run prohibitInput on all
194 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
195 // current LyxView that should be prohibited (Lgb) (This applies to
196 // "allowInput" as well.)
197 void XFormsView::prohibitInput() const
199 view()->hideCursor();
201 static Cursor cursor;
202 static bool cursor_undefined = true;
204 if (cursor_undefined) {
205 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
206 XFlush(fl_get_display());
207 cursor_undefined = false;
210 /* set the cursor to the watch for all forms and the canvas */
211 XDefineCursor(fl_get_display(), getForm()->window, cursor);
213 XFlush(fl_get_display());
214 fl_deactivate_all_forms();
218 void XFormsView::allowInput() const
220 /* reset the cursor from the watch for all forms and the canvas */
222 XUndefineCursor(fl_get_display(), getForm()->window);
224 XFlush(fl_get_display());
225 fl_activate_all_forms();