int LyXText::workWidth(BufferView * bview, Inset * inset) const
{
Paragraph * par = 0;
- pos_type pos = 0;
-
- Buffer::inset_iterator it = bview->buffer()->inset_iterator_begin();
- Buffer::inset_iterator end = bview->buffer()->inset_iterator_end();
- for ( ; it != end; ++it) {
- if (*it == inset) {
- par = it.getPar();
- pos = it.getPos();
- break;
+ pos_type pos = -1;
+
+ par = inset->parOwner();
+ if (par)
+ pos = par->getPositionOfInset(inset);
+
+ if (!par || pos == -1) {
+ lyxerr << "LyXText::workWidth: something is wrong,"
+ " fall back to the brute force method" << endl;
+ Buffer::inset_iterator it = bview->buffer()->inset_iterator_begin();
+ Buffer::inset_iterator end = bview->buffer()->inset_iterator_end();
+ for ( ; it != end; ++it) {
+ if (*it == inset) {
+ par = it.getPar();
+ pos = it.getPos();
+ break;
+ }
}
}
+
if (!par) {
return workWidth(bview);
}
y_top += asc;
int const w = (inset_owner ? inset_owner->width(p.bv, font) : ww);
- int const xp = static_cast<int>(inset_owner ? p.x : 0);
- p.pain->line(xp, p.yo + y_top, w, p.yo + y_top,
+ int const xp = static_cast<int>(inset_owner ? p.xo : 0);
+ p.pain->line(xp, p.yo + y_top, xp + w, p.yo + y_top,
LColor::topline, Painter::line_solid,
Painter::line_thick);
y_bottom -= asc;
int const w = (inset_owner ? inset_owner->width(p.bv, font) : ww);
- int const xp = static_cast<int>(inset_owner ? p.x : 0);
+ int const xp = static_cast<int>(inset_owner ? p.xo : 0);
int const y = p.yo + y_bottom;
- p.pain->line(xp, y, w, y, LColor::topline, Painter::line_solid,
+ p.pain->line(xp, y, xp + w, y, LColor::topline, Painter::line_solid,
Painter::line_thick);
y_bottom -= asc;