Changeset 562 for Common/UPersistentForm.pas
- Timestamp:
- May 27, 2023, 11:00:20 AM (18 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/UPersistentForm.pas
r558 r562 1 1 unit UPersistentForm; 2 3 // Date: 2020-11-264 2 5 3 interface … … 21 19 procedure SaveControl(Control: TControl); 22 20 public 23 FormNormalSize: TRect;24 21 FormRestoredSize: TRect; 25 22 FormWindowState: TWindowState; … … 155 152 RootKey := RegistryContext.RootKey; 156 153 OpenKey(RegistryContext.Key + '\Forms\' + Form.Name, True); 157 // Normal size 158 FormNormalSize.Left := ReadIntegerWithDefault('NormalLeft', FormNormalSize.Left); 159 FormNormalSize.Top := ReadIntegerWithDefault('NormalTop', FormNormalSize.Top); 160 FormNormalSize.Right := ReadIntegerWithDefault('NormalWidth', FormNormalSize.Right - FormNormalSize.Left) 161 + FormNormalSize.Left; 162 FormNormalSize.Bottom := ReadIntegerWithDefault('NormalHeight', FormNormalSize.Bottom - FormNormalSize.Top) 163 + FormNormalSize.Top; 154 164 155 // Restored size 165 156 FormRestoredSize.Left := ReadIntegerWithDefault('RestoredLeft', FormRestoredSize.Left); … … 169 160 FormRestoredSize.Bottom := ReadIntegerWithDefault('RestoredHeight', FormRestoredSize.Bottom - FormRestoredSize.Top) 170 161 + FormRestoredSize.Top; 162 171 163 // Other state 172 164 FormWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(FormWindowState))); … … 183 175 RootKey := RegistryContext.RootKey; 184 176 OpenKey(RegistryContext.Key + '\Forms\' + Form.Name, True); 185 // Normal state 186 WriteInteger('NormalWidth', FormNormalSize.Right - FormNormalSize.Left); 187 WriteInteger('NormalHeight', FormNormalSize.Bottom - FormNormalSize.Top); 188 WriteInteger('NormalTop', FormNormalSize.Top); 189 WriteInteger('NormalLeft', FormNormalSize.Left); 190 // Restored state 177 178 // Restored size 191 179 WriteInteger('RestoredWidth', FormRestoredSize.Right - FormRestoredSize.Left); 192 180 WriteInteger('RestoredHeight', FormRestoredSize.Bottom - FormRestoredSize.Top); 193 181 WriteInteger('RestoredTop', FormRestoredSize.Top); 194 182 WriteInteger('RestoredLeft', FormRestoredSize.Left); 183 195 184 // Other state 196 185 WriteInteger('WindowState', Integer(FormWindowState)); … … 257 246 begin 258 247 Self.Form := Form; 248 259 249 // Set default 260 FormNormalSize := Bounds((Screen.Width - Form.Width) div 2,261 (Screen.Height - Form.Height) div 2, Form.Width, Form.Height);262 250 FormRestoredSize := Bounds((Screen.Width - Form.Width) div 2, 263 251 (Screen.Height - Form.Height) div 2, Form.Width, Form.Height); … … 267 255 LoadFromRegistry(RegistryContext); 268 256 269 if not EqualRect(FormNormalSize, FormRestoredSize) or 270 DefaultMaximized then begin 257 if (FormWindowState = wsMaximized) or DefaultMaximized then begin 271 258 // Restore to maximized state 272 259 Form.WindowState := wsNormal; … … 277 264 // Restore to normal state 278 265 Form.WindowState := wsNormal; 279 if FEntireVisible then Form NormalSize := CheckEntireVisible(FormNormalSize)266 if FEntireVisible then FormRestoredSize := CheckEntireVisible(FormRestoredSize) 280 267 else if FMinVisiblePart > 0 then 281 FormNormalSize := CheckPartVisible(FormNormalSize, FMinVisiblePart);282 if not EqualRect(Form NormalSize, Form.BoundsRect) then283 Form.BoundsRect := Form NormalSize;268 FormRestoredSize := CheckPartVisible(FormRestoredSize, FMinVisiblePart); 269 if not EqualRect(FormRestoredSize, Form.BoundsRect) then 270 Form.BoundsRect := FormRestoredSize; 284 271 end; 285 272 if FormFullScreen then SetFullScreen(True); … … 290 277 begin 291 278 Self.Form := Form; 292 FormNormalSize := Bounds(Form.Left, Form.Top, Form.Width, Form.Height); 293 if not FormFullScreen then 294 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 295 Form.RestoredHeight); 296 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; 297 289 SaveToRegistry(RegistryContext); 298 290 SaveControl(Form); … … 312 304 if State then begin 313 305 FormFullScreen := True; 314 FormNormalSize := Form.BoundsRect; 315 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 316 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; 317 313 FormWindowState := Form.WindowState; 314 Form.WindowState := wsMaximized; 315 Form.WindowState := wsNormal; 318 316 ShowWindow(Form.Handle, SW_SHOWFULLSCREEN); 319 317 {$IFDEF WINDOWS} … … 327 325 ShowWindow(Form.Handle, SW_SHOWNORMAL); 328 326 if FormWindowState = wsNormal then begin 329 Form.BoundsRect := FormNormalSize; 327 Form.WindowState := wsNormal; 328 Form.BoundsRect := FormRestoredSize; 330 329 end else 331 330 if FormWindowState = wsMaximized then begin … … 337 336 338 337 end. 339
Note:
See TracChangeset
for help on using the changeset viewer.