Infinite recursion elimination
| 582 | |
| 583 | static bool GraphicsInSizeToContents = false; // Infinite recursion elimination |
| 584 | void wxShape::FormatText(wxDC& dc, const wxString& s, int i) |
| 585 | { |
| 586 | double w, h; |
| 587 | ClearText(i); |
| 588 | |
| 589 | if (m_regions.GetCount() < 1) |
| 590 | return; |
| 591 | wxNode *node = m_regions.Item(i); |
| 592 | if (!node) |
| 593 | return; |
| 594 | |
| 595 | wxShapeRegion *region = (wxShapeRegion *)node->GetData(); |
| 596 | // region->SetText(s); // don't set the formatted text yet, it will be done below |
| 597 | region->m_regionText = s; |
| 598 | dc.SetFont(* region->GetFont()); |
| 599 | |
| 600 | region->GetSize(&w, &h); |
| 601 | |
| 602 | wxStringList *stringList = oglFormatText(dc, s, (w-2*m_textMarginX), (h-2*m_textMarginY), region->GetFormatMode()); |
| 603 | node = (wxNode*)stringList->GetFirst(); |
| 604 | while (node) |
| 605 | { |
| 606 | wxChar *s = (wxChar *)node->GetData(); |
| 607 | wxShapeTextLine *line = new wxShapeTextLine(0.0, 0.0, s); |
| 608 | region->GetFormattedText().Append((wxObject *)line); |
| 609 | node = node->GetNext(); |
| 610 | } |
| 611 | delete stringList; |
| 612 | double actualW = w; |
| 613 | double actualH = h; |
| 614 | // Don't try to resize an object with more than one image (this case should be dealt |
| 615 | // with by overriden handlers) |
| 616 | if ((region->GetFormatMode() & FORMAT_SIZE_TO_CONTENTS) && |
| 617 | (region->GetFormattedText().GetCount() > 0) && |
| 618 | (m_regions.GetCount() == 1) && !GraphicsInSizeToContents) |
| 619 | { |
| 620 | oglGetCentredTextExtent(dc, &(region->GetFormattedText()), m_xpos, m_ypos, w, h, &actualW, &actualH); |
| 621 | if ((actualW+2*m_textMarginX != w ) || (actualH+2*m_textMarginY != h)) |
| 622 | { |
| 623 | // If we are a descendant of a composite, must make sure the composite gets |
| 624 | // resized properly |
| 625 | wxShape *topAncestor = GetTopAncestor(); |
| 626 | |
| 627 | if (topAncestor != this) |
| 628 | { |
| 629 | // Make sure we don't recurse infinitely |
| 630 | GraphicsInSizeToContents = true; |
| 631 | |
| 632 | wxCompositeShape *composite = (wxCompositeShape *)topAncestor; |
| 633 | composite->Erase(dc); |
| 634 | SetSize(actualW+2*m_textMarginX, actualH+2*m_textMarginY); |
| 635 | Move(dc, m_xpos, m_ypos); |
| 636 | composite->CalculateSize(); |
| 637 | if (composite->Selected()) |
| 638 | { |
| 639 | composite->DeleteControlPoints(& dc); |
| 640 | composite->MakeControlPoints(); |
| 641 | composite->MakeMandatoryControlPoints(); |
no test coverage detected