Menu

[r2009]: / trunk / Src / UWindowSettings.pas  Maximize  Restore  History

Download this file

211 lines (190 with data), 8.3 kB

  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
{
* UWindowSettings.pas
*
* Implements a class that can save and record position of main window along
* with some window widgets.
*
* Requires DelphiDabbler Window State Components v5.3 of later.
*
* $Rev$
* $Date$
*
* ***** BEGIN LICENSE BLOCK *****
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The Original Code is UWindowSettings.pas
*
* The Initial Developer of the Original Code is Peter Johnson
* (http://www.delphidabbler.com/).
*
* Portions created by the Initial Developer are Copyright (C) 2006-2011 Peter
* Johnson. All Rights Reserved.
*
* Contributor(s)
* NONE
*
* ***** END LICENSE BLOCK *****
}
unit UWindowSettings;
interface
uses
// Delphi
Classes,
// DelphiDabbler library
PJWdwState;
type
{
TWindowSettings:
Class that can save and record position of main window along with some of
window's widgets.
}
TWindowSettings = class(TPJCustomWdwState)
strict private
var
fSplitterPos: Integer; // Value of SplitterPos property
fOverviewTab: Integer; // Value of OverviewTab property
const
cDefLeftPanelWidth = 186; // Default width of left hand panel
strict protected
procedure ReadWdwState(var Left, Top, Width, Height, State: Integer);
override;
{Reads window state from persistent local settings. Also reads information
about location, size and state of other main window widgets and sets
appropriate property. If persistent storage not present window defaults to
designed size and is placed at centre of work area.
@param Left [in/out] Location of left hand side of window. Designed
value passed in. Set to value from persistent storage if available,
otherwise set to a value that centres window horizontally in work
area.
@param Top [in/out] Location of top of window. Designed value passed in.
Set to value from persistent storage if available, otherwise set to a
value that centres window vertically in work area.
@param Width [in/out] Width of window. Passed in as designed width. Set
to width from persistent storage if available, otherwise unchanged.
@param Height [in/out] Height of window. Passed in as designed height.
Set to height from persistent storage if available, otherwise
unchanged.
@param State [in/out] State of window (ordinal value of TWindowState
enumeration). Passed in as designed state. Set to state from
persistent storage if available, otherwise unchanged.
}
procedure SaveWdwState(const Left, Top, Width, Height, State: Integer);
override;
{Writes window state to persistent local settings. Also writes information
about location, size and state of other main window widgets per assoicated
property values.
@param Left [in] Location of left hand side of window.
@param Top [in] Location of top of window.
@param Width [in] Width of window.
@param Height [in] Height of window.
@param State [in] State of window (ordinal value of TWindowState
enumeration). If state is minimized this is ignored and normal state
used.
}
public
const
MinLeftPanelWidth = 160; // minimum width of left panel
MinRightPanelWidth = 300; // minimum width of right panel
constructor Create(AOwner: TComponent); override;
{Class constructor. Sets up object and default property values.
@param AOwner [in] Owning component (must be a TForm).
}
property SplitterPos: Integer
read fSplitterPos write fSplitterPos default cDefLeftPanelWidth;
{Position of main window's vertical splitter}
property OverviewTab: Integer
read fOverviewTab write fOverviewTab;
{Index of selected tab in overview pane}
end;
implementation
uses
// Delphi
SysUtils, Forms, Windows,
// Project
USettings, UStructs;
{ TWindowSettings }
constructor TWindowSettings.Create(AOwner: TComponent);
{Class constructor. Sets up object and default property values.
@param AOwner [in] Owning component (must be a TForm).
}
begin
inherited;
AutoSaveRestore := False; // need to call Save and Restore manually
Options := [woFitWorkArea]; // keep main window inside work area
fSplitterPos := cDefLeftPanelWidth; // default splitter position
end;
procedure TWindowSettings.ReadWdwState(var Left, Top, Width, Height,
State: Integer);
{Reads window state from persistent local settings. Also reads information
about location, size and state of other main window widgets and sets
appropriate property. If persistent storage not present window defaults to
designed size and is placed at centre of work area.
@param Left [in/out] Location of left hand side of window. Designed value
passed in. Set to value from persistent storage if available, otherwise
set to a value that centres window horizontally in work area.
@param Top [in/out] Location of top of window. Designed value passed in. Set
to value from persistent storage if available, otherwise set to a value
that centres window vertically in work area.
@param Width [in/out] Width of window. Passed in as designed width. Set to
width from persistent storage if available, otherwise unchanged.
@param Height [in/out] Height of window. Passed in as designed height. Set
to height from persistent storage if available, otherwise unchanged.
@param State [in/out] State of window (ordinal value of TWindowState
enumeration). Passed in as designed state. Set to state from persistent
storage if available, otherwise unchanged.
}
var
Section: ISettingsSection; // object used to access persistent storage
WorkArea: TRectEx; // screen's workarea
begin
// Set default values: centre form in workarea using designed width & height
WorkArea := Screen.WorkAreaRect;
Left := (WorkArea.Width - Width) div 2;
Top := (WorkArea.Height - Height) div 2;
// Read values from storage
Section := Settings.ReadSection(ssMainWindow);
Left := StrToIntDef(Section.ItemValues['Left'], Left);
Top := StrToIntDef(Section.ItemValues['Top'], Top);
Width := StrToIntDef(Section.ItemValues['Width'], Width);
Height := StrToIntDef(Section.ItemValues['Height'], Height);
State := StrToIntDef(Section.ItemValues['State'], State);
if TWindowState(State) = wsMinimized then
State := Ord(wsNormal); // we don't allow minimized: use normal
fSplitterPos := StrToIntDef(Section.ItemValues['SplitterPos'], fSplitterPos);
fOverviewTab := StrToIntDef(Section.ItemValues['OverviewTab'], fOverviewTab);
end;
procedure TWindowSettings.SaveWdwState(const Left, Top, Width, Height,
State: Integer);
{Writes window state to persistent local settings. Also writes information
about location, size and state of other main window widgets per assoicated
property values.
@param Left [in] Location of left hand side of window.
@param Top [in] Location of top of window.
@param Width [in] Width of window.
@param Height [in] Height of window.
@param State [in] State of window (ordinal value of TWindowState
enumeration). If state is minimized this is ignored and normal state used.
}
var
Section: ISettingsSection; // object used to access persistent storage
begin
Section := Settings.ReadSection(ssMainWindow);
Section.ItemValues['Left'] := IntToStr(Left);
Section.ItemValues['Top'] := IntToStr(Top);
Section.ItemValues['Width'] := IntToStr(Width);
Section.ItemValues['Height'] := IntToStr(Height);
Section.ItemValues['State'] := IntToStr(State);
Section.ItemValues['SplitterPos'] := IntToStr(fSplitterPos);
Section.ItemValues['OverviewTab'] := IntToStr(fOverviewTab);
Section.Save;
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.