From 02774924f6a54e4e21704d21b934a15f51d9e3a7 Mon Sep 17 00:00:00 2001 From: mattias Date: Sat, 29 Dec 2007 19:17:18 +0000 Subject: [PATCH] LCL: added TPicture.FindGraphicClassWithFileExt git-svn-id: trunk@13526 - --- components/synedit/synedit.pp | 8 +++++++- lcl/graphics.pp | 3 +++ lcl/include/picture.inc | 17 ++++++++++++++--- lcl/lazhelpintf.pas | 4 ++-- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/components/synedit/synedit.pp b/components/synedit/synedit.pp index 062c2e5c3d..413ab4f3b5 100644 --- a/components/synedit/synedit.pp +++ b/components/synedit/synedit.pp @@ -8773,19 +8773,21 @@ var {$ENDIF} begin {$IFDEF SYN_LAZARUS} - LogCaret:=PhysicalToLogicalPos(CaretXY); + LogCaret:=LogicalCaretXY; CX := LogCaret.X; CY := LogCaret.Y; {$ELSE} CX := CaretX; CY := CaretY; {$ENDIF} + //DebugLn(['TCustomSynEdit.PrevWordPos ',dbgs(LogCaret)]); // valid line? if (CY >= 1) and (CY <= Lines.Count) then begin Line := Lines[CY - 1]; CX := Min(CX, Length(Line) + 1); CurIdentChars:=IdentChars; WhiteChars := [#1..#255] - CurIdentChars; + //DebugLn(['TCustomSynEdit.PrevWordPos Line="',dbgstr(Line),'" CX=',CX]); if CX <= 1 then begin // find last IdentChar in the previous line if CY > 1 then begin @@ -8797,6 +8799,7 @@ begin // if previous char is a "whitespace" search for the last IdentChar if Line[CX - 1] in WhiteChars then CX := StrRScanForCharInSet(Line, CX - 1, CurIdentChars); + //DebugLn(['TCustomSynEdit.PrevWordPos AAA1 CX=',CX]); if CX > 0 then // search for the first IdentChar of this "word" CX := StrRScanForCharInSet(Line, CX - 1, WhiteChars) + 1 @@ -8807,13 +8810,16 @@ begin Line := Lines[CY - 1]; CX := Length(Line) + 1; end; + //DebugLn(['TCustomSynEdit.PrevWordPos AAA2 CX=',CX]); end; end; + //DebugLn(['TCustomSynEdit.PrevWordPos AAA3 ',CX,',',CY]); {$IFDEF SYN_LAZARUS} Result := LogicalToPhysicalPos(Point(CX, CY)); {$ELSE} Result := Point(CX, CY); {$ENDIF} + //DebugLn(['TCustomSynEdit.PrevWordPos END ',dbgs(Result)]); end; procedure TCustomSynEdit.SetSelectionMode(const Value: TSynSelectionMode); diff --git a/lcl/graphics.pp b/lcl/graphics.pp index a71d9ce108..59ae5c702a 100644 --- a/lcl/graphics.pp +++ b/lcl/graphics.pp @@ -817,6 +817,7 @@ type destructor Destroy; override; procedure LoadFromFile(const Filename: string); procedure SaveToFile(const Filename: string); + procedure LoadFromStream(const Filename: string); procedure LoadFromClipboardFormat(FormatID: TClipboardFormat); procedure LoadFromClipboardFormatID(ClipboardType: TClipboardType; FormatID: TClipboardFormat); @@ -829,6 +830,8 @@ type AGraphicClass: TGraphicClass); class procedure UnregisterGraphicClass(AClass: TGraphicClass); procedure Clear; virtual; + function FindGraphicClassWithFileExt(const Ext: string; + ExceptionOnNotFound: boolean = true): TGraphicClass; public property Bitmap: TBitmap read GetBitmap write SetBitmap; property Icon: TIcon read GetIcon write SetIcon; diff --git a/lcl/include/picture.inc b/lcl/include/picture.inc index 9597dc6309..eafcf3378f 100644 --- a/lcl/include/picture.inc +++ b/lcl/include/picture.inc @@ -488,9 +488,7 @@ var begin Ext := ExtractFileExt(Filename); System.Delete(Ext, 1, 1); // delete '.' - GraphicClass := GetPicFileFormats.FindExt(Ext); - if GraphicClass = nil then - raise EInvalidGraphic.CreateFmt(rsUnknownPictureExtension, [Ext]); + GraphicClass := FindGraphicClassWithFileExt(Ext); NewGraphic := GraphicClass.Create; ok:=false; @@ -594,6 +592,19 @@ begin SetGraphic(nil); end; +function TPicture.FindGraphicClassWithFileExt(const Ext: string; + ExceptionOnNotFound: boolean): TGraphicClass; +var + FileExt: String; +begin + FileExt:=Ext; + if (FileExt<>'') and (FileExt[1]='.') then + FileExt:=copy(FileExt,2,length(FileExt)); + Result := GetPicFileFormats.FindExt(FileExt); + if (Result = nil) and ExceptionOnNotFound then + raise EInvalidGraphic.CreateFmt(rsUnknownPictureExtension, [Ext]); +end; + procedure TPicture.Changed(Sender: TObject); begin if Assigned(FOnChange) then FOnChange(Self); diff --git a/lcl/lazhelpintf.pas b/lcl/lazhelpintf.pas index c2f38bff5f..d45e9ea99e 100644 --- a/lcl/lazhelpintf.pas +++ b/lcl/lazhelpintf.pas @@ -548,7 +548,7 @@ procedure FreeUnusedLCLHelpSystem; function FilenameToURL(const Filename: string): string; function FilenameToURLPath(const Filename: string): string; function URLPathToFilename(const URLPath: string): string; -procedure SplitURL(const URL: string; var URLType, URLPath, URLParams: string); +procedure SplitURL(const URL: string; out URLType, URLPath, URLParams: string); function CombineURL(const URLType, URLPath, URLParams: string): string; function URLFilenameIsAbsolute(const URLPath: string): boolean; function FindURLPathStart(const URL: string): integer; @@ -626,7 +626,7 @@ begin {$warnings on} end; -procedure SplitURL(const URL: string; var URLType, URLPath, URLParams: string); +procedure SplitURL(const URL: string; out URLType, URLPath, URLParams: string); var Len: Integer; ColonPos: Integer;