Example #1
0
        /// <summary>
        /// Set the enabled gestures.
        /// This method is called from the internal SetEnabledGestures method.
        /// </summary>
        private int SetEnabledGestures(MS.Win32.Recognizer.ContextSafeHandle recContext, ApplicationGesture[] enabledGestures)
        {
            Debug.Assert(recContext != null && !recContext.IsInvalid);

            // NOTICE-2005/01/11-WAYNEZEN,
            // The following usage was copied from drivers\tablet\recognition\ink\core\twister\src\wispapis.c
            // SetEnabledUnicodeRanges
            //      Set ranges of gestures enabled in this recognition context
            //      The behavior of this function is the following:
            //          (a) (A part of) One of the requested ranges lies outside
            //              gesture interval---currently  [GESTURE_NULL, GESTURE_NULL + 255)
            //              return E_UNEXPECTED and keep the previously set ranges
            //          (b) All requested ranges are within the gesture interval but
            //              some of them are not supported:
            //              return S_TRUNCATED and set those requested gestures that are
            //              supported (possibly an empty set)
            //          (c) All requested gestures are supported
            //              return S_OK and set all requested gestures.
            //      Note:  An easy way to set all supported gestures as enabled is to use
            //              SetEnabledUnicodeRanges() with one range=(GESTURE_NULL,255).

            // Enabel gestures
            uint cRanges = (uint)(enabledGestures.Length);

            MS.Win32.Recognizer.CHARACTER_RANGE[] charRanges = new MS.Win32.Recognizer.CHARACTER_RANGE[cRanges];

            if (cRanges == 1 && enabledGestures[0] == ApplicationGesture.AllGestures)
            {
                charRanges[0].cChars = MAX_GESTURE_COUNT;
                charRanges[0].wcLow  = GESTURE_NULL;
            }
            else
            {
                for (int i = 0; i < cRanges; i++)
                {
                    charRanges[i].cChars = 1;
                    charRanges[i].wcLow  = (ushort)(enabledGestures[i]);
                }
            }
            int hr = MS.Win32.Recognizer.UnsafeNativeMethods.SetEnabledUnicodeRanges(recContext, cRanges, charRanges);

            return(hr);
        }
        private int AddStrokes(MS.Win32.Recognizer.ContextSafeHandle recContext, StrokeCollection strokes)
        {
            Debug.Assert(recContext != null && !recContext.IsInvalid);

            int hr;

            foreach ( Stroke stroke in strokes )
            {
                MS.Win32.Recognizer.PACKET_DESCRIPTION packetDescription = 
                    new MS.Win32.Recognizer.PACKET_DESCRIPTION();
                IntPtr packets = IntPtr.Zero;
                try
                {
                    int countOfBytes;
                    NativeMethods.XFORM xForm;
                    GetPacketData(stroke, out packetDescription, out countOfBytes, out packets, out xForm);
                    if (packets == IntPtr.Zero)
                    {
                        return -2147483640; //E_FAIL - 0x80000008.  We never raise this in an exception
                    }

                    hr = MS.Win32.Recognizer.UnsafeNativeMethods.AddStroke(recContext, ref packetDescription, (uint)countOfBytes, packets, xForm);
                    if ( HRESULT.Failed(hr) )
                    {
                        // Return from here. The finally block will free the memory and report the error properly.
                        return hr;
                    }
                }
                finally
                {
                    // Release the resources in the finally block
                    ReleaseResourcesinPacketDescription(packetDescription, packets);
                }
            }

            return MS.Win32.Recognizer.UnsafeNativeMethods.EndInkInput(recContext);

        }