X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fxforms%2FXFormsView.C;h=f13ca1f3369fd1980480cba30a58b389be2e7608;hb=8c93f63b48a1b15d4f3e163b7305213f2f73879e;hp=36a2cc90d5ddec3bf5e25a7f829b98c7618580a3;hpb=13080e1cce039a28a4847b8f2d88a3fe520f38a3;p=lyx.git diff --git a/src/frontends/xforms/XFormsView.C b/src/frontends/xforms/XFormsView.C index 36a2cc90d5..f13ca1f336 100644 --- a/src/frontends/xforms/XFormsView.C +++ b/src/frontends/xforms/XFormsView.C @@ -5,65 +5,142 @@ * * \author unknown * - * Full author contact details are available in file CREDITS + * Full author contact details are available in file CREDITS. */ #include - #include "XFormsView.h" -#include FORMS_H_LOCATION +#include "XFormsMenubar.h" #include "XMiniBuffer.h" + +#include "BufferView.h" #include "debug.h" -#include "intl.h" -#include "lyxrc.h" -#include "support/filetools.h" // OnlyFilename() -#include "frontends/Toolbar.h" -#include "frontends/Menubar.h" -#include "frontends/Timeout.h" -#include "frontends/Dialogs.h" -#include "MenuBackend.h" -#include "ToolbarDefaults.h" +#include "lyx_main.h" +#include "session.h" #include "lyxfunc.h" -#include "bufferview_funcs.h" -#include "BufferView.h" +#include "MenuBackend.h" +#include "funcrequest.h" + +#include "frontends/Dialogs.h" +#include "frontends/Toolbars.h" + +#include "support/filetools.h" // OnlyFilename() +#include "support/convert.h" #include -#include + +using boost::shared_ptr; + using std::abs; using std::endl; +using std::string; //extern void AutoSave(BufferView *); -extern void QuitLyX(); +extern void QuitLyX(bool); + +namespace lyx { -// This is very temporary -BufferView * current_view; +using support::libFileSearch; + +namespace frontend { extern "C" { static -int C_XFormsView_atCloseMainFormCB(FL_FORM * form, void * p) +int C_XFormsView_atCloseMainFormCB(FL_FORM * /*form*/, void * arg) { - return XFormsView::atCloseMainFormCB(form, p); + // For some reason u_vdata does not contain the pointer + // to the XFormsView that we need. We get it through arg instead. + //XFormsView * view = static_cast(form->u_vdata); + XFormsView * view = static_cast(arg); + return view->atCloseMainFormCB(); } } +void print_metrics(std::ostream & os, std::string const & name, Box const & box) +{ + os << name << " metrics:" + << "\tx = " << box.xorigin() + << "\ty = " << box.yorigin() + << "\tw = " << box.width() + << "\th = " << box.height() << '\n'; +} + + XFormsView::XFormsView(int width, int height) : LyXView(), + window_(Box(width, height)), icon_pixmap_(0), icon_mask_(0) { - create_form_form_main(width, height); - fl_set_form_atclose(getForm(), C_XFormsView_atCloseMainFormCB, 0); + int const air = 2; - view_state_con = view_state_changed.connect(boost::bind(&XFormsView::show_view_state, this)); - focus_con = focus_command_buffer.connect(boost::bind(&XMiniBuffer::focus, minibuffer_.get())); + // Logical layout of the boxes making up the LyX window. + shared_ptr top = window_.children().push_back(Box(0,0)); + shared_ptr middle = window_.children().push_back(Box(0,0)); + middle->set(Box::Horizontal); + shared_ptr bottom = window_.children().push_back(Box(0,0)); + + shared_ptr left = middle->children().push_back(Box(air,0)); + shared_ptr center = middle->children().push_back(Box(0,0)); + center->set(Box::Expand); + shared_ptr right = middle->children().push_back(Box(air,0)); + + // Define accessors to the various boxes. + box_map_[Top] = top; + box_map_[Bottom] = bottom; + box_map_[Left] = left; + box_map_[Center] = center; + box_map_[Right] = right; + + // Define the XForms components making up the window. + // Each uses the layout engine defined above to control its + // dimensions. + form_ = fl_bgn_form(FL_NO_BOX, width, height); + form_->u_vdata = this; + fl_set_form_atclose(form_, C_XFormsView_atCloseMainFormCB, this); + + FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, ""); + fl_set_object_color(obj, FL_MCOL, FL_MCOL); + + menubar_.reset(new XFormsMenubar(this, menubackend)); + getToolbars().init(); + bufferview_.reset(new BufferView(this, width, height)); + minibuffer_.reset(new XMiniBuffer(*this, *controlcommand_)); + + // Assign an icon to the main form. + string const iconname = libFileSearch("images", "lyx", "xpm"); + if (!iconname.empty()) { + unsigned int w, h; + icon_pixmap_ = fl_read_pixmapfile(fl_root, + iconname.c_str(), + &w, + &h, + &icon_mask_, + 0, + 0, + 0); + fl_set_form_icon(form_, icon_pixmap_, icon_mask_); + } + + fl_end_form(); + + // Update the layout so that all widgets fit. + window_.show(); + updateMetrics(true); + + view_state_con = + view_state_changed.connect(boost::bind(&XFormsView::show_view_state, this)); + focus_con = + focus_command_buffer.connect(boost::bind(&XMiniBuffer::focus, minibuffer_.get())); // Make sure the buttons are disabled if needed. - updateToolbar(); - redraw_con = getDialogs().redrawGUI().connect(boost::bind(&XFormsView::redraw, this)); + updateToolbars(); + redraw_con = + getDialogs().redrawGUI().connect(boost::bind(&XFormsView::redraw, this)); } @@ -78,6 +155,14 @@ XFormsView::~XFormsView() } +shared_ptr XFormsView::getBox(Position pos) const +{ + BoxMap::const_iterator it = box_map_.find(pos); + BOOST_ASSERT(it != box_map_.end()); + return it->second; +} + + /// Redraw the main form. void XFormsView::redraw() { @@ -94,9 +179,15 @@ FL_FORM * XFormsView::getForm() const // Callback for close main form from window manager -int XFormsView::atCloseMainFormCB(FL_FORM *, void *) +int XFormsView::atCloseMainFormCB() { - QuitLyX(); + // save windows size + LyX::ref().session().saveSessionInfo("WindowWidth", convert(form_->w)); + LyX::ref().session().saveSessionInfo("WindowHeight", convert(form_->h)); + // trigger LFUN_QUIT instead of quit directly + // since LFUN_QUIT may have more cleanup stuff + // + getLyXFunc().dispatch(FuncRequest(LFUN_QUIT)); return FL_IGNORE; } @@ -121,60 +212,32 @@ void XFormsView::show(int x, int y, string const & title) } -void XFormsView::create_form_form_main(int width, int height) - /* to make this work as it should, .lyxrc should have been - * read first; OR maybe this one should be made dynamic. - * Hmmmm. Lgb. - * We will probably not have lyxrc before the main form is - * initialized, because error messages from lyxrc parsing - * are presented (and rightly so) in GUI popups. Asger. - */ +void XFormsView::updateMetrics(bool resize_form) { - // the main form - form_ = fl_bgn_form(FL_NO_BOX, width, height); - getForm()->u_vdata = this; - FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, ""); - fl_set_object_color(obj, FL_MCOL, FL_MCOL); - - // Parameters for the appearance of the main form - int const air = 2; - int const bw = abs(fl_get_border_width()); - - menubar_.reset(new Menubar(this, menubackend)); - - toolbar_.reset(new Toolbar(this, air, 30 + air + bw, toolbardefaults)); + FL_FORM * form = getForm(); - int const ywork = 60 + 2 * air + bw; - int const workheight = height - ywork - (25 + 2 * air); + // We don't want the window to be downsized. + if (!resize_form) + window_.setMinimumDimensions(form->w, form->h); - bufferview_.reset(new BufferView(this, air, ywork, - width - 3 * air, workheight)); - ::current_view = bufferview_.get(); + window_.updateMetrics(); - minibuffer_.reset(new XMiniBuffer(this, *controlcommand_, - air, height - (25 + air), width - (2 * air), 25)); + fl_freeze_form(form); - // assign an icon to main form - string const iconname = LibFileSearch("images", "lyx", "xpm"); - if (!iconname.empty()) { - unsigned int w, h; - icon_pixmap_ = fl_read_pixmapfile(fl_root, - iconname.c_str(), - &w, - &h, - &icon_mask_, - 0, - 0, - 0); - fl_set_form_icon(getForm(), icon_pixmap_, icon_mask_); - } + if (resize_form) + fl_set_form_size(form, window_.width(), window_.height()); - // set min size - fl_set_form_minsize(getForm(), 50, 50); + // Emit a signal so that all daughter widgets are layed-out + // correctly. + metricsUpdated(); + fl_unfreeze_form(form); +} - fl_end_form(); - minibuffer_->dd_init(); +bool XFormsView::hasFocus() const +{ + // No real implementation needed for now + return true; } @@ -191,9 +254,15 @@ void XFormsView::message(string const & str) } +void XFormsView::clearMessage() +{ + message(getLyXFunc().viewStatusMessage()); +} + + void XFormsView::show_view_state() { - message(getLyXFunc().view_status_message()); + message(getLyXFunc().viewStatusMessage()); } @@ -228,3 +297,6 @@ void XFormsView::busy(bool yes) const fl_activate_all_forms(); } } + +} // namespace frontend +} // namespace lyx