Changeset 308 for trunk/Packages/Common/UPersistentForm.pas
- Timestamp:
- Aug 18, 2021, 11:50:13 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UPersistentForm.pas
r207 r308 3 3 {$mode delphi} 4 4 5 // Date: 20 15-04-185 // Date: 2020-11-26 6 6 7 7 interface 8 8 9 9 uses 10 Classes, SysUtils, Forms, URegistry, LCLIntf, Registry, Controls, ComCtrls; 10 Classes, SysUtils, Forms, URegistry, LCLIntf, Registry, Controls, ComCtrls, 11 ExtCtrls, LCLType; 11 12 12 13 type … … 19 20 FMinVisiblePart: Integer; 20 21 FRegistryContext: TRegistryContext; 21 FirstLoad: Boolean;22 22 procedure LoadControl(Control: TControl); 23 23 procedure SaveControl(Control: TControl); … … 26 26 FormRestoredSize: TRect; 27 27 FormWindowState: TWindowState; 28 FormFullScreen: Boolean; 28 29 Form: TForm; 29 30 procedure LoadFromRegistry(RegistryContext: TRegistryContext); … … 31 32 function CheckEntireVisible(Rect: TRect): TRect; 32 33 function CheckPartVisible(Rect: TRect; Part: Integer): TRect; 33 procedure Load(Form: TForm; DefaultMaximized: Boolean = False); 34 procedure Load(Form: TForm; DefaultMaximized: Boolean = False; 35 DefaultFullScreen: Boolean = False); 34 36 procedure Save(Form: TForm); 35 37 constructor Create(AOwner: TComponent); override; 38 procedure SetFullScreen(State: Boolean); 36 39 property RegistryContext: TRegistryContext read FRegistryContext 37 40 write FRegistryContext; … … 43 46 procedure Register; 44 47 48 45 49 implementation 46 47 50 48 51 procedure Register; … … 72 75 end; 73 76 77 if (Control is TPanel) then begin 78 with Form, TRegistryEx.Create do 79 try 80 RootKey := RegistryContext.RootKey; 81 OpenKey(RegistryContext.Key + '\Forms\' + Form.Name + '\' + Control.Name, True); 82 if (TPanel(Control).Align = alRight) or (TPanel(Control).Align = alLeft) then begin 83 if ValueExists('Width') then 84 TPanel(Control).Width := ReadInteger('Width'); 85 end; 86 if (TPanel(Control).Align = alTop) or (TPanel(Control).Align = alBottom) then begin 87 if ValueExists('Height') then 88 TPanel(Control).Height := ReadInteger('Height'); 89 end; 90 finally 91 Free; 92 end; 93 end; 94 74 95 if Control is TWinControl then begin 75 96 WinControl := TWinControl(Control); … … 96 117 for I := 0 to TListView(Control).Columns.Count - 1 do begin 97 118 WriteInteger('ColWidth' + IntToStr(I), TListView(Control).Columns[I].Width); 119 end; 120 finally 121 Free; 122 end; 123 end; 124 125 if (Control is TPanel) then begin 126 with Form, TRegistryEx.Create do 127 try 128 RootKey := RegistryContext.RootKey; 129 OpenKey(RegistryContext.Key + '\Forms\' + Form.Name + '\' + Control.Name, True); 130 if (TPanel(Control).Align = alRight) or (TPanel(Control).Align = alLeft) then begin 131 WriteInteger('Width', TPanel(Control).Width); 132 end; 133 if (TPanel(Control).Align = alTop) or (TPanel(Control).Align = alBottom) then begin 134 WriteInteger('Height', TPanel(Control).Height); 98 135 end; 99 136 finally … … 120 157 RootKey := RegistryContext.RootKey; 121 158 OpenKey(RegistryContext.Key + '\Forms\' + Form.Name, True); 122 FirstLoad := not ValueExists('WindowState');123 159 // Normal size 124 160 FormNormalSize.Left := ReadIntegerWithDefault('NormalLeft', FormNormalSize.Left); … … 136 172 + FormRestoredSize.Top; 137 173 // Other state 138 FormWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(wsNormal))); 174 FormWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(FormWindowState))); 175 FormFullScreen := ReadBoolWithDefault('FullScreen', FormFullScreen); 139 176 finally 140 177 Free; … … 160 197 // Other state 161 198 WriteInteger('WindowState', Integer(FormWindowState)); 199 WriteBool('FullScreen', FormFullScreen); 162 200 finally 163 201 Free; … … 217 255 end; 218 256 219 procedure TPersistentForm.Load(Form: TForm; DefaultMaximized: Boolean = False); 257 procedure TPersistentForm.Load(Form: TForm; DefaultMaximized: Boolean = False; 258 DefaultFullScreen: Boolean = False); 220 259 begin 221 260 Self.Form := Form; … … 225 264 FormRestoredSize := Bounds((Screen.Width - Form.Width) div 2, 226 265 (Screen.Height - Form.Height) div 2, Form.Width, Form.Height); 266 FormWindowState := Form.WindowState; 267 FormFullScreen := DefaultFullScreen; 227 268 228 269 LoadFromRegistry(RegistryContext); 229 270 230 271 if not EqualRect(FormNormalSize, FormRestoredSize) or 231 (DefaultMaximized and FirstLoad)then begin272 DefaultMaximized then begin 232 273 // Restore to maximized state 233 274 Form.WindowState := wsNormal; … … 244 285 Form.BoundsRect := FormNormalSize; 245 286 end; 287 if FormFullScreen then SetFullScreen(True); 246 288 LoadControl(Form); 247 289 end; … … 251 293 Self.Form := Form; 252 294 FormNormalSize := Bounds(Form.Left, Form.Top, Form.Width, Form.Height); 253 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 254 Form.RestoredHeight); 295 if not FormFullScreen then 296 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 297 Form.RestoredHeight); 255 298 FormWindowState := Form.WindowState; 256 299 SaveToRegistry(RegistryContext); … … 265 308 FMinVisiblePart := 50; 266 309 FRegistryContext.RootKey := HKEY_CURRENT_USER; 267 FirstLoad := False; 310 end; 311 312 procedure TPersistentForm.SetFullScreen(State: Boolean); 313 begin 314 if State then begin 315 FormFullScreen := True; 316 FormNormalSize := Form.BoundsRect; 317 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 318 Form.RestoredHeight); 319 FormWindowState := Form.WindowState; 320 ShowWindow(Form.Handle, SW_SHOWFULLSCREEN); 321 {$IFDEF WINDOWS} 322 Form.BorderStyle := bsNone; 323 {$ENDIF} 324 end else begin 325 FormFullScreen := False; 326 {$IFDEF WINDOWS} 327 Form.BorderStyle := bsSizeable; 328 {$ENDIF} 329 ShowWindow(Form.Handle, SW_SHOWNORMAL); 330 if FormWindowState = wsNormal then begin 331 Form.BoundsRect := FormNormalSize; 332 end else 333 if FormWindowState = wsMaximized then begin 334 Form.BoundsRect := FormRestoredSize; 335 Form.WindowState := wsMaximized; 336 end; 337 end; 268 338 end; 269 339
Note:
See TracChangeset
for help on using the changeset viewer.