blob: 0f3ff2874cba7117bd932f80ce9e6b241cca4235 (
plain)
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
|
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
namespace MediaBrowser.UI.Controls
{
/// <summary>
/// Provides a base class for all Windows
/// </summary>
public abstract class BaseWindow : Window, INotifyPropertyChanged
{
/// <summary>
/// Occurs when [property changed].
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Called when [property changed].
/// </summary>
/// <param name="info">The info.</param>
public void OnPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
/// <summary>
/// The _content scale
/// </summary>
private double _contentScale = 1;
/// <summary>
/// Gets the content scale.
/// </summary>
/// <value>The content scale.</value>
public double ContentScale
{
get { return _contentScale; }
private set
{
_contentScale = value;
OnPropertyChanged("ContentScale");
}
}
/// <summary>
/// Initializes a new instance of the <see cref="BaseWindow" /> class.
/// </summary>
protected BaseWindow()
: base()
{
SizeChanged += MainWindow_SizeChanged;
Loaded += BaseWindowLoaded;
}
/// <summary>
/// Bases the window loaded.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
void BaseWindowLoaded(object sender, RoutedEventArgs e)
{
OnLoaded();
}
/// <summary>
/// Called when [loaded].
/// </summary>
protected virtual void OnLoaded()
{
MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
}
/// <summary>
/// Handles the SizeChanged event of the MainWindow control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="SizeChangedEventArgs" /> instance containing the event data.</param>
void MainWindow_SizeChanged(object sender, SizeChangedEventArgs e)
{
ContentScale = e.NewSize.Height / 1080;
}
/// <summary>
/// Called when [browser back].
/// </summary>
protected virtual void OnBrowserBack()
{
}
/// <summary>
/// Called when [browser forward].
/// </summary>
protected virtual void OnBrowserForward()
{
}
/// <summary>
/// Invoked when an unhandled <see cref="E:System.Windows.Input.Keyboard.PreviewKeyDown" /> attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
/// </summary>
/// <param name="e">The <see cref="T:System.Windows.Input.KeyEventArgs" /> that contains the event data.</param>
protected override void OnPreviewKeyDown(KeyEventArgs e)
{
if (IsBackPress(e))
{
e.Handled = true;
if (!e.IsRepeat)
{
OnBrowserBack();
}
}
else if (IsForwardPress(e))
{
e.Handled = true;
if (!e.IsRepeat)
{
OnBrowserForward();
}
}
base.OnPreviewKeyDown(e);
}
/// <summary>
/// Determines if a keypress should be treated as a backward press
/// </summary>
/// <param name="e">The <see cref="KeyEventArgs" /> instance containing the event data.</param>
/// <returns><c>true</c> if [is back press] [the specified e]; otherwise, <c>false</c>.</returns>
private bool IsBackPress(KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
return true;
}
if (e.Key == Key.BrowserBack || e.Key == Key.Back)
{
return true;
}
if (e.SystemKey == Key.Left && e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Alt))
{
return true;
}
return false;
}
/// <summary>
/// Determines if a keypress should be treated as a forward press
/// </summary>
/// <param name="e">The <see cref="KeyEventArgs" /> instance containing the event data.</param>
/// <returns><c>true</c> if [is forward press] [the specified e]; otherwise, <c>false</c>.</returns>
private bool IsForwardPress(KeyEventArgs e)
{
if (e.Key == Key.BrowserForward)
{
return true;
}
if (e.SystemKey == Key.RightAlt && e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Alt))
{
return true;
}
return false;
}
}
}
|