SynEdit / IDE: zoom with ctrl wheel

git-svn-id: trunk@33986 -
This commit is contained in:
martin 2011-12-05 23:32:21 +00:00
parent b940e9e6a6
commit 3403a53c21
5 changed files with 191 additions and 50 deletions

View File

@ -390,6 +390,7 @@ type
fCharsInWindow: Integer;
fCharWidth: Integer;
fFontDummy: TFont;
FLastSetFontSize: Integer;
{$IFDEF SYN_MBCSSUPPORT}
fImeCount: Integer;
fMBCSStepAside: Boolean;
@ -1364,6 +1365,11 @@ procedure TSynEditMouseGlobalActions.InitForOptions(AnOptions: TSynEditorMouseOp
begin
AddCommand(emcWheelScrollDown, False, mbWheelDown, ccAny, cdDown, [], []);
AddCommand(emcWheelScrollUp, False, mbWheelUp, ccAny, cdDown, [], []);
if emCtrlWheelZoom in AnOptions then begin
AddCommand(emcWheelZoomOut, False, mbWheelDown, ccAny, cdDown, [ssCtrl], [ssCtrl]);
AddCommand(emcWheelZoomIn, False, mbWheelUp, ccAny, cdDown, [ssCtrl], [ssCtrl]);
end;
end;
{ TSynEditMouseTextActions }
@ -1821,6 +1827,7 @@ begin
fFontDummy.Height := SynDefaultFontHeight;
fFontDummy.Pitch := SynDefaultFontPitch;
fFontDummy.Quality := SynDefaultFontQuality;
FLastSetFontSize := fFontDummy.Size;
fLastMouseCaret := Point(-1,-1);
FLastMousePoint := Point(-1,-1);
fBlockIndent := 2;
@ -2142,6 +2149,7 @@ end;
procedure TCustomSynEdit.FontChanged(Sender: TObject);
begin
FLastSetFontSize := Font.Size;
RecalcCharExtent;
SizeOrFontChanged(TRUE);
end;
@ -2595,6 +2603,7 @@ function TCustomSynEdit.DoHandleMouseAction(AnActionList: TSynEditMouseActions;
AnInfo: TSynEditMouseActionInfo): Boolean;
var
CaretDone: Boolean;
AnAction: TSynEditMouseAction;
procedure MoveCaret;
begin
@ -2602,14 +2611,49 @@ var
CaretDone := True;
end;
function GetWheelScrollAmount(APageSize: integer): integer;
const
WHEEL_PAGESCROLL = MAXDWORD;
begin
case AnAction.Option of
emcWheelScrollSystem:
begin
Result := Mouse.WheelScrollLines;
if (Result = WHEEL_PAGESCROLL) or (Result > APageSize) then
Result := APageSize;
end;
emcWheelScrollLines:
begin
Result := 1;
if AnAction.Option2 > 0 then
Result := AnAction.Option2;
if (Result > APageSize) then
Result := APageSize;
exit;
end;
emcWheelScrollPages:
Result := APageSize;
emcWheelScrollPagesLessOne:
Result := APageSize - 1;
else
begin
Result := Mouse.WheelScrollLines;
if (Result = WHEEL_PAGESCROLL) or (Result > APageSize) then
Result := APageSize;
exit;
end;
end;
if AnAction.Option2 > 0 then
Result := MulDiv(Result, AnAction.Option2, 100);
if (Result > APageSize) then
Result := APageSize;
end;
var
ACommand: TSynEditorMouseCommand;
Handled: Boolean;
AnAction: TSynEditMouseAction;
ClipHelper: TSynClipboardStream;
i: integer;
const
WHEEL_PAGESCROLL = MAXDWORD;
i, j: integer;
begin
AnAction := nil;
Result := False;
@ -2655,6 +2699,22 @@ begin
CaretDone := AnInfo.CaretDone;
MouseCapture := False;
if (ACommand = emcWheelScrollDown)
then begin
// sroll dependant on visible scrollbar / or not at all
if (sfVertScrollbarVisible in fStateFlags) then ACommand := emcWheelVertScrollDown
else
if (sfHorizScrollbarVisible in fStateFlags) then ACommand := emcWheelHorizScrollDown;
end;
if (ACommand = emcWheelScrollUp)
then begin
// sroll dependant on visible scrollbar / or not at all
if (sfVertScrollbarVisible in fStateFlags) then ACommand := emcWheelVertScrollUp
else
if (sfHorizScrollbarVisible in fStateFlags) then ACommand := emcWheelHorizScrollUp;
end;
case ACommand of
emcNone: ; // do nothing, but result := true
emcStartSelections, emcStartColumnSelections, emcStartLineSelections:
@ -2756,20 +2816,39 @@ begin
MoveCaret;
CommandProcessor(AnAction.Option, #0, nil);
end;
emcWheelScrollDown:
emcWheelHorizScrollDown, emcWheelHorizScrollUp:
begin
i := Mouse.WheelScrollLines;
if (i = WHEEL_PAGESCROLL) or (i > fLinesInWindow) then
i := fLinesInWindow;
TopView := TopView - i;
i := GetWheelScrollAmount(fCharsInWindow);
if ACommand = emcWheelHorizScrollUp then i := -i;
LeftChar := LeftChar + i;
end;
emcWheelScrollUp:
emcWheelVertScrollDown, emcWheelVertScrollUp:
begin
i := Mouse.WheelScrollLines;
if (i = WHEEL_PAGESCROLL) or (i > fLinesInWindow) then
i := fLinesInWindow;
i := GetWheelScrollAmount(fLinesInWindow);
if ACommand = emcWheelVertScrollUp then i := -i;
TopView := TopView + i;
end;
emcWheelZoomOut, emcWheelZoomIn:
begin
if ( (ACommand = emcWheelZoomOut) and (abs(Font.Size) < 3) ) or
( (ACommand = emcWheelZoomIn) and (abs(Font.Size) > 50) )
then begin
Result := False;
end
else begin
j := 1;
if ACommand = emcWheelZoomIn then j := -1;
i := FLastSetFontSize;
if Font.Size < 0
then Font.Size := Font.Size + j
else Font.Size := Font.Size - j;
FLastSetFontSize := i;
end;
end;
emcWheelZoomNorm:
begin
Font.Size := FLastSetFontSize;
end;
else
Result := False; // ACommand was not handled => Fallback to parent Context
end;
@ -7202,12 +7281,12 @@ begin
try
while FMouseWheelAccumulator > WHEEL_DELTA do begin
dec(FMouseWheelAccumulator, WHEEL_DELTA);
FindAndHandleMouseAction(mbWheelDown, lState, Message.X, Message.Y, ccSingle, cdDown);
FindAndHandleMouseAction(mbWheelUp, lState, Message.X, Message.Y, ccSingle, cdDown);
end;
while FMouseWheelAccumulator < WHEEL_DELTA do begin
inc(FMouseWheelAccumulator, WHEEL_DELTA);
FindAndHandleMouseAction(mbWheelUp, lState, Message.X, Message.Y, ccSingle, cdDown);
FindAndHandleMouseAction(mbWheelDown, lState, Message.X, Message.Y, ccSingle, cdDown);
end;
finally
DecPaintLock;

View File

@ -46,7 +46,8 @@ type
emDragDropEditing, // Allows you to select a block of text and drag it within the document to another location
emRightMouseMovesCursor, // When clicking with the right mouse for a popup menu, move the cursor to that location
emDoubleClickSelectsLine, // Select line on double click
emShowCtrlMouseLinks // Pressing Ctrl (SYNEDIT_LINK_MODIFIER) will highlight the word under the mouse cursor
emShowCtrlMouseLinks, // Pressing Ctrl (SYNEDIT_LINK_MODIFIER) will highlight the word under the mouse cursor
emCtrlWheelZoom
);
TSynEditorMouseOptions = set of TSynEditorMouseOption;
@ -85,6 +86,7 @@ type
private
FClickDir: TSynMAClickDir;
FOption: TSynEditorMouseCommandOpt;
FOption2: Integer;
FPriority: TSynEditorMouseCommandOpt;
FShift, FShiftMask: TShiftState;
FButton: TSynMouseButton;
@ -97,6 +99,7 @@ type
procedure SetCommand(const AValue: TSynEditorMouseCommand);
procedure SetMoveCaret(const AValue: Boolean);
procedure SetOption(const AValue: TSynEditorMouseCommandOpt);
procedure SetOption2(AValue: Integer);
procedure SetPriority(const AValue: TSynEditorMouseCommandOpt);
procedure SetShift(const AValue: TShiftState);
procedure SetShiftMask(const AValue: TShiftState);
@ -120,6 +123,7 @@ type
property Command: TSynEditorMouseCommand read FCommand write SetCommand;
property MoveCaret: Boolean read FMoveCaret write SetMoveCaret default False;
property Option: TSynEditorMouseCommandOpt read FOption write SetOption default 0;
property Option2: Integer read FOption2 write SetOption2 default 0;
property Priority: TSynEditorMouseCommandOpt read FPriority write SetPriority default 0;
end;
@ -152,7 +156,8 @@ type
const AButton: TSynMouseButton; const AClickCount: TSynMAClickCount;
const ADir: TSynMAClickDir; const AShift, AShiftMask: TShiftState;
const AOpt: TSynEditorMouseCommandOpt = 0;
const APrior: Integer = 0);
const APrior: Integer = 0;
const AOpt2: integer = 0);
public
property Items[Index: Integer]: TSynEditMouseAction read GetItem
write SetItem; default;
@ -236,30 +241,44 @@ const
emcWheelScrollDown = TSynEditorMouseCommand(18);
emcWheelScrollUp = TSynEditorMouseCommand(19);
emcMax = 19;
emcWheelVertScrollDown = TSynEditorMouseCommand(20);
emcWheelVertScrollUp = TSynEditorMouseCommand(21);
emcWheelHorizScrollDown = TSynEditorMouseCommand(22);
emcWheelHorizScrollUp = TSynEditorMouseCommand(23);
emcWheelZoomOut = TSynEditorMouseCommand(24);
emcWheelZoomIn = TSynEditorMouseCommand(25);
emcWheelZoomNorm = TSynEditorMouseCommand(26);
emcMax = 26;
emcPluginFirst = 20000;
// Options
emcoSelectionStart = 0;
emcoSelectionContinue = 1;
emcoSelectionStart = TSynEditorMouseCommandOpt(0);
emcoSelectionContinue = TSynEditorMouseCommandOpt(1);
emcoSelectLineSmart = 0;
emcoSelectLineFull = 1;
emcoMouseLinkShow = 0;
emcoMouseLinkHide = 1;
emcoSelectLineSmart = TSynEditorMouseCommandOpt(0);
emcoSelectLineFull = TSynEditorMouseCommandOpt(1);
emcoMouseLinkShow = TSynEditorMouseCommandOpt(0);
emcoMouseLinkHide = TSynEditorMouseCommandOpt(1);
emcoCodeFoldCollapsOne = 0;
emcoCodeFoldCollapsAll = 1;
emcoCodeFoldCollapsAtCaret = 2;
emcoCodeFoldCollapsPreCaret = 3;
emcoCodeFoldExpandOne = 0;
emcoCodeFoldExpandAll = 1;
emcoCodeFoldCollapsOne = TSynEditorMouseCommandOpt(0);
emcoCodeFoldCollapsAll = TSynEditorMouseCommandOpt(1);
emcoCodeFoldCollapsAtCaret = TSynEditorMouseCommandOpt(2);
emcoCodeFoldCollapsPreCaret = TSynEditorMouseCommandOpt(3);
emcoCodeFoldExpandOne = TSynEditorMouseCommandOpt(0);
emcoCodeFoldExpandAll = TSynEditorMouseCommandOpt(1);
// menu, and caret move
emcoSelectionCaretMoveNever = 0;
emcoSelectionCaretMoveOutside = 1; // click is outside selected area
emcoSelectionCaretMoveAlways = 2;
emcoSelectionCaretMoveNever = TSynEditorMouseCommandOpt(0);
emcoSelectionCaretMoveOutside = TSynEditorMouseCommandOpt(1); // click is outside selected area
emcoSelectionCaretMoveAlways = TSynEditorMouseCommandOpt(2);
emcWheelScrollSystem = TSynEditorMouseCommandOpt(0); // Opt2 > 0 ==> percentage
emcWheelScrollLines = TSynEditorMouseCommandOpt(1); // Opt2 > 0 ==> amount of lines
emcWheelScrollPages = TSynEditorMouseCommandOpt(2); // Opt2 > 0 ==> percentage
emcWheelScrollPagesLessOne = TSynEditorMouseCommandOpt(3); // Opt2 > 0 ==> percentage
// Plugins don't know of other plugins, so they need to map the codes
// Plugins all start at ecPluginFirst (overlapping)
@ -280,7 +299,7 @@ const
implementation
const
SynMouseCommandNames: array [0..17] of TIdentMapEntry = (
SynMouseCommandNames: array [0..24] of TIdentMapEntry = (
(Value: emcNone; Name: 'emcNone'),
(Value: emcStartSelections; Name: 'emcStartSelections'),
(Value: emcStartColumnSelections; Name: 'emcStartColumnSelections'),
@ -290,22 +309,30 @@ const
(Value: emcSelectLine; Name: 'emcSelectLine'),
(Value: emcSelectPara; Name: 'emcSelectPara'),
(Value: emcStartDragMove; Name: 'emcStartDragMove'),
(Value: emcStartDragMove; Name: 'emcStartDragMove'),
(Value: emcPasteSelection; Name: 'emcPasteSelection'),
(Value: emcMouseLink; Name: 'emcMouseLink'),
(Value: emcMouseLink; Name: 'emcMouseLink'),
(Value: emcContextMenu; Name: 'emcContextMenu'),
(Value: emcContextMenu; Name: 'emcContextMenu'),
(Value: emcOnMainGutterClick; Name: 'emcOnMainGutterClick'),
(Value: emcOnMainGutterClick; Name: 'emcOnMainGutterClick'),
(Value: emcCodeFoldCollaps; Name: 'emcCodeFoldCollaps'),
(Value: emcCodeFoldExpand; Name: 'emcCodeFoldExpand'),
(Value: emcCodeFoldCollaps; Name: 'emcCodeFoldCollaps'),
(Value: emcCodeFoldExpand; Name: 'emcCodeFoldExpand'),
(Value: emcCodeFoldContextMenu; Name: 'emcCodeFoldContextMenu'),
(Value: emcSynEditCommand; Name: 'emcSynEditCommand'),
(Value: emcSynEditCommand; Name: 'emcSynEditCommand'),
(Value: emcWheelScrollDown; Name: 'emcWheelScrollDown'),
(Value: emcWheelScrollUp; Name: 'emcWheelScrollUp')
(Value: emcWheelScrollDown; Name: 'emcWheelScrollDown'),
(Value: emcWheelScrollUp; Name: 'emcWheelScrollUp'),
(Value: emcWheelVertScrollDown; Name: 'emcWheelVertScrollDown'),
(Value: emcWheelVertScrollUp; Name: 'emcWheelVertScrollUp'),
(Value: emcWheelHorizScrollDown; Name: 'emcWheelHorizScrollDown'),
(Value: emcWheelHorizScrollUp; Name: 'emcWheelHorizScrollUp'),
(Value: emcWheelZoomOut; Name: 'emcWheelZoomOut'),
(Value: emcWheelZoomIn; Name: 'emcWheelZoomIn'),
(Value: emcWheelZoomNorm; Name: 'emcWheelZoomNorm')
);
@ -342,6 +369,14 @@ begin
emcWheelScrollDown: Result := SYNS_emcWheelScrollDown;
emcWheelScrollUp: Result := SYNS_emcWheelScrollUp;
emcWheelHorizScrollDown: Result := SYNS_emcWheelHorizScrollDown;
emcWheelHorizScrollUp: Result := SYNS_emcWheelHorizScrollUp;
emcWheelVertScrollDown: Result := SYNS_emcWheelVertScrollDown;
emcWheelVertScrollUp: Result := SYNS_emcWheelVertScrollUp;
emcWheelZoomOut: Result := SYNS_emcWheelZoomOut;
emcWheelZoomIn: Result := SYNS_emcWheelZoomIn;
emcWheelZoomNorm: Result := SYNS_emcWheelZoomNorm;
else Result := ''
end;
@ -494,6 +529,14 @@ begin
TSynEditMouseActions(Collection).AssertNoConflict(self);
end;
procedure TSynEditMouseAction.SetOption2(AValue: Integer);
begin
if FOption2 = AValue then Exit;
FOption2 := AValue;
if Collection <> nil then
TSynEditMouseActions(Collection).AssertNoConflict(self);
end;
procedure TSynEditMouseAction.SetPriority(const AValue: TSynEditorMouseCommandOpt);
begin
if FPriority = AValue then exit;
@ -583,7 +626,8 @@ begin
and (Other.Shift * self.ShiftMask = self.Shift * Other.ShiftMask)
and ((Other.Command <> self.Command) or // Only conflicts, if Command differs
(Other.MoveCaret <> self.MoveCaret) or
(Other.Option <> self.Option) )
(Other.Option <> self.Option) or
(Other.Option2 <> self.Option2) )
and not(Other.IsFallback xor self.IsFallback)
and (Other.Priority = self.Priority);
end;
@ -599,6 +643,7 @@ begin
and (Other.Priority = self.Priority)
and ((Other.Command = self.Command) or IgnoreCmd)
and ((Other.Option = self.Option) or IgnoreCmd)
and ((Other.Option2 = self.Option2) or IgnoreCmd)
and ((Other.MoveCaret = self.MoveCaret) or IgnoreCmd);
end;
@ -747,7 +792,7 @@ procedure TSynEditMouseActions.AddCommand(const ACmd: TSynEditorMouseCommand;
const AMoveCaret: Boolean; const AButton: TSynMouseButton;
const AClickCount: TSynMAClickCount; const ADir: TSynMAClickDir;
const AShift, AShiftMask: TShiftState; const AOpt: TSynEditorMouseCommandOpt = 0;
const APrior: Integer = 0);
const APrior: Integer = 0; const AOpt2: integer = 0);
var
new: TSynEditMouseAction;
begin
@ -764,6 +809,7 @@ begin
ShiftMask := AShiftMask;
Option := AOpt;
Priority := APrior;
Option2 := AOpt2;
end;
finally
dec(FAssertLock);

View File

@ -304,7 +304,7 @@ type
constructor Create(AHandleOwner: TWinControl);
destructor Destroy; override;
procedure Hide; // Keep visible = true
procedure DestroyCaret;
procedure DestroyCaret(SkipHide: boolean = False);
procedure Lock;
procedure UnLock;
property HandleOwner: TWinControl read FHandleOwner;
@ -1614,7 +1614,7 @@ begin
HideCaret;
end;
procedure TSynEditScreenCaret.DestroyCaret;
procedure TSynEditScreenCaret.DestroyCaret(SkipHide: boolean = False);
begin
if FCurrentCreated and HandleAllocated then begin
{$IFDeF SynCaretDebug}
@ -1624,7 +1624,8 @@ begin
end;
FCurrentCreated := False;
FCurrentVisible := False;
FVisible := False;
if not SkipHide then
FVisible := False;
end;
procedure TSynEditScreenCaret.Lock;
@ -1731,6 +1732,7 @@ begin
end;
end;
CalcExtraLineChars;
DestroyCaret(True);
UpdateDisplay;
end;

View File

@ -406,6 +406,14 @@ resourcestring
SYNS_emcSynEditCommand = 'IDE Command';
SYNS_emcWheelScrollDown = 'Wheel scroll down';
SYNS_emcWheelScrollUp = 'Wheel scroll up';
SYNS_emcWheelHorizScrollDown = 'Wheel scroll down (Horizontal)';
SYNS_emcWheelHorizScrollUp = 'Wheel scroll up (Horizontal)';
SYNS_emcWheelVertScrollDown = 'Wheel scroll down (Vertical)';
SYNS_emcWheelVertScrollUp = 'Wheel scroll up (Vertical)';
SYNS_emcWheelZoomOut = 'Wheel zoom out';
SYNS_emcWheelZoomIn = 'Wheel zoom in';
SYNS_emcWheelZoomNorm = 'Wheel zoom default';
SYNS_emcContextMenuCaretMove_opt = '"Move caret, when selection exists", Never, "Click outside", Always';
implementation

View File

@ -2401,7 +2401,7 @@ begin
moTMIgnore: {nothing} ;
moTMDeclarationJump:
begin
AddCommand(emcMouseLink, False, mbMiddle, ccSingle, cdDown, [ssCtrl], [ssCtrl], emcoMouseLinkShow);
AddCommand(emcMouseLink, False, mbMiddle, ccSingle, cdDown, [ssCtrl], [ssCtrl], emcoMouseLinkShow, 999);
AddCommand(emcMouseLink, False, mbMiddle, ccSingle, cdDown, [], [], emcoMouseLinkHide);
end;
end;
@ -2417,11 +2417,17 @@ begin
AddCommand(emcSynEditCommand, False, mbLeft, ccSingle, cdUp, [SYNEDIT_LINK_MODIFIER], [ssShift, ssAlt, ssCtrl], ecFindBlockOtherEnd, 1);
end;
end;
AddCommand(emcWheelZoomNorm, False, mbMiddle, ccAny, cdDown, [ssCtrl], [ssCtrl]);
end;
with FMainActions do begin
AddCommand(emcWheelScrollDown, False, mbWheelDown, ccAny, cdDown, [], []);
AddCommand(emcWheelScrollUp, False, mbWheelUp, ccAny, cdDown, [], []);
AddCommand(emcWheelScrollUp, False, mbWheelUp, ccAny, cdDown, [], []);
AddCommand(emcWheelZoomOut, False, mbWheelDown, ccAny, cdDown, [ssCtrl], [ssCtrl]);
AddCommand(emcWheelZoomIn, False, mbWheelUp, ccAny, cdDown, [ssCtrl], [ssCtrl]);
AddCommand(emcWheelZoomNorm, False, mbMiddle, ccAny, cdDown, [ssCtrl], [ssCtrl]);
end;
if FTextDrag then