+ // is there a better way of getting these two iterators?
+ DocIterator beg = cur;
+ DocIterator end = cur;
+
+ beg.top() = cur.selBegin();
+ end.top() = cur.selEnd();
+
+ // the selection doesn't touch the visible screen
+ if (bv_funcs::status(pi.base.bv, beg) == bv_funcs::CUR_BELOW
+ || bv_funcs::status(pi.base.bv, end) == bv_funcs::CUR_ABOVE)
+ return;
+
+ Paragraph const & par1 = pars_[beg.pit()];
+ Paragraph const & par2 = pars_[end.pit()];
+
+ bool const above = (bv_funcs::status(pi.base.bv, beg)
+ == bv_funcs::CUR_ABOVE);
+ bool const below = (bv_funcs::status(pi.base.bv, end)
+ == bv_funcs::CUR_BELOW);
+ int y1,y2,x1,x2;
+ if (above) {
+ y1 = 0;
+ y2 = 0;
+ x1 = 0;
+ x2 = dim_.wid;
+ } else {
+ Row const & row1 = par1.getRow(beg.pos());
+ y1 = bv_funcs::getPos(beg).y_ - row1.ascent();
+ y2 = y1 + row1.height();
+ int const startx = cursorX(beg.top());
+ x1 = !isRTL(par1) ? startx : 0;
+ x2 = !isRTL(par1) ? 0 + dim_.wid : startx;
+ }
+
+ int Y1,Y2,X1,X2;
+ if (below) {
+ Y1 = pi.base.bv->workHeight();
+ Y2 = pi.base.bv->workHeight();
+ X1 = 0;
+ X2 = dim_.wid;
+ } else {
+ Row const & row2 = par2.getRow(end.pos());
+ Y1 = bv_funcs::getPos(end).y_ - row2.ascent();
+ Y2 = Y1 + row2.height();
+ int const endx = cursorX(end.top());
+ X1 = !isRTL(par2) ? 0 : endx;
+ X2 = !isRTL(par2) ? endx : 0 + dim_.wid;
+ }
+
+ if (!above && !below && &par1.getRow(beg.pos())
+ == &par2.getRow(end.pos()))
+ {
+ // paint only one rectangle
+ pi.pain.fillRectangle(x + x1, y1, X2 - x1, y2 - y1,
+ LColor::selection);
+ return;
+ }
+
+ // paint upper rectangle
+ pi.pain.fillRectangle(x + x1, y1, x2 - x1, y2 - y1,
+ LColor::selection);
+ // paint bottom rectangle
+ pi.pain.fillRectangle(x + X1, Y1, X2 - X1, Y2 - Y1,
+ LColor::selection);
+ // paint center rectangle
+ pi.pain.fillRectangle(x, y2, dim_.wid,
+ Y1 - y2, LColor::selection);
+}