Beispiel #1
0
                public byte[] this[Guid id]
                {
                    // 'size' should be the size of the data pointed to by 'data'
                    get
                    {
                        // Request the size of the available private data
                        var size = 0U;
                        View3d_TexturePrivateDataGet(m_handle, id, ref size, IntPtr.Zero);
                        if (size == 0)
                        {
                            return(Array.Empty <byte>());
                        }

                        // Create a buffer and read the private data
                        var buffer = new byte[size];
                        using var buf = Marshal_.Pin(buffer, GCHandleType.Pinned);
                        View3d_TexturePrivateDataGet(m_handle, id, ref size, buf.Pointer);
                        return(buffer);
                    }
                    set
                    {
                        using var buf = Marshal_.Pin(value, GCHandleType.Pinned);
                        View3d_TexturePrivateDataSet(m_handle, id, (uint)(value?.Length ?? 0), buf.Pointer);
                    }
                }
Beispiel #2
0
                public IntPtr this[Guid id]
                {
                    // 'size' should be the size of the data pointed to by 'data'
                    get
                    {
                        // Request the size of the available private data
                        var size = 0U;
                        View3d_TexturePrivateDataGet(m_handle, id, ref size, IntPtr.Zero);
                        if (size == 0)
                        {
                            return(IntPtr.Zero);
                        }

                        // Create a buffer and read the private data
                        var buffer = new byte[size];
                        using var buf = Marshal_.Pin(buffer, GCHandleType.Pinned);
                        View3d_TexturePrivateDataGet(m_handle, id, ref size, buf.Pointer);

                        if (size == 8)
                        {
                            return(new IntPtr(BitConverter.ToInt64(buffer, 0)));
                        }
                        if (size == 4)
                        {
                            return(new IntPtr(BitConverter.ToInt32(buffer, 0)));
                        }

                        throw new Exception("Private data is not a pointer type");
                    }
                    set
                    {
                        View3d_TexturePrivateDataIFSet(m_handle, id, value);
                    }
                }
Beispiel #3
0
            internal RichEditOleInterface(RichTextBox rtb)
            {
                m_rich_edit_ole = IntPtr.Zero;
                m_text_document = IntPtr.Zero;

                // Allocate the ptr that EM_GETOLEINTERFACE will fill in.
                using (var buffer = Marshal_.Alloc(EHeap.CoTaskMem, typeof(IntPtr), 1))
                {
                    //Marshal.WriteIntPtr(ptr, IntPtr.Zero);  // Clear it.
                    if (Win32.SendMessage(rtb.Handle, Win32.EM_GETOLEINTERFACE, IntPtr.Zero, buffer.Value.Ptr) == IntPtr.Zero)
                    {
                        throw new Exception("RichTextBox.OleInterface - EM_GETOLEINTERFACE failed.");
                    }

                    // Read the returned pointer.
                    using (var pRichEdit = Scope.Create(() => Marshal.ReadIntPtr(buffer.Value.Ptr), p => Marshal.Release(p)))
                    {
                        if (pRichEdit == IntPtr.Zero)
                        {
                            throw new Exception("RichTextBox.OleInterface - failed to get the pointer.");
                        }

                        {                        // Query for the IRichEditOle interface.
                            var guid = new Guid("00020D00-0000-0000-c000-000000000046");
                            Marshal.QueryInterface(pRichEdit, ref guid, out m_rich_edit_ole);
                        }
                        {                        // Query for the ITextDocument interface
                            var guid = new Guid("8CC497C0-A1DF-11CE-8098-00AA0047BE5D");
                            Marshal.QueryInterface(pRichEdit, ref guid, out m_text_document);
                        }
                    }
                }
            }
Beispiel #4
0
        public DummyWindow(string?diag_name = null)
        {
            var atom = EnsureWndClassRegistered(HInstance);

            using var pin = Marshal_.Pin(this, GCHandleType.Normal);
            Handle        = Win32.CreateWindow(0, atom, diag_name ?? string.Empty, 0, 0, 0, 1, 1, Win32.HWND_MESSAGE, IntPtr.Zero, HInstance, pin.Pointer);
            if (Handle == IntPtr.Zero)
            {
                throw new Win32Exception();
            }
        }
Beispiel #5
0
            public Object(string name, uint colour, byte[] p3d_data, Guid?context_id)
            {
                Owned = true;
                var ctx = context_id ?? Guid.NewGuid();

                using var pin = Marshal_.Pin(p3d_data, GCHandleType.Pinned);
                Handle        = View3D_ObjectCreateP3DStream(name, colour, p3d_data.Length, pin.Pointer, ref ctx);
                if (Handle == HObject.Zero)
                {
                    throw new Exception($"Failed to create object from p3d model data stream");
                }
            }
Beispiel #6
0
            /// <summary>Create from buffer</summary>
            public Object(string name, uint colour, int vcount, int icount, int ncount, Vertex[] verts, ushort[] indices, Nugget[] nuggets, Guid?context_id)
            {
                Owned = true;
                var ctx = context_id ?? Guid.NewGuid();

                // Serialise the verts/indices to a memory buffer
                using var vbuf = Marshal_.Pin(verts, GCHandleType.Pinned);
                using var ibuf = Marshal_.Pin(indices, GCHandleType.Pinned);
                using var nbuf = Marshal_.ArrayToPtr(EHeap.HGlobal, nuggets);
                Handle         = View3D_ObjectCreate(name, colour, vcount, icount, ncount, vbuf.Pointer, ibuf.Pointer, nbuf.Value.Ptr, ref ctx);
                if (Handle == HObject.Zero)
                {
                    throw new System.Exception($"Failed to create object '{name}' from provided buffers");
                }
            }
Beispiel #7
0
            public HitTestResult HitTest(HitTestRay ray, float snap_distance, EHitTestFlags flags, IEnumerable <Object> objects)
            {
                var rays = new HitTestRay[1] {
                    ray
                };
                var hits  = new HitTestResult[1];
                var insts = objects.Select(x => x.Handle).ToArray();

                using var rays_buf  = Marshal_.Pin(rays, GCHandleType.Pinned);
                using var hits_buf  = Marshal_.Pin(hits, GCHandleType.Pinned);
                using var insts_buf = Marshal_.Pin(insts, GCHandleType.Pinned);
                View3D_WindowHitTestObjects(Handle, rays_buf.Pointer, hits_buf.Pointer, 1, snap_distance, flags, insts, insts.Length);

                return(hits[0]);
            }
Beispiel #8
0
            public HitTestResult HitTest(HitTestRay ray, float snap_distance, EHitTestFlags flags, Guid[] guids, int include_count, int exclude_count)
            {
                Debug.Assert(include_count + exclude_count == guids.Length);
                var rays = new HitTestRay[1] {
                    ray
                };
                var hits = new HitTestResult[1];

                using var rays_buf  = Marshal_.Pin(rays, GCHandleType.Pinned);
                using var hits_buf  = Marshal_.Pin(hits, GCHandleType.Pinned);
                using var guids_buf = Marshal_.Pin(guids, GCHandleType.Pinned);
                View3D_WindowHitTestByCtx(Handle, rays_buf.Pointer, hits_buf.Pointer, 1, snap_distance, flags, guids_buf.Pointer, include_count, exclude_count);

                return(hits[0]);
            }
Beispiel #9
0
        /// <summary>
        /// Render the contents of the RichTextBox for printing.
        /// Return the last character printed + 1 (printing start from this point for next page).
        /// http://support.microsoft.com/default.aspx?scid=kb;en-us;812425
        /// The RichTextBox control does not provide any method to print the content of the RichTextBox.
        /// You can extend the RichTextBox class to use EM_FORMATRANGE message to send the content of
        /// a RichTextBox control to an output device such as printer.</summary>
        public static int Print(IntPtr rtb_handle, int charFrom, int charTo, PrintPageEventArgs e)
        {
            // Convert the unit used by the .NET framework (1/100 inch)
            // and the unit used by Win32 API calls ('twips' 1/1440 inch)
            const double anInch = 14.4;

            // Calculate the area to render and print
            var print_rect = Win32.RECT.FromLTRB(
                (int)(e.MarginBounds.Left * anInch),
                (int)(e.MarginBounds.Top * anInch),
                (int)(e.MarginBounds.Right * anInch),
                (int)(e.MarginBounds.Bottom * anInch));

            // Calculate the size of the page
            var page_rect = Win32.RECT.FromLTRB(
                (int)(e.PageBounds.Left * anInch),
                (int)(e.PageBounds.Top * anInch),
                (int)(e.PageBounds.Right * anInch),
                (int)(e.PageBounds.Bottom * anInch));

            // Create a format range
            using (var hdc = e.Graphics.GetHdcScope())
            {
                var fmt_range = new Win32.FORMATRANGE
                {
                    char_range = new Win32.CHARRANGE
                    {
                        max = charTo,                            // Indicate character from to character to
                        min = charFrom,                          //
                    },
                    hdc       = hdc,                             // Use the same DC for measuring and rendering
                    hdcTarget = hdc,                             // Point at printer hDC
                    rc        = print_rect,                      // Indicate the area on page to print
                    rcPage    = page_rect,                       // Indicate size of page
                };

                // Get the pointer to the FORMATRANGE structure in non-GC memory
                using (var buffer = Marshal_.Alloc <Win32.FORMATRANGE>(EHeap.CoTaskMem))
                {
                    Marshal.StructureToPtr(fmt_range, buffer.Value.Ptr, false);

                    // Send the rendered data for printing, then release and cached info
                    var res = Win32.SendMessage(rtb_handle, (uint)Win32.EM_FORMATRANGE, new IntPtr(1), buffer.Value.Ptr);
                    Win32.SendMessage(rtb_handle, (uint)Win32.EM_FORMATRANGE, (IntPtr)0, (IntPtr)0);
                    return((int)res);                    // Return last + 1 character printed
                }
            }
        }
Beispiel #10
0
 public virtual void Dispose()
 {
     Marshal_.Release(ref m_rich_edit_ole);
     Marshal_.Release(ref m_text_document);
 }