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 "XMiniBuffer.h"
18 #include "BufferView.h"
21 #include "MenuBackend.h"
23 #include "frontends/Dialogs.h"
24 #include "frontends/Toolbars.h"
26 #include "support/filetools.h" // OnlyFilename()
28 #include <boost/bind.hpp>
30 using boost::shared_ptr;
36 //extern void AutoSave(BufferView *);
37 extern void QuitLyX();
41 using support::LibFileSearch;
48 int C_XFormsView_atCloseMainFormCB(FL_FORM * form, void * p)
50 return XFormsView::atCloseMainFormCB(form, p);
56 void print_metrics(std::ostream & os, std::string const & name, Box const & box)
58 os << name << " metrics:"
59 << "\tx = " << box.xorigin()
60 << "\ty = " << box.yorigin()
61 << "\tw = " << box.width()
62 << "\th = " << box.height() << '\n';
66 XFormsView::XFormsView(int width, int height)
68 window_(Box(width, height)),
69 icon_pixmap_(0), icon_mask_(0)
73 // Logical layout of the boxes making up the LyX window.
74 shared_ptr<Box> top = window_.children().push_back(Box(0,0));
75 shared_ptr<Box> middle = window_.children().push_back(Box(0,0));
76 middle->set(Box::Horizontal);
77 shared_ptr<Box> bottom = window_.children().push_back(Box(0,0));
79 shared_ptr<Box> left = middle->children().push_back(Box(air,0));
80 shared_ptr<Box> center = middle->children().push_back(Box(0,0));
81 center->set(Box::Expand);
82 shared_ptr<Box> right = middle->children().push_back(Box(air,0));
84 // Define accessors to the various boxes.
86 box_map_[Bottom] = bottom;
87 box_map_[Left] = left;
88 box_map_[Center] = center;
89 box_map_[Right] = right;
91 // Define the XForms components making up the window.
92 // Each uses the layout engine defined above to control its
94 form_ = fl_bgn_form(FL_NO_BOX, width, height);
95 form_->u_vdata = this;
96 fl_set_form_atclose(form_, C_XFormsView_atCloseMainFormCB, 0);
98 FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
99 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
101 menubar_.reset(new XFormsMenubar(this, menubackend));
102 getToolbars().init();
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 shared_ptr<Box> XFormsView::getBox(Position pos) const
152 BoxMap::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(bool resize_form)
203 FL_FORM * form = getForm();
205 // We don't want the window to be downsized.
207 window_.setMinimumDimensions(form->w, form->h);
209 window_.updateMetrics();
211 fl_freeze_form(form);
214 fl_set_form_size(form, window_.width(), window_.height());
216 // Emit a signal so that all daughter widgets are layed-out
219 fl_unfreeze_form(form);
223 bool XFormsView::hasFocus() const
225 // No real implementation needed for now
230 void XFormsView::setWindowTitle(string const & title, string const & icon_title)
232 fl_set_form_title(getForm(), title.c_str());
233 fl_winicontitle(form_->window, icon_title.c_str());
237 void XFormsView::message(string const & str)
239 minibuffer_->message(str);
243 void XFormsView::clearMessage()
245 message(getLyXFunc().viewStatusMessage());
249 void XFormsView::show_view_state()
251 message(getLyXFunc().viewStatusMessage());
255 void XFormsView::busy(bool yes) const
258 view()->hideCursor();
260 static Cursor cursor;
261 static bool cursor_undefined = true;
263 if (cursor_undefined) {
264 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
265 XFlush(fl_get_display());
266 cursor_undefined = false;
269 /// set the cursor to the watch for all forms and the canvas
270 XDefineCursor(fl_get_display(), getForm()->window, cursor);
272 XFlush(fl_get_display());
274 /// we only need to deactivate to prevent resetting the cursor
275 /// to I-beam over the workarea
276 fl_deactivate_all_forms();
278 /// reset the cursor from the watch for all forms and the canvas
280 XUndefineCursor(fl_get_display(), getForm()->window);
282 XFlush(fl_get_display());
283 fl_activate_all_forms();
287 } // namespace frontend