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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
use super::*;
use std::fmt;

#[cfg(target_family = "windows")]
pub type fmx_int64 = i64;
#[cfg(target_family = "unix")]
pub type fmx_int64 = i32;
#[cfg(target_family = "windows")]
pub type fmx_uint64 = u64;
#[cfg(target_family = "unix")]
pub type fmx_uint64 = u32;
#[cfg(target_family = "windows")]
pub type fmx_unusedid = i16;
#[cfg(target_family = "unix")]
pub type fmx_unusedid = i32;

pub type fmx_ptrtype = u64;
pub type fmx_ExternCallSwitch = u8;
pub type fmx_ScriptControl = u8;
pub type fmx_IdleLevel = u8;
pub type fmx_ExternCallProc = Option<unsafe extern "C" fn(arg1: *mut fmx_ExternCallStruct)>;
pub type fmx_CurrentEnvCall = Option<unsafe extern "C" fn(env: *mut fmx_ExprEnv) -> FMError>;
pub type fmx_fontface = u16;
pub type fmx_fontid = u16;
pub type fmx_fontsize = u16;
pub type fmx_colorchannel = u8;
pub type fmx_colorchannel16 = u16;
pub type fmx_fontscript = u16;
pub type fmx_ExtPluginType = Option<
    extern "C" fn(
        functionId: i16,
        env: *const fmx_ExprEnv,
        parms: *const fmx_DataVect,
        result: *mut fmx_Data,
    ) -> FMError,
>;
pub type fmx_StartScriptCall = Option<
    unsafe extern "C" fn(
        fileName: *const fmx_Text,
        scriptName: *const fmx_Text,
        control: ScriptControl,
        parameter: *const fmx_Data,
    ) -> FMError,
>;

#[derive(Debug, Clone, Copy)]
#[repr(i8)]
pub enum fmx_boolean {
    False = 0,
    True = 1,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct fmx_Locale {
    _address: u8,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct fmx_QuadChar {
    _address: u8,
}

#[cfg_attr(target_os = "macos", link(kind = "framework", name = "FMWrapper"))]
#[cfg_attr(target_os = "windows", link(kind = "static", name = "FMWrapper"))]
#[cfg_attr(target_os = "linux", link(kind = "dylib", name = "FMWrapper"))]
extern "C" {
    #[allow(dead_code)]
    fn FM_QuadChar_Constructor1(_x: *mut fmx__fmxcpt) -> *mut fmx_QuadChar;

    fn FM_QuadChar_Constructor2(
        c0: i8,
        c1: i8,
        c2: i8,
        c3: i8,
        _x: *mut fmx__fmxcpt,
    ) -> *mut fmx_QuadChar;

    #[allow(dead_code)]
    fn FM_QuadChar_Constructor3(
        value: *const fmx_QuadChar,
        _x: *mut fmx__fmxcpt,
    ) -> *mut fmx_QuadChar;

    #[allow(dead_code)]
    fn FM_QuadChar_operatorAS(
        _self: *mut fmx_QuadChar,
        value: *const fmx_QuadChar,
        _x: *mut fmx__fmxcpt,
    ) -> *const fmx_QuadChar;

    #[allow(dead_code)]
    fn FM_QuadChar_operatorAR(_self: *mut fmx_QuadChar, i: i32, _x: *mut fmx__fmxcpt) -> u8;

    #[allow(dead_code)]
    fn FM_QuadChar_operatorCAR(_self: *const fmx_QuadChar, i: i32, _x: *mut fmx__fmxcpt) -> u8;

    #[allow(dead_code)]
    fn FM_QuadChar_operatorEQ(
        _self: *const fmx_QuadChar,
        value: *const fmx_QuadChar,
        _x: *mut fmx__fmxcpt,
    ) -> bool;

    #[allow(dead_code)]
    fn FM_QuadChar_operatorNE(
        _self: *const fmx_QuadChar,
        value: *const fmx_QuadChar,
        _x: *mut fmx__fmxcpt,
    ) -> bool;

    #[allow(dead_code)]
    fn FM_QuadChar_operatorLT(
        _self: *const fmx_QuadChar,
        value: *const fmx_QuadChar,
        _x: *mut fmx__fmxcpt,
    ) -> bool;

    #[allow(dead_code)]
    fn FM_QuadChar_operatorLE(
        _self: *const fmx_QuadChar,
        value: *const fmx_QuadChar,
        _x: *mut fmx__fmxcpt,
    ) -> bool;

    #[allow(dead_code)]
    fn FM_QuadChar_operatorGT(
        _self: *const fmx_QuadChar,
        value: *const fmx_QuadChar,
        _x: *mut fmx__fmxcpt,
    ) -> bool;

    #[allow(dead_code)]
    fn FM_QuadChar_operatorGE(
        _self: *const fmx_QuadChar,
        value: *const fmx_QuadChar,
        _x: *mut fmx__fmxcpt,
    ) -> bool;

    #[allow(dead_code)]
    fn FM_QuadChar_GetMacType(_self: *const fmx_QuadChar, _x: *mut fmx__fmxcpt) -> u32;

    #[allow(dead_code)]
    fn FM_QuadChar_SetMacType(_self: *mut fmx_QuadChar, value: u32, _x: *mut fmx__fmxcpt);

    fn FM_QuadChar_Delete(_self: *mut fmx_QuadChar, _x: *mut fmx__fmxcpt);

    fn FM_Locale_Delete(_self: *mut fmx_Locale, _x: *mut fmx__fmxcpt);

    fn FM_Locale_Constructor1(inputType: LocaleType, _x: *mut fmx__fmxcpt) -> *mut fmx_Locale;

    #[allow(dead_code)]
    fn FM_Locale_operatorAS(
        _self: *mut fmx_Locale,
        rhs: *const fmx_Locale,
        _x: *mut fmx__fmxcpt,
    ) -> *mut fmx_Locale;

}

pub struct Locale {
    pub(crate) ptr: *mut fmx_Locale,
    drop: bool,
}

impl Locale {
    pub fn new(input_type: LocaleType) -> Self {
        let mut _x = fmx__fmxcpt::new();
        let ptr = unsafe { FM_Locale_Constructor1(input_type, &mut _x) };
        _x.check();
        Self { ptr, drop: true }
    }

    pub fn from_ptr(ptr: *const fmx_Locale) -> Self {
        Self {
            ptr: ptr as *mut fmx_Locale,
            drop: false,
        }
    }
}

impl Drop for Locale {
    fn drop(&mut self) {
        if self.drop {
            let mut _x = fmx__fmxcpt::new();
            unsafe { FM_Locale_Delete(self.ptr, &mut _x) };
            _x.check();
        }
    }
}

impl Default for Locale {
    fn default() -> Self {
        Locale::new(LocaleType::System)
    }
}

pub struct QuadChar {
    pub(crate) ptr: *mut fmx_QuadChar,
    drop: bool,
}

impl QuadChar {
    pub fn new(bytes: &[u8; 4]) -> Self {
        let mut _x = fmx__fmxcpt::new();
        let b: &[i8; 4] = unsafe { &*(bytes as *const [u8; 4] as *const [i8; 4]) };
        let ptr = unsafe { FM_QuadChar_Constructor2(b[0], b[1], b[2], b[3], &mut _x) };
        _x.check();
        Self { ptr, drop: true }
    }

    pub fn empty() -> Self {
        let mut _x = fmx__fmxcpt::new();
        let ptr = unsafe { FM_QuadChar_Constructor1(&mut _x) };
        _x.check();
        Self { ptr, drop: true }
    }
}

impl Drop for QuadChar {
    fn drop(&mut self) {
        if self.drop {
            let mut _x = fmx__fmxcpt::new();
            unsafe { FM_QuadChar_Delete(self.ptr, &mut _x) };
            _x.check();
        }
    }
}

#[repr(i32)]
pub enum LocaleType {
    None = 0,            // Empty
    System = 1,          // Uses system settings
    UnicodeRaw = 2,      // Use raw unicode bytes (like the old ASCII ordering)
    UnicodeStandard = 3, // Standard unicode rules
    Catalog = 4,         // FileMaker list rules
    CAT = 16,            // Catalan
    HRV = 17,            // Croatian
    CES = 18,            // Czech
    DAN = 19,            // Danish
    NLD = 20,            // Dutch
    ENG = 21,            // English
    FIN = 22,            // Finnish
    FINFMI = 23,         // Finnish (FileMaker custom)
    FRA = 24,            // French
    DEU = 25,            // German
    DEUDictionary = 26,  // German (dictionary ordering)
    ELL = 27,            // Greek
    HUN = 28,            // Hungarian
    ISL = 29,            // Icelandic
    ITA = 30,            // Italian
    JPN = 31,            // Japanese
    NOR = 32,            // Norwegian
    POL = 33,            // Polish
    POR = 34,            // Portuguese
    RON = 35,            // Romanian
    RUS = 36,            // Russian
    SLK = 37,            // Slovak
    SLV = 38,            // Slovenian
    SPA = 39,            // Spanish
    SPATraditional = 40, // Spanish (traditional)
    SWE = 41,            // Swedish
    SWEFMI = 42,         // Swedish (FileMaker custom)
    TUR = 43,            // Turkish
    UKR = 44,            // Ukrainian

    // New to FileMaker Pro 8.5
    CHI = 45,       // Chinese (PinYin)
    CHIStroke = 46, // Chinese (Stroke-radical)

    // New to FileMaker Pro 13
    KOR = 76, // Korean

    // For compatibility with WinSoft versions (supported in FMI versions >= 12)
    HE = 47,       // Hebrew
    HI = 48,       // Hindi
    AR = 49,       // Arabic
    ET = 50,       // Estonian
    LT = 51,       // Lithuanian
    LV = 52,       // Latvian
    SR = 53,       // Serbian
    FA = 54,       // Persian
    BG = 55,       // Bulgarian
    VI = 56,       // Vietnamese
    TH = 57,       // Thai
    ELLMixed = 58, // Greek Mixed
    BEN = 59,      // Bengali
    TEL = 60,      // Telugu
    MAR = 61,      // Marathi
    TAM = 62,      // Tamil
    GUJ = 63,      // Gujarati
    KAN = 64,      // Kannada
    MAL = 65,      // Malayalam
    PAN = 67,      // Panjabi

    // Used in versions distributed by WinSoft (not supported in FMI versions)
    ORI = 66, // Oriya
    SIN = 68, // Sinhala
    URD = 69, // Urdu
    DIV = 70, // Divehi (Thanaa)
    BUR = 71, // Burmese (Myanmar)
    SAN = 72, // Sanskrit
    LAO = 73, // Lao
    KHM = 74, // Khmer
    BOD = 75, // Tibetan

    Invalid = 0xFFFF,
}

impl fmt::Display for QuadChar {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let mut _x = fmx__fmxcpt::new();
        let mut bytes: Vec<u8> = Vec::with_capacity(4);
        for i in 0..4 {
            let c = unsafe { FM_QuadChar_operatorAR(self.ptr, i, &mut _x) };
            bytes.push(c);
            _x.check();
        }
        let str = unsafe { String::from_utf8_unchecked(bytes) };
        write!(f, "{}", str)
    }
}