int CRollupCtrl::MovePageAt(int id, int newidx) { if (!FindPage(id)) return -1; int idx = FindPageIndex(id); if (idx==newidx) return -1; if (newidx>0 && newidx>= (int)m_PageList.size()) newidx=-1; //Remove page from its old position RC_PAGEINFO* pi = FindPage(id); m_PageList.erase( m_PageList.begin() + FindPageIndex(id) ); //Insert at its new position int retidx; if (newidx<0) { m_PageList.push_back(pi); retidx = m_PageList.size()-1; } else { m_PageList.insert( m_PageList.begin()+newidx, pi); retidx=newidx; } //Update RecalLayout(); return retidx; }
void CRollupCtrl::_RemovePage(int idx) { // Find page RC_PAGEINFO* pi = FindPage(idx); //Remove page from array m_PageList.erase( m_PageList.begin() + FindPageIndex(idx) ); //Get Page Rect CRect tr; pi->pwndTemplate->GetWindowRect(&tr); //Update PageHeight m_nPageHeight-=RC_PGBUTTONHEIGHT+(RC_GRPBOXINDENT*2); if (pi->bExpanded) m_nPageHeight-=tr.Height(); //Remove wnds if (pi->pwndButton) delete pi->pwndButton; if (pi->pwndGroupBox) delete pi->pwndGroupBox; // fix ::SetWindowLongPtr(pi->pwndTemplate->m_hWnd, DWLP_DLGPROC, (LONG_PTR)pi->pOldDlgProc); if (pi->pwndTemplate && pi->bAutoDestroyTpl) { pi->pwndTemplate->DestroyWindow(); delete pi->pwndTemplate; } else { pi->pwndTemplate->ShowWindow(SW_HIDE); } //Delete pageinfo delete pi; }
int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode, uint32_t& skip_count, uint32_t objnum, int& index, int level) { if (!pNode->KeyExist("Kids")) { if (objnum == pNode->GetObjNum()) return index; if (skip_count) skip_count--; index++; return -1; } CPDF_Array* pKidList = pNode->GetArrayFor("Kids"); if (!pKidList) return -1; if (level >= FX_MAX_PAGE_LEVEL) return -1; size_t count = pNode->GetIntegerFor("Count"); if (count <= skip_count) { skip_count -= count; index += count; return -1; } if (count && count == pKidList->GetCount()) { for (size_t i = 0; i < count; i++) { if (CPDF_Reference* pKid = ToReference(pKidList->GetObjectAt(i))) { if (pKid->GetRefObjNum() == objnum) { m_PageList.SetAt(index + i, objnum); return static_cast<int>(index + i); } } } } for (size_t i = 0; i < pKidList->GetCount(); i++) { CPDF_Dictionary* pKid = pKidList->GetDictAt(i); if (!pKid || pKid == pNode) continue; int found_index = FindPageIndex(pKid, skip_count, objnum, index, level + 1); if (found_index >= 0) return found_index; } return -1; }
int CPDF_Document::GetPageIndex(uint32_t objnum) { uint32_t nPages = m_PageList.GetSize(); uint32_t skip_count = 0; bool bSkipped = false; for (uint32_t i = 0; i < nPages; i++) { uint32_t objnum1 = m_PageList.GetAt(i); if (objnum1 == objnum) return i; if (!bSkipped && objnum1 == 0) { skip_count = i; bSkipped = true; } } CPDF_Dictionary* pPages = GetPagesDict(); if (!pPages) return -1; int index = 0; return FindPageIndex(pPages, skip_count, objnum, index); }