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::frontend::Box;
32 using lyx::support::LibFileSearch;
39 //extern void AutoSave(BufferView *);
40 extern void QuitLyX();
45 int C_XFormsView_atCloseMainFormCB(FL_FORM * form, void * p)
47 return XFormsView::atCloseMainFormCB(form, p);
53 void print_metrics(std::ostream & os, std::string const & name, Box const & box)
55 os << name << " metrics:"
56 << "\tx = " << box.xorigin()
57 << "\ty = " << box.yorigin()
58 << "\tw = " << box.width()
59 << "\th = " << box.height() << '\n';
63 XFormsView::XFormsView(int width, int height)
65 window_(Box(width, height)),
66 icon_pixmap_(0), icon_mask_(0)
70 // Logical layout of the boxes making up the LyX window.
71 Box & top = window_.children().push_back(Box(0,0));
72 Box & middle = window_.children().push_back(Box(0,0));
73 middle.set(Box::Horizontal);
74 Box & bottom = window_.children().push_back(Box(0,0));
76 Box & left = middle.children().push_back(Box(air,0));
77 Box & center = middle.children().push_back(Box(0,0));
78 center.set(Box::Expand);
79 Box & right = middle.children().push_back(Box(air,0));
81 // Define accessors to the various boxes.
83 box_map_[Bottom] = ⊥
84 box_map_[Left] = &left;
85 box_map_[Center] = ¢er;
86 box_map_[Right] = &right;
88 // Define the XForms components making up the window.
89 // Each uses the layout engine defined above to control its
91 form_ = fl_bgn_form(FL_NO_BOX, width, height);
92 form_->u_vdata = this;
93 fl_set_form_atclose(form_, C_XFormsView_atCloseMainFormCB, 0);
95 FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
96 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
98 menubar_.reset(new XFormsMenubar(this, menubackend));
100 toolbar_.reset(new XFormsToolbar(this));
103 bufferview_.reset(new BufferView(this, width, height));
104 minibuffer_.reset(new XMiniBuffer(*this, *controlcommand_));
106 // Assign an icon to the main form.
107 string const iconname = LibFileSearch("images", "lyx", "xpm");
108 if (!iconname.empty()) {
110 icon_pixmap_ = fl_read_pixmapfile(fl_root,
118 fl_set_form_icon(form_, icon_pixmap_, icon_mask_);
123 // Update the layout so that all widgets fit.
128 view_state_changed.connect(boost::bind(&XFormsView::show_view_state, this));
130 focus_command_buffer.connect(boost::bind(&XMiniBuffer::focus, minibuffer_.get()));
132 // Make sure the buttons are disabled if needed.
135 getDialogs().redrawGUI().connect(boost::bind(&XFormsView::redraw, this));
139 XFormsView::~XFormsView()
142 XFreePixmap(fl_get_display(), icon_pixmap_);
144 minibuffer_->freeze();
150 Box & XFormsView::getBox(Position pos) const
152 std::map<Position, Box *>::const_iterator it = box_map_.find(pos);
153 BOOST_ASSERT(it != box_map_.end());
158 /// Redraw the main form.
159 void XFormsView::redraw()
161 lyxerr[Debug::INFO] << "XFormsView::redraw()" << endl;
162 fl_redraw_form(getForm());
163 minibuffer_->redraw();
167 FL_FORM * XFormsView::getForm() const
173 // Callback for close main form from window manager
174 int XFormsView::atCloseMainFormCB(FL_FORM *, void *)
181 void XFormsView::show(int x, int y, string const & title)
183 FL_FORM * form = getForm();
185 fl_set_form_minsize(form, form->w, form->h);
187 int placement = FL_PLACE_CENTER | FL_FREE_SIZE;
189 // Did we get a valid geometry position ?
190 if (x >= 0 && y >= 0) {
191 fl_set_form_position(form, x, y);
192 placement = FL_PLACE_POSITION;
195 fl_show_form(form, placement, FL_FULLBORDER, title.c_str());
201 void XFormsView::updateMetrics()
203 window_.updateMetrics();
205 FL_FORM * form = getForm();
206 fl_set_form_size(form, window_.width(), window_.height());
208 // Emit a signal so that all daughter widgets are layed-out
214 void XFormsView::setWindowTitle(string const & title, string const & icon_title)
216 fl_set_form_title(getForm(), title.c_str());
217 fl_winicontitle(form_->window, icon_title.c_str());
221 void XFormsView::message(string const & str)
223 minibuffer_->message(str);
227 void XFormsView::clearMessage()
229 message(getLyXFunc().viewStatusMessage());
233 void XFormsView::show_view_state()
235 message(getLyXFunc().viewStatusMessage());
239 void XFormsView::busy(bool yes) const
242 view()->hideCursor();
244 static Cursor cursor;
245 static bool cursor_undefined = true;
247 if (cursor_undefined) {
248 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
249 XFlush(fl_get_display());
250 cursor_undefined = false;
253 /// set the cursor to the watch for all forms and the canvas
254 XDefineCursor(fl_get_display(), getForm()->window, cursor);
256 XFlush(fl_get_display());
258 /// we only need to deactivate to prevent resetting the cursor
259 /// to I-beam over the workarea
260 fl_deactivate_all_forms();
262 /// reset the cursor from the watch for all forms and the canvas
264 XUndefineCursor(fl_get_display(), getForm()->window);
266 XFlush(fl_get_display());
267 fl_activate_all_forms();