📄 syneditmiscclasses.pas
字号:
{-------------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: SynEditMiscClasses.pas, released 2000-04-07.
The Original Code is based on the mwSupportClasses.pas file from the
mwEdit component suite by Martin Waldenburg and other developers, the Initial
Author of this file is Michael Hieke.
All Rights Reserved.
Contributors to the SynEdit and mwEdit projects are listed in the
Contributors.txt file.
Alternatively, the contents of this file may be used under the terms of the
GNU General Public License Version 2 or later (the "GPL"), in which case
the provisions of the GPL are applicable instead of those above.
If you wish to allow use of your version of this file only under the terms
of the GPL and not to allow others to use your version of this file
under the MPL, indicate your decision by deleting the provisions above and
replace them with the notice and other provisions required by the GPL.
If you do not delete the provisions above, a recipient may use your version
of this file under either the MPL or the GPL.
$Id: SynEditMiscClasses.pas,v 1.23 2003/08/31 11:22:54 etrusco Exp $
You may retrieve the latest version of this file at the SynEdit home page,
located at http://SynEdit.SourceForge.net
Known Issues:
-------------------------------------------------------------------------------}
{$IFNDEF QSYNEDITMISCCLASSES}
unit SynEditMiscClasses;
{$ENDIF}
{$I SynEdit.inc}
interface
uses
{$IFDEF SYN_CLX}
Types,
Qt,
QGraphics,
QControls,
QImgList,
QStdCtrls,
QMenus,
kTextDrawer,
//<<<<<<< SynEditMiscClasses.pas
{$IFDEF SYN_WIN32}
// Registry,
{$ENDIF}
//=======
QSynEditTypes,
QSynEditKeyConst,
//>>>>>>> 1.21
{$ELSE}
Windows,
Messages,
Graphics,
Controls,
StdCtrls,
Menus,
Registry,
SynEditTypes,
SynEditKeyConst,
{$ENDIF}
{$IFDEF SYN_COMPILER_4_UP}
Math,
{$ENDIF}
Classes,
SysUtils;
type
TSynSelectedColor = class(TPersistent)
private
fBG: TColor;
fFG: TColor;
fOnChange: TNotifyEvent;
procedure SetBG(Value: TColor);
procedure SetFG(Value: TColor);
public
constructor Create;
procedure Assign(Source: TPersistent); override; //jcr 2000-12-08
published
property Background: TColor read fBG write SetBG default clHighLight;
property Foreground: TColor read fFG write SetFG default clHighLightText;
property OnChange: TNotifyEvent read fOnChange write fOnChange;
end;
TSynGutterBorderStyle = (gbsNone, gbsMiddle, gbsRight);
TSynGutter = class(TPersistent)
private
fFont: TFont; //DDH 10/16/01
fColor: TColor;
fWidth: integer;
fShowLineNumbers: boolean;
fDigitCount: integer;
fLeadingZeros: boolean;
fZeroStart: boolean;
fLeftOffset: integer;
fRightOffset: integer;
fOnChange: TNotifyEvent;
fCursor: TCursor;
fVisible: boolean;
fUseFontStyle: boolean;
fAutoSize: boolean;
fAutoSizeDigitCount: integer;
fBorderStyle: TSynGutterBorderStyle;
procedure SetAutoSize(const Value: boolean);
procedure SetColor(const Value: TColor);
procedure SetDigitCount(Value: integer);
procedure SetLeadingZeros(const Value: boolean);
procedure SetLeftOffset(Value: integer);
procedure SetRightOffset(Value: integer);
procedure SetShowLineNumbers(const Value: boolean);
procedure SetUseFontStyle(Value: boolean);
procedure SetVisible(Value: boolean);
procedure SetWidth(Value: integer);
procedure SetZeroStart(const Value: boolean);
procedure SetFont(Value: TFont); //DDH 10/16/01
procedure OnFontChange(Sender: TObject);
procedure SetBorderStyle(const Value: TSynGutterBorderStyle); //DDH 10/16/01
public
constructor Create;
destructor Destroy; override; //DDH 10/16/01
procedure Assign(Source: TPersistent); override;
procedure AutoSizeDigitCount(LinesCount: integer);
function FormatLineNumber(Line: integer): string;
function RealGutterWidth(CharWidth: integer): integer;
published
property AutoSize: boolean read fAutoSize write SetAutoSize default FALSE;
property BorderStyle: TSynGutterBorderStyle read fBorderStyle
write SetBorderStyle default gbsMiddle;
property Color: TColor read fColor write SetColor default clBtnFace;
property Cursor: TCursor read fCursor write fCursor default crDefault;
property DigitCount: integer read fDigitCount write SetDigitCount
default 4;
property Font: TFont read fFont write SetFont; //DDH 10/16/01
property LeadingZeros: boolean read fLeadingZeros write SetLeadingZeros
default FALSE;
property LeftOffset: integer read fLeftOffset write SetLeftOffset
default 16;
property RightOffset: integer read fRightOffset write SetRightOffset
default 2;
property ShowLineNumbers: boolean read fShowLineNumbers
write SetShowLineNumbers default FALSE;
property UseFontStyle: boolean read fUseFontStyle write SetUseFontStyle
default TRUE; //DDH 10/16/01
property Visible: boolean read fVisible write SetVisible default TRUE;
property Width: integer read fWidth write SetWidth default 30;
property ZeroStart: boolean read fZeroStart write SetZeroStart
default FALSE;
property OnChange: TNotifyEvent read fOnChange write fOnChange;
end;
TSynBookMarkOpt = class(TPersistent)
private
fBookmarkImages: TImageList;
fDrawBookmarksFirst: boolean;
fEnableKeys: Boolean;
fGlyphsVisible: Boolean;
fLeftMargin: Integer;
fOwner: TComponent;
fXoffset: integer;
fOnChange: TNotifyEvent;
procedure SetBookmarkImages(const Value: TImageList);
procedure SetDrawBookmarksFirst(Value: boolean);
procedure SetGlyphsVisible(Value: Boolean);
procedure SetLeftMargin(Value: Integer);
procedure SetXOffset(Value: integer);
public
constructor Create(AOwner: TComponent);
procedure Assign(Source: TPersistent); override; //jcr 2000-12-08
published
property BookmarkImages: TImageList
read fBookmarkImages write SetBookmarkImages;
property DrawBookmarksFirst: boolean read fDrawBookmarksFirst
write SetDrawBookmarksFirst default True;
property EnableKeys: Boolean
read fEnableKeys write fEnableKeys default True;
property GlyphsVisible: Boolean
read fGlyphsVisible write SetGlyphsVisible default True;
property LeftMargin: Integer read fLeftMargin write SetLeftMargin default 2;
property Xoffset: integer read fXoffset write SetXOffset default 12;
property OnChange: TNotifyEvent read fOnChange write fOnChange;
end;
{ TSynMethodChain }
ESynMethodChain = class(Exception);
TSynExceptionEvent = procedure (Sender: TObject; E: Exception;
var DoContinue: Boolean) of object;
TSynMethodChain = class
private
FNotifyProcs: TList;
FExceptionHandler: TSynExceptionEvent;
protected
procedure DoFire(AEvent: TMethod); virtual; abstract;
function DoHandleException(E: Exception): Boolean; virtual;
property ExceptionHandler: TSynExceptionEvent read FExceptionHandler
write FExceptionHandler;
public
constructor Create; virtual;
destructor Destroy; override;
procedure Add(AEvent: TMethod);
procedure Remove(AEvent: TMethod);
procedure Fire;
end;
{ TSynNotifyEventChain }
TSynNotifyEventChain = class(TSynMethodChain)
private
FSender: TObject;
protected
procedure DoFire(AEvent: TMethod); override;
public
constructor CreateEx(ASender: TObject);
procedure Add(AEvent: TNotifyEvent);
procedure Remove(AEvent: TNotifyEvent);
property ExceptionHandler;
property Sender: TObject read FSender write FSender;
end;
{ TSynInternalImage }
TSynInternalImage = class(TObject)
private
fImages : TBitmap;
fWidth : Integer;
fHeight : Integer;
fCount : Integer;
function CreateBitmapFromInternalList(aModule: THandle; const Name: string): TBitmap;
procedure FreeBitmapFromInternalList;
public
constructor Create(aModule: THandle; const Name: string; Count: integer);
destructor Destroy; override;
procedure DrawMark(ACanvas: TCanvas; Number, X, Y, LineHeight: integer);
procedure DrawMarkTransparent(ACanvas: TCanvas; Number, X, Y,
LineHeight: integer; TransparentColor: TColor);
end;
TSynHotKey=class(TEdit)
private
function GetHotKey: TShortcut;
procedure SetHotKey(const Value: TShortcut);
protected
{$IFDEF SYN_CLX}
{$ELSE}
procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
{$ENDIF}
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
procedure DoExit; override;
published
property HotKey: TShortcut read GetHotKey write SetHotKey;
end;
TSynEditSearchCustom = class(TComponent)
protected
function GetPattern: string; virtual; abstract;
procedure SetPattern(const Value: string); virtual; abstract;
function GetLength(aIndex: integer): integer; virtual; abstract;
function GetResult(aIndex: integer): integer; virtual; abstract;
function GetResultCount: integer; virtual; abstract;
procedure SetOptions(const Value: TSynSearchOptions); virtual; abstract;
public
function FindAll(const NewText: string): integer; virtual; abstract;
function Replace(const aOccurrence, aReplacement: string): string; virtual; abstract;
property Pattern: string read GetPattern write SetPattern;
property ResultCount: integer read GetResultCount;
property Results[aIndex: integer]: integer read GetResult;
property Lengths[aIndex: integer]: integer read GetLength;
property Options: TSynSearchOptions write SetOptions;
end;
{$IFNDEF SYN_CLX}
{$IFNDEF SYN_COMPILER_4_UP}
TBetterRegistry = class(TRegistry)
function OpenKeyReadOnly(const Key: string): Boolean;
end;
{$ELSE}
TBetterRegistry = TRegistry;
{$ENDIF}
{$ENDIF}
implementation
uses
{$IFDEF SYN_CLX}
QSynEditMiscProcs;
{$ELSE}
SynEditMiscProcs;
{$ENDIF}
{ TSynSelectedColor }
constructor TSynSelectedColor.Create;
begin
inherited Create;
fBG := clHighLight;
fFG := clHighLightText;
end;
procedure TSynSelectedColor.Assign(Source: TPersistent); //jcr 2000-12-08
var
Src: TSynSelectedColor;
begin
if (Source <> nil) and (Source is TSynSelectedColor) then begin
Src := TSynSelectedColor(Source);
fBG := Src.fBG;
fFG := Src.fFG;
if Assigned(fOnChange) then fOnChange(Self);
end else
inherited Assign(Source);
end;
procedure TSynSelectedColor.SetBG(Value: TColor);
begin
if (fBG <> Value) then begin
fBG := Value;
if Assigned(fOnChange) then fOnChange(Self);
end;
end;
procedure TSynSelectedColor.SetFG(Value: TColor);
begin
if (fFG <> Value) then begin
fFG := Value;
if Assigned(fOnChange) then fOnChange(Self);
end;
end;
{ TSynGutter }
constructor TSynGutter.Create;
begin
inherited Create;
fFont := TFont.Create;
fFont.Name := 'Courier New';
fFont.Size := 8;
fFont.Style := [];
fUseFontStyle := True;
fFont.OnChange := OnFontChange;
fColor := clBtnFace;
fVisible := TRUE;
fWidth := 30;
fLeftOffset := 16;
fDigitCount := 4;
fAutoSizeDigitCount := fDigitCount;
fRightOffset := 2;
fBorderStyle := gbsMiddle;
end;
destructor TSynGutter.Destroy;
begin
fFont.Free;
inherited Destroy;
end;
procedure TSynGutter.Assign(Source: TPersistent);
var
Src: TSynGutter;
begin
if Assigned(Source) and (Source is TSynGutter) then begin
Src := TSynGutter(Source);
fFont.Assign(src.Font); //DDH 10/16/01
fUseFontStyle := src.fUseFontStyle; //DDH 10/16/01
fColor := Src.fColor;
fVisible := Src.fVisible;
fWidth := Src.fWidth;
fShowLineNumbers := Src.fShowLineNumbers;
fLeadingZeros := Src.fLeadingZeros;
fZeroStart := Src.fZeroStart;
fLeftOffset := Src.fLeftOffset;
fDigitCount := Src.fDigitCount;
fRightOffset := Src.fRightOffset;
fAutoSize := Src.fAutoSize;
fAutoSizeDigitCount := Src.fAutoSizeDigitCount;
if Assigned(fOnChange) then fOnChange(Self);
end else
inherited;
end;
procedure TSynGutter.AutoSizeDigitCount(LinesCount: integer);
var
nDigits: integer;
begin
if fVisible and fAutoSize and fShowLineNumbers then begin
if fZeroStart then Dec(LinesCount);
nDigits := Max(Length(IntToStr(LinesCount)), fDigitCount);
if fAutoSizeDigitCount <> nDigits then begin
fAutoSizeDigitCount := nDigits;
if Assigned(fOnChange) then fOnChange(Self);
end;
end else
fAutoSizeDigitCount := fDigitCount;
end;
function TSynGutter.FormatLineNumber(Line: integer): string;
var
i: integer;
begin
if fZeroStart then Dec(Line);
Str(Line : fAutoSizeDigitCount, Result);
if fLeadingZeros then
for i := 1 to fAutoSizeDigitCount - 1 do begin
if (Result[i] <> ' ') then break;
Result[i] := '0';
end;
end;
function TSynGutter.RealGutterWidth(CharWidth: integer): integer;
begin
if not fVisible then
Result := 0
else if fShowLineNumbers then
Result := fLeftOffset + fRightOffset + fAutoSizeDigitCount * CharWidth + 2
else
Result := fWidth;
end;
procedure TSynGutter.SetAutoSize(const Value: boolean);
begin
if fAutoSize <> Value then begin
fAutoSize := Value;
if Assigned(fOnChange) then fOnChange(Self);
end;
end;
procedure TSynGutter.SetColor(const Value: TColor);
begin
if fColor <> Value then begin
fColor := Value;
if Assigned(fOnChange) then fOnChange(Self);
end;
end;
//DDH 10/16/01 Start
procedure TSynGutter.SetFont(Value: TFont);
begin
fFont.Assign(Value);
end;
procedure TSynGutter.OnFontChange(Sender: TObject);
begin
if Assigned(fOnChange) then fOnChange(Self);
end;
//DDH 10/16/01 End
procedure TSynGutter.SetDigitCount(Value: integer);
begin
Value := MinMax(Value, 2, 12);
if fDigitCount <> Value then begin
fDigitCount := Value;
fAutoSizeDigitCount := fDigitCount;
if Assigned(fOnChange) then fOnChange(Self);
end;
end;
procedure TSynGutter.SetLeadingZeros(const Value: boolean);
begin
if fLeadingZeros <> Value then begin
fLeadingZeros := Value;
if Assigned(fOnChange) then fOnChange(Self);
end;
end;
procedure TSynGutter.SetLeftOffset(Value: integer);
begin
Value := Max(0, Value);
if fLeftOffset <> Value then begin
fLeftOffset := Value;
if Assigned(fOnChange) then fOnChange(Self);
end;
end;
procedure TSynGutter.SetRightOffset(Value: integer);
begin
Value := Max(0, Value);
if fRightOffset <> Value then begin
fRightOffset := Value;
if Assigned(fOnChange) then fOnChange(Self);
end;
end;
procedure TSynGutter.SetShowLineNumbers(const Value: boolean);
begin
if fShowLineNumbers <> Value then begin
fShowLineNumbers := Value;
if Assigned(fOnChange) then fOnChange(Self);
end;
end;
procedure TSynGutter.SetUseFontStyle(Value: boolean);
begin
if fUseFontStyle <> Value then begin
fUseFontStyle := Value;
if Assigned(fOnChange) then fOnChange(Self);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -