X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0c6afdbf4ca53111339a65994bedc29da138b2f4..58cccb3b449cff705230aadb936c891b7fa6fd28:/samples/treectrl/treetest.cpp diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index a6c3435ade..759c7c5067 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -50,6 +50,9 @@ #include "state4.xpm" #include "state5.xpm" +#include "unchecked.xpm" +#include "checked.xpm" + #ifndef __WXMSW__ #include "../sample.xpm" #endif @@ -677,6 +680,11 @@ void MyFrame::OnToggleAlternateStates(wxCommandEvent& WXUNUSED(event)) m_treeCtrl->SetAlternateStates(!alternateStates); m_treeCtrl->CreateStateImageList(); + + // normal states < alternate states + // so we must reset broken states + if ( alternateStates ) + m_treeCtrl->ResetBrokenStateImages(); } void MyFrame::OnToggleButtons(wxCommandEvent& WXUNUSED(event)) @@ -925,40 +933,18 @@ void MyTreeCtrl::CreateStateImageList(bool del) } else { -#if 0 - int width = ::GetSystemMetrics(SM_CXMENUCHECK), - height = ::GetSystemMetrics(SM_CYMENUCHECK); -#else - int width = 16; - int height = 16; -#endif - - // make an state checkbox image list + wxIcon icons[2]; + icons[0] = wxIcon(unchecked_xpm); + icons[1] = wxIcon(checked_xpm); + + int width = icons[0].GetWidth(), + height = icons[0].GetHeight(); + + // Make an state image list containing small icons states = new wxImageList(width, height, true); - wxBitmap checkBmp(width, height); - wxRect rect (0, 0, width, height); - - wxRendererNative& renderer = wxRendererNative::Get(); - - // create no checked image - { - // first create bitmap in a memory DC - wxMemoryDC memDC(checkBmp); - memDC.Clear(); - // then draw a check mark into it - renderer.DrawCheckBox(this, memDC, rect, 0); - } // select checkBmp out of memDC - - states->Add(checkBmp); - - // create checked image - { - wxMemoryDC memDC(checkBmp); - renderer.DrawCheckBox(this, memDC, rect, wxCONTROL_CHECKED); - } - - states->Add(checkBmp); + for ( size_t i = 0; i < WXSIZEOF(icons); i++ ) + states->Add(icons[i]); } AssignStateImageList(states); @@ -1171,6 +1157,29 @@ void MyTreeCtrl::DoToggleState(const wxTreeItemId& item) } } +void MyTreeCtrl::DoResetBrokenStateImages(const wxTreeItemId& idParent, + wxTreeItemIdValue cookie, int state) +{ + wxTreeItemId id; + + if ( !cookie ) + id = GetFirstChild(idParent, cookie); + else + id = GetNextChild(idParent, cookie); + + if ( !id.IsOk() ) + return; + + int curState = GetItemState(id); + if ( curState != wxTREE_ITEMSTATE_NONE && curState > state ) + SetItemState(id, state); + + if (ItemHasChildren(id)) + DoResetBrokenStateImages(id, 0, state); + + DoResetBrokenStateImages(idParent, cookie, state); +} + void MyTreeCtrl::LogEvent(const wxChar *name, const wxTreeEvent& event) { wxTreeItemId item = event.GetItem(); @@ -1487,6 +1496,8 @@ void MyTreeCtrl::OnContextMenu(wxContextMenuEvent& event) wxPoint pt = event.GetPosition(); wxLogMessage(wxT("OnContextMenu at screen coords (%i, %i)"), pt.x, pt.y); + + event.Skip(); } void MyTreeCtrl::ShowMenu(wxTreeItemId id, const wxPoint& pt)