/// Gets the style combined with the base style
wxTextAttr wxRichTextStyleDefinition::GetStyleMergedWithBase(const wxRichTextStyleSheet* sheet) const
{
- if (!m_baseStyle.IsEmpty())
+ if (m_baseStyle.IsEmpty())
+ return m_style;
+
+ // Collect the styles, detecting loops
+ wxArrayString styleNames;
+ wxList styles;
+ const wxRichTextStyleDefinition* def = this;
+ while (def)
{
- wxRichTextStyleDefinition* baseStyle = sheet->FindStyle(m_baseStyle);
- if (baseStyle)
- {
- wxTextAttr baseAttr = baseStyle->GetStyleMergedWithBase(sheet);
- baseAttr.Apply(m_style, NULL);
- return baseAttr;
- }
+ styles.Insert((wxObject*) def);
+ styleNames.Add(def->GetName());
+
+ wxString baseStyleName = def->GetBaseStyle();
+ if (!baseStyleName.IsEmpty() && styleNames.Index(baseStyleName) == wxNOT_FOUND)
+ def = sheet->FindStyle(baseStyleName);
+ else
+ def = NULL;
+ }
+
+ wxRichTextAttr attr;
+ wxList::compatibility_iterator node = styles.GetFirst();
+ while (node)
+ {
+ wxRichTextStyleDefinition* def = (wxRichTextStyleDefinition*) node->GetData();
+ attr.Apply(def->GetStyle(), NULL);
+ node = node->GetNext();
}
- return m_style;
+
+ return attr;
}
/*!
{
if (GetStyleSheet())
{
+ int oldSel = GetSelection();
+
SetSelection(wxNOT_FOUND);
m_styleNames.Clear();
Refresh();
- if (GetItemCount() > 0)
+ int newSel = -1;
+ if (oldSel >= 0 && oldSel < (int) GetItemCount())
+ newSel = oldSel;
+ else if (GetItemCount() > 0)
+ newSel = 0;
+
+ if (newSel >= 0)
{
- SetSelection(0);
+ SetSelection(newSel);
SendSelectedEvent();
}
}
int size = 3;
#endif
- // Guess a standard font size
+ // Guess a standard font size
int stdFontSize = 0;
// First see if we have a default/normal style to base the size on
size_t i;
for (i = 0; i < m_styleNames.GetCount(); i++)
{
- wxString name = m_styleNames[i].Lower();
- if (name.Find(wxT("normal")) != wxNOT_FOUND || name.Find(normalTranslated) != wxNOT_FOUND ||
- name.Find(wxT("default")) != wxNOT_FOUND || name.Find(defaultTranslated) != wxNOT_FOUND)
- {
- wxRichTextStyleDefinition* d = GetStyleSheet()->FindStyle(m_styleNames[i]);
- if (d)
- {
- wxRichTextAttr attr2(d->GetStyleMergedWithBase(GetStyleSheet()));
- if (attr2.HasFontSize())
- {
- stdFontSize = attr2.GetFontSize();
- break;
- }
- }
- }
- }
+ wxString name = m_styleNames[i].Lower();
+ if (name.Find(wxT("normal")) != wxNOT_FOUND || name.Find(normalTranslated) != wxNOT_FOUND ||
+ name.Find(wxT("default")) != wxNOT_FOUND || name.Find(defaultTranslated) != wxNOT_FOUND)
+ {
+ wxRichTextStyleDefinition* d = GetStyleSheet()->FindStyle(m_styleNames[i]);
+ if (d)
+ {
+ wxRichTextAttr attr2(d->GetStyleMergedWithBase(GetStyleSheet()));
+ if (attr2.HasFontSize())
+ {
+ stdFontSize = attr2.GetFontSize();
+ break;
+ }
+ }
+ }
+ }
if (stdFontSize == 0)
{
{
if (sizes[i] > mostCommonSize)
mostCommonSize = i;
- }
+ }
if (mostCommonSize > 0)
stdFontSize = mostCommonSize;
}
if (stdFontSize == 0)
- stdFontSize = 12;
+ stdFontSize = 12;
int thisFontSize = ((attr.GetFlags() & wxTEXT_ATTR_FONT_SIZE) != 0) ? attr.GetFontSize() : stdFontSize;
{
wxVListBox::OnLeftDown(event);
- int item = HitTest(event.GetPosition());
+ int item = VirtualHitTest(event.GetPosition().y);
if (item != wxNOT_FOUND && GetApplyOnSelection())
ApplyStyle(item);
}
{
wxVListBox::OnLeftDown(event);
- int item = HitTest(event.GetPosition());
+ int item = VirtualHitTest(event.GetPosition().y);
if (item != wxNOT_FOUND && !GetApplyOnSelection())
ApplyStyle(item);
}
return;
wxRichTextStyleListBox::wxRichTextStyleType styleType = StyleIndexToType(event.GetSelection());
+ m_styleListBox->SetSelection(-1);
m_styleListBox->SetStyleType(styleType);
}
}
{
// Move selection to cursor if it is inside the popup
- int itemHere = wxRichTextStyleListBox::HitTest(event.GetPosition());
+ int itemHere = wxRichTextStyleListBox::VirtualHitTest(event.GetPosition().y);
if ( itemHere >= 0 )
{
wxRichTextStyleListBox::SetSelection(itemHere);