-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomProfileListBox.cs
429 lines (397 loc) · 14.5 KB
/
CustomProfileListBox.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
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
// Type: Intel.Mobile.WiMAXCU.UI.Dashboard.CustomProfileListBox
// Assembly: WiMAXCU, Version=6.2.4357.25644, Culture=neutral, PublicKeyToken=null
// MVID: 3C622363-C72C-43B7-9311-DD8942A58F18
// Assembly location: E:\Extracted\program files\Intel\WiMAX\Bin\WiMAXCU.exe
using Intel.Mobile.WiMAXCU.Common;
using Intel.Mobile.WiMAXCU.SDKInterop;
using Intel.Mobile.WiMAXCU.UI.CustomControls;
using Intel.Mobile.WiMAXCU.UI.DisplayWiMAX;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
namespace Intel.Mobile.WiMAXCU.UI.Dashboard
{
public class CustomProfileListBox : ListBox
{
private ToolTip _tooltip = new ToolTip();
private int _tooltip_DisplayedForIndex = -1;
private const int STARTX = 0;
private const int STARTY = 3;
private const int SINGLE_LINE_HEIGHT = 36;
private const int HEADER_HEIGHT = 24;
private bool _hasFocus;
private ProfileSelectedDelegate _profileSelectedCallback;
private ProperitesDelegate _properitesCallback;
private SetAsDefaultDelegate _setAsDefaultCallback;
private EnableProperitesDelegate _enableProperitesCallback;
private EnableSetAsDefaultDelegate _enableSetAsDefaultCallback;
public ProfileSelectedDelegate ProfileSelectedCallback
{
get
{
return this._profileSelectedCallback;
}
set
{
this._profileSelectedCallback = value;
}
}
public ProperitesDelegate ProperitesCallback
{
get
{
return this._properitesCallback;
}
set
{
this._properitesCallback = value;
}
}
public SetAsDefaultDelegate SetAsDefaultCallback
{
get
{
return this._setAsDefaultCallback;
}
set
{
this._setAsDefaultCallback = value;
}
}
public EnableProperitesDelegate EnableProperitesCallback
{
get
{
return this._enableProperitesCallback;
}
set
{
this._enableProperitesCallback = value;
}
}
public EnableSetAsDefaultDelegate EnableSetAsDefaultCallback
{
get
{
return this._enableSetAsDefaultCallback;
}
set
{
this._enableSetAsDefaultCallback = value;
}
}
public CustomProfileListBox()
{
this.DrawMode = DrawMode.OwnerDrawVariable;
this.BorderStyle = BorderStyle.None;
this.DrawItem += new DrawItemEventHandler(this.DrawItemHandler);
this.MeasureItem += new MeasureItemEventHandler(this.MeasureItemHandler);
this.SelectedIndexChanged += new EventHandler(this.OnSelectedIndexChanged);
this.MouseDown += new MouseEventHandler(this.OnMouseDown);
this.MouseMove += new MouseEventHandler(this.OnMouseMove);
this.Leave += new EventHandler(this.OnLostFocus);
this.Enter += new EventHandler(this.OnGotFocus);
this.DoubleClick += new EventHandler(this.OnItemDoubleClicked);
this.SelectionMode = SelectionMode.One;
this._tooltip.ShowAlways = true;
}
protected override void OnMouseDown(MouseEventArgs e)
{
if (this.IgnoreMouseEvent(e.X, e.Y))
return;
base.OnMouseDown(e);
}
protected override void OnMouseUp(MouseEventArgs e)
{
if (this.IgnoreMouseEvent(e.X, e.Y))
return;
base.OnMouseUp(e);
}
protected override void OnClick(EventArgs e)
{
Point point = this.PointToClient(Cursor.Position);
if (this.IgnoreMouseEvent(point.X, point.Y))
return;
base.OnClick(e);
}
protected override void OnDoubleClick(EventArgs e)
{
Point point = this.PointToClient(Cursor.Position);
if (this.IgnoreMouseEvent(point.X, point.Y))
return;
base.OnDoubleClick(e);
}
private void OnItemDoubleClicked(object sender, EventArgs e)
{
if (this._setAsDefaultCallback == null)
return;
this._setAsDefaultCallback();
}
private void OnSelectedIndexChanged(object sender, EventArgs e)
{
this.Invalidate();
if (this._profileSelectedCallback == null)
return;
this._profileSelectedCallback();
}
private void ContextMenu_SetAsPreferred_Click(object sender, EventArgs e)
{
if (this._setAsDefaultCallback == null)
return;
this._setAsDefaultCallback();
}
private void ContextMenu_Properites_Click(object sender, EventArgs e)
{
if (this._properitesCallback == null)
return;
this._properitesCallback();
}
private void OnGotFocus(object sender, EventArgs e)
{
this._hasFocus = true;
this.Invalidate();
}
private void OnLostFocus(object sender, EventArgs e)
{
this._hasFocus = false;
this.Invalidate();
}
private void OnMouseDown(object sender, MouseEventArgs e)
{
if (this.Items.Count <= 0 || e.Button != MouseButtons.Right)
return;
int num1 = this.IndexFromPoint(e.X, e.Y);
if (num1 == -1)
return;
int num2 = 0;
for (int topIndex = this.TopIndex; topIndex < this.Items.Count; ++topIndex)
num2 += base.GetItemHeight(topIndex);
if (e.Y > num2)
return;
this.SelectedIndex = num1;
this.ShowContextMenu(new Point(e.X, e.Y));
}
private void OnMouseMove(object sender, MouseEventArgs e)
{
string str = string.Empty;
if (this.Items.Count <= 0)
return;
int iItem = this.IndexFromPoint(e.X, e.Y);
if (iItem == -1)
return;
int num1 = this.ItemViewportY(iItem);
List<NDIAvailNetworkListboxColumn> list = this.SetupColumns((ProfileDisplayItem) this.Items[iItem]);
int num2 = 0;
int num3 = 3;
for (int index1 = 0; index1 < list.Count; ++index1)
{
NDIAvailNetworkListboxColumn networkListboxColumn = list[index1];
int[] iconXpositions = this.GetIconXPositions(networkListboxColumn.Items, networkListboxColumn.ColWidth);
for (int index2 = 0; index2 < networkListboxColumn.Items.Count; ++index2)
{
if (networkListboxColumn.Items[index2] is NDIAvailNetworkListboxColumnIcon)
{
NDIAvailNetworkListboxColumnIcon listboxColumnIcon = (NDIAvailNetworkListboxColumnIcon) networkListboxColumn.Items[index2];
if (new Rectangle(new Point(num2 + iconXpositions[index2], num3 + num1), new Size(listboxColumnIcon.Icon.Width, listboxColumnIcon.Icon.Height)).Contains(new Point(e.X, e.Y)) && listboxColumnIcon.Visible)
{
str = listboxColumnIcon.IconTooltip;
break;
}
}
}
num2 += networkListboxColumn.ColWidth;
}
if (this._tooltip.GetToolTip((Control) this).CompareTo(str) != 0 || iItem != this._tooltip_DisplayedForIndex)
{
if (string.IsNullOrEmpty(str))
this._tooltip.RemoveAll();
else
this._tooltip.SetToolTip((Control) this, str);
}
this._tooltip_DisplayedForIndex = iItem;
}
private bool IgnoreMouseEvent(int x, int y)
{
return this.Items.Count <= 0 || this.IndexFromPoint(x, y) == -1 || y > this.ItemViewportY(this.Items.Count);
}
private void DrawItemHandler(object sender, DrawItemEventArgs e)
{
if (this.Items == null || this.Items.Count <= 0 || (e == null || e.Index < 0))
return;
int num1 = e.Bounds.Y + 4;
int num2 = 0;
ProfileDisplayItem pdi = (ProfileDisplayItem) this.Items[e.Index];
int itemHeight = this.GetItemHeight();
if (this.SelectedIndex == e.Index)
{
if (e.Index != 0)
{
using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(81, 149, 217)))
e.Graphics.FillRectangle((Brush) solidBrush, e.Bounds.X + 1, e.Bounds.Y + 2 + num2, this.Width - 2, itemHeight - 3 - num2);
if (this._hasFocus)
ControlPaint.DrawFocusRectangle(e.Graphics, new Rectangle(e.Bounds.X + 1, e.Bounds.Y + 2 + num2, this.Width - 2, itemHeight - 3 - num2));
}
else
{
int num3 = 1;
using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(81, 149, 217)))
e.Graphics.FillRectangle((Brush) solidBrush, e.Bounds.X + 1, e.Bounds.Y + num3 + num2, this.Width - 2, itemHeight - (num3 + 1) - num2);
if (this._hasFocus)
ControlPaint.DrawFocusRectangle(e.Graphics, new Rectangle(e.Bounds.X + 1, e.Bounds.Y + num3 + num2, this.Width - 2, itemHeight - (num3 + 1) - num2));
}
}
if (e.Index > 0)
{
using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(204, 204, 204)))
e.Graphics.FillRectangle((Brush) solidBrush, e.Bounds.X, e.Bounds.Y + num2, this.Width, 1);
}
List<NDIAvailNetworkListboxColumn> list = this.SetupColumns(pdi);
int xPos = 0;
int yPos = num1 + 3;
foreach (NDIAvailNetworkListboxColumn column in list)
{
this.DrawColumn(column, xPos, yPos, e);
xPos += column.ColWidth;
}
}
private List<NDIAvailNetworkListboxColumn> SetupColumns(ProfileDisplayItem pdi)
{
List<NDIAvailNetworkListboxColumn> list = new List<NDIAvailNetworkListboxColumn>();
List<ListBoxHeaderData> listboxHeaderData = ProfileListBox.GetListboxHeaderData();
list.Add(new NDIAvailNetworkListboxColumn()
{
ColWidth = listboxHeaderData[0].Width,
Items = {
(NDIAvailNetworkListboxColumnItem) new NDIAvailNetworkListboxColumnIcon()
{
Icon = WiMAXDisplayService.Singleton.GetPreferredIcon(),
IconTooltip = WiMAXDisplayService.Singleton.GetPreferredIconTooltip(),
Visible = pdi.Preferred
},
(NDIAvailNetworkListboxColumnItem) new NDIAvailNetworkListboxColumnIcon()
{
Icon = WiMAXDisplayService.Singleton.GetHomeIcon(),
IconTooltip = WiMAXDisplayService.Singleton.GetHomeIconTooltip(),
Visible = WiMAXDisplayService.IsHomeNetwork(pdi.TheProfile.profileId)
}
}
});
list.Add(new NDIAvailNetworkListboxColumn()
{
ColWidth = listboxHeaderData[1].Width,
Items = {
(NDIAvailNetworkListboxColumnItem) new NDIAvailNetworkListboxColumnText()
{
Text = MiscUtilities.ParseProfileName(pdi.TheProfile.profileName)
}
}
});
return list;
}
private void DrawColumn(NDIAvailNetworkListboxColumn column, int xPos, int yPos, DrawItemEventArgs e)
{
int[] iconXpositions = this.GetIconXPositions(column.Items, column.ColWidth);
for (int index = 0; index < column.Items.Count; ++index)
{
if (column.Items[index] is NDIAvailNetworkListboxColumnIcon)
this.DrawIcon((NDIAvailNetworkListboxColumnIcon) column.Items[index], xPos + iconXpositions[index], yPos, e);
else if (column.Items[index] is NDIAvailNetworkListboxColumnText)
this.DrawText((NDIAvailNetworkListboxColumnText) column.Items[index], xPos, yPos, column.ColWidth, e);
}
}
private int[] GetIconXPositions(List<NDIAvailNetworkListboxColumnItem> items, int colWidth)
{
int num1 = 8;
int[] numArray = new int[items.Count];
int num2 = 0;
for (int index = 0; index < items.Count; ++index)
{
if (!(items[index] is NDIAvailNetworkListboxColumnIcon))
return new int[0];
numArray[index] = num2;
num2 += ((NDIAvailNetworkListboxColumnIcon) items[index]).Icon.Width;
}
int num3 = num2 + (items.Count - 1) * num1;
int num4 = (colWidth - num3) / 2;
for (int index = 0; index < items.Count; ++index)
{
numArray[index] += num4;
if (index > 0)
numArray[index] += num1;
}
return numArray;
}
private void DrawIcon(NDIAvailNetworkListboxColumnIcon iconItem, int xPos, int yPos, DrawItemEventArgs e)
{
if (!iconItem.Visible)
return;
Point[] destPoints = new Point[3]
{
new Point(xPos, yPos),
new Point(xPos + iconItem.Icon.Width, yPos),
new Point(xPos, yPos + iconItem.Icon.Height)
};
e.Graphics.DrawImage((Image) iconItem.Icon, destPoints);
}
private void DrawText(NDIAvailNetworkListboxColumnText textItem, int xPos, int yPos, int colWidth, DrawItemEventArgs e)
{
string text = textItem.Text;
Color color = Color.Black;
if (!this.Enabled)
color = SystemColors.GrayText;
if (text == null)
return;
string s = text.Trim();
using (SolidBrush solidBrush = new SolidBrush(color))
e.Graphics.DrawString(s, this.Font, (Brush) solidBrush, (float) xPos, (float) yPos);
}
private void MeasureItemHandler(object sender, MeasureItemEventArgs e)
{
e.ItemHeight = this.GetItemHeight();
}
private int ItemViewportY(int iItem)
{
int num = 0;
using (this.CreateGraphics())
{
for (int topIndex = this.TopIndex; topIndex < iItem; ++topIndex)
num += this.GetItemHeight();
}
return num;
}
private int GetItemHeight()
{
return DPIUtils.ScaleY(36);
}
public void SetDataSource(List<ProfileDisplayItem> profileList)
{
this.SelectedIndexChanged -= new EventHandler(this.OnSelectedIndexChanged);
this.Items.Clear();
for (int index = 0; index < profileList.Count; ++index)
this.Items.Add((object) profileList[index]);
if (this.Items.Count > 0)
this.SelectedIndex = 0;
this.Invalidate();
this.SelectedIndexChanged += new EventHandler(this.OnSelectedIndexChanged);
}
private void ShowContextMenu(Point p)
{
ContextMenu contextMenu = new ContextMenu();
MenuItem menuItem = new MenuItem();
menuItem.Text = ManageNetworksDlgStringHelper.GetString("ManageNetworksPanel_SetAsPreferredBtn");
menuItem.Click += new EventHandler(this.ContextMenu_SetAsPreferred_Click);
menuItem.Enabled = this._enableSetAsDefaultCallback();
contextMenu.MenuItems.Add(menuItem);
try
{
contextMenu.Show((Control) this, p);
}
catch (Exception ex)
{
Logging.LogEvent(TraceModule.SDK, TraceLevel.Warning, (object) this, Logging.GetMessageForException(ex));
}
}
}
}