OutLineControlViewModel.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKit.PDFDocument.Action;
  3. using ComPDFKit.PDFPage;
  4. using ComPDFKitViewer.PdfViewer;
  5. using PDF_Master.CustomControl;
  6. using PDF_Master.Model;
  7. using PDF_Master.Model.BOTA;
  8. using Prism.Commands;
  9. using Prism.Mvvm;
  10. using Prism.Regions;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Collections.ObjectModel;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Media;
  20. using System.Windows.Media.Imaging;
  21. namespace PDF_Master.ViewModels.BOTA
  22. {
  23. class OutLineControlViewModel : BindableBase, INavigationAware
  24. {
  25. #region 文案
  26. private string T_title;
  27. public string T_Title
  28. {
  29. get { return T_title; }
  30. set
  31. {
  32. SetProperty(ref T_title, value);
  33. }
  34. }
  35. private string T_expand;
  36. public string T_Expand
  37. {
  38. get { return T_expand; }
  39. set
  40. {
  41. SetProperty(ref T_expand, value);
  42. }
  43. }
  44. private string T_collapse;
  45. public string T_Collapse
  46. {
  47. get { return T_collapse; }
  48. set
  49. {
  50. SetProperty(ref T_collapse, value);
  51. }
  52. }
  53. private string T_removeAll;
  54. public string T_RemoveAll
  55. {
  56. get { return T_removeAll; }
  57. set
  58. {
  59. SetProperty(ref T_removeAll, value);
  60. }
  61. }
  62. private void InitString()
  63. {
  64. T_Title = App.MainPageLoader.GetString("Outline_Title");
  65. T_Expand = App.MainPageLoader.GetString("Outline_Expand");
  66. T_Collapse = App.MainPageLoader.GetString("Outline_Collapse");
  67. T_RemoveAll = App.MainPageLoader.GetString("Outline_RemoveAll");
  68. }
  69. #endregion
  70. private string PageDefaultName = "";
  71. //缩略图相关全局变量,减少内存申请次数
  72. private WriteableBitmap WirteBitmap;
  73. private byte[] bmpData;
  74. private CPDFViewer PDFViewer;
  75. public ObservableCollection<OutlineNode> Outlinelist { get; set; }
  76. private bool isInsertHead = false;
  77. /// <summary>
  78. /// 是否为插入最顶部
  79. /// </summary>
  80. public bool IsInsertHead
  81. {
  82. get { return isInsertHead; }
  83. set
  84. {
  85. SetProperty(ref isInsertHead, value);
  86. }
  87. }
  88. private bool isOnDrop = false;
  89. public bool IsOnDrop
  90. {
  91. get { return isOnDrop; }
  92. set { isOnDrop = value; }
  93. }
  94. public DelegateCommand<ObservableCollection<OutlineNode>> CollapseAllCommand { get; set; }
  95. public DelegateCommand<ObservableCollection<OutlineNode>> ExpandAllCommand { get; set; }
  96. public DelegateCommand DeleteAllCommand { get; set; }
  97. public DelegateCommand<OutlineNode> DowngradeCommand { get; set; }
  98. public OutLineControlViewModel()
  99. {
  100. Outlinelist = new ObservableCollection<OutlineNode>();
  101. DeleteAllCommand = new DelegateCommand(DeleteAll);
  102. CollapseAllCommand = new DelegateCommand<ObservableCollection<OutlineNode>>(CollapseAll);
  103. ExpandAllCommand = new DelegateCommand<ObservableCollection<OutlineNode>>(ExpandAll);
  104. InitString();
  105. }
  106. public bool IsNavigationTarget(NavigationContext navigationContext)
  107. {
  108. return true;
  109. }
  110. public void OnNavigatedFrom(NavigationContext navigationContext)
  111. {
  112. return;
  113. }
  114. public void OnNavigatedTo(NavigationContext navigationContext)
  115. {
  116. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  117. if (PDFViewer == null)
  118. {
  119. return;
  120. }
  121. List<CPDFOutline> datasource = PDFViewer.Document.GetOutlineList();
  122. Outlinelist.Clear();
  123. foreach (CPDFOutline item in datasource)
  124. {
  125. OutlineNode dto = ConvertCPDFToOutlineNode(item, null, false);
  126. if (dto != null)
  127. {
  128. Outlinelist.Add(dto);
  129. }
  130. }
  131. if (Outlinelist.Count>0)
  132. {
  133. //如果是第一条数据不允许点击降级
  134. Outlinelist[0].CanDown = false;
  135. }
  136. PDFViewer.GetCreateOutLineInfo();
  137. }
  138. /// <summary>
  139. /// 更新大纲数据,并保存状态设置为true
  140. /// </summary>
  141. public void Updata(bool IsMoveData)
  142. {
  143. PDFViewer.Document.ReleaseOutlineList();
  144. ObservableCollection<OutlineNode> list = new ObservableCollection<OutlineNode>();
  145. List<CPDFOutline> datasource = PDFViewer.Document.GetOutlineList();
  146. //遍历,转换UI状态存入临时数组
  147. foreach (CPDFOutline item in datasource)
  148. {
  149. OutlineNode dto = ConvertCPDFToOutlineNode(item, null, IsMoveData);
  150. if (dto != null)
  151. {
  152. list.Add(dto);
  153. }
  154. }
  155. if (list.Count > 0)
  156. {
  157. //如果是第一条数据不允许点击降级
  158. list[0].CanDown = false;
  159. }
  160. //清空绑定数组,并填充新数据
  161. Outlinelist.Clear();
  162. foreach (OutlineNode item in list)
  163. {
  164. Outlinelist.Add(item);
  165. }
  166. PDFViewer.UndoManager.CanSave = true;
  167. }
  168. /// <summary>
  169. /// 设置当前大纲对象的Title
  170. /// </summary>
  171. public bool SetTitle(CPDFOutline cPDFOutline, string Title)
  172. {
  173. if (cPDFOutline == null)
  174. {
  175. return false;
  176. }
  177. return cPDFOutline.SetTitle(Title);
  178. }
  179. /// <summary>
  180. /// 跳转到指定位置或者URL动作
  181. /// </summary>
  182. public void GoToPage(TreeViewItem treeViewItem)
  183. {
  184. OutlineNode outline = treeViewItem.DataContext as OutlineNode;
  185. if (outline == null)
  186. {
  187. return;
  188. }
  189. CPDFAction action = outline.Outline.GetAction();
  190. if (action != null && action.ActionType != C_ACTION_TYPE.ACTION_TYPE_UNKNOWN)
  191. {
  192. PDFViewer.ProcessAction(action);
  193. }
  194. else if(!string.IsNullOrEmpty(outline.PageIndex))
  195. {
  196. Size size = PDFViewer.Document.GetPageSize(Convert.ToInt32(outline.PageIndex) - 1);
  197. if (outline.PositionX == -1)
  198. {
  199. outline.PositionX = 0;
  200. }
  201. if (outline.PositionY == -1)
  202. {
  203. outline.PositionY = size.Height;
  204. }
  205. PDFViewer.GoToPage(Convert.ToInt32(outline.PageIndex) - 1, new Point(outline.PositionX, size.Height - outline.PositionY));
  206. }
  207. }
  208. /// <summary>
  209. /// 收起所有展开
  210. /// </summary>
  211. public void CollapseAll(ObservableCollection<OutlineNode> outlineNodes)
  212. {
  213. foreach (var item in outlineNodes)
  214. {
  215. item.IsExpanded = false;
  216. if (item.Chlidlist.Count > 0)
  217. {
  218. CollapseAll(item.Chlidlist);
  219. }
  220. }
  221. }
  222. /// <summary>
  223. /// 展开所有大纲
  224. /// </summary>
  225. public void ExpandAll(ObservableCollection<OutlineNode> outlineNodes)
  226. {
  227. foreach (var item in outlineNodes)
  228. {
  229. item.IsExpanded = true;
  230. if (item.Chlidlist.Count > 0)
  231. {
  232. ExpandAll(item.Chlidlist);
  233. }
  234. }
  235. }
  236. /// <summary>
  237. /// 更改目标位置
  238. /// </summary>
  239. public void ChangeOutLineDestination(OutlineNode outline)
  240. {
  241. List<TextSelectNode> textSelectNodes = PDFViewer.GetCreateOutLineInfo();
  242. CPDFDestination info = new CPDFDestination();
  243. info.PageIndex = textSelectNodes[0].PageIndex;
  244. Size size = PDFViewer.Document.GetPageSize(textSelectNodes[0].PageIndex);
  245. info.Position_X = (float)(size.Width - textSelectNodes[0].StartPoint.X);
  246. info.Position_Y = (float)(size.Height - textSelectNodes[0].StartPoint.Y);
  247. outline.Outline.SetDestination(PDFViewer.Document, info);
  248. Updata(false);
  249. }
  250. /// <summary>
  251. /// 添加大纲
  252. /// </summary>
  253. public int AddOutLine(OutlineNode outline)
  254. {
  255. int ItemIndex = 0;
  256. List<TextSelectNode> textSelectNodes = PDFViewer.GetCreateOutLineInfo();
  257. CPDFDestination info = new CPDFDestination();
  258. if (textSelectNodes.Count <= 0)
  259. {
  260. //SDK出错了
  261. return -1;
  262. }
  263. info.PageIndex = textSelectNodes[0].PageIndex;
  264. Size size = PDFViewer.Document.GetPageSize(info.PageIndex);
  265. info.Position_X = (float)(textSelectNodes[0].StartPoint.X);
  266. info.Position_Y = (float)(size.Height - textSelectNodes[0].StartPoint.Y);
  267. CPDFOutline dto = null;
  268. //当前有选中大纲列表
  269. if (outline != null)
  270. {
  271. CPDFOutline parentoutline = outline.Outline.GetParent();
  272. if (parentoutline == null)
  273. {
  274. //获取父级失败,直接添加在根节点最下方
  275. PDFViewer.Document.GetOutlineList();
  276. CPDFOutline parent = PDFViewer.Document.GetOutlineRoot();
  277. if (!parent.InsertChildAtIndex(PDFViewer.Document, parent.ChildList.Count, ref dto))
  278. {
  279. //SDK出错了
  280. return -1;
  281. }
  282. ItemIndex = parent.ChildList.Count;
  283. }
  284. else
  285. {
  286. //获取父节点成功,添加在父节点中选中项下方
  287. int index = GetOutlinesIndexFormParent(parentoutline, outline.Outline);
  288. parentoutline.InsertChildAtIndex(PDFViewer.Document, index, ref dto);
  289. ItemIndex = index + 1;
  290. }
  291. }
  292. else
  293. {
  294. //未选中数据,直接添加在根节点最下方
  295. PDFViewer.Document.GetOutlineList();
  296. CPDFOutline parent = PDFViewer.Document.GetOutlineRoot();
  297. if (!parent.InsertChildAtIndex(PDFViewer.Document, parent.ChildList.Count, ref dto))
  298. {
  299. //SDK出错了
  300. return -1;
  301. }
  302. ItemIndex = parent.ChildList.Count;
  303. }
  304. ///当前没有选中文字
  305. if (string.IsNullOrEmpty(textSelectNodes[0].SelectText))
  306. {
  307. string addPageName = PageDefaultName + (textSelectNodes[0].PageIndex + 1).ToString();
  308. if (!dto.SetTitle(addPageName))
  309. {
  310. //SDK出错了
  311. return -1;
  312. }
  313. }
  314. else
  315. {
  316. string addPageName = PageDefaultName + textSelectNodes[0].SelectText;
  317. if (!dto.SetTitle(addPageName))
  318. {
  319. //SDK出错了
  320. return -1;
  321. }
  322. }
  323. dto.SetDestination(PDFViewer.Document, info);
  324. Updata(false);
  325. return ItemIndex;
  326. }
  327. /// <summary>
  328. /// 添加大纲到子节点的最后一位
  329. /// </summary>
  330. public int InsertParentOutline(OutlineNode outline)
  331. {
  332. int ItemIndex = 0;
  333. List<TextSelectNode> textSelectNodes = PDFViewer.GetCreateOutLineInfo();
  334. CPDFDestination info = new CPDFDestination();
  335. if (textSelectNodes.Count <= 0)
  336. {
  337. //SDK出错了
  338. return -1;
  339. }
  340. info.PageIndex = textSelectNodes[0].PageIndex;
  341. info.Position_X = (float)textSelectNodes[0].StartPoint.X;
  342. info.Position_Y = (float)textSelectNodes[0].StartPoint.Y;
  343. CPDFOutline dto = null;
  344. CPDFOutline parent = outline.Outline.GetParent();
  345. if (parent != null)
  346. {
  347. CPDFOutline trueparent = parent.GetParent();
  348. if (trueparent != null)
  349. {
  350. ItemIndex = GetOutlinesIndexFormParent(trueparent, parent);
  351. if (!trueparent.InsertChildAtIndex(PDFViewer.Document, ItemIndex, ref dto))
  352. {
  353. return -1;
  354. }
  355. ItemIndex = ItemIndex + 1;
  356. }
  357. }
  358. ///当前没有选中文字
  359. if (string.IsNullOrEmpty(textSelectNodes[0].SelectText))
  360. {
  361. string addPageName = PageDefaultName + (textSelectNodes[0].PageIndex + 1).ToString();
  362. if (!dto.SetTitle(addPageName))
  363. {
  364. //SDK出错了
  365. return -1;
  366. }
  367. }
  368. else
  369. {
  370. string addPageName = PageDefaultName + textSelectNodes[0].SelectText;
  371. if (!dto.SetTitle(addPageName))
  372. {
  373. //SDK出错了
  374. return -1;
  375. }
  376. }
  377. dto.SetDestination(PDFViewer.Document, info);
  378. Updata(false);
  379. return ItemIndex;
  380. }
  381. /// <summary>
  382. /// 添加大纲到父节点的下一位
  383. /// </summary>
  384. public int InsertChlidOutline(OutlineNode outline)
  385. {
  386. int ItemIndex = 0;
  387. if (outline == null)
  388. {
  389. return -1;
  390. }
  391. if (outline.Outline.ChildList != null)
  392. {
  393. ItemIndex = outline.Outline.ChildList.Count;
  394. }
  395. List<TextSelectNode> textSelectNodes = PDFViewer.GetCreateOutLineInfo();
  396. CPDFDestination info = new CPDFDestination();
  397. if (textSelectNodes.Count <= 0)
  398. {
  399. //SDK出错了
  400. return -1;
  401. }
  402. info.PageIndex = textSelectNodes[0].PageIndex;
  403. info.Position_X = (float)textSelectNodes[0].StartPoint.X;
  404. info.Position_Y = (float)textSelectNodes[0].StartPoint.Y;
  405. CPDFOutline dto = null;
  406. if (!outline.Outline.InsertChildAtIndex(PDFViewer.Document, ItemIndex, ref dto))
  407. {
  408. return -1;
  409. }
  410. ///当前没有选中文字
  411. if (string.IsNullOrEmpty(textSelectNodes[0].SelectText))
  412. {
  413. string addPageName = PageDefaultName + (textSelectNodes[0].PageIndex + 1).ToString();
  414. if (!dto.SetTitle(addPageName))
  415. {
  416. //SDK出错了
  417. return -1;
  418. }
  419. }
  420. else
  421. {
  422. string addPageName = PageDefaultName + textSelectNodes[0].SelectText;
  423. if (!dto.SetTitle(addPageName))
  424. {
  425. //SDK出错了
  426. return -1;
  427. }
  428. }
  429. dto.SetDestination(PDFViewer.Document, info);
  430. Updata(false);
  431. return ItemIndex;
  432. }
  433. /// <summary>
  434. /// 删除所有大纲
  435. /// </summary>
  436. public void DeleteAll()
  437. {
  438. AlertsMessage alertsMessage = new AlertsMessage();
  439. alertsMessage.ShowDialog("", "This action will permanently delete all outlines,Whether to continue?", "No", "Yes");
  440. if (alertsMessage.result == ContentResult.Ok)
  441. {
  442. foreach (var item in Outlinelist)
  443. {
  444. item.Outline.RemoveFromParent(this.PDFViewer.Document);
  445. }
  446. Updata(false);
  447. }
  448. }
  449. /// <summary>
  450. /// 降级当前大纲
  451. /// </summary>
  452. public void Downgrade(OutlineNode outline)
  453. {
  454. if (outline != null)
  455. {
  456. CPDFOutline parent = outline.Outline.GetParent();
  457. int index = GetOutlinesIndexFormParent(parent, outline.Outline);
  458. CPDFOutline newparent = parent.ChildList[index - 2];
  459. int insertindex = newparent.ChildList.Count;
  460. newparent.MoveChildAtIndex(PDFViewer.Document, outline.Outline, insertindex);
  461. Updata(false);
  462. }
  463. }
  464. /// <summary>
  465. /// 升级当前大纲
  466. /// </summary>
  467. public void Upgrade(OutlineNode outline)
  468. {
  469. if (outline != null)
  470. {
  471. CPDFOutline parent = outline.Outline.GetParent();
  472. CPDFOutline newparent = parent.GetParent();
  473. int index = GetOutlinesIndexFormParent(parent.GetParent(), parent);
  474. newparent.MoveChildAtIndex(PDFViewer.Document, outline.Outline, index);
  475. Updata(false);
  476. }
  477. }
  478. /// <summary>
  479. /// 删除当前大纲
  480. /// </summary>
  481. public void RemoveOutline(OutlineNode outline)
  482. {
  483. outline.Outline.RemoveFromParent(PDFViewer.Document);
  484. Updata(false);
  485. }
  486. /// <summary>
  487. /// 移动大纲到目标节点
  488. /// </summary>
  489. /// <param name="target">目标节点</param>
  490. /// <param name="soure">需要插入的数据</param>
  491. /// <returns></returns>
  492. public bool MoveOutLine(OutlineNode target, OutlineNode soure)
  493. {
  494. bool Tag = true;
  495. if (IsInsertHead)
  496. {
  497. CPDFOutline root = PDFViewer.Document.GetOutlineRoot();
  498. if (root != null)
  499. {
  500. Tag = root.MoveChildAtIndex(PDFViewer.Document, soure.Outline, 0);
  501. }
  502. }
  503. else
  504. {
  505. if (target.IsInsertNextLayer)
  506. {
  507. target.IsExpanded = true;
  508. Tag = target.Outline.MoveChildAtIndex(PDFViewer.Document, soure.Outline, target.Outline.ChildList.Count);
  509. }
  510. else
  511. {
  512. CPDFOutline parent = target.Outline.GetParent();
  513. if (parent != null && parent.ChildList.Count > 0)
  514. {
  515. int index = parent.ChildList.IndexOf(target.Outline);
  516. int sourceindex = parent.ChildList.IndexOf(soure.Outline);
  517. //源数据不在目标节点树中的情况
  518. if (sourceindex == -1)
  519. {
  520. Tag = parent.MoveChildAtIndex(PDFViewer.Document, soure.Outline, index + 1);
  521. }
  522. //分向上和向下移动
  523. else if (sourceindex > index)
  524. {
  525. Tag = parent.MoveChildAtIndex(PDFViewer.Document, soure.Outline, index + 1);
  526. }
  527. else
  528. {
  529. Tag = parent.MoveChildAtIndex(PDFViewer.Document, soure.Outline, index);
  530. }
  531. }
  532. }
  533. }
  534. return Tag;
  535. }
  536. /// <summary>
  537. /// 获取对应大纲所需的缩略图数据
  538. /// </summary>
  539. public WriteableBitmap LoadPreview(OutlineNode outlineNode,int Width,int Height)
  540. {
  541. CPDFPage page = PDFViewer.Document.PageAtIndex(Convert.ToInt32(outlineNode.PageIndex) - 1);
  542. if (page==null)
  543. {
  544. return null;
  545. }
  546. Size size = PDFViewer.Document.GetPageSize(Convert.ToInt32(outlineNode.PageIndex) - 1);
  547. //当前对象添加时没创建默认对象,SDK会返回(-1,-1)
  548. if (outlineNode.PositionX == -1)
  549. {
  550. outlineNode.PositionX = 0;
  551. }
  552. if (outlineNode.PositionY == -1)
  553. {
  554. outlineNode.PositionY = size.Height;
  555. }
  556. Point zoomXY = new Point(outlineNode.PositionX * outlineNode.Zoom, outlineNode.PositionY * outlineNode.Zoom);
  557. Size zoomSize = new Size((int)(Width * outlineNode.Zoom), (int)(Height * outlineNode.Zoom));
  558. bmpData = new byte[(int)(zoomSize.Width * zoomSize.Height * 4)];
  559. WirteBitmap = new WriteableBitmap((int)zoomSize.Width, (int)zoomSize.Height, 96, 96, PixelFormats.Bgra32, null);
  560. if (!page.IsValid())
  561. {
  562. return null;
  563. }
  564. page.RenderPageBitmapWithMatrix((float)outlineNode.Zoom, new Rect(outlineNode.PositionX, size.Height- outlineNode.PositionY, zoomSize.Width, zoomSize.Height), 0xFFFFFFFF, bmpData, 1, true);
  565. WirteBitmap.WritePixels(new Int32Rect(0, 0, (int)zoomSize.Width, (int)zoomSize.Height), bmpData, WirteBitmap.BackBufferStride, 0);
  566. WirteBitmap.Freeze();
  567. return WirteBitmap;
  568. }
  569. /// <summary>
  570. /// 将PDF对象转换为自定义数据类型,并存储
  571. /// </summary>
  572. private OutlineNode ConvertCPDFToOutlineNode(CPDFOutline outline, OutlineNode parent, bool IsMoveData)
  573. {
  574. OutlineNode node = new OutlineNode();
  575. if (outline != null)
  576. {
  577. node.IsInsertNextLayer = false;
  578. node.IsInsertCurrentLayer = false;
  579. node.IsExpanded = false;
  580. node.IsSelected = false;
  581. node.Outline = outline;
  582. node.CanUp = outline.Level == 0 ? false : true;
  583. node.CanAddParent = outline.Level == 0 ? false : true;
  584. CPDFAction action = outline.GetAction();
  585. if (action != null)
  586. {
  587. if (action.ActionType != C_ACTION_TYPE.ACTION_TYPE_URI)
  588. {
  589. CPDFDestination cPDFDestination = outline.GetDestination(PDFViewer.Document);
  590. if (cPDFDestination != null&& cPDFDestination.PageIndex >=0)
  591. {
  592. //存储大纲相关属性
  593. node.PageIndex = (cPDFDestination.PageIndex + 1).ToString();
  594. node.PositionX = cPDFDestination.Position_X;
  595. node.PositionY = cPDFDestination.Position_Y;
  596. if (cPDFDestination.Zoom <= 0)
  597. {
  598. node.Zoom = 1;
  599. }
  600. else
  601. {
  602. node.Zoom = cPDFDestination.Zoom;
  603. }
  604. }
  605. else
  606. {
  607. node.PageIndex = "";
  608. node.PositionX = 0;
  609. node.PositionY = 0;
  610. node.Zoom = 1;
  611. }
  612. }
  613. else
  614. {
  615. node.PageIndex = "";
  616. node.PositionX = 0;
  617. node.PositionY = 0;
  618. node.Zoom = 1;
  619. }
  620. }
  621. else
  622. {
  623. node.PageIndex = "";
  624. node.PositionX = 0;
  625. node.PositionY = 0;
  626. node.Zoom = 1;
  627. }
  628. if (parent != null)
  629. {
  630. node.Parent = parent;
  631. }
  632. if (Outlinelist != null && Outlinelist.Count > 0)
  633. {
  634. OutlineNode oldnode = FindOutlineFromDto(Outlinelist, node.Outline, IsMoveData);
  635. if (oldnode != null)
  636. {
  637. node.IsExpanded = oldnode.IsExpanded;
  638. node.IsSelected = oldnode.IsSelected;
  639. }
  640. }
  641. node.Chlidlist = new ObservableCollection<OutlineNode>();
  642. if (outline.ChildList.Count > 0)
  643. {
  644. foreach (CPDFOutline item in outline.ChildList)
  645. {
  646. node.Chlidlist.Add(ConvertCPDFToOutlineNode(item, node, IsMoveData));
  647. }
  648. //如果是第一条数据不允许点击降级
  649. node.Chlidlist[0].CanDown = false;
  650. }
  651. else
  652. {
  653. node.CanDown = true;
  654. }
  655. }
  656. return node;
  657. }
  658. /// <summary>
  659. /// 从当前列表中找到和SDK大纲对象相同的数据
  660. /// </summary>
  661. public OutlineNode FindOutlineFromDto(ObservableCollection<OutlineNode> list, CPDFOutline outline, bool IsMoveData)
  662. {
  663. foreach (OutlineNode item in list)
  664. {
  665. CPDFOutline parent = outline.GetParent();
  666. CPDFOutline PARENT = item.Outline.GetParent();
  667. int i = GetIndexFromParent(parent.ChildList, outline);
  668. int I = GetIndexFromParent(PARENT.ChildList, item.Outline);
  669. if (IsMoveData)
  670. {
  671. if (item.Outline.Title == outline.Title)
  672. {
  673. return item;
  674. }
  675. else if (item.Chlidlist.Count > 0)
  676. {
  677. OutlineNode retdto = FindOutlineFromDto(item.Chlidlist, outline, IsMoveData);
  678. if (retdto != null)
  679. {
  680. return retdto;
  681. }
  682. }
  683. }
  684. else
  685. {
  686. if (item.Outline.Title == outline.Title && i == I && outline.Level == item.Outline.Level && ((parent.Title == PARENT.Title) || (parent.Title == null && PARENT.Title == null)))
  687. {
  688. return item;
  689. }
  690. else if (item.Chlidlist.Count > 0)
  691. {
  692. OutlineNode retdto = FindOutlineFromDto(item.Chlidlist, outline, IsMoveData);
  693. if (retdto != null)
  694. {
  695. return retdto;
  696. }
  697. }
  698. }
  699. }
  700. return null;
  701. }
  702. /// <summary>
  703. /// 从当前列表中找到对应的OutlineNode对象
  704. /// </summary>
  705. public OutlineNode FindOutlineFromList(ObservableCollection<OutlineNode> list, OutlineNode outline, int outlineindex)
  706. {
  707. //如果传入比对数据为null,则返回最后一项
  708. if (outline == null)
  709. {
  710. return list.Last();
  711. }
  712. if (list.Count<=0)
  713. {
  714. return null;
  715. }
  716. int index = list.IndexOf(outline);
  717. if (index >= 0)
  718. {
  719. if (outlineindex <= index)
  720. {
  721. return list[index];
  722. }
  723. else
  724. {
  725. return list[outlineindex - 1];
  726. }
  727. }
  728. else
  729. {
  730. foreach (var item in list)
  731. {
  732. OutlineNode node = FindOutlineFromList(item.Chlidlist, outline, outlineindex);
  733. if (node != null)
  734. {
  735. return node;
  736. }
  737. }
  738. }
  739. return null;
  740. }
  741. private int GetIndexFromParent(List<CPDFOutline> parentlist, CPDFOutline outline)
  742. {
  743. for (int i = 0; i < parentlist.Count; i++)
  744. {
  745. if (parentlist[i] == outline)
  746. {
  747. return i;
  748. }
  749. }
  750. return -1;
  751. }
  752. private int GetOutlinesIndexFormParent(CPDFOutline parentoutline, CPDFOutline outline)
  753. {
  754. if (parentoutline != null)
  755. {
  756. if (parentoutline.ChildList.Count > 0)
  757. {
  758. for (int i = 0; i < parentoutline.ChildList.Count; i++)
  759. {
  760. if (parentoutline.ChildList[i] == outline)
  761. {
  762. return i + 1;
  763. }
  764. }
  765. }
  766. return parentoutline.ChildList.Count;
  767. }
  768. return 0;
  769. }
  770. }
  771. }