mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 18:39:09 +02:00
LCL-CustomDrawn-Android: Improves the combobox selection further, fixing the case where the item index didnt change but the text did. Starts implementing Clipboard text setting
git-svn-id: trunk@37223 -
This commit is contained in:
parent
81d61cbfd7
commit
2b25ebf0b3
@ -934,6 +934,7 @@ end;
|
|||||||
procedure TCDComboBox.SetItemIndex(AValue: Integer);
|
procedure TCDComboBox.SetItemIndex(AValue: Integer);
|
||||||
var
|
var
|
||||||
lValue: Integer;
|
lValue: Integer;
|
||||||
|
lText: String;
|
||||||
begin
|
begin
|
||||||
lValue := AValue;
|
lValue := AValue;
|
||||||
|
|
||||||
@ -941,9 +942,14 @@ begin
|
|||||||
if lValue > FItems.Count then lValue := FItems.Count;
|
if lValue > FItems.Count then lValue := FItems.Count;
|
||||||
if lValue < -1 then lValue := -1;
|
if lValue < -1 then lValue := -1;
|
||||||
|
|
||||||
if FItemIndex=lValue then Exit;
|
// Check if the text changed too, because it might differ from the choosen item
|
||||||
FItemIndex:=lValue;
|
FItemIndex:=lValue;
|
||||||
if lValue >= 0 then Text := FItems.Strings[lValue];
|
if lValue >= 0 then
|
||||||
|
begin
|
||||||
|
lText := FItems.Strings[lValue];
|
||||||
|
if Lines.Text = lText then Exit;
|
||||||
|
Text := lText;
|
||||||
|
end;
|
||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
// ==================
|
// ==================
|
||||||
// Android options
|
// Android options
|
||||||
// ==================
|
// ==================
|
||||||
{$define VerboseCDShowSelectItemDialog}
|
{.$define VerboseCDShowSelectItemDialog}
|
||||||
|
|
||||||
// ==================
|
// ==================
|
||||||
// X11 options
|
// X11 options
|
||||||
@ -81,7 +81,7 @@
|
|||||||
{.$define VerboseCDX11WinAPI}
|
{.$define VerboseCDX11WinAPI}
|
||||||
{.$define VerboseCDEvents}
|
{.$define VerboseCDEvents}
|
||||||
{.$define VerboseCDAccessibility}
|
{.$define VerboseCDAccessibility}
|
||||||
{$define VerboseCDClipboard}
|
{.$define VerboseCDClipboard}
|
||||||
{.$define VerboseCDFocus}
|
{.$define VerboseCDFocus}
|
||||||
{.$define VerboseCDKeyInput}
|
{.$define VerboseCDKeyInput}
|
||||||
|
|
||||||
|
@ -218,9 +218,11 @@ begin
|
|||||||
begin
|
begin
|
||||||
lChar := lNativeString[i];
|
lChar := lNativeString[i];
|
||||||
Stream.WriteByte(Byte(lChar));
|
Stream.WriteByte(Byte(lChar));
|
||||||
|
{$ifdef VerboseCDClipboard}
|
||||||
|
DebugLn(Format(':[TCDWidgetSet.ClipboardGetData] Writing char %d="%s"', [Byte(lChar), string(lChar)]));
|
||||||
|
{$endif}
|
||||||
Inc(i);
|
Inc(i);
|
||||||
end;
|
end;
|
||||||
Stream.WriteByte(0);
|
|
||||||
javaEnvRef^^.ReleaseStringUTFChars(javaEnvRef, lJavaString, lNativeString);
|
javaEnvRef^^.ReleaseStringUTFChars(javaEnvRef, lJavaString, lNativeString);
|
||||||
{$ifdef VerboseCDClipboard}
|
{$ifdef VerboseCDClipboard}
|
||||||
DebugLn(Format(':<[TCDWidgetSet.ClipboardGetData] lNativeString=%s lJavaString=%x', [StrPas(lNativeString), PtrInt(lJavaString)]));
|
DebugLn(Format(':<[TCDWidgetSet.ClipboardGetData] lNativeString=%s lJavaString=%x', [StrPas(lNativeString), PtrInt(lJavaString)]));
|
||||||
@ -246,31 +248,66 @@ end;
|
|||||||
with the invalid FormatID 0 to notify the old owner of the lost of ownership.
|
with the invalid FormatID 0 to notify the old owner of the lost of ownership.
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
function TCDWidgetSet.ClipboardGetOwnerShip(ClipboardType: TClipboardType;
|
function TCDWidgetSet.ClipboardGetOwnerShip(ClipboardType: TClipboardType;
|
||||||
OnRequestProc: TClipboardRequestEvent; FormatCount: integer;
|
OnRequestProc: TClipboardRequestEvent; FormatCount: integer;
|
||||||
Formats: PClipboardFormat): boolean;
|
Formats: PClipboardFormat): boolean;
|
||||||
var
|
var
|
||||||
|
// Java IDs
|
||||||
|
javaAndroidTextClipboardManagerClass: JClass;
|
||||||
|
javaMethod_ClipboardManager_setText: jmethodid = nil;
|
||||||
|
// Java Object instances
|
||||||
lJavaString: jstring;
|
lJavaString: jstring;
|
||||||
|
lClipboardManagerObject: JObject;
|
||||||
|
javaString_CLIPBOARD_SERVICE: JString;
|
||||||
|
// array for the parameters
|
||||||
lParams: array[0..0] of JValue;
|
lParams: array[0..0] of JValue;
|
||||||
|
//
|
||||||
|
lStringStream: TStringStream;
|
||||||
|
lTextFormatIndex: TClipboardFormat;
|
||||||
|
lTextFormatFound: Boolean = False;
|
||||||
|
i: Integer;
|
||||||
|
const
|
||||||
|
javaConstant_CLIPBOARD_SERVICE = 'clipboard';
|
||||||
begin
|
begin
|
||||||
{$ifdef VerboseCDClipboard}
|
{$ifdef VerboseCDClipboard}
|
||||||
DebugLn('[TCDWidgetSet.ClipboardGetOwnerShip]');
|
DebugLn(Format('[TCDWidgetSet.ClipboardGetOwnerShip] OnRequestProc=%x', [PtrInt(OnRequestProc)]));
|
||||||
{$endif}
|
{$endif}
|
||||||
Result := True;
|
Result := True; // Result always true, so that we can at least use internally the clipboard
|
||||||
|
|
||||||
// abstract void setText(CharSequence text)
|
if (javaEnvRef = nil) then Exit;
|
||||||
|
if OnRequestProc = nil then Exit;
|
||||||
|
|
||||||
{// Prepare the input
|
// Check if there is text in the list. If there isn't, give up
|
||||||
lJavaString :=javaEnvRef^^.NewStringUTF(javaEnvRef, Str);
|
lTextFormatIndex := Self.ClipboardRegisterFormat('text/plain');
|
||||||
javaEnvRef^^.SetObjectField(javaEnvRef, javaActivityObject, JavaField_lcltext, lJavaString);
|
for i := 0 to FormatCount-1 do
|
||||||
javaEnvRef^^.DeleteLocalRef(javaEnvRef, lJavaString);
|
begin
|
||||||
javaEnvRef^^.SetIntField(javaEnvRef, javaActivityObject, javaField_lcltextsize, lFontSize);
|
if Formats[i] = lTextFormatIndex then
|
||||||
|
begin
|
||||||
|
lTextFormatFound := True;
|
||||||
|
Break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
// With API level 8 we can only have text support
|
||||||
|
if not lTextFormatFound then
|
||||||
|
begin
|
||||||
|
Exit;
|
||||||
|
DebugLn(':<[TCDWidgetSet.ClipboardGetOwnerShip] Exiting because non-textual formats are not supported');
|
||||||
|
end;
|
||||||
|
|
||||||
// Call the method to measure the text
|
// First IDs
|
||||||
javaEnvRef^^.CallObjectMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoGetTextBounds);
|
javaAndroidTextClipboardManagerClass := javaEnvRef^^.FindClass(javaEnvRef,'android/text/ClipboardManager');
|
||||||
}
|
javaMethod_ClipboardManager_setText := javaEnvRef^^.GetMethodID(javaEnvRef, javaAndroidTextClipboardManagerClass, 'setText', '(Ljava/lang/CharSequence;)V');
|
||||||
{// Call the method to draw the text
|
|
||||||
lParams[0].i := FPColorToAndroidColor(lDestCanvas.Font.FPColor);
|
// Gets a handle to the Clipboard Manager
|
||||||
javaEnvRef^^.CallVoidMethodA(javaEnvRef, javaActivityObject, javaMethod_LCLDoDrawText, @lParams[0]);}
|
//ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
javaString_CLIPBOARD_SERVICE := javaEnvRef^^.NewStringUTF(javaEnvRef, pchar(javaConstant_CLIPBOARD_SERVICE));
|
||||||
|
lParams[0].l := javaString_CLIPBOARD_SERVICE;
|
||||||
|
lClipboardManagerObject := javaEnvRef^^.CallObjectMethodA(javaEnvRef, javaActivityObject, javaMethod_getSystemService, @lParams[0]);
|
||||||
|
|
||||||
|
// clipboard.setText
|
||||||
|
OnRequestProc(lTextFormatIndex, lStringStream);
|
||||||
|
lJavaString := javaEnvRef^^.NewStringUTF(javaEnvRef, PChar(lStringStream.DataString));
|
||||||
|
lParams[0].l := lJavaString;
|
||||||
|
javaEnvRef^^.CallVoidMethodA(javaEnvRef, lClipboardManagerObject, javaMethod_ClipboardManager_setText, @lParams[0]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
(*{------------------------------------------------------------------------------
|
(*{------------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user