+void wxGenericTreeItem::CalculateSize(wxGenericTreeCtrl* control)
+{
+ // check if we need to do anything before creating the DC
+ if ( m_width != 0 )
+ return;
+
+ wxClientDC dc(control);
+ DoCalculateSize(control, dc, false /* normal font not used */);
+}
+
+void
+wxGenericTreeItem::DoCalculateSize(wxGenericTreeCtrl* control,
+ wxDC& dc,
+ bool dcUsesNormalFont)
+{
+ if ( m_width != 0 ) // Size known, nothing to do
+ return;
+
+ if ( m_widthText == -1 )
+ {
+ bool fontChanged;
+ if ( SetFont(control, dc) )
+ {
+ fontChanged = true;
+ }
+ else // we have no special font
+ {
+ if ( !dcUsesNormalFont )
+ {
+ // but we do need to ensure that the normal font is used: notice
+ // that this doesn't count as changing the font as we don't need
+ // to restore it
+ dc.SetFont(control->m_normalFont);
+ }
+
+ fontChanged = false;
+ }
+
+ dc.GetTextExtent( GetText(), &m_widthText, &m_heightText );
+
+ // restore normal font if the DC used it previously and we changed it
+ if ( fontChanged )
+ dc.SetFont(control->m_normalFont);
+ }
+
+ int text_h = m_heightText + 2;
+
+ int image_h = 0, image_w = 0;
+ int image = GetCurrentImage();
+ if ( image != NO_IMAGE && control->m_imageListNormal )
+ {
+ control->m_imageListNormal->GetSize(image, image_w, image_h);
+ image_w += MARGIN_BETWEEN_IMAGE_AND_TEXT;
+ }
+
+ int state_h = 0, state_w = 0;
+ int state = GetState();
+ if ( state != wxTREE_ITEMSTATE_NONE && control->m_imageListState )
+ {
+ control->m_imageListState->GetSize(state, state_w, state_h);
+ if ( image_w != 0 )
+ state_w += MARGIN_BETWEEN_STATE_AND_IMAGE;
+ else
+ state_w += MARGIN_BETWEEN_IMAGE_AND_TEXT;
+ }
+
+ int img_h = wxMax(state_h, image_h);
+ m_height = wxMax(img_h, text_h);
+
+ if (m_height < 30)
+ m_height += 2; // at least 2 pixels
+ else
+ m_height += m_height / 10; // otherwise 10% extra spacing
+
+ if (m_height > control->m_lineHeight)
+ control->m_lineHeight = m_height;
+
+ m_width = state_w + image_w + m_widthText + 2;
+}
+
+void wxGenericTreeItem::RecursiveResetSize()
+{
+ m_width = 0;
+
+ const size_t count = m_children.Count();
+ for (size_t i = 0; i < count; i++ )
+ m_children[i]->RecursiveResetSize();
+}
+
+void wxGenericTreeItem::RecursiveResetTextSize()
+{
+ m_width = 0;
+ m_widthText = -1;
+
+ const size_t count = m_children.Count();
+ for (size_t i = 0; i < count; i++ )
+ m_children[i]->RecursiveResetTextSize();
+}
+