This patch removes two unused methods for BV, and makes workarea_ use a scoped_ptr. This is necessary in order to use the virtual constructor factory idiom later, ie. in the GUII patch, a method is called into the frontends toolkits, which returns a WorkArea * which is really an XWorkArea * or QWorkArea *.
This seems to be the simplest way of doing things, and doesn't have any obvious disadvantages imo (we already do this for LyXView). OK to apply ? thanks john Index: src/BufferView.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.C,v retrieving revision 1.87 diff -u -r1.87 BufferView.C --- src/BufferView.C 23 May 2002 15:43:24 -0000 1.87 +++ src/BufferView.C 26 May 2002 20:57:51 -0000 @@ -18,6 +18,7 @@ #include "BufferView_pimpl.h" #include "lyxtext.h" #include "frontends/screen.h" +#include "frontends/WorkArea.h" BufferView::BufferView(LyXView * o, int xpos, int ypos, @@ -210,21 +211,9 @@ } -bool BufferView::active() const -{ - return pimpl_->active(); -} - - int BufferView::workWidth() const { - return pimpl_->workarea_.workWidth(); -} - - -bool BufferView::belowMouse() const -{ - return pimpl_->belowMouse(); + return pimpl_->workarea_->workWidth(); } @@ -266,7 +255,7 @@ string const BufferView::getClipboard() const { - return pimpl_->workarea_.getClipboard(); + return pimpl_->workarea_->getClipboard(); } Index: src/BufferView.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.h,v retrieving revision 1.84 diff -u -r1.84 BufferView.h --- src/BufferView.h 23 Apr 2002 13:35:41 -0000 1.84 +++ src/BufferView.h 26 May 2002 20:57:51 -0000 @@ -191,10 +191,6 @@ bool focus() const; /// void focus(bool); - /// - bool active() const; - /// - bool belowMouse() const; /// A callback for the slider in the scrollbar. void scrollCB(double); Index: src/BufferView_pimpl.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v retrieving revision 1.243 diff -u -r1.243 BufferView_pimpl.C --- src/BufferView_pimpl.C 26 May 2002 17:33:07 -0000 1.243 +++ src/BufferView_pimpl.C 26 May 2002 20:57:58 -0000 @@ -7,6 +7,9 @@ #include "BufferView_pimpl.h" #include "frontends/WorkArea.h" #include "frontends/screen.h" +#include "frontends/Dialogs.h" +#include "frontends/Alert.h" +#include "frontends/FileDialog.h" #include "lyxtext.h" #include "lyxrow.h" #include "paragraph.h" @@ -28,9 +31,6 @@ #include "undo_funcs.h" #include "lyxtextclasslist.h" -#include "frontends/Dialogs.h" -#include "frontends/Alert.h" -#include "frontends/FileDialog.h" #include "insets/insetbib.h" #include "insets/insettext.h" @@ -127,46 +127,47 @@ int xpos, int ypos, int width, int height) : bv_(b), owner_(o), buffer_(0), current_scrollbar_value(0), cursor_timeout(400), - workarea_(xpos, ypos, width, height), using_xterm_cursor(false), - inset_slept(false) + using_xterm_cursor(false), inset_slept(false) { + workarea_.reset(new WorkArea(xpos, ypos, width, height)); + // Setup the signals - workarea_.scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB)); - workarea_.workAreaExpose + workarea_->scrollCB.connect(slot(this, &BufferView::Pimpl::scrollCB)); + workarea_->workAreaExpose .connect(slot(this, &BufferView::Pimpl::workAreaExpose)); - workarea_.workAreaEnter + workarea_->workAreaEnter .connect(slot(this, &BufferView::Pimpl::enterView)); - workarea_.workAreaLeave + workarea_->workAreaLeave .connect(slot(this, &BufferView::Pimpl::leaveView)); - workarea_.workAreaButtonPress + workarea_->workAreaButtonPress .connect(slot(this, &BufferView::Pimpl::workAreaButtonPress)); - workarea_.workAreaButtonRelease + workarea_->workAreaButtonRelease .connect(slot(this, &BufferView::Pimpl::workAreaButtonRelease)); - workarea_.workAreaMotionNotify + workarea_->workAreaMotionNotify .connect(slot(this, &BufferView::Pimpl::workAreaMotionNotify)); - workarea_.workAreaDoubleClick + workarea_->workAreaDoubleClick .connect(slot(this, &BufferView::Pimpl::doubleClick)); - workarea_.workAreaTripleClick + workarea_->workAreaTripleClick .connect(slot(this, &BufferView::Pimpl::tripleClick)); - workarea_.workAreaKeyPress + workarea_->workAreaKeyPress .connect(slot(this, &BufferView::Pimpl::workAreaKeyPress)); - workarea_.selectionRequested + workarea_->selectionRequested .connect(slot(this, &BufferView::Pimpl::selectionRequested)); - workarea_.selectionLost + workarea_->selectionLost .connect(slot(this, &BufferView::Pimpl::selectionLost)); cursor_timeout.timeout.connect(slot(this, &BufferView::Pimpl::cursorToggle)); cursor_timeout.start(); - workarea_.setFocus(); + workarea_->setFocus(); saved_positions.resize(saved_positions_num); } Painter & BufferView::Pimpl::painter() { - return workarea_.getPainter(); + return workarea_->getPainter(); } @@ -184,7 +185,7 @@ // only if the buffer is still loaded. // Also set the owner of the test to 0 // bv_->text->owner(0); - textcache.add(buffer_, workarea_.workWidth(), bv_->text); + textcache.add(buffer_, workarea_->workWidth(), bv_->text); if (lyxerr.debugging()) textcache.show(lyxerr, "BufferView::buffer"); @@ -232,7 +233,7 @@ owner_->updateToolbar(); owner_->getDialogs()->hideBufferDependent(); updateScrollbar(); - workarea_.redraw(); + workarea_->redraw(); // Also remove all remaining text's from the testcache. // (there should not be any!) (if there is any it is a @@ -250,7 +251,7 @@ void BufferView::Pimpl::resize(int xpos, int ypos, int width, int height) { - workarea_.resize(xpos, ypos, width, height); + workarea_->resize(xpos, ypos, width, height); update(bv_->text, SELECT); redraw(); } @@ -266,7 +267,7 @@ void BufferView::Pimpl::redraw() { lyxerr[Debug::INFO] << "BufferView::redraw()" << endl; - workarea_.redraw(); + workarea_->redraw(); } @@ -338,11 +339,11 @@ } else { // See if we have a text in TextCache that fits // the new buffer_ with the correct width. - bv_->text = textcache.findFit(buffer_, workarea_.workWidth()); + bv_->text = textcache.findFit(buffer_, workarea_->workWidth()); if (bv_->text) { if (lyxerr.debugging()) { lyxerr << "Found a LyXText that fits:\n"; - textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea_.workWidth(), bv_->text))); + textcache.show(lyxerr, make_pair(buffer_, +make_pair(workarea_->workWidth(), bv_->text))); } // Set the owner of the newly found text // bv_->text->owner(bv_); @@ -396,7 +397,7 @@ void BufferView::Pimpl::updateScreen() { // Regenerate the screen. - screen_.reset(new LyXScreen(workarea_)); + screen_.reset(new LyXScreen(*workarea_.get())); } @@ -404,12 +405,12 @@ { if (!bv_->text) { lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl; - workarea_.setScrollbar(0, 1.0); + workarea_->setScrollbar(0, 1.0); return; } long const text_height = bv_->text->height; - long const work_height = workarea_.height(); + long const work_height = workarea_->height(); double const lineh = bv_->text->defaultHeight(); double const slider_size = @@ -423,16 +424,16 @@ * be possible */ if (text_height <= work_height) { lyxerr[Debug::GUI] << "doc smaller than workarea !" << endl; - workarea_.setScrollbarBounds(0.0, 0.0); + workarea_->setScrollbarBounds(0.0, 0.0); current_scrollbar_value = bv_->text->first_y; - workarea_.setScrollbar(current_scrollbar_value, 1.0); + workarea_->setScrollbar(current_scrollbar_value, 1.0); return; } - workarea_.setScrollbarBounds(0.0, text_height - work_height); - workarea_.setScrollbarIncrements(lineh); + workarea_->setScrollbarBounds(0.0, text_height - work_height); + workarea_->setScrollbarIncrements(lineh); current_scrollbar_value = bv_->text->first_y; - workarea_.setScrollbar(current_scrollbar_value, slider_size); + workarea_->setScrollbar(current_scrollbar_value, slider_size); } @@ -462,7 +463,7 @@ int const height = vbt->defaultHeight(); int const first = static_cast<int>((bv_->text->first_y + height)); - int const last = static_cast<int>((bv_->text->first_y + workarea_.height() - height)); + int const last = static_cast<int>((bv_->text->first_y + workarea_->height() - +height)); if (vbt->cursor.y() < first) vbt->setCursorFromCoordinates(bv_, 0, first); @@ -478,7 +479,7 @@ if (!buffer_ || !screen_.get()) return 0; - double value = workarea_.getScrollbarValue(); + double value = workarea_->getScrollbarValue(); if (value == 0) return 0; @@ -487,11 +488,11 @@ float add_value = (bv_->text->defaultHeight() + float(time) * float(time) * 0.125); - if (add_value > workarea_.height()) - add_value = float(workarea_.height() - + if (add_value > workarea_->height()) + add_value = float(workarea_->height() - bv_->text->defaultHeight()); #else - float add_value = float(workarea_.height()) * float(time) / 100; + float add_value = float(workarea_->height()) * float(time) / 100; #endif value -= add_value; @@ -499,7 +500,7 @@ if (value < 0) value = 0; - workarea_.setScrollbarValue(value); + workarea_->setScrollbarValue(value); scrollCB(value); return 0; @@ -511,8 +512,8 @@ if (!buffer_ || !screen_.get()) return 0; - double value = workarea_.getScrollbarValue(); - pair<float, float> p = workarea_.getScrollbarBounds(); + double value = workarea_->getScrollbarValue(); + pair<float, float> p = workarea_->getScrollbarBounds(); double const max = p.second; if (value == max) @@ -522,11 +523,11 @@ float add_value = (bv_->text->defaultHeight() + float(time) * float(time) * 0.125); - if (add_value > workarea_.height()) - add_value = float(workarea_.height() - + if (add_value > workarea_->height()) + add_value = float(workarea_->height() - bv_->text->defaultHeight()); #else - float add_value = float(workarea_.height()) * float(time) / 100; + float add_value = float(workarea_->height()) * float(time) / 100; #endif value += add_value; @@ -534,7 +535,7 @@ if (value > max) value = max; - workarea_.setScrollbarValue(value); + workarea_->setScrollbarValue(value); scrollCB(value); return 0; @@ -594,7 +595,7 @@ #endif // This is to allow jumping over large insets if (cursorrow == bv_->text->cursor.row()) { - if (y >= int(workarea_.height())) { + if (y >= int(workarea_->height())) { bv_->text->cursorDown(bv_, false); } else if (y < 0) { bv_->text->cursorUp(bv_, false); @@ -799,14 +800,14 @@ bv_->text->xsel_cache.set(false); } if (!sel.empty()) { - workarea_.putClipboard(sel); + workarea_->putClipboard(sel); } } void BufferView::Pimpl::selectionLost() { - if (active() && available()) { + if (available()) { hideCursor(); toggleSelection(); bv_->getLyXText()->clearSelection(); @@ -818,8 +819,8 @@ void BufferView::Pimpl::enterView() { - if (active() && available()) { - SetXtermCursor(workarea_.getWin()); + if (available()) { + SetXtermCursor(workarea_->getWin()); using_xterm_cursor = true; } } @@ -828,7 +829,7 @@ void BufferView::Pimpl::leaveView() { if (using_xterm_cursor) { - XUndefineCursor(fl_get_display(), workarea_.getWin()); + XUndefineCursor(fl_get_display(), workarea_->getWin()); using_xterm_cursor = false; } } @@ -864,7 +865,7 @@ // finish selection if (button == mouse_button::button1) { - workarea_.haveSelection(bv_->getLyXText()->selection.set()); + workarea_->haveSelection(bv_->getLyXText()->selection.set()); } setState(); @@ -1034,12 +1035,12 @@ static int work_area_width; static unsigned int work_area_height; - bool const widthChange = workarea_.workWidth() != work_area_width; - bool const heightChange = workarea_.height() != work_area_height; + bool const widthChange = workarea_->workWidth() != work_area_width; + bool const heightChange = workarea_->height() != work_area_height; // update from work area - work_area_width = workarea_.workWidth(); - work_area_height = workarea_.height(); + work_area_width = workarea_->workWidth(); + work_area_height = workarea_->height(); if (buffer_ != 0) { if (widthChange) { // The visible LyXView need a resize @@ -1069,7 +1070,7 @@ screen_->redraw(bv_->text, bv_); } else { // Grey box when we don't have a buffer - workarea_.greyOut(); + workarea_->greyOut(); } // always make sure that the scrollbar is sane. @@ -1208,7 +1209,7 @@ { if (!text->cursor.row()->previous()) { if (text->first_y > 0) { - int new_y = bv_->text->first_y - workarea_.height(); + int new_y = bv_->text->first_y - workarea_->height(); screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y); updateScrollbar(); } @@ -1228,18 +1229,18 @@ // as we move the cursor or do something while inside the row (it may // span several workarea-heights) we'll move to the top again, but this // is better than just jump down and only display part of the row. - new_y = bv_->text->first_y - workarea_.height(); + new_y = bv_->text->first_y - workarea_->height(); } else { if (text->inset_owner) { new_y = bv_->text->cursor.iy() + bv_->theLockingInset()->insetInInsetY() + y + text->cursor.row()->height() - - workarea_.height() + 1; + - workarea_->height() + 1; } else { new_y = text->cursor.y() - text->cursor.row()->baseline() + text->cursor.row()->height() - - workarea_.height() + 1; + - workarea_->height() + 1; } } screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y); @@ -1260,15 +1261,15 @@ if (!text->cursor.row()->next()) { int y = text->cursor.y() - text->cursor.row()->baseline() + text->cursor.row()->height(); - if (y > int(text->first_y + workarea_.height())) { + if (y > int(text->first_y + workarea_->height())) { screen_->draw(bv_->text, bv_, - bv_->text->first_y + workarea_.height()); + bv_->text->first_y + +workarea_->height()); updateScrollbar(); } return; } - int y = text->first_y + workarea_.height(); + int y = text->first_y + workarea_->height(); if (text->inset_owner && !text->first_y) { y -= (bv_->text->cursor.iy() - bv_->text->first_y @@ -1286,7 +1287,7 @@ // as we move the cursor or do something while inside the row (it may // span several workarea-heights) we'll move to the top again, but this // is better than just jump down and only display part of the row. - new_y = bv_->text->first_y + workarea_.height(); + new_y = bv_->text->first_y + workarea_->height(); } else { if (text->inset_owner) { new_y = bv_->text->cursor.iy() @@ -1301,7 +1302,7 @@ LyXCursor cur; text->setCursor(bv_, cur, text->cursor.row()->next()->par(), text->cursor.row()->next()->pos(), false); - if (cur.y() < int(text->first_y + workarea_.height())) { + if (cur.y() < int(text->first_y + workarea_->height())) { text->cursorDown(bv_, true); } } @@ -1434,25 +1435,13 @@ bool BufferView::Pimpl::focus() const { - return workarea_.hasFocus(); + return workarea_->hasFocus(); } void BufferView::Pimpl::focus(bool f) { - if (f) workarea_.setFocus(); -} - - -bool BufferView::Pimpl::active() const -{ - return workarea_.active(); -} - - -bool BufferView::Pimpl::belowMouse() const -{ - return workarea_.belowMouse(); + if (f) workarea_->setFocus(); } @@ -1498,8 +1487,8 @@ void BufferView::Pimpl::center() { beforeChange(bv_->text); - if (bv_->text->cursor.y() > static_cast<int>((workarea_.height() / 2))) { - screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - workarea_.height() / 2); + if (bv_->text->cursor.y() > static_cast<int>((workarea_->height() / 2))) { + screen_->draw(bv_->text, bv_, bv_->text->cursor.y() - +workarea_->height() / 2); } else { screen_->draw(bv_->text, bv_, 0); } @@ -1516,7 +1505,7 @@ screen_->hideCursor(); beforeChange(bv_->text); - string const clip(workarea_.getClipboard()); + string const clip(workarea_->getClipboard()); if (clip.empty()) return; @@ -1533,7 +1522,7 @@ void BufferView::Pimpl::stuffClipboard(string const & stuff) const { - workarea_.putClipboard(stuff); + workarea_->putClipboard(stuff); } @@ -1568,7 +1557,7 @@ } if (!lt->selection.set()) - workarea_.haveSelection(false); + workarea_->haveSelection(false); /* ---> Everytime the cursor is moved, show the current font state. */ // should this too me moved out of this func? @@ -3306,7 +3295,7 @@ | BufferView::FITCUR | BufferView::CHANGE); } - workarea_.haveSelection(false); + workarea_->haveSelection(false); } beforeChange(lt); Index: src/BufferView_pimpl.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.h,v retrieving revision 1.52 diff -u -r1.52 BufferView_pimpl.h --- src/BufferView_pimpl.h 26 May 2002 17:33:07 -0000 1.52 +++ src/BufferView_pimpl.h 26 May 2002 20:57:58 -0000 @@ -6,13 +6,15 @@ #include "BufferView.h" #include "commandtags.h" #include "frontends/mouse_state.h" +#include "frontends/key_state.h" #include "frontends/Timeout.h" -// FIXME remove me -#include "frontends/WorkArea.h" #include "box.h" #include "insets/insetspecialchar.h" #include "support/types.h" +// FIXME: remove +#include <X11/Xlib.h> + #include <boost/scoped_ptr.hpp> #ifdef __GNUG__ @@ -117,10 +119,6 @@ /// void focus(bool); /// - bool active() const; - /// - bool belowMouse() const; - /// void showCursor(); /// void hideCursor(); @@ -176,11 +174,11 @@ /// boost::scoped_ptr<LyXScreen> screen_; /// + boost::scoped_ptr<WorkArea> workarea_; + /// long current_scrollbar_value; /// Timeout cursor_timeout; - /// - WorkArea workarea_; /// void pasteClipboard(bool asPara); /// Index: src/frontends/xforms/XWorkArea.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/XWorkArea.C,v retrieving revision 1.1 diff -u -r1.1 XWorkArea.C --- src/frontends/xforms/XWorkArea.C 26 May 2002 18:30:34 -0000 1.1 +++ src/frontends/xforms/XWorkArea.C 26 May 2002 20:58:14 -0000 @@ -245,21 +245,6 @@ } -bool WorkArea::belowMouse() const -{ - FL_Coord x, y; - unsigned int button; - fl_get_mouse(&x, &y, &button); - FL_Coord ulx = work_area->form->x + work_area->x; - FL_Coord uly = work_area->form->y + work_area->y; - FL_Coord w = work_area->w; - FL_Coord h = work_area->h; - if (x > ulx && y > uly && x < ulx + h && y < uly + w) - return true; - return false; -} - - void WorkArea::resize(int xpos, int ypos, int width, int height) { fl_freeze_all_forms(); Index: src/frontends/xforms/XWorkArea.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/XWorkArea.h,v retrieving revision 1.1 diff -u -r1.1 XWorkArea.h --- src/frontends/xforms/XWorkArea.h 26 May 2002 18:30:34 -0000 1.1 +++ src/frontends/xforms/XWorkArea.h 26 May 2002 20:58:14 -0000 @@ -62,10 +62,6 @@ /// bool hasFocus() const { return work_area->focus; } /// - bool active() const { return work_area->active; } - /// - bool belowMouse() const; - /// bool visible() const { return work_area->form->visible; } /// void greyOut() const;