-
Notifications
You must be signed in to change notification settings - Fork 63
/
KryptonComboBox.cs
3180 lines (2782 loc) · 125 KB
/
KryptonComboBox.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
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
// *****************************************************************************
// BSD 3-Clause License (https://github.com/ComponentFactory/Krypton/blob/master/LICENSE)
// © Component Factory Pty Ltd, 2006 - 2016, All rights reserved.
// The software and associated documentation supplied hereunder are the
// proprietary information of Component Factory Pty Ltd, 13 Swallows Close,
// Mornington, Vic 3931, Australia and are supplied subject to license terms.
//
// Modifications by MegaKraken, Peter Wagner(aka Wagnerp) & Simon Coghlan(aka Smurf-IV) 2017 - 2020. All rights reserved. (https://github.com/Wagnerp/Krypton-Toolkit-Suite-NET-Core)
// Version 5.500.0.0 www.ComponentFactory.com
// *****************************************************************************
using Microsoft.Win32;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace ComponentFactory.Krypton.Toolkit
{
/// <summary>
/// Provide a ComboBox with Krypton styling applied.
/// </summary>
[ToolboxItem(true)]
[ToolboxBitmap(typeof(KryptonComboBox), "ToolboxBitmaps.KryptonComboBox.bmp")]
[DefaultEvent("SelectedIndexChanged")]
[DefaultProperty("Text")]
[DefaultBindingProperty("Text")]
[LookupBindingProperties("DataSource", "DisplayMember", "ValueMember", "SelectedValue")]
[Designer(typeof(KryptonComboBoxDesigner))]
[DesignerCategory("code")]
[Description("Displays an editable textbox with a drop-down list of permitted values.")]
public class KryptonComboBox : VisualControlBase,
IContainedInputControl,
ISupportInitializeNotification
{
#region Classes
private class InternalPanel : Panel
{
#region Instance Fields
private readonly KryptonComboBox _kryptonComboBox;
#endregion
#region Identity
/// <summary>
/// Initialise a new instance of the InternalPanel class.
/// </summary>
/// <param name="kryptonComboBox">Reference to owning control.</param>
public InternalPanel(KryptonComboBox kryptonComboBox)
{
_kryptonComboBox = kryptonComboBox;
}
#endregion
#region Public
/// <summary>
/// Retrieves the size of a rectangular area into which a control can be fitted.
/// </summary>
public override Size GetPreferredSize(Size proposedSize)
{
Size maxSize = Size.Empty;
// Find the largest size of any child control
foreach (Control c in Controls)
{
Size cSize = c.GetPreferredSize(proposedSize);
maxSize.Width = Math.Max(maxSize.Width, cSize.Width);
maxSize.Height = Math.Max(maxSize.Height, cSize.Height);
}
// The panel needs to be 2 above and 2 below bigger than the height of an item
return new Size(maxSize.Width - 3, _kryptonComboBox._comboBox.ItemHeight + 4);
}
#endregion
#region Protected
/// <summary>
/// Process Windows-based messages.
/// </summary>
/// <param name="m">A Windows-based message.</param>
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case PI.WM_.NCHITTEST:
if (_kryptonComboBox.InTransparentDesignMode)
{
m.Result = (IntPtr)PI.HT.TRANSPARENT;
}
else
{
base.WndProc(ref m);
}
break;
default:
base.WndProc(ref m);
break;
}
}
#endregion
}
private class InternalComboBox : ComboBox, IContentValues
{
#region Instance Fields
private readonly KryptonComboBox _kryptonComboBox;
private PaletteTripleToPalette _palette;
private ViewDrawButton _viewButton;
private Nullable<bool> _appThemed;
private bool _mouseTracking;
private bool _mouseOver;
#endregion
#region Events
/// <summary>
/// Occurs when the mouse enters the InternalComboBox.
/// </summary>
public event EventHandler TrackMouseEnter;
/// <summary>
/// Occurs when the mouse leaves the InternalComboBox.
/// </summary>
public event EventHandler TrackMouseLeave;
#endregion
#region Identity
/// <summary>
/// Initialize a new instance of the InternalComboBox class.
/// </summary>
/// <param name="kryptonComboBox">Reference to owning control.</param>
public InternalComboBox(KryptonComboBox kryptonComboBox)
{
// Remember incoming reference
_kryptonComboBox = kryptonComboBox;
// Remove from view until size for the first time by the Krypton control
ItemHeight = 15;
DropDownHeight = 200;
DrawMode = DrawMode.OwnerDrawVariable;
}
#endregion
#region Public
/// <summary>
/// Gets and sets if the combo box is currently dropped.
/// </summary>
public bool Dropped { get; set; }
/// <summary>
/// Gets and sets if the mouse is currently over the combo box.
/// </summary>
public bool MouseOver
{
get => _mouseOver;
set
{
// Only interested in changes
if (_mouseOver != value)
{
_mouseOver = value;
// Generate appropriate change event
if (_mouseOver)
{
OnTrackMouseEnter(EventArgs.Empty);
}
else
{
OnTrackMouseLeave(EventArgs.Empty);
}
}
}
}
/// <summary>
/// Reset the app themed setting so it is retested when next required.
/// </summary>
public void ClearAppThemed()
{
_appThemed = null;
}
/// <summary>
/// Gets the content short text.
/// </summary>
/// <returns>String value.</returns>
public virtual string GetShortText()
{
return string.Empty;
}
/// <summary>
/// Gets the content image.
/// </summary>
/// <param name="state">The state for which the image is needed.</param>
/// <returns>Image value.</returns>
public virtual Image GetImage(PaletteState state)
{
return null;
}
/// <summary>
/// Gets the image color that should be transparent.
/// </summary>
/// <param name="state">The state for which the image is needed.</param>
/// <returns>Color value.</returns>
public virtual Color GetImageTransparentColor(PaletteState state)
{
return Color.Empty;
}
/// <summary>
/// Gets the content long text.
/// </summary>
/// <returns>String value.</returns>
public virtual string GetLongText()
{
return string.Empty;
}
#endregion
#region Protected
/// <summary>
/// Raises the FontChanged event.
/// </summary>
/// <param name="e">Contains the event data.</param>
protected override void OnFontChanged(EventArgs e)
{
// Working on Windows XP or earlier systems?
if (_osMajorVersion < 6)
{
// Fudge by adding one to the font height, this gives the actual space used by the
// combo box control to draw an individual item in the main part of the control
ItemHeight = Font.Height + 1;
}
else
{
// Vista performs differently depending of the use of themes...
if (IsAppThemed)
{
// Fudge by subtracting 1, which ensure correct sizing of combo box main area
ItemHeight = Font.Height - 1;
}
else
{
// On under Vista without themes is the font height the actual height used
// by the combo box for the space required for drawing the actual item
ItemHeight = Font.Height;
}
}
base.OnFontChanged(e);
}
/// <summary>
/// Process Windows-based messages.
/// </summary>
/// <param name="m">A Windows-based message.</param>
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case PI.WM_.NCHITTEST:
if (_kryptonComboBox.InTransparentDesignMode)
{
m.Result = (IntPtr)PI.HT.TRANSPARENT;
}
else
{
base.WndProc(ref m);
}
break;
case PI.WM_.MOUSELEAVE:
{
// Mouse is not over the control
MouseOver = false;
_mouseTracking = false;
_kryptonComboBox.PerformNeedPaint(false);
Invalidate();
}
break;
case PI.WM_.MOUSEMOVE:
{
// Mouse is over the control
if (!MouseOver)
{
MouseOver = true;
_kryptonComboBox.PerformNeedPaint(false);
Invalidate();
}
// Grab the client area of the control
PI.GetClientRect(Handle, out PI.RECT rect);
// Get the constant used to crack open the display
int dropDownWidth = SystemInformation.VerticalScrollBarWidth;
Size borderSize = SystemInformation.BorderSize;
// Create rect for the text area
rect.left += borderSize.Width;
rect.right -= (borderSize.Width + dropDownWidth);
rect.top += borderSize.Height;
rect.bottom -= borderSize.Height;
// Create rectangle that represents the drop down button
Rectangle dropRect = new Rectangle(rect.right + 2, rect.top, dropDownWidth - 2, (rect.bottom - rect.top));
// Extract the point in client coordinates
Point clientPoint = new Point((int)m.LParam);
bool mouseTracking = dropRect.Contains(clientPoint);
if (mouseTracking != _mouseTracking)
{
_mouseTracking = mouseTracking;
_kryptonComboBox.PerformNeedPaint(false);
Invalidate();
}
}
break;
case PI.WM_.PRINTCLIENT:
case PI.WM_.PAINT:
{
PI.PAINTSTRUCT ps = new PI.PAINTSTRUCT();
// Do we need to BeginPaint or just take the given HDC?
IntPtr hdc = m.WParam == IntPtr.Zero ? PI.BeginPaint(Handle, ref ps) : m.WParam;
//////////////////////////////////////////////////////
// Following removed to allow the Draw to always happen, to allow centering etc
//if (_kryptonComboBox.Enabled && _kryptonComboBox.DropDownStyle == ComboBoxStyle.DropDown)
//{
// // Let base implementation draw the actual text area
// if (m.WParam == IntPtr.Zero)
// {
// m.WParam = hdc;
// DefWndProc(ref m);
// m.WParam = IntPtr.Zero;
// }
// else
// {
// DefWndProc(ref m);
// }
//}
// Paint the entire area in the background color
using (Graphics g = Graphics.FromHdc(hdc))
{
// Grab the client area of the control
PI.GetClientRect(Handle, out PI.RECT rect);
PaletteState state = (_kryptonComboBox.Enabled
? (_kryptonComboBox.IsActive ? PaletteState.Tracking : PaletteState.Normal)
: PaletteState.Disabled
);
PaletteInputControlTripleStates states = _kryptonComboBox.GetComboBoxTripleState();
// Drawn entire client area in the background color
using (SolidBrush backBrush = new SolidBrush(states.PaletteBack.GetBackColor1(state)))
{
g.FillRectangle(backBrush, new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top));
}
// Get the constant used to crack open the display
int dropDownWidth = SystemInformation.VerticalScrollBarWidth;
Size borderSize = SystemInformation.BorderSize;
// Create rect for the text area
rect.top += borderSize.Height;
rect.bottom -= borderSize.Height;
// Create rectangle that represents the drop down button
Rectangle dropRect;
// Update text and drop down rects dependent on the right to left setting
if (_kryptonComboBox.RightToLeft == RightToLeft.Yes)
{
dropRect = new Rectangle(rect.left + borderSize.Width + 1, rect.top + 1, dropDownWidth - 2, (rect.bottom - rect.top - 2));
rect.left += borderSize.Width + dropDownWidth;
rect.right -= borderSize.Width;
}
else
{
rect.left += borderSize.Width;
rect.right -= (borderSize.Width + dropDownWidth);
dropRect = new Rectangle(rect.right + 1, rect.top + 1, dropDownWidth - 2, (rect.bottom - rect.top - 2));
}
// Exclude border from being drawn, we need to take off another 2 pixels from all edges
PI.IntersectClipRect(hdc, rect.left + 2, rect.top + 2, rect.right - 2, rect.bottom - 2);
//////////////////////////////////////////////////////
// Following commented out, to allow the Draw to always happen even tho the edit box will draw over afterwards
// If not enabled or not the dropDown Style then we can draw over the text area
//if (!_kryptonComboBox.Enabled || _kryptonComboBox.DropDownStyle != ComboBoxStyle.DropDown)
{
// Set the correct text rendering hint for the text drawing. We only draw if the edit text is disabled so we
// just always grab the disable state value. Without this line the wrong hint can occur because it inherits
// it from the device context. Resulting in blurred text.
g.TextRenderingHint = CommonHelper.PaletteTextHintToRenderingHint(states.Content.GetContentShortTextHint(state));
// Define the string formatting requirements
StringFormat stringFormat = new StringFormat
{
LineAlignment = StringAlignment.Near,
FormatFlags = StringFormatFlags.NoWrap,
Trimming = StringTrimming.None,
// Use the correct prefix setting
HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None
};
switch (states.Content.GetContentShortTextH(state))
{
case PaletteRelativeAlign.Near:
stringFormat.Alignment = RightToLeft == RightToLeft.Yes
? StringAlignment.Far
: StringAlignment.Near;
break;
case PaletteRelativeAlign.Far:
stringFormat.Alignment = RightToLeft == RightToLeft.Yes
? StringAlignment.Near
: StringAlignment.Far;
break;
case PaletteRelativeAlign.Center:
stringFormat.Alignment = StringAlignment.Center;
break;
}
// Draw using a solid brush
Rectangle rectangle = new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
rectangle = CommonHelper.ApplyPadding(VisualOrientation.Top, rectangle,
states.Content.GetContentPadding(state));
try
{
using (SolidBrush foreBrush = new SolidBrush(states.Content.GetContentShortTextColor1(state)))
{
g.DrawString(Text, states.Content.GetContentShortTextFont(state), foreBrush, rectangle, stringFormat);
}
}
catch (ArgumentException)
{
using (SolidBrush foreBrush = new SolidBrush(ForeColor))
{
g.DrawString(Text, Font, foreBrush, rectangle, stringFormat);
}
}
}
// Remove clipping settings
PI.SelectClipRgn(hdc, IntPtr.Zero);
// Draw the drop down button
DrawDropButton(g, dropRect);
}
// Do we need to match the original BeginPaint?
if (m.WParam == IntPtr.Zero)
{
PI.EndPaint(Handle, ref ps);
}
}
break;
case PI.WM_.CONTEXTMENU:
// Only interested in overriding the behavior when we have a krypton context menu...
if (_kryptonComboBox.KryptonContextMenu != null)
{
// Extract the screen mouse position (if might not actually be provided)
Point mousePt = new Point(PI.LOWORD(m.LParam), PI.HIWORD(m.LParam));
// If keyboard activated, the menu position is centered
if (((int)((long)m.LParam)) == -1)
{
mousePt = PointToScreen(new Point(Width / 2, Height / 2));
}
// Show the context menu
_kryptonComboBox.KryptonContextMenu.Show(_kryptonComboBox, mousePt);
// We eat the message!
return;
}
base.WndProc(ref m);
break;
default:
base.WndProc(ref m);
break;
}
}
/// <summary>
/// Raises the TrackMouseEnter event.
/// </summary>
/// <param name="e">An EventArgs containing the event data.</param>
[Description("Raises the TrackMouseEnter event in the wrapped control.")]
[Category("Mouse")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual void OnTrackMouseEnter(EventArgs e)
{
TrackMouseEnter?.Invoke(this, e);
}
/// <summary>
/// Raises the TrackMouseLeave event.
/// </summary>
/// <param name="e">An EventArgs containing the event data.</param>
protected virtual void OnTrackMouseLeave(EventArgs e)
{
TrackMouseLeave?.Invoke(this, e);
}
#endregion
#region Implementation
private void DrawDropButton(Graphics g, Rectangle drawRect)
{
// Create the view and palette entries first time around
if (_viewButton == null)
{
// Create helper object to get all values from the KryptonComboBox redirector
_palette = new PaletteTripleToPalette(_kryptonComboBox.Redirector,
PaletteBackStyle.ButtonStandalone,
PaletteBorderStyle.ButtonStandalone,
PaletteContentStyle.ButtonStandalone);
// Create view element for drawing the actual button
_viewButton = new ViewDrawButton(_palette, _palette, _palette,
_palette, _palette, _palette, _palette,
new PaletteMetricRedirect(_kryptonComboBox.Redirector),
this, VisualOrientation.Top, false);
}
// Update with the latest button style for the drop down
_palette.SetStyles(_kryptonComboBox.DropButtonStyle);
// Find the new state for the button
PaletteState state;
if (_kryptonComboBox.Enabled)
{
if (Dropped)
{
state = PaletteState.Pressed;
}
else if (_mouseTracking)
{
state = PaletteState.Tracking;
}
else if (_kryptonComboBox.IsActive || (_kryptonComboBox.IsFixedActive && (_kryptonComboBox.InputControlStyle == InputControlStyle.Standalone)))
{
state = _kryptonComboBox.InputControlStyle == InputControlStyle.Standalone ? PaletteState.CheckedNormal : PaletteState.CheckedTracking;
}
else
{
state = PaletteState.Normal;
}
}
else
{
state = PaletteState.Disabled;
}
_viewButton.ElementState = state;
// Position the button element inside the available drop down button area
using (ViewLayoutContext layoutContext = new ViewLayoutContext(_kryptonComboBox, _kryptonComboBox.Renderer))
{
// Define the available area for layout
layoutContext.DisplayRectangle = drawRect;
// Perform actual layout inside that area
_viewButton.Layout(layoutContext);
}
// Fill background with the solid background color
using (SolidBrush backBrush = new SolidBrush(BackColor))
{
g.FillRectangle(backBrush, drawRect);
}
// Ask the element to draw now
using (RenderContext renderContext = new RenderContext(_kryptonComboBox, g, drawRect, _kryptonComboBox.Renderer))
{
// Ask the button element to draw itself
_viewButton.Render(renderContext);
// Call the renderer directly to draw the drop down glyph
renderContext.Renderer.RenderGlyph.DrawInputControlDropDownGlyph(renderContext,
_viewButton.ClientRectangle,
_palette.PaletteContent,
state);
}
}
private bool IsAppThemed
{
get
{
try
{
if (!_appThemed.HasValue)
{
_appThemed = (PI.IsThemeActive() && PI.IsAppThemed());
}
return _appThemed.Value;
}
catch
{
return false;
}
}
}
#endregion
}
private class SubclassEdit : NativeWindow
{
#region Instance Fields
private readonly KryptonComboBox _kryptonComboBox;
private bool _mouseOver;
#endregion
#region Events
/// <summary>
/// Occurs when the mouse enters the InternalComboBox.
/// </summary>
public event EventHandler TrackMouseEnter;
/// <summary>
/// Occurs when the mouse leaves the InternalComboBox.
/// </summary>
public event EventHandler TrackMouseLeave;
#endregion
#region Identity
/// <summary>
/// Initialize a new instance of the SubclassEdit class.
/// </summary>
/// <param name="editControl">Handle of the Edit control to subclass.</param>
/// <param name="kryptonComboBox">Reference to top level control.</param>
public SubclassEdit(IntPtr editControl,
KryptonComboBox kryptonComboBox)
{
_kryptonComboBox = kryptonComboBox;
// Attach ourself to the provided control, subclassing it
AssignHandle(editControl);
}
#endregion
#region Public
/// <summary>
/// Gets and sets if the mouse is currently over the combo box.
/// </summary>
public bool MouseOver
{
get => _mouseOver;
set
{
// Only interested in changes
if (_mouseOver != value)
{
_mouseOver = value;
// Generate appropriate change event
if (_mouseOver)
{
OnTrackMouseEnter(EventArgs.Empty);
}
else
{
OnTrackMouseLeave(EventArgs.Empty);
}
}
}
}
/// <summary>
/// Sets the visible state of the control.
/// </summary>
public bool Visible
{
set => PI.SetWindowPos(Handle,
IntPtr.Zero,
0, 0, 0, 0,
(PI.SWP_.NOMOVE | PI.SWP_.NOSIZE |
(value ? PI.SWP_.SHOWWINDOW : PI.SWP_.HIDEWINDOW))
);
}
#endregion
#region Protected
/// <summary>
/// Process Windows-based messages.
/// </summary>
/// <param name="m">A Windows-based message.</param>
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case PI.WM_.NCHITTEST:
if (_kryptonComboBox.InTransparentDesignMode)
{
m.Result = (IntPtr)PI.HT.TRANSPARENT;
}
else
{
base.WndProc(ref m);
}
break;
case PI.WM_.MOUSELEAVE:
// Mouse is not over the control
MouseOver = false;
_kryptonComboBox.PerformNeedPaint(false);
base.WndProc(ref m);
break;
case PI.WM_.MOUSEMOVE:
// Mouse is over the control
if (!MouseOver)
{
PI.TRACKMOUSEEVENTS tme = new PI.TRACKMOUSEEVENTS
{
// This structure needs to know its own size in bytes
cbSize = (uint)Marshal.SizeOf(typeof(PI.TRACKMOUSEEVENTS)),
dwHoverTime = 100,
// We need to know then the mouse leaves the client window area
dwFlags = PI.TME_LEAVE,
// We want to track our own window
hWnd = Handle
};
// Call Win32 API to start tracking
PI.TrackMouseEvent(ref tme);
MouseOver = true;
_kryptonComboBox.PerformNeedPaint(false);
}
base.WndProc(ref m);
break;
case PI.WM_.CONTEXTMENU:
// Only interested in overriding the behavior when we have a krypton context menu...
if (_kryptonComboBox.KryptonContextMenu != null)
{
// Extract the screen mouse position (if might not actually be provided)
Point mousePt = new Point(PI.LOWORD(m.LParam), PI.HIWORD(m.LParam));
// If keyboard activated, the menu position is centered
if (((int)((long)m.LParam)) == -1)
{
PI.GetClientRect(Handle, out PI.RECT clientRect);
mousePt = new Point((clientRect.right - clientRect.left) / 2,
(clientRect.bottom - clientRect.top) / 2);
}
// Show the context menu
_kryptonComboBox.KryptonContextMenu.Show(_kryptonComboBox, mousePt);
// We eat the message!
return;
}
base.WndProc(ref m);
break;
case PI.WM_.DESTROY:
// Remove this code as it prevents the auto suggest features from working
// _kryptonComboBox.DetachEditControl();
base.WndProc(ref m);
break;
default:
base.WndProc(ref m);
break;
}
}
/// <summary>
/// Raises the TrackMouseEnter event.
/// </summary>
/// <param name="e">An EventArgs containing the event data.</param>
protected virtual void OnTrackMouseEnter(EventArgs e)
{
TrackMouseEnter?.Invoke(this, e);
}
/// <summary>
/// Raises the TrackMouseLeave event.
/// </summary>
/// <param name="e">An EventArgs containing the event data.</param>
protected virtual void OnTrackMouseLeave(EventArgs e)
{
TrackMouseLeave?.Invoke(this, e);
}
#endregion
}
#endregion
#region Type Definitions
/// <summary>
/// Collection for managing ButtonSpecAny instances.
/// </summary>
public class ComboBoxButtonSpecCollection : ButtonSpecCollection<ButtonSpecAny>
{
#region Identity
/// <summary>
/// Initialize a new instance of the ComboBoxButtonSpecCollection class.
/// </summary>
/// <param name="owner">Reference to owning object.</param>
public ComboBoxButtonSpecCollection(KryptonComboBox owner)
: base(owner)
{
}
#endregion
}
#endregion
#region Static Fields
private static readonly int _osMajorVersion;
#endregion
#region Instance Fields
private VisualPopupToolTip _visualPopupToolTip;
private readonly ButtonSpecManagerLayout _buttonManager;
private readonly ViewLayoutDocker _drawDockerInner;
private readonly ViewDrawDocker _drawDockerOuter;
private readonly ViewLayoutFill _layoutFill;
private readonly InternalComboBox _comboBox;
private readonly InternalPanel _comboHolder;
private SubclassEdit _subclassEdit;
private ButtonStyle _dropButtonStyle;
private PaletteBackStyle _dropBackStyle;
private InputControlStyle _inputControlStyle;
private Nullable<bool> _fixedActive;
private readonly FixedContentValue _contentValues;
private ButtonStyle _style;
private readonly ViewDrawButton _drawButton;
private readonly ViewDrawPanel _drawPanel;
private Padding _layoutPadding;
private IntPtr _screenDC;
private ButtonSpecAny _toolTipSpec;
private VisualPopupToolTip _toolTip;
private bool _firstTimePaint;
private bool _trackingMouseEnter;
private bool _forcedLayout;
private bool _mouseOver;
private bool _alwaysActive;
private int _cachedHeight;
private int _hoverIndex;
#endregion
#region Events
/// <summary>
/// Occurs when [draw item].
/// </summary>
[Category("Behavior")]
[Description("Occurs when an item needs to be Drawn.")]
public event DrawItemEventHandler DrawItem;
/// <summary>
/// Occurs when the control is initialized.
/// </summary>
[Category("Behavior")]
[Description("Occurs when the control has been fully initialized.")]
public event EventHandler Initialized;
/// <summary>
/// Occurs when the drop-down portion of the KryptonComboBox is shown.
/// </summary>
[Description("Occurs when the drop-down portion of the KryptonComboBox is shown.")]
[Category("Behavior")]
public event EventHandler DropDown;
/// <summary>
/// Indicates that the drop-down portion of the KryptonComboBox has closed.
/// </summary>
[Description("Indicates that the drop-down portion of the KryptonComboBox has closed.")]
[Category("Behavior")]
public event EventHandler DropDownClosed;
/// <summary>
/// Occurs when the value of the DropDownStyle property changed.
/// </summary>
[Description("Occurs when the value of the DropDownStyle property changed.")]
[Category("Behavior")]
public event EventHandler DropDownStyleChanged;
/// <summary>
/// Occurs when the value of the SelectedIndex property changes.
/// </summary>
[Description("Occurs when the value of the SelectedIndex property changes.")]
[Category("Behavior")]
public event EventHandler SelectedIndexChanged;
/// <summary>
/// Occurs when an item is chosen from the drop-down list and the drop-down list is closed.
/// </summary>
[Description("Occurs when an item is chosen from the drop-down list and the drop-down list is closed.")]
[Category("Behavior")]
public event EventHandler SelectionChangeCommitted;
/// <summary>
/// Occurs when the value of the DataSource property changed.
/// </summary>
[Description("Occurs when the value of the DataSource property changed.")]
[Category("PropertyChanged")]
public event EventHandler DataSourceChanged;
/// <summary>
/// Occurs when the value of the DisplayMember property changed.
/// </summary>
[Description("Occurs when the value of the DisplayMember property changed.")]
[Category("PropertyChanged")]
public event EventHandler DisplayMemberChanged;
/// <summary>
/// Occurs when the list format has changed.
/// </summary>
[Description("Occurs when the list format has changed.")]
[Category("PropertyChanged")]
public event ListControlConvertEventHandler Format;
/// <summary>
/// Occurs when the value of the FormatInfo property changed.
/// </summary>
[Description("Occurs when the value of the FormatInfo property changed.")]
[Category("PropertyChanged")]
public event EventHandler FormatInfoChanged;
/// <summary>
/// Occurs when the value of the FormatString property changed.
/// </summary>
[Description("Occurs when the value of the FormatString property changed.")]
[Category("PropertyChanged")]
public event EventHandler FormatStringChanged;
/// <summary>
/// Occurs when the value of the FormattingEnabled property changed.
/// </summary>
[Description("Occurs when the value of the FormattingEnabled property changed.")]
[Category("PropertyChanged")]
public event EventHandler FormattingEnabledChanged;
/// <summary>
/// Occurs when the value of the SelectedValue property changed.
/// </summary>
[Description("Occurs when the value of the SelectedValue property changed.")]
[Category("PropertyChanged")]
public event EventHandler SelectedValueChanged;
/// <summary>
/// Occurs when the value of the ValueMember property changed.
/// </summary>
[Description("Occurs when the value of the ValueMember property changed.")]
[Category("PropertyChanged")]
public event EventHandler ValueMemberChanged;
/// <summary>
/// Occurs when the KryptonComboBox text has changed.
/// </summary>
[Description("Occurs when the KryptonComboBox text has changed.")]
[Category("Behavior")]
public event EventHandler TextUpdate;
/// <summary>
/// Occurs when the hovered selection changed.
/// </summary>
[Description("Occurs when the hovered selection changed.")]
[Category("Behavior")]
public event EventHandler<HoveredSelectionChangedEventArgs> HoveredSelectionChanged;
/// <summary>
/// Occurs when the <see cref="KryptonComboBox"/> wants to display a tooltip.
/// </summary>
[Description("Occurs when the KryptonComboBox wants to display a tooltip.")]
[Category("Behavior")]
public event EventHandler<ToolTipNeededEventArgs> ToolTipNeeded;
/// <summary>
/// Occurs when the mouse enters the control.
/// </summary>
[Description("Raises the TrackMouseEnter event in the wrapped control.")]
[Category("Mouse")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public event EventHandler TrackMouseEnter;
/// <summary>
/// Occurs when the mouse leaves the control.
/// </summary>
[Description("Raises the TrackMouseLeave event in the wrapped control.")]
[Category("Mouse")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public event EventHandler TrackMouseLeave;
/// <summary>
/// Occurs when the value of the BackColor property changes.
/// </summary>