void MyTreeCtrl::CreateButtonsImageList(int size) { if ( size == -1 ) { SetButtonsImageList(NULL); return; } // Make an image list containing small icons wxImageList *images = new wxImageList(size, size, true); // should correspond to TreeCtrlIcon_xxx enum wxBusyCursor wait; wxIcon icons[4]; icons[0] = wxIcon(icon3_xpm); // closed icons[1] = wxIcon(icon3_xpm); // closed, selected icons[2] = wxIcon(icon5_xpm); // open icons[3] = wxIcon(icon5_xpm); // open, selected for ( size_t i = 0; i < WXSIZEOF(icons); i++ ) { int sizeOrig = icons[i].GetWidth(); if ( size == sizeOrig ) { images->Add(icons[i]); } else { images->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size))); } } AssignButtonsImageList(images); #else void MyTreeCtrl::CreateButtonsImageList(int WXUNUSED(size)) { #endif } int MyTreeCtrl::OnCompareItems(const wxTreeItemId& item1, const wxTreeItemId& item2) { if ( m_reverseSort ) { // just exchange 1st and 2nd items return wxTreeCtrl::OnCompareItems(item2, item1); } else { return wxTreeCtrl::OnCompareItems(item1, item2); } } void MyTreeCtrl::AddItemsRecursively(const wxTreeItemId& idParent, size_t numChildren, size_t depth, size_t folder) { if ( depth > 0 ) { bool hasChildren = depth > 1; wxString str; for ( size_t n = 0; n < numChildren; n++ ) { // at depth 1 elements won't have any more children if ( hasChildren ) str.Printf(wxT("%s child %u"), wxT("Folder"), unsigned(n + 1)); else str.Printf(wxT("%s child %u.%u"), wxT("File"), unsigned(folder), unsigned(n + 1)); // here we pass to AppendItem() normal and selected item images (we // suppose that selected image follows the normal one in the enum) int image, imageSel; if ( wxGetApp().ShowImages() ) { image = depth == 1 ? TreeCtrlIcon_File : TreeCtrlIcon_Folder; imageSel = image + 1; } else { image = imageSel = -1; } wxTreeItemId id = AppendItem(idParent, str, image, imageSel, new MyTreeItemData(str)); // and now we also set the expanded one (only for the folders) if ( hasChildren && wxGetApp().ShowImages() ) { SetItemImage(id, TreeCtrlIcon_FolderOpened, wxTreeItemIcon_Expanded); } // remember the last child for OnEnsureVisible() if ( !hasChildren && n == numChildren - 1 ) { m_lastItem = id; } AddItemsRecursively(id, numChildren, depth - 1, n + 1); } } //else: done! } void MyTreeCtrl::AddTestItemsToTree(size_t numChildren, size_t depth) { int image = wxGetApp().ShowImages() ? MyTreeCtrl::TreeCtrlIcon_Folder : -1; wxTreeItemId rootId = AddRoot(wxT("Root"), image, image, new MyTreeItemData(wxT("Root item"))); if ( !HasFlag(wxTR_HIDE_ROOT) && image != -1 ) { SetItemImage(rootId, TreeCtrlIcon_FolderOpened, wxTreeItemIcon_Expanded); } AddItemsRecursively(rootId, numChildren, depth, 0); // set some colours/fonts for testing if ( !HasFlag(wxTR_HIDE_ROOT) ) SetItemFont(rootId, *wxITALIC_FONT); wxTreeItemIdValue cookie; wxTreeItemId id = GetFirstChild(rootId, cookie); SetItemTextColour(id, *wxBLUE); id = GetNextChild(rootId, cookie); id = GetNextChild(rootId, cookie); SetItemTextColour(id, *wxRED); SetItemBackgroundColour(id, *wxLIGHT_GREY); }
void OPJMarkerTree::CreateButtonsImageList(int size) { if ( size == -1 ) { SetButtonsImageList(NULL); return; } // Make an image list containing small icons wxImageList *images = new wxImageList(size, size, true); // should correspond to TreeCtrlIcon_xxx enum wxBusyCursor wait; wxIcon icons[4]; icons[0] = wxIcon(icon3_xpm); // closed icons[1] = wxIcon(icon3_xpm); // closed, selected icons[2] = wxIcon(icon5_xpm); // open icons[3] = wxIcon(icon5_xpm); // open, selected for ( size_t i = 0; i < WXSIZEOF(icons); i++ ) { int sizeOrig = icons[i].GetWidth(); if ( size == sizeOrig ) { images->Add(icons[i]); } else { images->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size))); } } AssignButtonsImageList(images); #else void OPJMarkerTree::CreateButtonsImageList(int WXUNUSED(size)) { #endif } void OPJParseThread::LoadFile(wxFileName fname) { wxTreeItemId rootid; // this is the root node int image = wxGetApp().ShowImages() ? m_tree->TreeCtrlIcon_Folder : -1; if (this->m_parentid) { // leaf of a tree rootid = m_parentid; m_tree->SetItemText(rootid, wxT("Parsing...")); } else { // delete the existing tree hierarchy m_tree->DeleteAllItems(); // new tree rootid = m_tree->AddRoot(wxT("Parsing..."), image, image, new OPJMarkerData(fname.GetFullPath()) ); //m_tree->SetItemFont(rootid, *wxITALIC_FONT); m_tree->SetItemBold(rootid); } // open the file wxFile m_file(fname.GetFullPath().c_str(), wxFile::read); // parsing enabled? if (wxGetApp().m_enableparse) { // what is the extension? if ((fname.GetExt() == wxT("j2k")) || (fname.GetExt() == wxT("j2c"))) { // parse the file ParseJ2KFile(&m_file, 0, m_file.Length(), rootid); } else if ((fname.GetExt() == wxT("jp2")) || (fname.GetExt() == wxT("mj2"))) { // parse the file if (this->m_parentid) { //WriteText(wxT("Only a subsection of jp2")); OPJMarkerData *data = (OPJMarkerData *) m_tree->GetItemData(rootid); ParseJ2KFile(&m_file, data->m_start, data->m_length, rootid); m_tree->Expand(rootid); } else { // as usual ParseJP2File(&m_file, 0, m_file.Length(), rootid); } } else { // unknown extension WriteText(wxT("Unknown file format!")); } } // this is the root node if (this->m_parentid) m_tree->SetItemText(rootid, wxT("Codestream")); else //m_tree->SetItemText(rootid, wxString::Format(wxT("%s (%d B)"), fname.GetFullName(), m_file.Length())); m_tree->SetItemText(rootid, fname.GetFullName()); // close the file m_file.Close(); WriteText(wxT("Parsing finished!")); }