Changeset 487 for Common


Ignore:
Timestamp:
Jul 26, 2016, 11:26:11 PM (8 years ago)
Author:
chronos
Message:
  • Modified: Improved ScaleDPI component.
  • Modified: Improved storing position with TPersistentForm.
Location:
Common
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • Common/Common.pas

    r467 r487  
    2424  RegisterUnit('UPersistentForm', @UPersistentForm.Register);
    2525  RegisterUnit('UFindFile', @UFindFile.Register);
     26  RegisterUnit('UScaleDPI', @UScaleDPI.Register);
    2627end;
    2728
  • Common/Demo/PersistentForm/PersistentFormDemo.lpi

    r474 r487  
    2828      </local>
    2929    </RunParams>
    30     <RequiredPackages Count="2">
     30    <RequiredPackages Count="3">
    3131      <Item1>
    32         <PackageName Value="Common"/>
     32        <PackageName Value="FCL"/>
    3333      </Item1>
    3434      <Item2>
     35        <PackageName Value="Common"/>
     36        <DefaultFilename Value="../../Common.lpk" Prefer="True"/>
     37      </Item2>
     38      <Item3>
    3539        <PackageName Value="LCL"/>
    36       </Item2>
     40      </Item3>
    3741    </RequiredPackages>
    3842    <Units Count="2">
     
    4044        <Filename Value="PersistentFormDemo.lpr"/>
    4145        <IsPartOfProject Value="True"/>
    42         <UnitName Value="PersistentFormDemo"/>
    4346      </Unit0>
    4447      <Unit1>
     
    4649        <IsPartOfProject Value="True"/>
    4750        <ComponentName Value="Form1"/>
     51        <HasResources Value="True"/>
    4852        <ResourceBaseClass Value="Form"/>
    4953        <UnitName Value="Unit1"/>
  • Common/Demo/PersistentForm/Unit1.lfm

    r474 r487  
    11object Form1: TForm1
    2   Left = 779
     2  Left = 952
    33  Height = 622
    4   Top = 364
     4  Top = 489
    55  Width = 698
    66  Caption = 'PersistentForm demo'
     
    4040    top = 314
    4141  end
     42  object XMLConfig1: TXMLConfig
     43    StartEmpty = False
     44    RootName = 'CONFIG'
     45    left = 240
     46    top = 217
     47  end
    4248end
  • Common/Demo/PersistentForm/Unit1.pas

    r474 r487  
    66
    77uses
    8   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Buttons,
    9   StdCtrls, ExtCtrls, ComCtrls, UPersistentForm;
     8  Classes, SysUtils, XMLConf, FileUtil, Forms, Controls, Graphics, Dialogs,
     9  Buttons, StdCtrls, ExtCtrls, ComCtrls, Menus, XMLPropStorage, UPersistentForm;
    1010
    1111type
     
    1717    PersistentForm1: TPersistentForm;
    1818    Timer1: TTimer;
     19    XMLConfig1: TXMLConfig;
    1920    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    2021    procedure FormResize(Sender: TObject);
  • Common/UFindFile.pas

    r463 r487  
    5555  end;
    5656
     57const
     58{$IFDEF WINDOWS}
     59  FilterAll = '*.*';
     60{$ENDIF}
     61{$IFDEF LINUX}
     62  FilterAll = '*';
     63{$ENDIF}
     64
    5765procedure Register;
    5866
     
    7179  inherited Create(AOwner);
    7280  Path := IncludeTrailingBackslash(UTF8Encode(GetCurrentDir));
    73   FileMask := '*.*';
     81  FileMask := FilterAll;
    7482  FileAttr := [ffaAnyFile];
    7583  s := TStringList.Create;
     
    127135  If not InSubFolders then Exit;
    128136
    129   if SysUtils.FindFirst(UTF8Decode(inPath + '*.*'), faDirectory, Rec) = 0 then
     137  if SysUtils.FindFirst(UTF8Decode(inPath + FilterAll), faDirectory, Rec) = 0 then
    130138  try
    131139    repeat
  • Common/UScaleDPI.pas

    r469 r487  
    1717  TControlDimension = class
    1818    BoundsRect: TRect;
    19     AuxSize: TPoint;
    2019    FontHeight: Integer;
    2120    Controls: TObjectList; // TList<TControlDimension>
     21    // Class specifics
     22    ButtonSize: TPoint; // TToolBar
     23    CoolBandWidth: Integer;
     24    ConstraintsMin: TPoint; // TForm
     25    ConstraintsMax: TPoint; // TForm
    2226    constructor Create;
    2327    destructor Destroy; override;
     
    7478destructor TControlDimension.Destroy;
    7579begin
    76   Controls.Free;
     80  FreeAndNil(Controls);
    7781  inherited Destroy;
    7882end;
     
    113117  Dimensions.Controls.Clear;
    114118  if Control is TToolBar then
    115     Dimensions.AuxSize := Point(TToolBar(Control).ButtonWidth, TToolBar(Control).ButtonHeight);
    116 
     119    Dimensions.ButtonSize := Point(TToolBar(Control).ButtonWidth, TToolBar(Control).ButtonHeight);
     120  if Control is TForm then begin
     121    Dimensions.ConstraintsMin := Point(TForm(Control).Constraints.MinWidth,
     122      TForm(Control).Constraints.MinHeight);
     123    Dimensions.ConstraintsMax := Point(TForm(Control).Constraints.MaxWidth,
     124      TForm(Control).Constraints.MaxHeight);
     125  end;
    117126  if Control is TWinControl then
    118127  for I := 0 to TWinControl(Control).ControlCount - 1 do begin
    119     if TWinControl(Control).Controls[I] is TControl then begin
     128    if TWinControl(Control).Controls[I] is TControl then
     129    // Do not scale docked forms twice
     130    if not (TWinControl(Control).Controls[I] is TForm) then begin
    120131      NewControl := TControlDimension.Create;
    121132      Dimensions.Controls.Add(NewControl);
     
    133144  Control.Font.Height := Dimensions.FontHeight;
    134145  if Control is TToolBar then begin
    135     TToolBar(Control).ButtonWidth := Dimensions.AuxSize.X;
    136     TToolBar(Control).ButtonHeight := Dimensions.AuxSize.Y;
     146    TToolBar(Control).ButtonWidth := Dimensions.ButtonSize.X;
     147    TToolBar(Control).ButtonHeight := Dimensions.ButtonSize.Y;
     148  end;
     149  if Control is TForm then begin
     150    TForm(Control).Constraints.MinWidth := Dimensions.ConstraintsMin.X;
     151    TForm(Control).Constraints.MinHeight := Dimensions.ConstraintsMin.Y;
     152    TForm(Control).Constraints.MaxWidth := Dimensions.ConstraintsMax.X;
     153    TForm(Control).Constraints.MaxHeight := Dimensions.ConstraintsMax.Y;
    137154  end;
    138155  if Control is TWinControl then
    139156  for I := 0 to TWinControl(Control).ControlCount - 1 do begin
    140     if TWinControl(Control).Controls[I] is TControl then begin
     157    if TWinControl(Control).Controls[I] is TControl then
     158    // Do not scale docked forms twice
     159    if not (TWinControl(Control).Controls[I] is TForm) then begin
    141160      RestoreDimensions(TWinControl(Control).Controls[I], TControlDimension(Dimensions.Controls[I]));
    142161    end;
     
    152171  Control.Font.Height := ScaleY(Dimensions.FontHeight, DesignDPI.Y);
    153172  if Control is TToolBar then begin
    154     TToolBar(Control).ButtonWidth := ScaleX(Dimensions.AuxSize.X, DesignDPI.X);
    155     TToolBar(Control).ButtonHeight := ScaleY(Dimensions.AuxSize.Y, DesignDPI.Y);
     173    TToolBar(Control).ButtonWidth := ScaleX(Dimensions.ButtonSize.X, DesignDPI.X);
     174    TToolBar(Control).ButtonHeight := ScaleY(Dimensions.ButtonSize.Y, DesignDPI.Y);
     175  end;
     176  if Control is TCoolBar then begin
     177    with TCoolBar(Control) do
     178    for I := 0 to Bands.Count - 1 do
     179    with TCoolBand(Bands[I]) do begin
     180      MinWidth := ScaleX(Dimensions.ButtonSize.X, DesignDPI.X);
     181      MinHeight := ScaleY(Dimensions.ButtonSize.Y, DesignDPI.Y);
     182      //Width := ScaleX(Dimensions.BoundsRect.Left -
     183    end;
     184  end;
     185  if Control is TForm then begin
     186    TForm(Control).Constraints.MinWidth := ScaleX(Dimensions.ConstraintsMin.X, DesignDPI.X);
     187    TForm(Control).Constraints.MaxWidth := ScaleX(Dimensions.ConstraintsMax.X, DesignDPI.X);
     188    TForm(Control).Constraints.MinHeight := ScaleY(Dimensions.ConstraintsMin.Y, DesignDPI.Y);
     189    TForm(Control).Constraints.MaxHeight := ScaleY(Dimensions.ConstraintsMax.Y, DesignDPI.Y);
    156190  end;
    157191  if Control is TWinControl then
    158192  for I := 0 to TWinControl(Control).ControlCount - 1 do begin
    159     if TWinControl(Control).Controls[I] is TControl then begin
     193    if TWinControl(Control).Controls[I] is TControl then
     194    // Do not scale docked forms twice
     195    if not (TWinControl(Control).Controls[I] is TForm) then begin
    160196      ScaleDimensions(TWinControl(Control).Controls[I], TControlDimension(Dimensions.Controls[I]));
    161197    end;
     
    183219
    184220  SetLength(Temp, ImgList.Count);
    185   TempBmp := TBitmap.Create;
    186221  for I := 0 to ImgList.Count - 1 do
    187222  begin
     223    TempBmp := TBitmap.Create;
     224    TempBmp.PixelFormat := pf32bit;
    188225    ImgList.GetBitmap(I, TempBmp);
    189     //TempBmp.PixelFormat := pfDevice;
    190226    Temp[I] := TBitmap.Create;
    191227    Temp[I].SetSize(NewWidth, NewHeight);
     228    Temp[I].PixelFormat := pf32bit;
    192229    Temp[I].TransparentColor := TempBmp.TransparentColor;
    193230    //Temp[I].TransparentMode := TempBmp.TransparentMode;
     
    199236    if (Temp[I].Width = 0) or (Temp[I].Height = 0) then Continue;
    200237    Temp[I].Canvas.StretchDraw(Rect(0, 0, Temp[I].Width, Temp[I].Height), TempBmp);
    201   end;
    202   TempBmp.Free;
     238    TempBmp.Free;
     239  end;
    203240
    204241  ImgList.Clear;
     
    272309  end;
    273310
    274 
    275 
    276311  if Control is TToolBar then begin
    277312    ToolBarControl := TToolBar(Control);
Note: See TracChangeset for help on using the changeset viewer.