Changeset 85 for trunk/Packages/Common/PersistentForm.pas
- Timestamp:
- Jun 7, 2024, 11:59:43 AM (5 months ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/PersistentForm.pas
r84 r85 1 unit UPersistentForm; 2 3 {$mode delphi} 4 5 // Date: 2020-11-26 1 unit PersistentForm; 6 2 7 3 interface 8 4 9 5 uses 10 Classes, SysUtils, Forms, URegistry, LCLIntf, Registry, Controls, ComCtrls,6 Classes, SysUtils, Forms, RegistryEx, LCLIntf, Registry, Controls, ComCtrls, 11 7 ExtCtrls, LCLType; 12 8 … … 23 19 procedure SaveControl(Control: TControl); 24 20 public 25 FormNormalSize: TRect;26 21 FormRestoredSize: TRect; 27 22 FormWindowState: TWindowState; … … 157 152 RootKey := RegistryContext.RootKey; 158 153 OpenKey(RegistryContext.Key + '\Forms\' + Form.Name, True); 159 // Normal size 160 FormNormalSize.Left := ReadIntegerWithDefault('NormalLeft', FormNormalSize.Left); 161 FormNormalSize.Top := ReadIntegerWithDefault('NormalTop', FormNormalSize.Top); 162 FormNormalSize.Right := ReadIntegerWithDefault('NormalWidth', FormNormalSize.Right - FormNormalSize.Left) 163 + FormNormalSize.Left; 164 FormNormalSize.Bottom := ReadIntegerWithDefault('NormalHeight', FormNormalSize.Bottom - FormNormalSize.Top) 165 + FormNormalSize.Top; 154 166 155 // Restored size 167 156 FormRestoredSize.Left := ReadIntegerWithDefault('RestoredLeft', FormRestoredSize.Left); … … 171 160 FormRestoredSize.Bottom := ReadIntegerWithDefault('RestoredHeight', FormRestoredSize.Bottom - FormRestoredSize.Top) 172 161 + FormRestoredSize.Top; 162 173 163 // Other state 174 164 FormWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(FormWindowState))); … … 185 175 RootKey := RegistryContext.RootKey; 186 176 OpenKey(RegistryContext.Key + '\Forms\' + Form.Name, True); 187 // Normal state 188 WriteInteger('NormalWidth', FormNormalSize.Right - FormNormalSize.Left); 189 WriteInteger('NormalHeight', FormNormalSize.Bottom - FormNormalSize.Top); 190 WriteInteger('NormalTop', FormNormalSize.Top); 191 WriteInteger('NormalLeft', FormNormalSize.Left); 192 // Restored state 177 178 // Restored size 193 179 WriteInteger('RestoredWidth', FormRestoredSize.Right - FormRestoredSize.Left); 194 180 WriteInteger('RestoredHeight', FormRestoredSize.Bottom - FormRestoredSize.Top); 195 181 WriteInteger('RestoredTop', FormRestoredSize.Top); 196 182 WriteInteger('RestoredLeft', FormRestoredSize.Left); 183 197 184 // Other state 198 185 WriteInteger('WindowState', Integer(FormWindowState)); … … 259 246 begin 260 247 Self.Form := Form; 248 261 249 // Set default 262 FormNormalSize := Bounds((Screen.Width - Form.Width) div 2,263 (Screen.Height - Form.Height) div 2, Form.Width, Form.Height);264 250 FormRestoredSize := Bounds((Screen.Width - Form.Width) div 2, 265 251 (Screen.Height - Form.Height) div 2, Form.Width, Form.Height); … … 269 255 LoadFromRegistry(RegistryContext); 270 256 271 if not EqualRect(FormNormalSize, FormRestoredSize) or 272 DefaultMaximized then begin 257 if (FormWindowState = wsMaximized) or DefaultMaximized then begin 273 258 // Restore to maximized state 274 259 Form.WindowState := wsNormal; … … 279 264 // Restore to normal state 280 265 Form.WindowState := wsNormal; 281 if FEntireVisible then Form NormalSize := CheckEntireVisible(FormNormalSize)266 if FEntireVisible then FormRestoredSize := CheckEntireVisible(FormRestoredSize) 282 267 else if FMinVisiblePart > 0 then 283 FormNormalSize := CheckPartVisible(FormNormalSize, FMinVisiblePart);284 if not EqualRect(Form NormalSize, Form.BoundsRect) then285 Form.BoundsRect := Form NormalSize;268 FormRestoredSize := CheckPartVisible(FormRestoredSize, FMinVisiblePart); 269 if not EqualRect(FormRestoredSize, Form.BoundsRect) then 270 Form.BoundsRect := FormRestoredSize; 286 271 end; 287 272 if FormFullScreen then SetFullScreen(True); … … 292 277 begin 293 278 Self.Form := Form; 294 FormNormalSize := Bounds(Form.Left, Form.Top, Form.Width, Form.Height); 295 if not FormFullScreen then 296 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 297 Form.RestoredHeight); 298 FormWindowState := Form.WindowState; 279 if not FormFullScreen then begin 280 FormWindowState := Form.WindowState; 281 if FormWindowState = wsMaximized then begin 282 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 283 Form.RestoredHeight); 284 end else 285 if FormWindowState = wsNormal then begin 286 FormRestoredSize := Bounds(Form.Left, Form.Top, Form.Width, Form.Height); 287 end; 288 end; 299 289 SaveToRegistry(RegistryContext); 300 290 SaveControl(Form); … … 314 304 if State then begin 315 305 FormFullScreen := True; 316 FormNormalSize := Form.BoundsRect; 317 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 318 Form.RestoredHeight); 306 if Form.WindowState = wsMaximized then begin 307 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 308 Form.RestoredHeight); 309 end else 310 if Form.WindowState = wsNormal then begin 311 FormRestoredSize := Bounds(Form.Left, Form.Top, Form.Width, Form.Height); 312 end; 319 313 FormWindowState := Form.WindowState; 314 Form.WindowState := wsMaximized; 315 Form.WindowState := wsNormal; 320 316 ShowWindow(Form.Handle, SW_SHOWFULLSCREEN); 321 317 {$IFDEF WINDOWS} … … 329 325 ShowWindow(Form.Handle, SW_SHOWNORMAL); 330 326 if FormWindowState = wsNormal then begin 331 Form.BoundsRect := FormNormalSize; 327 Form.WindowState := wsNormal; 328 Form.BoundsRect := FormRestoredSize; 332 329 end else 333 330 if FormWindowState = wsMaximized then begin … … 339 336 340 337 end. 341
Note:
See TracChangeset
for help on using the changeset viewer.