Ignore:
Timestamp:
Aug 18, 2021, 11:50:13 AM (3 years ago)
Author:
chronos
Message:
  • Modified: Updated Common package to newer version.
  • Modified: About dialog is now part of Common package.
  • Modified: CoolTranslator is now part of Common package.
File:
1 edited

Legend:

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

    r207 r308  
    33{$mode delphi}
    44
    5 // Date: 2015-04-18
     5// Date: 2020-11-26
    66
    77interface
    88
    99uses
    10   Classes, SysUtils, Forms, URegistry, LCLIntf, Registry, Controls, ComCtrls;
     10  Classes, SysUtils, Forms, URegistry, LCLIntf, Registry, Controls, ComCtrls,
     11  ExtCtrls, LCLType;
    1112
    1213type
     
    1920    FMinVisiblePart: Integer;
    2021    FRegistryContext: TRegistryContext;
    21     FirstLoad: Boolean;
    2222    procedure LoadControl(Control: TControl);
    2323    procedure SaveControl(Control: TControl);
     
    2626    FormRestoredSize: TRect;
    2727    FormWindowState: TWindowState;
     28    FormFullScreen: Boolean;
    2829    Form: TForm;
    2930    procedure LoadFromRegistry(RegistryContext: TRegistryContext);
     
    3132    function CheckEntireVisible(Rect: TRect): TRect;
    3233    function CheckPartVisible(Rect: TRect; Part: Integer): TRect;
    33     procedure Load(Form: TForm; DefaultMaximized: Boolean = False);
     34    procedure Load(Form: TForm; DefaultMaximized: Boolean = False;
     35      DefaultFullScreen: Boolean = False);
    3436    procedure Save(Form: TForm);
    3537    constructor Create(AOwner: TComponent); override;
     38    procedure SetFullScreen(State: Boolean);
    3639    property RegistryContext: TRegistryContext read FRegistryContext
    3740      write FRegistryContext;
     
    4346procedure Register;
    4447
     48
    4549implementation
    46 
    4750
    4851procedure Register;
     
    7275  end;
    7376
     77  if (Control is TPanel) then begin
     78    with Form, TRegistryEx.Create do
     79    try
     80      RootKey := RegistryContext.RootKey;
     81      OpenKey(RegistryContext.Key + '\Forms\' + Form.Name + '\' + Control.Name, True);
     82      if (TPanel(Control).Align = alRight) or (TPanel(Control).Align = alLeft) then begin
     83        if ValueExists('Width') then
     84          TPanel(Control).Width := ReadInteger('Width');
     85      end;
     86      if (TPanel(Control).Align = alTop) or (TPanel(Control).Align = alBottom) then begin
     87        if ValueExists('Height') then
     88          TPanel(Control).Height := ReadInteger('Height');
     89      end;
     90    finally
     91      Free;
     92    end;
     93  end;
     94
    7495  if Control is TWinControl then begin
    7596    WinControl := TWinControl(Control);
     
    96117      for I := 0 to TListView(Control).Columns.Count - 1 do begin
    97118        WriteInteger('ColWidth' + IntToStr(I), TListView(Control).Columns[I].Width);
     119      end;
     120    finally
     121      Free;
     122    end;
     123  end;
     124
     125  if (Control is TPanel) then begin
     126    with Form, TRegistryEx.Create do
     127    try
     128      RootKey := RegistryContext.RootKey;
     129      OpenKey(RegistryContext.Key + '\Forms\' + Form.Name + '\' + Control.Name, True);
     130      if (TPanel(Control).Align = alRight) or (TPanel(Control).Align = alLeft) then begin
     131        WriteInteger('Width', TPanel(Control).Width);
     132      end;
     133      if (TPanel(Control).Align = alTop) or (TPanel(Control).Align = alBottom) then begin
     134        WriteInteger('Height', TPanel(Control).Height);
    98135      end;
    99136    finally
     
    120157    RootKey := RegistryContext.RootKey;
    121158    OpenKey(RegistryContext.Key + '\Forms\' + Form.Name, True);
    122     FirstLoad := not ValueExists('WindowState');
    123159    // Normal size
    124160    FormNormalSize.Left := ReadIntegerWithDefault('NormalLeft', FormNormalSize.Left);
     
    136172      + FormRestoredSize.Top;
    137173    // Other state
    138     FormWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(wsNormal)));
     174    FormWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(FormWindowState)));
     175    FormFullScreen := ReadBoolWithDefault('FullScreen', FormFullScreen);
    139176  finally
    140177    Free;
     
    160197    // Other state
    161198    WriteInteger('WindowState', Integer(FormWindowState));
     199    WriteBool('FullScreen', FormFullScreen);
    162200  finally
    163201    Free;
     
    217255end;
    218256
    219 procedure TPersistentForm.Load(Form: TForm; DefaultMaximized: Boolean = False);
     257procedure TPersistentForm.Load(Form: TForm; DefaultMaximized: Boolean = False;
     258  DefaultFullScreen: Boolean = False);
    220259begin
    221260  Self.Form := Form;
     
    225264  FormRestoredSize := Bounds((Screen.Width - Form.Width) div 2,
    226265    (Screen.Height - Form.Height) div 2, Form.Width, Form.Height);
     266  FormWindowState := Form.WindowState;
     267  FormFullScreen := DefaultFullScreen;
    227268
    228269  LoadFromRegistry(RegistryContext);
    229270
    230271  if not EqualRect(FormNormalSize, FormRestoredSize) or
    231     (DefaultMaximized and FirstLoad) then begin
     272    DefaultMaximized then begin
    232273    // Restore to maximized state
    233274    Form.WindowState := wsNormal;
     
    244285      Form.BoundsRect := FormNormalSize;
    245286  end;
     287  if FormFullScreen then SetFullScreen(True);
    246288  LoadControl(Form);
    247289end;
     
    251293  Self.Form := Form;
    252294  FormNormalSize := Bounds(Form.Left, Form.Top, Form.Width, Form.Height);
    253   FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth,
    254     Form.RestoredHeight);
     295  if not FormFullScreen then
     296    FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth,
     297      Form.RestoredHeight);
    255298  FormWindowState := Form.WindowState;
    256299  SaveToRegistry(RegistryContext);
     
    265308  FMinVisiblePart := 50;
    266309  FRegistryContext.RootKey := HKEY_CURRENT_USER;
    267   FirstLoad := False;
     310end;
     311
     312procedure TPersistentForm.SetFullScreen(State: Boolean);
     313begin
     314  if State then begin
     315    FormFullScreen := True;
     316    FormNormalSize := Form.BoundsRect;
     317    FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth,
     318      Form.RestoredHeight);
     319    FormWindowState := Form.WindowState;
     320    ShowWindow(Form.Handle, SW_SHOWFULLSCREEN);
     321    {$IFDEF WINDOWS}
     322    Form.BorderStyle := bsNone;
     323    {$ENDIF}
     324  end else begin
     325    FormFullScreen := False;
     326    {$IFDEF WINDOWS}
     327    Form.BorderStyle := bsSizeable;
     328    {$ENDIF}
     329    ShowWindow(Form.Handle, SW_SHOWNORMAL);
     330    if FormWindowState = wsNormal then begin
     331      Form.BoundsRect := FormNormalSize;
     332    end else
     333    if FormWindowState = wsMaximized then begin
     334      Form.BoundsRect := FormRestoredSize;
     335      Form.WindowState := wsMaximized;
     336    end;
     337  end;
    268338end;
    269339
Note: See TracChangeset for help on using the changeset viewer.