* \brief Scrolls the viewport, so that the region between \em it1 and * \em it2 is seen, according to \em hpos and \em vpos. * * The parameters \em start and \em end have the same meaning as in * dw::core::Iterator::getAllocation, \em start refers * to \em it1, while \em end rerers to \em it2. * * If \em it1 and \em it2 point to the same location (see code), only * \em it1 is regarded, and
| 96 | * \em it1 is regarded, and both belowstart and belowend refer to it. |
| 97 | */ |
| 98 | void Iterator::scrollTo (Iterator *it1, Iterator *it2, int start, int end, |
| 99 | HPosition hpos, VPosition vpos) |
| 100 | { |
| 101 | Allocation alloc1, alloc2, alloc; |
| 102 | int x1, x2, y1, y2; |
| 103 | DeepIterator *eit1, *eit2, *eit3; |
| 104 | int curStart, curEnd, cmp; |
| 105 | bool atStart; |
| 106 | |
| 107 | if (it1->equals(it2)) { |
| 108 | it1->getAllocation (start, end, &alloc); |
| 109 | it1->getWidget()->getLayout()->scrollTo (hpos, vpos, alloc.x, alloc.y, |
| 110 | alloc.width, |
| 111 | alloc.ascent + alloc.descent); |
| 112 | } else { |
| 113 | // First, determine the rectangle all iterators from it1 and it2 |
| 114 | // allocate, i.e. the smallest rectangle containing all allocations of |
| 115 | // these iterators. |
| 116 | eit1 = new DeepIterator (it1); |
| 117 | eit2 = new DeepIterator (it2); |
| 118 | |
| 119 | x1 = INT_MAX; |
| 120 | x2 = INT_MIN; |
| 121 | y1 = INT_MAX; |
| 122 | y2 = INT_MIN; |
| 123 | |
| 124 | for (atStart = true, eit3 = (DeepIterator*)eit1->clone (); |
| 125 | (cmp = eit3->compareTo (eit2)) <= 0; |
| 126 | eit3->next (), atStart = false) { |
| 127 | if (atStart) |
| 128 | curStart = start; |
| 129 | else |
| 130 | curStart = 0; |
| 131 | |
| 132 | if (cmp == 0) |
| 133 | curEnd = end; |
| 134 | else |
| 135 | curEnd = INT_MAX; |
| 136 | |
| 137 | eit3->getAllocation (curStart, curEnd, &alloc); |
| 138 | x1 = misc::min (x1, alloc.x); |
| 139 | x2 = misc::max (x2, alloc.x + alloc.width); |
| 140 | y1 = misc::min (y1, alloc.y); |
| 141 | y2 = misc::max (y2, alloc.y + alloc.ascent + alloc.descent); |
| 142 | } |
| 143 | |
| 144 | delete eit3; |
| 145 | delete eit2; |
| 146 | delete eit1; |
| 147 | |
| 148 | it1->getAllocation (start, INT_MAX, &alloc1); |
| 149 | it2->getAllocation (0, end, &alloc2); |
| 150 | |
| 151 | if (alloc1.x > alloc2.x) { |
| 152 | // |
| 153 | // This is due to a line break within the region. When the line is |
| 154 | // longer than the viewport, and the region is actually quite short, |
| 155 | // the user would not see anything of the region, as in this figure |
nothing calls this directly
no test coverage detected