1- using DisplayRotation . Internal ;
21using System ;
32using System . Drawing ;
43using System . Linq ;
54using System . Reflection ;
65using System . Windows ;
6+ using System . Windows . Controls ;
77using System . Windows . Forms ;
8+ using DisplayRotation . Internal ;
9+ using Button = System . Windows . Controls . Button ;
10+ using ContextMenu = System . Windows . Forms . ContextMenu ;
11+ using MenuItem = System . Windows . Forms . MenuItem ;
812
913namespace DisplayRotation . Core
1014{
@@ -14,15 +18,23 @@ public class ApplicationSettings : IApplicationSettings
1418 private NotifyIcon _ni ;
1519 private readonly IActiveDevices _activeDevices ;
1620 private readonly IRotateDisplay _rotateDisplay ;
21+ private readonly IRotateButtonAndCanvas _rotateButtonAndCanvas ;
1722
1823 /// <summary>
1924 /// </summary>
2025 /// <param name="mainWindow"></param>
2126 /// <param name="ni"></param>
2227 /// <param name="activeDevices"></param>
2328 /// <param name="rotateDisplay"></param>
24- public ApplicationSettings ( MainWindow mainWindow , NotifyIcon ni , IActiveDevices activeDevices ,
25- IRotateDisplay rotateDisplay )
29+ /// <param name="rotateButtonAndCanvas"></param>
30+ /// <exception cref="ArgumentNullException">
31+ /// <paramref name="mainWindow" /> is <see langword="null" />.
32+ /// <paramref name="ni" /> is <see langword="null" />.
33+ /// <paramref name="activeDevices" /> is <see langword="null" />.
34+ /// <paramref name="rotateDisplay" /> is <see langword="null" />.
35+ /// <paramref name="rotateButtonAndCanvas" /> is <see langword="null" />.
36+ /// </exception>
37+ public ApplicationSettings ( MainWindow mainWindow , NotifyIcon ni , IActiveDevices activeDevices , IRotateDisplay rotateDisplay , IRotateButtonAndCanvas rotateButtonAndCanvas )
2638 {
2739 if ( mainWindow == null )
2840 {
@@ -40,10 +52,15 @@ public ApplicationSettings(MainWindow mainWindow, NotifyIcon ni, IActiveDevices
4052 {
4153 throw new ArgumentNullException ( nameof ( rotateDisplay ) ) ;
4254 }
55+ if ( rotateButtonAndCanvas == null )
56+ {
57+ throw new ArgumentNullException ( nameof ( rotateButtonAndCanvas ) ) ;
58+ }
4359 _mainWindow = mainWindow ;
4460 _ni = ni ;
4561 _activeDevices = activeDevices ;
4662 _rotateDisplay = rotateDisplay ;
63+ _rotateButtonAndCanvas = rotateButtonAndCanvas ;
4764 }
4865
4966 /// <summary>
@@ -56,19 +73,17 @@ public void Run()
5673 StartMinimized ( ) ;
5774 _ni . ContextMenu = NotifyIconContextMenu ( ) ;
5875 _ni . DoubleClick += NotifyIcon_DoubleClick ;
59- //_ni.Click += (sender, args) => _ni.ShowBalloonTip(10);
6076 }
6177
6278 /// <summary>
6379 /// </summary>
6480 public void StartMinimized ( )
6581 {
6682 _ni = new NotifyIcon
67- {
68- Icon = Icon . ExtractAssociatedIcon ( Assembly . GetEntryAssembly ( ) . Location ) ,
69- //BalloonTipTitle = Resources.ApplicationSettings_StartMinimized_BalloonTipTitle,
70- Visible = true
71- } ;
83+ {
84+ Icon = Icon . ExtractAssociatedIcon ( Assembly . GetEntryAssembly ( ) . Location ) ,
85+ Visible = true
86+ } ;
7287
7388 _mainWindow . Hide ( ) ;
7489 }
@@ -79,34 +94,68 @@ private ContextMenu NotifyIconContextMenu()
7994
8095 foreach ( var device in _activeDevices . Get ( ) . OrderBy ( d => d . PositionX ) )
8196 {
97+ var currentButton = new Button ( ) ;
98+
99+ foreach ( Canvas canvas in _mainWindow . DisplayStackPanel . Children )
100+ {
101+ foreach ( Button button in canvas . Children )
102+ {
103+ if ( button . Name == $ "ButtonDisplay{ device . Id } ")
104+ {
105+ currentButton = button ;
106+ break ;
107+ }
108+ }
109+ }
110+
82111 var parent = new MenuItem ( device . Name ) ;
83112
84113 //anticlockwise
85- var anticlockwiseItem = new MenuItem ( "Hochformat 'anticlockwise'" ) ;
86- anticlockwiseItem . Click += ( sender , args ) => _rotateDisplay . For ( NativeMethods . Dmdo90 , device . Id ) ;
114+ var anticlockwiseItem = new MenuItem ( "Upright 'anticlockwise'" ) ;
115+ anticlockwiseItem . Click += ( sender , args ) =>
116+ {
117+ _rotateDisplay . For ( NativeMethods . Dmdo90 , device . Id ) ;
118+ _rotateButtonAndCanvas . For ( NativeMethods . Dmdo90 , currentButton ) ;
119+ _mainWindow . SetWindowMargins ( ) ;
120+ } ;
87121
88122 //180
89- var clockwiseItem = new MenuItem ( "Querformat (gedreht)" ) ;
90- clockwiseItem . Click += ( sender , args ) => _rotateDisplay . For ( NativeMethods . Dmdo180 , device . Id ) ;
123+ var clockwiseItem = new MenuItem ( "Landscape (rotated)" ) ;
124+ clockwiseItem . Click += ( sender , args ) =>
125+ {
126+ _rotateDisplay . For ( NativeMethods . Dmdo180 , device . Id ) ;
127+ _rotateButtonAndCanvas . For ( NativeMethods . Dmdo180 , currentButton ) ;
128+ _mainWindow . SetWindowMargins ( ) ;
129+ } ;
91130
92131 //clockwise
93- var mirrorItem = new MenuItem ( "Hochformat (gedreht) 'clockwise'" ) ;
94- mirrorItem . Click += ( sender , args ) => _rotateDisplay . For ( NativeMethods . Dmdo270 , device . Id ) ;
132+ var mirrorItem = new MenuItem ( "Upright 'clockwise'" ) ;
133+ mirrorItem . Click += ( sender , args ) =>
134+ {
135+ _rotateDisplay . For ( NativeMethods . Dmdo270 , device . Id ) ;
136+ _rotateButtonAndCanvas . For ( NativeMethods . Dmdo270 , currentButton ) ;
137+ _mainWindow . SetWindowMargins ( ) ;
138+ } ;
95139
96140 //restore
97- var restoreItem = new MenuItem ( "Querformat " ) ;
141+ var restoreItem = new MenuItem ( "Reset " ) ;
98142 restoreItem . DefaultItem = true ;
99- restoreItem . Click += ( sender , args ) => _rotateDisplay . For ( NativeMethods . DmdoDefault , device . Id ) ;
143+ restoreItem . Click += ( sender , args ) =>
144+ {
145+ _rotateDisplay . For ( NativeMethods . DmdoDefault , device . Id ) ;
146+ _rotateButtonAndCanvas . For ( NativeMethods . DmdoDefault , currentButton ) ;
147+ _mainWindow . SetWindowMargins ( ) ;
148+ } ;
100149
101150 parent . MenuItems . AddRange ( new [ ] { anticlockwiseItem , clockwiseItem , mirrorItem , restoreItem } ) ;
102151
103152 contextMenu . MenuItems . Add ( parent ) ;
104153 }
105154 contextMenu . MenuItems . Add ( "-" ) ;
106- var restore = new MenuItem ( "Fenster öffnen " ) ;
155+ var restore = new MenuItem ( "Restore application " ) ;
107156 restore . Click += ContextMenuItemRestore_Click ;
108157
109- var close = new MenuItem ( "Beenden " ) ;
158+ var close = new MenuItem ( "Close application " ) ;
110159 close . Click += ContextMenuItemClose_Click ;
111160
112161 contextMenu . MenuItems . AddRange ( new [ ] { restore , close } ) ;
@@ -116,21 +165,18 @@ private ContextMenu NotifyIconContextMenu()
116165
117166 private void ContextMenuItemClose_Click ( object sender , EventArgs e )
118167 {
119- // Will Close Your Application
120168 _ni . Dispose ( ) ;
121169 _mainWindow . Close ( ) ;
122170 }
123171
124172 private void ContextMenuItemRestore_Click ( object sender , EventArgs e )
125173 {
126- //Will Restore Your Application
127174 _mainWindow . Show ( ) ;
128175 _mainWindow . WindowState = WindowState . Normal ;
129176 }
130177
131178 private void NotifyIcon_DoubleClick ( object sender , EventArgs e )
132179 {
133- //Will Restore Your Application
134180 _mainWindow . Show ( ) ;
135181 _mainWindow . WindowState = WindowState . Normal ;
136182 }
0 commit comments