Ejemplo n.º 1
0
        public static string GetText(TreeNode node)
        {
            TreeNode.StringChunkRange txtChunkRange = node.GetText();
            TreeNode.StringChunk      textLocal     = txtChunkRange != null ? txtChunkRange.First : null; //node.GetTextChunk();

            if (textLocal != null)
            {
                //DebugFix.Assert(textMedia.First.IsAbstractTextMedia);
                //DebugFix.Assert(range.Last == null);

                return(textLocal.Str);
            }
            //else
            //{
            //    QualifiedName qname = node.GetXmlElementQName();
            //    if (qname != null && qname.LocalName.Equals("img", StringComparison.OrdinalIgnoreCase))
            //    {
            //        property.xml.XmlAttribute xmlAttr = node.GetXmlProperty().GetAttribute("alt");
            //        if (xmlAttr != null)
            //        {
            //            return xmlAttr.Value;
            //        }
            //    }
            //}
            return(null);
        }
Ejemplo n.º 2
0
        public static string GetMarkerDescription(TreeNode treeNode)
        {
            StringBuilder strBuilder = new StringBuilder();
            int           length     = 0;

            if (treeNode.HasXmlProperty)
            {
                string localName = treeNode.GetXmlElementPrefixedLocalName();

                strBuilder.Append("[");
                strBuilder.Append(localName);
                strBuilder.Append("] ");

                length = strBuilder.Length;
            }

            TreeNode.StringChunkRange range = treeNode.GetTextFlattened_();
            if (range != null && range.First != null && !string.IsNullOrEmpty(range.First.Str))
            {
                int l1 = length;
                TreeNode.ConcatStringChunks(range, -1, strBuilder);
                int l2 = strBuilder.Length;

                int added = l2 - l1;
                if (added > 40)
                {
                    //string str = strBuilder.ToString(0, 40);
                    //#if NET40
                    //                    stringBuilder.Clear();
                    //#else
                    //                    stringBuilder.Length = 0;
                    //#endif //NET40
                    //strBuilder.Append(str);
                    //strBuilder.Append("(...)");

                    string addon = "(...)";
                    strBuilder.Insert(length + 40, addon);
                    length += 40 + addon.Length;
                }
                else
                {
                    length += added;
                }
            }

            return(strBuilder.ToString(0, Math.Min(length, strBuilder.Length)));
        }
        ////returns a 1-child-deep "flat" xml representation
        //public static string GetNodeXml(TreeNode node, bool flat)
        //{
        //    if (node == null) return "";
        //    if (flat)
        //        return GetNodeXml_Flat(node);
        //    else
        //        return GetNodeXml_Deep(node, 0);
        //}

        public static string GetTreeNodeTextExcerpt(TreeNode node)
        {
            TreeNode.StringChunkRange range = node.GetTextFlattened_();
            if (range == null || range.First == null || string.IsNullOrEmpty(range.First.Str))
            {
                return("");
            }

            int strBuilderCapacity = 0;

            ////if this is a mixed content model node with previous sibling(s), add some ellipses before the text too
            //string strBuilder_str1 = (node.GetXmlElementQName() == null && node.PreviousSibling != null)
            //                            ? @"...\n" : null;
            //if (strBuilder_str1 != null)
            //{
            //    strBuilderCapacity += strBuilder_str1.Length;
            //}

            int maxLength = 100;
            int length    = range.GetLength();

            strBuilderCapacity += Math.Min(length, maxLength);
            string strBuilder_str2 = length > maxLength ? @"..." : null;

            if (strBuilder_str2 != null)
            {
                strBuilderCapacity += strBuilder_str2.Length;
            }

            StringBuilder strBuilder = new StringBuilder(strBuilderCapacity);

            TreeNode.ConcatStringChunks(range, maxLength, strBuilder);
            if (strBuilder_str2 != null)
            {
                strBuilder.Append(strBuilder_str2);
            }
            //if (strBuilder_str1 != null)
            //{
            //    strBuilder.Insert(0, strBuilder_str1);
            //}
            DebugFix.Assert(strBuilder.Length == strBuilderCapacity);
            return(strBuilder.ToString());
        }
        private static bool isPage(TreeNode node)
        {
            if (!isPageNumber(node))
            {
                return(false);
            }

            string id = node.GetXmlElementId();

            string pageID = null;

            if (!string.IsNullOrEmpty(id))
            {
                pageID = id;
            }
            else
            {
                TreeNode.StringChunkRange range = node.GetTextFlattened_();
                if (range != null && range.First != null && !string.IsNullOrEmpty(range.First.Str))
                {
                    StringBuilder strBuilder = new StringBuilder(range.GetLength());
                    TreeNode.ConcatStringChunks(range, -1, strBuilder);

                    strBuilder.Replace(" ", "_");
                    strBuilder.Insert(0, "id_tobipage_");

                    pageID = strBuilder.ToString();
                }
            }

            if (!string.IsNullOrEmpty(pageID))
            {
                return(true);
            }
            return(false);
        }
        //private TreeNode m_CurrentTreeNode;
        //public TreeNode CurrentTreeNode
        //{
        //    get
        //    {
        //        return m_CurrentTreeNode;
        //    }
        //    set
        //    {
        //        if (m_CurrentTreeNode == value) return;

        //        m_CurrentTreeNode = value;
        //        //RaisePropertyChanged(() => CurrentTreeNode);
        //    }
        //}

        //private TreeNode m_CurrentSubTreeNode;
        //public TreeNode CurrentSubTreeNode
        //{
        //    get
        //    {
        //        return m_CurrentSubTreeNode;
        //    }
        //    set
        //    {
        //        if (m_CurrentSubTreeNode == value) return;
        //        m_CurrentSubTreeNode = value;


        //        //RaisePropertyChanged(() => CurrentSubTreeNode);
        //    }
        //}

        private void refreshData(Tuple <TreeNode, TreeNode> newTreeNodeSelection)
        {
            if (newTreeNodeSelection.Item1 == null)
            {
                return;
            }


            TreeNode treeNode = newTreeNodeSelection.Item2 ?? newTreeNodeSelection.Item1;

            StringBuilder strBuilder = null;

            TreeNode.StringChunkRange range = treeNode.GetTextFlattened_();

            if (range != null && range.First != null && !string.IsNullOrEmpty(range.First.Str))
            {
                strBuilder = new StringBuilder(range.GetLength());
                TreeNode.ConcatStringChunks(range, -1, strBuilder);

                string strShort = strBuilder.ToString(0, Math.Min(1000, strBuilder.Length));

                m_FocusStartElement.SetAccessibleNameAndNotifyScreenReaderAutomationIfKeyboardFocused(strShort);
                m_FocusStartElement.ToolTip = strShort;
            }

            if (strBuilder == null)
            {
                strBuilder = new StringBuilder();
            }

            strBuilder.Insert(0, " *** ");

            string audioInfo = treeNode.GetManagedAudioMedia() != null ||
                               treeNode.GetFirstAncestorWithManagedAudio() != null
                                   ? Tobi_Plugin_StructureTrailPane_Lang.Audio
                                   : Tobi_Plugin_StructureTrailPane_Lang.NoAudio;

            strBuilder.Insert(0, audioInfo);
            strBuilder.Insert(0, " ");

            string label = getTreeNodeLabel(treeNode);

            string qNameStr = (!treeNode.HasXmlProperty
                                  ? Tobi_Plugin_StructureTrailPane_Lang.NoXML
                                  : String.Format(Tobi_Plugin_StructureTrailPane_Lang.XMLName, label)
                               );

            strBuilder.Insert(0, qNameStr);

            if (newTreeNodeSelection.Item2 != null)
            {
                TreeNode containingTreeNode = newTreeNodeSelection.Item1;

                string label2 = getTreeNodeLabel(containingTreeNode);

                string qNameStr2 = (!containingTreeNode.HasXmlProperty
                                      ? Tobi_Plugin_StructureTrailPane_Lang.NoXML
                                      : String.Format(Tobi_Plugin_StructureTrailPane_Lang.XMLName, label2)
                                    );

                strBuilder.Insert(0, " >> ");

                strBuilder.Insert(0, qNameStr2);
            }

            string str = strBuilder.ToString(0, Math.Min(500, strBuilder.Length));

            m_FocusStartElement2.SetAccessibleNameAndNotifyScreenReaderAutomationIfKeyboardFocused(str);
            m_FocusStartElement2.ToolTip = str;


            updateBreadcrumbPanel(newTreeNodeSelection);
        }
        private void OnBreadCrumbSeparatorClick(object sender, RoutedEventArgs e)
        {
            var ui = sender as Button;

            if (ui == null)
            {
                return;
            }
            var n = ui.Tag as TreeNode;

            if (n == null)
            {
                return;
            }

            if (ui.ContextMenu == null)
            {
                ui.ContextMenu = new ContextMenu();

                foreach (TreeNode child in n.Children.ContentsAs_Enumerable)
                {
                    bool childIsInPath = PathToCurrentTreeNode.Contains(child);

                    MenuItem menuItem = null;

                    string label = getTreeNodeLabel(child);
                    if (child.HasXmlProperty)
                    {
                        menuItem = new MenuItem();

                        if (childIsInPath)
                        {
                            var runMenuItem = new Run(label)
                            {
                                FontWeight = FontWeights.ExtraBold
                            };
                            var textBlock = new TextBlock(runMenuItem);
                            //textBlock.SetValue(AutomationProperties.NameProperty, qnameChild.LocalName);
                            menuItem.Header = textBlock;
                        }
                        else
                        {
                            menuItem.Header = label;
                        }
                    }
                    else
                    {
                        TreeNode.StringChunkRange txtChunkRange = child.GetText();
                        TreeNode.StringChunk      txtChunk      = txtChunkRange != null ? txtChunkRange.First : null; //child.GetTextChunk();

                        bool isWhiteSpace = txtChunk != null && txtChunk.Str == @" ";
                        if (!isWhiteSpace)
                        {
                            menuItem = new MenuItem();

                            if (childIsInPath)
                            {
                                var runMenuItem = new Run(label)
                                {
                                    FontWeight = FontWeights.ExtraBold
                                };
                                var textBlock = new TextBlock(runMenuItem);
                                //textBlock.SetValue(AutomationProperties.NameProperty, "TXT");
                                menuItem.Header = textBlock;
                            }
                            else
                            {
                                menuItem.Header = label;
                            }
                        }
                    }

                    if (menuItem != null)
                    {
                        menuItem.Tag    = child;
                        menuItem.Click += menuItem_Click;
                        ui.ContextMenu.Items.Add(menuItem);
                    }
                }
            }


            ui.ContextMenu.PlacementTarget = ui;
            ui.ContextMenu.Placement       = PlacementMode.Bottom;
            //ui.ContextMenu.PlacementRectangle=ui.
            ui.ContextMenu.IsOpen = true;

            //var node = (TreeNode)ui.Tag;

            //var popup = new Popup { IsOpen = false, Width = 120, Height = 150 };
            //BreadcrumbPanel.Children.Add(popup);
            //popup.PlacementTarget = ui;
            //popup.LostFocus += OnPopupLostFocus;
            //popup.LostMouseCapture += OnPopupLostFocus;
            //popup.LostKeyboardFocus += OnPopupLostKeyboardFocus;

            //var listOfNodes = new ListView();
            //listOfNodes.SelectionChanged += OnListOfNodesSelectionChanged;

            //foreach (TreeNode child in node.Children.ContentsAs_YieldEnumerable)
            //{
            //    listOfNodes.Items.Add(new TreeNodeWrapper()
            //    {
            //        Popup = popup,
            //        TreeNode = child
            //    });
            //}

            //var scroll = new ScrollViewer
            //{
            //    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
            //    VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
            //    Content = listOfNodes
            //};

            //popup.Child = scroll;
            //popup.IsOpen = true;

            //FocusHelper.FocusBeginInvoke(listOfNodes);
        }
Ejemplo n.º 7
0
        public static string GetDescriptionLabel(TreeNode treeNode, int limit)
        {
            //if (qname != null)
            //{
            //    str = "[" + qname.LocalName + "] ";
            //}

            StringBuilder strBuilder = null;
            int           length     = 0;

            TreeNode.StringChunkRange range = treeNode.GetTextFlattened_();
            if (range != null && range.First != null && !string.IsNullOrEmpty(range.First.Str))
            {
                strBuilder = new StringBuilder(range.GetLength());
                TreeNode.ConcatStringChunks(range, -1, strBuilder);
                length = strBuilder.Length;
                if (length > limit)
                {
                    //string str = strBuilder.ToString(0, 40);
                    //#if NET40
                    //                    stringBuilder.Clear();
                    //#else
                    //                    stringBuilder.Length = 0;
                    //#endif //NET40
                    //strBuilder.Append(str);
                    //strBuilder.Append("(...)");

                    string addon = "(...)";
                    strBuilder.Insert(limit, addon);
                    length = limit + addon.Length;
                }
            }

            if (treeNode.HasXmlProperty)
            {
                string localName = treeNode.GetXmlElementLocalName();

                if (localName.Equals("img", StringComparison.OrdinalIgnoreCase)
                    //|| localName.Equals("video", StringComparison.OrdinalIgnoreCase)
                    )
                {
                    XmlAttribute xmlAttr = treeNode.GetXmlProperty().GetAttribute("src");
                    if (xmlAttr != null && !String.IsNullOrEmpty(xmlAttr.Value))
                    {
                        if (strBuilder == null)
                        {
                            strBuilder = new StringBuilder();
                        }

                        int l1 = strBuilder.Length;

                        strBuilder.Append("  --> [");
                        string strAttr = xmlAttr.Value.TrimEnd('/');
                        strAttr = FileDataProvider.UriDecode(strAttr);

                        int index = strAttr.LastIndexOf('/');
                        if (index >= 0)
                        {
                            strBuilder.Append(strAttr.Substring(index + 1));
                        }
                        else
                        {
                            strBuilder.Append(strAttr);
                        }
                        strBuilder.Append("] ");

                        int l2    = strBuilder.Length;
                        int added = l2 - l1;
                        length += added;
                    }
                }
            }

            if (strBuilder == null)
            {
                return("");
            }

            return(strBuilder.ToString(0, Math.Min(length, strBuilder.Length)));
        }
Ejemplo n.º 8
0
        private static string ComputeNodeText(TreeNode level, TreeNode heading)
        {
            if (level == null && heading == null)
            {
                Debug.Fail("WTF ?");
                return("!??!");
            }

            StringBuilder strBuilder = null;

            if (heading != null)
            {
                TreeNode.StringChunkRange range = heading.GetTextFlattened_();

                if (range == null || range.First == null || string.IsNullOrEmpty(range.First.Str))
                {
                    return("");
                }

                strBuilder = new StringBuilder(range.GetLength());
                TreeNode.ConcatStringChunks(range, -1, strBuilder);

                strBuilder.Insert(0, "] ");
                strBuilder.Insert(0, heading.GetXmlElementLocalName());
                strBuilder.Insert(0, "[");
            }
            else
            {
                strBuilder = new StringBuilder();
                strBuilder.Append("[");
                strBuilder.Append(level.GetXmlElementLocalName());
                strBuilder.Append("] ");
                strBuilder.Append(Tobi_Plugin_NavigationPane_Lang.NoHeading);
            }

            return(strBuilder.ToString().Trim());

            //string sResult = string.Empty;
            //QualifiedName qName = node.GetXmlElementQName();
            //if (qName == null) { return sResult; }
            //if (HeadingsNavigator.IsLevel(qName.LocalName))
            //{
            //    if (node.Children.Count > 0)
            //    {
            //        TreeNode nd = node.Children.Get(0);
            //        if (nd != null)
            //        {
            //            QualifiedName qname = nd.GetXmlElementQName();
            //            if (qname != null && qname.LocalName == "pagenum" && node.Children.Count > 1)
            //            {
            //                nd = node.Children.Get(1);
            //                if (nd != null)
            //                {
            //                    qname = nd.GetXmlElementQName();
            //                }
            //            }
            //            if (qname != null &&
            //                (HeadingsNavigator.IsHeading(qname.LocalName) || qname.LocalName == "doctitle"))
            //            {
            //                sResult = nd.GetTextMediaFlattened(true);
            //            }
            //        }
            //    }
            //}
            //else if (HeadingsNavigator.IsHeading(qName.LocalName))
            //{
            //    sResult = node.GetTextMediaFlattened(true);
            //}
            //return sResult;
        }
Ejemplo n.º 9
0
        private static void SetText(TreeNode node, string txt)
        {
            TreeNode.StringChunkRange txtChunkRange = node.GetText();
            TreeNode.StringChunk      textLocal     = txtChunkRange != null ? txtChunkRange.First : null; //node.GetTextChunk();

            DebugFix.Assert(textLocal != null);
            if (textLocal != null)
            {
                if (textLocal.IsAbstractTextMedia)
                {
                    DebugFix.Assert(textLocal.m_TextMedia != null);

#if DEBUG
                    media.AbstractTextMedia textMedia = node.GetTextMedia();
                    DebugFix.Assert(textLocal.m_TextMedia == textMedia);
#endif //DEBUG

                    textLocal.m_TextMedia.Text = txt;
                }
                else
                {
                    DebugFix.Assert(textLocal.m_XmlAttribute != null);

#if DEBUG
                    if (node.HasXmlProperty)
                    {
                        string localName = node.GetXmlElementLocalName();
                        bool   isMath    = localName.Equals("math", StringComparison.OrdinalIgnoreCase);
                        if (localName.Equals("img", StringComparison.OrdinalIgnoreCase) ||
                            localName.Equals("video", StringComparison.OrdinalIgnoreCase) ||
                            isMath
                            )
                        {
                            urakawa.property.xml.XmlAttribute xmlAttr = node.GetXmlProperty().GetAttribute(isMath ? "alttext" : "alt");
                            if (xmlAttr != null)
                            {
                                DebugFix.Assert(textLocal.m_XmlAttribute == xmlAttr);
                            }
                        }
                        else if (node.Children.Count == 0)
                        {
                            urakawa.property.xml.XmlAttribute xmlAttr = node.GetXmlProperty().GetAttribute("title");
                            if (xmlAttr != null)
                            {
                                DebugFix.Assert(textLocal.m_XmlAttribute == xmlAttr);
                            }
                        }
                    }
#endif //DEBUG

                    textLocal.m_XmlAttribute.Value = txt;
                }

                DebugFix.Assert(textLocal.Str == txt);
                //DebugFix.Assert(textLocal.IsAbstractTextMedia);
                //DebugFix.Assert(range.Last == null);
            }

            //media.AbstractTextMedia textMedia = node.GetTextMedia();
            //if (textMedia != null)
            //{
            //    textMedia.Text = txt;

            //    TreeNode.StringChunk textLocal = node.GetTextMedia(true);
            //    DebugFix.Assert(textLocal != null);
            //    if (textLocal != null)
            //    {
            //        DebugFix.Assert(textLocal.Str == txt);
            //        DebugFix.Assert(textLocal.IsAbstractTextMedia);
            //        //DebugFix.Assert(range.Last == null);
            //    }

            //    return;
            //}
            //else
            //{
            //    QualifiedName qname = node.GetXmlElementQName();
            //    if (qname != null && qname.LocalName.Equals("img", StringComparison.OrdinalIgnoreCase))
            //    {
            //        urakawa.property.xml.XmlAttribute  xmlAttr = node.GetXmlProperty().GetAttribute("alt");
            //        if (xmlAttr != null)
            //        {
            //            xmlAttr.Value = txt;

            //            TreeNode.StringChunk textLocal = node.GetTextMedia(true);
            //            DebugFix.Assert(textLocal != null);
            //            if (textLocal != null)
            //            {
            //                DebugFix.Assert(textLocal.Str == txt);
            //                DebugFix.Assert(!textLocal.IsAbstractTextMedia);
            //                //DebugFix.Assert(range.Last == null);
            //            }

            //            return;
            //        }
            //    }
            //}
            //Debug.Fail("WTF ??");
        }
Ejemplo n.º 10
0
        public void drawChunkInfos(DrawingContext drawingContext,
                                   double hoffset, double heightAvailable, double widthAvailable, double bytesPerPixel
                                   , ScaleTransform trans)
        {
            //double xZoomed = imageAndDraw == null ? -1 : imageAndDraw.m_originalX * zoom;
            //double wZoomed = imageAndDraw == null ? -1 : imageAndDraw.m_originalW * zoom;

            Tuple <TreeNode, TreeNode> treeNodeSelection = m_AudioPaneViewModel.m_UrakawaSession.GetTreeNodeSelection();

            if (treeNodeSelection.Item1 != null && m_AudioPaneViewModel.State.Audio.PlayStreamMarkers != null)
            {
                //drawingContext.Pop(); //PushOpacity

                long   sumData     = 0;
                double pixelsLeft  = 0;
                double pixelsRight = 0;
                double widthChunk  = 0;

                m_marker_MouseOver_Left  = null;
                m_marker_MouseOver_Right = null;

#if USE_NORMAL_LIST
                foreach (TreeNodeAndStreamDataLength marker in m_AudioPaneViewModel.State.Audio.PlayStreamMarkers)
                {
#else
                LightLinkedList <TreeNodeAndStreamDataLength> .Item current = m_AudioPaneViewModel.State.Audio.PlayStreamMarkers.m_First;
                while (current != null)
                {
                    TreeNodeAndStreamDataLength marker = current.m_data;
#endif //USE_NORMAL_LIST
                    if (pixelsLeft > (hoffset + widthAvailable))
                    {
                        break;
                    }


                    //if (m_MousePosX >= 0)
                    //{
                    //    //long timeInLocalUnits = m_AudioPaneViewModel.State.Audio.GetCurrentPcmFormat().Data.
                    //    //    ConvertBytesToTime(
                    //    //        m_AudioPaneViewModel.State.Audio.GetCurrentPcmFormat().Data.
                    //    //            AdjustByteToBlockAlignFrameSize(
                    //    //                (long) Math.Round(m_AudioPaneView.BytesPerPixel*(hoffset + m_MousePosX))));


                    //    m_point1.X = m_MousePosX;
                    //    m_point1.Y = 0;

                    //    m_point2.X = m_MousePosX;
                    //    m_point2.Y = heightAvailable;

                    //    drawingContext.DrawLine(m_penTick, m_point1, m_point2);
                    //}

                    if (pixelsLeft > hoffset)
                    {
                        m_point1.X = pixelsLeft - hoffset;
                        m_point2.X = m_point1.X;
                        m_point1.Y = 0;
                        m_point2.Y = heightAvailable;
                        drawingContext.DrawLine(m_penPhrases, m_point1, m_point2);

                        if (marker == m_marker_MouseGrab_Left)
                        {
                            m_marker_MouseGrab_Left_X = m_point1.X;
                        }

                        bool mouseMatch = m_MousePosX > 0 &&
                                          m_MousePosX > m_point1.X - MOUSE_GRAB_OFFSET &&
                                          m_MousePosX < m_point1.X + MOUSE_GRAB_OFFSET;

                        bool highlightMark = mouseMatch || marker == m_marker_MouseGrab_Left;
                        if (highlightMark)
                        {
                            if (mouseMatch)
                            {
                                m_marker_MouseOver_Left = marker;
                            }

                            double pt1x = m_point1.X;

highlightMark_1:
                            double p1X = highlightMark ? pt1x : m_MousePosX;

                            m_point1.X = p1X - MOUSE_GRAB_OFFSET;
                            m_point2.X = m_point1.X;
                            drawingContext.DrawLine(!highlightMark ? m_penPhrases : m_penTick, m_point1, m_point2);

                            m_point1.X = p1X + MOUSE_GRAB_OFFSET;
                            m_point2.X = m_point1.X;
                            drawingContext.DrawLine(!highlightMark ? m_penPhrases : m_penTick, m_point1, m_point2);

                            if (highlightMark && marker == m_marker_MouseGrab_Left)
                            {
                                highlightMark = false;
                                goto highlightMark_1;
                            }
                        }
                    }

                    pixelsRight = (sumData + marker.m_LocalStreamDataLength) / bytesPerPixel;

                    if (pixelsRight > hoffset && pixelsRight < (hoffset + widthAvailable))
                    {
                        m_point1.X = pixelsRight - hoffset;
                        m_point2.X = m_point1.X;
                        m_point1.Y = 0;
                        m_point2.Y = heightAvailable;
                        drawingContext.DrawLine(m_penPhrases, m_point1, m_point2);

                        if (marker == m_marker_MouseGrab_Right)
                        {
                            m_marker_MouseGrab_Right_X = m_point1.X;
                        }

                        bool mouseMatch = m_MousePosX > 0 &&
                                          m_MousePosX > m_point1.X - MOUSE_GRAB_OFFSET &&
                                          m_MousePosX < m_point1.X + MOUSE_GRAB_OFFSET;

                        bool highlightMark = mouseMatch || marker == m_marker_MouseGrab_Right;

                        if (highlightMark)
                        {
                            if (mouseMatch)
                            {
                                m_marker_MouseOver_Right = marker;
                            }

                            double pt1x = m_point1.X;

highlightMark_2:
                            double p1X = highlightMark ? pt1x : m_MousePosX;

                            m_point1.X = p1X - MOUSE_GRAB_OFFSET;
                            m_point2.X = m_point1.X;
                            drawingContext.DrawLine(!highlightMark ? m_penPhrases : m_penTick, m_point1, m_point2);

                            m_point1.X = p1X + MOUSE_GRAB_OFFSET;
                            m_point2.X = m_point1.X;
                            drawingContext.DrawLine(!highlightMark ? m_penPhrases : m_penTick, m_point1, m_point2);

                            if (highlightMark && marker == m_marker_MouseGrab_Right)
                            {
                                highlightMark = false;
                                goto highlightMark_2;
                            }
                        }
                    }


                    widthChunk = pixelsRight - pixelsLeft;
                    if (pixelsRight > hoffset && pixelsLeft < (hoffset + widthAvailable))
                    {
                        if (widthChunk < 20)
                        {
                            sumData   += marker.m_LocalStreamDataLength;
                            pixelsLeft = pixelsRight;

#if !USE_NORMAL_LIST
                            current = current.m_nextItem;
#endif //USE_NORMAL_LIST

                            continue;
                        }

                        if (trans != null)
                        {
                            drawingContext.PushTransform(trans);
                        }


                        long timeInLocalUnits = m_AudioPaneViewModel.State.Audio.GetCurrentPcmFormat().Data.ConvertBytesToTime(
                            m_AudioPaneViewModel.State.Audio.GetCurrentPcmFormat().Data.AdjustByteToBlockAlignFrameSize(
                                (long)Math.Round(bytesPerPixel * (pixelsRight - pixelsLeft))));

                        double tickHeight = m_tickHeight;

                        double chunkWidthForText = widthChunk - tickHeight - tickHeight - 1;

                        //                        if (m_standardTextHeight <= 0)
                        //                        {
                        //                            var txt = new FormattedText("Test Height",
                        //                                                                  m_culture,
                        //                                                                  FlowDirection.LeftToRight,
                        //                                                                  m_typeFace,
                        //                                                                  12,
                        //                                                                  m_phraseBrush
                        //#if NET40
                        //, null, TextFormattingMode.Display
                        //#endif //NET40
                        //);
                        //                            m_standardTextHeight = txt.Height;
                        //                        }


                        string strTime = null;

                        if (marker.m_Tag1 == null || !(marker.m_Tag1 is string))
                        {
                            strTime       = AudioPaneViewModel.FormatTimeSpan_Units(timeInLocalUnits);
                            marker.m_Tag1 = strTime;
                        }
                        else
                        {
                            strTime = (string)marker.m_Tag1;
                        }

                        var formattedTextDuration = new FormattedText(
                            strTime,
                            m_culture,
                            FlowDirection.LeftToRight,
                            m_typeFace,
                            12 * (trans != null ? m_zoom : 1),
                            m_timeTextBrush
#if NET40
                            , null, TextFormattingMode.Display
#endif //NET40
                            );

                        double formattedTextDurationWidth  = formattedTextDuration.Width;
                        double formattedTextDurationHeight = formattedTextDuration.Height;
                        if (trans != null)
                        {
                            formattedTextDurationWidth  *= (1 / m_zoom);
                            formattedTextDurationHeight *= (1 / m_zoom);
                        }

                        formattedTextDuration.Trimming      = TextTrimming.CharacterEllipsis;
                        formattedTextDuration.MaxTextWidth  = chunkWidthForText * (trans != null ? m_zoom : 1);
                        formattedTextDuration.MaxTextHeight = (formattedTextDurationHeight + tickHeight) * (trans != null ? m_zoom : 1);

                        double horizontalMargin = m_horizontalMargin;

                        m_point3.X = pixelsLeft - hoffset + horizontalMargin + tickHeight;
                        if (m_point3.X < tickHeight)
                        {
                            widthChunk += m_point3.X;
                            m_point3.X  = tickHeight;
                        }

                        m_point3.Y = heightAvailable - (formattedTextDurationHeight * 2) - tickHeight - tickHeight - tickHeight;

                        double diff = (pixelsRight - hoffset) - widthAvailable;
                        if (diff > 0)
                        {
                            widthChunk -= diff;
                        }

                        double minW = Math.Min(formattedTextDurationWidth + horizontalMargin + horizontalMargin,
                                               widthChunk - tickHeight - tickHeight - 1);
                        if (minW > 0)
                        {
                            m_rectRect.X      = m_point3.X - horizontalMargin;
                            m_rectRect.Y      = m_point3.Y;
                            m_rectRect.Width  = minW;
                            m_rectRect.Height = formattedTextDurationHeight;

                            //if (drawingGroup != null)
                            //{
                            //    if (imageAndDraw == null
                            //        ||
                            //        (
                            //        m_rectRect.Left >= xZoomed
                            //        && m_rectRect.Left < xZoomed + wZoomed
                            //        ||
                            //        m_rectRect.Right > xZoomed
                            //        && m_rectRect.Right <= xZoomed + wZoomed
                            //        )
                            //        )
                            //    {
                            //        m_rectRect.X -= xZoomed;
                            //        if (m_rectRect.X <0)
                            //        {
                            //            m_rectRect.Width -= -m_rectRect.X;
                            //            m_rectRect.X = 0;
                            //        }
                            //        var rectGeo = new RectangleGeometry(m_rectRect);
                            //        rectGeo.Freeze();
                            //        var rectGeoDraw = new GeometryDrawing(m_renderBrush, null, rectGeo);
                            //        rectGeoDraw.Freeze();
                            //        drawingGroup.Children.Add(rectGeoDraw);

                            //        m_point4.X = m_point3.X;
                            //        m_point4.Y = m_point3.Y;
                            //        m_point4.X -= xZoomed;
                            //        if (m_point4.X >= 0)
                            //        {
                            //            var textGeo = formattedTextDuration.BuildGeometry(m_point4);
                            //            textGeo.Freeze();
                            //            var textGeoDraw = new GeometryDrawing(m_timeTextBrush, null, textGeo);
                            //            textGeoDraw.Freeze();
                            //            drawingGroup.Children.Add(textGeoDraw);
                            //        }
                            //    }
                            //}
                            //else
                            //{


                            if (trans != null)
                            {
                                m_point3.X *= m_zoom;
                                m_point3.Y *= m_zoom;

                                m_rectRect.X      *= m_zoom;
                                m_rectRect.Y      *= m_zoom;
                                m_rectRect.Width  *= m_zoom;
                                m_rectRect.Height *= m_zoom;
                            }


                            drawingContext.DrawRectangle(m_renderBrush, null, m_rectRect);

                            var clipGeo = new RectangleGeometry(m_rectRect);
                            clipGeo.Freeze();
                            drawingContext.PushClip(clipGeo);

                            drawingContext.DrawText(formattedTextDuration, m_point3);

                            drawingContext.Pop(); //PushClip
                            //}
                        }

                        if (chunkWidthForText <= 10)
                        {
                            sumData   += marker.m_LocalStreamDataLength;
                            pixelsLeft = pixelsRight;

#if !USE_NORMAL_LIST
                            current = current.m_nextItem;
#endif //USE_NORMAL_LIST

                            if (trans != null)
                            {
                                drawingContext.Pop();
                            }
                            continue;
                        }

                        //QualifiedName qName = marker.m_TreeNode.GetXmlElementQName();
                        //string imgAlt = null;
                        //if (qName != null && qName.LocalName.ToLower() == "img")
                        //{
                        //    XmlAttribute xmlAttr = marker.m_TreeNode.GetXmlProperty().GetAttribute("alt");
                        //    if (xmlAttr != null)
                        //    {
                        //        imgAlt = xmlAttr.Value;
                        //    }
                        //}
                        //string nodeTxt = !String.IsNullOrEmpty(imgAlt) ? imgAlt : marker.m_TreeNode.GetTextMediaFlattened(false);

                        string        strText       = null;
                        FlowDirection flowDirection = FlowDirection.LeftToRight;

                        if (marker.m_Tag2 == null || !(marker.m_Tag2 is string))
                        {
                            TreeNode.StringChunkRange range = marker.m_TreeNode.GetTextFlattened_();

                            if (range != null && range.First != null && !String.IsNullOrEmpty(range.First.Str))
                            {
                                if (range.First.Direction == TreeNode.TextDirection.RTL)
                                {
                                    flowDirection = FlowDirection.RightToLeft;
                                }

                                StringBuilder strBuilder = new StringBuilder(range.GetLength());
                                TreeNode.ConcatStringChunks(range, -1, strBuilder);

                                strBuilder.Replace("\r\n", "");
                                strBuilder.Replace("\n", "");
                                strBuilder.Replace(Environment.NewLine, "");

                                strText = strBuilder.ToString().Trim();

                                marker.m_Tag2 = strText;
                            }
                        }
                        else
                        {
                            strText = (string)marker.m_Tag2;
                        }

                        if (!string.IsNullOrEmpty(strText))
                        {
                            var formattedText = new FormattedText(strText,
                                                                  m_culture,
                                                                  flowDirection,
                                                                  m_typeFace,
                                                                  12 * (trans != null ? m_zoom : 1),
                                                                  m_phraseBrush
#if NET40
                                                                  , null, TextFormattingMode.Display
#endif //NET40
                                                                  );

                            formattedText.Trimming      = TextTrimming.CharacterEllipsis;
                            formattedText.MaxTextWidth  = chunkWidthForText * (trans != null ? m_zoom : 1);
                            formattedText.MaxTextHeight = (formattedTextDurationHeight + tickHeight) * (trans != null ? m_zoom : 1);

                            double formattedTextWidth  = formattedText.Width;
                            double formattedTextHeight = formattedText.Height;
                            if (trans != null)
                            {
                                formattedTextWidth  *= (1 / m_zoom);
                                formattedTextHeight *= (1 / m_zoom);
                            }
                            //FormattedText formattedTextDots = null;

                            m_point3.Y = heightAvailable - formattedTextDurationHeight - tickHeight - tickHeight;

                            minW = Math.Min(formattedTextWidth + horizontalMargin + horizontalMargin,
                                            widthChunk - tickHeight - tickHeight - 1);     //chunkWidthForText
                            if (minW > 0)
                            {
                                m_rectRect.X      = m_point3.X / m_zoom - horizontalMargin;
                                m_rectRect.Y      = m_point3.Y;
                                m_rectRect.Width  = minW;
                                m_rectRect.Height = formattedTextDurationHeight;

                                //if (drawingGroup != null)
                                //{
                                //    if (imageAndDraw == null
                                //        ||
                                //        (
                                //        m_rectRect.Left >= xZoomed
                                //        && m_rectRect.Left < xZoomed + wZoomed
                                //        ||
                                //        m_rectRect.Right > xZoomed
                                //        && m_rectRect.Right <= xZoomed + wZoomed
                                //        )
                                //        )
                                //    {
                                //        m_rectRect.X -= xZoomed;
                                //        if (m_rectRect.X < 0)
                                //        {
                                //            m_rectRect.Width -= -m_rectRect.X;
                                //            m_rectRect.X = 0;
                                //        }
                                //        var rectGeo = new RectangleGeometry(m_rectRect);
                                //        rectGeo.Freeze();
                                //        var rectGeoDraw = new GeometryDrawing(m_renderBrush, null, rectGeo);
                                //        rectGeoDraw.Freeze();
                                //        drawingGroup.Children.Add(rectGeoDraw);

                                //        m_point3.X -= xZoomed;
                                //        if (m_point3.X >= 0)
                                //        {
                                //            var textGeo = formattedText.BuildGeometry(m_point3);
                                //            textGeo.Freeze();
                                //            var textGeoDraw = new GeometryDrawing(m_phraseBrush, null, textGeo);
                                //            textGeoDraw.Freeze();
                                //            drawingGroup.Children.Add(textGeoDraw);
                                //        }
                                //    }
                                //}
                                //else
                                //{
                                //drawingContext.PushOpacity(0.6);


                                if (trans != null)
                                {
                                    //m_point3.X *= m_zoom; ==> X is "borrowed" from previous text render, already zoomed
                                    m_point3.Y *= m_zoom;

                                    m_rectRect.X      *= m_zoom;
                                    m_rectRect.Y      *= m_zoom;
                                    m_rectRect.Width  *= m_zoom;
                                    m_rectRect.Height *= m_zoom;
                                }


                                drawingContext.DrawRectangle(m_renderBrush, null, m_rectRect);

                                //Boolean mouseIn = m_MousePosX >= (pixelsLeft - hoffset) &&
                                //                  m_MousePosX < (pixelsRight - hoffset);
                                //if (mouseIn)
                                //{
                                //    //drawingContext.Pop(); //PushOpacity
                                //}
                                var clipGeo = new RectangleGeometry(m_rectRect);
                                clipGeo.Freeze();
                                drawingContext.PushClip(clipGeo);

                                drawingContext.DrawText(formattedText, m_point3);

                                drawingContext.Pop(); //PushClip

                                //if (!mouseIn)
                                //{
                                //    //drawingContext.Pop(); //PushOpacity
                                //}

                                //if (false && formattedText.Width >= minW)
                                //{
                                //    formattedTextDots = new FormattedText(" ...",
                                //                                      m_culture,
                                //                                      FlowDirection.LeftToRight,
                                //                                      m_typeFace,
                                //                                      12,
                                //                                      m_timeTextBrush
                                //    );
                                //}

                                //if (formattedTextDots != null && formattedTextDots.Width < minW)
                                //{
                                //    m_point3.X = m_rectRect.X + m_rectRect.Width - formattedTextDots.Width;
                                //    m_rectRect.X = m_point3.X;
                                //    m_rectRect.Width = formattedTextDots.Width;

                                //    drawingContext.DrawRectangle(m_renderBrush, null, m_rectRect);
                                //    drawingContext.DrawText(formattedTextDots, m_point3);
                                //}
                                //}
                            }
                        }

                        if (trans != null)
                        {
                            drawingContext.Pop();
                        }
                    }

                    sumData   += marker.m_LocalStreamDataLength;
                    pixelsLeft = pixelsRight;

#if USE_NORMAL_LIST
                }
#else
                    current = current.m_nextItem;
                }
#endif //USE_NORMAL_LIST
                //drawingContext.PushOpacity(0.6);
            }
        }
Ejemplo n.º 11
0
        protected string AdjustAudioFileName(ExternalAudioMedia externalAudio, TreeNode levelNode)
        {
            //#if !TOBI
            //            // Obi should not use this, as the above AddSectionNameToAudioFileName() is used instead!!
            //            Debugger.Break();
            //            return externalAudio.Src;
            //#endif

            // Obi should return below!
            if (!IsAdjustAudioFileNameEnabled)
            {
                return(externalAudio.Src);
            }

            if (externalAudio.Tag == null || !(externalAudio.Tag is TreeNode))
            {
#if DEBUG
                Debugger.Break();
#endif
                return(externalAudio.Src);
            }
            TreeNode node = externalAudio.Tag as TreeNode;

            // In some cases this occurs (for example with Great Painters,
            // or when m_audioExportDTBOOKElementNameTriggers / doesTreeNodeTriggerNewSmil() is set to level2 but not level1
            // The generated SMIL and audio file structure looks okay, but the heading/section title is missing in the filename
            // DebugFix.Assert(node == levelNode);
#if DEBUG
            if (node != levelNode)
            {
                bool breakpointHere = true;
            }
            // Debugger.Break();
#endif

            string src = null;
            m_adjustedExternalAudioFileNames.TryGetValue(node, out src);

            if (!string.IsNullOrEmpty(src))
            {
#if DEBUG
                //DebugFix.Assert(!src.Equals(externalAudio.Src, StringComparison.Ordinal));

                //if (src.Equals(externalAudio.Src, StringComparison.Ordinal))
                //{
                //    Debugger.Break();
                //}
#endif
                externalAudio.Src = src;
                return(src);
            }

            string strTitle = "";

            bool html5_outlining = node.Presentation.RootNode.GetXmlElementLocalName()
                                   .Equals("body", StringComparison.OrdinalIgnoreCase);
            if (html5_outlining)
            {
#if DEBUG
                Debugger.Break();
#endif
                //TODO?
                //List<Section> sections = node.Presentation.RootNode.GetOrCreateOutline()
                // spine item / HTML title??
            }
            else
            {
                string localName = node.GetXmlElementLocalName();

#if DEBUG
                //protected virtual bool doesTreeNodeTriggerNewSmil(TreeNode node)

                DebugFix.Assert(node.HasXmlProperty);

                DebugFix.Assert(localName.StartsWith("level", StringComparison.OrdinalIgnoreCase) ||
                                localName.Equals("section", StringComparison.OrdinalIgnoreCase) ||
                                localName.Equals("book", StringComparison.OrdinalIgnoreCase)
                                );
#endif

                TreeNode heading = null;

                if (TreeNode.IsLevel(localName))
                {
                    TreeNode level = node;

                    if (level.Children.Count > 0)
                    {
                        TreeNode nd = level.Children.Get(0);
                        if (nd != null)
                        {
                            localName = nd.HasXmlProperty ? nd.GetXmlElementLocalName() : null;

                            if (localName != null && (localName == "pagenum" || localName == "img") &&
                                level.Children.Count > 1)
                            {
                                nd = level.Children.Get(1);
                                if (nd != null)
                                {
                                    localName = nd.GetXmlElementLocalName();
                                }
                            }

                            if (localName != null &&
                                (TreeNode.IsHeading(localName)))
                            {
                                heading = nd;
                            }
                            else
                            {
                                if (localName != null && (localName == "pagenum" || localName == "img") &&
                                    level.Children.Count > 2)
                                {
                                    nd = level.Children.Get(2);
                                    if (nd != null)
                                    {
                                        localName = nd.GetXmlElementLocalName();
                                    }
                                }

                                if (localName != null &&
                                    (TreeNode.IsHeading(localName)))
                                {
                                    heading = nd;
                                }
                            }
                        }
                    }
                }
                else if (TreeNode.IsHeading(localName))
                {
#if DEBUG
                    Debugger.Break();
#endif
                    heading = node;
                }
                else if (!localName.Equals("book", StringComparison.OrdinalIgnoreCase))
                {
#if DEBUG
                    Debugger.Break();
#endif
                }


                StringBuilder strBuilder = null;

                if (heading != null)
                {
                    TreeNode.StringChunkRange range = heading.GetTextFlattened_();

                    if (!(range == null || range.First == null || string.IsNullOrEmpty(range.First.Str)))
                    {
                        strBuilder = new StringBuilder(range.GetLength());
                        TreeNode.ConcatStringChunks(range, -1, strBuilder);

                        //strBuilder.Insert(0, "] ");
                        //strBuilder.Insert(0, heading.GetXmlElementLocalName());
                        //strBuilder.Insert(0, "[");
                    }
                }
                //else
                //{
                //    strBuilder = new StringBuilder();
                //    strBuilder.Append("[");
                //    strBuilder.Append(level.GetXmlElementLocalName());
                //    strBuilder.Append("] ");
                //    strBuilder.Append(Tobi_Plugin_NavigationPane_Lang.NoHeading);
                //}

                if (strBuilder != null)
                {
                    strTitle = strBuilder.ToString().Trim();
                }
            }

            if (strTitle.Length > 0)
            {
                strTitle = FileDataProvider.EliminateForbiddenFileNameCharacters(strTitle.Replace(" ", "_"));
            }

            int MAX_LENGTH = AudioFileNameCharsLimit > 0 ? AudioFileNameCharsLimit : 10;
            if (strTitle.Length > MAX_LENGTH)
            {
                strTitle = strTitle.Substring(0, MAX_LENGTH);
            }

            string filename = Path.GetFileName(externalAudio.Src);
            string source   = Path.Combine(m_OutputDirectory, filename);
            if (File.Exists(source))
            {
                if (strTitle.Length > 0)
                {
                    string newFileName = filename;

                    string name = Path.GetFileNameWithoutExtension(externalAudio.Src);
                    name = name.Replace("aud", "");

                    string ext = Path.GetExtension(externalAudio.Src);
                    newFileName = name + "_" + strTitle + ext;

                    //externalAudio.Src = externalAudio.Src.Replace(filename, newFileName);
                    externalAudio.Src = newFileName;
                    m_adjustedExternalAudioFileNames.Add(node, externalAudio.Src);

                    string dest = Path.Combine(m_OutputDirectory, newFileName);

                    File.Move(source, dest);
                    try
                    {
                        File.SetAttributes(dest, FileAttributes.Normal);
                    }
                    catch
                    {
                    }

                    return(newFileName);
                }
            }

            return(filename);
        }