This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomMenuManager.cs
109 lines (94 loc) · 3.2 KB
/
CustomMenuManager.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
using System;
using System.Drawing;
using DevExpress.XtraBars;
using System.Windows.Forms;
using DevExpress.Utils.Menu;
using DevExpress.XtraEditors;
using System.Collections.Generic;
namespace CustomFilterControlPopupMenu {
public class CustomMenuManager :IDXMenuManager {
BarManager Manager;
public CustomMenuManager(BarManager manager) {
this.Manager = manager;
}
PopupControlContainer fPopup;
PopupControlContainer Popup {
get {
if (fPopup == null) {
fPopup = new PopupControlContainer();
fPopup.Manager = Manager;
fPopup.CloseUp += OnPopupCloseUp;
}
return fPopup;
}
}
ListBoxControl fListBox;
ListBoxControl ListBox {
get {
if (fListBox == null) {
fListBox = new ListBoxControl();
fListBox.Dock = DockStyle.Fill;
fListBox.Parent = Popup;
fListBox.MouseClick += OnItemClick;
fListBox.KeyDown += OnListBoxKeyDown;
fListBox.IncrementalSearch = true;
}
return fListBox;
}
}
void OnItemClick(object sender, EventArgs e) {
((DXMenuItemWrapper)ListBox.SelectedItem).DoClick();
Popup.HidePopup();
}
void OnPopupCloseUp(object sender, EventArgs e) {
foreach (IDisposable d in ListBox.Items)
d.Dispose();
ListBox.Items.Clear();
}
void OnListBoxKeyDown(object sender, KeyEventArgs e) {
if (e.KeyCode == Keys.Enter)
OnItemClick(fListBox, EventArgs.Empty);
}
class DXMenuItemWrapper :IDisposable {
DXMenuItem Item;
public DXMenuItemWrapper(DXMenuItem item) {
this.Item = item;
}
public override string ToString() {
return Item.Caption;
}
public void DoClick() {
Item.GenerateClickEvent();
}
#region IDisposable
void IDisposable.Dispose() {
Item = null;
GC.SuppressFinalize(this);
}
#endregion
}
#region IDXMenuManager
IDXMenuManager IDXMenuManager.Clone(Form newForm) {
return this;
}
void IDXMenuManager.DisposeManager() {
fPopup.Dispose();
Manager = null;
}
void IDXMenuManager.ShowPopupMenu(DXPopupMenu menu, Control control, Point pos) {
if (menu.Tag == null)
new DXPopupStandardOwnerDrawMenu(new DXMenuItemPainter(), menu).Show(
control, pos);
else {
ListBox.BeginUpdate();
try {
foreach (DXMenuItem i in menu.Items)
ListBox.Items.Add(new DXMenuItemWrapper(i));
} finally { ListBox.EndUpdate(); }
Popup.ShowPopup(control.PointToScreen(pos));
ListBox.Focus();
}
}
#endregion
}
}