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 #include "XFormsView.h"
15 #include "lyx_forms.h"
17 #include "XMiniBuffer.h"
21 #include "support/filetools.h" // OnlyFilename()
22 #include "frontends/Toolbar.h"
23 #include "frontends/Menubar.h"
24 #include "frontends/Timeout.h"
25 #include "frontends/Dialogs.h"
26 #include "MenuBackend.h"
27 #include "ToolbarBackend.h"
29 #include "bufferview_funcs.h"
30 #include "BufferView.h"
32 #include <boost/bind.hpp>
33 #include <boost/signals/connection.hpp>
37 //extern void AutoSave(BufferView *);
38 extern void QuitLyX();
40 // This is very temporary
41 BufferView * current_view;
46 int C_XFormsView_atCloseMainFormCB(FL_FORM * form, void * p)
48 return XFormsView::atCloseMainFormCB(form, p);
54 XFormsView::XFormsView(int width, int height)
56 icon_pixmap_(0), icon_mask_(0)
58 create_form_form_main(width, height);
59 fl_set_form_atclose(getForm(), C_XFormsView_atCloseMainFormCB, 0);
61 view_state_con = view_state_changed.connect(boost::bind(&XFormsView::show_view_state, this));
62 focus_con = focus_command_buffer.connect(boost::bind(&XMiniBuffer::focus, minibuffer_.get()));
64 // Make sure the buttons are disabled if needed.
66 redraw_con = getDialogs().redrawGUI().connect(boost::bind(&XFormsView::redraw, this));
70 XFormsView::~XFormsView()
73 XFreePixmap(fl_get_display(), icon_pixmap_);
75 minibuffer_->freeze();
81 /// Redraw the main form.
82 void XFormsView::redraw()
84 lyxerr[Debug::INFO] << "XFormsView::redraw()" << endl;
85 fl_redraw_form(getForm());
86 minibuffer_->redraw();
90 FL_FORM * XFormsView::getForm() const
96 // Callback for close main form from window manager
97 int XFormsView::atCloseMainFormCB(FL_FORM *, void *)
104 void XFormsView::show(int x, int y, string const & title)
106 FL_FORM * form = getForm();
108 fl_set_form_minsize(form, form->w, form->h);
110 int placement = FL_PLACE_CENTER | FL_FREE_SIZE;
112 // Did we get a valid geometry position ?
113 if (x >= 0 && y >= 0) {
114 fl_set_form_position(form, x, y);
115 placement = FL_PLACE_POSITION;
118 fl_show_form(form, placement, FL_FULLBORDER, title.c_str());
124 void XFormsView::create_form_form_main(int width, int height)
125 /* to make this work as it should, .lyxrc should have been
126 * read first; OR maybe this one should be made dynamic.
128 * We will probably not have lyxrc before the main form is
129 * initialized, because error messages from lyxrc parsing
130 * are presented (and rightly so) in GUI popups. Asger.
134 form_ = fl_bgn_form(FL_NO_BOX, width, height);
135 getForm()->u_vdata = this;
136 FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
137 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
139 // Parameters for the appearance of the main form
141 int const bw = abs(fl_get_border_width());
143 menubar_.reset(new Menubar(this, menubackend));
145 toolbar_.reset(new Toolbar(this, air, 30 + air + bw));
147 int const ywork = 60 + 2 * air + bw;
148 int const workheight = height - ywork - (25 + 2 * air);
150 bufferview_.reset(new BufferView(this, air, ywork,
151 width - 3 * air, workheight));
152 ::current_view = bufferview_.get();
154 minibuffer_.reset(new XMiniBuffer(*controlcommand_,
155 air, height - (25 + air), width - (2 * air), 25));
157 // assign an icon to main form
158 string const iconname = LibFileSearch("images", "lyx", "xpm");
159 if (!iconname.empty()) {
161 icon_pixmap_ = fl_read_pixmapfile(fl_root,
169 fl_set_form_icon(getForm(), icon_pixmap_, icon_mask_);
173 fl_set_form_minsize(getForm(), 50, 50);
179 void XFormsView::setWindowTitle(string const & title, string const & icon_title)
181 fl_set_form_title(getForm(), title.c_str());
182 fl_winicontitle(form_->window, icon_title.c_str());
186 void XFormsView::message(string const & str)
188 minibuffer_->message(str);
192 void XFormsView::clearMessage()
194 message(getLyXFunc().view_status_message());
198 void XFormsView::show_view_state()
200 message(getLyXFunc().view_status_message());
204 void XFormsView::busy(bool yes) const
207 view()->hideCursor();
209 static Cursor cursor;
210 static bool cursor_undefined = true;
212 if (cursor_undefined) {
213 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
214 XFlush(fl_get_display());
215 cursor_undefined = false;
218 /// set the cursor to the watch for all forms and the canvas
219 XDefineCursor(fl_get_display(), getForm()->window, cursor);
221 XFlush(fl_get_display());
223 /// we only need to deactivate to prevent resetting the cursor
224 /// to I-beam over the workarea
225 fl_deactivate_all_forms();
227 /// reset the cursor from the watch for all forms and the canvas
229 XUndefineCursor(fl_get_display(), getForm()->window);
231 XFlush(fl_get_display());
232 fl_activate_all_forms();