From c4db1d0f5a05429726d244caebd207bf29c58d71 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Tue, 13 Nov 2007 09:52:28 +0000 Subject: [PATCH] Push latest Andre's changes toward their true direction: * WorkArea.h and LyXView.h: remove unneeded pure virtual interface. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21575 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LyXFunc.cpp | 32 ++++-------- src/frontends/Application.cpp | 1 - src/frontends/LyXView.h | 43 ++------------- src/frontends/WorkArea.h | 33 +----------- src/frontends/qt4/GuiDocument.cpp | 6 --- src/frontends/qt4/GuiErrorList.cpp | 5 -- src/frontends/qt4/GuiSpellchecker.cpp | 4 -- src/frontends/qt4/GuiView.cpp | 75 +++++++++++++-------------- src/frontends/qt4/GuiView.h | 45 ++++++++++------ src/frontends/qt4/GuiWorkArea.cpp | 7 +-- src/frontends/qt4/GuiWorkArea.h | 28 +++++----- 11 files changed, 96 insertions(+), 183 deletions(-) diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index ce6df25bcc..04b68a03dd 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -83,7 +83,6 @@ #include "frontends/KeySymbol.h" #include "frontends/LyXView.h" #include "frontends/Selection.h" -#include "frontends/WorkArea.h" #include "support/environment.h" #include "support/FileFilterList.h" @@ -186,7 +185,7 @@ bool import(LyXView * lv, FileName const & filename, } updateLabels(*buf); lv->setBuffer(buf); - lv->showErrorList("Parse"); + lv->errors("Parse"); } else { Buffer * const b = newFile(lyxfile.absFilename(), string(), true); if (b) @@ -384,17 +383,6 @@ void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer) } -namespace { -void restartCursor(LyXView * lv) -{ - /* When we move around, or type, it's nice to be able to see - * the cursor immediately after the keypress. - */ - if (lv && lv->currentWorkArea()) - lv->currentWorkArea()->startBlinkingCursor(); -} -} - void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state) { LYXERR(Debug::KEY) << "KeySym is " << keysym.getSymbolName() << endl; @@ -403,13 +391,13 @@ void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state) if (!keysym.isOK()) { LYXERR(Debug::KEY) << "Empty kbd action (probably composing)" << endl; - restartCursor(lyx_view_); + lyx_view_->restartCursor(); return; } if (keysym.isModifier()) { LYXERR(Debug::KEY) << "isModifier true" << endl; - restartCursor(lyx_view_); + lyx_view_->restartCursor(); return; } @@ -479,7 +467,7 @@ void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state) } else { LYXERR(Debug::KEY) << "Unknown, !isText() - giving up" << endl; lyx_view_->message(_("Unknown function.")); - restartCursor(lyx_view_); + lyx_view_->restartCursor(); return; } } @@ -496,7 +484,7 @@ void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state) dispatch(func); } - restartCursor(lyx_view_); + lyx_view_->restartCursor(); } @@ -1292,7 +1280,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) if (buf) { updateLabels(*buf); lyx_view_->setBuffer(buf); - lyx_view_->showErrorList("Parse"); + lyx_view_->errors("Parse"); } updateFlags = Update::None; break; @@ -1438,7 +1426,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) lyx_view_->setBuffer(buf); view()->setCursorFromRow(row); if (loaded) - lyx_view_->showErrorList("Parse"); + lyx_view_->errors("Parse"); updateFlags = Update::FitCursor; break; } @@ -1654,7 +1642,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) updateLabels(*child->masterBuffer()); lyx_view_->setBuffer(child); if (parsed) - lyx_view_->showErrorList("Parse"); + lyx_view_->errors("Parse"); } // If a screen update is required (in case where auto_open is false), @@ -2272,7 +2260,7 @@ void LyXFunc::open(string const & fname) if (buf) { updateLabels(*buf); lyx_view_->setBuffer(buf); - lyx_view_->showErrorList("Parse"); + lyx_view_->errors("Parse"); str2 = bformat(_("Document %1$s opened."), disp_fn); } else { str2 = bformat(_("Could not open document %1$s"), disp_fn); @@ -2387,7 +2375,7 @@ void LyXFunc::reloadBuffer() if (buf) { updateLabels(*buf); lyx_view_->setBuffer(buf); - lyx_view_->showErrorList("Parse"); + lyx_view_->errors("Parse"); str = bformat(_("Document %1$s reloaded."), disp_fn); } else { str = bformat(_("Could not reload document %1$s"), disp_fn); diff --git a/src/frontends/Application.cpp b/src/frontends/Application.cpp index 06b5af18ab..ec010f4df8 100644 --- a/src/frontends/Application.cpp +++ b/src/frontends/Application.cpp @@ -18,7 +18,6 @@ #include "frontends/FontMetrics.h" #include "frontends/Gui.h" #include "frontends/LyXView.h" -#include "frontends/WorkArea.h" #include "FuncRequest.h" #include "FuncStatus.h" diff --git a/src/frontends/LyXView.h b/src/frontends/LyXView.h index 51008ea6fd..06d46ee1dc 100644 --- a/src/frontends/LyXView.h +++ b/src/frontends/LyXView.h @@ -31,7 +31,6 @@ class ToolbarInfo; namespace frontend { class Dialogs; -class WorkArea; /** * LyXView - main LyX window @@ -53,7 +52,7 @@ public: /// LyXView(int id) : id_(id) {} /// - virtual ~LyXView(); + virtual ~LyXView() {} /// int id() const { return id_; } /// @@ -61,20 +60,6 @@ public: /// virtual void setFocus() = 0; - /// - virtual WorkArea * workArea(Buffer & buffer) = 0; - /// - virtual WorkArea * addWorkArea(Buffer & buffer) = 0; - /// - virtual void setCurrentWorkArea(WorkArea * work_area) = 0; - /// - virtual void removeWorkArea(WorkArea * work_area) = 0; - /// return the current WorkArea (the one that has the focus). - virtual WorkArea const * currentWorkArea() const = 0; - /// FIXME: This non-const access is needed because of - /// a mis-designed \c ControlSpellchecker. - virtual WorkArea * currentWorkArea() = 0; - /** * This is called after the concrete view has been created. * We have to have the toolbar and the other stuff created @@ -98,9 +83,6 @@ public: unsigned int iconSizeXY, const std::string & geometryArg) = 0; - /// save the geometry state in the session manager. - virtual void saveGeometry() = 0; - /// show busy cursor virtual void setBusy(bool) = 0; @@ -152,9 +134,6 @@ public: /// clear any temporary message and replace with current status virtual void clearMessage() = 0; - /// reset autosave timer - virtual void resetAutosaveTimer() = 0; - /// dispatch to current BufferView virtual void dispatch(FuncRequest const & cmd) = 0; @@ -166,28 +145,14 @@ public: /// returns true if this view has the focus. virtual bool hasFocus() const = 0; - /// show the error list to the user - virtual void showErrorList(std::string const &) = 0; + /// + virtual void restartCursor() = 0; // // GuiBufferDelegate // - /// This function is called when the buffer structure is changed. - virtual void structureChanged() = 0; - /// This function is called when some parsing error shows up. - void errors(std::string const & err) { showErrorList(err); } - /// Reset autosave timers for all users. - void resetAutosaveTimers() { resetAutosaveTimer(); } - - /// connect to signals in the given BufferView - virtual void connectBufferView(BufferView & bv) = 0; - /// disconnect from signals in the given BufferView - virtual void disconnectBufferView() = 0; - /// connect to signals in the given buffer - virtual void connectBuffer(Buffer & buf) = 0; - /// disconnect from signals in the given buffer - virtual void disconnectBuffer() = 0; + virtual void errors(std::string const &) = 0; private: /// noncopyable diff --git a/src/frontends/WorkArea.h b/src/frontends/WorkArea.h index b4d9f9ee19..eef1d018f5 100644 --- a/src/frontends/WorkArea.h +++ b/src/frontends/WorkArea.h @@ -36,41 +36,10 @@ public: /// WorkArea() {} /// - virtual ~WorkArea(); - - /// - virtual BufferView & bufferView() = 0; - /// - virtual BufferView const & bufferView() const = 0; - - /// return true if has the keyboard input focus. - virtual bool hasFocus() const = 0; - - /// return true if has this WorkArea is visible. - virtual bool isVisible() const = 0; - - /// return the width of the work area in pixels - virtual int width() const = 0; - - /// return the height of the work area in pixels - virtual int height() const = 0; - - /** - * Update the scrollbar. - * @param height the total document height in pixels - * @param pos the current position in the document, in pixels - * @param line_height the line-scroll amount, in pixels - */ - virtual void setScrollbarParams(int height, int pos, int line_height) = 0; - - /// - virtual void scheduleRedraw() = 0; + virtual ~WorkArea() {} /// redraw the screen, without using existing pixmap virtual void redraw() = 0; - /// - virtual void stopBlinkingCursor() = 0; - virtual void startBlinkingCursor() = 0; /// Process Key pressed event. /// This needs to be public because it is accessed externally by GuiView. diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index f095f5c0af..a1617053b2 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -40,12 +40,6 @@ #include "TextClassList.h" #include "Validator.h" - -// FIXME: those two headers are needed because of the -// WorkArea::redraw() call below. -#include "frontends/LyXView.h" -#include "frontends/WorkArea.h" - #include "insets/InsetListingsParams.h" #include "support/lstrings.h" diff --git a/src/frontends/qt4/GuiErrorList.cpp b/src/frontends/qt4/GuiErrorList.cpp index e9d213443a..54a035f006 100644 --- a/src/frontends/qt4/GuiErrorList.cpp +++ b/src/frontends/qt4/GuiErrorList.cpp @@ -21,11 +21,6 @@ #include "qt_helpers.h" -// FIXME: those two headers are needed because of the -// WorkArea::redraw() call below. -#include "frontends/LyXView.h" -#include "frontends/WorkArea.h" - #include "support/lstrings.h" #include diff --git a/src/frontends/qt4/GuiSpellchecker.cpp b/src/frontends/qt4/GuiSpellchecker.cpp index 45359ca182..f942304e08 100644 --- a/src/frontends/qt4/GuiSpellchecker.cpp +++ b/src/frontends/qt4/GuiSpellchecker.cpp @@ -53,10 +53,6 @@ #endif #include "frontends/alert.h" -// FIXME: those two headers are needed because of the -// WorkArea::redraw() call below. -#include "frontends/LyXView.h" -#include "frontends/WorkArea.h" using std::advance; using std::distance; diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 857b736913..f29bbdceb0 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -22,7 +22,6 @@ #include "GuiToolbar.h" #include "GuiToolbars.h" #include "Dialogs.h" -#include "WorkArea.h" #include "Gui.h" #include "qt_helpers.h" @@ -30,7 +29,6 @@ #include "frontends/Application.h" #include "frontends/Dialogs.h" #include "frontends/Gui.h" -#include "frontends/WorkArea.h" #include "support/filetools.h" #include "support/convert.h" @@ -270,10 +268,6 @@ public: unsigned int GuiView::GuiViewPrivate::lastIconSize = 0; -/// FIXME -LyXView::~LyXView() {} - - GuiView::GuiView(int id) : QMainWindow(), LyXView(id), d(*new GuiViewPrivate), @@ -869,7 +863,7 @@ GuiToolbar * GuiView::makeToolbar(ToolbarInfo const & tbinfo, bool newline) } -WorkArea * GuiView::workArea(Buffer & buffer) +GuiWorkArea * GuiView::workArea(Buffer & buffer) { for (int i = 0; i != d.splitter_->count(); ++i) { GuiWorkArea * wa = d.tabWorkArea(i)->workArea(buffer); @@ -880,7 +874,7 @@ WorkArea * GuiView::workArea(Buffer & buffer) } -WorkArea * GuiView::addWorkArea(Buffer & buffer) +GuiWorkArea * GuiView::addWorkArea(Buffer & buffer) { GuiWorkArea * wa = new GuiWorkArea(buffer, *this); wa->setUpdatesEnabled(false); @@ -912,19 +906,19 @@ void GuiView::addTabWorkArea() } -WorkArea * GuiView::currentWorkArea() +GuiWorkArea * GuiView::currentWorkArea() { return d.current_work_area_; } -WorkArea const * GuiView::currentWorkArea() const +GuiWorkArea const * GuiView::currentWorkArea() const { return d.current_work_area_; } -void GuiView::setCurrentWorkArea(WorkArea * work_area) +void GuiView::setCurrentWorkArea(GuiWorkArea * work_area) { BOOST_ASSERT(work_area); @@ -941,7 +935,7 @@ void GuiView::setCurrentWorkArea(WorkArea * work_area) } -void GuiView::removeWorkArea(WorkArea * work_area) +void GuiView::removeWorkArea(GuiWorkArea * work_area) { BOOST_ASSERT(work_area); GuiWorkArea * gwa = static_cast(work_area); @@ -962,7 +956,7 @@ void GuiView::removeWorkArea(WorkArea * work_area) // Not found in this tab group. continue; - // We found and removed the WorkArea. + // We found and removed the GuiWorkArea. if (twa->count()) { // No more WorkAreas in this tab group, so delete it. delete twa; @@ -970,10 +964,10 @@ void GuiView::removeWorkArea(WorkArea * work_area) } if (d.current_work_area_) - // This means that we are not closing the current WorkArea; + // This means that we are not closing the current GuiWorkArea; break; - // Switch to the next WorkArea in the found TabWorkArea. + // Switch to the next GuiWorkArea in the found TabWorkArea. d.current_work_area_ = twa->currentWorkArea(); break; } @@ -1072,18 +1066,16 @@ void GuiView::toggleToolbarState(string const & name, bool allowauto) Buffer * GuiView::buffer() { - WorkArea * work_area = currentWorkArea(); - if (work_area) - return &work_area->bufferView().buffer(); + if (d.current_work_area_) + return &d.current_work_area_->bufferView().buffer(); return 0; } Buffer const * GuiView::buffer() const { - WorkArea const * work_area = currentWorkArea(); - if (work_area) - return &work_area->bufferView().buffer(); + if (d.current_work_area_) + return &d.current_work_area_->bufferView().buffer(); return 0; } @@ -1093,7 +1085,7 @@ void GuiView::setBuffer(Buffer * newBuffer) BOOST_ASSERT(newBuffer); setBusy(true); - WorkArea * wa = workArea(*newBuffer); + GuiWorkArea * wa = workArea(*newBuffer); if (wa == 0) { updateLabels(*newBuffer->masterBuffer()); wa = addWorkArea(*newBuffer); @@ -1122,7 +1114,7 @@ Buffer * GuiView::loadLyXFile(FileName const & filename, bool tolastfiles) return 0; } - WorkArea * wa = workArea(*newBuffer); + GuiWorkArea * wa = workArea(*newBuffer); if (wa == 0) wa = addWorkArea(*newBuffer); @@ -1151,8 +1143,8 @@ void GuiView::connectBuffer(Buffer & buf) void GuiView::disconnectBuffer() { - if (WorkArea * work_area = currentWorkArea()) - work_area->bufferView().setGuiDelegate(0); + if (d.current_work_area_) + d.current_work_area_->bufferView().setGuiDelegate(0); } @@ -1164,12 +1156,12 @@ void GuiView::connectBufferView(BufferView & bv) void GuiView::disconnectBufferView() { - if (WorkArea * work_area = currentWorkArea()) - work_area->bufferView().setGuiDelegate(0); + if (d.current_work_area_) + d.current_work_area_->bufferView().setGuiDelegate(0); } -void GuiView::showErrorList(string const & error_type) +void GuiView::errors(string const & error_type) { ErrorList & el = buffer()->errorList(error_type); if (!el.empty()) @@ -1205,8 +1197,7 @@ void GuiView::updateDialog(string const & name, string const & data) BufferView * GuiView::view() { - WorkArea * wa = currentWorkArea(); - return wa ? &wa->bufferView() : 0; + return d.current_work_area_ ? &d.current_work_area_->bufferView() : 0; } @@ -1231,7 +1222,7 @@ void GuiView::autoSave() } -void GuiView::resetAutosaveTimer() +void GuiView::resetAutosaveTimers() { if (lyxrc.autosave) autosave_timeout_->restart(); @@ -1254,15 +1245,23 @@ void GuiView::dispatch(FuncRequest const & cmd) Buffer const * GuiView::updateInset(Inset const * inset) { - WorkArea * work_area = currentWorkArea(); - if (!work_area) + if (!d.current_work_area_) return 0; - if (inset) { - BOOST_ASSERT(work_area); - work_area->scheduleRedraw(); - } - return &work_area->bufferView().buffer(); + if (inset) + d.current_work_area_->scheduleRedraw(); + + return &d.current_work_area_->bufferView().buffer(); +} + + +void GuiView::restartCursor() +{ + /* When we move around, or type, it's nice to be able to see + * the cursor immediately after the keypress. + */ + if (d.current_work_area_) + d.current_work_area_->startBlinkingCursor(); } } // namespace frontend diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 2c4daad81c..95d34fb5fd 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -65,6 +65,7 @@ public: int maximized, unsigned int iconSizeXY, const std::string & geometryArg); + /// save the geometry state in the session manager. virtual void saveGeometry(); virtual void setBusy(bool); /// add toolbar, if newline==true, add a toolbar break before the toolbar @@ -122,6 +123,8 @@ public Q_SLOTS: void bigSizedIcons(); private: + friend GuiWorkArea; + /// make sure we quit cleanly virtual void closeEvent(QCloseEvent * e); /// @@ -131,31 +134,39 @@ private: /// \return the \c Workarea associated to \p Buffer /// \retval 0 if no \c WorkArea is found. - WorkArea * workArea(Buffer & buffer); + GuiWorkArea * workArea(Buffer & buffer); /// Add a \c WorkArea /// \return the \c Workarea associated to \p Buffer /// \retval 0 if no \c WorkArea is found. - WorkArea * addWorkArea(Buffer & buffer); - void setCurrentWorkArea(WorkArea * work_area); - void removeWorkArea(WorkArea * work_area); - WorkArea const * currentWorkArea() const; - WorkArea * currentWorkArea(); - + GuiWorkArea * addWorkArea(Buffer & buffer); /// - void resetAutosaveTimer(); - /// - void showErrorList(std::string const & error_type); + void setCurrentWorkArea(GuiWorkArea * work_area); /// + void removeWorkArea(GuiWorkArea * work_area); + /// return the current WorkArea (the one that has the focus). + GuiWorkArea const * currentWorkArea() const; + /// FIXME: This non-const access is needed because of + /// a mis-designed \c ControlSpellchecker. + GuiWorkArea * currentWorkArea(); + + /// GuiBufferDelegate. + ///@{ + void resetAutosaveTimers(); + void errors(std::string const &); void structureChanged() { updateToc(); } - /// - void connectBuffer(Buffer & buf); - /// - void disconnectBuffer(); - /// + ///@} + + + /// connect to signals in the given BufferView void connectBufferView(BufferView & bv); - /// + /// disconnect from signals in the given BufferView void disconnectBufferView(); + /// connect to signals in the given buffer + void connectBuffer(Buffer & buf); + /// disconnect from signals in the given buffer + void disconnectBuffer(); + //// void showDialog(std::string const & name); void showDialogWithData(std::string const & name, @@ -201,6 +212,8 @@ private: * visible. If successful return a pointer to the owning Buffer. */ Buffer const * updateInset(Inset const *); + /// + void restartCursor(); private: diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index 06e1d824cf..29be5d68ac 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -25,6 +25,7 @@ #include "GuiApplication.h" #include "GuiKeySymbol.h" #include "GuiPainter.h" +#include "GuiView.h" #include "KeySymbol.h" #include "Language.h" #include "LyXFunc.h" @@ -42,7 +43,6 @@ #include "frontends/Application.h" #include "frontends/Dialogs.h" // only used in setReadOnly #include "frontends/FontMetrics.h" -#include "frontends/LyXView.h" #include "frontends/WorkAreaManager.h" #include @@ -199,11 +199,8 @@ SyntheticMouseEvent::SyntheticMouseEvent() static boost::signals::connection timecon; -// HACK: FIXME -WorkArea::~WorkArea() {} - -GuiWorkArea::GuiWorkArea(Buffer & buffer, LyXView & lv) +GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & lv) : buffer_view_(new BufferView(buffer)), lyx_view_(&lv), cursor_visible_(false), cursor_timeout_(400), need_resize_(false), schedule_redraw_(false), diff --git a/src/frontends/qt4/GuiWorkArea.h b/src/frontends/qt4/GuiWorkArea.h index 19e0d6e31b..004d260420 100644 --- a/src/frontends/qt4/GuiWorkArea.h +++ b/src/frontends/qt4/GuiWorkArea.h @@ -44,7 +44,7 @@ class Buffer; namespace frontend { -class LyXView; +class GuiView; /// types of cursor in work area enum CursorShape { @@ -106,22 +106,19 @@ class GuiWorkArea : public QAbstractScrollArea, public WorkArea public: /// - GuiWorkArea(Buffer & buffer, LyXView & lv); + GuiWorkArea(Buffer & buffer, GuiView & lv); /// ~GuiWorkArea(); + /** + * Update the scrollbar. + * @param height the total document height in pixels + * @param pos the current position in the document, in pixels + * @param line_height the line-scroll amount, in pixels + */ + void setScrollbarParams(int height, int pos, int line_height); /// - bool hasFocus() const { return QAbstractScrollArea::hasFocus(); } - bool isVisible() const { return QAbstractScrollArea::isVisible(); } - - /// return the width of the content pane - virtual int width() const { return viewport()->width(); } - /// return the height of the content pane - virtual int height() const { return viewport()->height(); } - /// - virtual void setScrollbarParams(int height, int pos, int line_height); - /// - virtual void scheduleRedraw() { schedule_redraw_ = true; } + void scheduleRedraw() { schedule_redraw_ = true; } /// update the passed area. void update(int x, int y, int w, int h); @@ -144,7 +141,8 @@ public: void stopBlinkingCursor(); /// void startBlinkingCursor(); - /// + /// Process Key pressed event. + /// This needs to be public because it is accessed externally by GuiView. void processKeySym(KeySymbol const & key, KeyModifier mod); public Q_SLOTS: @@ -217,7 +215,7 @@ private: /// BufferView * buffer_view_; /// - LyXView * lyx_view_; + GuiView * lyx_view_; /// is the cursor currently displayed bool cursor_visible_; -- 2.39.2