#include "frmMain.h" class tocItemTreeData : public wxTreeItemData { public: uint32_t itemIndex; tocItemTreeData() : wxTreeItemData() { }; }; frmMain::frmMain( wxWindow* parent, ODT::ODT *document ) : frmMainADT( parent ) , document( document ) { wxTreeItemId rootItem = treHelpTopics->AddRoot("Xestia Address Book", -1, -1, nullptr); wxTreeItemId previousItem; wxTreeItemId lastItemAtLevel[9]; lastItemAtLevel[ODT::HelpTopicCurrentLevel::TOPIC_LEVEL1] = rootItem; uint32_t itemIndex = 0; for (auto tocItem : document->tocData) { if (tocItem.tocItemLevel == ODT::HelpTopicCurrentLevel::TOPIC_LEVEL1) { lastItemAtLevel[0] = treHelpTopics->AppendItem(rootItem, tocItem.tocItemName, -1, -1, nullptr); tocItem.tocItemData = lastItemAtLevel[0].GetID(); } else if (tocItem.tocItemLevel == ODT::HelpTopicCurrentLevel::TOPIC_LEVEL2) { lastItemAtLevel[1] = treHelpTopics->AppendItem(lastItemAtLevel[0], tocItem.tocItemName, -1, -1, nullptr); tocItem.tocItemData = lastItemAtLevel[1].GetID(); } else if (tocItem.tocItemLevel == ODT::HelpTopicCurrentLevel::TOPIC_LEVEL3) { lastItemAtLevel[2] = treHelpTopics->AppendItem(lastItemAtLevel[1], tocItem.tocItemName, -1, -1, nullptr); tocItem.tocItemData = lastItemAtLevel[2].GetID(); } else if (tocItem.tocItemLevel == ODT::HelpTopicCurrentLevel::TOPIC_LEVEL4) { lastItemAtLevel[3] = treHelpTopics->AppendItem(lastItemAtLevel[2], tocItem.tocItemName, -1, -1, nullptr); tocItem.tocItemData = lastItemAtLevel[3].GetID(); } else { wxTreeItemId newItem = treHelpTopics->AppendItem(rootItem, tocItem.tocItemName, -1, -1, nullptr); tocItem.tocItemData = newItem.GetID(); } tocItemTreeData *tocItemIndexData = new tocItemTreeData(); tocItemIndexData->itemIndex = itemIndex; treHelpTopics->SetItemData(tocItem.tocItemData, tocItemIndexData); itemIndex++; } // Load in the images. SetTitle(document->title); } void frmMain::UpdateHelpTopic( wxTreeEvent& event ) { wxTreeItemId currentTreeItem = event.GetItem(); tocItemTreeData *tocItemData = static_cast(treHelpTopics->GetItemData(currentTreeItem)); std::string pageData; pageData += "

" + std::string(treHelpTopics->GetItemText(currentTreeItem).ToStdString()) + "

\n"; // Process the help topic sections. bool firstSection = true; for (auto helpTopicSection : document->helpTopicData[tocItemData->itemIndex].helpTopicSections) { if (!firstSection) pageData += "

"; firstSection = false; pageData += helpTopicSection.sectionText + "\n"; } // Process the foot note sections. if (document->helpTopicData[tocItemData->itemIndex].helpTopicFootnotes.size() > 0) pageData += "
\n"; for (auto footnoteSection : document->helpTopicData[tocItemData->itemIndex].helpTopicFootnotes) { std::string footnoteID = std::to_string(footnoteSection.footnoteID); pageData += "" + footnoteID + " " + footnoteSection.footnoteText + "
\n"; } htmPage->SetPage((wxString)pageData); }