static void PrepareAndSaveTabData(WindowInfo *win, TabData **tdata) { if (*tdata == NULL) *tdata = new TabData(); if (win->tocLoaded) { win->tocState.Reset(); HTREEITEM hRoot = TreeView_GetRoot(win->hwndTocTree); if (hRoot) UpdateTocExpansionState(win, hRoot); } if (win->AsChm()) win->AsChm()->RemoveParentHwnd(); SaveTabData(win, *tdata); // prevent data from being deleted win->ctrl = NULL; win->watcher = NULL; }
void UpdateTocExpansionState(TabInfo *tab, HWND hwndTocTree, HTREEITEM hItem) { while (hItem) { TVITEM item; item.hItem = hItem; item.mask = TVIF_PARAM | TVIF_STATE; item.stateMask = TVIS_EXPANDED; TreeView_GetItem(hwndTocTree, &item); DocTocItem *tocItem = item.lParam ? (DocTocItem *)item.lParam : nullptr; if (tocItem && tocItem->child) { // add the ids of toggled items to tocState bool wasToggled = !(item.state & TVIS_EXPANDED) == tocItem->open; if (wasToggled) tab->tocState.Append(tocItem->id); UpdateTocExpansionState(tab, hwndTocTree, TreeView_GetChild(hwndTocTree, hItem)); } hItem = TreeView_GetNextSibling(hwndTocTree, hItem); } }
// Must be called when the active tab is losing selection. // This happens when a new document is loaded or when another tab is selected. void SaveCurrentTabInfo(WindowInfo* win) { if (!win) return; int current = TabCtrl_GetCurSel(win->hwndTabBar); if (-1 == current) return; CrashIf(win->currentTab != win->tabs.at(current)); TabInfo* tdata = win->currentTab; CrashIf(!tdata); if (win->tocLoaded) { tdata->tocState.Reset(); HTREEITEM hRoot = win->tocTreeCtrl->GetRoot(); if (hRoot) UpdateTocExpansionState(tdata, win->tocTreeCtrl, hRoot); } VerifyTabInfo(win, tdata); // update the selection history win->tabSelectionHistory->Remove(tdata); win->tabSelectionHistory->Push(tdata); }