void PhoneBook::AddEntry(const Entry& anEntry) { const char* pName = anEntry.Name(); if (pName && pName != '\0') { int length = strlen(pName); char key; Node* currNode = iRoot; Node* childNode = NULL; Entry blankEntry(NULL, NULL); for (int index = 0; index < length; index++) { key = pName[index]; childNode = currNode->GetChildNodeByKey(key); //if this is a new node, create one if (!childNode) { //If we have reaches the last character, then its a terminal node if (index == length-1) { //So store the Entry childNode = new Node(key, anEntry); childNode->IsTerminal(true); } else { //Not a terminal node, so dont have to store anything, store some dummy value childNode = new Node(key, blankEntry); } //Add the Node to the currNode currNode->AddChild(childNode); currNode = childNode; } else { currNode = childNode; } } } }
void MainFrame::OnTreeSelectionChanged(wxTreeEvent &event) { auto treeItemId = event.GetItem(); auto rootId = dirTree->GetRootItem(); auto currentFileEntry = dynamic_cast<EntryItemData *>(dirTree->GetItemData(treeItemId))->Get(); auto gridPanel = dynamic_cast<wxScrolledWindow *>(splitter->GetWindow2()); if (loadThread) { loadThread->Delete(nullptr, wxTHREAD_WAIT_BLOCK); loadThread = nullptr; } gridPanel->Show(false); auto grid = gridPanel->GetSizer(); grid->Clear(true); std::vector<Entry *> loadEntries; imgButtons.clear(); for (int i = 0; i < currentFileEntry->Count(); ++i) { Entry *childEntry = (*currentFileEntry)[i]; if (childEntry->IsDirectory()) continue; auto ext = childEntry->Name().AfterLast('.').Lower(); if (ext != "jpg" && ext != "jpeg" && ext != "png" && ext != "gif") continue; loadEntries.push_back(childEntry); } for (auto entry : loadEntries) { auto button = new wxButton(gridPanel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); imgButtons.push_back(button); button->Bind(wxEVT_BUTTON, &MainFrame::OnImageButtonClick, this); button->SetClientObject(new EntryItemData(entry)); button->SetMinSize({250, 250}); auto staticText = new wxStaticText(gridPanel, wxID_ANY, entry->Name()); staticText->SetMaxSize({250, 50}); auto btnSizer = new wxBoxSizer(wxVERTICAL); btnSizer->Add(button, 0, wxEXPAND); btnSizer->Add(staticText); grid->Add(btnSizer, 0, wxALL | wxEXPAND, 5); } GetStatusBar()->SetStatusText(wxString::Format("Loading Thumbnail %i of %i", 1, (int)loadEntries.size())); grid->FitInside(gridPanel); gridPanel->Show(true); gridPanel->Scroll(0, 0); gridPanel->Refresh(); gridPanel->Update(); loadThread = new ThumbnailLoadThread(this, loadEntries, currentEntry); loadThread->Run(); threadId = loadThread->GetId(); }