-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathPropertyGrid.h
More file actions
1320 lines (1109 loc) · 41.6 KB
/
PropertyGrid.h
File metadata and controls
1320 lines (1109 loc) · 41.6 KB
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
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef UI_CONTROL_PROPERTY_GRID_H_
#define UI_CONTROL_PROPERTY_GRID_H_
#include "duilib/Box/VBox.h"
#include "duilib/Core/FontManager.h"
#include "duilib/Control/Split.h"
#include "duilib/Control/Label.h"
#include "duilib/Control/RichText.h"
#include "duilib/Control/RichEdit.h"
#include "duilib/Control/TreeView.h"
#include "duilib/Control/Combo.h"
#include "duilib/Control/ComboButton.h"
#include "duilib/Control/DateTime.h"
#include "duilib/Control/IPAddress.h"
#include "duilib/Control/HotKey.h"
#include "duilib/Utils/FileDialog.h"
namespace ui
{
/** 属性表控件的支持的属性
*/
class PropertyGridGroup;
class PropertyGridProperty;
class PropertyGridTextProperty; //文本和数字
class PropertyGridComboProperty; //下拉框
class PropertyGridFontProperty; //字体名称
class PropertyGridFontSizeProperty; //字体大小
class PropertyGridColorProperty; //颜色
class PropertyGridDateTimeProperty; //日期时间
class PropertyGridIPAddressProperty; //IP地址
class PropertyGridHotKeyProperty; //热键
class PropertyGridFileProperty; //文件路径
class PropertyGridDirectoryProperty; //文件夹
/** 属性表控件
*/
class PropertyGrid : public VBox
{
typedef VBox BaseClass;
public:
explicit PropertyGrid(Window* pWindow);
/** 获取控件类型
*/
virtual DString GetType() const override;
virtual void SetAttribute(const DString& strName, const DString& strValue) override;
/** DPI发生变化,更新控件大小和布局
* @param [in] nOldDpiScale 旧的DPI缩放百分比
* @param [in] nNewDpiScale 新的DPI缩放百分比,与Dpi().GetScale()的值一致
*/
virtual void ChangeDpiScale(uint32_t nOldDpiScale, uint32_t nNewDpiScale) override;
public:
/** 设置是否显示表头
*/
void SetEnableHeaderCtrl(bool bEnable,
const DString& sLeftColumn = _T(""),
const DString& sRightColumn = _T(""));
/** 判断当前是否显示表头
*/
bool IsEnableHeaderCtrl() const { return m_bHeaderCtrl; }
/** 获取Header接口
*/
Control* GetHeaderCtrl() const { return m_pHeaderCtrl; }
/** 获取Header中的左侧一列
*/
Label* GetHeaderLeft() const { return m_pHeaderLeft; }
/** 获取Header中的右侧一列
*/
Label* GetHeaderRight() const { return m_pHeaderRight; }
/** 获取Header中的分割条
*/
Split* GetHeaderSplit() const { return m_pHeaderSplit; }
public:
/** 增加一个分组
* @param [in] groupName 分组的名称
* @param [in] description 分组的描述信息
* @param [in] nGroupData 用户自定义数据
* @return 返回该分组的接口,可用于添加属性
*/
PropertyGridGroup* AddGroup(const DString& groupName,
const DString& description = _T(""),
size_t nGroupData = 0);
/** 获取所有的分组
* @param [out] groups 返回当前所有的分组列表
*/
void GetGroups(std::vector<PropertyGridGroup*>& groups) const;
/** 删除分组
* @param [in] pGroup 待删除的分组
*/
bool RemoveGroup(PropertyGridGroup* pGroup);
/** 删除所有分组
*/
void RemoveAllGroups();
/** 添加一个属性(由调用方创建属性)
* @param [in] pGroup 该属性所属的分组
* @param [in] pProperty 属性接口
*/
bool AddProperty(PropertyGridGroup* pGroup, PropertyGridProperty* pProperty);
/** 增加一个属性(文本、数字类型)
* @param [in] pGroup 该属性所属的分组
* @param [in] propertyName 属性的名称
* @param [in] propertyValue 属性的值
* @param [in] description 属性的描述信息
* @param [in] nPropertyData 用户自定义数据
* @return 返回该属性的接口
*/
PropertyGridTextProperty* AddTextProperty(PropertyGridGroup* pGroup,
const DString& propertyName,
const DString& propertyValue,
const DString& description = _T(""),
size_t nPropertyData = 0);
/** 增加一个属性(下拉框)
* @param [in] pGroup 该属性所属的分组
* @param [in] propertyName 属性的名称
* @param [in] propertyValue 属性的值
* @param [in] description 属性的描述信息
* @param [in] nPropertyData 用户自定义数据
* @return 返回该属性的接口
*/
PropertyGridComboProperty* AddComboProperty(PropertyGridGroup* pGroup,
const DString& propertyName,
const DString& propertyValue,
const DString& description = _T(""),
size_t nPropertyData = 0);
/** 增加一个属性(字体名称)
* @param [in] pGroup 该属性所属的分组
* @param [in] propertyName 属性的名称
* @param [in] propertyValue 属性的值(字体名称)
* @param [in] description 属性的描述信息
* @param [in] nPropertyData 用户自定义数据
* @return 返回该属性的接口
*/
PropertyGridFontProperty* AddFontProperty(PropertyGridGroup* pGroup,
const DString& propertyName,
const DString& propertyValue,
const DString& description = _T(""),
size_t nPropertyData = 0);
/** 增加一个属性(字体大小)
* @param [in] pGroup 该属性所属的分组
* @param [in] propertyName 属性的名称
* @param [in] propertyValue 属性的值(字体大小)
* @param [in] description 属性的描述信息
* @param [in] nPropertyData 用户自定义数据
* @return 返回该属性的接口
*/
PropertyGridFontSizeProperty* AddFontSizeProperty(PropertyGridGroup* pGroup,
const DString& propertyName,
const DString& propertyValue,
const DString& description = _T(""),
size_t nPropertyData = 0);
/** 增加一个属性(颜色)
* @param [in] pGroup 该属性所属的分组
* @param [in] propertyName 属性的名称
* @param [in] propertyValue 属性的值(字体大小)
* @param [in] description 属性的描述信息
* @param [in] nPropertyData 用户自定义数据
* @return 返回该属性的接口
*/
PropertyGridColorProperty* AddColorProperty(PropertyGridGroup* pGroup,
const DString& propertyName,
const DString& propertyValue,
const DString& description = _T(""),
size_t nPropertyData = 0);
/** 增加一个属性(日期时间)
* @param [in] pGroup 该属性所属的分组
* @param [in] propertyName 属性的名称
* @param [in] dateTimeValue 属性的值(日期时间值)
* @param [in] editFormat 日期的编辑格式
* @param [in] description 属性的描述信息
* @param [in] nPropertyData 用户自定义数据
* @return 返回该属性的接口
*/
PropertyGridDateTimeProperty* AddDateTimeProperty(PropertyGridGroup* pGroup,
const DString& propertyName,
const DString& dateTimeValue,
const DString& description = _T(""),
size_t nPropertyData = 0,
DateTime::EditFormat editFormat = DateTime::EditFormat::kDateCalendar);
/** 增加一个属性(IP地址)
* @param [in] pGroup 该属性所属的分组
* @param [in] propertyName 属性的名称
* @param [in] propertyValue 属性的值
* @param [in] description 属性的描述信息
* @param [in] nPropertyData 用户自定义数据
* @return 返回该属性的接口
*/
PropertyGridIPAddressProperty* AddIPAddressProperty(PropertyGridGroup* pGroup,
const DString& propertyName,
const DString& propertyValue,
const DString& description = _T(""),
size_t nPropertyData = 0);
/** 增加一个属性(热键)
* @param [in] pGroup 该属性所属的分组
* @param [in] propertyName 属性的名称
* @param [in] propertyValue 属性的值
* @param [in] description 属性的描述信息
* @param [in] nPropertyData 用户自定义数据
* @return 返回该属性的接口
*/
PropertyGridHotKeyProperty* AddHotKeyProperty(PropertyGridGroup* pGroup,
const DString& propertyName,
const DString& propertyValue,
const DString& description = _T(""),
size_t nPropertyData = 0);
/** 增加一个属性(文件路径)
* @param [in] pGroup 该属性所属的分组
* @param [in] propertyName 属性的名称
* @param [in] propertyValue 属性的值(文件路径)
* @param [in] description 属性的描述信息
* @param [in] nPropertyData 用户自定义数据
* @param [in] bOpenFileDialog true表示打开文件,false表示保存文件
* @param [in] fileTypes 对话框可以打开或保存的文件类型
* @param [in] nFileTypeIndex 选择的文件类型,有效范围:[0, fileTypes.size())
* @param [in] defaultExt 默认的文件类型, 举例:"doc;docx"
* @return 返回该属性的接口
*/
PropertyGridFileProperty* AddFileProperty(PropertyGridGroup* pGroup,
const DString& propertyName,
const DString& propertyValue,
const DString& description = _T(""),
size_t nPropertyData = 0,
bool bOpenFileDialog = true,
const std::vector<FileDialog::FileType>& fileTypes = std::vector<FileDialog::FileType>(),
int32_t nFileTypeIndex = -1,
const DString& defaultExt = _T(""));
/** 增加一个属性(文件夹)
* @param [in] pGroup 该属性所属的分组
* @param [in] propertyName 属性的名称
* @param [in] propertyValue 属性的值
* @param [in] description 属性的描述信息
* @param [in] nPropertyData 用户自定义数据
* @return 返回该属性的接口
*/
PropertyGridDirectoryProperty* AddDirectoryProperty(PropertyGridGroup* pGroup,
const DString& propertyName,
const DString& propertyValue,
const DString& description = _T(""),
size_t nPropertyData = 0);
/** 设置左侧一列的宽度
* @param [in] nLeftColumnWidth 左侧一列的宽度
* @param [in] bNeedDpiScale 是否需要对列宽值进行DPI自适应
*/
void SetLeftColumnWidth(int32_t nLeftColumnWidth, bool bNeedDpiScale);
/** 获取左侧一列的宽度值
*/
int32_t GetLeftColumnWidth() const;
public:
/** 设置是否显示描述区域
*/
void SetEnableDescriptionArea(bool bEnable);
/** 判断是否显示描述区域
*/
bool IsEnableDescriptionArea() const { return m_bDescriptionArea; }
/** 设置描述区域的高度值
* @param [in] nHeight 高度值
* @param [in] bNeedDpiScale 是否需要对列宽值进行DPI自适应
*/
void SetDescriptionAreaHeight(int32_t nHeight, bool bNeedDpiScale);
/** 获取当前描述区域的高度值
*/
int32_t GetDescriptionAreaHeight() const;
/** 获取描述控件的接口
*/
RichText* GetDescriptionArea() const { return m_pDescriptionArea; }
/** 描述控件的分割条接口
*/
Split* GetDescriptionAreaSplit() const { return m_pDescriptionAreaSplit; }
public:
/** 获取属性表的树控件接口(用于管理数据)
*/
TreeView* GetTreeView() const { return m_pTreeView; }
/** 横向网格线的宽度
* @param [in] nLineWidth 网格线的宽度,如果为0表示不显示横向网格线
* @param [in] bNeedDpiScale 如果为true表示需要对宽度进行DPI自适应
*/
void SetRowGridLineWidth(int32_t nLineWidth, bool bNeedDpiScale);
int32_t GetRowGridLineWidth() const;
/** 横向网格线的颜色
* @param [in] color 横向网格线的颜色
*/
void SetRowGridLineColor(const DString& color);
DString GetRowGridLineColor() const;
/** 纵向网格线的宽度
* @param [in] nLineWidth 网格线的宽度,如果为0表示不显示纵向网格线
* @param [in] bNeedDpiScale 如果为true表示需要对宽度进行DPI自适应
*/
void SetColumnGridLineWidth(int32_t nLineWidth, bool bNeedDpiScale);
int32_t GetColumnGridLineWidth() const;
/** 纵向网格线的颜色
* @param [in] color 纵向网格线的颜色
*/
void SetColumnGridLineColor(const DString& color);
DString GetColumnGridLineColor() const;
/** 表头的Class
*/
void SetHeaderClass(const DString& headerClass);
DString GetHeaderClass() const;
/** 分组的Class
*/
void SetGroupClass(const DString& groupClass);
DString GetGroupClass() const;
/** 属性的Class
*/
void SetPropertyClass(const DString& propertyClass);
DString GetPropertyClass() const;
protected:
/** 初始化函数
*/
virtual void OnInit() override;
/** 绘制子控件
*/
virtual void PaintChild(IRender* pRender, const UiRect& rcPaint) override;
/** 绘制网格线
*/
void PaintGridLines(IRender* pRender);
/** 拖动列表头改变列宽的事件响应函数
*/
void OnHeaderColumnResized();
/** 调整一个属性节点的列宽
*/
void ResizePropertyColumn(TreeNode* pPropertyNode, int32_t nLeftColumnWidth);
private:
/** 获取左侧列宽的值
*/
int32_t GetLeftColumnWidthValue() const;
private:
/** 配置XML文件
*/
UiString m_configXml;
private:
/** 是否显示Header
*/
bool m_bHeaderCtrl;
/** Header接口
*/
Control* m_pHeaderCtrl;
/** Header中的左侧一列
*/
Label* m_pHeaderLeft;
/** Header中的右侧一列
*/
Label* m_pHeaderRight;
/** Header中的分割条
*/
Split* m_pHeaderSplit;
/** 左侧一列的宽度
*/
int32_t m_nLeftColumnWidth;
private:
/** 描述控件的分割条
*/
Split* m_pDescriptionAreaSplit;
/** 描述控件
*/
RichText* m_pDescriptionArea;
/** 是否显示描述区域
*/
bool m_bDescriptionArea;
private:
/** 属性表的树控件接口
*/
TreeView* m_pTreeView;
/** 表头的Class
*/
UiString m_headerClass;
/** 分组的Class
*/
UiString m_groupClass;
/** 属性的Class
*/
UiString m_propertyClass;
private:
/** 横向网格线的宽度
*/
int32_t m_nRowGridLineWidth;
/** 横向网格线的颜色
*/
UiString m_rowGridLineColor;
/** 纵向网格线的宽度
*/
int32_t m_nColumnGridLineWidth;
/** 纵向网格线的颜色
*/
UiString m_columnGridLineColor;
};
/** 属性表的分组, 基本结构
* <PropertyGridGroup>
* <HBox>
* <LabelBox/>
* </HBox>
* </PropertyGridGroup>
*/
class PropertyGridGroup : public TreeNode
{
typedef TreeNode BaseClass;
public:
/** 构造一个组
* @param [in] groupName 组的名称
* @param [in] description 组的描述信息
* @param [in] nGroupData 用户自定义数据
*/
explicit PropertyGridGroup(Window* pWindow,
const DString& groupName,
const DString& description = _T(""),
size_t nGroupData = 0);
public:
/** 获取属性名称
*/
DString GetGroupName() const { return m_groupName.c_str(); }
/** 获取组的描述信息
*/
DString GetDescriptiion() const { return m_description.c_str(); }
/** 获取用户自定义数据
*/
size_t GetGroupData() const { return m_nGroupData; }
/** 设置用户自定义数据
*/
void SetGroupData(size_t nGroupData) { m_nGroupData = nGroupData; }
/** 获取属性名称的显示控件
*/
LabelBox* GetLabelBox() const { return m_pLabelBox; }
/** 获取分组下的所有属性
* @param [out] properties 返回当前所有的分组列表
*/
void GetProperties(std::vector<PropertyGridProperty*>& properties) const;
/** 删除该分组下的属性
* @param [in] pProperty 需要删除的属性接口
*/
bool RemoveProperty(PropertyGridProperty* pProperty);
/** 删除该分组下的所有属性
*/
void RemoveAllProperties();
protected:
/** 初始化函数
*/
virtual void OnInit() override;
private:
/** 分组的名称
*/
UiString m_groupName;
/** 组的描述信息
*/
UiString m_description;
/** 用户自定义数据
*/
size_t m_nGroupData;
/** 属性名称的显示控件
*/
LabelBox* m_pLabelBox;
};
/** 属性的类型
*/
enum class PropertyGridPropertyType
{
kNone, //无具体类型,基类
kText, //普通文本
kCombo, //下拉框
kFont, //字体名称
kFontSize, //字体大小
kColor, //颜色
kDateTime, //日期时间
kIPAddress, //IP地址
kHotKey, //热键
kFile, //文件路径
kDirectory, //文件夹
kCustom //用户自定义的类型,比如自己实现一个子类
};
/** 属性表的属性, 基本结构
* <PropertyGridProperty>
* <HBox>
* <LabelBox/>
* <LabelBox/>
* </HBox>
* </PropertyGridProperty>
*/
class PropertyGridProperty: public TreeNode
{
typedef TreeNode BaseClass;
public:
/** 构造一个属性
* @param [in] propertyName 属性的名称
* @param [in] propertyValue 属性的值
* @param [in] description 属性的描述信息
* @param [in] nPropertyData 用户自定义数据
*/
PropertyGridProperty(Window* pWindow,
const DString& propertyName,
const DString& propertyValue,
const DString& description = _T(""),
size_t nPropertyData = 0);
public:
/** 获取属性类型
*/
virtual PropertyGridPropertyType GetPropertyType() const
{
return PropertyGridPropertyType::kNone;
}
/** 获取属性名称
*/
DString GetPropertyName() const { return m_propertyName.c_str(); }
/** 获取属性值(原值)
*/
DString GetPropertyValue() const { return m_propertyValue.c_str(); }
/** 获取属性的描述信息
*/
DString GetDescriptiion() const { return m_description.c_str(); }
/** 获取用户自定义数据
*/
size_t GetPropertyData() const { return m_nPropertyData; }
/** 设置用户自定义数据
*/
void SetPropertyData(size_t nPropertyData) { m_nPropertyData = nPropertyData; }
/** 获取属性名称和属性值所在容器控件,可用于设置背景色等
*/
HBox* GetHBox() const { return m_pHBox; }
/** 获取属性名称的显示控件, 父控件是GetHBox()
*/
LabelBox* GetLabelBoxLeft() const { return m_pLabelBoxLeft; }
/** 获取属性值的显示控件, 父控件是GetHBox()
*/
LabelBox* GetLabelBoxRight() const { return m_pLabelBoxRight; }
/** 设置只读模式
*/
void SetReadOnly(bool bReadOnly);
/** 是否为只读模式
*/
bool IsReadOnly() const { return m_bReadOnly; }
/** 获取新的属性值(修改后的属性值, 如果无修改则返回原值)
*/
virtual DString GetPropertyNewValue() const;
protected:
/** 初始化函数
*/
virtual void OnInit() override;
/** 设置是否允许存在编辑框控件
* @param [in] bEnable true表示允许存在编辑框控件,false表示不允许存在编辑框控件
*/
virtual void EnableEditControl(bool /*bEnable*/) {}
/** 显示或者隐藏编辑框控件
* @param [in] bShow 表示显示编辑控件,false表示隐藏编辑控件
* @return 返回编辑控件的接口
*/
virtual Control* ShowEditControl(bool /*bShow*/) { return nullptr; }
/** 滚动条发生了滚动(用于处理弹出式子窗口的位置问题)
*/
virtual void OnScrollPosChanged() {}
/** 获取编辑控件的Margin.right(避免滚动条遮挡编辑控件)
*/
int32_t GetEditControlMarginRight() const;
protected:
/** 设置属性值的文本(显示控件)
* @param [in] text 文本内容
* @param [in] bChanged 是否标记为变化
*/
void SetPropertyText(const DString& text, bool bChanged);
/** 获取属性值文本(显示控件)
*/
DString GetPropertyText() const;
/** 设置属性值的文字颜色(显示控件)
* @param [in] text 文本内容
*/
void SetPropertyTextColor(const DString& textColor);
/** 将焦点设置到属性值文本显示控件
*/
void SetPropertyFocus();
/** 在属性值的LabelBox中添加控件
*/
bool AddPropertySubItem(Control* pControl);
/** 在属性值的LabelBox中移除控件
*/
bool RemovePropertySubItem(Control* pControl);
/** 判断属性值的LabelBox中是否包含控件
*/
bool HasPropertySubItem(Control* pControl) const;
private:
/** 属性的名称
*/
UiString m_propertyName;
/** 属性的值
*/
UiString m_propertyValue;
/** 属性的描述信息
*/
UiString m_description;
/** 用户自定义数据
*/
size_t m_nPropertyData;
/** 属性名称和属性值所在容器控件
*/
HBox* m_pHBox;
/** 属性名称的显示控件
*/
LabelBox* m_pLabelBoxLeft;
/** 属性值的显示控件
*/
LabelBox* m_pLabelBoxRight;
/** 只读模式
*/
bool m_bReadOnly;
};
/** 文本类型的属性:使用RichEdit编辑
*/
class PropertyGridTextProperty : public PropertyGridProperty
{
public:
/** 构造一个属性
* @param [in] propertyName 属性的名称
* @param [in] propertyValue 属性的值
* @param [in] description 属性的描述信息
* @param [in] nPropertyData 用户自定义数据
*/
PropertyGridTextProperty(Window* pWindow,
const DString& propertyName,
const DString& propertyValue,
const DString& description = _T(""),
size_t nPropertyData = 0);
public:
/** 获取属性类型
*/
virtual PropertyGridPropertyType GetPropertyType() const override
{
return PropertyGridPropertyType::kText;
}
/** 获取新的属性值(修改后的属性值, 如果无修改则返回原值)
*/
virtual DString GetPropertyNewValue() const override;
/** 获取编辑框控件
*/
RichEdit* GetRichEdit() const { return m_pRichEdit; }
/** 设置新的文本
* @param [in] newText 新的文本内容
*/
void SetNewTextValue(const DString& newText);
/** 设置密码模式(显示 ***)
* @param[in] bPasswordMode 设置为 true 让控件显示内容为 ***,false 为显示正常内容
*/
void SetPasswordMode(bool bPasswordMode);
/** 是否为密码模式
*/
bool IsPasswordMode() const { return m_bPasswordMode; }
/** 设置是否支持Spin控件
* @param [in] bEnable true表示支持Spin控件,false表示不支持Spin控件
* @param [in] nMin 表示设置数字的最小值
* @param [in] nMax 表示设置数字的最大值,如果 nMin和nMax同时为0, 表示不设置数字的最小值和最大值
*/
void SetEnableSpin(bool bEnable, int32_t nMin = 0, int32_t nMax = 0);
protected:
/** 设置是否允许存在编辑框控件
* @param [in] bEnable true表示允许存在编辑框控件,false表示不允许存在编辑框控件
*/
virtual void EnableEditControl(bool bEnable) override;
/** 显示或者隐藏编辑框控件
* @param [in] bShow 表示显示编辑控件,false表示隐藏编辑控件
*/
virtual Control* ShowEditControl(bool bShow) override;
private:
/** 编辑框控件(用于修改属性)
*/
RichEdit* m_pRichEdit;
/** 密码模式
*/
bool m_bPasswordMode;
};
/** 下拉框类型的属性:使用Combo编辑
*/
class PropertyGridComboProperty : public PropertyGridProperty
{
public:
/** 构造一个属性
* @param [in] propertyName 属性的名称
* @param [in] propertyValue 属性的值
* @param [in] description 属性的描述信息
* @param [in] nPropertyData 用户自定义数据
*/
PropertyGridComboProperty(Window* pWindow,
const DString& propertyName,
const DString& propertyValue,
const DString& description = _T(""),
size_t nPropertyData = 0);
public:
/** 获取属性类型
*/
virtual PropertyGridPropertyType GetPropertyType() const override
{
return PropertyGridPropertyType::kCombo;
}
/** 获取新的属性值(修改后的属性值, 如果无修改则返回原值)
*/
virtual DString GetPropertyNewValue() const override;
/** 增加一个下拉框选项
* @param [in] optionText 下拉框列表项的内容
* @return 返回该子项的下标值
*/
size_t AddOption(const DString& optionText);
/** 获取下拉框选项的格式
*/
size_t GetOptionCount() const;
/** 获取下拉表子项的文本
* @param [in] nIndex 子项的下标值,有效范围:[0, GetOptionCount())
*/
DString GetOption(size_t nIndex) const;
/** 设置子项关联的数据
* @param [in] nIndex 子项的下标值,有效范围:[0, GetOptionCount())
* @param [in] nOptionData 关联数据
*/
void SetOptionData(size_t nIndex, size_t nOptionData);
/** 获取子项关联的数据
* @param [in] nIndex 子项的下标值,有效范围:[0, GetOptionCount())
*/
size_t GetOptionData(size_t nIndex) const;
/** 删除指定的子项
* @param [in] nIndex 子项的下标值,有效范围:[0, GetOptionCount())
*/
bool RemoveOption(size_t nIndex);
/** 删除所有子项
*/
void RemoveAllOptions();
/** 获取当前选择项索引
* @return 返回当前选择项索引, (如果无有效索引,则返回Box::InvalidIndex)
*/
size_t GetCurSel() const;
/** 选择一个子项, 不触发选择事件
* @param[in] nIndex 要选择的子项索引,有效范围:[0, GetOptionCount())
* @return 返回 true 表示成功,否则为 false
*/
bool SetCurSel(size_t nIndex);
/** 设置为列表模式
* @param [in] bListMode true表示不支持编辑文本,只能从下拉表中选择;false表示允许编辑,允许选择
*/
void SetComboListMode(bool bListMode);
/** 获取下拉框接口
*/
Combo* GetCombo() const { return m_pCombo; }
protected:
/** 设置是否允许存在编辑框控件
* @param [in] bEnable true表示允许存在编辑框控件,false表示不允许存在编辑框控件
*/
virtual void EnableEditControl(bool bEnable) override;
/** 显示或者隐藏编辑框控件
* @param [in] bShow 表示显示编辑控件,false表示隐藏编辑控件
*/
virtual Control* ShowEditControl(bool bShow) override;
/** 滚动条发生了滚动(用于处理弹出式子窗口的位置问题)
*/
virtual void OnScrollPosChanged() override;
private:
/** 下拉框接口
*/
Combo* m_pCombo;
};
/** 设置字体名称的属性
*/
class PropertyGridFontProperty : public PropertyGridComboProperty
{
typedef PropertyGridComboProperty BaseClass;
public:
/** 构造一个属性
* @param [in] propertyName 属性的名称
* @param [in] propertyValue 属性的值(原字体名称)
* @param [in] description 属性的描述信息
* @param [in] nPropertyData 用户自定义数据
*/
PropertyGridFontProperty(Window* pWindow,
const DString& propertyName,
const DString& propertyValue,
const DString& description = _T(""),
size_t nPropertyData = 0);
public:
/** 获取属性类型
*/
virtual PropertyGridPropertyType GetPropertyType() const override
{
return PropertyGridPropertyType::kFont;
}
/** 获取新的字体值(修改后的属性值, 如果无修改则返回原值)
*/
virtual DString GetPropertyNewValue() const override;
protected:
/** 初始化函数
*/
virtual void OnInit() override;
};
/** 设置字体大小的属性
*/
class PropertyGridFontSizeProperty : public PropertyGridComboProperty
{
typedef PropertyGridComboProperty BaseClass;
public:
/** 构造一个属性
* @param [in] propertyName 属性的名称
* @param [in] propertyValue 属性的值(原字体名称)
* @param [in] description 属性的描述信息
* @param [in] nPropertyData 用户自定义数据
*/
PropertyGridFontSizeProperty(Window* pWindow,
const DString& propertyName,
const DString& propertyValue,
const DString& description = _T(""),
size_t nPropertyData = 0);
public:
/** 获取属性类型
*/
virtual PropertyGridPropertyType GetPropertyType() const override
{
return PropertyGridPropertyType::kFontSize;
}
/** 获取新的字体大小值, 显示值(修改后的属性值, 如果无修改则返回原值)
*/
virtual DString GetPropertyNewValue() const override;
/** 获取字体大小值,浮点数,未做DPI自适应值
* @return 如果从列表中选择,返回值为非空;如果未能从列表中选择,则返回空
*/
DString GetFontSize() const;
/** 获取字体大小值,浮点数,已做DPI自适应值
* @return 如果从列表中选择,返回值为非空;如果未能从列表中选择,则返回空
*/
DString GetDpiFontSize() const;
/** 获取字体大小显示名称对应的字体大小值,浮点数,未做DPI自适应值
* @param [in] fontSizeName 比如:"五号"
*/
DString GetFontSize(const DString& fontSizeName) const;
/** 获取字体大小显示名称对应的字体大小值,浮点数,已做DPI自适应值
* @param [in] fontSizeName 比如:"五号"
*/
DString GetDpiFontSize(const DString& fontSizeName) const;
protected:
/** 初始化函数
*/
virtual void OnInit() override;
private:
/** 字体大小
*/
std::vector<FontSizeInfo> m_fontSizeList;
};
/** 设置颜色的属性
*/
class PropertyGridColorProperty : public PropertyGridProperty
{
public:
/** 构造一个属性
* @param [in] propertyName 属性的名称
* @param [in] propertyValue 属性的值(原字体名称)
* @param [in] description 属性的描述信息
* @param [in] nPropertyData 用户自定义数据
*/