This patch replaces several of workarea signals with direct function calls into BufferView.
This means that the dependency direction is changed, now the frontend depend on the core and not the other way around. (IMO more correct) As a added bonues this should be a bit faster as well... Will go in shortly, but comments are appreciated. NB: Qt4 files have been updated, but not tested. So changes might be needed.
Index: src/BufferView_pimpl.C =================================================================== --- src/BufferView_pimpl.C (revision 13670) +++ src/BufferView_pimpl.C (working copy) @@ -116,14 +116,7 @@ // to these connections we avoid a segfault upon startup, and also at exit. // (Lgb) -boost::signals::connection dispatchcon; boost::signals::connection timecon; -boost::signals::connection doccon; -boost::signals::connection resizecon; -boost::signals::connection kpresscon; -boost::signals::connection selectioncon; -boost::signals::connection lostcon; - /// Return an inset of this class if it exists at the current cursor position template <class T> @@ -153,22 +146,11 @@ screen_.reset(LyXScreenFactory::create(workarea())); // Setup the signals - doccon = workarea().scrollDocView - .connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1)); - resizecon = workarea().workAreaResize - .connect(boost::bind(&BufferView::Pimpl::workAreaResize, this)); - dispatchcon = workarea().dispatch - .connect(boost::bind(&BufferView::Pimpl::workAreaDispatch, this, _1)); - kpresscon = workarea().workAreaKeyPress - .connect(boost::bind(&BufferView::Pimpl::workAreaKeyPress, this, _1, _2)); - selectioncon = workarea().selectionRequested - .connect(boost::bind(&BufferView::Pimpl::selectionRequested, this)); - lostcon = workarea().selectionLost - .connect(boost::bind(&BufferView::Pimpl::selectionLost, this)); - timecon = cursor_timeout.timeout .connect(boost::bind(&BufferView::Pimpl::cursorToggle, this)); + cursor_timeout.start(); + saved_positions.resize(saved_positions_num); // load saved bookmarks lyx::Session::BookmarkList & bmList = LyX::ref().session().loadBookmarks(); Index: src/frontends/gtk/GWorkArea.h =================================================================== --- src/frontends/gtk/GWorkArea.h (revision 13670) +++ src/frontends/gtk/GWorkArea.h (working copy) @@ -97,6 +97,7 @@ bool onKeyPress(GdkEventKey * event); void onClipboardGet(Gtk::SelectionData & selection_data, guint info); void onClipboardClear(); + LyXView & view_; Gtk::HBox hbox_; Gtk::DrawingArea workArea_; Gtk::VScrollbar vscrollbar_; Index: src/frontends/gtk/GWorkArea.C =================================================================== --- src/frontends/gtk/GWorkArea.C (revision 13670) +++ src/frontends/gtk/GWorkArea.C (working copy) @@ -23,6 +23,7 @@ #include "GtkmmX.h" #include "GLyXKeySym.h" +#include "BufferView.h" #include "debug.h" #include "funcrequest.h" #include "LColor.h" @@ -172,7 +173,7 @@ GWorkArea::GWorkArea(LyXView & owner, int width, int height) - : workAreaPixmap_(0), painter_(*this), draw_(0), colorHandler_(*this), + : view_(owner), workAreaPixmap_(0), painter_(*this), draw_(0), colorHandler_(*this), adjusting_(false) { workArea_.set_size_request(width, height); @@ -331,7 +332,7 @@ gtk_im_context_set_client_window( imContext_, workArea_.get_window()->gobj()); } - workAreaResize(); + view_.view()->workAreaResize(); return true; } @@ -374,7 +375,7 @@ adjusting_ = true; double val = vscrollbar_.get_adjustment()->get_value(); - scrollDocView(static_cast<int>(val)); + view_.view()->scrollDocView(static_cast<int>(val)); adjusting_ = false; } @@ -420,7 +421,7 @@ default: break; } - dispatch(FuncRequest(ka, + view_.view()->workAreaDispatch(FuncRequest(ka, static_cast<int>(event->x), static_cast<int>(event->y), gButtonToLyx(event->button))); @@ -431,7 +432,7 @@ bool GWorkArea::onButtonRelease(GdkEventButton * event) { - dispatch(FuncRequest(LFUN_MOUSE_RELEASE, + view_.view()->workAreaDispatch(FuncRequest(LFUN_MOUSE_RELEASE, static_cast<int>(event->x), static_cast<int>(event->y), gButtonToLyx(event->button))); @@ -456,7 +457,7 @@ } timeBefore = event->time; } - dispatch(FuncRequest(LFUN_MOUSE_MOTION, + view_.view()->workAreaDispatch(FuncRequest(LFUN_MOUSE_MOTION, static_cast<int>(event->x), static_cast<int>(event->y), gtkButtonState(event->state))); @@ -480,7 +481,7 @@ !inputGet) { #endif GLyXKeySym *glk = new GLyXKeySym(event->keyval); - workAreaKeyPress(LyXKeySymPtr(glk), + view_.view()->workAreaKeyPress(LyXKeySymPtr(glk), gtkKeyState(event->state)); #ifdef I18N } else if (!inputCache_.empty()) @@ -493,7 +494,7 @@ void GWorkArea::onClipboardGet(Gtk::SelectionData & /*selection_data*/, guint /*info*/) { - selectionRequested(); + view_.view()->selectionRequested(); } Index: src/frontends/WorkArea.h =================================================================== --- src/frontends/WorkArea.h (revision 13670) +++ src/frontends/WorkArea.h (working copy) @@ -58,19 +58,6 @@ virtual std::string const getClipboard() const = 0; /// fill the clipboard virtual void putClipboard(std::string const &) const = 0; - - /// work area dimensions have changed - boost::signal<void()> workAreaResize; - /// the scrollbar has changed - boost::signal<void(int)> scrollDocView; - /// a key combination has been pressed - boost::signal<void(LyXKeySymPtr, key_modifier::state)> workAreaKeyPress; - /// some mouse event - boost::signal<void(FuncRequest)> dispatch; - /// emitted when an X client has requested our selection - boost::signal<void()> selectionRequested; - /// emitted when another X client has stolen our selection - boost::signal<void()> selectionLost; }; #endif // WORKAREA_H Index: src/frontends/qt2/QWorkArea.C =================================================================== --- src/frontends/qt2/QWorkArea.C (revision 13670) +++ src/frontends/qt2/QWorkArea.C (working copy) @@ -10,6 +10,9 @@ #include <config.h> +#include "frontends/LyXView.h" +#include "BufferView.h" + #include "QWorkArea.h" #include "lcolorcache.h" @@ -46,11 +49,11 @@ namespace os = lyx::support::os; namespace { -QWorkArea const * wa_ptr = 0; +QWorkArea * wa_ptr = 0; } -QWorkArea::QWorkArea(LyXView &, int, int) - : WorkArea(), QWidget(qApp->mainWidget()), painter_(*this) +QWorkArea::QWorkArea(LyXView & owner, int, int) + : WorkArea(), QWidget(qApp->mainWidget()), owner_(owner), painter_(*this) { scrollbar_ = new QScrollBar(QScrollBar::Vertical, this); content_ = new QContentPane(this); @@ -103,12 +106,12 @@ case SelectionRequest: lyxerr[Debug::GUI] << "X requested selection." << endl; if (wa_ptr) - wa_ptr->selectionRequested(); + wa_ptr->view().view()->selectionRequested(); break; case SelectionClear: lyxerr[Debug::GUI] << "Lost selection." << endl; if (wa_ptr) - wa_ptr->selectionLost(); + wa_ptr->view().view()->selectionLost(); break; } return false; @@ -183,7 +186,7 @@ void QWorkArea::haveSelection(bool own) const { - wa_ptr = this; + wa_ptr = const_cast<QWorkArea*>(this); if (!QApplication::clipboard()->supportsSelection()) return; @@ -240,7 +243,7 @@ for (QStringList::Iterator i = files.begin(); i!=files.end(); ++i) { string const file = os::internal_path(fromqstr(*i)); - dispatch(FuncRequest(LFUN_FILE_OPEN, file)); + view().view()->workAreaDispatch(FuncRequest(LFUN_FILE_OPEN, file)); } } } Index: src/frontends/qt2/QWorkArea.h =================================================================== --- src/frontends/qt2/QWorkArea.h (revision 13670) +++ src/frontends/qt2/QWorkArea.h (working copy) @@ -63,7 +63,15 @@ /// get the content pane widget QWidget * getContent() const { return content_; } + /// + LyXView & view() + { + return owner_; + } private: + /// The owning LyXView + LyXView & owner_; + /// scroll bar QScrollBar * scrollbar_; /// content Index: src/frontends/qt2/QContentPane.C =================================================================== --- src/frontends/qt2/QContentPane.C (revision 13670) +++ src/frontends/qt2/QContentPane.C (working copy) @@ -10,6 +10,9 @@ #include <config.h> +#include "BufferView.h" +#include "frontends/LyXView.h" + // Qt defines a macro 'signals' that clashes with a boost namespace. // All is well if the namespace is visible first. #include "QWorkArea.h" @@ -155,7 +158,7 @@ synthetic_mouse_event_.scrollbar_value_old = scrollbar_value; // ... and dispatch the event to the LyX core. - wa_->dispatch(synthetic_mouse_event_.cmd); + wa_->view().view()->workAreaDispatch(synthetic_mouse_event_.cmd); } } @@ -163,7 +166,7 @@ void QContentPane::scrollBarChanged(int val) { if (track_scrollbar_) - wa_->scrollDocView(val); + wa_->view().view()->scrollDocView(val); } @@ -174,13 +177,13 @@ FuncRequest cmd(LFUN_MOUSE_TRIPLE, dc_event_.x, dc_event_.y, q_button_state(dc_event_.state)); - wa_->dispatch(cmd); + wa_->view().view()->workAreaDispatch(cmd); return; } FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(), q_button_state(e->button())); - wa_->dispatch(cmd); + wa_->view().view()->workAreaDispatch(cmd); } @@ -191,7 +194,7 @@ FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(), q_button_state(e->button())); - wa_->dispatch(cmd); + wa_->view().view()->workAreaDispatch(cmd); } @@ -251,7 +254,7 @@ synthetic_mouse_event_.scrollbar_value_old = scrollbar_value; // ... and dispatch the event to the LyX core. - wa_->dispatch(cmd); + wa_->view().view()->workAreaDispatch(cmd); } } @@ -289,7 +292,7 @@ boost::shared_ptr<QLyXKeySym> sym(new QLyXKeySym); sym->set(ev.get()); - wa_->workAreaKeyPress(sym, q_key_state(ev->state())); + wa_->view().view()->workAreaKeyPress(sym, q_key_state(ev->state())); keyeventQueue_.pop(); handle_autos = false; @@ -310,7 +313,7 @@ FuncRequest cmd(LFUN_MOUSE_DOUBLE, dc_event_.x, dc_event_.y, q_button_state(dc_event_.state)); - wa_->dispatch(cmd); + wa_->view().view()->workAreaDispatch(cmd); } @@ -331,7 +334,7 @@ } pixmap_->resize(width(), height()); - wa_->workAreaResize(); + wa_->view().view()->workAreaResize(); } @@ -339,7 +342,7 @@ { if (!pixmap_.get()) { pixmap_.reset(new QPixmap(width(), height())); - wa_->workAreaResize(); + wa_->view().view()->workAreaResize(); return; } Index: src/frontends/qt4/QWorkArea.C =================================================================== --- src/frontends/qt4/QWorkArea.C (revision 13670) +++ src/frontends/qt4/QWorkArea.C (working copy) @@ -60,7 +60,7 @@ namespace { -QWorkArea const * wa_ptr = 0; +QWorkArea * wa_ptr = 0; /// return the LyX key state from Qt's key_modifier::state q_key_state(Qt::ButtonState state) @@ -120,8 +120,8 @@ {} -QWorkArea::QWorkArea(LyXView &, int w, int h) - : QAbstractScrollArea(qApp->mainWidget()), WorkArea(), painter_(this) +QWorkArea::QWorkArea(LyXView & owner, int w, int h) + : QAbstractScrollArea(qApp->mainWidget()), WorkArea(), view_(owner), painter_(this) { setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -224,7 +224,7 @@ << " linestep=" << verticalScrollBar()->lineStep() << endl; - this->scrollDocView(verticalScrollBar()->sliderPosition()); + view_.view()->scrollDocView(verticalScrollBar()->sliderPosition()); } @@ -292,7 +292,7 @@ for (QStringList::Iterator i = files.begin(); i!=files.end(); ++i) { string const file = os::internal_path(fromqstr(*i)); - dispatch(FuncRequest(LFUN_FILE_OPEN, file)); + view_.view()->workAreaDispatch(FuncRequest(LFUN_FILE_OPEN, file)); } } } @@ -305,13 +305,13 @@ FuncRequest cmd(LFUN_MOUSE_TRIPLE, dc_event_.x, dc_event_.y, q_button_state(dc_event_.state)); - this->dispatch(cmd); + view_.view()->workAreaDispatch(cmd); return; } FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(), q_button_state(e->button())); - this->dispatch(cmd); + view_.view()->workAreaDispatch(cmd); } @@ -322,7 +322,7 @@ FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(), q_button_state(e->button())); - this->dispatch(cmd); + view_.view()->workAreaDispatch(cmd); } @@ -382,7 +382,7 @@ synthetic_mouse_event_.scrollbar_value_old = scrollbar_value; // ... and dispatch the event to the LyX core. - this->dispatch(cmd); + view_.view()->workAreaDispatch(cmd); } } @@ -412,7 +412,7 @@ synthetic_mouse_event_.scrollbar_value_old = scrollbar_value; // ... and dispatch the event to the LyX core. - this->dispatch(synthetic_mouse_event_.cmd); + view_.view()->workAreaDispatch(synthetic_mouse_event_.cmd); } } @@ -429,7 +429,7 @@ boost::shared_ptr<QLyXKeySym> sym(new QLyXKeySym); sym->set(e); - this->workAreaKeyPress(sym, q_key_state(e->state())); + view_.view()->workAreaKeyPress(sym, q_key_state(e->state())); } @@ -458,7 +458,7 @@ << " key=" << ev->key() << endl; - this->workAreaKeyPress(sym, q_key_state(ev->state())); + view_.view()->workAreaKeyPress(sym, q_key_state(ev->state())); keyeventQueue_.pop(); handle_autos = false; @@ -481,7 +481,7 @@ FuncRequest cmd(LFUN_MOUSE_DOUBLE, dc_event_.x, dc_event_.y, q_button_state(dc_event_.state)); - this->dispatch(cmd); + view_.view()->workAreaDispatch(cmd); } @@ -495,7 +495,7 @@ screen_device_ = QPixmap(viewport()->width(), viewport()->height()); paint_device_ = QImage(viewport()->width(), viewport()->height(), QImage::Format_RGB32); - this->workAreaResize(); + view_.view()->workAreaResize(); /* lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION @@ -588,12 +589,12 @@ case SelectionRequest: lyxerr[Debug::GUI] << "X requested selection." << endl; if (wa_ptr) - wa_ptr->selectionRequested(); + wa_ptr->view().view()->selectionRequested(); break; case SelectionClear: lyxerr[Debug::GUI] << "Lost selection." << endl; if (wa_ptr) - wa_ptr->selectionLost(); + wa_ptr->view().view()->selectionLost(); break; } return false; @@ -657,7 +658,7 @@ FSRefMakePath(&ref, (UInt8*)qstr_buf, 1024); s_arg=QString::fromUtf8(qstr_buf); - wa_ptr->dispatch( + wa_ptr->view().view()->workAreaDispatch( FuncRequest(LFUN_FILE_OPEN, fromqstr(s_arg))); break; Index: src/frontends/qt4/QWorkArea.h =================================================================== --- src/frontends/qt4/QWorkArea.h (revision 13670) +++ src/frontends/qt4/QWorkArea.h (working copy) @@ -145,6 +145,10 @@ */ void drawScreen(int x, int y, QPixmap pixmap); + LyXView & view() + { + return view_; + } protected: /// repaint part of the widget @@ -185,6 +189,8 @@ void adjustViewWithScrollBar(int action = 0); private: + /// + LyXView & view_; /// Buffer view width. int workWidth_; Index: src/frontends/xforms/XWorkArea.C =================================================================== --- src/frontends/xforms/XWorkArea.C (revision 13670) +++ src/frontends/xforms/XWorkArea.C (working copy) @@ -12,6 +12,7 @@ #include <config.h> #include "XWorkArea.h" +#include "BufferView.h" #include "Color.h" #include "XFormsView.h" @@ -108,7 +109,7 @@ XWorkArea::XWorkArea(LyXView & owner, int w, int h) - : workareapixmap(0), painter_(*this) + : view_(owner), workareapixmap(0), painter_(*this) { fl_freeze_all_forms(); @@ -219,7 +220,7 @@ height, fl_get_visual_depth()); - workAreaResize(); + view_.view()->workAreaResize(); } @@ -276,7 +277,7 @@ << "scroll: docheight: " << doc_height_ << endl; } - scrollDocView(int(val)); + view_.view()->scrollDocView(int(val)); waitForX(false); } @@ -331,7 +332,7 @@ // Should really have used xbutton.state lyxerr[Debug::WORKAREA] << "Workarea event: PUSH" << endl; - area->dispatch( + area->view_.view()->workAreaDispatch( FuncRequest(LFUN_MOUSE_PRESS, ev->xbutton.x - ob->x, ev->xbutton.y - ob->y, @@ -349,7 +350,7 @@ lyxerr[Debug::WORKAREA] << "Workarea event: RELEASE" << endl; - area->dispatch( + area->view_.view()->workAreaDispatch( FuncRequest(LFUN_MOUSE_RELEASE, ev->xbutton.x - ob->x, ev->xbutton.y - ob->y, @@ -418,7 +419,7 @@ ev->xbutton.x - ob->x, ev->xbutton.y - ob->y, x_button_state(key)); - area->dispatch(cmd); + area->view_.view()->workAreaDispatch(cmd); } break; } @@ -509,7 +510,7 @@ XLyXKeySym * xlk = new XLyXKeySym; xlk->initFromKeySym(ret_key); - area->workAreaKeyPress(LyXKeySymPtr(xlk), + area->view_.view()->workAreaKeyPress(LyXKeySymPtr(xlk), x_key_state(ret_state)); break; } @@ -542,7 +543,7 @@ ev->xbutton.x - ob->x, ev->xbutton.y - ob->y, x_button_state(key)); - area->dispatch(cmd); + area->view_.view()->workAreaDispatch(cmd); } break; @@ -558,7 +559,7 @@ ev->xbutton.x - ob->x, ev->xbutton.y - ob->y, x_button_state(key)); - area->dispatch(cmd); + area->view_.view()->workAreaDispatch(cmd); } break; @@ -601,11 +602,11 @@ switch (xev->type) { case SelectionRequest: lyxerr[Debug::GUI] << "X requested selection." << endl; - selectionRequested(); + view_.view()->selectionRequested(); break; case SelectionClear: lyxerr[Debug::GUI] << "Lost selection." << endl; - selectionLost(); + view_.view()->selectionLost(); break; } return 0; Index: src/frontends/xforms/XWorkArea.h =================================================================== --- src/frontends/xforms/XWorkArea.h (revision 13670) +++ src/frontends/xforms/XWorkArea.h (working copy) @@ -65,6 +65,8 @@ /// handles SelectionRequest X Event, to fill the clipboard int event_cb(XEvent * xev); private: + LyXView & view_; + /// generate the pixmap, and copy backing pixmap to it, /// and send resize event if needed void redraw(int, int); Index: src/BufferView.C =================================================================== --- src/BufferView.C (revision 13670) +++ src/BufferView.C (working copy) @@ -235,6 +235,36 @@ } +void BufferView::selectionRequested() +{ + pimpl_->selectionRequested(); +} + + +void BufferView::selectionLost() +{ + pimpl_->selectionLost(); +} + + +void BufferView::workAreaResize() +{ + pimpl_->workAreaResize(); +} + + +void BufferView::workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state) +{ + pimpl_->workAreaKeyPress(key, state); +} + + +bool BufferView::workAreaDispatch(FuncRequest const & ev) +{ + return pimpl_->workAreaDispatch(ev); +} + + void BufferView::scroll(int lines) { pimpl_->scroll(lines); Index: src/BufferView.h =================================================================== --- src/BufferView.h (revision 13670) +++ src/BufferView.h (working copy) @@ -15,6 +15,8 @@ #ifndef BUFFER_VIEW_H #define BUFFER_VIEW_H +#include "frontends/LyXKeySym.h" + #include "support/types.h" #include <boost/utility.hpp> @@ -175,6 +177,20 @@ /// execute the given function bool dispatch(FuncRequest const & argument); + /// + void selectionRequested(); + /// + void selectionLost(); + + /// + void workAreaResize(); + + /// Receive a keypress + void workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state); + + /// a function should be executed from the workarea + bool workAreaDispatch(FuncRequest const & ev); + /// clear the X selection void unsetXSel();
-- Lgb