OSDN Git Service

桁折モード有効時にキャレット周辺にごみが表示されることがあった
[fooeditengine/FooEditEngine.git] / DotNetTextStore / TextStore.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Diagnostics;
6 using System.Reflection;
7 using System.Runtime.InteropServices;
8 using System.Globalization;
9
10 using DotNetTextStore.UnmanagedAPI.TSF;
11 using DotNetTextStore.UnmanagedAPI.TSF.TextStore;
12 using DotNetTextStore.UnmanagedAPI.WinDef;
13 using DotNetTextStore.UnmanagedAPI.WinError;
14
15 namespace DotNetTextStore 
16 {
17
18
19     //========================================================================================
20
21     /// <summary>
22     ///  テキストストアの実装を担うクラス。
23     /// <pre>
24     ///   各ドキュメント毎に実装すべき部分をイベントとして切り離して、テキストストアの実装を楽に
25     ///   させる。
26     /// </pre>
27     /// <pre>
28     ///   使用側としては各イベントハンドラの実装、フォーカスを取得した時に SetFocus() メソッドの
29     ///   呼び出し、選択やテキストが変更された時に NotifySelectionChanged() メソッドや
30     ///   NotifyTextChange() メソッドの呼び出しを行う必要がある。
31     /// </pre>
32     public sealed class TextStore :  TextStoreBase,IDisposable, ITextStoreACP, ITfContextOwnerCompositionSink
33     {
34         public delegate IntPtr GetHWndHandler();
35         public event GetHWndHandler GetHWnd;
36
37         #region "生成と破棄"
38         /// <summary>
39         /// 後処理
40         /// </summary>
41         public void Dispose()
42         {
43             base.Dispose(false);
44             GC.SuppressFinalize(this);
45         }
46         #endregion
47
48         #region ITextStoreACPの実装
49         public void GetWnd(int i_viewCookie, out IntPtr o_hwnd)
50         {
51 #if TSF_DEBUG_OUTPUT
52             using(var dbgout = new DebugOut("{0}()", DebugOut.GetCaller()) )
53 #endif
54             {
55                 if (GetHWnd != null)
56                     o_hwnd = GetHWnd();
57                 else
58                     o_hwnd = IntPtr.Zero;
59             }
60         }
61         #endregion
62
63         #region TSF 関連のラッパメソッド
64         /// <summary>
65         /// スレッドマネージャの生成
66         /// </summary>
67         /// 
68         /// <exception cref="COMException">
69         /// スレッドマネージャーの生成に失敗した場合。
70         /// </exception>
71         protected override void CreateThreadMgr()
72         {
73             if( _threadMgr == null )
74             {
75                 TextFrameworkFunctions.TF_GetThreadMgr(out _threadMgr);
76                 if( _threadMgr == null )
77                 {
78                     Type clsid = Marshal.GetTypeFromCLSID(TfDeclarations.CLSID_TF_ThreadMgr);
79                     _threadMgr = Activator.CreateInstance(clsid) as ITfThreadMgr;
80
81                     if( _threadMgr == null )
82                     {
83                         const string message = "スレッドマネージャーの生成に失敗しました。";
84                         Debug.WriteLine(message);
85                         throw new COMException(message, HRESULT.E_NOTIMPL);
86                     }
87                 }
88             }
89         }
90
91         #endregion
92
93     }
94 }