This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
CustomCheckedComboBoxEdit.cs
200 lines (167 loc) · 7.79 KB
/
CustomCheckedComboBoxEdit.cs
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
using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.XtraEditors.Registrator;
using System.ComponentModel;
using DevExpress.XtraEditors.ViewInfo;
using DevExpress.XtraEditors.Drawing;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.Controls;
namespace CustomCheckedComboBox
{
[UserRepositoryItem("RegisterCustomCheckedComboBoxEdit")]
public class RepositoryItemCustomCheckedComboBoxEdit : RepositoryItemCheckedComboBoxEdit
{
static RepositoryItemCustomCheckedComboBoxEdit() { RegisterCustomCheckedComboBoxEdit(); }
public RepositoryItemCustomCheckedComboBoxEdit() { }
public const string CustomCheckedComboBoxEditName = "CustomCheckedComboBoxEdit";
public override string EditorTypeName { get { return CustomCheckedComboBoxEditName; } }
public static void RegisterCustomCheckedComboBoxEdit()
{
EditorRegistrationInfo.Default.Editors.Add(new EditorClassInfo(CustomCheckedComboBoxEditName,
typeof(CustomCheckedComboBoxEdit), typeof(RepositoryItemCustomCheckedComboBoxEdit),
typeof(PopupContainerEditViewInfo), new ButtonEditPainter(), true));
}
public override void Assign(RepositoryItem item)
{
base.Assign(item);
RepositoryItemCustomCheckedComboBoxEdit source = item as RepositoryItemCustomCheckedComboBoxEdit;
Events.AddHandler(_convertCheckStateToEditValue, source.Events[_convertCheckStateToEditValue]);
Events.AddHandler(_convertEditValueToCheckState, source.Events[_convertEditValueToCheckState]);
}
static readonly object _convertCheckStateToEditValue = new object();
protected override void PreQueryResultValue(QueryResultValueEventArgs e)
{
if (CanRaiseConvertCheckStateToEditValue)
{
ConvertCheckStateToEditValueEventArgs ea = new ConvertCheckStateToEditValueEventArgs(Items.Count);
for (int i = 0; i < Items.Count; i++)
if (Items[i].CheckState == System.Windows.Forms.CheckState.Checked)
ea.CheckedState[i] = Items[i].Enabled;
RaiseConvertCheckStateToEditValue(ea);
e.Value = ea.EditValue;
}
}
protected internal virtual string makeNormalValue(bool[] chekers)
{
string res = "";
if (chekers != null)
{
for (int i = 0; i < chekers.Length; i++)
if (chekers[i]) res = res + Items[i].Value as string + SeparatorChar + " ";
}
if (res.Length > 2) res = res.Substring(0, res.Length - 2);
return res;
}
protected override void PreQueryDisplayText(QueryDisplayTextEventArgs e)
{
if (CanRaiseConvertEditValueToCheckState && e.EditValue != null)
{
ConvertEditValueToCheckStateEventArgs ea = new ConvertEditValueToCheckStateEventArgs(e.EditValue as string, Items.Count);
RaiseConvertEditValueToCheckState(ea);
e.DisplayText = makeNormalValue(ea.CheckedState);
}
base.PreQueryDisplayText(e);
}
public event ConvertCheckStateToEditValueEventHandler ConvertCheckStateToEditValue
{
add { this.Events.AddHandler(_convertCheckStateToEditValue, value); }
remove { this.Events.RemoveHandler(_convertCheckStateToEditValue, value); }
}
protected internal virtual void RaiseConvertCheckStateToEditValue(ConvertCheckStateToEditValueEventArgs e)
{
ConvertCheckStateToEditValueEventHandler handler = (ConvertCheckStateToEditValueEventHandler)Events[_convertCheckStateToEditValue];
if (handler != null) handler(GetEventSender(), e);
}
internal bool CanRaiseConvertCheckStateToEditValue { get { return (ConvertCheckStateToEditValueEventHandler)Events[_convertCheckStateToEditValue] != null; } }
static readonly object _convertEditValueToCheckState = new object();
public event ConvertEditValueToCheckStateEventHandler ConvertEditValueToCheckState
{
add { this.Events.AddHandler(_convertEditValueToCheckState, value); }
remove { this.Events.RemoveHandler(_convertEditValueToCheckState, value); }
}
protected internal virtual void RaiseConvertEditValueToCheckState(ConvertEditValueToCheckStateEventArgs e)
{
ConvertEditValueToCheckStateEventHandler handler = (ConvertEditValueToCheckStateEventHandler)Events[_convertEditValueToCheckState];
if (handler != null) handler(GetEventSender(), e);
}
internal bool CanRaiseConvertEditValueToCheckState { get { return (ConvertEditValueToCheckStateEventHandler)Events[_convertEditValueToCheckState] != null; } }
}
public delegate void ConvertCheckStateToEditValueEventHandler(Object sender, ConvertCheckStateToEditValueEventArgs e);
public class ConvertCheckStateToEditValueEventArgs : EventArgs
{
string editValue;
bool[] checkedState;
public ConvertCheckStateToEditValueEventArgs(int count)
{
this.checkedState = new bool[count];
}
public string EditValue
{
get { return editValue; }
set { editValue = value; }
}
public bool[] CheckedState
{
get { return checkedState; }
set { checkedState = value; }
}
}
public delegate void ConvertEditValueToCheckStateEventHandler(Object sender, ConvertEditValueToCheckStateEventArgs e);
public class ConvertEditValueToCheckStateEventArgs : EventArgs
{
string editValue;
bool[] checkedState;
public ConvertEditValueToCheckStateEventArgs(string value, int count)
{
this.editValue = value;
this.checkedState = new bool[count];
}
public string EditValue
{
get { return editValue; }
set { editValue = value; }
}
public bool[] CheckedState
{
get { return checkedState; }
set { checkedState = value; }
}
}
public class CustomCheckedComboBoxEdit : CheckedComboBoxEdit
{
static CustomCheckedComboBoxEdit() { RepositoryItemCustomCheckedComboBoxEdit.RegisterCustomCheckedComboBoxEdit(); }
public CustomCheckedComboBoxEdit() : base() { isShowPopup = false; }
public override string EditorTypeName { get { return RepositoryItemCustomCheckedComboBoxEdit.CustomCheckedComboBoxEditName; } }
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public new RepositoryItemCustomCheckedComboBoxEdit Properties { get { return base.Properties as RepositoryItemCustomCheckedComboBoxEdit; } }
bool isShowPopup;
public override object EditValue
{
get
{
if (!isShowPopup) return base.EditValue;
if (Properties.CanRaiseConvertEditValueToCheckState && base.EditValue != null)
{
ConvertEditValueToCheckStateEventArgs e = new ConvertEditValueToCheckStateEventArgs(base.EditValue as string, Properties.Items.Count );
Properties.RaiseConvertEditValueToCheckState(e);
return Properties.makeNormalValue(e.CheckedState);
}
else
return base.EditValue;
}
set
{
base.EditValue = value;
}
}
protected override void DoShowPopup()
{
isShowPopup = true;
base.DoShowPopup();
isShowPopup = false;
PopupForm.OldEditValue = EditValue;
}
}
}