(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / nunit20 / util / FormSettings.cs
blob6e1e1eae1aace93f6dc13c20658ff84b49bb556a
1 #region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
2 /************************************************************************************
4 ' Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
5 ' Copyright 2000-2002 Philip A. Craig
7 ' This software is provided 'as-is', without any express or implied warranty. In no
8 ' event will the authors be held liable for any damages arising from the use of this
9 ' software.
11 ' Permission is granted to anyone to use this software for any purpose, including
12 ' commercial applications, and to alter it and redistribute it freely, subject to the
13 ' following restrictions:
15 ' 1. The origin of this software must not be misrepresented; you must not claim that
16 ' you wrote the original software. If you use this software in a product, an
17 ' acknowledgment (see the following) in the product documentation is required.
19 ' Portions Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
20 ' or Copyright 2000-2002 Philip A. Craig
22 ' 2. Altered source versions must be plainly marked as such, and must not be
23 ' misrepresented as being the original software.
25 ' 3. This notice may not be removed or altered from any source distribution.
27 '***********************************************************************************/
28 #endregion
30 namespace NUnit.Util
32 using System;
33 using System.Drawing;
35 /// <summary>
36 /// FormSettings holds settings for NUnitForm
37 /// </summary>
38 public class FormSettings : SettingsGroup
40 private static readonly string NAME = "Form";
42 private static readonly string MAXIMIZED = "maximized";
43 private static readonly string WIDTH = "width";
44 private static readonly string HEIGHT = "height";
45 private static readonly string XLOCATION = "x-location";
46 private static readonly string YLOCATION = "y-location";
47 private static readonly string TREE_SPLITTER_POSITION = "tree-splitter-position";
48 private static readonly string TAB_SPLITTER_POSITION = "tab-splitter-position";
50 public static readonly int DEFAULT_WIDTH = 756;
51 public static readonly int MIN_WIDTH = 160;
53 public static readonly int DEFAULT_HEIGHT = 512;
54 public static readonly int MIN_HEIGHT = 32;
56 public static readonly int DEFAULT_XLOCATION = 10;
58 public static readonly int DEFAULT_YLOCATION = 10;
60 public static readonly int TREE_DEFAULT_POSITION = 300;
61 public static readonly int TREE_MIN_POSITION = 240;
63 public static readonly int TAB_DEFAULT_POSITION = 119;
64 public static readonly int TAB_MIN_POSITION = 100;
66 public FormSettings( ) : base( NAME, UserSettings.GetStorageImpl( NAME ) ) { }
68 public FormSettings( SettingsStorage storage ) : base( NAME, storage ) { }
70 public FormSettings( SettingsGroup parent ) : base( NAME, parent ) { }
72 private Point location = Point.Empty;
73 private Size size = Size.Empty;
74 private int treeSplitterPosition = -1;
75 private int tabSplitterPosition = -1;
77 public bool IsMaximized
79 get
81 return LoadIntSetting( MAXIMIZED, 0 ) == 1 ? true : false;
84 set
86 SaveIntSetting( MAXIMIZED, value ? 1 : 0 );
90 public Point Location
92 get
94 if ( location == Point.Empty )
96 int x = LoadIntSetting( XLOCATION, DEFAULT_XLOCATION );
97 int y = LoadIntSetting( YLOCATION, DEFAULT_YLOCATION );
99 location = new Point(x, y);
101 if ( !IsValidLocation( location ) )
102 location = new Point( DEFAULT_XLOCATION, DEFAULT_YLOCATION );
105 return location;
107 set
109 location = value;
110 SaveSetting( XLOCATION, location.X );
111 SaveSetting( YLOCATION, location.Y );
115 private bool IsValidLocation( Point location )
117 Rectangle myArea = new Rectangle( location, this.Size );
118 bool intersect = false;
119 foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens)
121 intersect |= myArea.IntersectsWith(screen.WorkingArea);
123 return intersect;
126 public Size Size
128 get
130 if ( size == Size.Empty )
132 int width = LoadIntSetting( WIDTH, DEFAULT_WIDTH );
133 if ( width < MIN_WIDTH ) width = MIN_WIDTH;
134 int height = LoadIntSetting( HEIGHT, DEFAULT_HEIGHT );
135 if ( height < MIN_HEIGHT ) height = MIN_HEIGHT;
137 size = new Size(width, height);
140 return size;
144 size = value;
145 SaveIntSetting( WIDTH, size.Width );
146 SaveIntSetting( HEIGHT, size.Height );
150 public int TreeSplitterPosition
152 get
154 if ( treeSplitterPosition == -1 )
156 treeSplitterPosition =
157 LoadIntSetting( TREE_SPLITTER_POSITION, TREE_DEFAULT_POSITION );
159 if ( treeSplitterPosition < TREE_MIN_POSITION || treeSplitterPosition > this.Size.Width )
160 treeSplitterPosition = TREE_MIN_POSITION;
163 return treeSplitterPosition;
165 set
167 treeSplitterPosition = value;
168 SaveSetting( TREE_SPLITTER_POSITION, treeSplitterPosition );
172 public int TabSplitterPosition
174 get
176 if ( tabSplitterPosition == -1 )
178 tabSplitterPosition =
179 LoadIntSetting( TAB_SPLITTER_POSITION, TAB_DEFAULT_POSITION );
181 if ( tabSplitterPosition < TAB_MIN_POSITION || tabSplitterPosition > this.Size.Height )
182 tabSplitterPosition = TAB_MIN_POSITION;
185 return tabSplitterPosition;
187 set
189 tabSplitterPosition = value;
190 SaveSetting( TAB_SPLITTER_POSITION, tabSplitterPosition );