<commit_before>﻿// Copyright (c) 2010-2012 SharpDX - <NAME>
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#if WIN8METRO

using System;
using Windows.Devices.Input;
using Windows.Foundation;
using Windows.Graphics.Display;
using Windows.UI.Core;
using Windows.UI.Input;
using Windows.UI.Xaml;

namespace SharpDX.Toolkit.Input
{
    using global::Windows.UI.Xaml.Input;

    /// <summary>
    /// Represents a specific <see cref="MousePlatform"/> implementation for the WinRT platform
    /// </summary>
    internal class MousePlatformWinRT : MousePlatform
    {
        // keep the mouse cursor location from last event
        private int pointerX;
        private int pointerY;

        /// <summary>
        /// Initializes a new instance of <see cref="MousePlatformWinRT"/> class.
        /// </summary>
        /// <param name="nativeWindow">A reference to <see cref="CoreWindow"/> or <see cref="UIElement"/> class.</param>
        internal MousePlatformWinRT(object nativeWindow) : base(nativeWindow) { }

        /// <summary>
        /// Binds to specific events of the provided CoreWindow
        /// </summary>
        /// <param name="nativeWindow">A reference to <see cref="CoreWindow"/> or <see cref="UIElement"/> class.</param>
        /// <exception cref="ArgumentNullException">Is thrown when <paramref name="nativeWindow"/> is null.</exception>
        /// <exception cref="InvalidCastException">Is thrown when <paramref name="nativeWindow"/> is not an instance of the <see cref="CoreWindow"/> class.</exception>
        protected override void BindWindow(object nativeWindow)
        {
            if (nativeWindow == null) throw new ArgumentNullException("nativeWindow");
            var window = nativeWindow as CoreWindow;
            if (window != null)
            {
                window.PointerPressed += HandleWindowPointerEvent;
                window.PointerReleased += HandleWindowPointerEvent;
                window.PointerWheelChanged += HandleWindowPointerEvent;
                window.PointerMoved += HandleWindowPointerEvent;
            }
            else
            {
                var uiElement = nativeWindow as UIElement;
                if (uiElement != null)
                {
                    uiElement.PointerPressed += HandleUIElementPointerEvent;
                    uiElement.PointerReleased += HandleUIElementPointerEvent;
                    uiElement.PointerWheelChanged += HandleUIElementPointerEvent;
                    uiElement.PointerMoved += HandleUIElementPointerEvent;
                }
            }
        }

        /// <summary>
        /// Returns the mouse cursor position from cached values
        /// </summary>
        /// <param name="nativeWindow">A reference to <see cref="CoreWindow"/> or <see cref="UIElement"/> class.</param>
        /// <returns>The location of mouse cursor</returns>
        protected override Point GetLocationInternal(object nativeWindow)
        {
            return new Point(pointerX, pointerY);
        }

        /// <summary>
        /// Handles the <see cref="CoreWindow.PointerPressed"/>, <see cref="CoreWindow.PointerReleased"/>, <see cref="CoreWindow.PointerWheelChanged"/> and <see cref="CoreWindow.PointerMoved"/> events
        /// </summary>
        /// <param name="sender">Sender widow. Not used</param>
        /// <param name="args">Pointer event arguments.</param>
        private void HandleWindowPointerEvent(CoreWindow sender, PointerEventArgs args)
        {
            var p = args.CurrentPoint;
            // if the current device is not a mouse - ignore it
            if (p.PointerDevice.PointerDeviceType != PointerDeviceType.Mouse) return;

            UpdateMouse(p);

            args.Handled = true;
        }
<commit_msg>[Toolkit.Input] Improved initialization logic of MousePlatformWinRT - will throw exception an appropiate control was not provided<commit_after>﻿// Copyright (c) 2010-2012 SharpDX - <NAME>
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#if WIN8METRO

using System;
using Windows.Devices.Input;
using Windows.Foundation;
using Windows.Graphics.Display;
using Windows.UI.Core;
using Windows.UI.Input;
using Windows.UI.Xaml;

namespace SharpDX.Toolkit.Input
{
    using global::Windows.UI.Xaml.Input;

    /// <summary>
    /// Represents a specific <see cref="MousePlatform"/> implementation for the WinRT platform
    /// </summary>
    internal class MousePlatformWinRT : MousePlatform
    {
        // keep the mouse cursor location from last event
        private int pointerX;
        private int pointerY;

        /// <summary>
        /// Initializes a new instance of <see cref="MousePlatformWinRT"/> class.
        /// </summary>
        /// <param name="nativeWindow">A reference to <see cref="CoreWindow"/> or <see cref="UIElement"/> class.</param>
        internal MousePlatformWinRT(object nativeWindow) : base(nativeWindow) { }

        /// <summary>
        /// Binds to specific events of the provided CoreWindow
        /// </summary>
        /// <param name="nativeWindow">A reference to <see cref="CoreWindow"/> or <see cref="UIElement"/> class.</param>
        /// <exception cref="ArgumentNullException">Is thrown when <paramref name="nativeWindow"/> is null.</exception>
        /// <exception cref="ArgumentException">Is thrown when <paramref name="nativeWindow"/> is not a <see cref="CoreWindow"/> and not an <see cref="UIElement"/></exception>
        protected override void BindWindow(object nativeWindow)
        {
            if (nativeWindow == null) throw new ArgumentNullException("nativeWindow");
            var window = nativeWindow as CoreWindow;
            if (window != null)
            {
                window.PointerPressed += HandleWindowPointerEvent;
                window.PointerReleased += HandleWindowPointerEvent;
                window.PointerWheelChanged += HandleWindowPointerEvent;
                window.PointerMoved += HandleWindowPointerEvent;
                return;
            }
            
            var uiElement = nativeWindow as UIElement;
            if (uiElement != null)
            {
                uiElement.PointerPressed += HandleUIElementPointerEvent;
                uiElement.PointerReleased += HandleUIElementPointerEvent;
                uiElement.PointerWheelChanged += HandleUIElementPointerEvent;
                uiElement.PointerMoved += HandleUIElementPointerEvent;
                return;
            }

            throw new ArgumentException("Should be an instance of either CoreWindow or UIElement", "nativeWindow");
        }

        /// <summary>
        /// Returns the mouse cursor position from cached values
        /// </summary>
        /// <param name="nativeWindow">A reference to <see cref="CoreWindow"/> or <see cref="UIElement"/> class.</param>
        /// <returns>The location of mouse cursor</returns>
        protected override Point GetLocationInternal(object nativeWindow)
        {
            return new Point(pointerX, pointerY);
        }

        /// <summary>
        /// Handles the <see cref="CoreWindow.PointerPressed"/>, <see cref="CoreWindow.PointerReleased"/>, <see cref="CoreWindow.PointerWheelChanged"/> and <see cref="CoreWindow.PointerMoved"/> events
        /// </summary>
        /// <param name="sender">Sender widow. Not used</param>
        /// <param name="args">Pointer event arguments.</param>
        private void HandleWindowPointerEvent(CoreWindow sender, PointerEventArgs args)
        {
            var p = args.CurrentPoint;
            // if the current device is not a mouse - ignore it
            if (p.PointerDevice.PointerDeviceType != PointerDeviceType.Mouse) return;

            UpdateMouse(p);

            args.Handled = true;
        }

{'fraction_non_alphanumeric': 0.09897054326776068, 'fraction_numerical': 0.0018346753643869126, 'mean_word_length': 2.5941391941391942, 'pattern_counts': {'":': 0, '<': 88, '<?xml version=': 0, '>': 88, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2139728', 'n_tokens_mistral': 2401, 'n_tokens_neox': 2303, 'n_words': 852}