From: Bo Peng Date: Thu, 26 Apr 2007 04:03:46 +0000 (+0000) Subject: Rename .C ==> .cpp for files in src/frontends, part two X-Git-Tag: 1.6.10~10061 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=9a17e559f289845db02bc114fad5190280548e4e;p=lyx.git Rename .C ==> .cpp for files in src/frontends, part two git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18017 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/Alert.C b/src/frontends/Alert.C deleted file mode 100644 index 4ac7f9a478..0000000000 --- a/src/frontends/Alert.C +++ /dev/null @@ -1,104 +0,0 @@ -/** - * \file Alert.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author John Levon - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "Alert.h" -#include "Alert_pimpl.h" - -#include "debug.h" -#include "lyx_main.h" // for lyx::use_gui - -using std::endl; -using std::make_pair; -using std::pair; -using std::string; - - -namespace lyx { - -namespace frontend { - -int Alert::prompt(docstring const & title, docstring const & question, - int default_button, int escape_button, - docstring const & b1, docstring const & b2, docstring const & b3) -{ - if (!use_gui || lyxerr.debugging()) { - lyxerr << to_utf8(title) << '\n' - << "----------------------------------------\n" - << to_utf8(question) << endl; - - lyxerr << "Assuming answer is "; - switch (default_button) { - case 0: lyxerr << to_utf8(b1) << endl; - case 1: lyxerr << to_utf8(b2) << endl; - case 2: lyxerr << to_utf8(b3) << endl; - } - if (!use_gui) - return default_button; - } - - return prompt_pimpl(title, question, - default_button, escape_button, b1, b2, b3); - -} - - -void Alert::warning(docstring const & title, docstring const & message) -{ - lyxerr << "Warning: " << to_utf8(title) << '\n' - << "----------------------------------------\n" - << to_utf8(message) << endl; - - if (use_gui) - warning_pimpl(title, message); -} - - -void Alert::error(docstring const & title, docstring const & message) -{ - lyxerr << "Error: " << to_utf8(title) << '\n' - << "----------------------------------------\n" - << to_utf8(message) << endl; - - if (use_gui) - error_pimpl(title, message); -} - - -void Alert::information(docstring const & title, docstring const & message) -{ - if (!use_gui || lyxerr.debugging()) - lyxerr << to_utf8(title) << '\n' - << "----------------------------------------\n" - << to_utf8(message) << endl; - - if (use_gui) - information_pimpl(title, message); -} - - -pair const Alert::askForText(docstring const & msg, - docstring const & dflt) -{ - if (!use_gui || lyxerr.debugging()) { - lyxerr << "----------------------------------------\n" - << to_utf8(msg) << '\n' - << "Assuming answer is " << to_utf8(dflt) << '\n' - << "----------------------------------------" << endl; - if (!use_gui) - return make_pair(true, dflt); - } - - return askForText_pimpl(msg, dflt); -} - -} // namespace frontend -} // namespace lyx diff --git a/src/frontends/Alert.cpp b/src/frontends/Alert.cpp new file mode 100644 index 0000000000..4ac7f9a478 --- /dev/null +++ b/src/frontends/Alert.cpp @@ -0,0 +1,104 @@ +/** + * \file Alert.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Levon + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "Alert.h" +#include "Alert_pimpl.h" + +#include "debug.h" +#include "lyx_main.h" // for lyx::use_gui + +using std::endl; +using std::make_pair; +using std::pair; +using std::string; + + +namespace lyx { + +namespace frontend { + +int Alert::prompt(docstring const & title, docstring const & question, + int default_button, int escape_button, + docstring const & b1, docstring const & b2, docstring const & b3) +{ + if (!use_gui || lyxerr.debugging()) { + lyxerr << to_utf8(title) << '\n' + << "----------------------------------------\n" + << to_utf8(question) << endl; + + lyxerr << "Assuming answer is "; + switch (default_button) { + case 0: lyxerr << to_utf8(b1) << endl; + case 1: lyxerr << to_utf8(b2) << endl; + case 2: lyxerr << to_utf8(b3) << endl; + } + if (!use_gui) + return default_button; + } + + return prompt_pimpl(title, question, + default_button, escape_button, b1, b2, b3); + +} + + +void Alert::warning(docstring const & title, docstring const & message) +{ + lyxerr << "Warning: " << to_utf8(title) << '\n' + << "----------------------------------------\n" + << to_utf8(message) << endl; + + if (use_gui) + warning_pimpl(title, message); +} + + +void Alert::error(docstring const & title, docstring const & message) +{ + lyxerr << "Error: " << to_utf8(title) << '\n' + << "----------------------------------------\n" + << to_utf8(message) << endl; + + if (use_gui) + error_pimpl(title, message); +} + + +void Alert::information(docstring const & title, docstring const & message) +{ + if (!use_gui || lyxerr.debugging()) + lyxerr << to_utf8(title) << '\n' + << "----------------------------------------\n" + << to_utf8(message) << endl; + + if (use_gui) + information_pimpl(title, message); +} + + +pair const Alert::askForText(docstring const & msg, + docstring const & dflt) +{ + if (!use_gui || lyxerr.debugging()) { + lyxerr << "----------------------------------------\n" + << to_utf8(msg) << '\n' + << "Assuming answer is " << to_utf8(dflt) << '\n' + << "----------------------------------------" << endl; + if (!use_gui) + return make_pair(true, dflt); + } + + return askForText_pimpl(msg, dflt); +} + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/Application.C b/src/frontends/Application.C deleted file mode 100644 index cd62f7982c..0000000000 --- a/src/frontends/Application.C +++ /dev/null @@ -1,130 +0,0 @@ -/** - * \file frontend/Application.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Abdelrazak Younes - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "frontends/Application.h" - -#include "frontends/NoGuiFontLoader.h" -#include "frontends/NoGuiFontMetrics.h" -#include "frontends/FontLoader.h" -#include "frontends/FontMetrics.h" -#include "frontends/Gui.h" -#include "frontends/LyXView.h" -#include "frontends/WorkArea.h" - -#include "funcrequest.h" -#include "FuncStatus.h" -#include "lyx_main.h" // for lyx::use_gui -#include "lyxfont.h" -#include "lyxfunc.h" -#include "lyxrc.h" - -#include "support/lstrings.h" -#include "support/os.h" - -#include -#include - - -namespace lyx { -namespace frontend { - - -Application::Application(int &, char **) - : current_view_(0) -{ -} - - -LyXView & Application::createView(unsigned int width, - unsigned int height, - int posx, int posy, - int maximized, - unsigned int iconSizeXY, - const std::string & geometryArg) -{ - LyXView & view = gui().createRegisteredView(); - int view_id = view.id(); - - theLyXFunc().setLyXView(&view); - - /*int workArea_id_ =*/ gui().newWorkArea(width, height, view_id); - - view.init(); - view.setGeometry(width, height, posx, posy, maximized, iconSizeXY, geometryArg); - view.setFocus(); - - setCurrentView(view); - - return view; -} - - -LyXView const * Application::currentView() const -{ - return current_view_; -} - - -LyXView * Application::currentView() -{ - return current_view_; -} - - -void Application::setCurrentView(LyXView & current_view) -{ - current_view_ = ¤t_view; -} - -} // namespace frontend - - - -frontend::FontLoader & theFontLoader() -{ - static frontend::NoGuiFontLoader no_gui_font_loader; - - if (!use_gui) - return no_gui_font_loader; - - BOOST_ASSERT(theApp()); - return theApp()->fontLoader(); -} - - -frontend::FontMetrics const & theFontMetrics(LyXFont const & f) -{ - static frontend::NoGuiFontMetrics no_gui_font_metrics; - - if (!use_gui) - return no_gui_font_metrics; - - BOOST_ASSERT(theApp()); - return theApp()->fontLoader().metrics(f); -} - - -frontend::Clipboard & theClipboard() -{ - BOOST_ASSERT(theApp()); - return theApp()->clipboard(); -} - - -frontend::Selection & theSelection() -{ - BOOST_ASSERT(theApp()); - return theApp()->selection(); -} - - -} // namespace lyx diff --git a/src/frontends/Application.cpp b/src/frontends/Application.cpp new file mode 100644 index 0000000000..cd62f7982c --- /dev/null +++ b/src/frontends/Application.cpp @@ -0,0 +1,130 @@ +/** + * \file frontend/Application.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "frontends/Application.h" + +#include "frontends/NoGuiFontLoader.h" +#include "frontends/NoGuiFontMetrics.h" +#include "frontends/FontLoader.h" +#include "frontends/FontMetrics.h" +#include "frontends/Gui.h" +#include "frontends/LyXView.h" +#include "frontends/WorkArea.h" + +#include "funcrequest.h" +#include "FuncStatus.h" +#include "lyx_main.h" // for lyx::use_gui +#include "lyxfont.h" +#include "lyxfunc.h" +#include "lyxrc.h" + +#include "support/lstrings.h" +#include "support/os.h" + +#include +#include + + +namespace lyx { +namespace frontend { + + +Application::Application(int &, char **) + : current_view_(0) +{ +} + + +LyXView & Application::createView(unsigned int width, + unsigned int height, + int posx, int posy, + int maximized, + unsigned int iconSizeXY, + const std::string & geometryArg) +{ + LyXView & view = gui().createRegisteredView(); + int view_id = view.id(); + + theLyXFunc().setLyXView(&view); + + /*int workArea_id_ =*/ gui().newWorkArea(width, height, view_id); + + view.init(); + view.setGeometry(width, height, posx, posy, maximized, iconSizeXY, geometryArg); + view.setFocus(); + + setCurrentView(view); + + return view; +} + + +LyXView const * Application::currentView() const +{ + return current_view_; +} + + +LyXView * Application::currentView() +{ + return current_view_; +} + + +void Application::setCurrentView(LyXView & current_view) +{ + current_view_ = ¤t_view; +} + +} // namespace frontend + + + +frontend::FontLoader & theFontLoader() +{ + static frontend::NoGuiFontLoader no_gui_font_loader; + + if (!use_gui) + return no_gui_font_loader; + + BOOST_ASSERT(theApp()); + return theApp()->fontLoader(); +} + + +frontend::FontMetrics const & theFontMetrics(LyXFont const & f) +{ + static frontend::NoGuiFontMetrics no_gui_font_metrics; + + if (!use_gui) + return no_gui_font_metrics; + + BOOST_ASSERT(theApp()); + return theApp()->fontLoader().metrics(f); +} + + +frontend::Clipboard & theClipboard() +{ + BOOST_ASSERT(theApp()); + return theApp()->clipboard(); +} + + +frontend::Selection & theSelection() +{ + BOOST_ASSERT(theApp()); + return theApp()->selection(); +} + + +} // namespace lyx diff --git a/src/frontends/Dialogs.C b/src/frontends/Dialogs.C deleted file mode 100644 index afd4665c84..0000000000 --- a/src/frontends/Dialogs.C +++ /dev/null @@ -1,256 +0,0 @@ -/** - * \file frontends/Dialogs.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Angus Leeming - * - * Full author contact details are available in file CREDITS. - * - * Common to all frontends' Dialogs - */ - -#include - -#include "Dialogs.h" - -#include "lyx_cb.h" - -#include "controllers/Dialog.h" - -#include -#include - - -namespace lyx { - - -using std::string; -using lyx::frontend::Dialog; - - -// Note that static boost signals break some compilers, so this wrapper -// initialises the signal dynamically when it is first invoked. -template -class BugfixSignal { -public: - Signal & operator()() { return thesignal(); } - Signal const & operator()() const { return thesignal(); } - -private: - Signal & thesignal() const - { - if (!signal_.get()) - signal_.reset(new Signal); - return *signal_; - } - - mutable boost::scoped_ptr signal_; -}; - - -namespace { - -BugfixSignal > hideSignal; - -} - - -void Dialogs::hide(string const & name, InsetBase* inset) -{ - // Don't send the signal if we are quitting, because on MSVC it is - // destructed before the cut stack in CutAndPaste.C, and this method - // is called from some inset destructor if the cut stack is not empty - // on exit. - if (!quitting) - hideSignal()(name, inset); -} - - -Dialogs::Dialogs(LyXView & lyxview) - : lyxview_(lyxview), in_show_(false) -{ - // Connect signals - hideSignal().connect(boost::bind(&Dialogs::hideSlot, this, _1, _2)); -} - - -Dialog * Dialogs::find_or_build(string const & name) -{ - if (!isValidName(name)) - return 0; - - std::map::iterator it = - dialogs_.find(name); - - if (it != dialogs_.end()) - return it->second.get(); - - dialogs_[name] = build(name); - return dialogs_[name].get(); -} - - -void Dialogs::show(string const & name, string const & data) -{ - if (in_show_) { - return; - } - in_show_ = true; - Dialog * dialog = find_or_build(name); - if (dialog) { - // FIXME! Should check that the dialog is NOT an inset dialog. - dialog->show(data); - } - in_show_ = false; -} - - -void Dialogs::show(string const & name, string const & data, InsetBase * inset) -{ - if (in_show_) { - return; - } - in_show_ = true; - Dialog * dialog = find_or_build(name); - if (dialog) { - // FIXME! Should check that the dialog IS an inset dialog. - dialog->show(data); - open_insets_[name] = inset; - } - in_show_ = false; -} - - -bool Dialogs::visible(string const & name) const -{ - std::map::const_iterator it = - dialogs_.find(name); - if (it == dialogs_.end()) - return false; - return it->second.get()->isVisible(); -} - - -void Dialogs::update(string const & name, string const & data) -{ - std::map::const_iterator it = - dialogs_.find(name); - if (it == dialogs_.end()) - return; - - Dialog * const dialog = it->second.get(); - if (dialog->isVisible()) - dialog->update(data); -} - - -void Dialogs::hideSlot(string const & name, InsetBase * inset) -{ - std::map::const_iterator it = - dialogs_.find(name); - if (it == dialogs_.end()) - return; - - if (inset && inset != getOpenInset(name)) - return; - - Dialog * const dialog = it->second.get(); - if (dialog->isVisible()) - dialog->hide(); - open_insets_[name] = 0; -} - - -void Dialogs::disconnect(string const & name) -{ - if (!isValidName(name)) - return; - - if (open_insets_.find(name) != open_insets_.end()) - open_insets_[name] = 0; -} - - -InsetBase * Dialogs::getOpenInset(string const & name) const -{ - if (!isValidName(name)) - return 0; - - std::map::const_iterator it = - open_insets_.find(name); - return it == open_insets_.end() ? 0 : it->second; -} - - -void Dialogs::hideAll() const -{ - std::map::const_iterator it = dialogs_.begin(); - std::map::const_iterator end = dialogs_.end(); - - for(; it != end; ++it) { - it->second->hide(); - } -} - - -void Dialogs::hideBufferDependent() const -{ - std::map::const_iterator it = dialogs_.begin(); - std::map::const_iterator end = dialogs_.end(); - - for(; it != end; ++it) { - Dialog * dialog = it->second.get(); - if (dialog->controller().isBufferDependent()) - dialog->hide(); - } -} - - -void Dialogs::updateBufferDependent(bool switched) const -{ - std::map::const_iterator it = dialogs_.begin(); - std::map::const_iterator end = dialogs_.end(); - - for(; it != end; ++it) { - Dialog * dialog = it->second.get(); - if (switched && dialog->controller().isBufferDependent()) { - if (dialog->isVisible() && dialog->controller().initialiseParams("")) - dialog->view().update(); - else - dialog->hide(); - } else { - // A bit clunky, but the dialog will request - // that the kernel provides it with the necessary - // data. - dialog->RestoreButton(); - } - } -} - - -void Dialogs::redraw() const -{ - std::map::const_iterator it = dialogs_.begin(); - std::map::const_iterator end = dialogs_.end(); - - for(; it != end; ++it) { - it->second->redraw(); - } -} - - -void Dialogs::checkStatus() -{ - std::map::const_iterator it = dialogs_.begin(); - std::map::const_iterator end = dialogs_.end(); - - for(; it != end; ++it) { - Dialog * const dialog = it->second.get(); - if (dialog->isVisible()) - dialog->checkStatus(); - } -} - - -} // namespace lyx diff --git a/src/frontends/Dialogs.cpp b/src/frontends/Dialogs.cpp new file mode 100644 index 0000000000..afd4665c84 --- /dev/null +++ b/src/frontends/Dialogs.cpp @@ -0,0 +1,256 @@ +/** + * \file frontends/Dialogs.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Angus Leeming + * + * Full author contact details are available in file CREDITS. + * + * Common to all frontends' Dialogs + */ + +#include + +#include "Dialogs.h" + +#include "lyx_cb.h" + +#include "controllers/Dialog.h" + +#include +#include + + +namespace lyx { + + +using std::string; +using lyx::frontend::Dialog; + + +// Note that static boost signals break some compilers, so this wrapper +// initialises the signal dynamically when it is first invoked. +template +class BugfixSignal { +public: + Signal & operator()() { return thesignal(); } + Signal const & operator()() const { return thesignal(); } + +private: + Signal & thesignal() const + { + if (!signal_.get()) + signal_.reset(new Signal); + return *signal_; + } + + mutable boost::scoped_ptr signal_; +}; + + +namespace { + +BugfixSignal > hideSignal; + +} + + +void Dialogs::hide(string const & name, InsetBase* inset) +{ + // Don't send the signal if we are quitting, because on MSVC it is + // destructed before the cut stack in CutAndPaste.C, and this method + // is called from some inset destructor if the cut stack is not empty + // on exit. + if (!quitting) + hideSignal()(name, inset); +} + + +Dialogs::Dialogs(LyXView & lyxview) + : lyxview_(lyxview), in_show_(false) +{ + // Connect signals + hideSignal().connect(boost::bind(&Dialogs::hideSlot, this, _1, _2)); +} + + +Dialog * Dialogs::find_or_build(string const & name) +{ + if (!isValidName(name)) + return 0; + + std::map::iterator it = + dialogs_.find(name); + + if (it != dialogs_.end()) + return it->second.get(); + + dialogs_[name] = build(name); + return dialogs_[name].get(); +} + + +void Dialogs::show(string const & name, string const & data) +{ + if (in_show_) { + return; + } + in_show_ = true; + Dialog * dialog = find_or_build(name); + if (dialog) { + // FIXME! Should check that the dialog is NOT an inset dialog. + dialog->show(data); + } + in_show_ = false; +} + + +void Dialogs::show(string const & name, string const & data, InsetBase * inset) +{ + if (in_show_) { + return; + } + in_show_ = true; + Dialog * dialog = find_or_build(name); + if (dialog) { + // FIXME! Should check that the dialog IS an inset dialog. + dialog->show(data); + open_insets_[name] = inset; + } + in_show_ = false; +} + + +bool Dialogs::visible(string const & name) const +{ + std::map::const_iterator it = + dialogs_.find(name); + if (it == dialogs_.end()) + return false; + return it->second.get()->isVisible(); +} + + +void Dialogs::update(string const & name, string const & data) +{ + std::map::const_iterator it = + dialogs_.find(name); + if (it == dialogs_.end()) + return; + + Dialog * const dialog = it->second.get(); + if (dialog->isVisible()) + dialog->update(data); +} + + +void Dialogs::hideSlot(string const & name, InsetBase * inset) +{ + std::map::const_iterator it = + dialogs_.find(name); + if (it == dialogs_.end()) + return; + + if (inset && inset != getOpenInset(name)) + return; + + Dialog * const dialog = it->second.get(); + if (dialog->isVisible()) + dialog->hide(); + open_insets_[name] = 0; +} + + +void Dialogs::disconnect(string const & name) +{ + if (!isValidName(name)) + return; + + if (open_insets_.find(name) != open_insets_.end()) + open_insets_[name] = 0; +} + + +InsetBase * Dialogs::getOpenInset(string const & name) const +{ + if (!isValidName(name)) + return 0; + + std::map::const_iterator it = + open_insets_.find(name); + return it == open_insets_.end() ? 0 : it->second; +} + + +void Dialogs::hideAll() const +{ + std::map::const_iterator it = dialogs_.begin(); + std::map::const_iterator end = dialogs_.end(); + + for(; it != end; ++it) { + it->second->hide(); + } +} + + +void Dialogs::hideBufferDependent() const +{ + std::map::const_iterator it = dialogs_.begin(); + std::map::const_iterator end = dialogs_.end(); + + for(; it != end; ++it) { + Dialog * dialog = it->second.get(); + if (dialog->controller().isBufferDependent()) + dialog->hide(); + } +} + + +void Dialogs::updateBufferDependent(bool switched) const +{ + std::map::const_iterator it = dialogs_.begin(); + std::map::const_iterator end = dialogs_.end(); + + for(; it != end; ++it) { + Dialog * dialog = it->second.get(); + if (switched && dialog->controller().isBufferDependent()) { + if (dialog->isVisible() && dialog->controller().initialiseParams("")) + dialog->view().update(); + else + dialog->hide(); + } else { + // A bit clunky, but the dialog will request + // that the kernel provides it with the necessary + // data. + dialog->RestoreButton(); + } + } +} + + +void Dialogs::redraw() const +{ + std::map::const_iterator it = dialogs_.begin(); + std::map::const_iterator end = dialogs_.end(); + + for(; it != end; ++it) { + it->second->redraw(); + } +} + + +void Dialogs::checkStatus() +{ + std::map::const_iterator it = dialogs_.begin(); + std::map::const_iterator end = dialogs_.end(); + + for(; it != end; ++it) { + Dialog * const dialog = it->second.get(); + if (dialog->isVisible()) + dialog->checkStatus(); + } +} + + +} // namespace lyx diff --git a/src/frontends/LyXView.C b/src/frontends/LyXView.C deleted file mode 100644 index 6d6c9fcb30..0000000000 --- a/src/frontends/LyXView.C +++ /dev/null @@ -1,458 +0,0 @@ -/** - * \file LyXView.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Lars Gullik Bjønnes - * \author John Levon - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "LyXView.h" -#include "Dialogs.h" -#include "Timeout.h" -#include "Toolbars.h" -#include "Menubar.h" -#include "WorkArea.h" -#include "Gui.h" - -#include "buffer.h" -#include "bufferparams.h" -#include "BufferView.h" -#include "bufferview_funcs.h" -#include "cursor.h" -#include "debug.h" -#include "errorlist.h" -#include "funcrequest.h" -#include "gettext.h" -#include "intl.h" -#include "lyx_cb.h" -#include "lyxfunc.h" -#include "lyxrc.h" -#include "lyxtext.h" -#include "MenuBackend.h" -#include "paragraph.h" - -#include "controllers/ControlCommandBuffer.h" - -#include "support/lstrings.h" -#include "support/filetools.h" // OnlyFilename() - -#include - - -namespace lyx { - -#ifdef HAVE_SYS_TIME_H -# include -#endif -#ifdef HAVE_UNISTD_H -# include -#endif - -using frontend::WorkArea; - -using support::bformat; -using support::FileName; -using support::makeDisplayPath; -using support::onlyFilename; - -using std::endl; -using std::string; - -using lyx::frontend::ControlCommandBuffer; - -string current_layout; - - -LyXView::LyXView(int id) - : work_area_(0), - toolbars_(new Toolbars(*this)), - autosave_timeout_(new Timeout(5000)), - dialogs_(new Dialogs(*this)), - controlcommand_(new ControlCommandBuffer(*this)), id_(id) -{ - // Start autosave timer - if (lyxrc.autosave) { - autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this)); - autosave_timeout_->setTimeout(lyxrc.autosave * 1000); - autosave_timeout_->start(); - } -} - - -LyXView::~LyXView() -{ - disconnectBuffer(); -} - - -// FIXME, there's only one WorkArea per LyXView possible for now. -void LyXView::setWorkArea(WorkArea * work_area) -{ - BOOST_ASSERT(work_area); - work_area_ = work_area; - work_area_ids_.clear(); - work_area_ids_.push_back(work_area_->id()); -} - - -// FIXME, there's only one WorkArea per LyXView possible for now. -WorkArea const * LyXView::currentWorkArea() const -{ - return work_area_; -} - - -// FIXME, there's only one WorkArea per LyXView possible for now. -WorkArea * LyXView::currentWorkArea() -{ - return work_area_; -} - - -Buffer * LyXView::buffer() const -{ - BOOST_ASSERT(work_area_); - return work_area_->bufferView().buffer(); -} - - -void LyXView::setBuffer(Buffer * b) -{ - busy(true); - - BOOST_ASSERT(work_area_); - if (work_area_->bufferView().buffer()) - disconnectBuffer(); - - if (!b) - getDialogs().hideBufferDependent(); - - work_area_->bufferView().setBuffer(b); - // Make sure the TOC is updated before anything else. - updateToc(); - - if (work_area_->bufferView().buffer()) { - // Buffer-dependent dialogs should be updated or - // hidden. This should go here because some dialogs (eg ToC) - // require bv_->text. - getDialogs().updateBufferDependent(true); - connectBuffer(*work_area_->bufferView().buffer()); - } - - if (quitting) - return; - - updateMenubar(); - updateToolbars(); - updateLayoutChoice(); - updateWindowTitle(); - updateStatusBar(); - updateTab(); - busy(false); - work_area_->redraw(); -} - - -bool LyXView::loadLyXFile(FileName const & filename, bool tolastfiles) -{ - busy(true); - - BOOST_ASSERT(work_area_); - if (work_area_->bufferView().buffer()) - disconnectBuffer(); - - bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles); - - updateToc(); - updateMenubar(); - updateToolbars(); - updateLayoutChoice(); - updateWindowTitle(); - updateTab(); - if (loaded) { - connectBuffer(*work_area_->bufferView().buffer()); - showErrorList("Parse"); - } - updateStatusBar(); - busy(false); - work_area_->redraw(); - return loaded; -} - - -void LyXView::connectBuffer(Buffer & buf) -{ - if (errorsConnection_.connected()) - disconnectBuffer(); - - BOOST_ASSERT(work_area_); - bufferChangedConnection_ = - buf.changed.connect( - boost::bind(&WorkArea::redraw, work_area_)); - - bufferStructureChangedConnection_ = - buf.structureChanged.connect( - boost::bind(&LyXView::updateToc, this)); - - errorsConnection_ = - buf.errors.connect( - boost::bind(&LyXView::showErrorList, this, _1)); - - messageConnection_ = - buf.message.connect( - boost::bind(&LyXView::message, this, _1)); - - busyConnection_ = - buf.busy.connect( - boost::bind(&LyXView::busy, this, _1)); - - titleConnection_ = - buf.updateTitles.connect( - boost::bind(&LyXView::updateWindowTitle, this)); - - timerConnection_ = - buf.resetAutosaveTimers.connect( - boost::bind(&LyXView::resetAutosaveTimer, this)); - - readonlyConnection_ = - buf.readonly.connect( - boost::bind(&LyXView::showReadonly, this, _1)); - - closingConnection_ = - buf.closing.connect( - boost::bind(&LyXView::setBuffer, this, (Buffer *)0)); -} - - -void LyXView::disconnectBuffer() -{ - errorsConnection_.disconnect(); - bufferChangedConnection_.disconnect(); - bufferStructureChangedConnection_.disconnect(); - messageConnection_.disconnect(); - busyConnection_.disconnect(); - titleConnection_.disconnect(); - timerConnection_.disconnect(); - readonlyConnection_.disconnect(); - closingConnection_.disconnect(); - layout_changed_connection_.disconnect(); -} - - -void LyXView::connectBufferView(BufferView & bv) -{ - show_dialog_connection_ = bv.showDialog.connect( - boost::bind(&LyXView::showDialog, this, _1)); - show_dialog_with_data_connection_ = bv.showDialogWithData.connect( - boost::bind(&LyXView::showDialogWithData, this, _1, _2)); - show_inset_dialog_connection_ = bv.showInsetDialog.connect( - boost::bind(&LyXView::showInsetDialog, this, _1, _2, _3)); - update_dialog_connection_ = bv.updateDialog.connect( - boost::bind(&LyXView::updateDialog, this, _1, _2)); - layout_changed_connection_ = bv.layoutChanged.connect( - boost::bind(&Toolbars::setLayout, toolbars_.get(), _1)); -} - - -void LyXView::disconnectBufferView() -{ - show_dialog_connection_.disconnect(); - show_dialog_with_data_connection_.disconnect(); - show_inset_dialog_connection_.disconnect(); - update_dialog_connection_.disconnect(); -} - - -void LyXView::showErrorList(string const & error_type) -{ - ErrorList & el = buffer()->errorList(error_type); - if (!el.empty()) { - getDialogs().show("errorlist", error_type); - } -} - - -void LyXView::showDialog(string const & name) -{ - getDialogs().show(name); -} - - -void LyXView::showDialogWithData(string const & name, string const & data) -{ - getDialogs().show(name, data); -} - - -void LyXView::showInsetDialog(string const & name, string const & data, - InsetBase * inset) -{ - getDialogs().show(name, data, inset); -} - - -void LyXView::updateDialog(string const & name, string const & data) -{ - if (getDialogs().visible(name)) - getDialogs().update(name, data); -} - - -void LyXView::showReadonly(bool) -{ - updateWindowTitle(); - getDialogs().updateBufferDependent(false); -} - - -BufferView * LyXView::view() const -{ - BOOST_ASSERT(work_area_); - return &work_area_->bufferView(); -} - - -void LyXView::updateToc() -{ - updateDialog("toc", ""); -} - - -void LyXView::updateToolbars() -{ - BOOST_ASSERT(work_area_); - bool const math = - work_area_->bufferView().cursor().inMathed(); - bool const table = - lyx::getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled(); - bool const review = - lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).enabled() && - lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).onoff(true); - - toolbars_->update(math, table, review); - // update redaonly status of open dialogs. This could also be in - // updateMenubar(), but since updateToolbars() and updateMenubar() - // are always called together it is only here. - getDialogs().checkStatus(); -} - - -ToolbarInfo::Flags LyXView::getToolbarState(string const & name) -{ - return toolbars_->getToolbarState(name); -} - - -void LyXView::toggleToolbarState(string const & name) -{ - // it is possible to get current toolbar status like this,... - // but I decide to obey the order of ToolbarBackend::flags - // and disregard real toolbar status. - // toolbars_->saveToolbarInfo(); - // - // toggle state on/off/auto - toolbars_->toggleToolbarState(name); - // update toolbar - updateToolbars(); -} - - -void LyXView::updateMenubar() -{ - menubar_->update(); -} - - -void LyXView::autoSave() -{ - LYXERR(Debug::INFO) << "Running autoSave()" << endl; - - if (view()->buffer()) - lyx::autoSave(view()); -} - - -void LyXView::resetAutosaveTimer() -{ - if (lyxrc.autosave) - autosave_timeout_->restart(); -} - - -void LyXView::updateLayoutChoice() -{ - // Don't show any layouts without a buffer - if (!view()->buffer()) { - toolbars_->clearLayoutList(); - return; - } - - // Update the layout display - if (toolbars_->updateLayoutList(buffer()->params().textclass)) { - current_layout = buffer()->params().getLyXTextClass().defaultLayoutName(); - } - - BOOST_ASSERT(work_area_); - if (work_area_->bufferView().cursor().inMathed()) - return; - - string const & layout = - work_area_->bufferView().cursor().paragraph().layout()->name(); - - if (layout != current_layout) { - toolbars_->setLayout(layout); - current_layout = layout; - } -} - - -void LyXView::updateWindowTitle() -{ - docstring maximize_title = lyx::from_ascii("LyX"); - docstring minimize_title = lyx::from_ascii("LyX"); - - if (view()->buffer()) { - string const cur_title = buffer()->fileName(); - if (!cur_title.empty()) { - maximize_title += ": " + makeDisplayPath(cur_title, 30); - minimize_title = lyx::from_utf8(onlyFilename(cur_title)); - if (!buffer()->isClean()) { - maximize_title += _(" (changed)"); - minimize_title += lyx::char_type('*'); - } - if (buffer()->isReadonly()) - maximize_title += _(" (read only)"); - } - } - - setWindowTitle(maximize_title, minimize_title); - updateTab(); -} - - -void LyXView::dispatch(FuncRequest const & cmd) -{ - theLyXFunc().setLyXView(this); - lyx::dispatch(cmd); -} - - -Buffer const * const LyXView::updateInset(InsetBase const * inset) const -{ - Buffer const * buffer_ptr = 0; - if (inset) { - BOOST_ASSERT(work_area_); - work_area_->scheduleRedraw(); - - buffer_ptr = work_area_->bufferView().buffer(); - } - return buffer_ptr; -} - - -} // namespace lyx diff --git a/src/frontends/LyXView.cpp b/src/frontends/LyXView.cpp new file mode 100644 index 0000000000..6d6c9fcb30 --- /dev/null +++ b/src/frontends/LyXView.cpp @@ -0,0 +1,458 @@ +/** + * \file LyXView.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Lars Gullik Bjønnes + * \author John Levon + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "LyXView.h" +#include "Dialogs.h" +#include "Timeout.h" +#include "Toolbars.h" +#include "Menubar.h" +#include "WorkArea.h" +#include "Gui.h" + +#include "buffer.h" +#include "bufferparams.h" +#include "BufferView.h" +#include "bufferview_funcs.h" +#include "cursor.h" +#include "debug.h" +#include "errorlist.h" +#include "funcrequest.h" +#include "gettext.h" +#include "intl.h" +#include "lyx_cb.h" +#include "lyxfunc.h" +#include "lyxrc.h" +#include "lyxtext.h" +#include "MenuBackend.h" +#include "paragraph.h" + +#include "controllers/ControlCommandBuffer.h" + +#include "support/lstrings.h" +#include "support/filetools.h" // OnlyFilename() + +#include + + +namespace lyx { + +#ifdef HAVE_SYS_TIME_H +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif + +using frontend::WorkArea; + +using support::bformat; +using support::FileName; +using support::makeDisplayPath; +using support::onlyFilename; + +using std::endl; +using std::string; + +using lyx::frontend::ControlCommandBuffer; + +string current_layout; + + +LyXView::LyXView(int id) + : work_area_(0), + toolbars_(new Toolbars(*this)), + autosave_timeout_(new Timeout(5000)), + dialogs_(new Dialogs(*this)), + controlcommand_(new ControlCommandBuffer(*this)), id_(id) +{ + // Start autosave timer + if (lyxrc.autosave) { + autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this)); + autosave_timeout_->setTimeout(lyxrc.autosave * 1000); + autosave_timeout_->start(); + } +} + + +LyXView::~LyXView() +{ + disconnectBuffer(); +} + + +// FIXME, there's only one WorkArea per LyXView possible for now. +void LyXView::setWorkArea(WorkArea * work_area) +{ + BOOST_ASSERT(work_area); + work_area_ = work_area; + work_area_ids_.clear(); + work_area_ids_.push_back(work_area_->id()); +} + + +// FIXME, there's only one WorkArea per LyXView possible for now. +WorkArea const * LyXView::currentWorkArea() const +{ + return work_area_; +} + + +// FIXME, there's only one WorkArea per LyXView possible for now. +WorkArea * LyXView::currentWorkArea() +{ + return work_area_; +} + + +Buffer * LyXView::buffer() const +{ + BOOST_ASSERT(work_area_); + return work_area_->bufferView().buffer(); +} + + +void LyXView::setBuffer(Buffer * b) +{ + busy(true); + + BOOST_ASSERT(work_area_); + if (work_area_->bufferView().buffer()) + disconnectBuffer(); + + if (!b) + getDialogs().hideBufferDependent(); + + work_area_->bufferView().setBuffer(b); + // Make sure the TOC is updated before anything else. + updateToc(); + + if (work_area_->bufferView().buffer()) { + // Buffer-dependent dialogs should be updated or + // hidden. This should go here because some dialogs (eg ToC) + // require bv_->text. + getDialogs().updateBufferDependent(true); + connectBuffer(*work_area_->bufferView().buffer()); + } + + if (quitting) + return; + + updateMenubar(); + updateToolbars(); + updateLayoutChoice(); + updateWindowTitle(); + updateStatusBar(); + updateTab(); + busy(false); + work_area_->redraw(); +} + + +bool LyXView::loadLyXFile(FileName const & filename, bool tolastfiles) +{ + busy(true); + + BOOST_ASSERT(work_area_); + if (work_area_->bufferView().buffer()) + disconnectBuffer(); + + bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles); + + updateToc(); + updateMenubar(); + updateToolbars(); + updateLayoutChoice(); + updateWindowTitle(); + updateTab(); + if (loaded) { + connectBuffer(*work_area_->bufferView().buffer()); + showErrorList("Parse"); + } + updateStatusBar(); + busy(false); + work_area_->redraw(); + return loaded; +} + + +void LyXView::connectBuffer(Buffer & buf) +{ + if (errorsConnection_.connected()) + disconnectBuffer(); + + BOOST_ASSERT(work_area_); + bufferChangedConnection_ = + buf.changed.connect( + boost::bind(&WorkArea::redraw, work_area_)); + + bufferStructureChangedConnection_ = + buf.structureChanged.connect( + boost::bind(&LyXView::updateToc, this)); + + errorsConnection_ = + buf.errors.connect( + boost::bind(&LyXView::showErrorList, this, _1)); + + messageConnection_ = + buf.message.connect( + boost::bind(&LyXView::message, this, _1)); + + busyConnection_ = + buf.busy.connect( + boost::bind(&LyXView::busy, this, _1)); + + titleConnection_ = + buf.updateTitles.connect( + boost::bind(&LyXView::updateWindowTitle, this)); + + timerConnection_ = + buf.resetAutosaveTimers.connect( + boost::bind(&LyXView::resetAutosaveTimer, this)); + + readonlyConnection_ = + buf.readonly.connect( + boost::bind(&LyXView::showReadonly, this, _1)); + + closingConnection_ = + buf.closing.connect( + boost::bind(&LyXView::setBuffer, this, (Buffer *)0)); +} + + +void LyXView::disconnectBuffer() +{ + errorsConnection_.disconnect(); + bufferChangedConnection_.disconnect(); + bufferStructureChangedConnection_.disconnect(); + messageConnection_.disconnect(); + busyConnection_.disconnect(); + titleConnection_.disconnect(); + timerConnection_.disconnect(); + readonlyConnection_.disconnect(); + closingConnection_.disconnect(); + layout_changed_connection_.disconnect(); +} + + +void LyXView::connectBufferView(BufferView & bv) +{ + show_dialog_connection_ = bv.showDialog.connect( + boost::bind(&LyXView::showDialog, this, _1)); + show_dialog_with_data_connection_ = bv.showDialogWithData.connect( + boost::bind(&LyXView::showDialogWithData, this, _1, _2)); + show_inset_dialog_connection_ = bv.showInsetDialog.connect( + boost::bind(&LyXView::showInsetDialog, this, _1, _2, _3)); + update_dialog_connection_ = bv.updateDialog.connect( + boost::bind(&LyXView::updateDialog, this, _1, _2)); + layout_changed_connection_ = bv.layoutChanged.connect( + boost::bind(&Toolbars::setLayout, toolbars_.get(), _1)); +} + + +void LyXView::disconnectBufferView() +{ + show_dialog_connection_.disconnect(); + show_dialog_with_data_connection_.disconnect(); + show_inset_dialog_connection_.disconnect(); + update_dialog_connection_.disconnect(); +} + + +void LyXView::showErrorList(string const & error_type) +{ + ErrorList & el = buffer()->errorList(error_type); + if (!el.empty()) { + getDialogs().show("errorlist", error_type); + } +} + + +void LyXView::showDialog(string const & name) +{ + getDialogs().show(name); +} + + +void LyXView::showDialogWithData(string const & name, string const & data) +{ + getDialogs().show(name, data); +} + + +void LyXView::showInsetDialog(string const & name, string const & data, + InsetBase * inset) +{ + getDialogs().show(name, data, inset); +} + + +void LyXView::updateDialog(string const & name, string const & data) +{ + if (getDialogs().visible(name)) + getDialogs().update(name, data); +} + + +void LyXView::showReadonly(bool) +{ + updateWindowTitle(); + getDialogs().updateBufferDependent(false); +} + + +BufferView * LyXView::view() const +{ + BOOST_ASSERT(work_area_); + return &work_area_->bufferView(); +} + + +void LyXView::updateToc() +{ + updateDialog("toc", ""); +} + + +void LyXView::updateToolbars() +{ + BOOST_ASSERT(work_area_); + bool const math = + work_area_->bufferView().cursor().inMathed(); + bool const table = + lyx::getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled(); + bool const review = + lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).enabled() && + lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).onoff(true); + + toolbars_->update(math, table, review); + // update redaonly status of open dialogs. This could also be in + // updateMenubar(), but since updateToolbars() and updateMenubar() + // are always called together it is only here. + getDialogs().checkStatus(); +} + + +ToolbarInfo::Flags LyXView::getToolbarState(string const & name) +{ + return toolbars_->getToolbarState(name); +} + + +void LyXView::toggleToolbarState(string const & name) +{ + // it is possible to get current toolbar status like this,... + // but I decide to obey the order of ToolbarBackend::flags + // and disregard real toolbar status. + // toolbars_->saveToolbarInfo(); + // + // toggle state on/off/auto + toolbars_->toggleToolbarState(name); + // update toolbar + updateToolbars(); +} + + +void LyXView::updateMenubar() +{ + menubar_->update(); +} + + +void LyXView::autoSave() +{ + LYXERR(Debug::INFO) << "Running autoSave()" << endl; + + if (view()->buffer()) + lyx::autoSave(view()); +} + + +void LyXView::resetAutosaveTimer() +{ + if (lyxrc.autosave) + autosave_timeout_->restart(); +} + + +void LyXView::updateLayoutChoice() +{ + // Don't show any layouts without a buffer + if (!view()->buffer()) { + toolbars_->clearLayoutList(); + return; + } + + // Update the layout display + if (toolbars_->updateLayoutList(buffer()->params().textclass)) { + current_layout = buffer()->params().getLyXTextClass().defaultLayoutName(); + } + + BOOST_ASSERT(work_area_); + if (work_area_->bufferView().cursor().inMathed()) + return; + + string const & layout = + work_area_->bufferView().cursor().paragraph().layout()->name(); + + if (layout != current_layout) { + toolbars_->setLayout(layout); + current_layout = layout; + } +} + + +void LyXView::updateWindowTitle() +{ + docstring maximize_title = lyx::from_ascii("LyX"); + docstring minimize_title = lyx::from_ascii("LyX"); + + if (view()->buffer()) { + string const cur_title = buffer()->fileName(); + if (!cur_title.empty()) { + maximize_title += ": " + makeDisplayPath(cur_title, 30); + minimize_title = lyx::from_utf8(onlyFilename(cur_title)); + if (!buffer()->isClean()) { + maximize_title += _(" (changed)"); + minimize_title += lyx::char_type('*'); + } + if (buffer()->isReadonly()) + maximize_title += _(" (read only)"); + } + } + + setWindowTitle(maximize_title, minimize_title); + updateTab(); +} + + +void LyXView::dispatch(FuncRequest const & cmd) +{ + theLyXFunc().setLyXView(this); + lyx::dispatch(cmd); +} + + +Buffer const * const LyXView::updateInset(InsetBase const * inset) const +{ + Buffer const * buffer_ptr = 0; + if (inset) { + BOOST_ASSERT(work_area_); + work_area_->scheduleRedraw(); + + buffer_ptr = work_area_->bufferView().buffer(); + } + return buffer_ptr; +} + + +} // namespace lyx diff --git a/src/frontends/Painter.C b/src/frontends/Painter.C deleted file mode 100644 index 2cba549793..0000000000 --- a/src/frontends/Painter.C +++ /dev/null @@ -1,149 +0,0 @@ -/** - * \file Painter.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author unknown - * \author John Levon - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "frontends/Painter.h" - -#include "frontends/FontMetrics.h" - -#include "LColor.h" -#include "lyxfont.h" - -using lyx::docstring; - -using std::max; -using std::string; - -namespace lyx { -namespace frontend { - -void Painter::button(int x, int y, int w, int h, bool mouseHover) -{ - if (mouseHover) - fillRectangle(x, y, w, h, LColor::buttonhoverbg); - else - fillRectangle(x, y, w, h, LColor::buttonbg); - buttonFrame(x, y, w, h); -} - - -void Painter::buttonFrame(int x, int y, int w, int h) -{ - line(x, y, x, y + h - 1, LColor::buttonframe); - line(x - 1 + w, y, x - 1 + w, y + h - 1, LColor::buttonframe); - line(x, y - 1, x - 1 + w, y - 1, LColor::buttonframe); - line(x, y + h - 1, x - 1 + w, y + h - 1, LColor::buttonframe); -} - - -void Painter::rectText(int x, int y, - docstring const & str, - LyXFont const & font, - LColor_color back, - LColor_color frame) -{ - int width; - int ascent; - int descent; - - FontMetrics const & fm = theFontMetrics(font); - fm.rectText(str, width, ascent, descent); - - if (back != LColor::none) - fillRectangle(x + 1, y - ascent + 1, width - 1, - ascent + descent - 1, back); - - if (frame != LColor::none) - rectangle(x, y - ascent, width, ascent + descent, frame); - - text(x + 3, y, str, font); -} - - -void Painter::buttonText(int x, int y, docstring const & str, - LyXFont const & font, bool mouseHover) -{ - int width; - int ascent; - int descent; - - FontMetrics const & fm = theFontMetrics(font); - fm.buttonText(str, width, ascent, descent); - - button(x, y - ascent, width, descent + ascent, mouseHover); - text(x + 3, y - 1, str, font); -} - - -int Painter::preeditText(int x, int y, char_type c, - LyXFont const & font, preedit_style style) -{ - LyXFont temp_font = font; - FontMetrics const & fm = theFontMetrics(font); - int ascent = fm.maxAscent(); - int descent = fm.maxDescent(); - int height = ascent + descent; - int width = fm.width(c); - - switch (style) { - case preedit_default: - // default unselecting mode. - fillRectangle(x, y - height + 1, width, height, LColor::background); - dashedUnderline(font, x, y - descent + 1, width); - break; - case preedit_selecting: - // We are in selecting mode: white text on black background. - fillRectangle(x, y - height + 1, width, height, LColor::black); - temp_font.setColor(LColor::white); - break; - case preedit_cursor: - // The character comes with a cursor. - fillRectangle(x, y - height + 1, width, height, LColor::background); - underline(font, x, y - descent + 1, width); - break; - } - text(x, y - descent + 1, c, temp_font); - - return width; -} - - -void Painter::underline(LyXFont const & f, int x, int y, int width) -{ - FontMetrics const & fm = theFontMetrics(f); - - int const below = max(fm.maxDescent() / 2, 2); - int const height = max((fm.maxDescent() / 4) - 1, 1); - - if (height < 2) - line(x, y + below, x + width, y + below, f.color()); - else - fillRectangle(x, y + below, width, below + height, f.color()); -} - - -void Painter::dashedUnderline(LyXFont const & f, int x, int y, int width) -{ - FontMetrics const & fm = theFontMetrics(f); - - int const below = max(fm.maxDescent() / 2, 2); - int height = max((fm.maxDescent() / 4) - 1, 1); - - if (height >= 2) - height += below; - - for (int n = 0; n < height; ++n) - line(x, y + below + n, x + width, y + below + n, f.color(), line_onoffdash); -} - -} // namespace frontend -} // namespace lyx diff --git a/src/frontends/Painter.cpp b/src/frontends/Painter.cpp new file mode 100644 index 0000000000..2cba549793 --- /dev/null +++ b/src/frontends/Painter.cpp @@ -0,0 +1,149 @@ +/** + * \file Painter.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author unknown + * \author John Levon + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "frontends/Painter.h" + +#include "frontends/FontMetrics.h" + +#include "LColor.h" +#include "lyxfont.h" + +using lyx::docstring; + +using std::max; +using std::string; + +namespace lyx { +namespace frontend { + +void Painter::button(int x, int y, int w, int h, bool mouseHover) +{ + if (mouseHover) + fillRectangle(x, y, w, h, LColor::buttonhoverbg); + else + fillRectangle(x, y, w, h, LColor::buttonbg); + buttonFrame(x, y, w, h); +} + + +void Painter::buttonFrame(int x, int y, int w, int h) +{ + line(x, y, x, y + h - 1, LColor::buttonframe); + line(x - 1 + w, y, x - 1 + w, y + h - 1, LColor::buttonframe); + line(x, y - 1, x - 1 + w, y - 1, LColor::buttonframe); + line(x, y + h - 1, x - 1 + w, y + h - 1, LColor::buttonframe); +} + + +void Painter::rectText(int x, int y, + docstring const & str, + LyXFont const & font, + LColor_color back, + LColor_color frame) +{ + int width; + int ascent; + int descent; + + FontMetrics const & fm = theFontMetrics(font); + fm.rectText(str, width, ascent, descent); + + if (back != LColor::none) + fillRectangle(x + 1, y - ascent + 1, width - 1, + ascent + descent - 1, back); + + if (frame != LColor::none) + rectangle(x, y - ascent, width, ascent + descent, frame); + + text(x + 3, y, str, font); +} + + +void Painter::buttonText(int x, int y, docstring const & str, + LyXFont const & font, bool mouseHover) +{ + int width; + int ascent; + int descent; + + FontMetrics const & fm = theFontMetrics(font); + fm.buttonText(str, width, ascent, descent); + + button(x, y - ascent, width, descent + ascent, mouseHover); + text(x + 3, y - 1, str, font); +} + + +int Painter::preeditText(int x, int y, char_type c, + LyXFont const & font, preedit_style style) +{ + LyXFont temp_font = font; + FontMetrics const & fm = theFontMetrics(font); + int ascent = fm.maxAscent(); + int descent = fm.maxDescent(); + int height = ascent + descent; + int width = fm.width(c); + + switch (style) { + case preedit_default: + // default unselecting mode. + fillRectangle(x, y - height + 1, width, height, LColor::background); + dashedUnderline(font, x, y - descent + 1, width); + break; + case preedit_selecting: + // We are in selecting mode: white text on black background. + fillRectangle(x, y - height + 1, width, height, LColor::black); + temp_font.setColor(LColor::white); + break; + case preedit_cursor: + // The character comes with a cursor. + fillRectangle(x, y - height + 1, width, height, LColor::background); + underline(font, x, y - descent + 1, width); + break; + } + text(x, y - descent + 1, c, temp_font); + + return width; +} + + +void Painter::underline(LyXFont const & f, int x, int y, int width) +{ + FontMetrics const & fm = theFontMetrics(f); + + int const below = max(fm.maxDescent() / 2, 2); + int const height = max((fm.maxDescent() / 4) - 1, 1); + + if (height < 2) + line(x, y + below, x + width, y + below, f.color()); + else + fillRectangle(x, y + below, width, below + height, f.color()); +} + + +void Painter::dashedUnderline(LyXFont const & f, int x, int y, int width) +{ + FontMetrics const & fm = theFontMetrics(f); + + int const below = max(fm.maxDescent() / 2, 2); + int height = max((fm.maxDescent() / 4) - 1, 1); + + if (height >= 2) + height += below; + + for (int n = 0; n < height; ++n) + line(x, y + below + n, x + width, y + below + n, f.color(), line_onoffdash); +} + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/Timeout.C b/src/frontends/Timeout.C deleted file mode 100644 index 7ef659b3d9..0000000000 --- a/src/frontends/Timeout.C +++ /dev/null @@ -1,77 +0,0 @@ -/** - * \file Timeout.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Lars Gullik Bjønnes - * \author John Levon - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "Timeout.h" - - -namespace lyx { - - -Timeout::~Timeout() -{ - pimpl_->stop(); -} - - -bool Timeout::running() const -{ - return pimpl_->running(); -} - - -void Timeout::start() -{ - pimpl_->start(); -} - - -void Timeout::stop() -{ - pimpl_->stop(); -} - - -void Timeout::restart() -{ - pimpl_->stop(); - pimpl_->start(); -} - - -void Timeout::emit() -{ - pimpl_->reset(); - timeout(); - if (type == CONTINUOUS) - pimpl_->start(); -} - - -Timeout & Timeout::setType(Type t) -{ - type = t; - return * this; -} - - -Timeout & Timeout::setTimeout(unsigned int msec) -{ - // Can't have a timeout of zero! - BOOST_ASSERT(msec); - - timeout_ms = msec; - return * this; -} - - -} // namespace lyx diff --git a/src/frontends/Timeout.cpp b/src/frontends/Timeout.cpp new file mode 100644 index 0000000000..7ef659b3d9 --- /dev/null +++ b/src/frontends/Timeout.cpp @@ -0,0 +1,77 @@ +/** + * \file Timeout.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Lars Gullik Bjønnes + * \author John Levon + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "Timeout.h" + + +namespace lyx { + + +Timeout::~Timeout() +{ + pimpl_->stop(); +} + + +bool Timeout::running() const +{ + return pimpl_->running(); +} + + +void Timeout::start() +{ + pimpl_->start(); +} + + +void Timeout::stop() +{ + pimpl_->stop(); +} + + +void Timeout::restart() +{ + pimpl_->stop(); + pimpl_->start(); +} + + +void Timeout::emit() +{ + pimpl_->reset(); + timeout(); + if (type == CONTINUOUS) + pimpl_->start(); +} + + +Timeout & Timeout::setType(Type t) +{ + type = t; + return * this; +} + + +Timeout & Timeout::setTimeout(unsigned int msec) +{ + // Can't have a timeout of zero! + BOOST_ASSERT(msec); + + timeout_ms = msec; + return * this; +} + + +} // namespace lyx diff --git a/src/frontends/Toolbars.C b/src/frontends/Toolbars.C deleted file mode 100644 index fcf7e565c9..0000000000 --- a/src/frontends/Toolbars.C +++ /dev/null @@ -1,383 +0,0 @@ -/** - * \file Toolbars.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Lars Gullik Bjønnes - * \author Angus Leeming - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "Toolbars.h" - -#include "buffer.h" -#include "bufferparams.h" -#include "debug.h" -#include "funcrequest.h" -#include "FuncStatus.h" -#include "gettext.h" -#include "lyxfunc.h" -#include "lyxtextclass.h" -#include "LyXView.h" -#include "lyx_main.h" - - -namespace lyx { - -using std::endl; -using std::string; - - -Toolbars::Toolbars(LyXView & owner) - : owner_(owner), - layout_(0), - last_textclass_(-1) -{} - -#define TurnOnFlag(x) flags |= ToolbarInfo::x -#define TurnOffFlag(x) flags &= ~ToolbarInfo::x - -void Toolbars::initFlags(ToolbarInfo & tbinfo) -{ - ToolbarSection::ToolbarInfo & info = LyX::ref().session().toolbars().load(tbinfo.name); - - unsigned int flags = static_cast(tbinfo.flags); - - // Remove default.ui positions. Only when a valid postion is stored - // in the session file the default.ui value will be overwritten - unsigned int save = flags; - TurnOffFlag(TOP); - TurnOffFlag(BOTTOM); - TurnOffFlag(RIGHT); - TurnOffFlag(LEFT); - - bool valid_location = true; - // init tbinfo.flags with saved location - if (info.location == ToolbarSection::ToolbarInfo::TOP) - TurnOnFlag(TOP); - else if (info.location == ToolbarSection::ToolbarInfo::BOTTOM) - TurnOnFlag(BOTTOM); - else if (info.location == ToolbarSection::ToolbarInfo::RIGHT) - TurnOnFlag(RIGHT); - else if (info.location == ToolbarSection::ToolbarInfo::LEFT) - TurnOnFlag(LEFT); - else { - // use setting from default.ui - flags = save; - valid_location = false; - } - - // invalid location is for a new toolbar that has no saved information, - // so info.visible is not used for this case. - if (valid_location) { - // init tbinfo.flags with saved visibility, - TurnOffFlag(ON); - TurnOffFlag(OFF); - TurnOffFlag(AUTO); - if (info.state == ToolbarSection::ToolbarInfo::ON) - TurnOnFlag(ON); - else if (info.state == ToolbarSection::ToolbarInfo::OFF) - TurnOnFlag(OFF); - else - TurnOnFlag(AUTO); - } - /* - std::cout << "State " << info.state << " FLAGS: " << flags - << " ON:" << (flags & ToolbarBackend::ON) - << " OFF:" << (flags & ToolbarBackend::OFF) - << " L:" << (flags & ToolbarBackend::LEFT) - << " R:" << (flags & ToolbarBackend::RIGHT) - << " T:" << (flags & ToolbarBackend::TOP) - << " B:" << (flags & ToolbarBackend::BOTTOM) - << " MA:" << (flags & ToolbarBackend::MATH) - << " RE:" << (flags & ToolbarBackend::REVIEW) - << " TB:" << (flags & ToolbarBackend::TABLE) - << " AU:" << (flags & ToolbarBackend::AUTO) - << std::endl; - */ - // now set the flags - tbinfo.flags = static_cast(flags); -} - - -void Toolbars::init() -{ - // extracts the toolbars from the backend - ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin(); - ToolbarBackend::Toolbars::iterator end = toolbarbackend.end(); - - // init flags will also add these toolbars to session if they - // are not already there (e.g. first run of lyx). - for (; cit != end; ++cit) - initFlags(*cit); - - // add toolbars according the order in session - ToolbarSection::ToolbarList::const_iterator tb = LyX::ref().session().toolbars().begin(); - ToolbarSection::ToolbarList::const_iterator te = LyX::ref().session().toolbars().end(); - ToolbarSection::ToolbarInfo::Location last_loc = ToolbarSection::ToolbarInfo::NOTSET; - int last_posx = 0; - int last_posy = 0; - for (; tb != te; ++tb) { - LYXERR(Debug::INIT) << "Adding " << tb->get<0>() << " at position " << tb->get<1>().posx << " " << tb->get<1>().posy << endl; - // add toolbar break if posx or posy changes - bool newline = tb->get<1>().location == last_loc && ( - // if two toolbars at the same location, assume uninitialized and add toolbar break - (tb->get<1>().posx == last_posx && tb->get<1>().posy == last_posy) || - (last_loc == ToolbarSection::ToolbarInfo::TOP && tb->get<1>().posy != last_posy) || - (last_loc == ToolbarSection::ToolbarInfo::BOTTOM && tb->get<1>().posy != last_posy) || - (last_loc == ToolbarSection::ToolbarInfo::LEFT && tb->get<1>().posx != last_posx) || - (last_loc == ToolbarSection::ToolbarInfo::RIGHT && tb->get<1>().posx != last_posx) ); - // find the backend item and add - for (cit = toolbarbackend.begin(); cit != end; ++cit) - if (cit->name == tb->get<0>()) { - add(*cit, newline); - last_loc = tb->get<1>().location; - last_posx = tb->get<1>().posx; - last_posy = tb->get<1>().posy; - break; - } - } -} - - -void Toolbars::display(string const & name, bool show) -{ - ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin(); - ToolbarBackend::Toolbars::iterator end = toolbarbackend.end(); - - for (; cit != end; ++cit) { - if (cit->name == name) { - unsigned int flags = cit->flags; - TurnOffFlag(AUTO); - if (show) { - TurnOnFlag(ON); - TurnOnFlag(OFF); - } else { - TurnOnFlag(OFF); - TurnOnFlag(ON); - } - cit->flags = static_cast(flags); - displayToolbar(*cit, show); - return; - } - } - - LYXERR(Debug::GUI) << "Toolbar::display: no toolbar named " - << name << endl; -} - - -ToolbarInfo::Flags Toolbars::getToolbarState(string const & name) -{ - ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin(); - ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end(); - - for (; cit != end; ++cit) { - if (cit->name == name) - return cit->flags; - } - - LYXERR(Debug::GUI) << "Toolbar::display: no toolbar named " - << name << endl; - - // return dummy for msvc - return ToolbarInfo::OFF; -} - - -void Toolbars::toggleToolbarState(string const & name) -{ - ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin(); - ToolbarBackend::Toolbars::iterator end = toolbarbackend.end(); - - for (; cit != end; ++cit) { - if (cit->name == name) { - int flags = cit->flags; - // off -> on - if (flags & ToolbarInfo::OFF) { - TurnOffFlag(OFF); - TurnOnFlag(ON); - // auto -> off - } else if (flags & ToolbarInfo::AUTO) { - TurnOffFlag(AUTO); - TurnOnFlag(OFF); - } else if ((flags & ToolbarInfo::MATH) || (flags & ToolbarInfo::TABLE) - || (flags & ToolbarInfo::REVIEW)) { - // for math etc, toggle from on -> auto - TurnOffFlag(ON); - TurnOnFlag(AUTO); - } else { - // for others, toggle from on -> off - TurnOffFlag(ON); - TurnOnFlag(OFF); - } - cit->flags = static_cast(flags); - return; - } - } - LYXERR(Debug::GUI) << "Toolbar::display: no toolbar named " - << name << endl; -} -#undef TurnOnFlag -#undef TurnOffFlag - - -void Toolbars::update(bool in_math, bool in_table, bool review) -{ - update(); - - // extracts the toolbars from the backend - ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin(); - ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end(); - - for (; cit != end; ++cit) { - if (cit->flags & ToolbarInfo::ON) - displayToolbar(*cit, true); - else if (cit->flags & ToolbarInfo::OFF) - displayToolbar(*cit, false); - else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::MATH)) - displayToolbar(*cit, in_math); - else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::TABLE)) - displayToolbar(*cit, in_table); - else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::REVIEW)) - displayToolbar(*cit, review); - } -} - - -void Toolbars::saveToolbarInfo() -{ - ToolbarSection & tb = LyX::ref().session().toolbars(); - - for (ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin(); - cit != toolbarbackend.end(); ++cit) { - ToolbarsMap::iterator it = toolbars_.find(cit->name); - BOOST_ASSERT(it != toolbars_.end()); - // get toolbar info from session. - ToolbarSection::ToolbarInfo & info = tb.load(cit->name); - if (cit->flags & ToolbarInfo::ON) - info.state = ToolbarSection::ToolbarInfo::ON; - else if (cit->flags & ToolbarInfo::OFF) - info.state = ToolbarSection::ToolbarInfo::OFF; - else if (cit->flags & ToolbarInfo::AUTO) - info.state = ToolbarSection::ToolbarInfo::AUTO; - // save other information - // if auto, frontend should *not* set on/off - it->second->saveInfo(info); - // maybe it is useful to update flags with real status. I do not know - /* - if (!(cit->flags & ToolbarInfo::AUTO)) { - unsigned int flags = static_cast(cit->flags); - flags &= ~(info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarInfo::OFF : ToolbarInfo::ON); - flags |= (info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarInfo::ON : ToolbarInfo::OFF); - if (info.state == ToolbarSection::ToolbarInfo::ON) - cit->flags = static_cast(flags); - } - */ - } -} - - -void Toolbars::setLayout(string const & layout) -{ - if (layout_) - layout_->set(layout); -} - - -bool Toolbars::updateLayoutList(int textclass) -{ - // update the layout display - if (last_textclass_ != textclass) { - if (layout_) - layout_->update(); - last_textclass_ = textclass; - return true; - } else - return false; -} - - -void Toolbars::openLayoutList() -{ - if (layout_) - layout_->open(); -} - - -void Toolbars::clearLayoutList() -{ - last_textclass_ = -1; - if (layout_) - layout_->clear(); -} - - -void Toolbars::add(ToolbarInfo const & tbinfo, bool newline) -{ - ToolbarPtr tb_ptr = owner_.makeToolbar(tbinfo, newline); - toolbars_[tbinfo.name] = tb_ptr; - - if (tbinfo.flags & ToolbarInfo::ON) - tb_ptr->show(false); - else - tb_ptr->hide(false); - - if (tb_ptr->layout()) - layout_ = tb_ptr->layout(); -} - - -void Toolbars::displayToolbar(ToolbarInfo const & tbinfo, - bool show_it) -{ - ToolbarsMap::iterator it = toolbars_.find(tbinfo.name); - BOOST_ASSERT(it != toolbars_.end()); - - if (show_it) - it->second->show(true); - else - it->second->hide(true); -} - - -void Toolbars::update() -{ - ToolbarsMap::const_iterator it = toolbars_.begin(); - ToolbarsMap::const_iterator const end = toolbars_.end(); - for (; it != end; ++it) - it->second->update(); - - bool const enable = - lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled(); - - if (layout_) - layout_->setEnabled(enable); -} - - -void layoutSelected(LyXView & lv, string const & name) -{ - LyXTextClass const & tc = lv.buffer()->params().getLyXTextClass(); - - LyXTextClass::const_iterator it = tc.begin(); - LyXTextClass::const_iterator const end = tc.end(); - for (; it != end; ++it) { - string const & itname = (*it)->name(); - // Yes, the lyx::to_utf8(_()) is correct - if (lyx::to_utf8(_(itname)) == name) { - FuncRequest const func(LFUN_LAYOUT, itname, - FuncRequest::TOOLBAR); - lv.dispatch(func); - return; - } - } - lyxerr << "ERROR (layoutSelected): layout not found!" - << endl; -} - - -} // namespace lyx diff --git a/src/frontends/Toolbars.cpp b/src/frontends/Toolbars.cpp new file mode 100644 index 0000000000..fcf7e565c9 --- /dev/null +++ b/src/frontends/Toolbars.cpp @@ -0,0 +1,383 @@ +/** + * \file Toolbars.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Lars Gullik Bjønnes + * \author Angus Leeming + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "Toolbars.h" + +#include "buffer.h" +#include "bufferparams.h" +#include "debug.h" +#include "funcrequest.h" +#include "FuncStatus.h" +#include "gettext.h" +#include "lyxfunc.h" +#include "lyxtextclass.h" +#include "LyXView.h" +#include "lyx_main.h" + + +namespace lyx { + +using std::endl; +using std::string; + + +Toolbars::Toolbars(LyXView & owner) + : owner_(owner), + layout_(0), + last_textclass_(-1) +{} + +#define TurnOnFlag(x) flags |= ToolbarInfo::x +#define TurnOffFlag(x) flags &= ~ToolbarInfo::x + +void Toolbars::initFlags(ToolbarInfo & tbinfo) +{ + ToolbarSection::ToolbarInfo & info = LyX::ref().session().toolbars().load(tbinfo.name); + + unsigned int flags = static_cast(tbinfo.flags); + + // Remove default.ui positions. Only when a valid postion is stored + // in the session file the default.ui value will be overwritten + unsigned int save = flags; + TurnOffFlag(TOP); + TurnOffFlag(BOTTOM); + TurnOffFlag(RIGHT); + TurnOffFlag(LEFT); + + bool valid_location = true; + // init tbinfo.flags with saved location + if (info.location == ToolbarSection::ToolbarInfo::TOP) + TurnOnFlag(TOP); + else if (info.location == ToolbarSection::ToolbarInfo::BOTTOM) + TurnOnFlag(BOTTOM); + else if (info.location == ToolbarSection::ToolbarInfo::RIGHT) + TurnOnFlag(RIGHT); + else if (info.location == ToolbarSection::ToolbarInfo::LEFT) + TurnOnFlag(LEFT); + else { + // use setting from default.ui + flags = save; + valid_location = false; + } + + // invalid location is for a new toolbar that has no saved information, + // so info.visible is not used for this case. + if (valid_location) { + // init tbinfo.flags with saved visibility, + TurnOffFlag(ON); + TurnOffFlag(OFF); + TurnOffFlag(AUTO); + if (info.state == ToolbarSection::ToolbarInfo::ON) + TurnOnFlag(ON); + else if (info.state == ToolbarSection::ToolbarInfo::OFF) + TurnOnFlag(OFF); + else + TurnOnFlag(AUTO); + } + /* + std::cout << "State " << info.state << " FLAGS: " << flags + << " ON:" << (flags & ToolbarBackend::ON) + << " OFF:" << (flags & ToolbarBackend::OFF) + << " L:" << (flags & ToolbarBackend::LEFT) + << " R:" << (flags & ToolbarBackend::RIGHT) + << " T:" << (flags & ToolbarBackend::TOP) + << " B:" << (flags & ToolbarBackend::BOTTOM) + << " MA:" << (flags & ToolbarBackend::MATH) + << " RE:" << (flags & ToolbarBackend::REVIEW) + << " TB:" << (flags & ToolbarBackend::TABLE) + << " AU:" << (flags & ToolbarBackend::AUTO) + << std::endl; + */ + // now set the flags + tbinfo.flags = static_cast(flags); +} + + +void Toolbars::init() +{ + // extracts the toolbars from the backend + ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin(); + ToolbarBackend::Toolbars::iterator end = toolbarbackend.end(); + + // init flags will also add these toolbars to session if they + // are not already there (e.g. first run of lyx). + for (; cit != end; ++cit) + initFlags(*cit); + + // add toolbars according the order in session + ToolbarSection::ToolbarList::const_iterator tb = LyX::ref().session().toolbars().begin(); + ToolbarSection::ToolbarList::const_iterator te = LyX::ref().session().toolbars().end(); + ToolbarSection::ToolbarInfo::Location last_loc = ToolbarSection::ToolbarInfo::NOTSET; + int last_posx = 0; + int last_posy = 0; + for (; tb != te; ++tb) { + LYXERR(Debug::INIT) << "Adding " << tb->get<0>() << " at position " << tb->get<1>().posx << " " << tb->get<1>().posy << endl; + // add toolbar break if posx or posy changes + bool newline = tb->get<1>().location == last_loc && ( + // if two toolbars at the same location, assume uninitialized and add toolbar break + (tb->get<1>().posx == last_posx && tb->get<1>().posy == last_posy) || + (last_loc == ToolbarSection::ToolbarInfo::TOP && tb->get<1>().posy != last_posy) || + (last_loc == ToolbarSection::ToolbarInfo::BOTTOM && tb->get<1>().posy != last_posy) || + (last_loc == ToolbarSection::ToolbarInfo::LEFT && tb->get<1>().posx != last_posx) || + (last_loc == ToolbarSection::ToolbarInfo::RIGHT && tb->get<1>().posx != last_posx) ); + // find the backend item and add + for (cit = toolbarbackend.begin(); cit != end; ++cit) + if (cit->name == tb->get<0>()) { + add(*cit, newline); + last_loc = tb->get<1>().location; + last_posx = tb->get<1>().posx; + last_posy = tb->get<1>().posy; + break; + } + } +} + + +void Toolbars::display(string const & name, bool show) +{ + ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin(); + ToolbarBackend::Toolbars::iterator end = toolbarbackend.end(); + + for (; cit != end; ++cit) { + if (cit->name == name) { + unsigned int flags = cit->flags; + TurnOffFlag(AUTO); + if (show) { + TurnOnFlag(ON); + TurnOnFlag(OFF); + } else { + TurnOnFlag(OFF); + TurnOnFlag(ON); + } + cit->flags = static_cast(flags); + displayToolbar(*cit, show); + return; + } + } + + LYXERR(Debug::GUI) << "Toolbar::display: no toolbar named " + << name << endl; +} + + +ToolbarInfo::Flags Toolbars::getToolbarState(string const & name) +{ + ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin(); + ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end(); + + for (; cit != end; ++cit) { + if (cit->name == name) + return cit->flags; + } + + LYXERR(Debug::GUI) << "Toolbar::display: no toolbar named " + << name << endl; + + // return dummy for msvc + return ToolbarInfo::OFF; +} + + +void Toolbars::toggleToolbarState(string const & name) +{ + ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin(); + ToolbarBackend::Toolbars::iterator end = toolbarbackend.end(); + + for (; cit != end; ++cit) { + if (cit->name == name) { + int flags = cit->flags; + // off -> on + if (flags & ToolbarInfo::OFF) { + TurnOffFlag(OFF); + TurnOnFlag(ON); + // auto -> off + } else if (flags & ToolbarInfo::AUTO) { + TurnOffFlag(AUTO); + TurnOnFlag(OFF); + } else if ((flags & ToolbarInfo::MATH) || (flags & ToolbarInfo::TABLE) + || (flags & ToolbarInfo::REVIEW)) { + // for math etc, toggle from on -> auto + TurnOffFlag(ON); + TurnOnFlag(AUTO); + } else { + // for others, toggle from on -> off + TurnOffFlag(ON); + TurnOnFlag(OFF); + } + cit->flags = static_cast(flags); + return; + } + } + LYXERR(Debug::GUI) << "Toolbar::display: no toolbar named " + << name << endl; +} +#undef TurnOnFlag +#undef TurnOffFlag + + +void Toolbars::update(bool in_math, bool in_table, bool review) +{ + update(); + + // extracts the toolbars from the backend + ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin(); + ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end(); + + for (; cit != end; ++cit) { + if (cit->flags & ToolbarInfo::ON) + displayToolbar(*cit, true); + else if (cit->flags & ToolbarInfo::OFF) + displayToolbar(*cit, false); + else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::MATH)) + displayToolbar(*cit, in_math); + else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::TABLE)) + displayToolbar(*cit, in_table); + else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::REVIEW)) + displayToolbar(*cit, review); + } +} + + +void Toolbars::saveToolbarInfo() +{ + ToolbarSection & tb = LyX::ref().session().toolbars(); + + for (ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin(); + cit != toolbarbackend.end(); ++cit) { + ToolbarsMap::iterator it = toolbars_.find(cit->name); + BOOST_ASSERT(it != toolbars_.end()); + // get toolbar info from session. + ToolbarSection::ToolbarInfo & info = tb.load(cit->name); + if (cit->flags & ToolbarInfo::ON) + info.state = ToolbarSection::ToolbarInfo::ON; + else if (cit->flags & ToolbarInfo::OFF) + info.state = ToolbarSection::ToolbarInfo::OFF; + else if (cit->flags & ToolbarInfo::AUTO) + info.state = ToolbarSection::ToolbarInfo::AUTO; + // save other information + // if auto, frontend should *not* set on/off + it->second->saveInfo(info); + // maybe it is useful to update flags with real status. I do not know + /* + if (!(cit->flags & ToolbarInfo::AUTO)) { + unsigned int flags = static_cast(cit->flags); + flags &= ~(info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarInfo::OFF : ToolbarInfo::ON); + flags |= (info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarInfo::ON : ToolbarInfo::OFF); + if (info.state == ToolbarSection::ToolbarInfo::ON) + cit->flags = static_cast(flags); + } + */ + } +} + + +void Toolbars::setLayout(string const & layout) +{ + if (layout_) + layout_->set(layout); +} + + +bool Toolbars::updateLayoutList(int textclass) +{ + // update the layout display + if (last_textclass_ != textclass) { + if (layout_) + layout_->update(); + last_textclass_ = textclass; + return true; + } else + return false; +} + + +void Toolbars::openLayoutList() +{ + if (layout_) + layout_->open(); +} + + +void Toolbars::clearLayoutList() +{ + last_textclass_ = -1; + if (layout_) + layout_->clear(); +} + + +void Toolbars::add(ToolbarInfo const & tbinfo, bool newline) +{ + ToolbarPtr tb_ptr = owner_.makeToolbar(tbinfo, newline); + toolbars_[tbinfo.name] = tb_ptr; + + if (tbinfo.flags & ToolbarInfo::ON) + tb_ptr->show(false); + else + tb_ptr->hide(false); + + if (tb_ptr->layout()) + layout_ = tb_ptr->layout(); +} + + +void Toolbars::displayToolbar(ToolbarInfo const & tbinfo, + bool show_it) +{ + ToolbarsMap::iterator it = toolbars_.find(tbinfo.name); + BOOST_ASSERT(it != toolbars_.end()); + + if (show_it) + it->second->show(true); + else + it->second->hide(true); +} + + +void Toolbars::update() +{ + ToolbarsMap::const_iterator it = toolbars_.begin(); + ToolbarsMap::const_iterator const end = toolbars_.end(); + for (; it != end; ++it) + it->second->update(); + + bool const enable = + lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled(); + + if (layout_) + layout_->setEnabled(enable); +} + + +void layoutSelected(LyXView & lv, string const & name) +{ + LyXTextClass const & tc = lv.buffer()->params().getLyXTextClass(); + + LyXTextClass::const_iterator it = tc.begin(); + LyXTextClass::const_iterator const end = tc.end(); + for (; it != end; ++it) { + string const & itname = (*it)->name(); + // Yes, the lyx::to_utf8(_()) is correct + if (lyx::to_utf8(_(itname)) == name) { + FuncRequest const func(LFUN_LAYOUT, itname, + FuncRequest::TOOLBAR); + lv.dispatch(func); + return; + } + } + lyxerr << "ERROR (layoutSelected): layout not found!" + << endl; +} + + +} // namespace lyx diff --git a/src/frontends/WorkArea.C b/src/frontends/WorkArea.C deleted file mode 100644 index d6d2c93a26..0000000000 --- a/src/frontends/WorkArea.C +++ /dev/null @@ -1,354 +0,0 @@ -/** - * \file WorkArea.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author John Levon - * \author Abdelrazak Younes - * - * Full author contact details are available in file CREDITS. - * - * Splash screen code added by Angus Leeming - */ - -#include - -#include "frontends/WorkArea.h" - -#include "frontends/Application.h" -#include "frontends/FontMetrics.h" - -#include "funcrequest.h" -#include "lyxfunc.h" -#include "Painter.h" - -#include "BufferView.h" -#include "buffer.h" -#include "bufferparams.h" -#include "coordcache.h" -#include "cursor.h" -#include "debug.h" -#include "language.h" -#include "LColor.h" -#include "lyxfont.h" -#include "lyxrc.h" -#include "lyxrow.h" -#include "lyxtext.h" -#include "LyXView.h" -#include "metricsinfo.h" -#include "paragraph.h" -#include "rowpainter.h" - -#include "gettext.h" -#include "support/forkedcontr.h" - -#include -#include -#include - -using lyx::support::ForkedcallsController; - -using std::endl; -using std::min; -using std::max; -using std::string; - - -namespace { - -// All the below connection objects are needed because of a bug in some -// versions of GCC (<=2.96 are on the suspects list.) By having and assigning -// to these connections we avoid a segfault upon startup, and also at exit. -// (Lgb) - -boost::signals::connection timecon; - -} // anon namespace - -namespace lyx { -namespace frontend { - -WorkArea::WorkArea(int id, LyXView & lyx_view) - : buffer_view_(0), lyx_view_(lyx_view), greyed_out_(true), - id_(id), cursor_visible_(false), cursor_timeout_(400) -{ - // Start loading the pixmap as soon as possible - //if (lyxrc.show_banner) { - // showBanner(); - //} - - // Setup the signals - timecon = cursor_timeout_.timeout - .connect(boost::bind(&WorkArea::toggleCursor, this)); - - cursor_timeout_.start(); -} - - -void WorkArea::setBufferView(BufferView * buffer_view) -{ - if (buffer_view_) { - message_connection_.disconnect(); - lyx_view_.disconnectBufferView(); - } - - hideCursor(); - buffer_view_ = buffer_view; - toggleCursor(); - - message_connection_ = buffer_view_->message.connect( - boost::bind(&WorkArea::displayMessage, this, _1)); - - lyx_view_.connectBufferView(*buffer_view); -} - - -BufferView & WorkArea::bufferView() -{ - return *buffer_view_; -} - - -BufferView const & WorkArea::bufferView() const -{ - return *buffer_view_; -} - - -void WorkArea::stopBlinkingCursor() -{ - cursor_timeout_.stop(); - hideCursor(); -} - - -void WorkArea::startBlinkingCursor() -{ - showCursor(); - cursor_timeout_.restart(); -} - - -void WorkArea::redraw() -{ - if (!buffer_view_ || !buffer_view_->buffer()) { - greyed_out_ = true; - // The argument here are meaningless. - expose(1,1,1,1); - return; - } - - // No need to do anything if this is the current view. The BufferView - // metrics are already up to date. - if (&lyx_view_ != theApp()->currentView()) - // FIXME: it would be nice to optimize for the off-screen case. - buffer_view_->updateMetrics(false); - - updateScrollbar(); - - ViewMetricsInfo const & vi = buffer_view_->viewMetricsInfo(); - greyed_out_ = false; - - LYXERR(Debug::WORKAREA) << "WorkArea::redraw screen" << endl; - - int const ymin = std::max(vi.y1, 0); - int const ymax = vi.p2 < vi.size - 1 ? vi.y2 : height(); - - expose(0, ymin, width(), ymax - ymin); - - //LYXERR(Debug::WORKAREA) - //<< " ymin = " << ymin << " width() = " << width() -// << " ymax-ymin = " << ymax-ymin << std::endl; - - if (lyxerr.debugging(Debug::WORKAREA)) - buffer_view_->coordCache().dump(); -} - - -void WorkArea::processKeySym(LyXKeySymPtr key, key_modifier::state state) -{ - // In order to avoid bad surprise in the middle of an operation, we better stop - // the blinking cursor. - stopBlinkingCursor(); - - theLyXFunc().setLyXView(&lyx_view_); - theLyXFunc().processKeySym(key, state); - - /* When we move around, or type, it's nice to be able to see - * the cursor immediately after the keypress. - */ - startBlinkingCursor(); -} - - -void WorkArea::dispatch(FuncRequest const & cmd0, key_modifier::state k) -{ - // Handle drag&drop - if (cmd0.action == LFUN_FILE_OPEN) { - lyx_view_.dispatch(cmd0); - return; - } - - theLyXFunc().setLyXView(&lyx_view_); - - FuncRequest cmd; - - if (cmd0.action == LFUN_MOUSE_PRESS) { - if (k == key_modifier::shift) - cmd = FuncRequest(cmd0, "region-select"); - else if (k == key_modifier::ctrl) - cmd = FuncRequest(cmd0, "paragraph-select"); - else - cmd = cmd0; - } - else - cmd = cmd0; - - // In order to avoid bad surprise in the middle of an operation, we better stop - // the blinking cursor. - if (!(cmd.action == LFUN_MOUSE_MOTION - && cmd.button() == mouse_button::none)) - stopBlinkingCursor(); - - bool const needRedraw = buffer_view_->workAreaDispatch(cmd); - - if (needRedraw) - redraw(); - - // Skip these when selecting - if (cmd.action != LFUN_MOUSE_MOTION) { - lyx_view_.updateLayoutChoice(); - lyx_view_.updateMenubar(); - lyx_view_.updateToolbars(); - } - - // GUI tweaks except with mouse motion with no button pressed. - if (!(cmd.action == LFUN_MOUSE_MOTION - && cmd.button() == mouse_button::none)) { - // Slight hack: this is only called currently when we - // clicked somewhere, so we force through the display - // of the new status here. - lyx_view_.clearMessage(); - - // Show the cursor immediately after any operation. - startBlinkingCursor(); - } -} - - -void WorkArea::resizeBufferView() -{ - lyx_view_.busy(true); - lyx_view_.message(_("Formatting document...")); - buffer_view_->workAreaResize(width(), height()); - lyx_view_.updateLayoutChoice(); - lyx_view_.clearMessage(); - lyx_view_.busy(false); -} - - -void WorkArea::updateScrollbar() -{ - buffer_view_->updateScrollbar(); - ScrollbarParameters const & scroll_ = buffer_view_->scrollbarParameters(); - setScrollbarParams(scroll_.height, scroll_.position, - scroll_.lineScrollHeight); -} - - -void WorkArea::scrollBufferView(int position) -{ - stopBlinkingCursor(); - buffer_view_->scrollDocView(position); - redraw(); - if (lyxrc.cursor_follows_scrollbar) { - buffer_view_->setCursorFromScrollbar(); - lyx_view_.updateLayoutChoice(); - } - // Show the cursor immediately after any operation. - startBlinkingCursor(); -} - - -void WorkArea::showCursor() -{ - if (cursor_visible_) - return; - - if (!buffer_view_->buffer()) - return; - - CursorShape shape = BAR_SHAPE; - - LyXText const & text = *buffer_view_->cursor().innerText(); - LyXFont const & realfont = text.real_current_font; - BufferParams const & bp = buffer_view_->buffer()->params(); - bool const samelang = realfont.language() == bp.language; - bool const isrtl = realfont.isVisibleRightToLeft(); - - if (!samelang || isrtl != bp.language->rightToLeft()) { - shape = L_SHAPE; - if (isrtl) - shape = REVERSED_L_SHAPE; - } - - // The ERT language hack needs fixing up - if (realfont.language() == latex_language) - shape = BAR_SHAPE; - - LyXFont const font = buffer_view_->cursor().getFont(); - FontMetrics const & fm = theFontMetrics(font); - int const asc = fm.maxAscent(); - int const des = fm.maxDescent(); - int h = asc + des; - int x = 0; - int y = 0; - buffer_view_->cursor().getPos(x, y); - y -= asc; - - // if it doesn't touch the screen, don't try to show it - if (y + h < 0 || y >= height()) - return; - - cursor_visible_ = true; - showCursor(x, y, h, shape); -} - - -void WorkArea::hideCursor() -{ - if (!cursor_visible_) - return; - - cursor_visible_ = false; - removeCursor(); -} - - -void WorkArea::toggleCursor() -{ - if (buffer_view_->buffer()) { - - if (cursor_visible_) - hideCursor(); - else - showCursor(); - - // Use this opportunity to deal with any child processes that - // have finished but are waiting to communicate this fact - // to the rest of LyX. - ForkedcallsController & fcc = ForkedcallsController::get(); - fcc.handleCompletedProcesses(); - } - - cursor_timeout_.restart(); -} - - -void WorkArea::displayMessage(lyx::docstring const & message) -{ - lyx_view_.message(message); -} - -} // namespace frontend -} // namespace lyx diff --git a/src/frontends/WorkArea.cpp b/src/frontends/WorkArea.cpp new file mode 100644 index 0000000000..d6d2c93a26 --- /dev/null +++ b/src/frontends/WorkArea.cpp @@ -0,0 +1,354 @@ +/** + * \file WorkArea.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Levon + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + * + * Splash screen code added by Angus Leeming + */ + +#include + +#include "frontends/WorkArea.h" + +#include "frontends/Application.h" +#include "frontends/FontMetrics.h" + +#include "funcrequest.h" +#include "lyxfunc.h" +#include "Painter.h" + +#include "BufferView.h" +#include "buffer.h" +#include "bufferparams.h" +#include "coordcache.h" +#include "cursor.h" +#include "debug.h" +#include "language.h" +#include "LColor.h" +#include "lyxfont.h" +#include "lyxrc.h" +#include "lyxrow.h" +#include "lyxtext.h" +#include "LyXView.h" +#include "metricsinfo.h" +#include "paragraph.h" +#include "rowpainter.h" + +#include "gettext.h" +#include "support/forkedcontr.h" + +#include +#include +#include + +using lyx::support::ForkedcallsController; + +using std::endl; +using std::min; +using std::max; +using std::string; + + +namespace { + +// All the below connection objects are needed because of a bug in some +// versions of GCC (<=2.96 are on the suspects list.) By having and assigning +// to these connections we avoid a segfault upon startup, and also at exit. +// (Lgb) + +boost::signals::connection timecon; + +} // anon namespace + +namespace lyx { +namespace frontend { + +WorkArea::WorkArea(int id, LyXView & lyx_view) + : buffer_view_(0), lyx_view_(lyx_view), greyed_out_(true), + id_(id), cursor_visible_(false), cursor_timeout_(400) +{ + // Start loading the pixmap as soon as possible + //if (lyxrc.show_banner) { + // showBanner(); + //} + + // Setup the signals + timecon = cursor_timeout_.timeout + .connect(boost::bind(&WorkArea::toggleCursor, this)); + + cursor_timeout_.start(); +} + + +void WorkArea::setBufferView(BufferView * buffer_view) +{ + if (buffer_view_) { + message_connection_.disconnect(); + lyx_view_.disconnectBufferView(); + } + + hideCursor(); + buffer_view_ = buffer_view; + toggleCursor(); + + message_connection_ = buffer_view_->message.connect( + boost::bind(&WorkArea::displayMessage, this, _1)); + + lyx_view_.connectBufferView(*buffer_view); +} + + +BufferView & WorkArea::bufferView() +{ + return *buffer_view_; +} + + +BufferView const & WorkArea::bufferView() const +{ + return *buffer_view_; +} + + +void WorkArea::stopBlinkingCursor() +{ + cursor_timeout_.stop(); + hideCursor(); +} + + +void WorkArea::startBlinkingCursor() +{ + showCursor(); + cursor_timeout_.restart(); +} + + +void WorkArea::redraw() +{ + if (!buffer_view_ || !buffer_view_->buffer()) { + greyed_out_ = true; + // The argument here are meaningless. + expose(1,1,1,1); + return; + } + + // No need to do anything if this is the current view. The BufferView + // metrics are already up to date. + if (&lyx_view_ != theApp()->currentView()) + // FIXME: it would be nice to optimize for the off-screen case. + buffer_view_->updateMetrics(false); + + updateScrollbar(); + + ViewMetricsInfo const & vi = buffer_view_->viewMetricsInfo(); + greyed_out_ = false; + + LYXERR(Debug::WORKAREA) << "WorkArea::redraw screen" << endl; + + int const ymin = std::max(vi.y1, 0); + int const ymax = vi.p2 < vi.size - 1 ? vi.y2 : height(); + + expose(0, ymin, width(), ymax - ymin); + + //LYXERR(Debug::WORKAREA) + //<< " ymin = " << ymin << " width() = " << width() +// << " ymax-ymin = " << ymax-ymin << std::endl; + + if (lyxerr.debugging(Debug::WORKAREA)) + buffer_view_->coordCache().dump(); +} + + +void WorkArea::processKeySym(LyXKeySymPtr key, key_modifier::state state) +{ + // In order to avoid bad surprise in the middle of an operation, we better stop + // the blinking cursor. + stopBlinkingCursor(); + + theLyXFunc().setLyXView(&lyx_view_); + theLyXFunc().processKeySym(key, state); + + /* When we move around, or type, it's nice to be able to see + * the cursor immediately after the keypress. + */ + startBlinkingCursor(); +} + + +void WorkArea::dispatch(FuncRequest const & cmd0, key_modifier::state k) +{ + // Handle drag&drop + if (cmd0.action == LFUN_FILE_OPEN) { + lyx_view_.dispatch(cmd0); + return; + } + + theLyXFunc().setLyXView(&lyx_view_); + + FuncRequest cmd; + + if (cmd0.action == LFUN_MOUSE_PRESS) { + if (k == key_modifier::shift) + cmd = FuncRequest(cmd0, "region-select"); + else if (k == key_modifier::ctrl) + cmd = FuncRequest(cmd0, "paragraph-select"); + else + cmd = cmd0; + } + else + cmd = cmd0; + + // In order to avoid bad surprise in the middle of an operation, we better stop + // the blinking cursor. + if (!(cmd.action == LFUN_MOUSE_MOTION + && cmd.button() == mouse_button::none)) + stopBlinkingCursor(); + + bool const needRedraw = buffer_view_->workAreaDispatch(cmd); + + if (needRedraw) + redraw(); + + // Skip these when selecting + if (cmd.action != LFUN_MOUSE_MOTION) { + lyx_view_.updateLayoutChoice(); + lyx_view_.updateMenubar(); + lyx_view_.updateToolbars(); + } + + // GUI tweaks except with mouse motion with no button pressed. + if (!(cmd.action == LFUN_MOUSE_MOTION + && cmd.button() == mouse_button::none)) { + // Slight hack: this is only called currently when we + // clicked somewhere, so we force through the display + // of the new status here. + lyx_view_.clearMessage(); + + // Show the cursor immediately after any operation. + startBlinkingCursor(); + } +} + + +void WorkArea::resizeBufferView() +{ + lyx_view_.busy(true); + lyx_view_.message(_("Formatting document...")); + buffer_view_->workAreaResize(width(), height()); + lyx_view_.updateLayoutChoice(); + lyx_view_.clearMessage(); + lyx_view_.busy(false); +} + + +void WorkArea::updateScrollbar() +{ + buffer_view_->updateScrollbar(); + ScrollbarParameters const & scroll_ = buffer_view_->scrollbarParameters(); + setScrollbarParams(scroll_.height, scroll_.position, + scroll_.lineScrollHeight); +} + + +void WorkArea::scrollBufferView(int position) +{ + stopBlinkingCursor(); + buffer_view_->scrollDocView(position); + redraw(); + if (lyxrc.cursor_follows_scrollbar) { + buffer_view_->setCursorFromScrollbar(); + lyx_view_.updateLayoutChoice(); + } + // Show the cursor immediately after any operation. + startBlinkingCursor(); +} + + +void WorkArea::showCursor() +{ + if (cursor_visible_) + return; + + if (!buffer_view_->buffer()) + return; + + CursorShape shape = BAR_SHAPE; + + LyXText const & text = *buffer_view_->cursor().innerText(); + LyXFont const & realfont = text.real_current_font; + BufferParams const & bp = buffer_view_->buffer()->params(); + bool const samelang = realfont.language() == bp.language; + bool const isrtl = realfont.isVisibleRightToLeft(); + + if (!samelang || isrtl != bp.language->rightToLeft()) { + shape = L_SHAPE; + if (isrtl) + shape = REVERSED_L_SHAPE; + } + + // The ERT language hack needs fixing up + if (realfont.language() == latex_language) + shape = BAR_SHAPE; + + LyXFont const font = buffer_view_->cursor().getFont(); + FontMetrics const & fm = theFontMetrics(font); + int const asc = fm.maxAscent(); + int const des = fm.maxDescent(); + int h = asc + des; + int x = 0; + int y = 0; + buffer_view_->cursor().getPos(x, y); + y -= asc; + + // if it doesn't touch the screen, don't try to show it + if (y + h < 0 || y >= height()) + return; + + cursor_visible_ = true; + showCursor(x, y, h, shape); +} + + +void WorkArea::hideCursor() +{ + if (!cursor_visible_) + return; + + cursor_visible_ = false; + removeCursor(); +} + + +void WorkArea::toggleCursor() +{ + if (buffer_view_->buffer()) { + + if (cursor_visible_) + hideCursor(); + else + showCursor(); + + // Use this opportunity to deal with any child processes that + // have finished but are waiting to communicate this fact + // to the rest of LyX. + ForkedcallsController & fcc = ForkedcallsController::get(); + fcc.handleCompletedProcesses(); + } + + cursor_timeout_.restart(); +} + + +void WorkArea::displayMessage(lyx::docstring const & message) +{ + lyx_view_.message(message); +} + +} // namespace frontend +} // namespace lyx