Changeset 73 for trunk/Packages
- Timestamp:
- Oct 27, 2016, 3:00:47 PM (8 years ago)
- Location:
- trunk/Packages
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Common.lpk
r72 r73 13 13 <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> 14 14 </SearchPaths> 15 <Other>16 <CompilerMessages>17 <IgnoredMessages idx5024="True"/>18 </CompilerMessages>19 </Other>20 15 </CompilerOptions> 21 16 <Description Value="Various libraries"/> … … 115 110 <EnableI18N Value="True"/> 116 111 <OutDir Value="Languages"/> 112 <EnableI18NForLFM Value="True"/> 117 113 </i18n> 118 <RequiredPkgs Count=" 2">114 <RequiredPkgs Count="3"> 119 115 <Item1> 120 <PackageName Value=" TemplateGenerics"/>116 <PackageName Value="LCL"/> 121 117 </Item1> 122 118 <Item2> 119 <PackageName Value="TemplateGenerics"/> 120 </Item2> 121 <Item3> 123 122 <PackageName Value="FCL"/> 124 123 <MinVersion Major="1" Valid="True"/> 125 </Item 2>124 </Item3> 126 125 </RequiredPkgs> 127 126 <UsageOptions> -
trunk/Packages/Common/Common.pas
r72 r73 5 5 unit Common; 6 6 7 {$warn 5023 off : no warning about unused units}8 7 interface 9 8 -
trunk/Packages/Common/Languages/UJobProgressView.po
r68 r73 14 14 msgstr "" 15 15 16 #: ujobprogressview.soperations 17 msgid "Operations" 18 msgstr "" 19 16 20 #: ujobprogressview.spleasewait 17 21 msgid "Please wait..." -
trunk/Packages/Common/UApplicationInfo.pas
r72 r73 6 6 7 7 uses 8 SysUtils, Classes, Forms, URegistry;8 SysUtils, Registry, Classes, Forms, URegistry; 9 9 10 10 type … … 15 15 private 16 16 FIdentification: Byte; 17 FLicense: string; 17 18 FVersionMajor: Byte; 18 19 FVersionMinor: Byte; … … 47 48 property RegistryKey: string read FRegistryKey write FRegistryKey; 48 49 property RegistryRoot: TRegistryRoot read FRegistryRoot write FRegistryRoot; 50 property License: string read FLicense write FLicense; 49 51 end; 50 52 -
trunk/Packages/Common/UCommon.pas
r72 r73 8 8 {$IFDEF Windows}Windows,{$ENDIF} 9 9 Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf, 10 FileUtil , LazFileUtils; //, ShFolder, ShellAPI;10 FileUtil; //, ShFolder, ShellAPI; 11 11 12 12 type … … 64 64 procedure ExecuteProgram(CommandLine: string); 65 65 procedure FreeThenNil(var Obj); 66 function RemoveQuotes(Text: string): string; 67 function ComputerName: string; 68 function OccurenceOfChar(What: Char; Where: string): Integer; 69 function GetDirCount(Dir: string): Integer; 70 function MergeArray(A, B: array of string): TArrayOfString; 66 71 67 72 … … 91 96 I: Integer; 92 97 begin 93 Result := '';94 98 for I := 1 to Length(Source) do begin 95 99 Result := Result + LowerCase(IntToHex(Ord(Source[I]), 2)); … … 106 110 Path := IncludeTrailingPathDelimiter(APath); 107 111 108 Find := FindFirst( Path + AFileSpec, faAnyFile xor faDirectory, SearchRec);112 Find := FindFirst(UTF8Decode(Path + AFileSpec), faAnyFile xor faDirectory, SearchRec); 109 113 while Find = 0 do begin 110 DeleteFile UTF8(Path + SearchRec.Name);114 DeleteFile(Path + UTF8Encode(SearchRec.Name)); 111 115 112 116 Find := SysUtils.FindNext(SearchRec); … … 287 291 L: LongWord; 288 292 begin 289 290 293 L := MAX_USERNAME_LENGTH + 2; 291 294 SetLength(Result, L); … … 302 305 end; 303 306 end; 307 308 function ComputerName: string; 309 {$ifdef mswindows} 310 const 311 INFO_BUFFER_SIZE = 32767; 312 var 313 Buffer : array[0..INFO_BUFFER_SIZE] of WideChar; 314 Ret : DWORD; 315 begin 316 Ret := INFO_BUFFER_SIZE; 317 If (GetComputerNameW(@Buffer[0],Ret)) then begin 318 Result := UTF8Encode(WideString(Buffer)); 319 end 320 else begin 321 Result := 'ERROR_NO_COMPUTERNAME_RETURNED'; 322 end; 323 end; 324 {$endif} 325 {$ifdef unix} 326 begin 327 Result := GetHostName; 328 end; 329 {$endif} 304 330 305 331 function LoggedOnUserNameEx(Format: TUserNameFormat): string; … … 417 443 418 444 procedure OpenWebPage(URL: string); 445 var 446 Process: TProcess; 447 Browser, Params: string; 419 448 begin 420 449 OpenURL(URL); 450 {try 451 Process := TProcess.Create(nil); 452 Browser := ''; 453 //FindDefaultBrowser(Browser, Params); 454 //Process.Executable := Browser; 455 //Process.Parameters.Add(Format(Params, [ApplicationInfo.HomePage]); 456 Process.CommandLine := 'cmd.exe /c start ' + URL; 457 Process.Options := [poNoConsole]; 458 Process.Execute; 459 finally 460 Process.Free; 461 end;} 421 462 end; 422 463 … … 426 467 end; 427 468 469 function RemoveQuotes(Text: string): string; 470 begin 471 Result := Text; 472 if (Pos('"', Text) = 1) and (Text[Length(Text)] = '"') then 473 Result := Copy(Text, 2, Length(Text) - 2); 474 end; 475 476 function OccurenceOfChar(What: Char; Where: string): Integer; 477 var 478 I: Integer; 479 begin 480 Result := 0; 481 for I := 1 to Length(Where) do 482 if Where[I] = What then Inc(Result); 483 end; 484 485 function GetDirCount(Dir: string): Integer; 486 begin 487 Result := OccurenceOfChar(DirectorySeparator, Dir); 488 if Copy(Dir, Length(Dir), 1) = DirectorySeparator then 489 Dec(Result); 490 end; 491 492 function MergeArray(A, B: array of string): TArrayOfString; 493 var 494 I: Integer; 495 begin 496 SetLength(Result, Length(A) + Length(B)); 497 for I := 0 to Length(A) - 1 do 498 Result[I] := A[I]; 499 for I := 0 to Length(B) - 1 do 500 Result[Length(A) + I] := B[I]; 501 end; 502 503 504 428 505 initialization 429 506 -
trunk/Packages/Common/UDebugLog.pas
r72 r73 6 6 7 7 uses 8 Classes, SysUtils, FileUtil, SpecializedList, SyncObjs , LazFileUtils;8 Classes, SysUtils, FileUtil, SpecializedList, SyncObjs; 9 9 10 10 type … … 103 103 try 104 104 if ExtractFileDir(FileName) <> '' then 105 ForceDirectories UTF8(ExtractFileDir(FileName));106 if FileExists UTF8(FileName) then LogFile := TFileStream.Create(FileName, fmOpenWrite)107 else LogFile := TFileStream.Create( FileName, fmCreate);105 ForceDirectories(ExtractFileDir(FileName)); 106 if FileExists(FileName) then LogFile := TFileStream.Create(UTF8Decode(FileName), fmOpenWrite) 107 else LogFile := TFileStream.Create(UTF8Decode(FileName), fmCreate); 108 108 LogFile.Seek(0, soFromEnd); 109 109 Text := FormatDateTime('hh:nn:ss.zzz', Now) + ': ' + Text + LineEnding; -
trunk/Packages/Common/UFindFile.pas
r72 r73 24 24 25 25 uses 26 SysUtils, Classes, Graphics, Controls, Forms, Dialogs ;26 SysUtils, Classes, Graphics, Controls, Forms, Dialogs, FileCtrl; 27 27 28 28 type … … 55 55 end; 56 56 57 const 58 {$IFDEF WINDOWS} 59 FilterAll = '*.*'; 60 {$ENDIF} 61 {$IFDEF LINUX} 62 FilterAll = '*'; 63 {$ENDIF} 64 57 65 procedure Register; 58 66 … … 71 79 inherited Create(AOwner); 72 80 Path := IncludeTrailingBackslash(UTF8Encode(GetCurrentDir)); 73 FileMask := '*.*';81 FileMask := FilterAll; 74 82 FileAttr := [ffaAnyFile]; 75 83 s := TStringList.Create; … … 116 124 if ffaAnyFile in FileAttr then Attr := Attr + faAnyFile; 117 125 118 if SysUtils.FindFirst( inPath + FileMask, Attr, Rec) = 0 then126 if SysUtils.FindFirst(UTF8Decode(inPath + FileMask), Attr, Rec) = 0 then 119 127 try 120 128 repeat … … 127 135 If not InSubFolders then Exit; 128 136 129 if SysUtils.FindFirst( inPath + '*.*', faDirectory, Rec) = 0 then137 if SysUtils.FindFirst(UTF8Decode(inPath + FilterAll), faDirectory, Rec) = 0 then 130 138 try 131 139 repeat -
trunk/Packages/Common/UJobProgressView.lfm
r59 r73 14 14 OnDestroy = FormDestroy 15 15 Position = poScreenCenter 16 LCLVersion = '1. 1'16 LCLVersion = '1.6.0.4' 17 17 object PanelOperationsTitle: TPanel 18 18 Left = 0 -
trunk/Packages/Common/UJobProgressView.lrt
r54 r73 1 T JOBPROGRESSVIEW.LABELOPERATION.CAPTION=Operations:2 T JOBPROGRESSVIEW.LABELESTIMATEDTIMEPART.CAPTION=Estimated time:3 T JOBPROGRESSVIEW.LABELESTIMATEDTIMETOTAL.CAPTION=Total estimated time:1 TFORMJOBPROGRESSVIEW.LABELOPERATION.CAPTION=Operations: 2 TFORMJOBPROGRESSVIEW.LABELESTIMATEDTIMEPART.CAPTION=Estimated time: 3 TFORMJOBPROGRESSVIEW.LABELESTIMATEDTIMETOTAL.CAPTION=Total estimated time: -
trunk/Packages/Common/UJobProgressView.pas
r59 r73 166 166 STotalEstimatedTime = 'Total estimated time: %s'; 167 167 SFinished = 'Finished'; 168 SOperations = 'Operations'; 168 169 169 170 procedure Register; -
trunk/Packages/Common/ULastOpenedList.pas
r72 r73 139 139 OpenKey(Context.Key, True); 140 140 for I := 0 to Items.Count - 1 do 141 WriteString('File' + IntToStr(I), Items[I]);141 WriteString('File' + IntToStr(I), UTF8Decode(Items[I])); 142 142 finally 143 143 Free; -
trunk/Packages/Common/UListViewSort.pas
r72 r73 9 9 uses 10 10 {$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; 12 13 13 14 type … … 18 19 TCompareEvent = function (Item1, Item2: TObject): Integer of object; 19 20 TListFilterEvent = procedure (ListViewSort: TListViewSort) of object; 21 22 { TListViewSort } 20 23 21 24 TListViewSort = class(TComponent) … … 28 31 FColumn: Integer; 29 32 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); 30 38 procedure SetListView(const Value: TListView); 31 39 procedure ColumnClick(Sender: TObject; Column: TListColumn); … … 40 48 procedure SetColumn(const Value: Integer); 41 49 procedure SetOrder(const Value: TSortOrder); 50 {$IFDEF WINDOWS} 51 procedure NewListViewWindowProc(var AMsg: TMessage); 52 {$ENDIF} 42 53 public 43 54 List: TListObject; … … 58 69 property OnCustomDraw: TLVCustomDrawItemEvent read FOnCustomDraw 59 70 write FOnCustomDraw; 71 property OnColumnWidthChanged: TNotifyEvent read FOnColumnWidthChanged 72 write FOnColumnWidthChanged; 60 73 property Column: Integer read FColumn write SetColumn; 61 74 property Order: TSortOrder read FOrder write SetOrder; … … 69 82 FStringGrid1: TStringGrid; 70 83 procedure DoOnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); 84 procedure DoOnResize(Sender: TObject); 71 85 public 72 86 constructor Create(AOwner: TComponent); override; 73 87 procedure UpdateFromListView(ListView: TListView); 74 88 function TextEntered: Boolean; 89 function TextEnteredCount: Integer; 90 function TextEnteredColumn(Index: Integer): Boolean; 75 91 function GetColValue(Index: Integer): string; 76 92 property StringGrid: TStringGrid read FStringGrid1 write FStringGrid1; … … 79 95 property Align; 80 96 property Anchors; 97 property BorderSpacing; 81 98 end; 82 99 … … 98 115 if Assigned(FOnChange) then 99 116 FOnChange(Self); 117 end; 118 119 procedure TListViewFilter.DoOnResize(Sender: TObject); 120 begin 121 FStringGrid1.DefaultRowHeight := FStringGrid1.Height; 100 122 end; 101 123 … … 114 136 goHorzLine, goRangeSelect, goEditing, goAlwaysShowEditor, goSmoothScroll]; 115 137 FStringGrid1.OnKeyUp := DoOnKeyUp; 138 FStringGrid1.OnResize := DoOnResize; 116 139 end; 117 140 … … 121 144 begin 122 145 with FStringGrid1 do begin 123 Columns.Clear;146 //Columns.Clear; 124 147 while Columns.Count > ListView.Columns.Count do Columns.Delete(Columns.Count - 1); 125 148 while Columns.Count < ListView.Columns.Count do Columns.Add; … … 131 154 132 155 function TListViewFilter.TextEntered: Boolean; 156 begin 157 Result := TextEnteredCount > 0; 158 end; 159 160 function TListViewFilter.TextEnteredCount: Integer; 133 161 var 134 162 I: Integer; 135 163 begin 136 Result := False;164 Result := 0; 137 165 for I := 0 to FStringGrid1.ColCount - 1 do begin 138 166 if FStringGrid1.Cells[I, 0] <> '' then begin 139 Result := True; 140 Break; 167 Inc(Result); 141 168 end; 142 169 end; 170 end; 171 172 function TListViewFilter.TextEnteredColumn(Index: Integer): Boolean; 173 begin 174 Result := FStringGrid1.Cells[Index, 0] <> ''; 143 175 end; 144 176 … … 152 184 { TListViewSort } 153 185 186 {$IFDEF WINDOWS} 187 procedure TListViewSort.NewListViewWindowProc(var AMsg: TMessage); 188 var 189 vColWidth: Integer; 190 vMsgNotify: TLMNotify absolute AMsg; 191 Code: Integer; 192 begin 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; 219 end; 220 {$ENDIF} 221 222 procedure TListViewSort.DoColumnBeginResize(const AColIndex: Integer); 223 begin 224 end; 225 226 procedure TListViewSort.DoColumnResizing(const AColIndex, AWidth: Integer); 227 begin 228 end; 229 230 procedure TListViewSort.DoColumnResized(const AColIndex: Integer); 231 begin 232 if Assigned(FOnColumnWidthChanged) then 233 FOnColumnWidthChanged(Self); 234 end; 154 235 155 236 procedure TListViewSort.ColumnClick(Sender: TObject; Column: TListColumn); … … 178 259 procedure TListViewSort.SetListView(const Value: TListView); 179 260 begin 261 if FListView = Value then Exit; 262 if Assigned(FListView) then 263 ListView.WindowProc := FOldListViewWindowProc; 180 264 FListView := Value; 181 265 FListView.OnColumnClick := ColumnClick; 182 266 FListView.OnCustomDrawItem := ListViewCustomDrawItem; 183 267 FListView.OnClick := ListViewClick; 268 FOldListViewWindowProc := FListView.WindowProc; 269 {$IFDEF WINDOWS} 270 FListView.WindowProc := NewListViewWindowProc; 271 {$ENDIF} 184 272 end; 185 273 … … 198 286 if ListView.Items.Count <> List.Count then 199 287 ListView.Items.Count := List.Count; 200 if Assigned(FOnCompareItem) then Sort(FOnCompareItem);288 if Assigned(FOnCompareItem) and (Order <> soNone) then Sort(FOnCompareItem); 201 289 //ListView.Items[-1]; // Workaround for not show first row if selected 202 290 ListView.Refresh; -
trunk/Packages/Common/UPersistentForm.pas
r59 r73 3 3 {$mode delphi} 4 4 5 // Date: 201 0-06-015 // Date: 2015-04-18 6 6 7 7 interface … … 20 20 FRegistryContext: TRegistryContext; 21 21 public 22 FormNormalSize: TRect; 23 FormRestoredSize: TRect; 24 FormWindowState: TWindowState; 25 Form: TForm; 26 procedure LoadFromRegistry(RegistryContext: TRegistryContext); 27 procedure SaveToRegistry(RegistryContext: TRegistryContext); 22 28 function CheckEntireVisible(Rect: TRect): TRect; 23 29 function CheckPartVisible(Rect: TRect; Part: Integer): TRect; … … 44 50 { TPersistentForm } 45 51 52 procedure TPersistentForm.LoadFromRegistry(RegistryContext: TRegistryContext); 53 begin 54 with TRegistryEx.Create do 55 try 56 RootKey := RegistryContext.RootKey; 57 OpenKey(RegistryContext.Key + '\Forms\' + Form.Name, True); 58 // Normal size 59 FormNormalSize.Left := ReadIntegerWithDefault('NormalLeft', FormNormalSize.Left); 60 FormNormalSize.Top := ReadIntegerWithDefault('NormalTop', FormNormalSize.Top); 61 FormNormalSize.Right := ReadIntegerWithDefault('NormalWidth', FormNormalSize.Right - FormNormalSize.Left) 62 + FormNormalSize.Left; 63 FormNormalSize.Bottom := ReadIntegerWithDefault('NormalHeight', FormNormalSize.Bottom - FormNormalSize.Top) 64 + FormNormalSize.Top; 65 // Restored size 66 FormRestoredSize.Left := ReadIntegerWithDefault('RestoredLeft', FormRestoredSize.Left); 67 FormRestoredSize.Top := ReadIntegerWithDefault('RestoredTop', FormRestoredSize.Top); 68 FormRestoredSize.Right := ReadIntegerWithDefault('RestoredWidth', FormRestoredSize.Right - FormRestoredSize.Left) 69 + FormRestoredSize.Left; 70 FormRestoredSize.Bottom := ReadIntegerWithDefault('RestoredHeight', FormRestoredSize.Bottom - FormRestoredSize.Top) 71 + FormRestoredSize.Top; 72 // Other state 73 FormWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(wsNormal))); 74 finally 75 Free; 76 end; 77 end; 78 79 procedure TPersistentForm.SaveToRegistry(RegistryContext: TRegistryContext); 80 begin 81 with Form, TRegistryEx.Create do 82 try 83 RootKey := RegistryContext.RootKey; 84 OpenKey(RegistryContext.Key + '\Forms\' + Form.Name, True); 85 // Normal state 86 WriteInteger('NormalWidth', FormNormalSize.Right - FormNormalSize.Left); 87 WriteInteger('NormalHeight', FormNormalSize.Bottom - FormNormalSize.Top); 88 WriteInteger('NormalTop', FormNormalSize.Top); 89 WriteInteger('NormalLeft', FormNormalSize.Left); 90 // Restored state 91 WriteInteger('RestoredWidth', FormRestoredSize.Right - FormRestoredSize.Left); 92 WriteInteger('RestoredHeight', FormRestoredSize.Bottom - FormRestoredSize.Top); 93 WriteInteger('RestoredTop', FormRestoredSize.Top); 94 WriteInteger('RestoredLeft', FormRestoredSize.Left); 95 // Other state 96 WriteInteger('WindowState', Integer(FormWindowState)); 97 finally 98 Free; 99 end; 100 end; 101 46 102 function TPersistentForm.CheckEntireVisible(Rect: TRect): TRect; 47 103 var … … 98 154 procedure TPersistentForm.Load(Form: TForm; DefaultMaximized: Boolean = False); 99 155 var 100 Normal: TRect;101 Restored: TRect;102 156 LoadDefaults: Boolean; 103 157 begin 104 with TRegistryEx.Create do 105 try 106 RootKey := RegistryContext.RootKey; 107 OpenKey(RegistryContext.Key + '\Forms\' + Form.Name, True); 108 109 //RestoredWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(Form.WindowState))); 110 //if RestoredWindowState = wsMinimized then 111 // RestoredWindowState := wsNormal; 112 //Form.WindowState := RestoredWindowState; 113 LoadDefaults := not ValueExists('NormalLeft'); 114 Normal := Bounds(ReadIntegerWithDefault('NormalLeft', (Screen.Width - Form.Width) div 2), 115 ReadIntegerWithDefault('NormalTop', (Screen.Height - Form.Height) div 2), 116 ReadIntegerWithDefault('NormalWidth', Form.Width), 117 ReadIntegerWithDefault('NormalHeight', Form.Height)); 118 Restored := Bounds(ReadIntegerWithDefault('RestoredLeft', (Screen.Width - Form.Width) div 2), 119 ReadIntegerWithDefault('RestoredTop', (Screen.Height - Form.Height) div 2), 120 ReadIntegerWithDefault('RestoredWidth', Form.Width), 121 ReadIntegerWithDefault('RestoredHeight', Form.Height)); 122 123 if not EqualRect(Normal, Restored) or 124 (LoadDefaults and DefaultMaximized) then begin 125 // Restore to maximized state 126 Form.WindowState := wsNormal; 127 if not EqualRect(Restored, Form.BoundsRect) then 128 Form.BoundsRect := Restored; 129 Form.WindowState := wsMaximized; 130 end else begin 131 // Restore to normal state 132 Form.WindowState := wsNormal; 133 if FEntireVisible then Normal := CheckEntireVisible(Normal) 134 else if FMinVisiblePart > 0 then 135 Normal := CheckPartVisible(Normal, FMinVisiblePart); 136 if not EqualRect(Normal, Form.BoundsRect) then 137 Form.BoundsRect := Normal; 138 end; 139 140 //if ReadBoolWithDefault('Visible', False) then Form.Show; 141 finally 142 Free; 143 end; 158 Self.Form := Form; 159 // Set default 160 FormNormalSize := Bounds((Screen.Width - Form.Width) div 2, 161 (Screen.Height - Form.Height) div 2, Form.Width, Form.Height); 162 FormRestoredSize := Bounds((Screen.Width - Form.Width) div 2, 163 (Screen.Height - Form.Height) div 2, Form.Width, Form.Height); 164 165 LoadFromRegistry(RegistryContext); 166 167 if not EqualRect(FormNormalSize, FormRestoredSize) or 168 (LoadDefaults and DefaultMaximized) then begin 169 // Restore to maximized state 170 Form.WindowState := wsNormal; 171 if not EqualRect(FormRestoredSize, Form.BoundsRect) then 172 Form.BoundsRect := FormRestoredSize; 173 Form.WindowState := wsMaximized; 174 end else begin 175 // Restore to normal state 176 Form.WindowState := wsNormal; 177 if FEntireVisible then FormNormalSize := CheckEntireVisible(FormNormalSize) 178 else if FMinVisiblePart > 0 then 179 FormNormalSize := CheckPartVisible(FormNormalSize, FMinVisiblePart); 180 if not EqualRect(FormNormalSize, Form.BoundsRect) then 181 Form.BoundsRect := FormNormalSize; 182 end; 144 183 end; 145 184 146 185 procedure TPersistentForm.Save(Form: TForm); 147 186 begin 148 with Form, TRegistryEx.Create do 149 try 150 RootKey := RegistryContext.RootKey; 151 OpenKey(RegistryContext.Key + '\Forms\' + Form.Name, True); 152 WriteInteger('NormalWidth', Form.Width); 153 WriteInteger('NormalHeight', Form.Height); 154 WriteInteger('NormalTop', Form.Top); 155 WriteInteger('NormalLeft', Form.Left); 156 WriteInteger('RestoredWidth', Form.RestoredWidth); 157 WriteInteger('RestoredHeight', Form.RestoredHeight); 158 WriteInteger('RestoredTop', Form.RestoredTop); 159 WriteInteger('RestoredLeft', Form.RestoredLeft); 160 //WriteInteger('WindowState', Integer(Form.WindowState)); 161 //WriteBool('Visible', Form.Visible); 162 finally 163 Free; 164 end; 187 Self.Form := Form; 188 FormNormalSize := Bounds(Form.Left, Form.Top, Form.Width, Form.Height); 189 FormRestoredSize := Bounds(Form.RestoredLeft, Form.RestoredTop, Form.RestoredWidth, 190 Form.RestoredHeight); 191 FormWindowState := Form.WindowState; 192 SaveToRegistry(RegistryContext); 165 193 end; 166 194 … … 168 196 begin 169 197 inherited; 198 if AOwner is TForm then Form := TForm(AOwner) 199 else Form := nil; 170 200 FMinVisiblePart := 50; 171 201 FRegistryContext.RootKey := HKEY_CURRENT_USER; -
trunk/Packages/Common/UScaleDPI.pas
r72 r73 8 8 9 9 uses 10 Classes, Forms, Graphics, Controls, ComCtrls, LCLType; 10 Classes, Forms, Graphics, Controls, ComCtrls, LCLType, SysUtils, StdCtrls, 11 Contnrs; 11 12 12 13 type 14 15 { TControlDimension } 16 17 TControlDimension = class 18 BoundsRect: TRect; 19 FontHeight: Integer; 20 Controls: TObjectList; // TList<TControlDimension> 21 // Class specifics 22 ButtonSize: TPoint; // TToolBar 23 CoolBandWidth: Integer; 24 ConstraintsMin: TPoint; // TForm 25 ConstraintsMax: TPoint; // TForm 26 constructor Create; 27 destructor Destroy; override; 28 end; 13 29 14 30 { TScaleDPI } … … 17 33 private 18 34 FAutoDetect: Boolean; 35 FDesignDPI: TPoint; 36 FDPI: TPoint; 19 37 procedure SetAutoDetect(AValue: Boolean); 38 procedure SetDesignDPI(AValue: TPoint); 39 procedure SetDPI(AValue: TPoint); 20 40 public 21 DPI: TPoint; 22 DesignDPI: TPoint; 41 procedure StoreDimensions(Control: TControl; Dimensions: TControlDimension); 42 procedure RestoreDimensions(Control: TControl; Dimensions: TControlDimension); 43 procedure ScaleDimensions(Control: TControl; Dimensions: TControlDimension); 23 44 procedure ApplyToAll(FromDPI: TPoint); 24 procedure Scale DPI(Control: TControl; FromDPI: TPoint);45 procedure ScaleControl(Control: TControl; FromDPI: TPoint); 25 46 procedure ScaleImageList(ImgList: TImageList; FromDPI: TPoint); 26 function ScaleXY(Size: TPoint; FromDPI: Integer): TPoint; 47 function ScalePoint(APoint: TPoint; FromDPI: TPoint): TPoint; 48 function ScaleRect(ARect: TRect; FromDPI: TPoint): TRect; 27 49 function ScaleX(Size: Integer; FromDPI: Integer): Integer; 28 50 function ScaleY(Size: Integer; FromDPI: Integer): Integer; 29 51 constructor Create(AOwner: TComponent); override; 52 property DesignDPI: TPoint read FDesignDPI write SetDesignDPI; 53 property DPI: TPoint read FDPI write SetDPI; 30 54 published 31 55 property AutoDetect: Boolean read FAutoDetect write SetAutoDetect; … … 34 58 procedure Register; 35 59 60 36 61 implementation 37 62 63 resourcestring 64 SWrongDPI = 'Wrong DPI [%d,%d]'; 65 38 66 procedure Register; 39 67 begin 40 68 RegisterComponents('Common', [TScaleDPI]); 69 end; 70 71 { TControlDimension } 72 73 constructor TControlDimension.Create; 74 begin 75 Controls := TObjectList.Create; 76 end; 77 78 destructor TControlDimension.Destroy; 79 begin 80 FreeAndNil(Controls); 81 inherited Destroy; 41 82 end; 42 83 … … 50 91 end; 51 92 93 procedure TScaleDPI.SetDesignDPI(AValue: TPoint); 94 begin 95 if (FDesignDPI.X = AValue.X) and (FDesignDPI.Y = AValue.Y) then Exit; 96 if (AValue.X <= 0) or (AValue.Y <= 0) then 97 raise Exception.Create(Format(SWrongDPI, [AValue.X, AValue.Y])); 98 FDesignDPI := AValue; 99 end; 100 101 procedure TScaleDPI.SetDPI(AValue: TPoint); 102 begin 103 if (FDPI.X = AValue.X) and (FDPI.Y = AValue.Y) then Exit; 104 if (AValue.X <= 0) or (AValue.Y <= 0) then 105 raise Exception.Create(Format(SWrongDPI, [AValue.X, AValue.Y])); 106 FDPI := AValue; 107 end; 108 109 procedure TScaleDPI.StoreDimensions(Control: TControl; 110 Dimensions: TControlDimension); 111 var 112 NewControl: TControlDimension; 113 I: Integer; 114 begin 115 Dimensions.BoundsRect := Control.BoundsRect; 116 Dimensions.FontHeight := Control.Font.GetTextHeight('Hg'); 117 Dimensions.Controls.Clear; 118 if Control is TToolBar then 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; 126 if Control is TWinControl then 127 for I := 0 to TWinControl(Control).ControlCount - 1 do 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 131 NewControl := TControlDimension.Create; 132 Dimensions.Controls.Add(NewControl); 133 StoreDimensions(TWinControl(Control).Controls[I], NewControl); 134 end; 135 end; 136 end; 137 138 procedure TScaleDPI.RestoreDimensions(Control: TControl; 139 Dimensions: TControlDimension); 140 var 141 I: Integer; 142 begin 143 Control.BoundsRect := Dimensions.BoundsRect; 144 Control.Font.Height := Dimensions.FontHeight; 145 if Control is TToolBar then begin 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; 154 end; 155 if Control is TWinControl then 156 for I := 0 to TWinControl(Control).ControlCount - 1 do 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 160 RestoreDimensions(TWinControl(Control).Controls[I], TControlDimension(Dimensions.Controls[I])); 161 end; 162 end; 163 end; 164 165 procedure TScaleDPI.ScaleDimensions(Control: TControl; 166 Dimensions: TControlDimension); 167 var 168 I: Integer; 169 begin 170 Control.BoundsRect := ScaleRect(Dimensions.BoundsRect, DesignDPI); 171 Control.Font.Height := ScaleY(Dimensions.FontHeight, DesignDPI.Y); 172 if Control is TToolBar then begin 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); 190 end; 191 if Control is TWinControl then 192 for I := 0 to TWinControl(Control).ControlCount - 1 do 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 196 ScaleDimensions(TWinControl(Control).Controls[I], TControlDimension(Dimensions.Controls[I])); 197 end; 198 end; 199 end; 200 52 201 procedure TScaleDPI.ApplyToAll(FromDPI: TPoint); 53 202 var … … 55 204 begin 56 205 for I := 0 to Screen.FormCount - 1 do begin 57 Scale DPI(Screen.Forms[I], FromDPI);206 ScaleControl(Screen.Forms[I], FromDPI); 58 207 end; 59 208 end; … … 70 219 71 220 SetLength(Temp, ImgList.Count); 72 TempBmp := TBitmap.Create;73 221 for I := 0 to ImgList.Count - 1 do 74 222 begin 223 TempBmp := TBitmap.Create; 224 TempBmp.PixelFormat := pf32bit; 75 225 ImgList.GetBitmap(I, TempBmp); 76 //TempBmp.PixelFormat := pfDevice;77 226 Temp[I] := TBitmap.Create; 78 227 Temp[I].SetSize(NewWidth, NewHeight); 228 Temp[I].PixelFormat := pf32bit; 79 229 Temp[I].TransparentColor := TempBmp.TransparentColor; 80 230 //Temp[I].TransparentMode := TempBmp.TransparentMode; … … 86 236 if (Temp[I].Width = 0) or (Temp[I].Height = 0) then Continue; 87 237 Temp[I].Canvas.StretchDraw(Rect(0, 0, Temp[I].Width, Temp[I].Height), TempBmp); 88 end;89 TempBmp.Free;238 TempBmp.Free; 239 end; 90 240 91 241 ImgList.Clear; … … 110 260 end; 111 261 112 function TScaleDPI.ScaleXY(Size: TPoint; FromDPI: Integer): TPoint; 113 begin 114 Result.X := ScaleX(Size.X, FromDPI); 115 Result.Y := ScaleY(Size.Y, FromDPI); 262 function TScaleDPI.ScalePoint(APoint: TPoint; FromDPI: TPoint): TPoint; 263 begin 264 Result.X := ScaleX(APoint.X, FromDPI.X); 265 Result.Y := ScaleY(APoint.Y, FromDPI.Y); 266 end; 267 268 function TScaleDPI.ScaleRect(ARect: TRect; FromDPI: TPoint): TRect; 269 begin 270 Result.TopLeft := ScalePoint(ARect.TopLeft, FromDPI); 271 Result.BottomRight := ScalePoint(ARect.BottomRight, FromDPI); 116 272 end; 117 273 … … 123 279 end; 124 280 125 procedure TScaleDPI.Scale DPI(Control: TControl; FromDPI: TPoint);281 procedure TScaleDPI.ScaleControl(Control: TControl; FromDPI: TPoint); 126 282 var 127 283 I: Integer; 128 284 WinControl: TWinControl; 129 285 ToolBarControl: TToolBar; 130 begin 286 OldAnchors: TAnchors; 287 OldAutoSize: Boolean; 288 begin 289 //if Control is TMemo then Exit; 290 //if Control is TForm then 291 // Control.DisableAutoSizing; 131 292 with Control do begin 293 //OldAutoSize := AutoSize; 294 //AutoSize := False; 295 //Anchors := []; 132 296 Left := ScaleX(Left, FromDPI.X); 133 297 Top := ScaleY(Top, FromDPI.Y); 298 //if not (akRight in Anchors) then 134 299 Width := ScaleX(Width, FromDPI.X); 300 //if not (akBottom in Anchors) then 135 301 Height := ScaleY(Height, FromDPI.Y); 136 302 {$IFDEF LCL Qt} … … 139 305 Font.Height := ScaleY(Font.GetTextHeight('Hg'), FromDPI.Y); 140 306 {$ENDIF} 307 //Anchors := OldAnchors; 308 //AutoSize := OldAutoSize; 141 309 end; 142 310 … … 149 317 end; 150 318 319 //if not (Control is TCustomPage) then 151 320 if Control is TWinControl then begin 152 321 WinControl := TWinControl(Control); … … 154 323 for I := 0 to WinControl.ControlCount - 1 do begin 155 324 if WinControl.Controls[I] is TControl then begin 156 Scale DPI(WinControl.Controls[I], FromDPI);325 ScaleControl(WinControl.Controls[I], FromDPI); 157 326 end; 158 327 end; 159 328 end; 160 329 end; 330 //if Control is TForm then 331 // Control.EnableAutoSizing; 161 332 end; 162 333 -
trunk/Packages/Common/UURI.pas
r72 r73 89 89 function LeftCutString(var Source: string; out Output: string; Delimiter: string; Allowed: string = ''): Boolean; 90 90 var 91 I : Integer;91 I, J: Integer; 92 92 Matched: Boolean; 93 93 begin … … 113 113 function RightCutString(var Source: string; out Output: string; Delimiter: string; Allowed: string = ''): Boolean; 114 114 var 115 I : Integer;115 I, J: Integer; 116 116 Matched: Boolean; 117 117 begin … … 202 202 203 203 procedure TURI.SetAsString(Value: string); 204 var 205 HostAddr: string; 206 HostPort: string; 204 207 begin 205 208 LeftCutString(Value, Scheme, ':'); -
trunk/Packages/Common/UXMLUtils.pas
r72 r73 7 7 uses 8 8 {$IFDEF WINDOWS}Windows,{$ENDIF} 9 Classes, SysUtils, DateUtils ;9 Classes, SysUtils, DateUtils, XMLRead, XMLWrite, DOM; 10 10 11 11 function XMLTimeToDateTime(XMLDateTime: string): TDateTime; 12 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string; 12 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString; 13 procedure WriteInteger(Node: TDOMNode; Name: string; Value: Integer); 14 procedure WriteInt64(Node: TDOMNode; Name: string; Value: Int64); 15 procedure WriteBoolean(Node: TDOMNode; Name: string; Value: Boolean); 16 procedure WriteString(Node: TDOMNode; Name: string; Value: string); 17 procedure WriteDateTime(Node: TDOMNode; Name: string; Value: TDateTime); 18 function ReadInteger(Node: TDOMNode; Name: string; DefaultValue: Integer): Integer; 19 function ReadInt64(Node: TDOMNode; Name: string; DefaultValue: Int64): Int64; 20 function ReadBoolean(Node: TDOMNode; Name: string; DefaultValue: Boolean): Boolean; 21 function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string; 22 function ReadDateTime(Node: TDOMNode; Name: string; DefaultValue: TDateTime): TDateTime; 13 23 14 24 … … 35 45 function LeftCutString(var Source: string; out Output: string; Delimiter: string; Allowed: string = ''): Boolean; 36 46 var 37 I : Integer;47 I, J: Integer; 38 48 Matched: Boolean; 39 49 begin … … 66 76 Minute: Integer; 67 77 Second: Integer; 78 SecondFraction: Double; 68 79 Millisecond: Integer; 69 80 begin … … 88 99 if Pos('Z', XMLDateTime) > 0 then 89 100 LeftCutString(XMLDateTime, Part, 'Z'); 90 Millisecond := StrToInt(Part); 101 SecondFraction := StrToFloat('0' + DecimalSeparator + Part); 102 Millisecond := Trunc(SecondFraction * 1000); 91 103 end else begin 92 104 if Pos('+', XMLDateTime) > 0 then … … 106 118 end; 107 119 108 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string;120 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString; 109 121 const 110 122 Neg: array[Boolean] of string = ('+', '-'); … … 123 135 end; 124 136 137 procedure WriteInteger(Node: TDOMNode; Name: string; Value: Integer); 138 var 139 NewNode: TDOMNode; 140 begin 141 NewNode := Node.OwnerDocument.CreateElement(Name); 142 NewNode.TextContent := IntToStr(Value); 143 Node.AppendChild(NewNode); 144 end; 145 146 procedure WriteInt64(Node: TDOMNode; Name: string; Value: Int64); 147 var 148 NewNode: TDOMNode; 149 begin 150 NewNode := Node.OwnerDocument.CreateElement(Name); 151 NewNode.TextContent := IntToStr(Value); 152 Node.AppendChild(NewNode); 153 end; 154 155 procedure WriteBoolean(Node: TDOMNode; Name: string; Value: Boolean); 156 var 157 NewNode: TDOMNode; 158 begin 159 NewNode := Node.OwnerDocument.CreateElement(Name); 160 NewNode.TextContent := BoolToStr(Value); 161 Node.AppendChild(NewNode); 162 end; 163 164 procedure WriteString(Node: TDOMNode; Name: string; Value: string); 165 var 166 NewNode: TDOMNode; 167 begin 168 NewNode := Node.OwnerDocument.CreateElement(Name); 169 NewNode.TextContent := Value; 170 Node.AppendChild(NewNode); 171 end; 172 173 procedure WriteDateTime(Node: TDOMNode; Name: string; Value: TDateTime); 174 var 175 NewNode: TDOMNode; 176 begin 177 NewNode := Node.OwnerDocument.CreateElement(Name); 178 NewNode.TextContent := DateTimeToXMLTime(Value); 179 Node.AppendChild(NewNode); 180 end; 181 182 function ReadInteger(Node: TDOMNode; Name: string; DefaultValue: Integer): Integer; 183 var 184 NewNode: TDOMNode; 185 begin 186 Result := DefaultValue; 187 NewNode := Node.FindNode(Name); 188 if Assigned(NewNode) then 189 Result := StrToInt(NewNode.TextContent); 190 end; 191 192 function ReadInt64(Node: TDOMNode; Name: string; DefaultValue: Int64): Int64; 193 var 194 NewNode: TDOMNode; 195 begin 196 Result := DefaultValue; 197 NewNode := Node.FindNode(Name); 198 if Assigned(NewNode) then 199 Result := StrToInt64(NewNode.TextContent); 200 end; 201 202 function ReadBoolean(Node: TDOMNode; Name: string; DefaultValue: Boolean): Boolean; 203 var 204 NewNode: TDOMNode; 205 begin 206 Result := DefaultValue; 207 NewNode := Node.FindNode(Name); 208 if Assigned(NewNode) then 209 Result := StrToBool(NewNode.TextContent); 210 end; 211 212 function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string; 213 var 214 NewNode: TDOMNode; 215 begin 216 Result := DefaultValue; 217 NewNode := Node.FindNode(Name); 218 if Assigned(NewNode) then 219 Result := NewNode.TextContent; 220 end; 221 222 function ReadDateTime(Node: TDOMNode; Name: string; DefaultValue: TDateTime 223 ): TDateTime; 224 var 225 NewNode: TDOMNode; 226 begin 227 Result := DefaultValue; 228 NewNode := Node.FindNode(Name); 229 if Assigned(NewNode) then 230 Result := XMLTimeToDateTime(NewNode.TextContent); 231 end; 232 125 233 end. 126 234 -
trunk/Packages/CoolTranslator/CoolTranslator.pas
r72 r73 5 5 unit CoolTranslator; 6 6 7 {$warn 5023 off : no warning about unused units}8 7 interface 9 8 -
trunk/Packages/TemplateGenerics/TemplateGenerics.pas
r72 r73 5 5 unit TemplateGenerics; 6 6 7 {$warn 5023 off : no warning about unused units}8 7 interface 9 8
Note:
See TracChangeset
for help on using the changeset viewer.