Ejemplo n.º 1
0
        static public int AddActionsGoToE(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }
            IPXC_Bookmark bookmark = null;

            if (Parent.SelectedBookmarkNode == null)
            {
                bookmark = Parent.m_CurDoc.BookmarkRoot.AddNewChild(true);
            }
            else
            {
                bookmark = Parent.SelectedBookmarkNode.m_Bookmark.AddNewSibling(false);
            }

            IPXS_Inst       pxsInst     = Parent.m_pxcInst.GetExtension("PXS");
            uint            atomGoToE   = pxsInst.StrToAtom("GoToE");
            IPXC_NameTree   attachments = Parent.m_CurDoc.GetNameTree("EmbeddedFiles");
            IPXS_PDFVariant var         = null;

            try
            {
                var = attachments.Lookup("FeatureChartEU.pdf");
            }
            catch (Exception)
            {
                string                  sFilePath = System.Environment.CurrentDirectory + "\\Documents\\FeatureChartEU.pdf";
                IPXC_FileSpec           fileSpec  = Parent.m_CurDoc.CreateEmbeddFile(sFilePath);
                IPXC_EmbeddedFileStream EFS       = fileSpec.EmbeddedFile;
                EFS.UpdateFromFile2(sFilePath);
                var = fileSpec.PDFObject;
            }

            attachments.Add("FeatureChartEU.pdf", var);

            IPXC_Action_Goto actionGoToE = Parent.m_pxcInst.GetActionHandler(atomGoToE).CreateEmptyAction(atomGoToE, Parent.m_CurDoc) as IPXC_Action_Goto;

            IPXC_GoToETargetPath targetPath = actionGoToE.TargetPath;
            IPXC_GoToETargetItem targetItem = targetPath.InsertNew();

            targetItem.FileName   = "FeatureChartEU.pdf";
            targetItem            = targetPath.InsertNew();
            targetItem.FileName   = "MyStamps.pdf";
            targetItem            = targetPath.InsertNew();
            targetItem.AnnotIndex = 0;
            targetItem.PageNumber = 0;

            IPXC_ActionsList aList = Parent.m_CurDoc.CreateActionsList();

            bookmark.Title = "GoToE Action";
            bookmark.Style = PXC_BookmarkStyle.BookmarkFont_Normal;
            aList.Insert(0, actionGoToE);
            bookmark.Actions = aList;

            Marshal.ReleaseComObject(attachments);

            return((int)Form1.eFormUpdateFlags.efuf_Bookmarks | (int)Form1.eFormUpdateFlags.efuf_Attachments);
        }
        static public int SortBookmarksByPage(Form1 Parent)
        {
            //delegate double[] GetXYFromDestination(IPXC_Bookmark bookmark, PXC_Destination dest);
            GetXYFromDestination getXYFromDestination = (IPXC_Document doc, PXC_Destination destination) => {
                PXC_DestType Type          = destination.nType;
                PXC_Point    retValue      = new PXC_Point();
                IPXC_Pages   pages         = doc.Pages;
                IPXC_Page    page          = pages[destination.nPageNum];
                PXC_Rect     contentBBox   = page.get_Box(PXC_BoxType.PBox_BBox);
                PXC_Rect     pageBBox      = page.get_Box(PXC_BoxType.PBox_PageBox);
                bool         IsContentType = (Type == PXC_DestType.Dest_FitB) || (Type == PXC_DestType.Dest_FitBH) || (Type == PXC_DestType.Dest_FitBV);
                retValue.x = IsContentType ? contentBBox.left : pageBBox.left;
                retValue.y = IsContentType ? contentBBox.top : pageBBox.top;
                switch (Type)
                {
                case PXC_DestType.Dest_XYZ:
                {
                    if ((destination.nNullFlags & 1) == 0)
                    {
                        retValue.x = destination.dValues[0];
                    }
                    if ((destination.nNullFlags & 2) == 0)
                    {
                        retValue.y = destination.dValues[1];
                    }
                    break;
                }

                case PXC_DestType.Dest_FitH:
                {
                    if ((destination.nNullFlags & 2) == 0)
                    {
                        retValue.y = destination.dValues[1];
                    }
                    break;
                }

                case PXC_DestType.Dest_FitV:
                {
                    if ((destination.nNullFlags & 1) == 0)
                    {
                        retValue.x = destination.dValues[0];
                    }
                    break;
                }

                case PXC_DestType.Dest_FitR:
                {
                    if ((destination.nNullFlags & 1) == 0)
                    {
                        retValue.x = destination.dValues[0];
                    }
                    if ((destination.nNullFlags & 8) == 0)
                    {
                        retValue.y = destination.dValues[3];
                    }
                    break;
                }

                case PXC_DestType.Dest_FitBH:
                {
                    if ((destination.nNullFlags & 2) == 0)
                    {
                        retValue.y = destination.dValues[1];
                    }
                    break;
                }

                case PXC_DestType.Dest_FitBV:
                {
                    if ((destination.nNullFlags & 1) == 0)
                    {
                        retValue.x = destination.dValues[0];
                    }
                    break;
                }

                default:
                    break;
                }
                Marshal.ReleaseComObject(page);
                Marshal.ReleaseComObject(pages);
                return(retValue);
            };
            //delegate void SortByAnything(SortByAnything sort, IPXC_Bookmark root);
            SortByAnything sortByAnything = (sort, root, actionType) => {
                List <Tuple <IPXC_Bookmark, PXC_Destination> > bookmarks = new List <Tuple <IPXC_Bookmark, PXC_Destination> >();
                int             MAX_VALUE   = int.MaxValue;
                PXC_Destination invalidDest = new PXC_Destination();
                invalidDest.nPageNum = (uint)MAX_VALUE;

                while (root.ChildrenCount > 0)
                {
                    Tuple <IPXC_Bookmark, PXC_Destination> currentBookmark = Tuple.Create(root.FirstChild, invalidDest);
                    if (root.FirstChild.Actions != null)
                    {
                        for (int i = (int)root.FirstChild.Actions.Count - 1; i >= 0; i--)
                        {
                            if (root.FirstChild.Actions[(uint)i].Type == actionType)
                            {
                                IPXC_Action_Goto actionGoTo = root.FirstChild.Actions[(uint)i] as IPXC_Action_Goto;
                                PXC_Destination  currDest   = actionGoTo.IsNamedDest
                                                                        ? Parent.m_CurDoc.GetNamedDestination(actionGoTo.DestName)
                                                                        : actionGoTo.get_Dest();
                                currentBookmark = Tuple.Create(root.FirstChild, currDest);
                                break;
                            }
                        }
                    }
                    root.FirstChild.Unlink();

                    if ((bookmarks.Count == 0) || (currentBookmark.Item2.nPageNum > bookmarks[bookmarks.Count - 1].Item2.nPageNum))
                    {
                        bookmarks.Add(currentBookmark);
                        continue;
                    }
                    else if (currentBookmark.Item2.nPageNum < bookmarks[0].Item2.nPageNum)
                    {
                        bookmarks.Insert(0, currentBookmark);
                        continue;
                    }

                    int first = 0;
                    int last  = bookmarks.Count;

                    while (first < last)
                    {
                        int mid = first + (last - first) / 2;
                        if (currentBookmark.Item2.nPageNum == bookmarks[mid].Item2.nPageNum)
                        {
                            if ((MAX_VALUE == currentBookmark.Item2.nPageNum) && (MAX_VALUE == bookmarks[mid].Item2.nPageNum))
                            {
                                if (Form1.NativeMethods.StrCmpLogicalW(currentBookmark.Item1.Title, bookmarks[mid].Item1.Title) == 1)
                                {
                                    first = mid + 1;
                                }
                                else
                                {
                                    last = mid;
                                }
                            }
                            else
                            {
                                PXC_Point currentBookmarkXY   = getXYFromDestination(Parent.m_CurDoc, currentBookmark.Item2);
                                PXC_Point bookmarkXY_FromList = getXYFromDestination(Parent.m_CurDoc, bookmarks[mid].Item2);
                                if (currentBookmarkXY.y < bookmarkXY_FromList.y)
                                {
                                    first = mid + 1;
                                }
                                else if (currentBookmarkXY.y > bookmarkXY_FromList.y)
                                {
                                    last = mid;
                                }
                                else
                                {
                                    if (currentBookmarkXY.x < bookmarkXY_FromList.x)
                                    {
                                        last = mid;
                                    }
                                    else
                                    {
                                        first = mid + 1;
                                    }
                                }
                            }
                        }
                        else if (currentBookmark.Item2.nPageNum < bookmarks[mid].Item2.nPageNum)
                        {
                            last = mid;
                        }
                        else
                        {
                            first = mid + 1;
                        }
                    }
                    bookmarks.Insert(last, currentBookmark);
                }

                foreach (Tuple <IPXC_Bookmark, PXC_Destination> bookmark in bookmarks)
                {
                    root.AddChild(bookmark.Item1, true);
                    if (bookmark.Item1.ChildrenCount > 0)
                    {
                        sort(sort, bookmark.Item1, actionType);
                    }
                }
            };

            if (Parent.m_CurDoc == null)
            {
                return(0);
            }

            IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS") as IPXS_Inst;
            uint      nGoTo   = pxsInst.StrToAtom("GoTo");

            sortByAnything(sortByAnything, Parent.m_CurDoc.BookmarkRoot, nGoTo);
            return((int)Form1.eFormUpdateFlags.efuf_Bookmarks);
        }