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
//! `IVGSnapPoint` 一时—— 抓取点
//!
//! - [`IvgSnapPoint`]          : 通用抓取点
//! - [`IvgSnapPoints`]         : 集合
//! - [`IvgSnapPointRange`]     : 范围
//! - [`IvgUserSnapPoint`]      : 用户自定义抓取点
//! - [`IvgObjectSnapPoint`]    : 对象抓取点(中点、端点、圆心……)
//! - [`IvgBBoxSnapPoint`]      : 包围盒角点
//! - [`IvgEdgeSnapPoint`]      : 边缘抓取点

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

use crate::curve::IvgNode;
use crate::shape::IvgShape;

// =============================================================
// IvgSnapPoint
// =============================================================

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

impl IvgSnapPoint {
    /// 由 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_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()
    }

    // ---- 位置 ----

    /// 读取位置 X 坐标(`PositionX`)。
    pub fn position_x(&self) -> Option<f64> { self.prop_f64("PositionX") }
    /// 设置位置 X 坐标(`PositionX`)。
    pub fn set_position_x(&self, v: f64) -> bool { self.put_f64("PositionX", v) }

    /// 读取位置 Y 坐标(`PositionY`)。
    pub fn position_y(&self) -> Option<f64> { self.prop_f64("PositionY") }
    /// 设置位置 Y 坐标(`PositionY`)。
    pub fn set_position_y(&self, v: f64) -> bool { self.put_f64("PositionY", v) }

    /// 读取位置。
    pub fn get_position(&self) -> Option<(f64, f64)> {
        Some((self.position_x()?, self.position_y()?))
    }

    /// 设置位置。
    pub fn set_position(&self, x: f64, y: f64) -> bool {
        self.set_position_x(x) && self.set_position_y(y)
    }

    /// 移动(COM 方法 `Move`)。
    pub fn move_by(&self, dx: f64, dy: f64) -> bool {
        let args = vec![
            Variant::from_f64(dx),
            Variant::from_f64(dy),
        ];
        self.disp.invoke_method("Move", args).is_ok()
    }

    // ---- 类型 / 方向 ----

    /// `cdrPointType`
    pub fn point_type(&self) -> Option<i64> { self.prop_i64("Type") }

    /// 读取方向(`Direction`)。
    pub fn direction(&self) -> Option<f64> { self.prop_f64("Direction") }
    /// 设置方向(`Direction`)。
    pub fn set_direction(&self, v: f64) -> bool { self.put_f64("Direction", v) }

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

    /// 是否可选择(`IsSelectable`)。
    pub fn is_selectable(&self) -> Option<bool> { self.prop_bool("IsSelectable") }
    /// 读取 COM 属性 `IsDeletable`。
    pub fn is_deletable(&self) -> Option<bool> { self.prop_bool("IsDeletable") }
    /// 读取 COM 属性 `IsMovable`。
    pub fn is_movable(&self) -> Option<bool> { self.prop_bool("IsMovable") }
    /// 是否可以更改方向(`CanChangeDirection`)。
    pub fn can_change_direction(&self) -> Option<bool> {
        self.prop_bool("CanChangeDirection")
    }

    /// 读取已选中(`Selected`)。
    pub fn selected(&self) -> Option<bool> { self.prop_bool("Selected") }
    /// 设置已选中(`Selected`)。
    pub fn set_selected(&self, v: bool) -> bool { self.put_bool("Selected", v) }

    /// 创建选择(COM 方法 `CreateSelection`)。
    pub fn create_selection(&self) -> bool {
        self.disp.invoke_method("CreateSelection", vec![]).is_ok()
    }

    // ---- 关联 ----

    /// 读取节点(`Node`)。
    pub fn node(&self) -> Option<IvgNode> {
        self.prop_dispatch("Node").map(IvgNode::new)
    }

    /// 读取图形(`Shape`)。
    pub fn shape(&self) -> Option<IvgShape> {
        self.prop_dispatch("Shape").map(IvgShape::new)
    }

    /// 引用数据(GUID 字符串,唯一定位一个抓取点)。
    pub fn reference_data(&self) -> Option<String> {
        self.prop_string("ReferenceData")
    }

    // ---- 子类视图(按类型取) ----

    /// 读取用户(`User`)。
    pub fn user(&self) -> Option<IvgUserSnapPoint> {
        self.prop_dispatch("User").map(IvgUserSnapPoint::new)
    }

    /// 读取对象(`Object`)。
    pub fn object(&self) -> Option<IvgObjectSnapPoint> {
        self.prop_dispatch("Object").map(IvgObjectSnapPoint::new)
    }

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

    /// 读取边缘(`Edge`)。
    pub fn edge(&self) -> Option<IvgEdgeSnapPoint> {
        self.prop_dispatch("Edge").map(IvgEdgeSnapPoint::new)
    }

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

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

// =============================================================
// IvgUserSnapPoint
// =============================================================

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

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

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

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

    /// 读取标识(`ID`)。
    pub fn id(&self) -> Option<String> { self.prop_string("ID") }

    /// 读取自动捕捉(`AutoSnap`)。
    pub fn auto_snap(&self) -> Option<bool> { self.prop_bool("AutoSnap") }
    /// 设置自动捕捉(`AutoSnap`)。
    pub fn set_auto_snap(&self, v: bool) -> bool { self.put_bool("AutoSnap", v) }
}

// =============================================================
// IvgObjectSnapPoint
// =============================================================

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

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

    /// `cdrObjectSnapPointType`
    pub fn snap_type(&self) -> Option<i64> {
        self.disp.get_property("Type").ok()?.to_i64().ok()
    }
}

// =============================================================
// IvgBBoxSnapPoint
// =============================================================

/// CorelDRAW `IVGSnapPoint` 对象的后期绑定包装(b 框捕捉点)。
///
/// 所有属性与方法通过 `IDispatch::Invoke` 按名称调用,调用失败时一般返回 `None` 或 `false`。
pub struct IvgBBoxSnapPoint {
    disp: ComObject,
}

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

    /// `cdrReferencePoint`
    pub fn snap_type(&self) -> Option<i64> {
        self.disp.get_property("Type").ok()?.to_i64().ok()
    }
}

// =============================================================
// IvgEdgeSnapPoint
// =============================================================

/// CorelDRAW `IVGSnapPoint` 对象的后期绑定包装(边缘捕捉点)。
///
/// 所有属性与方法通过 `IDispatch::Invoke` 按名称调用,调用失败时一般返回 `None` 或 `false`。
pub struct IvgEdgeSnapPoint {
    disp: ComObject,
}

impl IvgEdgeSnapPoint {
    /// 由 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()
    }

    /// 读取线段索引(`SegmentIndex`)。
    pub fn segment_index(&self) -> Option<i64> { self.prop_i64("SegmentIndex") }
    /// 读取线段偏移(`SegmentOffset`)。
    pub fn segment_offset(&self) -> Option<f64> { self.prop_f64("SegmentOffset") }
}

// =============================================================
// IvgSnapPoints
// =============================================================

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

impl IvgSnapPoints {
    /// 由 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: i32) -> Option<IvgSnapPoint> {
        let args = vec![Variant::from_i64(index as i64)];
        self.disp
            .invoke_method("Item", args)
            .ok()?
            .to_idispatch()
            .ok()
            .map(IvgSnapPoint::new)
    }

    /// 返回全部条目。
    pub fn all(&self) -> Vec<IvgSnapPoint> {
        let n = self.count().unwrap_or(0) as i32;
        (1..=n).filter_map(|i| self.item(i)).collect()
    }

    // ---- 分类获取 ----

    /// 用户(COM 方法 `User`)。
    pub fn user(&self, id: impl Into<String>) -> Option<IvgSnapPoint> {
        let args = vec![Variant::from_str(id.into())];
        self.disp
            .invoke_method("User", args)
            .ok()?
            .to_idispatch()
            .ok()
            .map(IvgSnapPoint::new)
    }

    /// `cdrReferencePoint`
    pub fn bbox(&self, ref_point: i32) -> Option<IvgSnapPoint> {
        let args = vec![Variant::from_i64(ref_point as i64)];
        self.disp
            .invoke_method("BBox", args)
            .ok()?
            .to_idispatch()
            .ok()
            .map(IvgSnapPoint::new)
    }

    /// `cdrObjectSnapPointType`
    pub fn object(&self, snap_type: i32) -> Option<IvgSnapPoint> {
        let args = vec![Variant::from_i64(snap_type as i64)];
        self.disp
            .invoke_method("Object", args)
            .ok()?
            .to_idispatch()
            .ok()
            .map(IvgSnapPoint::new)
    }

    /// 边缘(COM 方法 `Edge`)。
    pub fn edge(&self, segment_index: i32, segment_offset: f64) -> Option<IvgSnapPoint> {
        let args = vec![
            Variant::from_i64(segment_index as i64),
            Variant::from_f64(segment_offset),
        ];
        self.disp
            .invoke_method("Edge", args)
            .ok()?
            .to_idispatch()
            .ok()
            .map(IvgSnapPoint::new)
    }

    /// 自动捕捉点(COM 方法 `Auto`)。
    pub fn auto_snap_point(&self) -> Option<IvgSnapPoint> {
        self.disp
            .invoke_method("Auto", vec![])
            .ok()?
            .to_idispatch()
            .ok()
            .map(IvgSnapPoint::new)
    }

    /// 查找最近(COM 方法 `FindClosest`)。
    pub fn find_closest(
        &self,
        type_set: i32,
        x: f64,
        y: f64,
    ) -> Option<IvgSnapPoint> {
        let args = vec![
            Variant::from_i64(type_set as i64),
            Variant::from_f64(x),
            Variant::from_f64(y),
        ];
        self.disp
            .invoke_method("FindClosest", args)
            .ok()?
            .to_idispatch()
            .ok()
            .map(IvgSnapPoint::new)
    }

    // ---- 范围 ----

    /// 按引用数组取范围。
    pub fn range(&self, references: Variant) -> Option<IvgSnapPointRange> {
        let args = vec![references];
        self.disp
            .invoke_method("Range", args)
            .ok()?
            .to_idispatch()
            .ok()
            .map(IvgSnapPointRange::new)
    }

    /// 读取选择(`Selection`)。
    pub fn selection(&self) -> Option<IvgSnapPointRange> {
        self.prop_dispatch("Selection").map(IvgSnapPointRange::new)
    }

    /// 读取全部范围(`All`)。
    pub fn all_range(&self) -> Option<IvgSnapPointRange> {
        self.prop_dispatch("All").map(IvgSnapPointRange::new)
    }

    /// 清除选择(COM 方法 `ClearSelection`)。
    pub fn clear_selection(&self) -> bool {
        self.disp.invoke_method("ClearSelection", vec![]).is_ok()
    }

    // ---- 添加用户抓取点----

    /// 添加用户捕捉点(COM 方法 `AddUserSnapPoint`)。
    pub fn add_user_snap_point(
        &self,
        x: f64,
        y: f64,
        direction: f64,
        use_direction: bool,
    ) -> Option<IvgSnapPoint> {
        let args = vec![
            Variant::from_f64(x),
            Variant::from_f64(y),
            Variant::from_f64(direction),
            Variant::from_bool(use_direction),
        ];
        self.disp
            .invoke_method("AddUserSnapPoint", args)
            .ok()?
            .to_idispatch()
            .ok()
            .map(IvgSnapPoint::new)
    }

    /// 添加用户捕捉点扩展版(COM 方法 `AddUserSnapPointEx`)。
    pub fn add_user_snap_point_ex(
        &self,
        id: impl Into<String>,
        x: f64,
        y: f64,
        direction: f64,
        use_direction: bool,
    ) -> Option<IvgSnapPoint> {
        let args = vec![
            Variant::from_str(id.into()),
            Variant::from_f64(x),
            Variant::from_f64(y),
            Variant::from_f64(direction),
            Variant::from_bool(use_direction),
        ];
        self.disp
            .invoke_method("AddUserSnapPointEx", args)
            .ok()?
            .to_idispatch()
            .ok()
            .map(IvgSnapPoint::new)
    }
}

// =============================================================
// IvgSnapPointRange
// =============================================================

/// CorelDRAW `IVGSnapPoint` 对象的后期绑定包装(捕捉点范围)。
///
/// 所有属性与方法通过 `IDispatch::Invoke` 按名称调用,调用失败时一般返回 `None` 或 `false`。
pub struct IvgSnapPointRange {
    disp: ComObject,
}

impl IvgSnapPointRange {
    /// 由 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<IvgSnapPoint> {
        let args = vec![Variant::from_i64(index as i64)];
        self.disp
            .invoke_method("Item", args)
            .ok()?
            .to_idispatch()
            .ok()
            .map(IvgSnapPoint::new)
    }

    /// 返回全部条目。
    pub fn all(&self) -> Vec<IvgSnapPoint> {
        let n = self.count().unwrap_or(0) as i32;
        (1..=n).filter_map(|i| self.item(i)).collect()
    }

    /// 移动(COM 方法 `Move`)。
    pub fn move_by(&self, dx: f64, dy: f64) -> bool {
        let args = vec![
            Variant::from_f64(dx),
            Variant::from_f64(dy),
        ];
        self.disp.invoke_method("Move", args).is_ok()
    }

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

    /// 添加(COM 方法 `Add`)。
    pub fn add(&self, sp: &IvgSnapPoint) -> Option<bool> {
        let args = vec![sp.as_variant()];
        self.disp.invoke_method("Add", args).ok()?.to_bool().ok()
    }

    /// 移除(COM 方法 `Remove`)。
    pub fn remove(&self, index: i32) -> Option<bool> {
        let args = vec![Variant::from_i64(index as i64)];
        self.disp.invoke_method("Remove", args).ok()?.to_bool().ok()
    }

    /// 移除参考(COM 方法 `RemoveByReference`)。
    pub fn remove_by_reference(&self, reference_data: impl Into<String>) -> Option<bool> {
        let args = vec![Variant::from_str(reference_data.into())];
        self.disp
            .invoke_method("RemoveByReference", args)
            .ok()?
            .to_bool()
            .ok()
    }

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

    /// 创建选择(COM 方法 `CreateSelection`)。
    pub fn create_selection(&self) -> bool {
        self.disp.invoke_method("CreateSelection", vec![]).is_ok()
    }

    /// 添加选择(COM 方法 `AddToSelection`)。
    pub fn add_to_selection(&self) -> bool {
        self.disp.invoke_method("AddToSelection", vec![]).is_ok()
    }

    /// 移除选择(COM 方法 `RemoveFromSelection`)。
    pub fn remove_from_selection(&self) -> bool {
        self.disp.invoke_method("RemoveFromSelection", vec![]).is_ok()
    }

    /// 更改方向(COM 方法 `ChangeDirection`)。
    pub fn change_direction(&self, direction: f64, uses_direction: i32) -> bool {
        let args = vec![
            Variant::from_f64(direction),
            Variant::from_i64(uses_direction as i64),
        ];
        self.disp.invoke_method("ChangeDirection", args).is_ok()
    }

    /// 设置自动捕捉(`SetAutoSnap`)。
    pub fn set_auto_snap(&self, v: bool) -> bool {
        let args = vec![Variant::from_bool(v)];
        self.disp.invoke_method("SetAutoSnap", args).is_ok()
    }
}