-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathVwPropertyStoreManaged.cs
More file actions
101 lines (85 loc) · 2.76 KB
/
Copy pathVwPropertyStoreManaged.cs
File metadata and controls
101 lines (85 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) 2002-2025 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)
using System;
using System.Runtime.InteropServices;
using System.Threading;
using SIL.LCModel.Core.KernelInterfaces;
namespace SIL.FieldWorks.Common.ViewsInterfaces
{
/// <summary/>
public sealed class VwPropertyStoreManaged : IDisposable
{
private const string _viewsDllPath = "views.dll";
private IntPtr pVwPropStore;
// Detect redundant Dispose() calls in a thread-safe manner.
// _isDisposed == 0 means Dispose(bool) has not been called yet.
// _isDisposed == 1 means Dispose(bool) has already been called.
private int _isDisposed;
/// <summary/>
public VwPropertyStoreManaged()
{
pVwPropStore = VwPropertyStore_Create();
}
/// <summary/>
public IVwStylesheet Stylesheet
{
set
{
VwPropertyStore_Stylesheet(pVwPropStore, value);
}
}
/// <summary/>
public ILgWritingSystemFactory WritingSystemFactory
{
set
{
VwPropertyStore_WritingSystemFactory(pVwPropStore, value);
}
}
/// <summary/>
public LgCharRenderProps get_ChrpFor(ITsTextProps ttp)
{
IntPtr pInt = VwPropertyStore_get_ChrpFor(pVwPropStore, ttp);
return (LgCharRenderProps)Marshal.PtrToStructure(pInt, typeof(LgCharRenderProps));
}
#region Disposable stuff
/// <summary/>
~VwPropertyStoreManaged() => Dispose(false);
/// <summary/>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary/>
private void Dispose(bool disposing)
{
if (Interlocked.CompareExchange(ref _isDisposed, 1, 0) == 0)
{
// Dispose managed resources (if there are any).
if (disposing)
{
}
// Dispose unmanaged resources.
VwPropertyStore_Delete(pVwPropStore);
}
}
#endregion
#region DLLImport stuff
[DllImport(_viewsDllPath, CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr VwPropertyStore_Create();
[DllImport(_viewsDllPath, CallingConvention = CallingConvention.Cdecl)]
private static extern void VwPropertyStore_Delete(IntPtr pVwPropStore);
[DllImport(_viewsDllPath, CallingConvention = CallingConvention.Cdecl)]
private static extern void VwPropertyStore_Stylesheet(IntPtr pVwPropStore,
[MarshalAs(UnmanagedType.Interface)] IVwStylesheet pss);
[DllImport(_viewsDllPath, CallingConvention = CallingConvention.Cdecl)]
private static extern void VwPropertyStore_WritingSystemFactory(IntPtr pVwPropStore,
[MarshalAs(UnmanagedType.Interface)] ILgWritingSystemFactory pwsf);
[DllImport(_viewsDllPath, CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr VwPropertyStore_get_ChrpFor(IntPtr pVwPropStore,
[MarshalAs(UnmanagedType.Interface)] ITsTextProps _ttp);
#endregion
}
}