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"
23 #include "MenuBackend.h"
24 #include "funcrequest.h"
26 #include "frontends/Dialogs.h"
27 #include "frontends/Toolbars.h"
29 #include "support/filetools.h" // OnlyFilename()
30 #include "support/convert.h"
32 #include <boost/bind.hpp>
34 using boost::shared_ptr;
40 //extern void AutoSave(BufferView *);
41 extern void QuitLyX(bool);
45 using support::libFileSearch;
52 int C_XFormsView_atCloseMainFormCB(FL_FORM * /*form*/, void * arg)
54 // For some reason u_vdata does not contain the pointer
55 // to the XFormsView that we need. We get it through arg instead.
56 //XFormsView * view = static_cast<XFormsView*>(form->u_vdata);
57 XFormsView * view = static_cast<XFormsView*>(arg);
58 return view->atCloseMainFormCB();
64 void print_metrics(std::ostream & os, std::string const & name, Box const & box)
66 os << name << " metrics:"
67 << "\tx = " << box.xorigin()
68 << "\ty = " << box.yorigin()
69 << "\tw = " << box.width()
70 << "\th = " << box.height() << '\n';
74 XFormsView::XFormsView(int width, int height)
76 window_(Box(width, height)),
77 icon_pixmap_(0), icon_mask_(0)
81 // Logical layout of the boxes making up the LyX window.
82 shared_ptr<Box> top = window_.children().push_back(Box(0,0));
83 shared_ptr<Box> middle = window_.children().push_back(Box(0,0));
84 middle->set(Box::Horizontal);
85 shared_ptr<Box> bottom = window_.children().push_back(Box(0,0));
87 shared_ptr<Box> left = middle->children().push_back(Box(air,0));
88 shared_ptr<Box> center = middle->children().push_back(Box(0,0));
89 center->set(Box::Expand);
90 shared_ptr<Box> right = middle->children().push_back(Box(air,0));
92 // Define accessors to the various boxes.
94 box_map_[Bottom] = bottom;
95 box_map_[Left] = left;
96 box_map_[Center] = center;
97 box_map_[Right] = right;
99 // Define the XForms components making up the window.
100 // Each uses the layout engine defined above to control its
102 form_ = fl_bgn_form(FL_NO_BOX, width, height);
103 form_->u_vdata = this;
104 fl_set_form_atclose(form_, C_XFormsView_atCloseMainFormCB, this);
106 FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
107 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
109 menubar_.reset(new XFormsMenubar(this, menubackend));
110 getToolbars().init();
111 bufferview_.reset(new BufferView(this, width, height));
112 minibuffer_.reset(new XMiniBuffer(*this, *controlcommand_));
114 // Assign an icon to the main form.
115 string const iconname = libFileSearch("images", "lyx", "xpm");
116 if (!iconname.empty()) {
118 icon_pixmap_ = fl_read_pixmapfile(fl_root,
126 fl_set_form_icon(form_, icon_pixmap_, icon_mask_);
131 // Update the layout so that all widgets fit.
136 view_state_changed.connect(boost::bind(&XFormsView::show_view_state, this));
138 focus_command_buffer.connect(boost::bind(&XMiniBuffer::focus, minibuffer_.get()));
140 // Make sure the buttons are disabled if needed.
143 getDialogs().redrawGUI().connect(boost::bind(&XFormsView::redraw, this));
147 XFormsView::~XFormsView()
150 XFreePixmap(fl_get_display(), icon_pixmap_);
152 minibuffer_->freeze();
158 shared_ptr<Box> XFormsView::getBox(Position pos) const
160 BoxMap::const_iterator it = box_map_.find(pos);
161 BOOST_ASSERT(it != box_map_.end());
166 /// Redraw the main form.
167 void XFormsView::redraw()
169 lyxerr[Debug::INFO] << "XFormsView::redraw()" << endl;
170 fl_redraw_form(getForm());
171 minibuffer_->redraw();
175 FL_FORM * XFormsView::getForm() const
181 // Callback for close main form from window manager
182 int XFormsView::atCloseMainFormCB()
185 LyX::ref().session().saveSessionInfo("WindowWidth", convert<string>(form_->w));
186 LyX::ref().session().saveSessionInfo("WindowHeight", convert<string>(form_->h));
187 // trigger LFUN_QUIT instead of quit directly
188 // since LFUN_QUIT may have more cleanup stuff
190 getLyXFunc().dispatch(FuncRequest(LFUN_QUIT));
195 void XFormsView::show(int x, int y, string const & title)
197 FL_FORM * form = getForm();
199 fl_set_form_minsize(form, form->w, form->h);
201 int placement = FL_PLACE_CENTER | FL_FREE_SIZE;
203 // Did we get a valid geometry position ?
204 if (x >= 0 && y >= 0) {
205 fl_set_form_position(form, x, y);
206 placement = FL_PLACE_POSITION;
209 fl_show_form(form, placement, FL_FULLBORDER, title.c_str());
215 void XFormsView::updateMetrics(bool resize_form)
217 FL_FORM * form = getForm();
219 // We don't want the window to be downsized.
221 window_.setMinimumDimensions(form->w, form->h);
223 window_.updateMetrics();
225 fl_freeze_form(form);
228 fl_set_form_size(form, window_.width(), window_.height());
230 // Emit a signal so that all daughter widgets are layed-out
233 fl_unfreeze_form(form);
237 bool XFormsView::hasFocus() const
239 // No real implementation needed for now
244 void XFormsView::setWindowTitle(string const & title, string const & icon_title)
246 fl_set_form_title(getForm(), title.c_str());
247 fl_winicontitle(form_->window, icon_title.c_str());
251 void XFormsView::message(string const & str)
253 minibuffer_->message(str);
257 void XFormsView::clearMessage()
259 message(getLyXFunc().viewStatusMessage());
263 void XFormsView::show_view_state()
265 message(getLyXFunc().viewStatusMessage());
269 void XFormsView::busy(bool yes) const
272 view()->hideCursor();
274 static Cursor cursor;
275 static bool cursor_undefined = true;
277 if (cursor_undefined) {
278 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
279 XFlush(fl_get_display());
280 cursor_undefined = false;
283 /// set the cursor to the watch for all forms and the canvas
284 XDefineCursor(fl_get_display(), getForm()->window, cursor);
286 XFlush(fl_get_display());
288 /// we only need to deactivate to prevent resetting the cursor
289 /// to I-beam over the workarea
290 fl_deactivate_all_forms();
292 /// reset the cursor from the watch for all forms and the canvas
294 XUndefineCursor(fl_get_display(), getForm()->window);
296 XFlush(fl_get_display());
297 fl_activate_all_forms();
301 } // namespace frontend