Ticket URL: <
http://trac.wxwidgets.org/ticket/15390#comment:2>
#15390: wxTreeCtrl::GetItemFont() returns null font - setting it again increases
font size
----------------------+-----------------------------------------------------
Reporter: daumling | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: wxMSW | Version: 2.9.4
Keywords: | Blockedby:
Patch: 0 | Blocking:
----------------------+-----------------------------------------------------
Changes (by daumling):
* status: infoneeded_new => new
Comment:
I checked GetItemFont(). The item is not part of m_attrs, so the call
returns wxNullFont. So I thiught I'd be clever, and set the background
color of the item to black to force an entry of the item in the m_attrs
map, but no joy. The font stored in the entry's wxTreeItemAttr class
appears to be the default system font.
IMHO, the change to ItemGetFont() should be as follows:
1) If the m_attrs map already has a wxTreeItemAttr entry, fine.
2) Create a new wxFont using the handle returned by a
SendMessage(getHWND(), WM_GETFONT, 0, 0).
3) Store that font into a new wxTreeItemAttr and store it into the m_attrs
map.
4) Return that font.
The following patch works, but it is ugly and nowhere near production
quality:
#include <wx/fontutil.h>
wxFont wxTreeCtrl::GetItemFont(const wxTreeItemId& item) const
{
wxCHECK_MSG( item.IsOk(), wxNullFont, wxT("invalid tree item") );
wxMapTreeAttr::const_iterator it = m_attrs.find(item.m_pItem);
if (it != m_attrs.end())
return it->second->GetFont();
HFONT hFont = (HFONT) ::SendMessage(GetHWND(), WM_GETFONT, 0, 0);
LOGFONT lf;
::GetObject(hFont, sizeof(LOGFONT), &lf);
wxNativeFontInfo dummy(lf);
wxFont font(dummy, hFont);
wxTreeCtrl* self = const_cast<wxTreeCtrl*>(this);
self->m_hasAnyAttr = true;
wxTreeItemAttr *attr;
self->m_attrs[item.m_pItem] =
attr = new wxTreeItemAttr;
attr->SetFont(font);
return attr->GetFont();
}
Hope this helps.
--
Ticket URL: <
http://trac.wxwidgets.org/ticket/15390#comment:2>