-
Notifications
You must be signed in to change notification settings - Fork 0
/
QChar.hs
278 lines (265 loc) · 9.04 KB
/
QChar.hs
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
-- This file is part of Qtah.
--
-- Copyright 2015-2016 Bryan Gardiner <bog@khumba.net>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU Lesser General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU Lesser General Public License for more details.
--
-- You should have received a copy of the GNU Lesser General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
{-# LANGUAGE CPP #-}
module Graphics.UI.Qtah.Generator.Interface.Core.QChar (
aModule,
c_QChar,
) where
#if !MIN_VERSION_base(4,8,0)
import Data.Monoid (mconcat)
#endif
import Foreign.Hoppy.Generator.Language.Haskell (
addImports,
sayLn,
)
import Foreign.Hoppy.Generator.Spec (
ClassHaskellConversion (
ClassHaskellConversion,
classHaskellConversionFromCppFn,
classHaskellConversionToCppFn,
classHaskellConversionType
),
Export (ExportClass, ExportEnum),
addReqIncludes,
classSetHaskellConversion,
hsImport1,
ident,
ident1,
includeStd,
makeClass,
mkConstMethod,
mkConstMethod',
mkCtor,
mkMethod',
mkStaticMethod,
mkStaticMethod',
)
import Foreign.Hoppy.Generator.Spec.ClassFeature (
ClassFeature (Assignable, Copyable, Comparable, Equatable),
classAddFeatures,
)
import Foreign.Hoppy.Generator.Types (boolT, charT, intT, enumT, objT, refT, ucharT, ushortT)
import Graphics.UI.Qtah.Generator.Flag (collect, just, test)
import Graphics.UI.Qtah.Generator.Flags (qtVersion)
import {-# SOURCE #-} Graphics.UI.Qtah.Generator.Interface.Core.QString (c_QString)
import Graphics.UI.Qtah.Generator.Interface.Imports
import Graphics.UI.Qtah.Generator.Types
import Language.Haskell.Syntax (
HsName (HsIdent),
HsQName (UnQual),
HsType (HsTyCon),
)
{-# ANN module "HLint: ignore Use camelCase" #-}
aModule =
AQtModule $
makeQtModule ["Core", "QChar"] $
collect
[ just $ QtExport $ ExportClass c_QChar
, just $ QtExport $ ExportEnum e_Category
, just $ QtExport $ ExportEnum e_Decomposition
, test (qtVersion < [5, 3]) $ QtExport $ ExportEnum e_Joining
, test (qtVersion >= [5, 3]) $ QtExport $ ExportEnum e_JoiningType
, just $ QtExport $ ExportEnum e_Direction
, just $ QtExport $ ExportEnum e_SpecialCharacter
, just $ QtExport $ ExportEnum e_UnicodeVersion
]
-- TODO Add more QChar methods.
c_QChar =
addReqIncludes [includeStd "QChar"] $
classAddFeatures [Assignable, Copyable, Comparable, Equatable] $
classSetHaskellConversion
ClassHaskellConversion
{ classHaskellConversionType = do
addImports importForPrelude
return $ HsTyCon $ UnQual $ HsIdent "QtahP.Char"
, classHaskellConversionToCppFn = do
addImports $ mconcat [hsImport1 "Prelude" "(.)", importForChar, importForRuntime]
sayLn "qChar_newFromInt . QtahFHR.coerceIntegral . QtahDC.ord"
, classHaskellConversionFromCppFn = do
addImports $ mconcat [hsImport1 "Prelude" "(.)", importForChar, importForPrelude,
importForRuntime]
sayLn "QtahP.fmap (QtahDC.chr . QtahFHR.coerceIntegral) . qChar_unicode"
} $
makeClass (ident "QChar") Nothing []
[ mkCtor "new" []
, mkCtor "newFromCellRow" [ucharT, ucharT]
, mkCtor "newFromInt" [intT]
, mkCtor "newFromSpecialCharacter" [enumT e_SpecialCharacter]
] $
collect
[ test (qtVersion < [5]) $ mkStaticMethod' "fromAscii" "newFromAscii" [charT] $ objT c_QChar
, just $ mkStaticMethod' "fromLatin1" "newFromLatin1" [charT] $ objT c_QChar
, just $ mkConstMethod "category" [] $ enumT e_Category
, just $ mkConstMethod "cell" [] ucharT
, just $ mkConstMethod "combiningClass" [] ucharT
, just $ mkStaticMethod "currentUnicodeVersion" [] $ enumT e_UnicodeVersion
, just $ mkConstMethod "decomposition" [] $ objT c_QString
, just $ mkConstMethod "decompositionTag" [] $ enumT e_Decomposition
, just $ mkConstMethod "digitValue" [] intT
, just $ mkConstMethod "direction" [] $ enumT e_Direction
, just $ mkConstMethod "hasMirrored" [] boolT
, just $ mkConstMethod "isDigit" [] boolT
, just $ mkConstMethod "isHighSurrogate" [] boolT
, just $ mkConstMethod "isLetter" [] boolT
, just $ mkConstMethod "isLetterOrNumber" [] boolT
, just $ mkConstMethod "isLowSurrogate" [] boolT
, just $ mkConstMethod "isLower" [] boolT
, just $ mkConstMethod "isMark" [] boolT
, just $ mkConstMethod "isNull" [] boolT
, just $ mkConstMethod "isNumber" [] boolT
, just $ mkConstMethod "isPrint" [] boolT
, just $ mkConstMethod "isPunct" [] boolT
, just $ mkConstMethod "isSpace" [] boolT
, just $ mkConstMethod "isSymbol" [] boolT
, just $ mkConstMethod "isTitleCase" [] boolT
, just $ mkConstMethod "isUpper" [] boolT
, test (qtVersion < [5, 3]) $ mkConstMethod "joining" [] $ enumT e_Joining
, test (qtVersion >= [5, 3]) $ mkConstMethod "joiningType" [] $ enumT e_JoiningType
, just $ mkConstMethod "mirroredChar" [] $ objT c_QChar
, just $ mkConstMethod "row" [] ucharT
-- TODO script (>=5.1)
, test (qtVersion < [5]) $ mkConstMethod "toAscii" [] charT
, just $ mkConstMethod "toCaseFolded" [] $ objT c_QChar
, just $ mkConstMethod "toLatin1" [] charT
, just $ mkConstMethod "toLower" [] $ objT c_QChar
, just $ mkConstMethod "toTitleCase" [] $ objT c_QChar
, just $ mkConstMethod "toUpper" [] $ objT c_QChar
, just $ mkConstMethod' "unicode" "unicode" [] ushortT
, just $ mkMethod' "unicode" "unicodeRef" [] $ refT ushortT
, just $ mkConstMethod "unicodeVersion" [] $ enumT e_UnicodeVersion
]
e_Category =
makeQtEnum (ident1 "QChar" "Category") [includeStd "QChar"]
[ -- Normative.
(1, ["mark", "non", "spacing"])
, (2, ["mark", "spacing", "combining"])
, (3, ["mark", "enclosing"])
, (4, ["number", "decimal", "digit"])
, (5, ["number", "letter"])
, (6, ["number", "other"])
, (7, ["separator", "space"])
, (8, ["separator", "line"])
, (9, ["separator", "paragraph"])
, (10, ["other", "control"])
, (11, ["other", "format"])
, (12, ["other", "surrogate"])
, (13, ["other", "private", "use"])
, (14, ["other", "not", "assigned"])
-- Informative.
, (15, ["letter", "uppercase"])
, (16, ["letter", "lowercase"])
, (17, ["letter", "titlecase"])
, (18, ["letter", "modifier"])
, (19, ["letter", "other"])
, (20, ["punctuation", "connector"])
, (21, ["punctuation", "dash"])
, (22, ["punctuation", "open"])
, (23, ["punctuation", "close"])
, (24, ["punctuation", "initial", "quote"])
, (25, ["punctuation", "final", "quote"])
, (26, ["punctuation", "other"])
, (27, ["symbol", "math"])
, (28, ["symbol", "currency"])
, (29, ["symbol", "modifier"])
, (30, ["symbol", "other"])
, (0, ["no", "category"])
]
e_Decomposition =
makeQtEnum (ident1 "QChar" "Decomposition") [includeStd "QChar"]
[ (0, ["no", "decomposition"])
, (1, ["canonical"])
, (8, ["circle"])
, (16, ["compat"])
, (6, ["final"])
, (2, ["font"])
, (17, ["fraction"])
, (4, ["initial"])
, (7, ["isolated"])
, (5, ["medial"])
, (13, ["narrow"])
, (3, ["no", "break"])
, (14, ["small"])
, (15, ["square"])
, (10, ["sub"])
, (9, ["super"])
, (11, ["vertical"])
, (12, ["wide"])
]
e_Direction =
makeQtEnum (ident1 "QChar" "Direction") [includeStd "QChar"]
[ (13, ["dir", "al"])
, (5, ["dir", "an"])
, (7, ["dir", "b"])
, (18, ["dir", "bn"])
, (6, ["dir", "cs"])
, (2, ["dir", "en"])
, (3, ["dir", "es"])
, (4, ["dir", "et"])
, (0, ["dir", "l"])
, (11, ["dir", "lre"])
, (12, ["dir", "lro"])
, (17, ["dir", "nsm"])
, (10, ["dir", "on"])
, (16, ["dir", "pdf"])
, (1, ["dir", "r"])
, (14, ["dir", "rle"])
, (15, ["dir", "rlo"])
, (8, ["dir", "s"])
, (9, ["dir", "ws"])
]
-- | Removed in Qt 5.3.0.
e_Joining =
makeQtEnum (ident1 "QChar" "Joining") [includeStd "QChar"]
[ (3, ["center"])
, (1, ["dual"])
, (0, ["other", "joining"])
, (2, ["right"])
]
-- | Since Qt 5.3.0.
e_JoiningType =
makeQtEnum (ident1 "QChar" "JoiningType") [includeStd "QChar"]
[ (0, ["joining", "none"])
, (1, ["joining", "causing"])
, (2, ["joining", "dual"])
, (3, ["joining", "right"])
, (4, ["joining", "left"])
, (5, ["joining", "transparent"])
]
e_SpecialCharacter =
makeQtEnum (ident1 "QChar" "SpecialCharacter") [includeStd "QChar"]
[ (0x0000, ["null"])
, (0x00a0, ["nbsp"])
, (0x2028, ["line", "separator"])
, (0x2029, ["paragraph", "separator"])
, (0xfffc, ["object", "replacement", "character"])
, (0xfffd, ["replacement", "character"])
, (0xfeff, ["byte", "order", "mark"])
, (0xfffe, ["byte", "order", "swapped"])
]
e_UnicodeVersion =
makeQtEnum (ident1 "QChar" "UnicodeVersion") [includeStd "QChar"]
[ (1, ["unicode", "1_1"])
, (2, ["unicode", "2_0"])
, (3, ["unicode", "2_1_2"])
, (4, ["unicode", "3_0"])
, (5, ["unicode", "3_1"])
, (6, ["unicode", "3_2"])
, (7, ["unicode", "4_0"])
, (8, ["unicode", "4_1"])
, (9, ["unicode", "5_0"])
, (0, ["unicode", "unassigned"])
]