-
-
Notifications
You must be signed in to change notification settings - Fork 335
/
WinConversions.cs
902 lines (821 loc) · 24.1 KB
/
WinConversions.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
using Eto.WinForms.Drawing;
using sdp = System.Drawing.Printing;
using Eto.WinForms.Forms.Printing;
using Eto.WinForms.Forms;
namespace Eto.WinForms
{
public static partial class WinConversions
{
public static DialogResult ToEto(this swf.DialogResult result)
{
switch (result)
{
case swf.DialogResult.OK:
return DialogResult.Ok;
case swf.DialogResult.Cancel:
return DialogResult.Cancel;
case swf.DialogResult.Yes:
return DialogResult.Yes;
case swf.DialogResult.No:
return DialogResult.No;
case swf.DialogResult.Abort:
return DialogResult.Cancel;
case swf.DialogResult.Ignore:
return DialogResult.Ignore;
case swf.DialogResult.Retry:
return DialogResult.Retry;
case swf.DialogResult.None:
return DialogResult.None;
default:
return DialogResult.None;
}
}
public static sd.Imaging.ImageFormat ToSD(this ImageFormat format)
{
switch (format)
{
case ImageFormat.Jpeg:
return sd.Imaging.ImageFormat.Jpeg;
case ImageFormat.Bitmap:
return sd.Imaging.ImageFormat.Bmp;
case ImageFormat.Gif:
return sd.Imaging.ImageFormat.Gif;
case ImageFormat.Tiff:
return sd.Imaging.ImageFormat.Tiff;
case ImageFormat.Png:
return sd.Imaging.ImageFormat.Png;
default:
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Invalid format specified"));
}
}
public static ImageInterpolation ToEto(this sd2.InterpolationMode value)
{
switch (value)
{
case sd2.InterpolationMode.NearestNeighbor:
return ImageInterpolation.None;
case sd2.InterpolationMode.Low:
return ImageInterpolation.Low;
case sd2.InterpolationMode.High:
return ImageInterpolation.Medium;
case sd2.InterpolationMode.HighQualityBilinear:
return ImageInterpolation.High;
case sd2.InterpolationMode.Default:
return ImageInterpolation.Default;
default:
throw new NotSupportedException();
}
}
public static sd2.InterpolationMode ToSD(this ImageInterpolation value)
{
switch (value)
{
case ImageInterpolation.Default:
return sd2.InterpolationMode.High;
case ImageInterpolation.None:
return sd2.InterpolationMode.NearestNeighbor;
case ImageInterpolation.Low:
return sd2.InterpolationMode.Low;
case ImageInterpolation.Medium:
return sd2.InterpolationMode.High;
case ImageInterpolation.High:
return sd2.InterpolationMode.HighQualityBilinear;
default:
throw new NotSupportedException();
}
}
public static sd.FontStyle ToSD(this FontStyle style)
{
sd.FontStyle ret = sd.FontStyle.Regular;
if (style.HasFlag(FontStyle.Bold))
ret |= sd.FontStyle.Bold;
if (style.HasFlag(FontStyle.Italic))
ret |= sd.FontStyle.Italic;
return ret;
}
public static sd.FontStyle ToSD(this FontDecoration decoration)
{
sd.FontStyle ret = sd.FontStyle.Regular;
if (decoration.HasFlag(FontDecoration.Underline))
ret |= sd.FontStyle.Underline;
if (decoration.HasFlag(FontDecoration.Strikethrough))
ret |= sd.FontStyle.Strikeout;
return ret;
}
public static sdp.PrintRange ToSDP(this PrintSelection value)
{
switch (value)
{
case PrintSelection.AllPages:
return sdp.PrintRange.AllPages;
case PrintSelection.SelectedPages:
return sdp.PrintRange.SomePages;
case PrintSelection.Selection:
return sdp.PrintRange.Selection;
default:
throw new NotSupportedException();
}
}
public static PrintSelection ToEto(this sdp.PrintRange value)
{
switch (value)
{
case sdp.PrintRange.AllPages:
return PrintSelection.AllPages;
case sdp.PrintRange.SomePages:
return PrintSelection.SelectedPages;
case sdp.PrintRange.Selection:
return PrintSelection.Selection;
default:
throw new NotSupportedException();
}
}
public static FontStyle ToEtoStyle(this sd.FontStyle style)
{
var ret = FontStyle.None;
if (style.HasFlag(sd.FontStyle.Bold))
ret |= FontStyle.Bold;
if (style.HasFlag(sd.FontStyle.Italic))
ret |= FontStyle.Italic;
return ret;
}
public static FontDecoration ToEtoDecoration(this sd.FontStyle style)
{
var ret = FontDecoration.None;
if (style.HasFlag(sd.FontStyle.Underline))
ret |= FontDecoration.Underline;
if (style.HasFlag(sd.FontStyle.Strikeout))
ret |= FontDecoration.Strikethrough;
return ret;
}
public static sd.Graphics ToSD(this Graphics graphics)
{
var h = (GraphicsHandler)graphics.Handler;
return h.Control;
}
public static sd.Image ToSD(this Image image, int? size = null)
{
if (image == null)
return null;
var h = (IWindowsImageSource)image.Handler;
return h.GetImageWithSize(size);
}
public static Icon ToEto(this sd.Icon icon)
{
return new Icon(new IconHandler(icon));
}
public static sd.Image ToSD(this Image image, Size? size)
{
if (image == null)
return null;
var h = (IWindowsImageSource)image.Handler;
return h.GetImageWithSize(size);
}
public static sd.Font ToSD(this Font font)
{
if (font == null)
return null;
return ((IWindowsFontSource)font.Handler).GetFont();
}
public static sd.FontFamily ToSD(this FontFamily family)
{
if (family == null)
return null;
return ((FontFamilyHandler)family.Handler).Control;
}
public static sd.FontStyle ToSD(this FontTypeface typeface)
{
if (typeface == null)
return sd.FontStyle.Regular;
return FontTypefaceHandler.GetControl(typeface);
}
public static sd.Font ToSDFont(this FontTypeface typeface, float size)
{
var typefaceHandler = typeface?.Handler as FontTypefaceHandler;
if (typefaceHandler == null)
return null;
return new sd.Font(typefaceHandler.SDFontFamily, size, typeface.ToSD());
}
public static sd.Font ToSD(this SystemFont systemFont)
{
switch (systemFont)
{
case SystemFont.Default:
return sd.SystemFonts.DefaultFont;
case SystemFont.User:
return sd.SystemFonts.DefaultFont;
case SystemFont.Bold:
return new sd.Font(sd.SystemFonts.DefaultFont, sd.FontStyle.Bold);
case SystemFont.TitleBar:
return sd.SystemFonts.CaptionFont;
case SystemFont.ToolTip:
return sd.SystemFonts.DefaultFont;
case SystemFont.Label:
return sd.SystemFonts.DialogFont;
case SystemFont.MenuBar:
return sd.SystemFonts.MenuFont;
case SystemFont.Menu:
return sd.SystemFonts.MenuFont;
case SystemFont.Message:
return sd.SystemFonts.MessageBoxFont;
case SystemFont.Palette:
return sd.SystemFonts.DialogFont;
case SystemFont.StatusBar:
return sd.SystemFonts.StatusFont;
default:
throw new NotSupportedException();
}
}
public static Font ToEto(this sd.Font font)
{
return font == null ? null : new Font(new FontHandler(font));
}
public static FontFamily ToEto(this sd.FontFamily family)
{
return family == null ? null : new FontFamily(new FontFamilyHandler(family));
}
/// <summary>
/// Convert native graphics to eto wrapper
/// </summary>
/// <param name="g">Native graphics</param>
/// <param name="dispose">Pass ownership and dispose native graphics in Dispose</param>
/// <returns>The wrapper</returns>
public static Graphics ToEto(this sd.Graphics g, bool dispose)
{
return new Graphics(new GraphicsHandler(g, dispose));
}
public static sd2.PixelOffsetMode ToSD(this PixelOffsetMode mode)
{
switch (mode)
{
case PixelOffsetMode.None:
return sd2.PixelOffsetMode.None;
case PixelOffsetMode.Half:
return sd2.PixelOffsetMode.Half;
case PixelOffsetMode.Aligned:
return sd2.PixelOffsetMode.None;
default:
throw new NotSupportedException();
}
}
public static PixelOffsetMode ToEto(this sd2.PixelOffsetMode mode)
{
switch (mode)
{
case sd2.PixelOffsetMode.None:
return PixelOffsetMode.None;
case sd2.PixelOffsetMode.Half:
return PixelOffsetMode.Half;
default:
throw new NotSupportedException();
}
}
public static sd2.Matrix ToSD(this IMatrix m)
{
return (sd2.Matrix)m.ControlObject;
}
public static IMatrix ToEto(this sd2.Matrix matrix)
{
return new MatrixHandler(matrix);
}
public static ITreeItem ToEto(this swf.TreeNode treeNode)
{
return
treeNode != null
? treeNode.Tag as ITreeItem
: null;
}
public static sd.Pen ToSD(this Pen pen, RectangleF bounds)
{
return ((PenHandler)pen.Handler).GetPen(pen, bounds);
}
public static sd.Brush ToSD(this Brush brush, RectangleF bounds)
{
return ((BrushHandler)brush.Handler).GetBrush(brush, bounds);
}
public static sd2.LineJoin ToSD(this PenLineJoin value)
{
switch (value)
{
case PenLineJoin.Miter:
return sd2.LineJoin.MiterClipped;
case PenLineJoin.Bevel:
return sd2.LineJoin.Bevel;
case PenLineJoin.Round:
return sd2.LineJoin.Round;
default:
throw new NotSupportedException();
}
}
public static PenLineJoin ToEto(this sd2.LineJoin value)
{
switch (value)
{
case sd2.LineJoin.Bevel:
return PenLineJoin.Bevel;
case sd2.LineJoin.Miter:
return PenLineJoin.Miter;
case sd2.LineJoin.Round:
return PenLineJoin.Round;
default:
throw new NotSupportedException();
}
}
public static sd2.LineCap ToSD(this PenLineCap value)
{
switch (value)
{
case PenLineCap.Butt:
return sd2.LineCap.Flat;
case PenLineCap.Round:
return sd2.LineCap.Round;
case PenLineCap.Square:
return sd2.LineCap.Square;
default:
throw new NotSupportedException();
}
}
public static PenLineCap ToEto(this sd2.LineCap value)
{
switch (value)
{
case sd2.LineCap.Flat:
return PenLineCap.Butt;
case sd2.LineCap.Round:
return PenLineCap.Round;
case sd2.LineCap.Square:
return PenLineCap.Square;
default:
throw new NotSupportedException();
}
}
public static sd2.GraphicsPath ToSD(this IGraphicsPath path)
{
return (sd2.GraphicsPath)path.ControlObject;
}
public static sd2.WrapMode ToSD(this GradientWrapMode wrap)
{
switch (wrap)
{
case GradientWrapMode.Reflect:
return sd2.WrapMode.TileFlipXY;
case GradientWrapMode.Repeat:
return sd2.WrapMode.Tile;
case GradientWrapMode.Pad:
return sd2.WrapMode.Clamp;
default:
throw new NotSupportedException();
}
}
public static GradientWrapMode ToEto(this sd2.WrapMode wrapMode)
{
switch (wrapMode)
{
case sd2.WrapMode.TileFlipXY:
return GradientWrapMode.Reflect;
case sd2.WrapMode.Tile:
return GradientWrapMode.Repeat;
case sd2.WrapMode.Clamp:
return GradientWrapMode.Pad;
default:
throw new NotSupportedException();
}
}
public static int BitsPerPixel(this sdi.PixelFormat format)
{
switch (format)
{
case sdi.PixelFormat.Format1bppIndexed:
return 1;
case sdi.PixelFormat.Format4bppIndexed:
return 4;
case sdi.PixelFormat.Format8bppIndexed:
return 8;
case sdi.PixelFormat.Format24bppRgb:
return 24;
case sdi.PixelFormat.Format32bppArgb:
case sdi.PixelFormat.Format32bppPArgb:
case sdi.PixelFormat.Format32bppRgb:
return 32;
default:
throw new NotSupportedException();
}
}
public static swf.TextImageRelation ToSD(this ButtonImagePosition value)
{
switch (value)
{
case ButtonImagePosition.Left:
return swf.TextImageRelation.ImageBeforeText;
case ButtonImagePosition.Right:
return swf.TextImageRelation.TextBeforeImage;
case ButtonImagePosition.Above:
return swf.TextImageRelation.ImageAboveText;
case ButtonImagePosition.Below:
return swf.TextImageRelation.TextAboveImage;
case ButtonImagePosition.Overlay:
return swf.TextImageRelation.Overlay;
default:
throw new NotSupportedException();
}
}
public static ButtonImagePosition ToEto(this swf.TextImageRelation value)
{
switch (value)
{
case swf.TextImageRelation.ImageAboveText:
return ButtonImagePosition.Above;
case swf.TextImageRelation.ImageBeforeText:
return ButtonImagePosition.Left;
case swf.TextImageRelation.Overlay:
return ButtonImagePosition.Overlay;
case swf.TextImageRelation.TextAboveImage:
return ButtonImagePosition.Below;
case swf.TextImageRelation.TextBeforeImage:
return ButtonImagePosition.Left;
default:
throw new NotSupportedException();
}
}
public static bool IsResizable(this swf.FormBorderStyle style)
{
switch (style)
{
case swf.FormBorderStyle.Fixed3D:
case swf.FormBorderStyle.FixedDialog:
case swf.FormBorderStyle.FixedSingle:
case swf.FormBorderStyle.FixedToolWindow:
case swf.FormBorderStyle.None:
return false;
case swf.FormBorderStyle.Sizable:
case swf.FormBorderStyle.SizableToolWindow:
return true;
default:
throw new NotSupportedException();
}
}
public static WindowStyle ToEto(this swf.FormBorderStyle style)
{
switch (style)
{
case swf.FormBorderStyle.SizableToolWindow:
case swf.FormBorderStyle.FixedToolWindow:
return WindowStyle.Utility;
case swf.FormBorderStyle.Fixed3D:
case swf.FormBorderStyle.Sizable:
case swf.FormBorderStyle.FixedDialog:
return WindowStyle.Default;
case swf.FormBorderStyle.None:
return WindowStyle.None;
default:
throw new NotSupportedException();
}
}
public static swf.FormBorderStyle ToSWF(this WindowStyle style, bool resizable, swf.FormBorderStyle defaultStyle)
{
switch (style)
{
case WindowStyle.Default:
return resizable ? swf.FormBorderStyle.Sizable : defaultStyle;
case WindowStyle.None:
return swf.FormBorderStyle.None;
case WindowStyle.Utility:
return resizable ? swf.FormBorderStyle.SizableToolWindow : swf.FormBorderStyle.FixedToolWindow;
default:
throw new NotSupportedException();
}
}
public static CellStates ToEto(this swf.DataGridViewElementStates state)
{
if (state.HasFlag(swf.DataGridViewElementStates.Selected))
return CellStates.Selected;
return CellStates.None;
}
public static PrintSettings ToEto(this sdp.PrinterSettings settings)
{
return settings == null ? null : new PrintSettings(new PrintSettingsHandler(settings));
}
public static sdp.PrinterSettings ToSD(this PrintSettings settings)
{
if (settings == null)
return PrintSettingsHandler.DefaultSettings();
return ((PrintSettingsHandler)settings.Handler).Control;
}
public static sdp.PrintDocument ToSD(this PrintDocument document)
{
return document == null ? null : ((PrintDocumentHandler)document.Handler).Control;
}
public static Range<DateTime> ToEto(this swf.SelectionRange range)
{
return new Range<DateTime>(range.Start, range.End);
}
public static swf.SelectionRange ToSWF(this Range<DateTime> range)
{
return new swf.SelectionRange(range.Start, range.End);
}
public static swf.HorizontalAlignment ToSWF(this TextAlignment align)
{
switch (align)
{
case TextAlignment.Left:
return swf.HorizontalAlignment.Left;
case TextAlignment.Center:
return swf.HorizontalAlignment.Center;
case TextAlignment.Right:
return swf.HorizontalAlignment.Right;
default:
throw new NotSupportedException();
}
}
public static TextAlignment ToEtoTextAlignment(this swf.DataGridViewContentAlignment existing)
{
switch (existing)
{
default:
case swf.DataGridViewContentAlignment.NotSet:
case swf.DataGridViewContentAlignment.TopLeft:
case swf.DataGridViewContentAlignment.MiddleLeft:
case swf.DataGridViewContentAlignment.BottomLeft:
return TextAlignment.Left;
case swf.DataGridViewContentAlignment.TopCenter:
case swf.DataGridViewContentAlignment.MiddleCenter:
case swf.DataGridViewContentAlignment.BottomCenter:
return TextAlignment.Center;
case swf.DataGridViewContentAlignment.TopRight:
case swf.DataGridViewContentAlignment.MiddleRight:
case swf.DataGridViewContentAlignment.BottomRight:
return TextAlignment.Right;
}
}
public static swf.DataGridViewContentAlignment ToSWFGridViewContentAlignment(this TextAlignment alignment, VerticalAlignment vertical = VerticalAlignment.Center)
{
switch (alignment)
{
default:
case TextAlignment.Left:
switch (vertical)
{
case VerticalAlignment.Top:
return swf.DataGridViewContentAlignment.TopLeft;
default:
case VerticalAlignment.Center:
return swf.DataGridViewContentAlignment.MiddleLeft;
case VerticalAlignment.Bottom:
return swf.DataGridViewContentAlignment.BottomLeft;
}
case TextAlignment.Center:
switch (vertical)
{
case VerticalAlignment.Top:
return swf.DataGridViewContentAlignment.TopCenter;
default:
case VerticalAlignment.Center:
return swf.DataGridViewContentAlignment.MiddleCenter;
case VerticalAlignment.Bottom:
return swf.DataGridViewContentAlignment.BottomCenter;
}
case TextAlignment.Right:
switch (vertical)
{
case VerticalAlignment.Top:
return swf.DataGridViewContentAlignment.TopRight;
default:
case VerticalAlignment.Center:
return swf.DataGridViewContentAlignment.MiddleRight;
case VerticalAlignment.Bottom:
return swf.DataGridViewContentAlignment.BottomRight;
}
}
}
public static VerticalAlignment ToEtoVerticalAlignment(this swf.DataGridViewContentAlignment existing)
{
switch (existing)
{
default:
case swf.DataGridViewContentAlignment.NotSet:
case swf.DataGridViewContentAlignment.TopLeft:
case swf.DataGridViewContentAlignment.MiddleLeft:
case swf.DataGridViewContentAlignment.BottomLeft:
return VerticalAlignment.Top;
case swf.DataGridViewContentAlignment.TopCenter:
case swf.DataGridViewContentAlignment.MiddleCenter:
case swf.DataGridViewContentAlignment.BottomCenter:
return VerticalAlignment.Center;
case swf.DataGridViewContentAlignment.TopRight:
case swf.DataGridViewContentAlignment.MiddleRight:
case swf.DataGridViewContentAlignment.BottomRight:
return VerticalAlignment.Bottom;
}
}
public static swf.DataGridViewContentAlignment ToSWF(TextAlignment textAlignment, VerticalAlignment verticalAlignment)
{
switch (verticalAlignment)
{
case VerticalAlignment.Stretch:
case VerticalAlignment.Top:
switch (textAlignment)
{
case TextAlignment.Left:
return swf.DataGridViewContentAlignment.TopLeft;
case TextAlignment.Center:
return swf.DataGridViewContentAlignment.TopCenter;
case TextAlignment.Right:
return swf.DataGridViewContentAlignment.TopRight;
default:
throw new ArgumentOutOfRangeException();
}
case VerticalAlignment.Center:
switch (textAlignment)
{
case TextAlignment.Left:
return swf.DataGridViewContentAlignment.MiddleLeft;
case TextAlignment.Center:
return swf.DataGridViewContentAlignment.MiddleCenter;
case TextAlignment.Right:
return swf.DataGridViewContentAlignment.MiddleRight;
default:
throw new ArgumentOutOfRangeException();
}
case VerticalAlignment.Bottom:
switch (textAlignment)
{
case TextAlignment.Left:
return swf.DataGridViewContentAlignment.BottomLeft;
case TextAlignment.Center:
return swf.DataGridViewContentAlignment.BottomCenter;
case TextAlignment.Right:
return swf.DataGridViewContentAlignment.BottomRight;
default:
throw new ArgumentOutOfRangeException();
}
default:
throw new ArgumentOutOfRangeException();
}
}
public static TextAlignment ToEto(this swf.HorizontalAlignment align)
{
switch (align)
{
case swf.HorizontalAlignment.Center:
return TextAlignment.Center;
case swf.HorizontalAlignment.Left:
return TextAlignment.Left;
case swf.HorizontalAlignment.Right:
return TextAlignment.Right;
default:
throw new NotSupportedException();
}
}
public static swf.Form ToSWF(this Window window)
{
if (window == null)
return null;
var handler = window.Handler as Forms.IWindowHandler;
if (handler != null)
return handler.Win32Window as swf.Form;
return null;
}
public static swf.TabAlignment ToSWF(this DockPosition position)
{
switch (position)
{
case DockPosition.Top:
return swf.TabAlignment.Top;
case DockPosition.Left:
return swf.TabAlignment.Left;
case DockPosition.Right:
return swf.TabAlignment.Right;
case DockPosition.Bottom:
return swf.TabAlignment.Bottom;
default:
throw new NotSupportedException();
}
}
public static DockPosition ToEto(this swf.TabAlignment alignment)
{
switch (alignment)
{
case swf.TabAlignment.Top:
return DockPosition.Top;
case swf.TabAlignment.Bottom:
return DockPosition.Bottom;
case swf.TabAlignment.Left:
return DockPosition.Left;
case swf.TabAlignment.Right:
return DockPosition.Right;
default:
throw new NotSupportedException();
}
}
public static Screen ToEto(this swf.Screen screen)
{
if (screen == null)
return null;
return new Screen(new ScreenHandler(screen));
}
public static BorderType ToEto(this swf.BorderStyle border)
{
switch (border)
{
case swf.BorderStyle.FixedSingle:
return BorderType.Line;
case swf.BorderStyle.None:
return BorderType.None;
case swf.BorderStyle.Fixed3D:
return BorderType.Bezel;
default:
throw new NotSupportedException();
}
}
public static swf.BorderStyle ToSWF(this BorderType border)
{
switch (border)
{
case BorderType.Bezel:
return swf.BorderStyle.Fixed3D;
case BorderType.Line:
return swf.BorderStyle.FixedSingle;
case BorderType.None:
return swf.BorderStyle.None;
default:
throw new NotSupportedException();
}
}
public static Bitmap ToEto(this sd.Bitmap sdbitmap)
{
if (sdbitmap == null)
return null;
return new Bitmap(new BitmapHandler(sdbitmap));
}
public static swf.DragDropEffects ToSwf(this DragEffects action)
{
var resultAction = swf.DragDropEffects.None;
if (action.HasFlag(DragEffects.Copy))
resultAction |= swf.DragDropEffects.Copy;
if (action.HasFlag(DragEffects.Move))
resultAction |= swf.DragDropEffects.Move;
if (action.HasFlag(DragEffects.Link))
resultAction |= swf.DragDropEffects.Link;
return resultAction;
}
public static DragEffects ToEto(this swf.DragDropEffects effects)
{
var action = DragEffects.None;
if (effects.HasFlag(swf.DragDropEffects.Copy))
action |= DragEffects.Copy;
if (effects.HasFlag(swf.DragDropEffects.Move))
action |= DragEffects.Move;
if (effects.HasFlag(swf.DragDropEffects.Link))
action |= DragEffects.Link;
return action;
}
public static swf.DataObject ToSwf(this DataObject data) => DataObjectHandler.GetControl(data);
public static DataObject ToEto(this swf.IDataObject data) => new DataObject(new DataObjectHandler(data));
public static Keys GetEtoModifiers(this swf.DragEventArgs e)
{
var modifiers = Keys.None;
if ((e.KeyState & 4) == 4)
modifiers |= Keys.Shift;
if ((e.KeyState & 8) == 8)
modifiers |= Keys.Control;
if ((e.KeyState & 32) == 32)
modifiers |= Keys.Alt;
return modifiers;
}
public static MouseButtons GetEtoButtons(this swf.DragEventArgs e)
{
var buttons = MouseButtons.None;
if ((e.KeyState & 1) == 1)
buttons |= MouseButtons.Primary;
if ((e.KeyState & 2) == 2)
buttons |= MouseButtons.Primary;
if ((e.KeyState & 16) == 16)
buttons |= MouseButtons.Middle;
return buttons;
}
public static swf.Cursor ToSwf(this Cursor cursor) => CursorHandler.GetControl(cursor);
public static bool IsPremultiplied(this sdi.PixelFormat format)
{
return format == sdi.PixelFormat.Format32bppPArgb
|| format == sdi.PixelFormat.Format64bppPArgb;
}
public static Image ToEto(this sd.Image image)
{
if (image is sd.Bitmap bitmap)
return new Bitmap(new BitmapHandler(bitmap));
throw new NotSupportedException();
}
public static GridCellType ToEto(this swf.DataGridViewHitTestType type)
{
switch (type)
{
case swf.DataGridViewHitTestType.ColumnHeader:
return GridCellType.ColumnHeader;
case swf.DataGridViewHitTestType.Cell:
return GridCellType.Data;
default:
return GridCellType.None;
}
}
}
}