|
@@ -85,6 +85,8 @@ Type
|
|
function DoDispatchEvent(aEvent: TAbstractEvent): Integer; override;
|
|
function DoDispatchEvent(aEvent: TAbstractEvent): Integer; override;
|
|
procedure HandleFocusChange(GotFocus: Boolean);
|
|
procedure HandleFocusChange(GotFocus: Boolean);
|
|
procedure HandleKeyDown(aEvent: TFresnelKeyEvent); virtual;
|
|
procedure HandleKeyDown(aEvent: TFresnelKeyEvent); virtual;
|
|
|
|
+ procedure HandleInput(aEvent: TFresnelInputEvent); virtual;
|
|
|
|
+ procedure HandleKeyUp(aEvent: TFresnelKeyEvent); virtual;
|
|
procedure HandleMouseDown(aEvent : TFresnelMouseEvent); virtual;
|
|
procedure HandleMouseDown(aEvent : TFresnelMouseEvent); virtual;
|
|
procedure HandleMouseMove(aEvent: TFresnelMouseEvent); virtual;
|
|
procedure HandleMouseMove(aEvent: TFresnelMouseEvent); virtual;
|
|
procedure HandleMouseUp(aEvent : TFresnelMouseEvent); virtual;
|
|
procedure HandleMouseUp(aEvent : TFresnelMouseEvent); virtual;
|
|
@@ -229,124 +231,148 @@ end;
|
|
procedure TEdit.HandleKeyDown(aEvent: TFresnelKeyEvent);
|
|
procedure TEdit.HandleKeyDown(aEvent: TFresnelKeyEvent);
|
|
|
|
|
|
var
|
|
var
|
|
- lKeyUTF8 : String;
|
|
|
|
- lKeyLen : Integer;
|
|
|
|
lChanged : Boolean;
|
|
lChanged : Boolean;
|
|
lOffset : Integer;
|
|
lOffset : Integer;
|
|
- pInsert,pStart : PAnsiChar;
|
|
|
|
|
|
|
|
begin
|
|
begin
|
|
- lChanged:=False;
|
|
|
|
// Printable character has numkey >0
|
|
// Printable character has numkey >0
|
|
if (aEvent.NumKey>0) and not (aEvent.CtrlKey) then
|
|
if (aEvent.NumKey>0) and not (aEvent.CtrlKey) then
|
|
- begin
|
|
|
|
- if ReadOnly then
|
|
|
|
- exit;
|
|
|
|
- DoDeleteSelection;
|
|
|
|
- lKeyUTF8:=UnicodeToUTF8(aEvent.NumKey);
|
|
|
|
- pStart:=PAnsiChar(FValue);
|
|
|
|
- pInsert:=UTF8CodepointStart(pStart,Length(FValue),FCursorPos);
|
|
|
|
- Insert(lKeyUTF8,FValue,PtrInt(PInsert-PStart)+1);
|
|
|
|
- if FCursorPos<=FSelectionEnd then
|
|
|
|
- Inc(FSelectionEnd,1);
|
|
|
|
- if FCursorPos<=FSelectionStart then
|
|
|
|
- Inc(FSelectionStart,1);
|
|
|
|
- Inc(FCursorPos,1);
|
|
|
|
- EventDispatcher.DispatchEvent(evtChange);
|
|
|
|
- lChanged:=True;
|
|
|
|
- end
|
|
|
|
- else
|
|
|
|
- begin
|
|
|
|
- lChanged:=True;
|
|
|
|
- Case aEvent.NumKey of
|
|
|
|
- TKeyCodes.BackSpace:
|
|
|
|
|
|
+ exit;
|
|
|
|
+ lChanged:=True;
|
|
|
|
+ Case aEvent.NumKey of
|
|
|
|
+ TKeyCodes.ArrowLeft :
|
|
|
|
+ begin
|
|
|
|
+ if FCursorPos>0 then
|
|
begin
|
|
begin
|
|
- if FSelectionStart=FSelectionEnd then
|
|
|
|
- begin
|
|
|
|
- if FCursorPos>0 then
|
|
|
|
- begin
|
|
|
|
- lOffset:=UTF8FindNearestCharStart(PChar(FValue),Length(FValue),FCursorPos-1);
|
|
|
|
- lKeyLen:=UTF8CodepointSize(@FValue[lOffset+1]);
|
|
|
|
- Delete(FValue,lOffSet+1,lKeyLen);
|
|
|
|
- FCursorPos:=lOffSet;
|
|
|
|
- FSelectionStart:=FCursorPos;
|
|
|
|
- FSelectionEnd:=FCursorPos;
|
|
|
|
- end
|
|
|
|
- end
|
|
|
|
|
|
+ if aEvent.CtrlKey then
|
|
|
|
+ lOffset:=PrevWordStartOffset-FCursorPos
|
|
else
|
|
else
|
|
- begin
|
|
|
|
- DoDeleteSelection;
|
|
|
|
|
|
+ lOffset:=-1; // Todo: calc length of codepoint in bytes
|
|
|
|
+ FCursorPos:=FCursorPos+lOffset;
|
|
|
|
+ FSelectionStart:=FCursorPos;
|
|
|
|
+ if not aEvent.ShiftKey then
|
|
FSelectionEnd:=FSelectionStart;
|
|
FSelectionEnd:=FSelectionStart;
|
|
- FCursorPos:=FSelectionStart;
|
|
|
|
- end;
|
|
|
|
end;
|
|
end;
|
|
- TKeyCodes.Delete:
|
|
|
|
|
|
+ end;
|
|
|
|
+ TKeyCodes.ArrowRight :
|
|
|
|
+ begin
|
|
|
|
+ if FCursorPos<Length(FValue) then
|
|
begin
|
|
begin
|
|
- if FSelectionStart=FSelectionEnd then
|
|
|
|
- begin
|
|
|
|
- lKeyLen:=UTF8CodepointSize(@FValue[FCursorPos+1]);
|
|
|
|
- Delete(FValue,FCursorPos+1,lKeyLen);
|
|
|
|
- end
|
|
|
|
|
|
+ if aEvent.CtrlKey then
|
|
|
|
+ lOffset:=NextWordEndOffset-FCursorPos
|
|
else
|
|
else
|
|
- begin
|
|
|
|
- lKeyLen:=Abs(FSelectionStart-FSelectionEnd);
|
|
|
|
- DoDeleteSelection;
|
|
|
|
- if FSelectionStart<FSelectionEnd then
|
|
|
|
- FSelectionEnd:=FSelectionStart
|
|
|
|
- else
|
|
|
|
- FSelectionStart:=FSelectionEnd;
|
|
|
|
- end;
|
|
|
|
- FCursorPos:=FSelectionEnd;
|
|
|
|
- end;
|
|
|
|
- TKeyCodes.ArrowLeft :
|
|
|
|
- begin
|
|
|
|
- if FCursorPos>0 then
|
|
|
|
- begin
|
|
|
|
- if aEvent.CtrlKey then
|
|
|
|
- lOffset:=PrevWordStartOffset-FCursorPos
|
|
|
|
- else
|
|
|
|
- lOffset:=-1; // Todo: calc length of codepoint in bytes
|
|
|
|
- FCursorPos:=FCursorPos+lOffset;
|
|
|
|
- FSelectionStart:=FCursorPos;
|
|
|
|
- if not aEvent.ShiftKey then
|
|
|
|
- FSelectionEnd:=FSelectionStart;
|
|
|
|
- end;
|
|
|
|
- end;
|
|
|
|
- TKeyCodes.ArrowRight :
|
|
|
|
- begin
|
|
|
|
- if FCursorPos<Length(FValue) then
|
|
|
|
- begin
|
|
|
|
- if aEvent.CtrlKey then
|
|
|
|
- lOffset:=NextWordEndOffset-FCursorPos
|
|
|
|
- else
|
|
|
|
- lOffset:=1;
|
|
|
|
- Inc(FCursorPos,lOffset);
|
|
|
|
- FSelectionEnd:=FCursorPos;
|
|
|
|
- if not aEvent.ShiftKey then
|
|
|
|
- FSelectionStart:=FSelectionEnd;
|
|
|
|
- end
|
|
|
|
- end;
|
|
|
|
- TKeyCodes.Home:
|
|
|
|
- begin
|
|
|
|
- FCursorPos:=0;
|
|
|
|
- FSelectionEnd:=0;
|
|
|
|
|
|
+ lOffset:=1;
|
|
|
|
+ Inc(FCursorPos,lOffset);
|
|
|
|
+ FSelectionEnd:=FCursorPos;
|
|
if not aEvent.ShiftKey then
|
|
if not aEvent.ShiftKey then
|
|
- FSelectionStart:=0;
|
|
|
|
- end;
|
|
|
|
- TKeyCodes.End_:
|
|
|
|
|
|
+ FSelectionStart:=FSelectionEnd;
|
|
|
|
+ end
|
|
|
|
+ end;
|
|
|
|
+ TKeyCodes.Home:
|
|
|
|
+ begin
|
|
|
|
+ FCursorPos:=0;
|
|
|
|
+ FSelectionEnd:=0;
|
|
|
|
+ if not aEvent.ShiftKey then
|
|
|
|
+ FSelectionStart:=0;
|
|
|
|
+ end;
|
|
|
|
+ TKeyCodes.End_:
|
|
|
|
+ begin
|
|
|
|
+ FCursorPos:=Length(FValue);
|
|
|
|
+ FSelectionEnd:=FCursorPos;
|
|
|
|
+ if not aEvent.ShiftKey then
|
|
|
|
+ FSelectionStart:=FCursorPos;
|
|
|
|
+ end;
|
|
|
|
+ else
|
|
|
|
+ lChanged:=False;
|
|
|
|
+ end;
|
|
|
|
+ if lChanged then
|
|
|
|
+ EditParamsChanged;
|
|
|
|
+// Writeln('Text now: "',FValue,'", Selection now: "',GetSelectionText,'"');
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TEdit.HandleInput(aEvent: TFresnelInputEvent);
|
|
|
|
+
|
|
|
|
+var
|
|
|
|
+ lKeyLen : Integer;
|
|
|
|
+ lKeyUTF8 : String;
|
|
|
|
+ pInsert,pStart : PAnsiChar;
|
|
|
|
+ lChanged : Boolean;
|
|
|
|
+ lOffset : Integer;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ // Writeln('In input, using data : "',aEvent.Data,'": ',aEvent.FresnelInputType);
|
|
|
|
+ if ReadOnly then
|
|
|
|
+ exit;
|
|
|
|
+ lChanged:=True;
|
|
|
|
+ Case aEvent.FresnelInputType of
|
|
|
|
+ fitDeleteContentBackward:
|
|
|
|
+ begin
|
|
|
|
+ if FSelectionStart=FSelectionEnd then
|
|
|
|
+ begin
|
|
|
|
+ if FCursorPos>0 then
|
|
begin
|
|
begin
|
|
- FCursorPos:=Length(FValue);
|
|
|
|
|
|
+ lOffset:=UTF8FindNearestCharStart(PChar(FValue),Length(FValue),FCursorPos-1);
|
|
|
|
+ lKeyLen:=UTF8CodepointSize(@FValue[lOffset+1]);
|
|
|
|
+ Delete(FValue,lOffSet+1,lKeyLen);
|
|
|
|
+ FCursorPos:=lOffSet;
|
|
|
|
+ FSelectionStart:=FCursorPos;
|
|
FSelectionEnd:=FCursorPos;
|
|
FSelectionEnd:=FCursorPos;
|
|
- if not aEvent.ShiftKey then
|
|
|
|
- FSelectionStart:=FCursorPos;
|
|
|
|
- end;
|
|
|
|
|
|
+ end
|
|
|
|
+ end
|
|
else
|
|
else
|
|
- lChanged:=False;
|
|
|
|
|
|
+ begin
|
|
|
|
+ DoDeleteSelection;
|
|
|
|
+ FSelectionEnd:=FSelectionStart;
|
|
|
|
+ FCursorPos:=FSelectionStart;
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+ fitDeleteContentForward:
|
|
|
|
+ begin
|
|
|
|
+ if FSelectionStart=FSelectionEnd then
|
|
|
|
+ begin
|
|
|
|
+ lKeyLen:=UTF8CodepointSize(@FValue[FCursorPos+1]);
|
|
|
|
+ Delete(FValue,FCursorPos+1,lKeyLen);
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ begin
|
|
|
|
+ lKeyLen:=Abs(FSelectionStart-FSelectionEnd);
|
|
|
|
+ DoDeleteSelection;
|
|
|
|
+ if FSelectionStart<FSelectionEnd then
|
|
|
|
+ FSelectionEnd:=FSelectionStart
|
|
|
|
+ else
|
|
|
|
+ FSelectionStart:=FSelectionEnd;
|
|
|
|
+ end;
|
|
|
|
+ FCursorPos:=FSelectionEnd;
|
|
end;
|
|
end;
|
|
|
|
+ fitInsertText,
|
|
|
|
+ fitInsertCompositionText,
|
|
|
|
+ fitInsertFromPaste:
|
|
|
|
+ begin
|
|
|
|
+ DoDeleteSelection;
|
|
|
|
+ lKeyUTF8:=aEvent.Data;
|
|
|
|
+ pStart:=PAnsiChar(FValue);
|
|
|
|
+ pInsert:=UTF8CodepointStart(pStart,Length(FValue),FCursorPos);
|
|
|
|
+ Insert(lKeyUTF8,FValue,PtrInt(PInsert-PStart)+1);
|
|
|
|
+ if FCursorPos<=FSelectionEnd then
|
|
|
|
+ Inc(FSelectionEnd,1);
|
|
|
|
+ if FCursorPos<=FSelectionStart then
|
|
|
|
+ Inc(FSelectionStart,1);
|
|
|
|
+ Inc(FCursorPos,1);
|
|
end;
|
|
end;
|
|
|
|
+ else
|
|
|
|
+ lChanged:=False;
|
|
|
|
+ end;
|
|
if lChanged then
|
|
if lChanged then
|
|
|
|
+ begin
|
|
|
|
+ EventDispatcher.DispatchEvent(evtChange);
|
|
EditParamsChanged;
|
|
EditParamsChanged;
|
|
- Writeln('Text now: "',FValue,'", Selection now: "',GetSelectionText,'"');
|
|
|
|
|
|
+ end;
|
|
|
|
+ // Writeln('Text now: "',FValue,'", Selection now: "',GetSelectionText,'"');
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TEdit.HandleKeyUp(aEvent: TFresnelKeyEvent);
|
|
|
|
+begin
|
|
|
|
+ // Do nothing for the moment.
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TEdit.HandleMouseMove(aEvent : TFresnelMouseEvent);
|
|
procedure TEdit.HandleMouseMove(aEvent : TFresnelMouseEvent);
|
|
@@ -542,7 +568,7 @@ begin
|
|
end
|
|
end
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
- Writeln('Prem brak');
|
|
|
|
|
|
+ // Writeln('Premature break');
|
|
break; // we can safely break after last visible character is found
|
|
break; // we can safely break after last visible character is found
|
|
end;
|
|
end;
|
|
Inc(lCharNum);
|
|
Inc(lCharNum);
|
|
@@ -562,7 +588,7 @@ begin
|
|
|
|
|
|
FVisibleText := Copy(lText, lFirstVisibleIndex, lLastVisibleIndex - lFirstVisibleIndex);
|
|
FVisibleText := Copy(lText, lFirstVisibleIndex, lLastVisibleIndex - lFirstVisibleIndex);
|
|
FDrawOffset := FTextOffset - FDrawOffset;
|
|
FDrawOffset := FTextOffset - FDrawOffset;
|
|
- Writeln('Calc cursor at: ',FCursorX,' text width : ',Font.TextSize(lText).x,' offset : ', FTextOffset);
|
|
|
|
|
|
+ //Writeln('Calc cursor at: ',FCursorX:5:2,' text width : ',Font.TextSize(lText).x:5:2,' offset : ', FTextOffset);
|
|
|
|
|
|
// Write('Value: "',FValue,'", Visible: "',FVisibleText,'"');
|
|
// Write('Value: "',FValue,'", Visible: "',FVisibleText,'"');
|
|
// Write(', Sel: [Char:',FSelectionStart:2,' -',FSelectionEnd:5,', Pos:',FSelectionStartX:5:2,' -',FSelectionEndX:5:2,']');
|
|
// Write(', Sel: [Char:',FSelectionStart:2,' -',FSelectionEnd:5,', Pos:',FSelectionStartX:5:2,' -',FSelectionEndX:5:2,']');
|
|
@@ -611,7 +637,7 @@ begin
|
|
break;
|
|
break;
|
|
Inc(lCharNum);
|
|
Inc(lCharNum);
|
|
end;
|
|
end;
|
|
- Writeln('CalcCharOffset : ',Result);
|
|
|
|
|
|
+ // Writeln('CalcCharOffset : ',Result);
|
|
end;
|
|
end;
|
|
|
|
|
|
Function TEdit.CalcXOffset(aCharPos: Integer; aUseOffset: Boolean = true; aUseDrawText : Boolean = False) : TFresnelLength;
|
|
Function TEdit.CalcXOffset(aCharPos: Integer; aUseOffset: Boolean = true; aUseDrawText : Boolean = False) : TFresnelLength;
|
|
@@ -742,6 +768,7 @@ var
|
|
lFresnelEvt : TFresnelEvent absolute aEvent;
|
|
lFresnelEvt : TFresnelEvent absolute aEvent;
|
|
lKeyEvent : TFresnelKeyEvent absolute aEvent;
|
|
lKeyEvent : TFresnelKeyEvent absolute aEvent;
|
|
lMouseEvent : TFresnelMouseEvent absolute aEvent;
|
|
lMouseEvent : TFresnelMouseEvent absolute aEvent;
|
|
|
|
+ lInputEvent : TFresnelInputEvent absolute aEvent;
|
|
|
|
|
|
begin
|
|
begin
|
|
Result:=inherited DoDispatchEvent(aEvent);
|
|
Result:=inherited DoDispatchEvent(aEvent);
|
|
@@ -753,15 +780,18 @@ begin
|
|
evtBlur,
|
|
evtBlur,
|
|
evtFocus:
|
|
evtFocus:
|
|
HandleFocusChange(aEvent.EventID=evtFocus);
|
|
HandleFocusChange(aEvent.EventID=evtFocus);
|
|
- evtKeyDown
|
|
|
|
- {, evtKeyUp
|
|
|
|
- , evtKeyPress
|
|
|
|
- }:
|
|
|
|
|
|
+ evtKeyDown,
|
|
|
|
+ evtKeyUp:
|
|
if (aEvent is TFresnelKeyEvent) then
|
|
if (aEvent is TFresnelKeyEvent) then
|
|
begin
|
|
begin
|
|
- if aEvent.EventID=evtKeyDown then
|
|
|
|
- HandleKeyDown(lKeyEvent);
|
|
|
|
|
|
+ Case aEvent.EventID of
|
|
|
|
+ evtKeyDown: HandleKeyDown(lKeyEvent);
|
|
|
|
+ evtKeyUp: HandleKeyUp(lKeyEvent);
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
|
|
+ evtInput:
|
|
|
|
+ HandleInput(lInputEvent);
|
|
|
|
+
|
|
evtMouseDown:
|
|
evtMouseDown:
|
|
if (aEvent is TFresnelMouseEvent) then
|
|
if (aEvent is TFresnelMouseEvent) then
|
|
HandleMouseDown(lMouseEvent);
|
|
HandleMouseDown(lMouseEvent);
|
|
@@ -827,10 +857,13 @@ begin
|
|
// Selection background.
|
|
// Selection background.
|
|
RSel:=R;
|
|
RSel:=R;
|
|
SelWidth:=Abs(FSelectionStartX-FSelectionEndX);
|
|
SelWidth:=Abs(FSelectionStartX-FSelectionEndX);
|
|
- RSel.Left:=RSel.Left+{lLeftSideMargin+}FSelectionStartX;
|
|
|
|
- RSel.Right:=RSel.Left+SelWidth;
|
|
|
|
- lBackColor:=fpimage.colDkBlue; // GetComputedColor(fcaSelectionBackGroundColor,colTransparent);
|
|
|
|
- aRenderer.FillRect(fpimage.colDkBlue,RSel);
|
|
|
|
|
|
+ if SelWidth>0 then
|
|
|
|
+ begin
|
|
|
|
+ RSel.Left:=RSel.Left+{lLeftSideMargin+}FSelectionStartX;
|
|
|
|
+ RSel.Right:=RSel.Left+SelWidth;
|
|
|
|
+ lBackColor:=fpimage.colDkBlue; // GetComputedColor(fcaSelectionBackGroundColor,colTransparent);
|
|
|
|
+ aRenderer.FillRect(fpimage.colDkBlue,RSel);
|
|
|
|
+ end;
|
|
lHaveShadow:=GetComputedTextShadow(lOffsetX, lOffsetY, lRadius, lShadowColor);
|
|
lHaveShadow:=GetComputedTextShadow(lOffsetX, lOffsetY, lRadius, lShadowColor);
|
|
if lHaveShadow then
|
|
if lHaveShadow then
|
|
aRenderer.AddTextShadow(lOffsetX,lOffsetY,lShadowColor,lRadius);
|
|
aRenderer.AddTextShadow(lOffsetX,lOffsetY,lShadowColor,lRadius);
|
|
@@ -838,6 +871,7 @@ begin
|
|
lTopSideMargin:=GetComputedLength(fcaPaddingTop);
|
|
lTopSideMargin:=GetComputedLength(fcaPaddingTop);
|
|
if FSelectionStart<>FSelectionEnd then
|
|
if FSelectionStart<>FSelectionEnd then
|
|
begin
|
|
begin
|
|
|
|
+ // Writeln('Have sel');
|
|
if FSelectionStart>0 then
|
|
if FSelectionStart>0 then
|
|
aRenderer.TextOut(R.Left+lLeftSideMargin,R.Top+lTopSideMargin,Font,lColorFP,Copy(lCaption,1,1+FSelectionStart));
|
|
aRenderer.TextOut(R.Left+lLeftSideMargin,R.Top+lTopSideMargin,Font,lColorFP,Copy(lCaption,1,1+FSelectionStart));
|
|
aRenderer.TextOut(RSel.Left,RSel.Top+lTopSideMargin,Font,colWhite,Copy(lCaption,1+FSelectionStart,FSelectionEnd-FSelectionStart));
|
|
aRenderer.TextOut(RSel.Left,RSel.Top+lTopSideMargin,Font,colWhite,Copy(lCaption,1+FSelectionStart,FSelectionEnd-FSelectionStart));
|
|
@@ -847,7 +881,7 @@ begin
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
aRenderer.TextOut(R.Left+lLeftSideMargin,R.Top+lTopSideMargin,Font,lColorFP,lCaption);
|
|
aRenderer.TextOut(R.Left+lLeftSideMargin,R.Top+lTopSideMargin,Font,lColorFP,lCaption);
|
|
- Writeln('Cursor at: ',FCursorX,' text width : ',Font.TextSize(lCaption).x);
|
|
|
|
|
|
+ // Writeln('Cursor at: ',FCursorX:5:2,' text width : ',Font.TextSize(lCaption).x:5:2);
|
|
end;
|
|
end;
|
|
|
|
|
|
if FCursorVisible then
|
|
if FCursorVisible then
|