Ignore:
Timestamp:
Sep 10, 2022, 6:54:43 PM (20 months ago)
Author:
chronos
Message:
  • Modified: CoolTranslator replaced by Common package.
  • Modified: Update common package.
File:
1 edited

Legend:

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

    r20 r25  
    11unit UPersistentForm;
    22
    3 {$mode delphi}
    4 
    5 // Date: 2015-04-18
     3// Date: 2020-11-26
    64
    75interface
    86
    97uses
    10   Classes, SysUtils, Forms, URegistry, LCLIntf, Registry, Controls, ComCtrls;
     8  Classes, SysUtils, Forms, URegistry, LCLIntf, Registry, Controls, ComCtrls,
     9  ExtCtrls, LCLType;
    1110
    1211type
     
    2524    FormRestoredSize: TRect;
    2625    FormWindowState: TWindowState;
     26    FormFullScreen: Boolean;
    2727    Form: TForm;
    2828    procedure LoadFromRegistry(RegistryContext: TRegistryContext);
     
    3030    function CheckEntireVisible(Rect: TRect): TRect;
    3131    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);
    3334    procedure Save(Form: TForm);
    3435    constructor Create(AOwner: TComponent); override;
     36    procedure SetFullScreen(State: Boolean);
    3537    property RegistryContext: TRegistryContext read FRegistryContext
    3638      write FRegistryContext;
     
    4244procedure Register;
    4345
     46
    4447implementation
    45 
    4648
    4749procedure Register;
     
    7173  end;
    7274
     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
    7393  if Control is TWinControl then begin
    7494    WinControl := TWinControl(Control);
     
    95115      for I := 0 to TListView(Control).Columns.Count - 1 do begin
    96116        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);
    97133      end;
    98134    finally
     
    134170      + FormRestoredSize.Top;
    135171    // Other state
    136     FormWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(wsNormal)));
     172    FormWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(FormWindowState)));
     173    FormFullScreen := ReadBoolWithDefault('FullScreen', FormFullScreen);
    137174  finally
    138175    Free;
     
    158195    // Other state
    159196    WriteInteger('WindowState', Integer(FormWindowState));
     197    WriteBool('FullScreen', FormFullScreen);
    160198  finally
    161199    Free;
     
    215253end;
    216254
    217 procedure TPersistentForm.Load(Form: TForm; DefaultMaximized: Boolean = False);
     255procedure TPersistentForm.Load(Form: TForm; DefaultMaximized: Boolean = False;
     256  DefaultFullScreen: Boolean = False);
    218257begin
    219258  Self.Form := Form;
     
    223262  FormRestoredSize := Bounds((Screen.Width - Form.Width) div 2,
    224263    (Screen.Height - Form.Height) div 2, Form.Width, Form.Height);
     264  FormWindowState := Form.WindowState;
     265  FormFullScreen := DefaultFullScreen;
    225266
    226267  LoadFromRegistry(RegistryContext);
     
    242283      Form.BoundsRect := FormNormalSize;
    243284  end;
     285  if FormFullScreen then SetFullScreen(True);
    244286  LoadControl(Form);
    245287end;
     
    249291  Self.Form := Form;
    250292  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);
    253296  FormWindowState := Form.WindowState;
    254297  SaveToRegistry(RegistryContext);
     
    265308end;
    266309
     310procedure TPersistentForm.SetFullScreen(State: Boolean);
     311begin
     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;
     336end;
     337
    267338end.
    268339
Note: See TracChangeset for help on using the changeset viewer.