-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathCSDeskBand.cs
2762 lines (2401 loc) · 86.9 KB
/
CSDeskBand.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
// <autogenerated/>
// Define the symbol DESKBAND_WINFORMS for winforms or DESKBAND_WPF for wpf
// VERSION 3.1
// LICENSE: https://raw.githubusercontent.com/dsafa/CSDeskBand/master/LICENSE
#pragma warning disable 1591
namespace CSDeskBand
{
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using CSDeskBand.ContextMenu;
using CSDeskBand.Interop;
using static CSDeskBand.Interop.DESKBANDINFO.DBIF;
using static CSDeskBand.Interop.DESKBANDINFO.DBIM;
using static CSDeskBand.Interop.DESKBANDINFO.DBIMF;
/// <summary>
/// Default implementation for icsdeskband
/// </summary>
internal sealed class CSDeskBandImpl : ICSDeskBand
{
private readonly IDeskBandProvider _provider;
private readonly Dictionary<uint, DeskBandMenuAction> _contextMenuActions = new Dictionary<uint, DeskBandMenuAction>();
private IntPtr _parentWindowHandle;
private object _parentSite; // Has these interfaces: IInputObjectSite, IOleWindow, IOleCommandTarget, IBandSite
private uint _id;
private uint _menutStartId = 0;
private Guid _deskbandCommandGroupId = new Guid("EB0FE172-1A3A-11D0-89B3-00A0C90A90AC"); // Command group id for deskband. Used for IOleCommandTarge.Exec
/// <summary>
/// Initializes a new instance of the <see cref="CSDeskBandImpl"/> class
/// with the handle to the window and the options.
/// </summary>
public CSDeskBandImpl(IDeskBandProvider provider)
{
_provider = provider;
Options = provider.Options;
Options.PropertyChanged += Options_PropertyChanged;
}
/// <summary>
/// Occurs when the deskband is closed.
/// </summary>
internal event EventHandler Closed;
/// <summary>
/// Gets the <see cref="CSDeskBandOptions"/>.
/// </summary>
internal CSDeskBandOptions Options { get; }
/// <summary>
/// Gets the <see cref="TaskbarInfo"/>.
/// </summary>
internal TaskbarInfo TaskbarInfo { get; } = new TaskbarInfo();
/// <inheritdoc/>
public int GetWindow(out IntPtr phwnd)
{
phwnd = _provider.Handle;
return HRESULT.S_OK;
}
/// <inheritdoc/>
public int ContextSensitiveHelp(bool fEnterMode)
{
return HRESULT.E_NOTIMPL;
}
/// <inheritdoc/>
public int ShowDW([In] bool fShow)
{
return HRESULT.S_OK;
}
/// <inheritdoc/>
public int CloseDW([In] uint dwReserved)
{
Closed?.Invoke(this, null);
return HRESULT.S_OK;
}
/// <inheritdoc/>
public int ResizeBorderDW(RECT prcBorder, [In, MarshalAs(UnmanagedType.IUnknown)] IntPtr punkToolbarSite, bool fReserved)
{
// Must return notimpl
return HRESULT.E_NOTIMPL;
}
/// <inheritdoc/>
public int GetBandInfo(uint dwBandID, DESKBANDINFO.DBIF dwViewMode, ref DESKBANDINFO pdbi)
{
// Sizing information is requested whenever the taskbar changes size/orientation
_id = dwBandID;
if (pdbi.dwMask.HasFlag(DBIM_MINSIZE))
{
if (dwViewMode.HasFlag(DBIF_VIEWMODE_VERTICAL))
{
pdbi.ptMinSize.Y = Options.MinVerticalSize.Width;
pdbi.ptMinSize.X = Options.MinVerticalSize.Height;
}
else
{
pdbi.ptMinSize.X = Options.MinHorizontalSize.Width;
pdbi.ptMinSize.Y = Options.MinHorizontalSize.Height;
}
}
// X is ignored
if (pdbi.dwMask.HasFlag(DBIM_MAXSIZE))
{
if (dwViewMode.HasFlag(DBIF_VIEWMODE_VERTICAL))
{
pdbi.ptMaxSize.Y = Options.MaxVerticalWidth;
pdbi.ptMaxSize.X = 0;
}
else
{
pdbi.ptMaxSize.X = 0;
pdbi.ptMaxSize.Y = Options.MaxHorizontalHeight;
}
}
// x member is ignored
if (pdbi.dwMask.HasFlag(DBIM_INTEGRAL))
{
pdbi.ptIntegral.Y = Options.HeightIncrement;
pdbi.ptIntegral.X = 0;
}
if (pdbi.dwMask.HasFlag(DBIM_ACTUAL))
{
if (dwViewMode.HasFlag(DBIF_VIEWMODE_VERTICAL))
{
pdbi.ptActual.Y = Options.VerticalSize.Width;
pdbi.ptActual.X = Options.VerticalSize.Height;
}
else
{
pdbi.ptActual.X = Options.HorizontalSize.Width;
pdbi.ptActual.Y = Options.HorizontalSize.Height;
}
}
if (pdbi.dwMask.HasFlag(DBIM_TITLE))
{
pdbi.wszTitle = Options.Title;
if (!Options.ShowTitle)
{
pdbi.dwMask &= ~DBIM_TITLE;
}
}
if (pdbi.dwMask.HasFlag(DBIM_MODEFLAGS))
{
pdbi.dwModeFlags = DBIMF_NORMAL;
pdbi.dwModeFlags |= Options.IsFixed ? DBIMF_FIXED | DBIMF_NOGRIPPER : 0;
pdbi.dwModeFlags |= Options.HeightCanChange ? DBIMF_VARIABLEHEIGHT : 0;
pdbi.dwModeFlags &= ~DBIMF_BKCOLOR; // Don't use background color
}
TaskbarInfo.UpdateInfo();
return HRESULT.S_OK;
}
/// <inheritdoc/>
public int CanRenderComposited(out bool pfCanRenderComposited)
{
pfCanRenderComposited = true;
return HRESULT.S_OK;
}
/// <inheritdoc/>
public int SetCompositionState(bool fCompositionEnabled)
{
return HRESULT.S_OK;
}
/// <inheritdoc/>
public int GetCompositionState(out bool pfCompositionEnabled)
{
pfCompositionEnabled = true;
return HRESULT.S_OK;
}
/// <inheritdoc/>
public int SetSite([In, MarshalAs(UnmanagedType.IUnknown)] object pUnkSite)
{
// Let gc release old site
_parentSite = null;
// pUnkSite null means deskband was closed
if (pUnkSite == null)
{
Closed?.Invoke(this, null);
return HRESULT.S_OK;
}
try
{
var oleWindow = (IOleWindow)pUnkSite;
oleWindow.GetWindow(out _parentWindowHandle);
User32.SetParent(_provider.Handle, _parentWindowHandle);
_parentSite = (IInputObjectSite)pUnkSite;
return HRESULT.S_OK;
}
catch
{
return HRESULT.E_FAIL;
}
}
/// <inheritdoc/>
public int GetSite(ref Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out IntPtr ppvSite)
{
if (_parentSite == null)
{
ppvSite = IntPtr.Zero;
return HRESULT.E_FAIL;
}
return Marshal.QueryInterface(Marshal.GetIUnknownForObject(_parentSite), ref riid, out ppvSite);
}
/// <inheritdoc/>
public int QueryContextMenu(IntPtr hMenu, uint indexMenu, uint idCmdFirst, uint idCmdLast, QueryContextMenuFlags uFlags)
{
if (uFlags.HasFlag(QueryContextMenuFlags.CMF_DEFAULTONLY))
{
return HRESULT.MakeHResult((uint)HRESULT.S_OK, 0, 0);
}
_menutStartId = idCmdFirst;
foreach (var item in Options.ContextMenuItems)
{
item.AddToMenu(hMenu, indexMenu++, ref idCmdFirst, _contextMenuActions);
}
return HRESULT.MakeHResult((uint)HRESULT.S_OK, 0, idCmdFirst + 1); // #id of last command + 1
}
/// <inheritdoc/>
public int InvokeCommand(IntPtr pici)
{
var commandInfo = Marshal.PtrToStructure<CMINVOKECOMMANDINFO>(pici);
#pragma warning disable CS0219 // Variable is assigned but its value is never used
var isUnicode = false;
var isExtended = false;
#pragma warning restore CS0219 // Variable is assigned but its value is never used
var verbPtr = commandInfo.lpVerb;
if (commandInfo.cbSize == Marshal.SizeOf<CMINVOKECOMMANDINFOEX>())
{
isExtended = true;
var extended = Marshal.PtrToStructure<CMINVOKECOMMANDINFOEX>(pici);
if (extended.fMask.HasFlag(CMINVOKECOMMANDINFOEX.CMIC.CMIC_MASK_UNICODE))
{
isUnicode = true;
verbPtr = extended.lpVerbW;
}
}
if (User32.HiWord(commandInfo.lpVerb.ToInt32()) != 0)
{
// TODO verbs
return HRESULT.E_FAIL;
}
var cmdIndex = User32.LoWord(verbPtr.ToInt32());
if (!_contextMenuActions.TryGetValue((uint)cmdIndex + _menutStartId, out var action))
{
return HRESULT.E_FAIL;
}
action.DoAction();
return HRESULT.S_OK;
}
/// <inheritdoc/>
public int GetCommandString(ref uint idcmd, uint uflags, ref uint pwReserved, out string pcszName, uint cchMax)
{
pcszName = "";
return HRESULT.E_NOTIMPL;
}
/// <inheritdoc/>
public int HandleMenuMsg(uint uMsg, IntPtr wParam, IntPtr lParam)
{
return HandleMenuMsg2(uMsg, wParam, lParam, out var i);
}
/// <inheritdoc/>
public int HandleMenuMsg2(uint uMsg, IntPtr wParam, IntPtr lParam, out IntPtr plResult)
{
plResult = IntPtr.Zero;
return HRESULT.S_OK;
}
/// <inheritdoc/>
public int GetClassID(out Guid pClassID)
{
pClassID = _provider.Guid;
return HRESULT.S_OK;
}
/// <inheritdoc/>
public int GetSizeMax(out ulong pcbSize)
{
pcbSize = 0;
return HRESULT.S_OK;
}
/// <inheritdoc/>
public int IsDirty()
{
return HRESULT.S_OK;
}
/// <inheritdoc/>
public int Load(object pStm)
{
return HRESULT.S_OK;
}
/// <inheritdoc/>
public int Save(IntPtr pStm, bool fClearDirty)
{
return HRESULT.S_OK;
}
/// <summary>
/// Closes the deskband.
/// </summary>
public void CloseDeskBand()
{
var bandSite = (IBandSite)_parentSite;
bandSite.RemoveBand(_id);
}
/// <inheritdoc/>
public int UIActivateIO(int fActivate, ref MSG msg)
{
_provider.HasFocus = fActivate != 0;
UpdateFocus(_provider.HasFocus);
return HRESULT.S_OK;
}
/// <inheritdoc/>
public int HasFocusIO()
{
return _provider.HasFocus ? HRESULT.S_OK : HRESULT.S_FALSE;
}
/// <inheritdoc/>
public int TranslateAcceleratorIO(ref MSG msg)
{
return HRESULT.S_OK;
}
/// <summary>
/// Updates the focus on the deskband. Explorer will call <see cref="UIActivateIO(int, ref MSG)"/> for example if tabbing when the taskbar is focused.
/// But if focus is acquired without in other ways, then explorer isn't aware of it and <see cref="IInputObjectSite.OnFocusChangeIS(object, int)"/> needs to be called.
/// </summary>
/// <param name="focused">True if focused.</param>
public void UpdateFocus(bool focused)
{
(_parentSite as IInputObjectSite)?.OnFocusChangeIS(this, focused ? 1 : 0);
}
private void Options_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (_parentSite == null)
{
return;
}
var parent = (IOleCommandTarget)_parentSite;
// Set pvaln to the id that was passed in SetSite
// When int is marshalled to variant, it is marshalled as VT_i4. See default marshalling for objects
parent.Exec(ref _deskbandCommandGroupId, (uint)tagDESKBANDCID.DBID_BANDINFOCHANGED, 0, IntPtr.Zero, IntPtr.Zero);
}
}
}
namespace CSDeskBand
{
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using CSDeskBand.ContextMenu;
/// <summary>
/// Options to configure the deskband
/// </summary>
public sealed class CSDeskBandOptions : INotifyPropertyChanged
{
/// <summary>
/// Height for a default horizontal taskbar.
/// </summary>
public static readonly int TaskbarHorizontalHeightLarge = 40;
/// <summary>
/// Height for a default horizontal taskbar with small icons.
/// </summary>
public static readonly int TaskbarHorizontalHeightSmall = 30;
/// <summary>
/// Width for a default vertical taskbar. There is no small vertical taskbar.
/// </summary>
public static readonly int TaskbarVerticalWidth = 62;
/// <summary>
/// Value that represents no limit for deskband size.
/// </summary>
/// <seealso cref="MaxHorizontalHeight"/>
/// <seealso cref="MaxVerticalWidth"/>
public static readonly int NoLimit = -1;
private DeskBandSize _horizontalSize;
private int _maxHorizontalHeight;
private DeskBandSize _minHorizontalSize;
private DeskBandSize _verticalSize;
private int _maxVerticalWidth;
private DeskBandSize _minVerticalSize;
private string _title = "";
private bool _showTitle = false;
private bool _isFixed = false;
private int _heightIncrement = 1;
private bool _heightCanChange = true;
private ICollection<DeskBandMenuItem> _contextMenuItems = new List<DeskBandMenuItem>();
/// <summary>
/// Initializes a new instance of the <see cref="CSDeskBandOptions"/> class.
/// </summary>
public CSDeskBandOptions()
{
// Initialize in constructor to hook up property change events
HorizontalSize = new DeskBandSize(200, TaskbarHorizontalHeightLarge);
MaxHorizontalHeight = NoLimit;
MinHorizontalSize = new DeskBandSize(NoLimit, NoLimit);
VerticalSize = new DeskBandSize(TaskbarVerticalWidth, 200);
MaxVerticalWidth = NoLimit;
MinVerticalSize = new DeskBandSize(NoLimit, NoLimit);
}
/// <summary>
/// Occurs when a property has change.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Gets or sets a value indicating whether the height of the horizontal deskband is allowed to change.
/// <para/>
/// Or for a deskband in the vertical orientation, if the width can change.
/// Works alongside with the property <see cref="HeightIncrement"/>.
/// </summary>
/// <value>
/// <see langword="true"/> if the height / width of the deskband can be changed. <see langword="false"/> to prevent changes.
/// The default value is <see langword="true"/>.
/// </value>
public bool HeightCanChange
{
get => _heightCanChange;
set
{
if (value == _heightCanChange)
{
return;
}
_heightCanChange = value;
OnPropertyChanged();
}
}
/// <summary>
/// Gets or sets the height step size of a horizontal deskband when it is being resized.
/// For a deskband in the vertical orientation, it will be the step size of the width.
/// <para/>
/// The deskband will only be resized to multiples of this value.
/// </summary>
/// <example>
/// If increment is 50, then the height of the deskband can only be resized to 50, 100 ...
/// </example>
/// <value>
/// The step size for resizing. This value is only used if <see cref="HeightCanChange"/> is true. If the value is less than 0, the height / width can be any size.
/// The default value is 1.
/// </value>
public int HeightIncrement
{
get => _heightIncrement;
set
{
if (value == _heightIncrement)
{
return;
}
_heightIncrement = value;
OnPropertyChanged();
}
}
/// <summary>
/// Gets or sets a value indicating whether the deskband has a fixed position and size.
/// </summary>
/// <value>
/// <see langword="true"/> if the deskband is fixed. <see langword="false"/> if the deskband can be adjusted.
/// The default value is <see langword="false"/>.
/// </value>
public bool IsFixed
{
get => _isFixed;
set
{
if (value == _isFixed)
{
return;
}
_isFixed = value;
OnPropertyChanged();
}
}
/// <summary>
/// Gets or sets a value indicating whether the value of <see cref="Title"/> is shown next to the deskband.
/// </summary>
/// <value>
/// <see langword="true"/> if the title should be shown. <see langword="false"/> if the title is hidden.
/// The default value is <see langword="false"/>.
/// </value>
public bool ShowTitle
{
get => _showTitle;
set
{
if (value == _showTitle)
{
return;
}
_showTitle = value;
OnPropertyChanged();
}
}
/// <summary>
/// Gets or sets the title of the deskband. This will be shown if <see cref="ShowTitle"/> is <see langword="true"/>.
/// </summary>
/// <value>
/// The title to display. If the title is null, it will be converted to an empty string.
/// The default value is an empty string.
/// </value>
public string Title
{
get => _title;
set
{
if (value == _title)
{
return;
}
_title = value ?? "";
OnPropertyChanged();
}
}
/// <summary>
/// Gets or sets the minimum <see cref="DeskBandSize"/> of the deskband in the vertical orientation.
/// </summary>
/// <seealso cref="TaskbarOrientation"/>
/// <value>
/// The default value is <see cref="NoLimit"/> for the width and height.
/// </value>
public DeskBandSize MinVerticalSize
{
get => _minVerticalSize;
set
{
if (value.Equals(_minVerticalSize))
{
return;
}
_minVerticalSize = value;
_minVerticalSize.PropertyChanged += (sender, args) => OnPropertyChanged();
OnPropertyChanged();
}
}
/// <summary>
/// Gets or sets the maximum width of the deskband in the vertical orientation.
/// </summary>
/// <remarks>
/// The maximum height will have to be addressed in your code as there is no limit to the height of the deskband when vertical.
/// </remarks>
/// <seealso cref="TaskbarOrientation"/>
/// <value>
/// The default value is <see cref="NoLimit"/>.
/// </value>
public int MaxVerticalWidth
{
get => _maxVerticalWidth;
set
{
if (value.Equals(_maxVerticalWidth))
{
return;
}
_maxVerticalWidth = value;
OnPropertyChanged();
}
}
/// <summary>
/// Gets or sets the ideal <see cref="DeskBandSize"/> of the deskband in the vertical orientation.
/// There is no guarantee that the deskband will be this size.
/// </summary>
/// <seealso cref="TaskbarOrientation"/>
/// <value>
/// The default value is <see cref="TaskbarVerticalWidth"/> for the width and 200 for the height.
/// </value>
public DeskBandSize VerticalSize
{
get => _verticalSize;
set
{
if (value.Equals(_verticalSize))
{
return;
}
_verticalSize = value;
_verticalSize.PropertyChanged += (sender, args) => OnPropertyChanged();
OnPropertyChanged();
}
}
/// <summary>
/// Gets or sets the minimum <see cref="DeskBandSize"/> of the deskband in the horizontal orientation.
/// </summary>
/// <seealso cref="TaskbarOrientation"/>
/// <value>
/// The default value is <see cref="NoLimit"/>.
/// </value>
public DeskBandSize MinHorizontalSize
{
get => _minHorizontalSize;
set
{
if (value.Equals(_minHorizontalSize))
{
return;
}
_minHorizontalSize = value;
_minHorizontalSize.PropertyChanged += (sender, args) => OnPropertyChanged();
OnPropertyChanged();
}
}
/// <summary>
/// Gets or sets the maximum height of the deskband in the horizontal orientation.
/// </summary>
/// <remarks>
/// The maximum width will have to be addressed in your code as there is no limit to the width of the deskband when horizontal.
/// </remarks>
/// <seealso cref="TaskbarOrientation"/>
/// <value>
/// The default value is <see cref="NoLimit"/>.
/// </value>
public int MaxHorizontalHeight
{
get => _maxHorizontalHeight;
set
{
if (value.Equals(_maxHorizontalHeight))
{
return;
}
_maxHorizontalHeight = value;
OnPropertyChanged();
}
}
/// <summary>
/// Gets or sets the ideal <see cref="DeskBandSize"/> of the deskband in the horizontal orientation.
/// There is no guarantee that the deskband will be this size.
/// </summary>
/// <seealso cref="TaskbarOrientation"/>
/// <value>
/// The default value is 200 for the width and <see cref="TaskbarHorizontalHeightLarge"/> for the height.
/// </value>
public DeskBandSize HorizontalSize
{
get => _horizontalSize;
set
{
if (value.Equals(_horizontalSize))
{
return;
}
_horizontalSize = value;
_horizontalSize.PropertyChanged += (sender, args) => OnPropertyChanged();
OnPropertyChanged();
}
}
/// <summary>
/// Gets or sets the collection of <see cref="DeskBandMenuItem"/> the comprise the deskbands context menu.
/// </summary>
/// <value>
/// A list of <see cref="DeskBandMenuItem"/> for the context menu. An empty collection indicates no context menu.
/// </value>
/// <remarks>
/// These context menu items are in addition of the default ones that windows provides.
/// The items will appear in their enumerated order.
/// </remarks>
public ICollection<DeskBandMenuItem> ContextMenuItems
{
get => _contextMenuItems;
set
{
if (Equals(value, _contextMenuItems))
{
return;
}
_contextMenuItems = value;
OnPropertyChanged();
}
}
private void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
namespace CSDeskBand
{
using System;
/// <summary>
/// Specifies registration configuration for a deskband.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
internal sealed class CSDeskBandRegistrationAttribute : Attribute
{
/// <summary>
/// Gets or sets the name of the deskband in the toolbar menu.
/// </summary>
/// <value>
/// The name is used to select the deskband from the toolbars menu.
/// </value>
public string Name { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to automatically show the deskband after registration.
/// </summary>
/// <value>
/// <see langword="true"/> if the deskband should be automatically shown after registration; <see langword="false"/> otherwise.
/// </value>
public bool ShowDeskBand { get; set; }
}
}
#pragma warning disable 1591
#if DESKBAND_WINFORMS
namespace CSDeskBand
{
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using CSDeskBand.Interop;
/// <summary>
/// Winforms implementation of <see cref="ICSDeskBand"/>.
/// The deskband should also have these attributes <see cref="ComVisibleAttribute"/>, <see cref="GuidAttribute"/>, <see cref="CSDeskBandRegistrationAttribute"/>.
/// </summary>
public abstract class CSDeskBandWin : ICSDeskBand, IDeskBandProvider
{
private readonly CSDeskBandImpl _impl;
/// <summary>
/// Initializes a new instance of the <see cref="CSDeskBandWin"/> class.
/// </summary>
public CSDeskBandWin()
{
Options.Title = RegistrationHelper.GetToolbarName(GetType());
_impl = new CSDeskBandImpl(this);
_impl.Closed += (o, e) => DeskbandOnClosed();
TaskbarInfo = _impl.TaskbarInfo;
}
[ComRegisterFunction]
private static void Register(Type t)
{
RegistrationHelper.Register(t);
}
[ComUnregisterFunction]
private static void Unregister(Type t)
{
RegistrationHelper.Unregister(t);
}
/// <summary>
/// Gets the taskbar information
/// </summary>
protected TaskbarInfo TaskbarInfo { get; }
/// <summary>
/// Gets the main control for the deskband.
/// </summary>
protected abstract Control Control { get; }
/// <summary>
/// Gets the options for this deskband.
/// </summary>
/// <seealso cref="CSDeskBandOptions"/>
public CSDeskBandOptions Options { get; } = new CSDeskBandOptions();
/// <summary>
/// Gets the handle
/// </summary>
public IntPtr Handle => Control.Handle;
/// <summary>
/// Gets the deskband guid
/// </summary>
public Guid Guid => GetType().GUID;
public bool HasFocus
{
get => Control?.ContainsFocus ?? false;
set
{
if (value)
{
Control?.Focus();
}
}
}
/// <summary>
/// Updates the focus on this deskband.
/// </summary>
/// <param name="focused"><see langword="true"/> if focused.</param>
public void UpdateFocus(bool focused)
{
_impl.UpdateFocus(focused);
}
/// <summary>
/// Handle closing of the deskband.
/// </summary>
protected virtual void DeskbandOnClosed()
{
}
public int GetWindow(out IntPtr phwnd)
{
return _impl.GetWindow(out phwnd);
}
public int ContextSensitiveHelp(bool fEnterMode)
{
return _impl.ContextSensitiveHelp(fEnterMode);
}
public int ShowDW([In] bool fShow)
{
return _impl.ShowDW(fShow);
}
public int CloseDW([In] uint dwReserved)
{
return _impl.CloseDW(dwReserved);
}
public int ResizeBorderDW(RECT prcBorder, [In, MarshalAs(UnmanagedType.IUnknown)] IntPtr punkToolbarSite, bool fReserved)
{
return _impl.ResizeBorderDW(prcBorder, punkToolbarSite, fReserved);
}
public int GetBandInfo(uint dwBandID, DESKBANDINFO.DBIF dwViewMode, ref DESKBANDINFO pdbi)
{
return _impl.GetBandInfo(dwBandID, dwViewMode, ref pdbi);
}
public int CanRenderComposited(out bool pfCanRenderComposited)
{
return _impl.CanRenderComposited(out pfCanRenderComposited);
}
public int SetCompositionState(bool fCompositionEnabled)
{
return _impl.SetCompositionState(fCompositionEnabled);
}
public int GetCompositionState(out bool pfCompositionEnabled)
{
return _impl.GetCompositionState(out pfCompositionEnabled);
}
public int SetSite([In, MarshalAs(UnmanagedType.IUnknown)] object pUnkSite)
{
return _impl.SetSite(pUnkSite);
}
public int GetSite(ref Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out IntPtr ppvSite)
{
return _impl.GetSite(ref riid, out ppvSite);
}
public int QueryContextMenu(IntPtr hMenu, uint indexMenu, uint idCmdFirst, uint idCmdLast, QueryContextMenuFlags uFlags)
{
return _impl.QueryContextMenu(hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
}
public int InvokeCommand(IntPtr pici)
{
return _impl.InvokeCommand(pici);
}
public int GetCommandString(ref uint idcmd, uint uflags, ref uint pwReserved, [MarshalAs(UnmanagedType.LPTStr)] out string pcszName, uint cchMax)
{
return _impl.GetCommandString(ref idcmd, uflags, ref pwReserved, out pcszName, cchMax);
}
public int HandleMenuMsg(uint uMsg, IntPtr wParam, IntPtr lParam)
{
return _impl.HandleMenuMsg(uMsg, wParam, lParam);
}
public int HandleMenuMsg2(uint uMsg, IntPtr wParam, IntPtr lParam, out IntPtr plResult)
{
return _impl.HandleMenuMsg2(uMsg, wParam, lParam, out plResult);
}
public int GetClassID(out Guid pClassID)
{
return _impl.GetClassID(out pClassID);
}
public int GetSizeMax(out ulong pcbSize)
{
return _impl.GetSizeMax(out pcbSize);
}
public int IsDirty()
{
return _impl.IsDirty();
}
public int Load(object pStm)
{
return _impl.Load(pStm);
}
public int Save(IntPtr pStm, bool fClearDirty)
{
return _impl.Save(pStm, fClearDirty);
}
public int UIActivateIO(int fActivate, ref MSG msg)
{
return _impl.UIActivateIO(fActivate, ref msg);
}
public int HasFocusIO()
{
return _impl.HasFocusIO();
}
public int TranslateAcceleratorIO(ref MSG msg)
{
return _impl.TranslateAcceleratorIO(ref msg);
}
}
}
#endif
#pragma warning disable 1591
#if DESKBAND_WPF
namespace CSDeskBand
{
using System;
using System.Runtime.InteropServices;
using System.Windows.Interop;
using CSDeskBand.Interop;