Ignore:
Timestamp:
Jun 19, 2024, 11:15:44 PM (5 months ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/PersistentForm.pas

    r314 r315  
    1 unit UPersistentForm;
    2 
    3 {$mode delphi}
    4 
    5 // Date: 2020-11-26
     1unit PersistentForm;
    62
    73interface
    84
    95uses
    10   Classes, SysUtils, Forms, URegistry, LCLIntf, Registry, Controls, ComCtrls,
     6  Classes, SysUtils, Forms, RegistryEx, LCLIntf, Registry, Controls, ComCtrls,
    117  ExtCtrls, LCLType;
    128
     
    2319    procedure SaveControl(Control: TControl);
    2420  public
    25     FormNormalSize: TRect;
    2621    FormRestoredSize: TRect;
    2722    FormWindowState: TWindowState;
     
    157152    RootKey := RegistryContext.RootKey;
    158153    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
    166155    // Restored size
    167156    FormRestoredSize.Left := ReadIntegerWithDefault('RestoredLeft', FormRestoredSize.Left);
     
    171160    FormRestoredSize.Bottom := ReadIntegerWithDefault('RestoredHeight', FormRestoredSize.Bottom - FormRestoredSize.Top)
    172161      + FormRestoredSize.Top;
     162
    173163    // Other state
    174164    FormWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(FormWindowState)));
     
    185175    RootKey := RegistryContext.RootKey;
    186176    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
    193179    WriteInteger('RestoredWidth', FormRestoredSize.Right - FormRestoredSize.Left);
    194180    WriteInteger('RestoredHeight', FormRestoredSize.Bottom - FormRestoredSize.Top);
    195181    WriteInteger('RestoredTop', FormRestoredSize.Top);
    196182    WriteInteger('RestoredLeft', FormRestoredSize.Left);
     183
    197184    // Other state
    198185    WriteInteger('WindowState', Integer(FormWindowState));
     
    259246begin
    260247  Self.Form := Form;
     248
    261249  // Set default
    262   FormNormalSize := Bounds((Screen.Width - Form.Width) div 2,
    263     (Screen.Height - Form.Height) div 2, Form.Width, Form.Height);
    264250  FormRestoredSize := Bounds((Screen.Width - Form.Width) div 2,
    265251    (Screen.Height - Form.Height) div 2, Form.Width, Form.Height);
     
    269255  LoadFromRegistry(RegistryContext);
    270256
    271   if not EqualRect(FormNormalSize, FormRestoredSize) or
    272     DefaultMaximized then begin
     257  if (FormWindowState = wsMaximized) or DefaultMaximized then begin
    273258    // Restore to maximized state
    274259    Form.WindowState := wsNormal;
     
    279264    // Restore to normal state
    280265    Form.WindowState := wsNormal;
    281     if FEntireVisible then FormNormalSize := CheckEntireVisible(FormNormalSize)
     266    if FEntireVisible then FormRestoredSize := CheckEntireVisible(FormRestoredSize)
    282267      else if FMinVisiblePart > 0 then
    283     FormNormalSize := CheckPartVisible(FormNormalSize, FMinVisiblePart);
    284     if not EqualRect(FormNormalSize, Form.BoundsRect) then
    285       Form.BoundsRect := FormNormalSize;
     268        FormRestoredSize := CheckPartVisible(FormRestoredSize, FMinVisiblePart);
     269    if not EqualRect(FormRestoredSize, Form.BoundsRect) then
     270      Form.BoundsRect := FormRestoredSize;
    286271  end;
    287272  if FormFullScreen then SetFullScreen(True);
     
    292277begin
    293278  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;
    299289  SaveToRegistry(RegistryContext);
    300290  SaveControl(Form);
     
    314304  if State then begin
    315305    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;
    319313    FormWindowState := Form.WindowState;
     314    Form.WindowState := wsMaximized;
     315    Form.WindowState := wsNormal;
    320316    ShowWindow(Form.Handle, SW_SHOWFULLSCREEN);
    321317    {$IFDEF WINDOWS}
     
    329325    ShowWindow(Form.Handle, SW_SHOWNORMAL);
    330326    if FormWindowState = wsNormal then begin
    331       Form.BoundsRect := FormNormalSize;
     327      Form.WindowState := wsNormal;
     328      Form.BoundsRect := FormRestoredSize;
    332329    end else
    333330    if FormWindowState = wsMaximized then begin
     
    339336
    340337end.
    341 
Note: See TracChangeset for help on using the changeset viewer.