internal static void OnClickOnPopupOrWindow(object sender, PointerRoutedEventArgs e)
#endif
        {
            // Note: If a popup has StayOpen=True, the value of "StayOpen" of its parents is ignored.
            // In other words, the parents of a popup that has StayOpen=True will always stay open
            // regardless of the value of their "StayOpen" property.

            HashSet2 <Popup> listOfPopupThatMustBeClosed = new HashSet2 <Popup>();
            List <PopupRoot> popupRootList = new List <PopupRoot>();

            foreach (object obj in GetAllRootUIElements())
            {
                if (obj is PopupRoot)
                {
                    PopupRoot root = (PopupRoot)obj;
                    popupRootList.Add(root);

                    if (root.INTERNAL_LinkedPopup != null)
                    {
                        listOfPopupThatMustBeClosed.Add(root.INTERNAL_LinkedPopup);
                    }
                }
            }

            // We determine which popup needs to stay open after this click
            foreach (PopupRoot popupRoot in popupRootList)
            {
                if (popupRoot.INTERNAL_LinkedPopup != null)
                {
                    // We must prevent all the parents of a popup to be closed when:
                    // - this popup is set to StayOpen
                    // - or the click happend in this popup

                    Popup popup = popupRoot.INTERNAL_LinkedPopup;

                    if (popup.StayOpen || sender == popupRoot)
                    {
                        do
                        {
                            if (!listOfPopupThatMustBeClosed.Contains(popup))
                            {
                                break;
                            }

                            listOfPopupThatMustBeClosed.Remove(popup);

                            popup = popup.ParentPopup;
                        } while (popup != null);
                    }
                }
            }

            foreach (Popup popup in listOfPopupThatMustBeClosed)
            {
                popup.CloseFromAnOutsideClick();
            }
        }
 static void RemoveFromDictionaryIfFound(Dictionary <DependencyObject, HashSet2 <DependencyObject> > dictionary, DependencyObject key, DependencyObject value)
 {
     if (dictionary.ContainsKey(key))
     {
         HashSet2 <DependencyObject> list = dictionary[key];
         if (list.Contains(value))
         {
             list.Remove(value);
         }
     }
 }
Beispiel #3
0
        static object ConvertCSharpObjectToJavaScriptObject(object cSharpObject, bool ignoreErrors, HashSet2 <object> listOfParentsToAvoidCyclicReferences)
        {
            if (cSharpObject != null && listOfParentsToAvoidCyclicReferences.Contains(cSharpObject))
            {
                return(null); //to avoid circular references, which "JSON.stringify" does not handle without specifying what to do in case of circulare reference (cf. https://stackoverflow.com/questions/10392293/stringify-convert-to-json-a-javascript-object-with-circular-reference )
            }
            else
            {
                listOfParentsToAvoidCyclicReferences.Add(cSharpObject);
                object returnValue;

                if (cSharpObject is Enum || cSharpObject is Guid || cSharpObject is long)
                {
                    returnValue = cSharpObject.ToString();
                }
                else if (cSharpObject is DateTime)
                {
                    //Uncomment when fully supported by CSHTML5:
                    //return ((DateTime)cSharpObject).ToUniversalTime().ToString("s", System.Globalization.CultureInfo.InvariantCulture);

                    var      dateTimeUtc           = ((DateTime)cSharpObject).ToUniversalTime();
                    TimeSpan timeSince1970         = (dateTimeUtc - new DateTime(1970, 1, 1, 0, 0, 0));
                    double   millisecondsSince1970 = timeSince1970.TotalMilliseconds;
                    var      jsDate = Interop.ExecuteJavaScript("new Date($0)", millisecondsSince1970);
                    string   json   = Convert.ToString(Interop.ExecuteJavaScript("$0.toJSON()", jsDate));
                    returnValue = json;
                }
                else if (cSharpObject is string
#if !BRIDGE
                         || (cSharpObject != null && cSharpObject.GetType().IsValueType)
#endif
                         )
                {
                    returnValue = cSharpObject;
                }
#if BRIDGE
                else if (cSharpObject != null && cSharpObject.GetType().IsValueType)
                {
                    returnValue = Interop.ExecuteJavaScript("$0.v", cSharpObject);
                }
#endif
                else if (cSharpObject is IEnumerable && !(cSharpObject is string))
                {
                    //----------------
                    // ARRAY
                    //----------------

                    // Create the JS array:
                    var jsArray = Interop.ExecuteJavaScript("[]");

                    // Traverse the enumerable:
                    foreach (var cSharpItem in (IEnumerable)cSharpObject)
                    {
                        var jsItem = ConvertCSharpObjectToJavaScriptObject(cSharpItem, ignoreErrors, listOfParentsToAvoidCyclicReferences);
                        Interop.ExecuteJavaScript("$0.push($1)", jsArray, jsItem);
                    }

                    returnValue = jsArray;
                }
                else if (cSharpObject != null)
                {
                    //----------------
                    // OBJECT
                    //----------------

                    var jsObject = Interop.ExecuteJavaScript(@"new Object()");

                    // Traverse all properties:
                    foreach (PropertyInfo property in cSharpObject.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
                    {
                        string propertyName  = property.Name;
                        object propertyValue = property.GetValue(cSharpObject);

                        if (propertyValue != null)
                        {
                            var recursionResult = ConvertCSharpObjectToJavaScriptObject(propertyValue, ignoreErrors, listOfParentsToAvoidCyclicReferences);
                            if (recursionResult != null)
                            {
                                Interop.ExecuteJavaScript(@"$0[$1] = $2;", jsObject, propertyName, recursionResult);
                            }
                        }
                    }

                    returnValue = jsObject;
                }
                else
                {
                    returnValue = Interop.ExecuteJavaScript("undefined");
                }

                listOfParentsToAvoidCyclicReferences.Remove(cSharpObject);

                return(returnValue);
            }
        }
Beispiel #4
0
        private static void RecourseFonts(PdfDictionary page, IntHashtable hits, List<object[]> fonts, int level, HashSet2<PdfDictionary> visitedResources)
        {
            ++level;
            if (level > 50) // in case we have an endless loop
                return;
            if (page == null)
                return;
            PdfDictionary resources = page.GetAsDict(PdfName.RESOURCES);
            if (resources == null)
                return;
            PdfDictionary font = resources.GetAsDict(PdfName.FONT);
            if (font != null) {
                foreach (PdfName key in font.Keys) {
                    PdfObject ft = font.Get(key);        
                    if (ft == null || !ft.IsIndirect())
                        continue;
                    int hit = ((PRIndirectReference)ft).Number;
                    if (hits.ContainsKey(hit))
                        continue;
                    AddFont((PRIndirectReference)ft, hits, fonts);
                }
            }
            
            
            PdfDictionary xobj = resources.GetAsDict(PdfName.XOBJECT);
            if(xobj != null){
                if (visitedResources.AddAndCheck(xobj)){
                    foreach (PdfName key in xobj.Keys) {
                        PdfObject po = xobj.GetDirectObject(key);
                        if (po is PdfDictionary)
                            RecourseFonts((PdfDictionary)po, hits, fonts, level, visitedResources);
                    }
                    visitedResources.Remove(xobj);
                } else                    
                throw new InvalidPdfException(MessageLocalization.GetComposedMessage("illegal.resources.tree"));
            }

        }