Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1452 chris 1
#region License
2
//
3
// The Open Toolkit Library License
4
//
5
// Copyright (c) 2006 - 2009 the Open Toolkit library.
6
//
7
// Permission is hereby granted, free of charge, to any person obtaining a copy
8
// of this software and associated documentation files (the "Software"), to deal
9
// in the Software without restriction, including without limitation the rights to 
10
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11
// the Software, and to permit persons to whom the Software is furnished to do
12
// so, subject to the following conditions:
13
//
14
// The above copyright notice and this permission notice shall be included in all
15
// copies or substantial portions of the Software.
16
//
17
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
// OTHER DEALINGS IN THE SOFTWARE.
25
//
26
#endregion
27
 
28
using System;
29
using System.ComponentModel;
30
using System.Drawing;
31
using OpenTK.Graphics;
32
using OpenTK.Input;
33
using OpenTK.Platform;
34
 
35
namespace OpenTK
36
{
37
 
38
    /// <summary>
39
    /// Instances of this class implement the <see cref="OpenTK.INativeWindow"/> interface on the current platform.
40
    /// </summary>
41
    public class NativeWindow : INativeWindow
42
    {
43
        #region --- Fields ---
44
 
45
        private readonly GameWindowFlags options;
46
 
47
        private readonly DisplayDevice device;
48
 
49
        private readonly INativeWindow implementation;
50
 
51
        private bool disposed, events;
52
 
53
        #endregion
54
 
55
        #region --- Contructors ---
56
 
57
        /// <summary>Constructs a new NativeWindow with default attributes without enabling events.</summary>
58
        public NativeWindow()
59
            : this(640, 480, "OpenTK Native Window", GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default) { }
60
 
61
        // TODO: Remaining constructors.
62
 
63
        /// <summary>Constructs a new centered NativeWindow with the specified attributes.</summary>
64
        /// <param name="width">The width of the NativeWindow in pixels.</param>
65
        /// <param name="height">The height of the NativeWindow in pixels.</param>
66
        /// <param name="title">The title of the NativeWindow.</param>
67
        /// <param name="options">GameWindow options specifying window appearance and behavior.</param>
68
        /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the NativeWindow.</param>
69
        /// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the NativeWindow in.</param>
70
        /// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception>
71
        /// <exception cref="System.ArgumentNullException">If mode or device is null.</exception>
72
        public NativeWindow(int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
73
            : this(device.Bounds.Left + (device.Bounds.Width - width) / 2,
74
                   device.Bounds.Top + (device.Bounds.Height - height) / 2,
75
                   width, height, title, options, mode, device) { }
76
 
77
        /// <summary>Constructs a new NativeWindow with the specified attributes.</summary>
78
        /// <param name="x">Horizontal screen space coordinate of the NativeWindow's origin.</param>
79
        /// <param name="y">Vertical screen space coordinate of the NativeWindow's origin.</param>
80
        /// <param name="width">The width of the NativeWindow in pixels.</param>
81
        /// <param name="height">The height of the NativeWindow in pixels.</param>
82
        /// <param name="title">The title of the NativeWindow.</param>
83
        /// <param name="options">GameWindow options specifying window appearance and behavior.</param>
84
        /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the NativeWindow.</param>
85
        /// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the NativeWindow in.</param>
86
        /// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception>
87
        /// <exception cref="System.ArgumentNullException">If mode or device is null.</exception>
88
        public NativeWindow(int x, int y, int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
89
        {
90
            // TODO: Should a constraint be added for the position?
91
            if (width < 1)
92
                throw new ArgumentOutOfRangeException("width", "Must be greater than zero.");
93
            if (height < 1)
94
                throw new ArgumentOutOfRangeException("height", "Must be greater than zero.");
95
            if (mode == null)
96
                throw new ArgumentNullException("mode");
97
            if (device == null)
98
                throw new ArgumentNullException("device");
99
 
100
            this.options = options;
101
            this.device = device;
102
 
103
            implementation = Factory.Default.CreateNativeWindow(x, y, width, height, title, mode, options, this.device);
104
 
105
            if ((options & GameWindowFlags.Fullscreen) != 0)
106
            {
107
                this.device.ChangeResolution(width, height, mode.ColorFormat.BitsPerPixel, 0);
108
                WindowState = WindowState.Fullscreen;
109
            }
110
        }
111
 
112
        #endregion
113
 
114
        #region --- INativeWindow Members ---
115
 
116
        #region Methods
117
 
118
        #region Close
119
 
120
        /// <summary>
121
        /// Closes the NativeWindow.
122
        /// </summary>
123
        public void Close()
124
        {
125
            EnsureUndisposed();
126
            implementation.Close();
127
        }
128
 
129
        #endregion
130
 
131
        #region PointToClient
132
 
133
        /// <summary>
134
        /// Transforms the specified point from screen to client coordinates. 
135
        /// </summary>
136
        /// <param name="point">
137
        /// A <see cref="System.Drawing.Point"/> to transform.
138
        /// </param>
139
        /// <returns>
140
        /// The point transformed to client coordinates.
141
        /// </returns>
142
        public Point PointToClient(Point point)
143
        {
144
            return implementation.PointToClient(point);
145
        }
146
 
147
        #endregion
148
 
149
        #region PointToScreen
150
 
151
        /// <summary>
152
        /// Transforms the specified point from client to screen coordinates.
153
        /// </summary>
154
        /// <param name="point">
155
        /// A <see cref="System.Drawing.Point"/> to transform.
156
        /// </param>
157
        /// <returns>
158
        /// The point transformed to screen coordinates.
159
        /// </returns>
160
        public Point PointToScreen(Point point)
161
        {
162
            // Here we use the fact that PointToClient just translates the point, and PointToScreen
163
            // should perform the inverse operation.
164
            Point trans = PointToClient(Point.Empty);
165
            point.X -= trans.X;
166
            point.Y -= trans.Y;
167
            return point;
168
        }
169
 
170
        #endregion
171
 
172
        #region ProcessEvents
173
 
174
        /// <summary>
175
        /// Processes operating system events until the NativeWindow becomes idle.
176
        /// </summary>
177
        public void ProcessEvents()
178
        {
179
            ProcessEvents(false);
180
        }
181
 
182
        #endregion
183
 
184
        #endregion
185
 
186
        #region Properties
187
 
188
        #region Bounds
189
 
190
        /// <summary>
191
        /// Gets or sets a <see cref="System.Drawing.Rectangle"/> structure that contains the external bounds of this window, in screen coordinates.
192
        /// External bounds include the title bar, borders and drawing area of the window.
193
        /// </summary>
194
        public Rectangle Bounds
195
        {
196
            get
197
            {
198
                EnsureUndisposed();
199
                return implementation.Bounds;
200
            }
201
            set
202
            {
203
                EnsureUndisposed();
204
                implementation.Bounds = value;
205
            }
206
        }
207
 
208
        #endregion
209
 
210
        #region ClientRectangle
211
 
212
        /// <summary>
213
        /// Gets or sets a <see cref="System.Drawing.Rectangle"/> structure that contains the internal bounds of this window, in client coordinates.
214
        /// The internal bounds include the drawing area of the window, but exclude the titlebar and window borders.
215
        /// </summary>
216
        public Rectangle ClientRectangle
217
        {
218
            get
219
            {
220
                EnsureUndisposed();
221
                return implementation.ClientRectangle;
222
            }
223
            set
224
            {
225
                EnsureUndisposed();
226
                implementation.ClientRectangle = value;
227
            }
228
        }
229
 
230
        #endregion
231
 
232
        #region ClientSize
233
 
234
        /// <summary>
235
        /// Gets or sets a <see cref="System.Drawing.Size"/> structure that contains the internal size this window.
236
        /// </summary>
237
        public Size ClientSize
238
        {
239
            get
240
            {
241
                EnsureUndisposed();
242
                return implementation.ClientSize;
243
            }
244
            set
245
            {
246
                EnsureUndisposed();
247
                implementation.ClientSize = value;
248
            }
249
        }
250
 
251
        #endregion
252
 
253
        #region Exists
254
 
255
        /// <summary>
256
        /// Gets a value indicating whether a render window exists.
257
        /// </summary>
258
        public bool Exists
259
        {
260
            get
261
            {
262
                return IsDisposed ? false : implementation.Exists; // TODO: Should disposed be ignored instead?
263
            }
264
        }
265
 
266
        #endregion
267
 
268
        #region Focused
269
 
270
        /// <summary>
271
        /// Gets a System.Boolean that indicates whether this NativeWindow has input focus.
272
        /// </summary>
273
        public bool Focused
274
        {
275
            get
276
            {
277
                EnsureUndisposed();
278
                return implementation.Focused;
279
            }
280
        }
281
 
282
        #endregion
283
 
284
        #region Height
285
 
286
        /// <summary>
287
        /// Gets or sets the external height of this window.
288
        /// </summary>
289
        public int Height
290
        {
291
            get
292
            {
293
                EnsureUndisposed();
294
                return implementation.Height;
295
            }
296
            set
297
            {
298
                EnsureUndisposed();
299
                implementation.Height = value;
300
            }
301
        }
302
 
303
        #endregion
304
 
305
        #region Icon
306
 
307
        /// <summary>
308
        /// Gets or sets the System.Drawing.Icon for this GameWindow.
309
        /// </summary>
310
        public Icon Icon
311
        {
312
            get
313
            {
314
                EnsureUndisposed();
315
                return implementation.Icon;
316
            }
317
            set
318
            {
319
                EnsureUndisposed();
320
                implementation.Icon = value;
321
            }
322
        }
323
 
324
        #endregion
325
 
326
        #region InputDriver
327
 
328
        /// <summary>
329
        /// This property is deprecated.
330
        /// </summary>
331
        [Obsolete]
332
        public IInputDriver InputDriver
333
        {
334
            get
335
            {
336
                EnsureUndisposed();
337
                return implementation.InputDriver;
338
            }
339
        }
340
 
341
        #endregion
342
 
343
        #region Location
344
 
345
        /// <summary>
346
        /// Gets or sets a <see cref="System.Drawing.Point"/> structure that contains the location of this window on the desktop.
347
        /// </summary>
348
        public Point Location
349
        {
350
            get
351
            {
352
                EnsureUndisposed();
353
                return implementation.Location;
354
            }
355
            set
356
            {
357
                EnsureUndisposed();
358
                implementation.Location = value;
359
            }
360
        }
361
 
362
        #endregion
363
 
364
        #region Size
365
 
366
        /// <summary>
367
        /// Gets or sets a <see cref="System.Drawing.Size"/> structure that contains the external size of this window.
368
        /// </summary>
369
        public Size Size
370
        {
371
            get
372
            {
373
                EnsureUndisposed();
374
                return implementation.Size;
375
            }
376
            set
377
            {
378
                EnsureUndisposed();
379
                implementation.Size = value;
380
            }
381
        }
382
 
383
        #endregion
384
 
385
        #region Title
386
 
387
        /// <summary>
388
        /// Gets or sets the NativeWindow title.
389
        /// </summary>
390
        public string Title
391
        {
392
            get
393
            {
394
                EnsureUndisposed();
395
                return implementation.Title;
396
            }
397
            set
398
            {
399
                EnsureUndisposed();
400
                implementation.Title = value;
401
            }
402
        }
403
 
404
        #endregion
405
 
406
        #region Visible
407
 
408
        /// <summary>
409
        /// Gets or sets a System.Boolean that indicates whether this NativeWindow is visible.
410
        /// </summary>
411
        public bool Visible
412
        {
413
            get
414
            {
415
                EnsureUndisposed();
416
                return implementation.Visible;
417
            }
418
            set
419
            {
420
                EnsureUndisposed();
421
                implementation.Visible = value;
422
            }
423
        }
424
 
425
        #endregion
426
 
427
        #region Width
428
 
429
        /// <summary>
430
        /// Gets or sets the external width of this window.
431
        /// </summary>
432
        public int Width
433
        {
434
            get
435
            {
436
                EnsureUndisposed();
437
                return implementation.Width;
438
            }
439
            set
440
            {
441
                EnsureUndisposed();
442
                implementation.Width = value;
443
            }
444
        }
445
 
446
        #endregion
447
 
448
        #region WindowBorder
449
 
450
        /// <summary>
451
        /// Gets or states the border of the NativeWindow.
452
        /// </summary>
453
        public WindowBorder WindowBorder
454
        {
455
            get
456
            {
457
                return implementation.WindowBorder;
458
            }
459
            set
460
            {
461
                implementation.WindowBorder = value;
462
            }
463
        }
464
 
465
        #endregion
466
 
467
        #region WindowInfo
468
 
469
        /// <summary>
470
        /// Gets the <see cref="OpenTK.Platform.IWindowInfo"/> of this window.
471
        /// </summary>
472
        public IWindowInfo WindowInfo
473
        {
474
            get
475
            {
476
                EnsureUndisposed();
477
                return implementation.WindowInfo;
478
            }
479
        }
480
 
481
        #endregion
482
 
483
        #region WindowState
484
 
485
        /// <summary>
486
        /// Gets or states the state of the NativeWindow.
487
        /// </summary>
488
        public virtual WindowState WindowState
489
        {
490
            get
491
            {
492
                return implementation.WindowState;
493
            }
494
            set
495
            {
496
                implementation.WindowState = value;
497
            }
498
        }
499
 
500
        #endregion
501
 
502
        #region X
503
 
504
        /// <summary>
505
        /// Gets or sets the horizontal location of this window on the desktop.
506
        /// </summary>
507
        public int X
508
        {
509
            get
510
            {
511
                EnsureUndisposed();
512
                return implementation.X;
513
            }
514
            set
515
            {
516
                EnsureUndisposed();
517
                implementation.X = value;
518
            }
519
        }
520
 
521
        #endregion
522
 
523
        #region Y
524
 
525
        /// <summary>
526
        /// Gets or sets the vertical location of this window on the desktop.
527
        /// </summary>
528
        public int Y
529
        {
530
            get
531
            {
532
                EnsureUndisposed();
533
                return implementation.Y;
534
            }
535
            set
536
            {
537
                EnsureUndisposed();
538
                implementation.Y = value;
539
            }
540
        }
541
 
542
        #endregion
543
 
544
        #endregion
545
 
546
        #region Events
547
 
548
        /// <summary>
549
        /// Occurs after the window has closed.
550
        /// </summary>
551
        public event EventHandler<EventArgs> Closed;
552
 
553
        /// <summary>
554
        /// Occurs when the window is about to close.
555
        /// </summary>
556
        public event EventHandler<CancelEventArgs> Closing;
557
 
558
        /// <summary>
559
        /// Occurs when the window is disposed.
560
        /// </summary>
561
        public event EventHandler<EventArgs> Disposed;
562
 
563
        /// <summary>
564
        /// Occurs when the <see cref="Focused"/> property of the window changes.
565
        /// </summary>
566
        public event EventHandler<EventArgs> FocusedChanged;
567
 
568
        /// <summary>
569
        /// Occurs when the <see cref="Icon"/> property of the window changes. 
570
        /// </summary>
571
        public event EventHandler<EventArgs> IconChanged;
572
 
573
        /// <summary>
574
        /// Occurs whenever a character is typed.
575
        /// </summary>
576
        public event EventHandler<KeyPressEventArgs> KeyPress;
577
 
578
        /// <summary>
579
        /// Occurs whenever the window is moved.
580
        /// </summary>
581
        public event EventHandler<EventArgs> Move;
582
 
583
        /// <summary>
584
        /// Occurs whenever the mouse cursor enters the window <see cref="Bounds"/>.
585
        /// </summary>
586
        public event EventHandler<EventArgs> MouseEnter;
587
 
588
        /// <summary>
589
        /// Occurs whenever the mouse cursor leaves the window <see cref="Bounds"/>.
590
        /// </summary>
591
        public event EventHandler<EventArgs> MouseLeave;
592
 
593
        /// <summary>
594
        /// Occurs whenever the window is resized.
595
        /// </summary>
596
        public event EventHandler<EventArgs> Resize;
597
 
598
        /// <summary>
599
        /// Occurs when the <see cref="Title"/> property of the window changes.
600
        /// </summary>
601
        public event EventHandler<EventArgs> TitleChanged;
602
 
603
        /// <summary>
604
        /// Occurs when the <see cref="Visible"/> property of the window changes.
605
        /// </summary>
606
        public event EventHandler<EventArgs> VisibleChanged;
607
 
608
        /// <summary>
609
        /// Occurs when the <see cref="WindowBorder"/> property of the window changes.
610
        /// </summary>
611
        public event EventHandler<EventArgs> WindowBorderChanged;
612
 
613
        /// <summary>
614
        /// Occurs when the <see cref="WindowState"/> property of the window changes.
615
        /// </summary>
616
        public event EventHandler<EventArgs> WindowStateChanged;
617
 
618
        #endregion
619
 
620
        #endregion
621
 
622
        #region --- IDisposable Members ---
623
 
624
        #region Dispose
625
 
626
        /// <summary>
627
        /// Releases all non-managed resources belonging to this NativeWindow.
628
        /// </summary>
629
        public virtual void Dispose()
630
        {
631
            if (!IsDisposed)
632
            {
633
                if ((options & GameWindowFlags.Fullscreen) != 0)
634
                {
635
                    //if (WindowState == WindowState.Fullscreen) WindowState = WindowState.Normal; // TODO: Revise.
636
                    device.RestoreResolution();
637
                }
638
                implementation.Dispose();
639
                GC.SuppressFinalize(this);
640
 
641
                IsDisposed = true;
642
            }
643
        }
644
 
645
        #endregion
646
 
647
        #endregion
648
 
649
        #region --- Protected Members ---
650
 
651
        #region Methods
652
 
653
        #region EnsureUndisposed
654
 
655
        /// <summary>
656
        /// Ensures that this NativeWindow has not been disposed.
657
        /// </summary>
658
        /// <exception cref="System.ObjectDisposedException">
659
        /// If this NativeWindow has been disposed.
660
        /// </exception>
661
        protected void EnsureUndisposed()
662
        {
663
            if (IsDisposed) throw new ObjectDisposedException(GetType().Name);
664
        }
665
 
666
        #endregion
667
 
668
        #region IsDisposed
669
 
670
        /// <summary>
671
        /// Gets or sets a <see cref="System.Boolean"/>, which indicates whether
672
        /// this instance has been disposed.
673
        /// </summary>
674
        protected bool IsDisposed
675
        {
676
            get { return disposed; }
677
            set { disposed = value; }
678
        }
679
 
680
        #endregion
681
 
682
        #region OnClosed
683
 
684
        /// <summary>
685
        /// Called when the NativeWindow has closed.
686
        /// </summary>
687
        /// <param name="e">Not used.</param>
688
        protected virtual void OnClosed(EventArgs e)
689
        {
690
            if (Closed != null) Closed(this, e);
691
        }
692
 
693
        #endregion
694
 
695
        #region OnClosing
696
 
697
        /// <summary>
698
        /// Called when the NativeWindow is about to close.
699
        /// </summary>
700
        /// <param name="e">
701
        /// The <see cref="System.ComponentModel.CancelEventArgs" /> for this event.
702
        /// Set e.Cancel to true in order to stop the NativeWindow from closing.</param>
703
        protected virtual void OnClosing(CancelEventArgs e)
704
        {
705
            if (Closing != null) Closing(this, e);
706
        }
707
 
708
        #endregion
709
 
710
        #region OnDisposed
711
 
712
        /// <summary>
713
        /// Called when the NativeWindow is disposed.
714
        /// </summary>
715
        /// <param name="e">Not used.</param>
716
        protected virtual void OnDisposed(EventArgs e)
717
        {
718
            if (Disposed != null) Disposed(this, e);
719
        }
720
 
721
        #endregion
722
 
723
        #region OnFocusedChanged
724
 
725
        /// <summary>
726
        /// Called when the <see cref="OpenTK.INativeWindow.Focused"/> property of the NativeWindow has changed.
727
        /// </summary>
728
        /// <param name="e">Not used.</param>
729
        protected virtual void OnFocusedChanged(EventArgs e)
730
        {
731
            if (FocusedChanged != null) FocusedChanged(this, e);
732
        }
733
 
734
        #endregion
735
 
736
        #region OnIconChanged
737
 
738
        /// <summary>
739
        /// Called when the <see cref="OpenTK.INativeWindow.Icon"/> property of the NativeWindow has changed.
740
        /// </summary>
741
        /// <param name="e">Not used.</param>
742
        protected virtual void OnIconChanged(EventArgs e)
743
        {
744
            if (IconChanged != null) IconChanged(this, e);
745
        }
746
 
747
        #endregion
748
 
749
        #region OnKeyPress
750
 
751
        /// <summary>
752
        /// Called when a character is typed.
753
        /// </summary>
754
        /// <param name="e">The <see cref="OpenTK.KeyPressEventArgs"/> for this event.</param>
755
        protected virtual void OnKeyPress(KeyPressEventArgs e)
756
        {
757
            if (KeyPress != null) KeyPress(this, e);
758
        }
759
 
760
        #endregion
761
 
762
        #region OnMove
763
 
764
        /// <summary>
765
        /// Called when the NativeWindow is moved.
766
        /// </summary>
767
        /// <param name="e">Not used.</param>
768
        protected virtual void OnMove(EventArgs e)
769
        {
770
            if (Move != null) Move(this, e);
771
        }
772
 
773
        #endregion
774
 
775
        #region OnMouseEnter
776
 
777
        /// <summary>
778
        /// Called whenever the mouse cursor reenters the window <see cref="Bounds"/>.
779
        /// </summary>
780
        /// <param name="e">Not used.</param>
781
        protected virtual void OnMouseEnter(EventArgs e)
782
        {
783
            if (MouseEnter != null) MouseEnter(this, e);
784
        }
785
 
786
        #endregion
787
 
788
        #region OnMouseLeave
789
 
790
        /// <summary>
791
        /// Called whenever the mouse cursor leaves the window <see cref="Bounds"/>.
792
        /// </summary>
793
        /// <param name="e">Not used.</param>
794
        protected virtual void OnMouseLeave(EventArgs e)
795
        {
796
            if (MouseLeave != null) MouseLeave(this, e);
797
        }
798
 
799
        #endregion
800
 
801
        #region OnResize
802
 
803
        /// <summary>
804
        /// Called when the NativeWindow is resized.
805
        /// </summary>
806
        /// <param name="e">Not used.</param>
807
        protected virtual void OnResize(EventArgs e)
808
        {
809
            if (Resize != null) Resize(this, e);
810
        }
811
 
812
        #endregion
813
 
814
        #region OnTitleChanged
815
 
816
        /// <summary>
817
        /// Called when the <see cref="OpenTK.INativeWindow.Title"/> property of the NativeWindow has changed.
818
        /// </summary>
819
        /// <param name="e">Not used.</param>
820
        protected virtual void OnTitleChanged(EventArgs e)
821
        {
822
            if (TitleChanged != null) TitleChanged(this, e);
823
        }
824
 
825
        #endregion
826
 
827
        #region OnVisibleChanged
828
 
829
        /// <summary>
830
        /// Called when the <see cref="OpenTK.INativeWindow.Visible"/> property of the NativeWindow has changed.
831
        /// </summary>
832
        /// <param name="e">Not used.</param>
833
        protected virtual void OnVisibleChanged(EventArgs e)
834
        {
835
            if (VisibleChanged != null) VisibleChanged(this, e);
836
        }
837
 
838
        #endregion
839
 
840
        #region OnWindowBorderChanged
841
 
842
        /// <summary>
843
        /// Called when the WindowBorder of this NativeWindow has changed.
844
        /// </summary>
845
        /// <param name="e">Not used.</param>
846
        protected virtual void OnWindowBorderChanged(EventArgs e)
847
        {
848
            if (WindowBorderChanged != null) WindowBorderChanged(this, e);
849
        }
850
 
851
        #endregion
852
 
853
        #region OnWindowStateChanged
854
 
855
        /// <summary>
856
        /// Called when the WindowState of this NativeWindow has changed.
857
        /// </summary>
858
        /// <param name="e">Not used.</param>
859
        protected virtual void OnWindowStateChanged(EventArgs e)
860
        {
861
            if (WindowStateChanged != null) WindowStateChanged(this, e);
862
        }
863
 
864
        #endregion
865
 
866
        #region ProcessEvents
867
 
868
        /// <summary>
869
        /// Processes operating system events until the NativeWindow becomes idle.
870
        /// </summary>
871
        /// <param name="retainEvents">If true, the state of underlying system event propagation will be preserved, otherwise event propagation will be enabled if it has not been already.</param>
872
        protected void ProcessEvents(bool retainEvents)
873
        {
874
            EnsureUndisposed();
875
            if (!retainEvents && !events) Events = true;
876
            implementation.ProcessEvents();
877
        }
878
 
879
        #endregion
880
 
881
        #endregion
882
 
883
        #endregion
884
 
885
        #region --- Private Members ---
886
 
887
        #region Methods
888
 
889
        #region OnClosedInternal
890
 
891
        private void OnClosedInternal(object sender, EventArgs e)
892
        {
893
            OnClosed(e);
894
            Events = false;
895
        }
896
 
897
        #endregion
898
 
899
        #region OnClosingInternal
900
 
901
        private void OnClosingInternal(object sender, CancelEventArgs e) { OnClosing(e); }
902
 
903
        #endregion
904
 
905
        #region OnDisposedInternal
906
 
907
        private void OnDisposedInternal(object sender, EventArgs e) { OnDisposed(e); }
908
 
909
        #endregion
910
 
911
        #region OnFocusedChangedInternal
912
 
913
        private void OnFocusedChangedInternal(object sender, EventArgs e) { OnFocusedChanged(e); }
914
 
915
        #endregion
916
 
917
        #region OnIconChangedInternal
918
 
919
        private void OnIconChangedInternal(object sender, EventArgs e) { OnIconChanged(e); }
920
 
921
        #endregion
922
 
923
        #region OnKeyPressInternal
924
 
925
        private void OnKeyPressInternal(object sender, KeyPressEventArgs e) { OnKeyPress(e); }
926
 
927
        #endregion
928
 
929
        #region OnMouseEnterInternal
930
 
931
        private void OnMouseEnterInternal(object sender, EventArgs e) { OnMouseEnter(e); }
932
 
933
        #endregion
934
 
935
        #region OnMouseLeaveInternal
936
 
937
        private void OnMouseLeaveInternal(object sender, EventArgs e) { OnMouseLeave(e); }
938
 
939
        #endregion
940
 
941
        #region OnMoveInternal
942
 
943
        private void OnMoveInternal(object sender, EventArgs e) { OnMove(e); }
944
 
945
        #endregion
946
 
947
        #region OnResizeInternal
948
 
949
        private void OnResizeInternal(object sender, EventArgs e) { OnResize(e); }
950
 
951
        #endregion
952
 
953
        #region OnTitleChangedInternal
954
 
955
        private void OnTitleChangedInternal(object sender, EventArgs e) { OnTitleChanged(e); }
956
 
957
        #endregion
958
 
959
        #region OnVisibleChangedInternal
960
 
961
        private void OnVisibleChangedInternal(object sender, EventArgs e) { OnVisibleChanged(e); }
962
 
963
        #endregion
964
 
965
        #region OnWindowBorderChangedInternal
966
 
967
        private void OnWindowBorderChangedInternal(object sender, EventArgs e) { OnWindowBorderChanged(e); }
968
 
969
        #endregion
970
 
971
        #region OnWindowStateChangedInternal
972
 
973
        private void OnWindowStateChangedInternal(object sender, EventArgs e) { OnWindowStateChanged(e); }
974
 
975
        #endregion
976
 
977
        #endregion
978
 
979
        #region Properties
980
 
981
        #region Events
982
 
983
        private bool Events
984
        {
985
            set
986
            {
987
                if (value)
988
                {
989
                    if (events)
990
                    {
991
                        throw new InvalidOperationException("Event propagation is already enabled.");
992
                    }
993
                    implementation.Closed += OnClosedInternal;
994
                    implementation.Closing += OnClosingInternal;
995
                    implementation.Disposed += OnDisposedInternal;
996
                    implementation.FocusedChanged += OnFocusedChangedInternal;
997
                    implementation.IconChanged += OnIconChangedInternal;
998
                    implementation.KeyPress += OnKeyPressInternal;
999
                    implementation.MouseEnter += OnMouseEnterInternal;
1000
                    implementation.MouseLeave += OnMouseLeaveInternal;
1001
                    implementation.Move += OnMoveInternal;
1002
                    implementation.Resize += OnResizeInternal;
1003
                    implementation.TitleChanged += OnTitleChangedInternal;
1004
                    implementation.VisibleChanged += OnVisibleChangedInternal;
1005
                    implementation.WindowBorderChanged += OnWindowBorderChangedInternal;
1006
                    implementation.WindowStateChanged += OnWindowStateChangedInternal;
1007
                    events = true;
1008
                }
1009
                else if (events)
1010
                {
1011
                    implementation.Closed -= OnClosedInternal;
1012
                    implementation.Closing -= OnClosingInternal;
1013
                    implementation.Disposed -= OnDisposedInternal;
1014
                    implementation.FocusedChanged -= OnFocusedChangedInternal;
1015
                    implementation.IconChanged -= OnIconChangedInternal;
1016
                    implementation.KeyPress -= OnKeyPressInternal;
1017
                    implementation.MouseEnter -= OnMouseEnterInternal;
1018
                    implementation.MouseLeave -= OnMouseLeaveInternal;
1019
                    implementation.Move -= OnMoveInternal;
1020
                    implementation.Resize -= OnResizeInternal;
1021
                    implementation.TitleChanged -= OnTitleChangedInternal;
1022
                    implementation.VisibleChanged -= OnVisibleChangedInternal;
1023
                    implementation.WindowBorderChanged -= OnWindowBorderChangedInternal;
1024
                    implementation.WindowStateChanged -= OnWindowStateChangedInternal;
1025
                    events = false;
1026
                }
1027
                else
1028
                {
1029
                    throw new InvalidOperationException("Event propagation is already disabled.");
1030
                }
1031
            }
1032
        }
1033
 
1034
        #endregion
1035
 
1036
        #endregion
1037
 
1038
        #endregion
1039
    }
1040
 
1041
}