3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
17 #include "XFormsView.h"
18 #include FORMS_H_LOCATION
20 #include "XMiniBuffer.h"
24 #include "support/filetools.h" // OnlyFilename()
25 #include "frontends/Toolbar.h"
26 #include "frontends/Menubar.h"
27 #include "frontends/Timeout.h"
28 #include "frontends/Dialogs.h"
29 #include "MenuBackend.h"
30 #include "ToolbarDefaults.h"
32 #include "bufferview_funcs.h"
33 #include "BufferView.h"
35 #include <boost/bind.hpp>
36 #include <boost/signals/connection.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)
59 icon_pixmap_(0), icon_mask_(0)
61 create_form_form_main(width, height);
62 fl_set_form_atclose(getForm(), C_XFormsView_atCloseMainFormCB, 0);
64 view_state_con = view_state_changed.connect(boost::bind(&XFormsView::show_view_state, this));
65 focus_con = focus_command_buffer.connect(boost::bind(&XMiniBuffer::focus, minibuffer_.get()));
67 // Make sure the buttons are disabled if needed.
69 redraw_con = getDialogs().redrawGUI().connect(boost::bind(&XFormsView::redraw, this));
73 XFormsView::~XFormsView()
76 XFreePixmap(fl_get_display(), icon_pixmap_);
78 minibuffer_->freeze();
84 /// Redraw the main form.
85 void XFormsView::redraw()
87 lyxerr[Debug::INFO] << "XFormsView::redraw()" << endl;
88 fl_redraw_form(getForm());
89 minibuffer_->redraw();
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());
127 void XFormsView::create_form_form_main(int width, int height)
128 /* to make this work as it should, .lyxrc should have been
129 * read first; OR maybe this one should be made dynamic.
131 * We will probably not have lyxrc before the main form is
132 * initialized, because error messages from lyxrc parsing
133 * are presented (and rightly so) in GUI popups. Asger.
137 form_ = fl_bgn_form(FL_NO_BOX, width, height);
138 getForm()->u_vdata = this;
139 FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
140 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
142 // Parameters for the appearance of the main form
144 int const bw = abs(fl_get_border_width());
146 menubar_.reset(new Menubar(this, menubackend));
148 toolbar_.reset(new Toolbar(this, air, 30 + air + bw, toolbardefaults));
150 int const ywork = 60 + 2 * air + bw;
151 int const workheight = height - ywork - (25 + 2 * air);
153 bufferview_.reset(new BufferView(this, air, ywork,
154 width - 3 * air, workheight));
155 ::current_view = bufferview_.get();
157 minibuffer_.reset(new XMiniBuffer(this, *controlcommand_,
158 air, height - (25 + air), width - (2 * air), 25));
160 // assign an icon to main form
161 string const iconname = LibFileSearch("images", "lyx", "xpm");
162 if (!iconname.empty()) {
164 icon_pixmap_ = fl_read_pixmapfile(fl_root,
172 fl_set_form_icon(getForm(), icon_pixmap_, icon_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 void XFormsView::message(string const & str)
193 minibuffer_->message(str);
197 void XFormsView::show_view_state()
199 message(getLyXFunc().view_status_message());
203 // How should this actually work? Should it prohibit input in all BufferViews,
204 // or just in the current one? If "just the current one", then it should be
205 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
206 // run "prohibitInput" on all LyXViews which will run prohibitInput on all
207 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
208 // current LyXView that should be prohibited (Lgb) (This applies to
209 // "allowInput" as well.)
210 void XFormsView::prohibitInput() const
212 view()->hideCursor();
214 static Cursor cursor;
215 static bool cursor_undefined = true;
217 if (cursor_undefined) {
218 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
219 XFlush(fl_get_display());
220 cursor_undefined = false;
223 /* set the cursor to the watch for all forms and the canvas */
224 XDefineCursor(fl_get_display(), getForm()->window, cursor);
226 XFlush(fl_get_display());
227 fl_deactivate_all_forms();
231 void XFormsView::allowInput() const
233 /* reset the cursor from the watch for all forms and the canvas */
235 XUndefineCursor(fl_get_display(), getForm()->window);
237 XFlush(fl_get_display());
238 fl_activate_all_forms();