Esempio n. 1
0
            public static void Invoke(Delegate callback, object args, SynchronizationContext context)
            {
                SynchronizationContext currentContext = SynchronizationContext.Current;

                try
                {
                    SynchronizationContext.SetSynchronizationContext(context);

                    if (callback is Action)
                    {
                        Action action = (Action)callback;
                        action();
                    }
                    else if (callback is SendOrPostCallback)
                    {
                        SendOrPostCallback sendOrPost = (SendOrPostCallback)callback;
                        sendOrPost(args);
                    }
                    else
                    {
                        callback.DynamicInvoke(args);
                    }
                }
                catch (OperationCanceledException) { }
                catch (Exception e)
                {
                    Error.UnhandledException(e);
                }
                finally
                {
                    SynchronizationContext.SetSynchronizationContext(currentContext);
                }
            }
        private static int OnTimerEvent(IntPtr cPtr, int timerId)
        {
            try
            {
                View     view = (View)Noesis.Extend.GetProxy(cPtr, false);
                TimerKey key  = new TimerKey {
                    View = view, TimerId = timerId
                };

                TimerCallback callback;
                if (_Timer.TryGetValue(key, out callback))
                {
                    int nextTick = callback();
                    if (nextTick <= 0)
                    {
                        _Timer.Remove(key);
                    }

                    return(nextTick);
                }
            }
            catch (Exception exception)
            {
                Error.UnhandledException(exception);
            }

            return(0);
        }
Esempio n. 3
0
        private static int OnTimerEvent(IntPtr cPtr, int timerId)
        {
            try
            {
                View view = (View)Noesis.Extend.GetProxy(cPtr, false);

                TimerCallback callback;
                if (view._timers.TryGetValue(timerId, out callback))
                {
                    int nextTick = callback();
                    if (nextTick <= 0)
                    {
                        view._timers.Remove(timerId);
                    }

                    return(nextTick);
                }
            }
            catch (Exception exception)
            {
                Error.UnhandledException(exception);
            }

            return(0);
        }
Esempio n. 4
0
 protected static void OnPropertyChanged(IntPtr cPtr, IntPtr d, IntPtr e)
 {
     try
     {
         PropertyChangedCallback callback;
         long ptr = cPtr.ToInt64();
         if (!_PropertyChangedCallback.TryGetValue(ptr, out callback))
         {
             throw new Exception("PropertyChangedCallback not found");
         }
         if (d == IntPtr.Zero && e == IntPtr.Zero)
         {
             _PropertyChangedCallback.Remove(ptr);
             return;
         }
         if (Noesis.Extend.Initialized && callback != null)
         {
             DependencyObject sender = (DependencyObject)Noesis.Extend.GetProxy(d, false);
             if (sender != null)
             {
                 callback(sender, new DependencyPropertyChangedEventArgs(e, false));
             }
         }
     }
     catch (Exception exception)
     {
         Error.UnhandledException(exception);
     }
 }
Esempio n. 5
0
 private static void RaiseRendering(IntPtr cPtr, IntPtr sender)
 {
     try
     {
         if (Noesis.Extend.Initialized)
         {
             if (sender == IntPtr.Zero)
             {
                 _Rendering.Remove(cPtr);
                 return;
             }
             RenderingEventHandler handler = null;
             if (!_Rendering.TryGetValue(cPtr, out handler))
             {
                 throw new InvalidOperationException(
                           "Delegate not registered for Rendering event");
             }
             if (handler != null)
             {
                 handler((View)Noesis.Extend.GetProxy(cPtr, false), NoesisEventArgs.Empty);
             }
         }
     }
     catch (Exception exception)
     {
         Error.UnhandledException(exception);
     }
 }
Esempio n. 6
0
 protected static void OnPropertyChanged(IntPtr cPtr, IntPtr d, IntPtr e)
 {
     try
     {
         if (!_PropertyChangedCallback.ContainsKey(cPtr))
         {
             throw new Exception("PropertyChangedCallback not found");
         }
         if (d == IntPtr.Zero && e == IntPtr.Zero)
         {
             _PropertyChangedCallback.Remove(cPtr);
             return;
         }
         if (Noesis.Extend.Initialized)
         {
             PropertyChangedCallback callback = _PropertyChangedCallback[cPtr];
             if (callback != null)
             {
                 callback((DependencyObject)Noesis.Extend.GetProxy(d, false),
                          new DependencyPropertyChangedEventArgs(e, false));
             }
         }
     }
     catch (Exception exception)
     {
         Error.UnhandledException(exception);
     }
 }
Esempio n. 7
0
 private static void OnRemoveCallback(int callbackId)
 {
     try {
         _callbacks.Remove(callbackId);
     }
     catch (Exception e) {
         Error.UnhandledException(e);
     }
 }
Esempio n. 8
0
 private static void UnregisterTexture(IntPtr texturePtr)
 {
     try
     {
         Textures.Remove(texturePtr.ToInt64());
     }
     catch (Exception exception)
     {
         Error.UnhandledException(exception);
     }
 }
Esempio n. 9
0
 private static void OnOpenUrl(IntPtr url)
 {
     try
     {
         if (_initialized)
         {
             _openUrlCallback(Extend.StringFromNativeUtf8(url));
         }
     }
     catch (Exception e)
     {
         Error.UnhandledException(e);
     }
 }
Esempio n. 10
0
 private static void OnPlaySound(IntPtr sound, float volume)
 {
     try
     {
         if (_initialized)
         {
             _playSoundCallback(Extend.StringFromNativeUtf8(sound), volume);
         }
     }
     catch (Exception e)
     {
         Error.UnhandledException(e);
     }
 }
Esempio n. 11
0
 private static void OnEnumKeys(int id, string key)
 {
     try {
         if (Noesis.Extend.Initialized)
         {
             KeysData keys = _keysData[id];
             Type     type = Noesis.Extend.FindType(key);
             keys.Keys[keys.Index++] = type != null ? (object)type : (object)key;
         }
     }
     catch (Exception e) {
         Error.UnhandledException(e);
     }
 }
Esempio n. 12
0
 private static void OnXamlDependency(int callbackId, IntPtr uri, int type)
 {
     try
     {
         if (_initialized)
         {
             Deps deps = _depsCallbacks[callbackId];
             deps.Callback(Extend.StringFromNativeUtf8(uri), (XamlDependencyType)type);
         }
     }
     catch (Exception e)
     {
         Error.UnhandledException(e);
     }
 }
Esempio n. 13
0
 private static void OnUpdateCursor(IntPtr cPtrView, int cursor)
 {
     try
     {
         if (_initialized)
         {
             View view = (View)Extend.GetProxy(cPtrView, false);
             _updateCursorCallback(view, (Cursor)cursor);
         }
     }
     catch (Exception e)
     {
         Error.UnhandledException(e);
     }
 }
Esempio n. 14
0
 private static void OnSoftwareKeyboard(IntPtr cPtrFocused, bool open)
 {
     try
     {
         if (_initialized)
         {
             UIElement focused = Extend.GetProxy(cPtrFocused, false) as UIElement;
             _softwareKeyboardCallback(focused, open);
         }
     }
     catch (Exception e)
     {
         Error.UnhandledException(e);
     }
 }
Esempio n. 15
0
 private static void OnPlayAudio(IntPtr sound, float volume)
 {
     try
     {
         if (_initialized)
         {
             string uriStr = Extend.StringFromNativeUtf8(sound);
             _playAudioCallback(new Uri(uriStr, UriKind.RelativeOrAbsolute), volume);
         }
     }
     catch (Exception e)
     {
         Error.UnhandledException(e);
     }
 }
Esempio n. 16
0
 private static void OnXamlDependency(int callbackId, IntPtr uri, int type)
 {
     try
     {
         if (_initialized)
         {
             Deps   deps   = _depsCallbacks[callbackId];
             string uriStr = Extend.StringFromNativeUtf8(uri);
             deps.Callback(new Uri(uriStr, UriKind.RelativeOrAbsolute), (XamlDependencyType)type);
         }
     }
     catch (Exception e)
     {
         Error.UnhandledException(e);
     }
 }
Esempio n. 17
0
 private static IntPtr OnTextureRender(int callbackId, IntPtr devicePtr, IntPtr userPtr)
 {
     try {
         if (Noesis.Extend.Initialized)
         {
             TextureRenderCallback callback = _callbacks[callbackId];
             RenderDevice          device   = (RenderDevice)Noesis.Extend.GetProxy(devicePtr, false);
             object  user    = Noesis.Extend.GetProxy(userPtr, false);
             Texture texture = callback(device, user);
             return(Noesis.Extend.GetInstanceHandle(texture).Handle);
         }
     }
     catch (Exception e) {
         Error.UnhandledException(e);
     }
     return(IntPtr.Zero);
 }
Esempio n. 18
0
        private static uint GetWidth(IntPtr cPtr)
        {
            try
            {
                Texture tex = (Texture)Noesis.Extend.GetExtendInstance(cPtr);
                if (tex != null)
                {
                    return(tex.Width);
                }
            }
            catch (Exception e)
            {
                Error.UnhandledException(e);
            }

            return(0);
        }
Esempio n. 19
0
        private static bool GetHasAlpha(IntPtr cPtr)
        {
            try
            {
                Texture tex = (Texture)Noesis.Extend.GetExtendInstance(cPtr);
                if (tex != null)
                {
                    return(tex.HasAlpha);
                }
            }
            catch (Exception e)
            {
                Error.UnhandledException(e);
            }

            return(false);
        }
Esempio n. 20
0
 private static void OnFontFace(int callbackId, int index, IntPtr familyName,
                                int weight, int style, int stretch)
 {
     try
     {
         if (_initialized)
         {
             Faces faces = _facesCallbacks[callbackId];
             faces.Callback(index, Extend.StringFromNativeUtf8(familyName),
                            (FontWeight)weight, (FontStyle)style, (FontStretch)stretch);
         }
     }
     catch (Exception e)
     {
         Error.UnhandledException(e);
     }
 }
Esempio n. 21
0
        private static IntPtr GetTexture(IntPtr cPtr)
        {
            try
            {
                RenderTarget rt = (RenderTarget)Noesis.Extend.GetExtendInstance(cPtr);
                if (rt != null)
                {
                    Texture   tex    = rt.Texture;
                    HandleRef texPtr = Noesis.Extend.GetInstanceHandle(tex);
                    return(texPtr.Handle);
                }
            }
            catch (Exception e)
            {
                Error.UnhandledException(e);
            }

            return(IntPtr.Zero);
        }
Esempio n. 22
0
        private static void OnClassHandler(IntPtr cPtrType, IntPtr cPtr,
                                           IntPtr sender, IntPtr args)
        {
            try
            {
                ClassHandlerInfo c = (ClassHandlerInfo)Extend.GetProxy(cPtrType, cPtr, false);

                HandlerInfo info;
                if (!_handlerTypes.TryGetValue(Key(c.RoutedEvent), out info))
                {
                    throw new InvalidOperationException("Routed event " + c.RoutedEvent.Name + " not registered");
                }

                info.Invoker(c.Handler, sender, args);
            }
            catch (Exception exception)
            {
                Error.UnhandledException(exception);
            }
        }
Esempio n. 23
0
        private static void RaiseEvent(IntPtr cPtrType, IntPtr cPtr, string eventId,
                                       IntPtr sender, IntPtr e)
        {
            try
            {
                if (Extend.Initialized)
                {
                    UIElement element = (UIElement)Extend.GetProxy(cPtrType, cPtr, false);
                    if (element == null)
                    {
                        return;
                    }

                    EnsureEventsProperty();
                    EventHandlerStore events = (EventHandlerStore)element.GetValue(EventsProperty);
                    long eventKey            = eventId.GetHashCode();

                    // check if we are called to unbind the event
                    if (sender == IntPtr.Zero && e == IntPtr.Zero)
                    {
                        events._binds.Remove(eventKey);
                        return;
                    }

                    // invoke handler
                    Delegate eventHandler;
                    if (!events._binds.TryGetValue(eventKey, out eventHandler))
                    {
                        return;
                    }

                    EventManager.InvokeHandler(eventId, eventHandler, sender, e);
                }
            }
            catch (Exception exception)
            {
                Error.UnhandledException(exception);
            }
        }
Esempio n. 24
0
        protected static IntPtr OnCoerceValue(IntPtr cPtr, IntPtr d, IntPtr baseValue)
        {
            try
            {
                if (!_CoerceValueCallback.ContainsKey(cPtr))
                {
                    throw new Exception("CoerceValueCallback not found");
                }
                if (d == IntPtr.Zero && baseValue == IntPtr.Zero)
                {
                    _CoerceValueCallback.Remove(cPtr);
                    return(IntPtr.Zero);
                }
                if (Noesis.Extend.Initialized)
                {
                    CoerceValueCallback callback = _CoerceValueCallback[cPtr];
                    if (callback != null)
                    {
                        object coercedValue = callback(
                            (DependencyObject)Noesis.Extend.GetProxy(d, false),
                            Noesis.Extend.GetProxy(baseValue, false));

                        HandleRef handle = Noesis.Extend.GetInstanceHandle(coercedValue);
                        BaseComponent.AddReference(handle.Handle); // released by native bindings

                        return(handle.Handle);
                    }
                }
            }
            catch (Exception exception)
            {
                Error.UnhandledException(exception);
            }

            BaseComponent.AddReference(baseValue); // released by native bindings
            return(baseValue);
        }
Esempio n. 25
0
        protected static IntPtr OnCoerceValue(IntPtr cPtr, IntPtr d, IntPtr baseValue)
        {
            try
            {
                CoerceValueCallback callback;
                long ptr = cPtr.ToInt64();
                if (!_CoerceValueCallback.TryGetValue(ptr, out callback))
                {
                    throw new Exception("CoerceValueCallback not found");
                }
                if (d == IntPtr.Zero && baseValue == IntPtr.Zero)
                {
                    _CoerceValueCallback.Remove(ptr);
                    return(IntPtr.Zero);
                }
                if (Noesis.Extend.Initialized && callback != null)
                {
                    DependencyObject sender = (DependencyObject)Noesis.Extend.GetProxy(d, false);
                    if (sender != null)
                    {
                        object coercedValue = callback(sender, Noesis.Extend.GetProxy(baseValue, false));

                        HandleRef handle = Noesis.Extend.GetInstanceHandle(coercedValue);
                        BaseComponent.AddReference(handle.Handle); // released by native bindings

                        return(handle.Handle);
                    }
                }
            }
            catch (Exception exception)
            {
                Error.UnhandledException(exception);
            }

            BaseComponent.AddReference(baseValue); // released by native bindings
            return(baseValue);
        }