-
Notifications
You must be signed in to change notification settings - Fork 238
/
Widget.cs
2101 lines (1885 loc) · 65.4 KB
/
Widget.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
//
// Widget.cs
//
// Author:
// Lluis Sanchez <lluis@xamarin.com>
// Wolfgang Silbermayr <wolfgang.silbermayr@gmail.com>
//
// Copyright (c) 2011 Xamarin Inc
// Copyright (C) 2012 Wolfgang Silbermayr
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.ComponentModel;
using System.Collections.Generic;
using Xwt.Backends;
using Xwt.Drawing;
using System.Reflection;
using System.Xaml;
using System.Linq;
using Xwt.Motion;
namespace Xwt
{
[BackendType (typeof(ICustomWidgetBackend))]
public abstract class Widget: XwtComponent, IWidgetSurface, IAnimatable
{
static bool DebugWidgetLayout = false;
static int DebugWidgetLayoutIndent = 0;
static Widget[] emptyList = new Widget[0];
List<Widget> children;
WidgetSpacing margin;
Size cachedSize;
SizeConstraint cachedWidthConstraint;
SizeConstraint cachedHeightConstraint;
bool sizeCached;
DragOperation currentDragOperation;
Widget contentWidget;
WindowFrame parentWindow;
double minWidth = -1, minHeight = -1;
double widthRequest = -1, heightRequest = -1;
CursorType cursor;
WidgetPlacement alignVertical = WidgetPlacement.Fill;
WidgetPlacement alignHorizontal = WidgetPlacement.Fill;
bool expandVertical;
bool expandHorizontal;
EventHandler<DragOverCheckEventArgs> dragOverCheck;
EventHandler<DragOverEventArgs> dragOver;
EventHandler<DragCheckEventArgs> dragDropCheck;
EventHandler<DragEventArgs> dragDrop;
EventHandler<DragStartedEventArgs> dragStarted;
EventHandler dragLeave;
EventHandler<KeyEventArgs> keyPressed;
EventHandler<KeyEventArgs> keyReleased;
EventHandler<TextInputEventArgs> textInput;
EventHandler mouseEntered;
EventHandler mouseExited;
EventHandler<ButtonEventArgs> buttonPressed;
EventHandler<ButtonEventArgs> buttonReleased;
EventHandler<MouseMovedEventArgs> mouseMoved;
EventHandler boundsChanged;
EventHandler<MouseScrolledEventArgs> mouseScrolled;
EventHandler gotFocus;
EventHandler lostFocus;
/// <summary>
/// The WidgetBackendHost is the link between an Xwt widget and a toolkit specific widget backend.
/// </summary>
/// <typeparam name="T">The Xwt widget type.</typeparam>
/// <typeparam name="B">The Xwt widget backend interface.</typeparam>
protected class WidgetBackendHost<T,B>: WidgetBackendHost where T:Widget where B:IWidgetBackend
{
public new T Parent {
get { return (T) base.Parent; }
set { base.Parent = value; }
}
public new B Backend {
get { return (B) base.Backend; }
}
}
/// <summary>
/// The WidgetBackendHost is the link between an Xwt widget and a toolkit specific widget backend.
/// </summary>
protected class WidgetBackendHost: BackendHost<Widget, IWidgetBackend>, IWidgetEventSink
{
public WidgetBackendHost ()
{
}
/// <summary>
/// Called when the backend has been created.
/// </summary>
protected override void OnBackendCreated ()
{
((IWidgetBackend)Backend).Initialize (this);
base.OnBackendCreated ();
}
/// <summary>
/// Gets the default natural size of the widget
/// </summary>
/// <returns>The default natural size.</returns>
/// <remarks>This method should only be used if there isn't a platform-specific natural
/// size for the widget. There may be widgets for which XWT can't provide
/// a default natural width or height, in which case it return 0.</remarks>
public virtual Size GetDefaultNaturalSize ()
{
return new Size (0, 0);
}
void IWidgetEventSink.OnDragOverCheck (DragOverCheckEventArgs args)
{
Parent.OnDragOverCheck (args);
}
void IWidgetEventSink.OnDragOver (DragOverEventArgs args)
{
Parent.OnDragOver (args);
}
void IWidgetEventSink.OnDragDropCheck (DragCheckEventArgs args)
{
Parent.OnDragDropCheck (args);
}
void IWidgetEventSink.OnDragDrop (DragEventArgs args)
{
Parent.OnDragDrop (args);
}
void IWidgetEventSink.OnDragLeave (EventArgs args)
{
Parent.OnDragLeave (args);
}
void IWidgetEventSink.OnPreferredSizeChanged ()
{
Parent.OnPreferredSizeChanged ();
}
void IWidgetEventSink.OnDragFinished (DragFinishedEventArgs args)
{
Parent.OnDragFinished (args);
}
DragStartData IWidgetEventSink.OnDragStarted ()
{
return Parent.InternalDragStarted ();
}
void IWidgetEventSink.OnKeyPressed (KeyEventArgs args)
{
Parent.OnKeyPressed (args);
}
void IWidgetEventSink.OnKeyReleased (KeyEventArgs args)
{
Parent.OnKeyReleased (args);
}
void IWidgetEventSink.OnTextInput (TextInputEventArgs args)
{
Parent.OnTextInput (args);
}
Size IWidgetEventSink.GetPreferredSize (SizeConstraint widthConstraint, SizeConstraint heightConstraint)
{
return Parent.OnGetPreferredSize (widthConstraint, heightConstraint);
}
void IWidgetEventSink.OnGotFocus ()
{
Parent.OnGotFocus (EventArgs.Empty);
}
void IWidgetEventSink.OnLostFocus ()
{
Parent.OnLostFocus (EventArgs.Empty);
}
void IWidgetEventSink.OnMouseEntered ()
{
Parent.OnMouseEntered (EventArgs.Empty);
}
void IWidgetEventSink.OnMouseExited ()
{
Parent.OnMouseExited (EventArgs.Empty);
}
void IWidgetEventSink.OnButtonPressed (ButtonEventArgs args)
{
Parent.OnButtonPressed (args);
}
void IWidgetEventSink.OnButtonReleased (ButtonEventArgs args)
{
Parent.OnButtonReleased (args);
}
void IWidgetEventSink.OnMouseMoved (MouseMovedEventArgs args)
{
Parent.OnMouseMoved (args);
}
bool IWidgetEventSink.SupportsCustomScrolling ()
{
return Parent.SupportsCustomScrolling;
}
void IWidgetEventSink.SetScrollAdjustments (IScrollAdjustmentBackend horizontal, IScrollAdjustmentBackend vertical)
{
var h = new ScrollAdjustment (horizontal);
var v = new ScrollAdjustment (vertical);
Parent.SetScrollAdjustments (h, v);
}
void IWidgetEventSink.OnBoundsChanged ()
{
Parent.OnBoundsChanged ();
}
void IWidgetEventSink.OnMouseScrolled(MouseScrolledEventArgs args)
{
Parent.OnMouseScrolled(args);
}
}
public Widget ()
{
if (!(base.BackendHost is WidgetBackendHost))
throw new InvalidOperationException ("CreateBackendHost for Widget did not return a WidgetBackendHost instance");
}
static Widget ()
{
MapEvent (WidgetEvent.DragOverCheck, typeof(Widget), "OnDragOverCheck");
MapEvent (WidgetEvent.DragOver, typeof(Widget), "OnDragOver");
MapEvent (WidgetEvent.DragDropCheck, typeof(Widget), "OnDragDropCheck");
MapEvent (WidgetEvent.DragDrop, typeof(Widget), "OnDragDrop");
MapEvent (WidgetEvent.DragLeave, typeof(Widget), "OnDragLeave");
MapEvent (WidgetEvent.KeyPressed, typeof(Widget), "OnKeyPressed");
MapEvent (WidgetEvent.KeyReleased, typeof(Widget), "OnKeyReleased");
MapEvent (WidgetEvent.TextInput, typeof(Widget), "OnTextInput");
MapEvent (WidgetEvent.GotFocus, typeof(Widget), "OnGotFocus");
MapEvent (WidgetEvent.LostFocus, typeof(Widget), "OnLostFocus");
MapEvent (WidgetEvent.MouseEntered, typeof(Widget), "OnMouseEntered");
MapEvent (WidgetEvent.MouseExited, typeof(Widget), "OnMouseExited");
MapEvent (WidgetEvent.ButtonPressed, typeof(Widget), "OnButtonPressed");
MapEvent (WidgetEvent.ButtonReleased, typeof(Widget), "OnButtonReleased");
MapEvent (WidgetEvent.MouseMoved, typeof(Widget), "OnMouseMoved");
MapEvent (WidgetEvent.DragStarted, typeof(Widget), "OnDragStarted");
MapEvent (WidgetEvent.BoundsChanged, typeof(Widget), "OnBoundsChanged");
MapEvent (WidgetEvent.PreferredSizeCheck, typeof (Widget), "OnGetPreferredSize");
MapEvent (WidgetEvent.MouseScrolled, typeof(Widget), "OnMouseScrolled");
}
/// <summary>
/// Gets the current widget backend.
/// </summary>
/// <returns>The widget backend.</returns>
/// <param name="w">The Xwt widget.</param>
internal protected static IBackend GetBackend (Widget w)
{
if (w != null && w.Backend is XwtWidgetBackend)
return GetBackend ((XwtWidgetBackend)w.Backend);
return w != null ? w.Backend : null;
}
/// <summary>
/// Gets the backend host.
/// </summary>
/// <value>The backend host.</value>
protected new WidgetBackendHost BackendHost {
get { return (WidgetBackendHost) base.BackendHost; }
}
/// <summary>
/// Creates the backend host.
/// </summary>
/// <returns>The backend host.</returns>
protected override Xwt.Backends.BackendHost CreateBackendHost ()
{
return new WidgetBackendHost ();
}
protected override void Dispose (bool disposing)
{
base.Dispose (disposing);
// Don't dispose the backend if this object is being finalized
// The backend has to handle the finalizing on its own
if (disposing) {
if (BackendHost.BackendCreated)
Backend.Dispose ();
if (children != null) {
foreach (var c in DirectChildren)
c.Dispose ();
}
}
}
/// <summary>
/// Gets the parent window of the widget.
/// </summary>
/// <value>The parent window.</value>
public WindowFrame ParentWindow {
get {
if (Parent != null)
return Parent.ParentWindow;
else if (parentWindow == null) {
var p = BackendHost.EngineBackend.GetNativeParentWindow (this);
if (p != null)
parentWindow = BackendHost.ToolkitEngine.WrapWindow (p);
}
return parentWindow;
}
}
/// <summary>
/// Sets the parent window.
/// </summary>
/// <param name="win">An Xwt window containing the widget.</param>
internal void SetParentWindow (WindowFrame win)
{
parentWindow = win;
}
/* protected virtual WidgetBackendHost CreateBackendHost ()
{
return new WidgetBackendHost ();
}
protected WidgetBackendHost BackendHost {
get { return backendHost; }
}*/
/// <summary>
/// Gets the backend.
/// </summary>
/// <value>The backend.</value>
IWidgetBackend Backend {
get { return (IWidgetBackend) BackendHost.Backend; }
}
/// <summary>
/// Gets or sets the <see cref="Xwt.Widget"/> margin.
/// </summary>
/// <value>The widget margin.</value>
public WidgetSpacing Margin {
get { return margin; }
set {
margin = value;
OnPreferredSizeChanged ();
OnPlacementChanged ();
}
}
/// <summary>
/// Gets or sets the margin on the left side of this <see cref="Xwt.Widget"/>.
/// </summary>
/// <value>The left margin.</value>
[DefaultValue (0d)]
public double MarginLeft {
get { return margin.Left; }
set {
margin.Left = value;
OnPreferredSizeChanged ();
OnPlacementChanged ();
}
}
/// <summary>
/// Gets or sets the margin on the right side of this <see cref="Xwt.Widget"/>.
/// </summary>
/// <value>The right margin.</value>
[DefaultValue (0d)]
public double MarginRight {
get { return margin.Right; }
set {
margin.Right = value;
OnPreferredSizeChanged ();
OnPlacementChanged ();
}
}
/// <summary>
/// Gets or sets the margin on the top side of this <see cref="Xwt.Widget"/>.
/// </summary>
/// <value>The top margin.</value>
[DefaultValue (0d)]
public double MarginTop {
get { return margin.Top; }
set {
margin.Top = value;
OnPreferredSizeChanged ();
OnPlacementChanged ();
}
}
/// <summary>
/// Gets or sets the margin on the bottom side of this <see cref="Xwt.Widget"/>.
/// </summary>
/// <value>The bottom margin.</value>
[DefaultValue (0d)]
public double MarginBottom {
get { return margin.Bottom; }
set {
margin.Bottom = value;
OnPreferredSizeChanged ();
OnPlacementChanged ();
}
}
/// <summary>
/// Gets or sets the vertical placement/alignment of this <see cref="Xwt.Widget"/>.
/// </summary>
/// <value>The vertical placement.</value>
public WidgetPlacement VerticalPlacement {
get { return alignVertical; }
set {
alignVertical = value;
OnPreferredSizeChanged ();
OnPlacementChanged ();
}
}
/// <summary>
/// Gets or sets the horizontal placement/alignment of this <see cref="Xwt.Widget"/>.
/// </summary>
/// <value>The horizontal placement.</value>
public WidgetPlacement HorizontalPlacement {
get { return alignHorizontal; }
set {
alignHorizontal = value;
OnPreferredSizeChanged ();
OnPlacementChanged ();
}
}
/// <summary>
/// Get the placement/alignment of the <see cref="Xwt.Widget"/> for the specified orientation.
/// </summary>
/// <returns>The alignment for an orientation.</returns>
/// <param name="or">The orientation of the container.</param>
internal WidgetPlacement AlignmentForOrientation (Orientation or)
{
if (or == Orientation.Vertical)
return VerticalPlacement;
else
return HorizontalPlacement;
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="Xwt.Widget"/> expands to fill all available vertical space.
/// </summary>
/// <value><c>true</c> if the widget expands vertically; otherwise, <c>false</c>.</value>
public bool ExpandVertical {
get { return expandVertical; }
set {
expandVertical = value;
OnPreferredSizeChanged ();
OnPlacementChanged ();
}
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="Xwt.Widget"/> expands to fill all available horizontal space.
/// </summary>
/// <value><c>true</c> if the widget expands horizontally; otherwise, <c>false</c>.</value>
public bool ExpandHorizontal {
get { return expandHorizontal; }
set {
expandHorizontal = value;
OnPreferredSizeChanged ();
OnPlacementChanged ();
}
}
/// <summary>
/// Determines whether this <see cref="Xwt.Widget"/> expands in a specific orientation.
/// </summary>
/// <returns><c>true</c>, if the widget expands in the specified orientation, <c>false</c> otherwise.</returns>
/// <param name="or">Or.</param>
internal bool ExpandsForOrientation (Orientation or)
{
if (or == Orientation.Vertical)
return ExpandVertical;
else
return ExpandHorizontal;
}
/// <summary>
/// Shows this widget.
/// </summary>
public void Show ()
{
Visible = true;
}
/// <summary>
/// Hides this widget.
/// </summary>
public void Hide ()
{
Visible = false;
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="Xwt.Widget"/> is visible.
/// </summary>
/// <value><c>true</c> if visible; otherwise, <c>false</c>.</value>
[DefaultValue (true)]
public bool Visible {
get { return Backend.Visible; }
set {
Backend.Visible = value;
OnPreferredSizeChanged ();
}
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="Xwt.Widget"/> is sensitive.
/// </summary>
/// <value><c>true</c> if sensitive; otherwise, <c>false</c>.</value>
[DefaultValue (true)]
public bool Sensitive {
get { return Backend.Sensitive; }
set { Backend.Sensitive = value; }
}
/// <summary>
/// Gets or sets a value indicating whether this this <see cref="Xwt.Widget"/> can get focus.
/// </summary>
/// <value><c>true</c> if this widget can get focus; otherwise, <c>false</c>.</value>
[DefaultValue (true)]
public bool CanGetFocus {
get { return Backend.CanGetFocus; }
set { Backend.CanGetFocus = value; }
}
/// <summary>
/// Gets a value indicating whether this <see cref="Xwt.Widget"/> has the focus.
/// </summary>
/// <value><c>true</c> if this widget has focus; otherwise, <c>false</c>.</value>
[DefaultValue (true)]
public bool HasFocus {
get { return Backend.HasFocus; }
}
/// <summary>
/// Gets or sets the opacity of this <see cref="Xwt.Widget"/>.
/// </summary>
/// <value>The opacity of this widget.</value>
/// <remarks>Not all toolkits support widget opacity. For toolkits that do not support it,
/// setting the opacity has no effect. Examine the <see cref="Xwt.Toolkit.SupportedFeatures"/>
/// property of the current <see cref="Xwt.IWidgetSurface.ToolkitEngine"/> (member of <see cref="Xwt.Widget.Surface"/>)
/// to determine if the current toolkit supports this feature.</remarks>
[DefaultValue (1d)]
public double Opacity {
get { return Backend.Opacity; }
set { Backend.Opacity = value; }
}
/// <summary>
/// Gets or sets the name of this widget.
/// </summary>
/// <value>The widgets name.</value>
/// <remarks>The name can be used to identify this widget by e.g. designers.</remarks>
[DefaultValue (null)]
public override string Name {
get { return Backend.Name; }
set { Backend.Name = value; }
}
/// <summary>
/// Gets the parent widget of this <see cref="Xwt.Widget"/>.
/// </summary>
/// <value>The parent.</value>
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public Widget Parent { get; private set; }
internal Widget InternalParent { get; private set; }
bool IsInternalChild {
get { return ExternalParent != null; }
}
Widget ExternalParent { get; set; }
/// <summary>
/// Gets the widgets surface.
/// </summary>
/// <value>The surface of this widget.</value>
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public IWidgetSurface Surface {
get { return this; }
}
/// <summary>
/// Gets or sets the content of this <see cref="Xwt.Widget"/>.
/// </summary>
/// <value>The content of the widget.</value>
protected Widget Content {
get { return contentWidget; }
set {
ICustomWidgetBackend bk = Backend as ICustomWidgetBackend;
if (bk == null)
throw new InvalidOperationException ("The Content widget can only be set when directly subclassing Xwt.Widget");
bk.SetContent ((IWidgetBackend)GetBackend (value));
if (contentWidget != null)
UnregisterChild (contentWidget);
if (value != null)
RegisterChild (value);
contentWidget = value;
OnPreferredSizeChanged ();
}
}
/// <summary>
/// Gets the size of this <see cref="Xwt.Widget"/>.
/// </summary>
/// <value>The size of the widget.</value>
public Size Size {
get { return Backend.Size; }
}
/// <summary>
/// Gets or sets the minimum width.
/// </summary>
/// <value>
/// The minimum width.
/// </value>
/// <remarks>
/// Minimum width for the widget. If set to -1, the widget's default minimum size will be used.
/// </remarks>
[DefaultValue((double)-1)]
public double MinWidth {
get { return minWidth; }
set {
if (value < -1)
throw new ArgumentException ("MinWidth can't be less that -1");
minWidth = value;
Backend.SetMinSize (minWidth >= 0 ? minWidth : -1, minHeight >= 0 ? minHeight : -1);
OnPreferredSizeChanged ();
}
}
/// <summary>
/// Gets or sets the minimum height.
/// </summary>
/// <value>
/// The minimum height.
/// </value>
/// <remarks>
/// Minimum height for the widget. If set to -1, the widget's default minimum size will be used.
/// </remarks>
[DefaultValue((double)-1)]
public double MinHeight {
get { return minHeight; }
set {
if (value < -1)
throw new ArgumentException ("MinHeight can't be less that -1");
minHeight = value;
Backend.SetMinSize (minWidth >= 0 ? minWidth : -1, minHeight >= 0 ? minHeight : -1);
OnPreferredSizeChanged ();
}
}
/// <summary>
/// Gets or sets the natural width.
/// </summary>
/// <value>
/// The natural width, or -1 if no custom natural width has been set
/// </value>
/// <remarks>
/// Natural width for the widget. If set to -1, the default natural size is used.
/// </remarks>
[DefaultValue((double)-1)]
public double WidthRequest {
get { return widthRequest; }
set {
if (value < -1)
throw new ArgumentException ("NaturalWidth can't be less that -1");
widthRequest = value;
Backend.SetSizeRequest (widthRequest >= 0 ? widthRequest : -1, heightRequest >= 0 ? heightRequest : -1);
OnPreferredSizeChanged ();
}
}
/// <summary>
/// Gets or sets the natural height.
/// </summary>
/// <value>
/// The natural height, or -1 if no custom natural height has been set
/// </value>
/// <remarks>
/// Natural height for the widget. If set to -1, the default natural size is used.
/// </remarks>
[DefaultValue((double)-1)]
public double HeightRequest {
get { return heightRequest; }
set {
if (value < -1)
throw new ArgumentException ("NaturalHeight can't be less that -1");
heightRequest = value;
Backend.SetSizeRequest (widthRequest >= 0 ? widthRequest : -1, heightRequest >= 0 ? heightRequest : -1);
OnPreferredSizeChanged ();
}
}
/// <summary>
/// Gets or sets the font of the widget.
/// </summary>
/// <value>
/// The font.
/// </value>
public Font Font {
get {
return new Font (Backend.Font, BackendHost.ToolkitEngine);
}
set {
Backend.Font = BackendHost.ToolkitEngine.GetSafeBackend (value);
}
}
/// <summary>
/// Gets or sets the background color.
/// </summary>
/// <value>The background color of the widget.</value>
public Color BackgroundColor {
get { return Backend.BackgroundColor; }
set { Backend.BackgroundColor = value; }
}
/// <summary>
/// Gets or sets the tooltip text.
/// </summary>
/// <value>The tooltip text.</value>
[DefaultValue ("")]
public string TooltipText {
get { return Backend.TooltipText ?? ""; }
set { Backend.TooltipText = value; }
}
/// <summary>
/// Gets or sets the cursor shape to be used when the mouse is over the widget
/// </summary>
/// <value>
/// The cursor.
/// </value>
[DefaultValue ("")]
public CursorType Cursor {
get { return cursor ?? CursorType.Arrow; }
set {
cursor = value;
Backend.SetCursor (value);
}
}
/// <summary>
/// Determines the value whether the cursor is set and should be serialized.
/// </summary>
/// <returns><c>true</c>, if the cursor should be serialized , <c>false</c> otherwise.</returns>
public bool ShouldSerializeCursor ()
{
return Cursor != CursorType.Arrow;
}
/// <summary>
/// Converts widget relative coordinates to screen coordinates.
/// </summary>
/// <returns>The screen coordinates.</returns>
/// <param name="widgetCoordinates">The relative widget coordinates.</param>
public Point ConvertToScreenCoordinates (Point widgetCoordinates)
{
return Backend.ConvertToScreenCoordinates (widgetCoordinates);
}
/// <summary>
/// Gets the bounds of the widget in screen coordinates
/// </summary>
/// <value>
/// The widget bounds
/// </value>
public Rectangle ScreenBounds {
get { return new Rectangle (ConvertToScreenCoordinates (new Point (0,0)), Size); }
}
/// <summary>
/// Determines a value whether the widgets parent should be serialized
/// </summary>
/// <returns><c>true</c>, if parent should be serialized, <c>false</c> otherwise.</returns>
public bool ShouldSerializeParent ()
{
return false;
}
/// <summary>
/// Sets the focus on this widget.
/// </summary>
public void SetFocus ()
{
Backend.SetFocus ();
}
/// <summary>
/// Creates a new drag operation originating from this widget.
/// </summary>
/// <returns>The new drag operation.</returns>
public DragOperation CreateDragOperation ()
{
currentDragOperation = new DragOperation (this);
return currentDragOperation;
}
/// <summary>
/// Starts a drag operation with the specified drag start arguments.
/// </summary>
/// <param name="sdata">The drag start arguments to start the drag with.</param>
internal void DragStart (DragStartData sdata)
{
Backend.DragStart (sdata);
}
/// <summary>
/// Sets this widget as a potential drop destination.
/// </summary>
/// <param name='types'>Types of data that can be dropped on this widget.</param>
public void SetDragDropTarget (params TransferDataType[] types)
{
Backend.SetDragTarget (types, DragDropAction.All);
}
/// <summary>
/// Sets this widget as a potential drop destination.
/// </summary>
/// <param name='types'>Types of data that can be dropped on this widget.</param>
public void SetDragDropTarget (params Type[] types)
{
Backend.SetDragTarget (types.Select (t => TransferDataType.FromType (t)).ToArray (), DragDropAction.All);
}
/// <summary>
/// Sets this widget as a potential drop destination.
/// </summary>
/// <param name='types'>Types of data that can be dropped on this widget.</param>
/// <param name='dragAction'>Bitmask of possible actions for a drop on this widget</param>
public void SetDragDropTarget (DragDropAction dragAction, params TransferDataType[] types)
{
Backend.SetDragTarget (types, dragAction);
}
/// <summary>
/// Sets this widget as a potential drop destination.
/// </summary>
/// <param name='types'>Types of data that can be dropped on this widget.</param>
/// <param name='dragAction'>Bitmask of possible actions for a drop on this widget</param>
public void SetDragDropTarget (DragDropAction dragAction, params Type[] types)
{
Backend.SetDragTarget (types.Select (t => TransferDataType.FromType (t)).ToArray(), dragAction);
}
/// <summary>
/// Sets up this widget so that XWT will start a drag operation when the user clicks and drags on this widget.
/// </summary>
/// <param name='types'>Types of data that can be dragged from this widget</param>
public void SetDragSource (params TransferDataType[] types)
{
Backend.SetDragSource (types, DragDropAction.All);
}
/// <summary>
/// Sets up this widget so that XWT will start a drag operation when the user clicks and drags on this widget.
/// </summary>
/// <param name='types'>Types of data that can be dragged from this widget</param>
public void SetDragSource (params Type[] types)
{
Backend.SetDragSource (types.Select (t => TransferDataType.FromType (t)).ToArray(), DragDropAction.All);
}
/// <summary>
/// Sets up this widget so that XWT will start a drag operation when the user clicks and drags on this widget.
/// </summary>
/// <param name='types'>Types of data that can be dragged from this widget</param>
/// <param name='dragAction'>Bitmask of possible actions for a drag from this widget</param>
public void SetDragSource (DragDropAction dragAction, params TransferDataType[] types)
{
Backend.SetDragSource (types, dragAction);
}
/// <summary>
/// Sets up this widget so that XWT will start a drag operation when the user clicks and drags on this widget.
/// </summary>
/// <param name='types'>Types of data that can be dragged from this widget</param>
/// <param name='dragAction'>Bitmask of possible actions for a drag from this widget</param>
public void SetDragSource (DragDropAction dragAction, params Type[] types)
{
Backend.SetDragSource (types.Select (t => TransferDataType.FromType (t)).ToArray(), dragAction);
}
/// <summary>
/// Gets a value indicating whether this <see cref="Xwt.Widget"/> supports custom scrolling.
/// </summary>
/// <value><c>true</c> if this widget supports custom scrolling; otherwise, <c>false</c>.</value>
internal protected virtual bool SupportsCustomScrolling {
get { return false; }
}
/// <summary>
/// Sets the scroll adjustments for custom scrolling.
/// </summary>
/// <param name="horizontal">The horizontal adjustment backend.</param>
/// <param name="vertical">The vertical adjustment backend.</param>
protected virtual void SetScrollAdjustments (ScrollAdjustment horizontal, ScrollAdjustment vertical)
{
}
/// <summary>
/// Raises the DragOverCheck event, when the mouse is moved over the widget in a drag&drop operation.
/// </summary>
/// <param name="args">The drag over check event arguments.</param>
/// <remarks>
/// Override <see cref="OnDragOverCheck"/> to handle the event internally and call
/// <see cref="Xwt.Widget.OnDragOverCheck"/> to finally raise the event.
/// The event will be enabled in the backend automatically, if <see cref="Xwt.Widget.OnDragOverCheck"/>
/// is overriden.
/// This event arguments provide information about the type of the data that is going
/// to be dropped, but not the actual data. Set <see cref="Xwt.DragOverCheckEventArgs.AllowedAction"/>
/// to the allowed action for this widget, or to <see cref="Xwt.DragDropAction.None"/> if no
/// dropping is allowed.
/// Do not set the value or set it to <see cref="Xwt.DragDropAction.Default"/> and override <see cref="OnDragOver"/>
/// to analyse the actual data transferred by the drag operation.
/// </remarks>
internal protected virtual void OnDragOverCheck (DragOverCheckEventArgs args)
{
if (dragOverCheck != null)
dragOverCheck (this, args);
}
/// <summary>
/// Raises the DragOver event, when the mouse is moved over the widget in a drag&drop operation.
/// </summary>
/// <param name="args">The drag over event arguments.</param>
/// <remarks>
/// Override <see cref="OnDragOver"/> to handle the event internally and call the base
/// <see cref="Xwt.Widget.OnDragOver"/> to finally raise the event.
/// The event will be enabled in the backend automatically, if <see cref="Xwt.Widget.OnDragOver"/>
/// is overridden.
/// This event arguments provide information about the actual data that is going
/// to be dropped. Set <see cref="Xwt.DragOverEventArgs.AllowedAction"/> to the
/// allowed action for this widget, or to <see cref="Xwt.DragDropAction.None"/> if no
/// dropping is allowed.
/// </remarks>
internal protected virtual void OnDragOver (DragOverEventArgs args)
{
if (dragOver != null)
dragOver (this, args);
}
/// <summary>
/// Raises the DragDropCheck event to check if a drop operation is allowed on the widget.
/// </summary>
/// <param name="args">The drag check event arguments.</param>
/// <remarks>
/// Override <see cref="OnDragDropCheck"/> to handle the event internally and call the base
/// <see cref="Xwt.Widget.OnDragDropCheck"/> to finally raise the event.
/// The event will be enabled in the backend automatically, if <see cref="Xwt.Widget.OnDragDropCheck"/>
/// is overridden.
/// This event arguments provide information about the type of the data that is going
/// to be dropped, but not the actual data. Set <see cref="Xwt.DragCheckEventArgs.Result"/> to
/// <see cref="DragDropResult.Success"/> to finish the drop action, or <see cref="DragDropResult.Canceled"/>
/// to abort it.
/// To request the transferred data do not set the result value or set it to <see cref="Xwt.DragDropAction.None"/>
/// and override <see cref="Xwt.Widget.OnDragDrop"/> to handle the dropped data.
/// </remarks>
internal protected virtual void OnDragDropCheck (DragCheckEventArgs args)
{