Changeset 59 for trunk/Packages


Ignore:
Timestamp:
Dec 3, 2014, 9:09:42 PM (10 years ago)
Author:
chronos
Message:
  • Added: Support for high DPI screens. If not detected automatically correctly then user can specify desired values.
  • Updated: Common package to newer version.
Location:
trunk/Packages/Common
Files:
5 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/Common.lpk

    r54 r59  
    1 <?xml version="1.0"?>
     1<?xml version="1.0" encoding="UTF-8"?>
    22<CONFIG>
    33  <Package Version="4">
     
    1212        <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
    1313      </SearchPaths>
    14       <Other>
    15         <CompilerMessages>
    16           <UseMsgFile Value="True"/>
    17         </CompilerMessages>
    18         <CompilerPath Value="$(CompPath)"/>
    19       </Other>
    2014    </CompilerOptions>
    2115    <Description Value="Various libraries"/>
    2216    <License Value="GNU/GPL"/>
    2317    <Version Minor="7"/>
    24     <Files Count="15">
     18    <Files Count="20">
    2519      <Item1>
    2620        <Filename Value="StopWatch.pas"/>
     
    8781        <UnitName Value="UApplicationInfo"/>
    8882      </Item15>
     83      <Item16>
     84        <Filename Value="USyncCounter.pas"/>
     85        <UnitName Value="USyncCounter"/>
     86      </Item16>
     87      <Item17>
     88        <Filename Value="UListViewSort.pas"/>
     89        <HasRegisterProc Value="True"/>
     90        <UnitName Value="UListViewSort"/>
     91      </Item17>
     92      <Item18>
     93        <Filename Value="UPersistentForm.pas"/>
     94        <HasRegisterProc Value="True"/>
     95        <UnitName Value="UPersistentForm"/>
     96      </Item18>
     97      <Item19>
     98        <Filename Value="UFindFile.pas"/>
     99        <HasRegisterProc Value="True"/>
     100        <UnitName Value="UFindFile"/>
     101      </Item19>
     102      <Item20>
     103        <Filename Value="UScaleDPI.pas"/>
     104        <UnitName Value="UScaleDPI"/>
     105      </Item20>
    89106    </Files>
    90107    <i18n>
  • trunk/Packages/Common/Common.pas

    r54 r59  
    1010  StopWatch, UCommon, UDebugLog, UDelay, UPrefixMultiplier, UURI, UThreading,
    1111  UMemory, UResetableThread, UPool, ULastOpenedList, URegistry,
    12   UJobProgressView, UXMLUtils, UApplicationInfo, LazarusPackageIntf;
     12  UJobProgressView, UXMLUtils, UApplicationInfo, USyncCounter, UListViewSort,
     13  UPersistentForm, UFindFile, UScaleDPI, LazarusPackageIntf;
    1314
    1415implementation
     
    2021  RegisterUnit('UJobProgressView', @UJobProgressView.Register);
    2122  RegisterUnit('UApplicationInfo', @UApplicationInfo.Register);
     23  RegisterUnit('UListViewSort', @UListViewSort.Register);
     24  RegisterUnit('UPersistentForm', @UPersistentForm.Register);
     25  RegisterUnit('UFindFile', @UFindFile.Register);
    2226end;
    2327
  • trunk/Packages/Common/UApplicationInfo.pas

    r54 r59  
    5555procedure Register;
    5656begin
    57   RegisterComponents('Samples', [TApplicationInfo]);
     57  RegisterComponents('Common', [TApplicationInfo]);
    5858end;
    5959
  • trunk/Packages/Common/UCommon.pas

    r55 r59  
    4848function LoggedOnUserNameEx(Format: TUserNameFormat): string;
    4949function SplitString(var Text: string; Count: Word): string;
     50function GetBitCount(Variable: QWord; MaxIndex: Integer): Integer;
    5051function GetBit(Variable: QWord; Index: Byte): Boolean;
     52procedure SetBit(var Variable: Int64; Index: Byte; State: Boolean); overload;
    5153procedure SetBit(var Variable: QWord; Index: Byte; State: Boolean); overload;
    5254procedure SetBit(var Variable: Cardinal; Index: Byte; State: Boolean); overload;
     
    336338end;
    337339
     340function GetBitCount(Variable: QWord; MaxIndex: Integer): Integer;
     341var
     342  I: Integer;
     343begin
     344  Result := 0;
     345  for I := 0 to MaxIndex - 1 do
     346    if ((Variable shr I) and 1) = 1 then Inc(Result);
     347end;
     348
    338349function GetBit(Variable:QWord;Index:Byte):Boolean;
    339350begin
     
    341352end;
    342353
     354procedure SetBit(var Variable: Int64; Index: Byte; State: Boolean);
     355begin
     356  Variable := (Variable and ((1 shl Index) xor High(QWord))) or (Int64(State) shl Index);
     357end;
     358
    343359procedure SetBit(var Variable:QWord;Index:Byte;State:Boolean); overload;
    344360begin
    345   Variable := (Variable and ((1 shl Index) xor QWord($ffffffffffffffff))) or (QWord(State) shl Index);
     361  Variable := (Variable and ((1 shl Index) xor High(QWord))) or (QWord(State) shl Index);
    346362end;
    347363
    348364procedure SetBit(var Variable:Cardinal;Index:Byte;State:Boolean); overload;
    349365begin
    350   Variable := (Variable and ((1 shl Index) xor Cardinal($ffffffff))) or (Cardinal(State) shl Index);
     366  Variable := (Variable and ((1 shl Index) xor High(Cardinal))) or (Cardinal(State) shl Index);
    351367end;
    352368
    353369procedure SetBit(var Variable:Word;Index:Byte;State:Boolean); overload;
    354370begin
    355   Variable := (Variable and ((1 shl Index) xor Word($ffff))) or (Word(State) shl Index);
     371  Variable := (Variable and ((1 shl Index) xor High(Word))) or (Word(State) shl Index);
    356372end;
    357373
  • trunk/Packages/Common/UDebugLog.pas

    r54 r59  
    3131    Items: TListObject;
    3232    Lock: TCriticalSection;
    33     procedure Add(Group: string; Text: string);
     33    procedure Add(Text: string; Group: string = '');
    3434    procedure WriteToFile(Text: string);
    3535    constructor Create(AOwner: TComponent); override;
     
    5252procedure Register;
    5353begin
    54   RegisterComponents('Samples', [TDebugLog]);
     54  RegisterComponents('Common', [TDebugLog]);
    5555end;
    5656
     
    6969end;
    7070
    71 procedure TDebugLog.Add(Group: string; Text: string);
     71procedure TDebugLog.Add(Text: string; Group: string = '');
    7272var
    7373  NewItem: TDebugLogItem;
  • trunk/Packages/Common/UFindFile.pas

    r54 r59  
    6464procedure Register;
    6565begin
    66   RegisterComponents('Samples', [TFindFile]);
     66  RegisterComponents('Common', [TFindFile]);
    6767end;
    6868
  • trunk/Packages/Common/UJobProgressView.lfm

    r54 r59  
    2828    object LabelOperation: TLabel
    2929      Left = 8
    30       Height = 14
     30      Height = 13
    3131      Top = 8
    32       Width = 67
     32      Width = 66
    3333      Caption = 'Operations:'
    3434      Font.Height = -11
     
    8080    object LabelEstimatedTimePart: TLabel
    8181      Left = 8
    82       Height = 14
     82      Height = 13
    8383      Top = -2
    84       Width = 72
     84      Width = 71
    8585      Caption = 'Estimated time:'
    8686      ParentColor = False
     
    132132    object LabelEstimatedTimeTotal: TLabel
    133133      Left = 8
    134       Height = 14
     134      Height = 13
    135135      Top = 0
    136       Width = 98
     136      Width = 97
    137137      Caption = 'Total estimated time:'
    138138      ParentColor = False
  • trunk/Packages/Common/UJobProgressView.pas

    r54 r59  
    111111    Finished: Boolean;
    112112    FOnJobFinish: TJobProgressViewMethod;
     113    FOnOwnerDraw: TNotifyEvent;
     114    FOwnerDraw: Boolean;
    113115    FShowDelay: Integer;
    114116    FTerminate: Boolean;
     
    116118    TotalStartTime: TDateTime;
    117119    Log: TStringList;
    118     Form: TFormJobProgressView;
    119120    procedure SetTerminate(const AValue: Boolean);
    120121    procedure UpdateProgress;
     
    122123    procedure StartJobs;
    123124    procedure UpdateHeight;
     125    procedure JobProgressChange(Sender: TObject);
    124126  public
     127    Form: TFormJobProgressView;
    125128    Jobs: TObjectList; // TListObject<TJob>
    126129    CurrentJob: TJob;
     
    136139    property Terminate: Boolean read FTerminate write SetTerminate;
    137140  published
     141    property OwnerDraw: Boolean read FOwnerDraw write FOwnerDraw;
    138142    property ShowDelay: Integer read FShowDelay write FShowDelay;
    139143    property AutoClose: Boolean read FAutoClose write FAutoClose;
    140144    property OnJobFinish: TJobProgressViewMethod read FOnJobFinish
    141145      write FOnJobFinish;
     146    property OnOwnerDraw: TNotifyEvent read FOnOwnerDraw
     147      write FOnOwnerDraw;
    142148  end;
    143149
     
    163169procedure Register;
    164170begin
    165   RegisterComponents('Samples', [TJobProgressView]);
     171  RegisterComponents('Common', [TJobProgressView]);
    166172end;
    167173
     
    196202  NewJob.Progress.Max := 100;
    197203  NewJob.Progress.Reset;
     204  NewJob.Progress.OnChange := JobProgressChange;
    198205  Jobs.Add(NewJob);
    199206  //ReloadJobList;
     
    212219  Terminate := False;
    213220
    214   Form.BringToFront;
     221  if not OwnerDraw then Form.BringToFront;
    215222
    216223  Finished := False;
     
    244251      CurrentJobIndex := I;
    245252      CurrentJob := TJob(Jobs[I]);
     253      JobProgressChange(Self);
    246254      StartTime := Now;
    247255      Form.LabelEstimatedTimePart.Caption := Format(SEstimatedTime, ['']);
     
    339347end;
    340348
     349procedure TJobProgressView.JobProgressChange(Sender: TObject);
     350begin
     351  if Assigned(FOnOwnerDraw) then
     352    FOnOwnerDraw(Self);
     353end;
     354
    341355procedure TFormJobProgressView.TimerUpdateTimer(Sender: TObject);
    342356var
     
    357371  if not Visible then begin
    358372    TimerUpdate.Interval := UpdateInterval;
    359     Show;
     373    if not JobProgressView.OwnerDraw then Show;
    360374  end;
    361375end;
     
    509523destructor TJobProgressView.Destroy;
    510524begin
    511   Log.Free;
    512   Jobs.Free;
    513   inherited Destroy;
     525  FreeAndNil(Log);
     526  FreeAndNil(Jobs);
     527  inherited;
    514528end;
    515529
     
    519533    FLock.Acquire;
    520534    FMax := AValue;
     535    if FMax < 1 then FMax := 1;
    521536    if FValue >= FMax then FValue := FMax;
    522537  finally
     
    610625begin
    611626  Progress.Free;
    612   inherited Destroy;
     627  inherited;
    613628end;
    614629
  • trunk/Packages/Common/ULastOpenedList.pas

    r55 r59  
    66
    77uses
    8   Classes, SysUtils, Registry, URegistry, Menus;
     8  Classes, SysUtils, Registry, URegistry, Menus, XMLConf;
    99
    1010type
     
    1818    procedure SetMaxCount(AValue: Integer);
    1919    procedure LimitMaxCount;
     20    procedure ItemsChange(Sender: TObject);
     21    procedure DoChange;
    2022  public
    2123    Items: TStringList;
     
    2527    procedure LoadFromRegistry(Context: TRegistryContext);
    2628    procedure SaveToRegistry(Context: TRegistryContext);
     29    procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; Path: string);
     30    procedure SaveToXMLConfig(XMLConfig: TXMLConfig; Path: string);
    2731    procedure AddItem(FileName: string);
    2832  published
     
    3842procedure Register;
    3943begin
    40   RegisterComponents('Samples', [TLastOpenedList]);
     44  RegisterComponents('Common', [TLastOpenedList]);
    4145end;
    4246
     
    5862end;
    5963
     64procedure TLastOpenedList.ItemsChange(Sender: TObject);
     65begin
     66  DoChange;
     67end;
     68
     69procedure TLastOpenedList.DoChange;
     70begin
     71  if Assigned(FOnChange) then
     72    FOnChange(Self);
     73end;
     74
    6075constructor TLastOpenedList.Create(AOwner: TComponent);
    6176begin
    6277  inherited;
    6378  Items := TStringList.Create;
     79  Items.OnChange := ItemsChange;
    6480  MaxCount := 10;
    6581end;
     
    129145end;
    130146
     147procedure TLastOpenedList.LoadFromXMLConfig(XMLConfig: TXMLConfig; Path: string
     148  );
     149var
     150  I: Integer;
     151  Value: string;
     152  Count: Integer;
     153begin
     154  with XMLConfig do begin
     155    Count := GetValue(Path + '/Count', 0);
     156    if Count > MaxCount then Count := MaxCount;
     157    Items.Clear;
     158    for I := 0 to Count - 1 do begin
     159      Value := GetValue(Path + '/File' + IntToStr(I), '');
     160      if Trim(Value) <> '' then Items.Add(Value);
     161    end;
     162    if Assigned(FOnChange) then
     163      FOnChange(Self);
     164  end;
     165end;
     166
     167procedure TLastOpenedList.SaveToXMLConfig(XMLConfig: TXMLConfig; Path: string);
     168var
     169  I: Integer;
     170begin
     171  with XMLConfig do begin
     172    SetValue(Path + '/Count', Items.Count);
     173    for I := 0 to Items.Count - 1 do
     174      SetValue(Path + '/File' + IntToStr(I), Items[I]);
     175    Flush;
     176  end;
     177end;
     178
    131179procedure TLastOpenedList.AddItem(FileName:string);
    132180begin
     
    134182  Items.Insert(0, FileName);
    135183  LimitMaxCount;
    136   if Assigned(FOnChange) then
    137     FOnChange(Self);
     184  DoChange;
    138185end;
    139186
  • trunk/Packages/Common/UMemory.pas

    r55 r59  
    2424    constructor Create;
    2525    destructor Destroy; override;
    26     procedure WriteMemory(Position: Integer; Memory: TMemory);
    27     procedure ReadMemory(Position: Integer; Memory: TMemory);
    2826    property Data: PByte read FData;
    2927    property Size: Integer read FSize write SetSize;
     
    110108end;
    111109
    112 procedure TMemory.WriteMemory(Position: Integer; Memory: TMemory);
    113 begin
    114   Move(Memory.FData, PByte(@FData + Position)^, Memory.Size);
    115 end;
    116 
    117 procedure TMemory.ReadMemory(Position: Integer; Memory: TMemory);
    118 begin
    119   Move(PByte(@FData + Position)^, Memory.FData, Memory.Size);
    120 end;
    121 
    122110end.
    123111
  • trunk/Packages/Common/URegistry.pas

    r55 r59  
    1717    rrKeyDynData = HKEY($80000006));
    1818
     19  { TRegistryContext }
     20
    1921  TRegistryContext = record
    2022    RootKey: HKEY;
    2123    Key: string;
     24    class operator Equal(A, B: TRegistryContext): Boolean;
    2225  end;
    2326
     
    2629  TRegistryEx = class(TRegistry)
    2730  private
     31    function GetCurrentContext: TRegistryContext;
     32    procedure SetCurrentContext(AValue: TRegistryContext);
    2833  public
    2934    function ReadBoolWithDefault(const Name: string;
     
    3540    function DeleteKeyRecursive(const Key: string): Boolean;
    3641    function OpenKey(const Key: string; CanCreate: Boolean): Boolean;
     42    property CurrentContext: TRegistryContext read GetCurrentContext write SetCurrentContext;
    3743  end;
    3844
     
    4652  Result.RootKey := RootKey;
    4753  Result.Key := Key;
     54end;
     55
     56{ TRegistryContext }
     57
     58class operator TRegistryContext.Equal(A, B: TRegistryContext): Boolean;
     59begin
     60  Result := (A.Key = B.Key) and (A.RootKey = B.RootKey);
    4861end;
    4962
     
    106119end;
    107120
     121function TRegistryEx.GetCurrentContext: TRegistryContext;
     122begin
     123  Result.Key := CurrentPath;
     124  Result.RootKey := RootKey;
     125end;
     126
     127procedure TRegistryEx.SetCurrentContext(AValue: TRegistryContext);
     128begin
     129  RootKey := AValue.RootKey;
     130  OpenKey(AValue.Key, True);
     131end;
     132
    108133function TRegistryEx.ReadBoolWithDefault(const Name: string;
    109134  DefaultValue: Boolean): Boolean;
  • trunk/Packages/Common/UResetableThread.pas

    r54 r59  
    104104
    105105procedure TResetableThread.WaitForStart;
    106 var
    107   WaitResult: TWaitResult;
     106//var
     107//  WaitResult: TWaitResult;
    108108begin
    109109  //try
     
    127127
    128128procedure TResetableThread.WaitForStop;
    129 var
    130   WaitState: TWaitResult;
     129//var
     130//  WaitState: TWaitResult;
    131131begin
    132132  try
  • trunk/Packages/Common/UURI.pas

    r54 r59  
    326326    Drive := Drive + DriveSeparator;
    327327  end else Drive := '';
    328   Directory.AsString := AValue;
     328  if (Drive <> '') and (AValue = '') then
     329    Directory.AsString := Directory.DirSeparator
     330    else Directory.AsString := AValue;
    329331end;
    330332
Note: See TracChangeset for help on using the changeset viewer.