Changeset 25 for trunk/Packages/Common/UPersistentForm.pas
- Timestamp:
- Sep 10, 2022, 6:54:43 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UPersistentForm.pas
r20 r25 1 1 unit UPersistentForm; 2 2 3 {$mode delphi} 4 5 // Date: 2015-04-18 3 // Date: 2020-11-26 6 4 7 5 interface 8 6 9 7 uses 10 Classes, SysUtils, Forms, URegistry, LCLIntf, Registry, Controls, ComCtrls; 8 Classes, SysUtils, Forms, URegistry, LCLIntf, Registry, Controls, ComCtrls, 9 ExtCtrls, LCLType; 11 10 12 11 type … … 25 24 FormRestoredSize: TRect; 26 25 FormWindowState: TWindowState; 26 FormFullScreen: Boolean; 27 27 Form: TForm; 28 28 procedure LoadFromRegistry(RegistryContext: TRegistryContext); … … 30 30 function CheckEntireVisible(Rect: TRect): TRect; 31 31 function CheckPartVisible(Rect: TRect; Part: Integer): TRect; 32 procedure Load(Form: TForm; DefaultMaximized: Boolean = False); 32 procedure Load(Form: TForm; DefaultMaximized: Boolean = False; 33 DefaultFullScreen: Boolean = False); 33 34 procedure Save(Form: TForm); 34 35 constructor Create(AOwner: TComponent); override; 36 procedure SetFullScreen(State: Boolean); 35 37 property RegistryContext: TRegistryContext read FRegistryContext 36 38 write FRegistryContext; … … 42 44 procedure Register; 43 45 46 44 47 implementation 45 46 48 47 49 procedure Register; … … 71 73 end; 72 74 75 if (Control is TPanel) then begin 76 with Form, TRegistryEx.Create do 77 try 78 RootKey := RegistryContext.RootKey; 79 OpenKey(RegistryContext.Key + '\Forms\' + Form.Name + '\' + Control.Name, True); 80 if (TPanel(Control).Align = alRight) or (TPanel(Control).Align = alLeft) then begin 81 if ValueExists('Width') then 82 TPanel(Control).Width := ReadInteger('Width'); 83 end; 84 if (TPanel(Control).Align = alTop) or (TPanel(Control).Align = alBottom) then begin 85 if ValueExists('Height') then 86 TPanel(Control).Height := ReadInteger('Height'); 87 end; 88 finally 89 Free; 90 end; 91 end; 92 73 93 if Control is TWinControl then begin 74 94 WinControl := TWinControl(Control); … … 95 115 for I := 0 to TListView(Control).Columns.Count - 1 do begin 96 116 WriteInteger('ColWidth' + IntToStr(I), TListView(Control).Columns[I].Width); 117 end; 118 finally 119 Free; 120 end; 121 end; 122 123 if (Control is TPanel) then begin 124 with Form, TRegistryEx.Create do 125 try 126 RootKey := RegistryContext.RootKey; 127 OpenKey(RegistryContext.Key + '\Forms\' + Form.Name + '\' + Control.Name, True); 128 if (TPanel(Control).Align = alRight) or (TPanel(Control).Align = alLeft) then begin 129 WriteInteger('Width', TPanel(Control).Width); 130 end; 131 if (TPanel(Control).Align = alTop) or (TPanel(Control).Align = alBottom) then begin 132 WriteInteger('Height', TPanel(Control).Height); 97 133 end; 98 134 finally … … 134 170 + FormRestoredSize.Top; 135 171 // Other state 136 FormWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(wsNormal))); 172 FormWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(FormWindowState))); 173 FormFullScreen := ReadBoolWithDefault('FullScreen', FormFullScreen); 137 174 finally 138 175 Free; … … 158 195 // Other state 159 196 WriteInteger('WindowState', Integer(FormWindowState)); 197 WriteBool('FullScreen', FormFullScreen); 160 198 finally 161 199 Free; … … 215 253 end; 216 254 217 procedure TPersistentForm.Load(Form: TForm; DefaultMaximized: Boolean = False); 255 procedure TPersistentForm.Load(Form: TForm; DefaultMaximized: Boolean = False; 256 DefaultFullScreen: Boolean = False); 218 257 begin 219 258 Self.Form := Form; … … 223 262 FormRestoredSize := Bounds((Screen.Width - Form.Width) div 2, 224 263 (Screen.Height - Form.Height) div 2, Form.Width, Form.Height); 264 FormWindowState := Form.WindowState; 265 FormFullScreen := DefaultFullScreen; 225 266 226 267 LoadFromRegistry(RegistryContext); … … 242 283 Form.BoundsRect := FormNormalSize; 243 284 end; 285 if FormFullScreen then SetFullScreen(True); 244 286 LoadControl(Form); 245 287 end; … … 249 291 Self.Form := Form; 250 292 FormNormalSize := Bounds(Form.Left, Form.Top, Form.Width, Form.Height); 251 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 252 Form.RestoredHeight); 293 if not FormFullScreen then 294 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 295 Form.RestoredHeight); 253 296 FormWindowState := Form.WindowState; 254 297 SaveToRegistry(RegistryContext); … … 265 308 end; 266 309 310 procedure TPersistentForm.SetFullScreen(State: Boolean); 311 begin 312 if State then begin 313 FormFullScreen := True; 314 FormNormalSize := Form.BoundsRect; 315 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 316 Form.RestoredHeight); 317 FormWindowState := Form.WindowState; 318 ShowWindow(Form.Handle, SW_SHOWFULLSCREEN); 319 {$IFDEF WINDOWS} 320 Form.BorderStyle := bsNone; 321 {$ENDIF} 322 end else begin 323 FormFullScreen := False; 324 {$IFDEF WINDOWS} 325 Form.BorderStyle := bsSizeable; 326 {$ENDIF} 327 ShowWindow(Form.Handle, SW_SHOWNORMAL); 328 if FormWindowState = wsNormal then begin 329 Form.BoundsRect := FormNormalSize; 330 end else 331 if FormWindowState = wsMaximized then begin 332 Form.BoundsRect := FormRestoredSize; 333 Form.WindowState := wsMaximized; 334 end; 335 end; 336 end; 337 267 338 end. 268 339
Note:
See TracChangeset
for help on using the changeset viewer.