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.
13 #include "XFormsView.h"
15 #include "XFormsMenubar.h"
16 #include "XFormsToolbar.h"
17 #include "XMiniBuffer.h"
19 #include "BufferView.h"
22 #include "MenuBackend.h"
24 #include "frontends/Dialogs.h"
26 #include "support/filetools.h" // OnlyFilename()
28 #include <boost/bind.hpp>
30 using lyx::support::LibFileSearch;
37 //extern void AutoSave(BufferView *);
38 extern void QuitLyX();
43 int C_XFormsView_atCloseMainFormCB(FL_FORM * form, void * p)
45 return XFormsView::atCloseMainFormCB(form, p);
51 XFormsView::XFormsView(int width, int height)
53 icon_pixmap_(0), icon_mask_(0)
55 create_form_form_main(width, height);
56 fl_set_form_atclose(getForm(), C_XFormsView_atCloseMainFormCB, 0);
58 view_state_con = view_state_changed.connect(boost::bind(&XFormsView::show_view_state, this));
59 focus_con = focus_command_buffer.connect(boost::bind(&XMiniBuffer::focus, minibuffer_.get()));
61 // Make sure the buttons are disabled if needed.
63 redraw_con = getDialogs().redrawGUI().connect(boost::bind(&XFormsView::redraw, this));
67 XFormsView::~XFormsView()
70 XFreePixmap(fl_get_display(), icon_pixmap_);
72 minibuffer_->freeze();
78 /// Redraw the main form.
79 void XFormsView::redraw()
81 lyxerr[Debug::INFO] << "XFormsView::redraw()" << endl;
82 fl_redraw_form(getForm());
83 minibuffer_->redraw();
87 FL_FORM * XFormsView::getForm() const
93 // Callback for close main form from window manager
94 int XFormsView::atCloseMainFormCB(FL_FORM *, void *)
101 void XFormsView::show(int x, int y, string const & title)
103 FL_FORM * form = getForm();
105 fl_set_form_minsize(form, form->w, form->h);
107 int placement = FL_PLACE_CENTER | FL_FREE_SIZE;
109 // Did we get a valid geometry position ?
110 if (x >= 0 && y >= 0) {
111 fl_set_form_position(form, x, y);
112 placement = FL_PLACE_POSITION;
115 fl_show_form(form, placement, FL_FULLBORDER, title.c_str());
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_ = 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 XFormsMenubar(this, menubackend));
142 toolbar_.reset(new XFormsToolbar(this, air, 30 + air + bw));
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));
151 minibuffer_.reset(new XMiniBuffer(*controlcommand_,
152 air, height - (25 + air), width - (2 * air), 25));
154 // assign an icon to main form
155 string const iconname = LibFileSearch("images", "lyx", "xpm");
156 if (!iconname.empty()) {
158 icon_pixmap_ = fl_read_pixmapfile(fl_root,
166 fl_set_form_icon(getForm(), icon_pixmap_, icon_mask_);
170 fl_set_form_minsize(getForm(), 50, 50);
176 void XFormsView::setWindowTitle(string const & title, string const & icon_title)
178 fl_set_form_title(getForm(), title.c_str());
179 fl_winicontitle(form_->window, icon_title.c_str());
183 void XFormsView::message(string const & str)
185 minibuffer_->message(str);
189 void XFormsView::clearMessage()
191 message(getLyXFunc().view_status_message());
195 void XFormsView::show_view_state()
197 message(getLyXFunc().view_status_message());
201 void XFormsView::busy(bool yes) const
204 view()->hideCursor();
206 static Cursor cursor;
207 static bool cursor_undefined = true;
209 if (cursor_undefined) {
210 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
211 XFlush(fl_get_display());
212 cursor_undefined = false;
215 /// set the cursor to the watch for all forms and the canvas
216 XDefineCursor(fl_get_display(), getForm()->window, cursor);
218 XFlush(fl_get_display());
220 /// we only need to deactivate to prevent resetting the cursor
221 /// to I-beam over the workarea
222 fl_deactivate_all_forms();
224 /// reset the cursor from the watch for all forms and the canvas
226 XUndefineCursor(fl_get_display(), getForm()->window);
228 XFlush(fl_get_display());
229 fl_activate_all_forms();