Changeset 119 for trunk/Packages/Common


Ignore:
Timestamp:
Oct 25, 2022, 11:02:30 PM (2 years ago)
Author:
chronos
Message:
  • Fixed: Error if track removed while train in station.
  • Fixed: Fullscreen was not working at the application first start.
File:
1 edited

Legend:

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

    r86 r119  
    11unit UPersistentForm;
    2 
    3 // Date: 2020-11-26
    42
    53interface
     
    2119    procedure SaveControl(Control: TControl);
    2220  public
    23     FormNormalSize: TRect;
    2421    FormRestoredSize: TRect;
    2522    FormWindowState: TWindowState;
     
    155152    RootKey := RegistryContext.RootKey;
    156153    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
    164155    // Restored size
    165156    FormRestoredSize.Left := ReadIntegerWithDefault('RestoredLeft', FormRestoredSize.Left);
     
    169160    FormRestoredSize.Bottom := ReadIntegerWithDefault('RestoredHeight', FormRestoredSize.Bottom - FormRestoredSize.Top)
    170161      + FormRestoredSize.Top;
     162
    171163    // Other state
    172164    FormWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(FormWindowState)));
     
    183175    RootKey := RegistryContext.RootKey;
    184176    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
    191179    WriteInteger('RestoredWidth', FormRestoredSize.Right - FormRestoredSize.Left);
    192180    WriteInteger('RestoredHeight', FormRestoredSize.Bottom - FormRestoredSize.Top);
    193181    WriteInteger('RestoredTop', FormRestoredSize.Top);
    194182    WriteInteger('RestoredLeft', FormRestoredSize.Left);
     183
    195184    // Other state
    196185    WriteInteger('WindowState', Integer(FormWindowState));
     
    257246begin
    258247  Self.Form := Form;
     248
    259249  // Set default
    260   FormNormalSize := Bounds((Screen.Width - Form.Width) div 2,
    261     (Screen.Height - Form.Height) div 2, Form.Width, Form.Height);
    262250  FormRestoredSize := Bounds((Screen.Width - Form.Width) div 2,
    263251    (Screen.Height - Form.Height) div 2, Form.Width, Form.Height);
     
    267255  LoadFromRegistry(RegistryContext);
    268256
    269   if not EqualRect(FormNormalSize, FormRestoredSize) or
    270     DefaultMaximized then begin
     257  if (FormWindowState = wsMaximized) or DefaultMaximized then begin
    271258    // Restore to maximized state
    272259    Form.WindowState := wsNormal;
     
    277264    // Restore to normal state
    278265    Form.WindowState := wsNormal;
    279     if FEntireVisible then FormNormalSize := CheckEntireVisible(FormNormalSize)
     266    if FEntireVisible then FormRestoredSize := CheckEntireVisible(FormRestoredSize)
    280267      else if FMinVisiblePart > 0 then
    281     FormNormalSize := CheckPartVisible(FormNormalSize, FMinVisiblePart);
    282     if not EqualRect(FormNormalSize, Form.BoundsRect) then
    283       Form.BoundsRect := FormNormalSize;
     268        FormRestoredSize := CheckPartVisible(FormRestoredSize, FMinVisiblePart);
     269    if not EqualRect(FormRestoredSize, Form.BoundsRect) then
     270      Form.BoundsRect := FormRestoredSize;
    284271  end;
    285272  if FormFullScreen then SetFullScreen(True);
     
    290277begin
    291278  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;
    297289  SaveToRegistry(RegistryContext);
    298290  SaveControl(Form);
     
    312304  if State then begin
    313305    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;
    317313    FormWindowState := Form.WindowState;
     314    Form.WindowState := wsMaximized;
    318315    Form.WindowState := wsNormal;
    319316    ShowWindow(Form.Handle, SW_SHOWFULLSCREEN);
     
    328325    ShowWindow(Form.Handle, SW_SHOWNORMAL);
    329326    if FormWindowState = wsNormal then begin
    330       Form.BoundsRect := FormNormalSize;
     327      Form.WindowState := wsNormal;
     328      Form.BoundsRect := FormRestoredSize;
    331329    end else
    332330    if FormWindowState = wsMaximized then begin
Note: See TracChangeset for help on using the changeset viewer.