This repository has been archived by the owner on Aug 29, 2022. It is now read-only.
forked from Jonathan-LeRoux/IguanaTex
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathTextWindow.cls
149 lines (115 loc) · 5.27 KB
/
TextWindow.cls
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "TextWindow"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' Replacement for TextBox
Option Explicit
Private Declare PtrSafe Function TWInit _
Lib "/Library/Application Support/Microsoft/Office365/User Content.localized/Add-Ins.localized/libIguanaTexHelper.dylib" _
() As LongLong
Private Declare PtrSafe Function TWTerm _
Lib "/Library/Application Support/Microsoft/Office365/User Content.localized/Add-Ins.localized/libIguanaTexHelper.dylib" _
(ByVal Handle As LongLong, ByVal b As LongLong, ByVal c As LongLong, ByVal d As LongLong) As Integer
Private Declare PtrSafe Function TWResize _
Lib "/Library/Application Support/Microsoft/Office365/User Content.localized/Add-Ins.localized/libIguanaTexHelper.dylib" _
(ByVal Handle As LongLong, ByVal b As LongLong, ByVal c As LongLong, ByVal d As LongLong) As Integer
Private Declare PtrSafe Function TWShow _
Lib "/Library/Application Support/Microsoft/Office365/User Content.localized/Add-Ins.localized/libIguanaTexHelper.dylib" _
(ByVal Handle As LongLong, ByVal b As LongLong, ByVal c As LongLong, ByVal d As LongLong) As Integer
Private Declare PtrSafe Function TWHide _
Lib "/Library/Application Support/Microsoft/Office365/User Content.localized/Add-Ins.localized/libIguanaTexHelper.dylib" _
(ByVal Handle As LongLong, ByVal b As LongLong, ByVal c As LongLong, ByVal d As LongLong) As Integer
Private Declare PtrSafe Function TWSet _
Lib "/Library/Application Support/Microsoft/Office365/User Content.localized/Add-Ins.localized/libIguanaTexHelper.dylib" _
(ByVal Handle As LongLong, ByVal data As LongPtr, ByVal length As LongLong, ByVal d As LongLong) As Integer
Private Declare PtrSafe Function TWGet _
Lib "/Library/Application Support/Microsoft/Office365/User Content.localized/Add-Ins.localized/libIguanaTexHelper.dylib" _
(ByVal Handle As LongLong, ByRef data As LongPtr, ByRef length As LongLong, ByVal d As LongLong) As Integer
Private Declare PtrSafe Function TWGetSel _
Lib "/Library/Application Support/Microsoft/Office365/User Content.localized/Add-Ins.localized/libIguanaTexHelper.dylib" _
(ByVal Handle As LongLong, ByVal b As LongLong, ByVal c As LongLong, ByVal d As LongLong) As Integer
Private Declare PtrSafe Function TWSetSel _
Lib "/Library/Application Support/Microsoft/Office365/User Content.localized/Add-Ins.localized/libIguanaTexHelper.dylib" _
(ByVal Handle As LongLong, ByVal Sel As LongLong, ByVal c As LongLong, ByVal d As LongLong) As Integer
Private Declare PtrSafe Function TWFocus _
Lib "/Library/Application Support/Microsoft/Office365/User Content.localized/Add-Ins.localized/libIguanaTexHelper.dylib" _
(ByVal Handle As LongLong, ByVal b As LongLong, ByVal c As LongLong, ByVal d As LongLong) As Integer
Private Declare PtrSafe Function TWGetSZ _
Lib "/Library/Application Support/Microsoft/Office365/User Content.localized/Add-Ins.localized/libIguanaTexHelper.dylib" _
(ByVal Handle As LongLong, ByVal b As LongLong, ByVal c As LongLong, ByVal d As LongLong) As Integer
Private Declare PtrSafe Function TWSetSZ _
Lib "/Library/Application Support/Microsoft/Office365/User Content.localized/Add-Ins.localized/libIguanaTexHelper.dylib" _
(ByVal Handle As LongLong, ByVal sz As LongLong, ByVal c As LongLong, ByVal d As LongLong) As Integer
Private Declare PtrSafe Function memcpy Lib "/usr/lib/libc.dylib" (ByVal dest As LongPtr, ByVal src As LongPtr, ByVal n As LongLong) As LongPtr
Private Declare PtrSafe Sub free Lib "/usr/lib/libc.dylib" (ByVal ptr As LongPtr)
' members
Private Handle As LongLong
' properties
Public Property Get Utf8() As Byte()
Dim ptr As LongPtr
Dim length As LongLong
Dim ret() As Byte
TWGet Handle, ptr, length, 0
If length <> 0& Then
ReDim ret(CLng(length) - 1)
memcpy VarPtr(ret(0)), ptr, length
End If
free ptr
Utf8 = ret
End Property
Public Property Let Utf8(data() As Byte)
Dim length As Long
length = ArrayLength(data)
If length > 0 Then
TWSet Handle, VarPtr(data(0)), length, 0
Else
TWSet Handle, 0, 0, 0
End If
End Property
Public Property Get Text() As String
Text = Utf8ToString(Me.Utf8)
End Property
Public Property Let Text(Str As String)
Me.Utf8 = StringToUtf8(Str)
End Property
Public Property Get SelStart() As Integer
SelStart = TWGetSel(Handle, 0, 0, 0)
End Property
Public Property Let SelStart(Sel As Integer)
TWSetSel Handle, Sel, 0, 0
End Property
Public Property Get FontSize() As Integer
FontSize = TWGetSZ(Handle, 0, 0, 0)
End Property
Public Property Let FontSize(sz As Integer)
TWSetSZ Handle, sz, 0, 0
End Property
' constructor/destructor
Private Sub Class_Initialize()
Handle = TWInit
End Sub
Private Sub Class_Terminate()
TWTerm Handle, 0, 0, 0
End Sub
' methods
Public Sub Show()
TWShow Handle, 0, 0, 0
End Sub
Public Sub Hide()
TWHide Handle, 0, 0, 0
End Sub
Public Sub ResizeAs(target As control, parentForm As UserForm)
Dim currentFocus As control
Set currentFocus = parentForm.ActiveControl
target.SetFocus
TWResize Handle, 0, 0, 0
currentFocus.SetFocus
End Sub
Public Sub SetFocus()
TWFocus Handle, 0, 0, 0
End Sub