cdrsdk 1.0.0

Rust SDK for CorelDRAW automation via COM IDispatch late binding
Documentation
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
//! `IVGHatchFill` —— 剖面线填充
//! `IVGHatchPattern(s)` —— 剖面线图案
//! `IVGHatchLibrary / Libraries` —— 剖面线库
//! `IVGHatchFills` —— 库里的填充集合

use wincom::{ComObject, Variant};
use windows::Win32::System::Com::IDispatch;

use crate::color::IvgColor;
use crate::outline::IvgOutlineStyle;

// =============================================================
// IvgHatchFill
// =============================================================

/// CorelDRAW `IVGHatchFill` 对象的后期绑定包装(剖面线填充)。
///
/// 所有属性与方法通过 `IDispatch::Invoke` 按名称调用,调用失败时一般返回 `None` 或 `false`。
pub struct IvgHatchFill {
    disp: ComObject,
}

impl IvgHatchFill {
    /// 由 COM `IDispatch` 构造包装对象。
    pub fn new(disp: IDispatch) -> Self {
        Self { disp: ComObject::from_dispatch(disp, crate::types::IID_IDISPATCH) }
    }

    /// 从 COM `IDispatch` 构造包装对象,等价于 `new`。
    pub fn from_disp(disp: IDispatch) -> Self {
        Self::new(disp)
    }

    /// 把底层 COM 对象包装成 `VARIANT`,用于传给其它 COM 调用。
    pub fn as_variant(&self) -> Variant {
        self.disp.as_variant()
    }

    fn prop_i64(&self, name: &str) -> Option<i64> {
        self.disp.get_property(name).ok()?.to_i64().ok()
    }

    fn prop_f64(&self, name: &str) -> Option<f64> {
        self.disp.get_property(name).ok()?.to_f64().ok()
    }

    fn prop_bool(&self, name: &str) -> Option<bool> {
        self.disp.get_property(name).ok()?.to_bool().ok()
    }

    fn prop_string(&self, name: &str) -> Option<String> {
        self.disp.get_property(name).ok()?.to_string().ok()
    }

    fn prop_dispatch(&self, name: &str) -> Option<IDispatch> {
        self.disp.get_property(name).ok()?.to_idispatch().ok()
    }

    // fn put_i64(&self, name: &str, v: i64) -> bool {
    //     let arg = Variant::from_i64(v);
    //     self.disp.set_property(name, vec![arg]).is_ok()
    // }

    fn put_f64(&self, name: &str, v: f64) -> bool {
        let arg = Variant::from_f64(v);
        self.disp.set_property(name, vec![arg]).is_ok()
    }

    fn put_bool(&self, name: &str, v: bool) -> bool {
        let arg = Variant::from_bool(v);
        self.disp.set_property(name, vec![arg]).is_ok()
    }

    fn put_color(&self, name: &str, c: &IvgColor) -> bool {
        self.disp.set_property(name, vec![c.as_variant()]).is_ok()
    }

    // ---- 背景色----

    /// 读取后颜色(`BackColor`)。
    pub fn back_color(&self) -> Option<IvgColor> {
        self.prop_dispatch("BackColor").map(IvgColor::new)
    }
    /// 设置后颜色(`BackColor`)。
    pub fn set_back_color(&self, c: &IvgColor) -> bool {
        self.put_color("BackColor", c)
    }

    /// 是否有背景(`HasBackground`)。
    pub fn has_background(&self) -> Option<bool> { self.prop_bool("HasBackground") }

    /// 设置无后颜色(`SetNoBackColor`)。
    pub fn set_no_back_color(&self) -> bool {
        self.disp.invoke_method("SetNoBackColor", vec![]).is_ok()
    }

    // ---- 变换 ----

    /// 读取变换图形(`TransformWithShape`)。
    pub fn transform_with_shape(&self) -> Option<bool> {
        self.prop_bool("TransformWithShape")
    }
    /// 设置变换图形(`TransformWithShape`)。
    pub fn set_transform_with_shape(&self, v: bool) -> bool {
        self.put_bool("TransformWithShape", v)
    }

    /// 读取缩放线图形(`ScaleLinesWithShape`)。
    pub fn scale_lines_with_shape(&self) -> Option<bool> {
        self.prop_bool("ScaleLinesWithShape")
    }
    /// 设置缩放线图形(`ScaleLinesWithShape`)。
    pub fn set_scale_lines_with_shape(&self, v: bool) -> bool {
        self.put_bool("ScaleLinesWithShape", v)
    }

    /// 读取 COM 属性 `UseWorldCoordinates`。
    pub fn use_world_coordinates(&self) -> Option<bool> {
        self.prop_bool("UseWorldCoordinates")
    }
    /// 设置 COM 属性 `UseWorldCoordinates`。
    pub fn set_use_world_coordinates(&self, v: bool) -> bool {
        self.put_bool("UseWorldCoordinates", v)
    }

    // ---- 应/ 名称 ----

    /// 读取库名称(`LibraryName`)。
    pub fn library_name(&self) -> Option<String> {
        self.prop_string("LibraryName")
    }

    /// 读取剖面线名称(`HatchName`)。
    pub fn hatch_name(&self) -> Option<String> {
        self.prop_string("HatchName")
    }

    /// 是否库(`IsFromLibrary`)。
    pub fn is_from_library(&self) -> Option<bool> { self.prop_bool("IsFromLibrary") }

    /// 读取索引(`Index`)。
    pub fn index(&self) -> Option<i64> { self.prop_i64("Index") }

    /// 读取库(`Library`)。
    pub fn library(&self) -> Option<IvgHatchLibrary> {
        self.prop_dispatch("Library").map(IvgHatchLibrary::new)
    }

    // ---- 缩放 ----

    /// 读取填充缩放 X 坐标(`FillScaleX`)。
    pub fn fill_scale_x(&self) -> Option<f64> { self.prop_f64("FillScaleX") }
    /// 设置填充缩放 X 坐标(`FillScaleX`)。
    pub fn set_fill_scale_x(&self, v: f64) -> bool { self.put_f64("FillScaleX", v) }

    /// 读取填充缩放 Y 坐标(`FillScaleY`)。
    pub fn fill_scale_y(&self) -> Option<f64> { self.prop_f64("FillScaleY") }
    /// 设置填充缩放 Y 坐标(`FillScaleY`)。
    pub fn set_fill_scale_y(&self, v: f64) -> bool { self.put_f64("FillScaleY", v) }

    /// 读取旋转角度(`RotationAngle`)。
    pub fn rotation_angle(&self) -> Option<f64> {
        self.prop_f64("RotationAngle")
    }
    /// 设置旋转角度(`RotationAngle`)。
    pub fn set_rotation_angle(&self, v: f64) -> bool {
        self.put_f64("RotationAngle", v)
    }

    /// 读取倾斜角度(`SkewAngle`)。
    pub fn skew_angle(&self) -> Option<f64> { self.prop_f64("SkewAngle") }
    /// 设置倾斜角度(`SkewAngle`)。
    pub fn set_skew_angle(&self, v: f64) -> bool { self.put_f64("SkewAngle", v) }

    /// 设置填充缩放(`SetFillScale`)。
    pub fn set_fill_scale(&self, v: f64) -> bool {
        let args = vec![Variant::from_f64(v)];
        self.disp.invoke_method("SetFillScale", args).is_ok()
    }

    /// 读取填充缩放(`GetFillScale`)。
    pub fn get_fill_scale(&self) -> Option<f64> {
        self.disp.invoke_method("GetFillScale", vec![]).ok()?.to_f64().ok()
    }

    /// 设置线缩放(`SetLineScale`)。
    pub fn set_line_scale(&self, v: f64) -> bool {
        let args = vec![Variant::from_f64(v)];
        self.disp.invoke_method("SetLineScale", args).is_ok()
    }

    /// 读取线缩放(`GetLineScale`)。
    pub fn get_line_scale(&self) -> Option<f64> {
        self.disp.invoke_method("GetLineScale", vec![]).ok()?.to_f64().ok()
    }

    // ---- 图案 ----

    /// 读取 COM 属性 `Patterns`。
    pub fn patterns(&self) -> Option<IvgHatchPatterns> {
        self.prop_dispatch("Patterns").map(IvgHatchPatterns::new)
    }

    /// 添加图案。
    #[allow(clippy::too_many_arguments)]
    pub fn add_pattern(
        &self,
        angle: f64,
        spacing: f64,
        shift: f64,
        origin_x: f64,
        origin_y: f64,
        width: f64,
        color: &IvgColor,
        style: &IvgOutlineStyle,
        dash_dot_length: f64,
        pen_width: f64,
    ) -> Option<IvgHatchPattern> {
        let args = vec![
            Variant::from_f64(angle),
            Variant::from_f64(spacing),
            Variant::from_f64(shift),
            Variant::from_f64(origin_x),
            Variant::from_f64(origin_y),
            Variant::from_f64(width),
            color.as_variant(),
            style.as_variant(),
            Variant::from_f64(dash_dot_length),
            Variant::from_f64(pen_width),
        ];
        self.disp
            .invoke_method("AddPattern", args)
            .ok()?
            .to_idispatch()
            .ok()
            .map(IvgHatchPattern::new)
    }

    /// 保存到剖面线库。
    pub fn add_to_library(
        &self,
        library_name: impl Into<String>,
        hatch_name: impl Into<String>,
    ) -> bool {
        let args = vec![
            Variant::from_str(library_name.into()),
            Variant::from_str(hatch_name.into()),
        ];
        self.disp.invoke_method("AddToLibrary", args).is_ok()
    }

    /// 从剖面线库选择。
    #[allow(clippy::too_many_arguments)]
    pub fn select(
        &self,
        library_name: impl Into<String>,
        hatch_name_or_index: Variant,
        back_color: &IvgColor,
        transform_with_shape: bool,
        scale_lines_with_shape: bool,
        use_world_coordinates: bool,
        fill_scale: f64,
        line_scale: f64,
        fill_angle: f64,
        fill_skew: f64,
    ) -> bool {
        let args = vec![
            Variant::from_str(library_name.into()),
            hatch_name_or_index,
            back_color.as_variant(),
            Variant::from_bool(transform_with_shape),
            Variant::from_bool(scale_lines_with_shape),
            Variant::from_bool(use_world_coordinates),
            Variant::from_f64(fill_scale),
            Variant::from_f64(line_scale),
            Variant::from_f64(fill_angle),
            Variant::from_f64(fill_skew),
        ];
        self.disp.invoke_method("Select", args).is_ok()
    }
}

// =============================================================
// IvgHatchPatterns
// =============================================================

/// CorelDRAW `IVGHatchFill` 对象的后期绑定包装(剖面线图案)。
///
/// 所有属性与方法通过 `IDispatch::Invoke` 按名称调用,调用失败时一般返回 `None` 或 `false`。
pub struct IvgHatchPatterns {
    disp: ComObject,
}

impl IvgHatchPatterns {
    /// 由 COM `IDispatch` 构造包装对象。
    pub fn new(disp: IDispatch) -> Self {
        Self { disp: ComObject::from_dispatch(disp, crate::types::IID_IDISPATCH) }
    }

    fn prop_i64(&self, name: &str) -> Option<i64> {
        self.disp.get_property(name).ok()?.to_i64().ok()
    }

    /// 读取返回条目数量(`Count`)。
    pub fn count(&self) -> Option<i64> { self.prop_i64("Count") }

    /// 按索引或名称取条目(COM 方法 `Item`)。
    pub fn item(&self, index: i32) -> Option<IvgHatchPattern> {
        let args = vec![Variant::from_i64(index as i64)];
        self.disp
            .invoke_method("Item", args)
            .ok()?
            .to_idispatch()
            .ok()
            .map(IvgHatchPattern::new)
    }

    /// 重置(COM 方法 `Reset`)。
    pub fn reset(&self) -> bool {
        self.disp.invoke_method("Reset", vec![]).is_ok()
    }
}

// =============================================================
// IvgHatchPattern
// =============================================================

/// CorelDRAW `IVGHatchFill` 对象的后期绑定包装(剖面线图案)。
///
/// 所有属性与方法通过 `IDispatch::Invoke` 按名称调用,调用失败时一般返回 `None` 或 `false`。
pub struct IvgHatchPattern {
    disp: ComObject,
}

impl IvgHatchPattern {
    /// 由 COM `IDispatch` 构造包装对象。
    pub fn new(disp: IDispatch) -> Self {
        Self { disp: ComObject::from_dispatch(disp, crate::types::IID_IDISPATCH) }
    }

    fn prop_i64(&self, name: &str) -> Option<i64> {
        self.disp.get_property(name).ok()?.to_i64().ok()
    }

    fn prop_f64(&self, name: &str) -> Option<f64> {
        self.disp.get_property(name).ok()?.to_f64().ok()
    }

    fn prop_dispatch(&self, name: &str) -> Option<IDispatch> {
        self.disp.get_property(name).ok()?.to_idispatch().ok()
    }

    // fn put_i64(&self, name: &str, v: i64) -> bool {
    //     let arg = Variant::from_i64(v);
    //     self.disp.set_property(name, vec![arg]).is_ok()
    // }

    fn put_f64(&self, name: &str, v: f64) -> bool {
        let arg = Variant::from_f64(v);
        self.disp.set_property(name, vec![arg]).is_ok()
    }

    // ---- 基本属性----

    /// 读取角度(`Angle`)。
    pub fn angle(&self) -> Option<f64> { self.prop_f64("Angle") }
    /// 设置角度(`Angle`)。
    pub fn set_angle(&self, v: f64) -> bool { self.put_f64("Angle", v) }

    /// 读取原点 X 坐标(`OriginX`)。
    pub fn origin_x(&self) -> Option<f64> { self.prop_f64("OriginX") }
    /// 设置原点 X 坐标(`OriginX`)。
    pub fn set_origin_x(&self, v: f64) -> bool { self.put_f64("OriginX", v) }

    /// 读取原点 Y 坐标(`OriginY`)。
    pub fn origin_y(&self) -> Option<f64> { self.prop_f64("OriginY") }
    /// 设置原点 Y 坐标(`OriginY`)。
    pub fn set_origin_y(&self, v: f64) -> bool { self.put_f64("OriginY", v) }

    /// 读取间距(`Spacing`)。
    pub fn spacing(&self) -> Option<f64> { self.prop_f64("Spacing") }
    /// 设置间距(`Spacing`)。
    pub fn set_spacing(&self, v: f64) -> bool { self.put_f64("Spacing", v) }

    /// 读取偏移(`Shift`)。
    pub fn shift(&self) -> Option<f64> { self.prop_f64("Shift") }
    /// 设置偏移(`Shift`)。
    pub fn set_shift(&self, v: f64) -> bool { self.put_f64("Shift", v) }

    /// 读取偏移百分比(`ShiftPercent`)。
    pub fn shift_percent(&self) -> Option<f64> { self.prop_f64("ShiftPercent") }
    /// 设置偏移百分比(`ShiftPercent`)。
    pub fn set_shift_percent(&self, v: f64) -> bool {
        self.put_f64("ShiftPercent", v)
    }

    /// 读取索引(`Index`)。
    pub fn index(&self) -> Option<i64> { self.prop_i64("Index") }

    /// 图案的轮廓(线条属性)。
    pub fn outline(&self) -> Option<crate::outline::IvgOutline> {
        self.prop_dispatch("Outline").map(crate::outline::IvgOutline::new)
    }

    // ---- 操作 ----

    /// 删除(COM 方法 `Delete`)。
    pub fn delete(&self) -> bool {
        self.disp.invoke_method("Delete", vec![]).is_ok()
    }

    /// 设置原点(`SetOrigin`)。
    pub fn set_origin(&self, x: f64, y: f64) -> bool {
        let args = vec![
            Variant::from_f64(x),
            Variant::from_f64(y),
        ];
        self.disp.invoke_method("SetOrigin", args).is_ok()
    }

    /// 读取原点。
    pub fn get_origin(&self) -> Option<(f64, f64)> {
        // 发 out 参数,用属性代替
        Some((self.origin_x()?, self.origin_y()?))
    }

    /// 一次性设置。
    #[allow(clippy::too_many_arguments)]
    pub fn set_properties(
        &self,
        angle: Variant,
        spacing: f64,
        shift: Variant,
        origin_x: Variant,
        origin_y: Variant,
        width: f64,
        color: &IvgColor,
        style: &IvgOutlineStyle,
        dash_dot_length: f64,
        pen_width: f64,
    ) -> bool {
        let args = vec![
            angle,
            Variant::from_f64(spacing),
            shift,
            origin_x,
            origin_y,
            Variant::from_f64(width),
            color.as_variant(),
            style.as_variant(),
            Variant::from_f64(dash_dot_length),
            Variant::from_f64(pen_width),
        ];
        self.disp.invoke_method("SetProperties", args).is_ok()
    }

    /// 重置(COM 方法 `Reset`)。
    pub fn reset(&self) -> bool {
        self.disp.invoke_method("Reset", vec![]).is_ok()
    }
}

// =============================================================
// IvgHatchLibrary
// =============================================================

/// CorelDRAW `IVGHatchFill` 对象的后期绑定包装(剖面线库)。
///
/// 所有属性与方法通过 `IDispatch::Invoke` 按名称调用,调用失败时一般返回 `None` 或 `false`。
pub struct IvgHatchLibrary {
    disp: ComObject,
}

impl IvgHatchLibrary {
    /// 由 COM `IDispatch` 构造包装对象。
    pub fn new(disp: IDispatch) -> Self {
        Self { disp: ComObject::from_dispatch(disp, crate::types::IID_IDISPATCH) }
    }

    fn prop_i64(&self, name: &str) -> Option<i64> {
        self.disp.get_property(name).ok()?.to_i64().ok()
    }

    fn prop_bool(&self, name: &str) -> Option<bool> {
        self.disp.get_property(name).ok()?.to_bool().ok()
    }

    fn prop_string(&self, name: &str) -> Option<String> {
        self.disp.get_property(name).ok()?.to_string().ok()
    }

    fn prop_dispatch(&self, name: &str) -> Option<IDispatch> {
        self.disp.get_property(name).ok()?.to_idispatch().ok()
    }

    /// 读取名称(`Name`)。
    pub fn name(&self) -> Option<String> { self.prop_string("Name") }
    /// 读取显示名称(`DisplayName`)。
    pub fn display_name(&self) -> Option<String> {
        self.prop_string("DisplayName")
    }

    /// 读取索引(`Index`)。
    pub fn index(&self) -> Option<i64> { self.prop_i64("Index") }
    /// 读取活动(`Active`)。
    pub fn active(&self) -> Option<bool> { self.prop_bool("Active") }

    /// 读取填充(`Fills`)。
    pub fn fills(&self) -> Option<IvgHatchFills> {
        self.prop_dispatch("Fills").map(IvgHatchFills::new)
    }

    /// activate(COM 方法 `Activate`)。
    pub fn activate(&self) -> bool {
        self.disp.invoke_method("Activate", vec![]).is_ok()
    }
}

// =============================================================
// IvgHatchLibraries
// =============================================================

/// CorelDRAW `IVGHatchFill` 对象的后期绑定包装(剖面线库集)。
///
/// 所有属性与方法通过 `IDispatch::Invoke` 按名称调用,调用失败时一般返回 `None` 或 `false`。
pub struct IvgHatchLibraries {
    disp: ComObject,
}

impl IvgHatchLibraries {
    /// 由 COM `IDispatch` 构造包装对象。
    pub fn new(disp: IDispatch) -> Self {
        Self { disp: ComObject::from_dispatch(disp, crate::types::IID_IDISPATCH) }
    }

    fn prop_i64(&self, name: &str) -> Option<i64> {
        self.disp.get_property(name).ok()?.to_i64().ok()
    }

    fn prop_dispatch(&self, name: &str) -> Option<IDispatch> {
        self.disp.get_property(name).ok()?.to_idispatch().ok()
    }

    /// 读取返回条目数量(`Count`)。
    pub fn count(&self) -> Option<i64> { self.prop_i64("Count") }

    /// 按索引或名称取条目(COM 方法 `Item`)。
    pub fn item(&self, index_or_name: Variant) -> Option<IvgHatchLibrary> {
        let args = vec![index_or_name];
        self.disp
            .invoke_method("Item", args)
            .ok()?
            .to_idispatch()
            .ok()
            .map(IvgHatchLibrary::new)
    }

    /// 查找(COM 方法 `Find`)。
    pub fn find(&self, name: impl Into<String>) -> Option<IvgHatchLibrary> {
        let args = vec![Variant::from_str(name.into())];
        self.disp
            .invoke_method("Find", args)
            .ok()?
            .to_idispatch()
            .ok()
            .map(IvgHatchLibrary::new)
    }

    /// 读取活动库(`ActiveLibrary`)。
    pub fn active_library(&self) -> Option<IvgHatchLibrary> {
        self.prop_dispatch("ActiveLibrary").map(IvgHatchLibrary::new)
    }

    /// 读取默认值库(`DefaultLibrary`)。
    pub fn default_library(&self) -> Option<IvgHatchLibrary> {
        self.prop_dispatch("DefaultLibrary").map(IvgHatchLibrary::new)
    }
}

// =============================================================
// IvgHatchFills
// =============================================================

/// CorelDRAW `IVGHatchFill` 对象的后期绑定包装(剖面线填充)。
///
/// 所有属性与方法通过 `IDispatch::Invoke` 按名称调用,调用失败时一般返回 `None` 或 `false`。
pub struct IvgHatchFills {
    disp: ComObject,
}

impl IvgHatchFills {
    /// 由 COM `IDispatch` 构造包装对象。
    pub fn new(disp: IDispatch) -> Self {
        Self { disp: ComObject::from_dispatch(disp, crate::types::IID_IDISPATCH) }
    }

    fn prop_i64(&self, name: &str) -> Option<i64> {
        self.disp.get_property(name).ok()?.to_i64().ok()
    }

    /// 读取返回条目数量(`Count`)。
    pub fn count(&self) -> Option<i64> { self.prop_i64("Count") }

    /// 按索引或名称取条目(COM 方法 `Item`)。
    pub fn item(&self, index_or_name: Variant) -> Option<crate::fill::IvgFill> {
        let args = vec![index_or_name];
        self.disp
            .invoke_method("Item", args)
            .ok()?
            .to_idispatch()
            .ok()
            .map(crate::fill::IvgFill::new)
    }

    /// 查找(COM 方法 `Find`)。
    pub fn find(&self, name: impl Into<String>) -> Option<crate::fill::IvgFill> {
        let args = vec![Variant::from_str(name.into())];
        self.disp
            .invoke_method("Find", args)
            .ok()?
            .to_idispatch()
            .ok()
            .map(crate::fill::IvgFill::new)
    }
}