Changeset 116


Ignore:
Timestamp:
Dec 10, 2016, 4:25:33 PM (8 years ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
Location:
trunk/Packages/Common
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/Languages/UJobProgressView.po

    r107 r116  
    1414msgstr ""
    1515
     16#: ujobprogressview.soperations
     17msgid "Operations"
     18msgstr ""
     19
    1620#: ujobprogressview.spleasewait
    1721msgid "Please wait..."
  • trunk/Packages/Common/UCommon.pas

    r109 r116  
    66
    77uses
    8   {$IFDEF Windows}Windows,{$ENDIF}
     8  {$ifdef Windows}Windows,{$endif}
     9  {$ifdef Linux}baseunix,{$endif}
    910  Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf,
    1011  FileUtil; //, ShFolder, ShellAPI;
     
    6566procedure FreeThenNil(var Obj);
    6667function RemoveQuotes(Text: string): string;
     68function ComputerName: string;
     69function OccurenceOfChar(What: Char; Where: string): Integer;
     70function GetDirCount(Dir: string): Integer;
     71function MergeArray(A, B: array of string): TArrayOfString;
    6772
    6873
     
    108113  Find := FindFirst(UTF8Decode(Path + AFileSpec), faAnyFile xor faDirectory, SearchRec);
    109114  while Find = 0 do begin
    110     DeleteFileUTF8(Path + UTF8Encode(SearchRec.Name));
     115    DeleteFile(Path + UTF8Encode(SearchRec.Name));
    111116
    112117    Find := SysUtils.FindNext(SearchRec);
     
    287292  L: LongWord;
    288293begin
    289 
    290294  L := MAX_USERNAME_LENGTH + 2;
    291295  SetLength(Result, L);
     
    302306  end;
    303307end;
    304 
     308{$endif}
     309
     310function ComputerName: string;
     311{$ifdef mswindows}
     312const
     313 INFO_BUFFER_SIZE = 32767;
     314var
     315  Buffer : array[0..INFO_BUFFER_SIZE] of WideChar;
     316  Ret : DWORD;
     317begin
     318  Ret := INFO_BUFFER_SIZE;
     319  If (GetComputerNameW(@Buffer[0],Ret)) then begin
     320    Result := UTF8Encode(WideString(Buffer));
     321  end
     322  else begin
     323    Result := 'ERROR_NO_COMPUTERNAME_RETURNED';
     324  end;
     325end;
     326{$endif}
     327{$ifdef unix}
     328var
     329  Name: UtsName;
     330begin
     331  fpuname(Name);
     332  Result := Name.Nodename;
     333end;
     334{$endif}
     335
     336{$ifdef windows}
    305337function LoggedOnUserNameEx(Format: TUserNameFormat): string;
    306338const
     
    417449
    418450procedure OpenWebPage(URL: string);
    419 var
    420   Process: TProcess;
    421   Browser, Params: string;
    422451begin
    423452  OpenURL(URL);
    424   {try
    425     Process := TProcess.Create(nil);
    426     Browser := '';
    427     //FindDefaultBrowser(Browser, Params);
    428     //Process.Executable := Browser;
    429     //Process.Parameters.Add(Format(Params, [ApplicationInfo.HomePage]);
    430     Process.CommandLine := 'cmd.exe /c start ' + URL;
    431     Process.Options := [poNoConsole];
    432     Process.Execute;
    433   finally
    434     Process.Free;
    435   end;}
    436453end;
    437454
     
    448465end;
    449466
     467function OccurenceOfChar(What: Char; Where: string): Integer;
     468var
     469  I: Integer;
     470begin
     471  Result := 0;
     472  for I := 1 to Length(Where) do
     473    if Where[I] = What then Inc(Result);
     474end;
     475
     476function GetDirCount(Dir: string): Integer;
     477begin
     478  Result := OccurenceOfChar(DirectorySeparator, Dir);
     479  if Copy(Dir, Length(Dir), 1) = DirectorySeparator then
     480    Dec(Result);
     481end;
     482
     483function MergeArray(A, B: array of string): TArrayOfString;
     484var
     485  I: Integer;
     486begin
     487  SetLength(Result, Length(A) + Length(B));
     488  for I := 0 to Length(A) - 1 do
     489    Result[I] := A[I];
     490  for I := 0 to Length(B) - 1 do
     491    Result[Length(A) + I] := B[I];
     492end;
     493
     494
    450495
    451496initialization
  • trunk/Packages/Common/UDebugLog.pas

    r43 r116  
    103103  try
    104104    if ExtractFileDir(FileName) <> '' then
    105       ForceDirectoriesUTF8(ExtractFileDir(FileName));
    106     if FileExistsUTF8(FileName) then LogFile := TFileStream.Create(UTF8Decode(FileName), fmOpenWrite)
     105      ForceDirectories(ExtractFileDir(FileName));
     106    if FileExists(FileName) then LogFile := TFileStream.Create(UTF8Decode(FileName), fmOpenWrite)
    107107      else LogFile := TFileStream.Create(UTF8Decode(FileName), fmCreate);
    108108    LogFile.Seek(0, soFromEnd);
  • trunk/Packages/Common/UJobProgressView.lfm

    r43 r116  
    1414  OnDestroy = FormDestroy
    1515  Position = poScreenCenter
    16   LCLVersion = '1.1'
     16  LCLVersion = '1.6.0.4'
    1717  object PanelOperationsTitle: TPanel
    1818    Left = 0
  • trunk/Packages/Common/UJobProgressView.lrt

    r43 r116  
    1 TJOBPROGRESSVIEW.LABELOPERATION.CAPTION=Operations:
    2 TJOBPROGRESSVIEW.LABELESTIMATEDTIMEPART.CAPTION=Estimated time:
    3 TJOBPROGRESSVIEW.LABELESTIMATEDTIMETOTAL.CAPTION=Total estimated time:
     1TFORMJOBPROGRESSVIEW.LABELOPERATION.CAPTION=Operations:
     2TFORMJOBPROGRESSVIEW.LABELESTIMATEDTIMEPART.CAPTION=Estimated time:
     3TFORMJOBPROGRESSVIEW.LABELESTIMATEDTIMETOTAL.CAPTION=Total estimated time:
  • trunk/Packages/Common/UJobProgressView.pas

    r43 r116  
    166166  STotalEstimatedTime = 'Total estimated time: %s';
    167167  SFinished = 'Finished';
     168  SOperations = 'Operations';
    168169
    169170procedure Register;
  • trunk/Packages/Common/UListViewSort.pas

    r109 r116  
    99uses
    1010  {$IFDEF Windows}Windows, CommCtrl, {$ENDIF}Classes, Graphics, ComCtrls, SysUtils,
    11   Controls, DateUtils, Dialogs, SpecializedList, Forms, Grids, StdCtrls, ExtCtrls;
     11  Controls, DateUtils, Dialogs, SpecializedList, Forms, Grids, StdCtrls, ExtCtrls,
     12  LclIntf, LMessages, LclType, LResources;
    1213
    1314type
     
    1819  TCompareEvent = function (Item1, Item2: TObject): Integer of object;
    1920  TListFilterEvent = procedure (ListViewSort: TListViewSort) of object;
     21
     22  { TListViewSort }
    2023
    2124  TListViewSort = class(TComponent)
     
    2831    FColumn: Integer;
    2932    FOrder: TSortOrder;
     33    FOldListViewWindowProc: TWndMethod;
     34    FOnColumnWidthChanged: TNotifyEvent;
     35    procedure DoColumnBeginResize(const AColIndex: Integer);
     36    procedure DoColumnResized(const AColIndex: Integer);
     37    procedure DoColumnResizing(const AColIndex, AWidth: Integer);
    3038    procedure SetListView(const Value: TListView);
    3139    procedure ColumnClick(Sender: TObject; Column: TListColumn);
     
    4048    procedure SetColumn(const Value: Integer);
    4149    procedure SetOrder(const Value: TSortOrder);
     50    {$IFDEF WINDOWS}
     51    procedure NewListViewWindowProc(var AMsg: TMessage);
     52    {$ENDIF}
    4253  public
    4354    List: TListObject;
     
    5869    property OnCustomDraw: TLVCustomDrawItemEvent read FOnCustomDraw
    5970      write FOnCustomDraw;
     71    property OnColumnWidthChanged: TNotifyEvent read FOnColumnWidthChanged
     72      write FOnColumnWidthChanged;
    6073    property Column: Integer read FColumn write SetColumn;
    6174    property Order: TSortOrder read FOrder write SetOrder;
     
    6982    FStringGrid1: TStringGrid;
    7083    procedure DoOnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
     84    procedure DoOnResize(Sender: TObject);
    7185  public
    7286    constructor Create(AOwner: TComponent); override;
    7387    procedure UpdateFromListView(ListView: TListView);
    7488    function TextEntered: Boolean;
     89    function TextEnteredCount: Integer;
    7590    function TextEnteredColumn(Index: Integer): Boolean;
    7691    function GetColValue(Index: Integer): string;
     
    8095    property Align;
    8196    property Anchors;
     97    property BorderSpacing;
    8298  end;
    8399
     
    99115  if Assigned(FOnChange) then
    100116    FOnChange(Self);
     117end;
     118
     119procedure TListViewFilter.DoOnResize(Sender: TObject);
     120begin
     121  FStringGrid1.DefaultRowHeight := FStringGrid1.Height;
    101122end;
    102123
     
    115136    goHorzLine, goRangeSelect, goEditing, goAlwaysShowEditor, goSmoothScroll];
    116137  FStringGrid1.OnKeyUp := DoOnKeyUp;
     138  FStringGrid1.OnResize := DoOnResize;
    117139end;
    118140
     
    120142var
    121143  I: Integer;
    122   NewColumn: TGridColumn;
    123144begin
    124145  with FStringGrid1 do begin
    125     Columns.Clear;
     146    //Columns.Clear;
    126147    while Columns.Count > ListView.Columns.Count do Columns.Delete(Columns.Count - 1);
    127     while Columns.Count < ListView.Columns.Count do NewColumn := Columns.Add;
     148    while Columns.Count < ListView.Columns.Count do Columns.Add;
    128149    for I := 0 to ListView.Columns.Count - 1 do begin
    129150      Columns[I].Width := ListView.Columns[I].Width;
     
    133154
    134155function TListViewFilter.TextEntered: Boolean;
     156begin
     157  Result := TextEnteredCount > 0;
     158end;
     159
     160function TListViewFilter.TextEnteredCount: Integer;
    135161var
    136162  I: Integer;
    137163begin
    138   Result := False;
     164  Result := 0;
    139165  for I := 0 to FStringGrid1.ColCount - 1 do begin
    140166    if FStringGrid1.Cells[I, 0] <> '' then begin
    141       Result := True;
    142       Break;
     167      Inc(Result);
    143168    end;
    144169  end;
     
    159184{ TListViewSort }
    160185
     186{$IFDEF WINDOWS}
     187procedure TListViewSort.NewListViewWindowProc(var AMsg: TMessage);
     188var
     189  vColWidth: Integer;
     190  vMsgNotify: TLMNotify absolute AMsg;
     191  Code: Integer;
     192begin
     193  // call the old WindowProc of ListView
     194  FOldListViewWindowProc(AMsg);
     195
     196  // Currently we care only with WM_NOTIFY message
     197  if AMsg.Msg = WM_NOTIFY then
     198  begin
     199    Code := PHDNotify(vMsgNotify.NMHdr)^.Hdr.Code;
     200    case Code of
     201      HDN_ENDTRACKA, HDN_ENDTRACKW:
     202        DoColumnResized(PHDNotify(vMsgNotify.NMHdr)^.Item);
     203
     204      HDN_BEGINTRACKA, HDN_BEGINTRACKW:
     205        DoColumnBeginResize(PHDNotify(vMsgNotify.NMHdr)^.Item);
     206
     207      HDN_TRACKA, HDN_TRACKW:
     208        begin
     209          vColWidth := -1;
     210          if (PHDNotify(vMsgNotify.NMHdr)^.PItem<>nil)
     211             and (PHDNotify(vMsgNotify.NMHdr)^.PItem^.Mask and HDI_WIDTH <> 0)
     212          then
     213            vColWidth := PHDNotify(vMsgNotify.NMHdr)^.PItem^.cxy;
     214
     215          DoColumnResizing(PHDNotify(vMsgNotify.NMHdr)^.Item, vColWidth);
     216        end;
     217    end;
     218  end;
     219end;
     220{$ENDIF}
     221
     222procedure TListViewSort.DoColumnBeginResize(const AColIndex: Integer);
     223begin
     224end;
     225
     226procedure TListViewSort.DoColumnResizing(const AColIndex, AWidth: Integer);
     227begin
     228end;
     229
     230procedure TListViewSort.DoColumnResized(const AColIndex: Integer);
     231begin
     232  if Assigned(FOnColumnWidthChanged) then
     233    FOnColumnWidthChanged(Self);
     234end;
    161235
    162236procedure TListViewSort.ColumnClick(Sender: TObject; Column: TListColumn);
     
    185259procedure TListViewSort.SetListView(const Value: TListView);
    186260begin
     261  if FListView = Value then Exit;
     262  if Assigned(FListView) then
     263    ListView.WindowProc := FOldListViewWindowProc;
    187264  FListView := Value;
    188265  FListView.OnColumnClick := ColumnClick;
    189266  FListView.OnCustomDrawItem := ListViewCustomDrawItem;
    190267  FListView.OnClick := ListViewClick;
     268  FOldListViewWindowProc := FListView.WindowProc;
     269  {$IFDEF WINDOWS}
     270  FListView.WindowProc := NewListViewWindowProc;
     271  {$ENDIF}
    191272end;
    192273
     
    205286  if ListView.Items.Count <> List.Count then
    206287    ListView.Items.Count := List.Count;
    207   if Assigned(FOnCompareItem) then Sort(FOnCompareItem);
     288  if Assigned(FOnCompareItem) and (Order <> soNone) then Sort(FOnCompareItem);
    208289  //ListView.Items[-1]; // Workaround for not show first row if selected
    209290  ListView.Refresh;
  • trunk/Packages/Common/UPersistentForm.pas

    r109 r116  
    88
    99uses
    10   Classes, SysUtils, Forms, URegistry, LCLIntf, Registry;
     10  Classes, SysUtils, Forms, URegistry, LCLIntf, Registry, Controls, ComCtrls;
    1111
    1212type
     
    1919    FMinVisiblePart: Integer;
    2020    FRegistryContext: TRegistryContext;
     21    procedure LoadControl(Control: TControl);
     22    procedure SaveControl(Control: TControl);
    2123  public
    2224    FormNormalSize: TRect;
     
    4951
    5052{ TPersistentForm }
     53
     54procedure TPersistentForm.LoadControl(Control: TControl);
     55var
     56  I: Integer;
     57  WinControl: TWinControl;
     58  Count: Integer;
     59begin
     60  if Control is TListView then begin
     61    with Form, TRegistryEx.Create do
     62    try
     63      RootKey := RegistryContext.RootKey;
     64      OpenKey(RegistryContext.Key + '\Forms\' + Form.Name + '\' + Control.Name, True);
     65      for I := 0 to TListView(Control).Columns.Count - 1 do begin
     66        if ValueExists('ColWidth' + IntToStr(I)) then
     67          TListView(Control).Columns[I].Width := ReadInteger('ColWidth' + IntToStr(I));
     68      end;
     69    finally
     70      Free;
     71    end;
     72  end;
     73
     74  if Control is TWinControl then begin
     75    WinControl := TWinControl(Control);
     76    if WinControl.ControlCount > 0 then begin
     77      for I := 0 to WinControl.ControlCount - 1 do begin
     78        if WinControl.Controls[I] is TControl then begin
     79          LoadControl(WinControl.Controls[I]);
     80        end;
     81      end;
     82    end;
     83  end;
     84end;
     85
     86procedure TPersistentForm.SaveControl(Control: TControl);
     87var
     88  I: Integer;
     89  WinControl: TWinControl;
     90begin
     91  if Control is TListView then begin
     92    with Form, TRegistryEx.Create do
     93    try
     94      RootKey := RegistryContext.RootKey;
     95      OpenKey(RegistryContext.Key + '\Forms\' + Form.Name + '\' + Control.Name, True);
     96      for I := 0 to TListView(Control).Columns.Count - 1 do begin
     97        WriteInteger('ColWidth' + IntToStr(I), TListView(Control).Columns[I].Width);
     98      end;
     99    finally
     100      Free;
     101    end;
     102  end;
     103
     104  if Control is TWinControl then begin
     105      WinControl := TWinControl(Control);
     106      if WinControl.ControlCount > 0 then begin
     107        for I := 0 to WinControl.ControlCount - 1 do begin
     108          if WinControl.Controls[I] is TControl then begin
     109            SaveControl(WinControl.Controls[I]);
     110          end;
     111        end;
     112      end;
     113    end;
     114end;
    51115
    52116procedure TPersistentForm.LoadFromRegistry(RegistryContext: TRegistryContext);
     
    181245      Form.BoundsRect := FormNormalSize;
    182246  end;
     247  LoadControl(Form);
    183248end;
    184249
     
    191256  FormWindowState := Form.WindowState;
    192257  SaveToRegistry(RegistryContext);
     258  SaveControl(Form);
    193259end;
    194260
  • trunk/Packages/Common/UScaleDPI.pas

    r107 r116  
    309309  end;
    310310
     311  if Control is TCoolBar then
     312  with TCoolBar(Control) do begin
     313    BeginUpdate;
     314    for I := 0 to Bands.Count - 1 do
     315      with Bands[I] do begin
     316        MinWidth := ScaleX(MinWidth, FromDPI.X);
     317        MinHeight := ScaleY(MinHeight, FromDPI.Y);
     318        Width := ScaleX(Width, FromDPI.X);
     319        //Control.Invalidate;
     320      end;
     321    EndUpdate;
     322  end;
     323
    311324  if Control is TToolBar then begin
    312325    ToolBarControl := TToolBar(Control);
Note: See TracChangeset for help on using the changeset viewer.