mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-17 21:30:04 +02:00
customdrawn-android: Improves the non-native form handling and implement appropriate support for the Back hardware key
git-svn-id: trunk@34180 -
This commit is contained in:
parent
872dd6830b
commit
4a5b2a2815
examples/androidlcl/android/src/com/pascal/lcltest
lcl/interfaces/customdrawn
@ -53,7 +53,10 @@ public class LCLActivity extends Activity
|
||||
{
|
||||
int eventResult = LCLOnKey(KeyEvent.ACTION_UP, keyCode, event, event.getDisplayLabel());
|
||||
if ((eventResult | 1) != 0) postInvalidate();
|
||||
return true;
|
||||
|
||||
// Handling of the Back hardware key
|
||||
if ((eventResult | 2) != 0) return false;
|
||||
else return true;
|
||||
}
|
||||
|
||||
@Override public boolean onTouchEvent (MotionEvent event)
|
||||
|
@ -127,6 +127,7 @@ begin
|
||||
Application.Run;
|
||||
end;
|
||||
|
||||
// This one is for all simple dialogs: MessageBox, PromptUser (MessageDlg) and AskUser
|
||||
function Java_com_pascal_lclproject_LCLActivity_LCLOnMessageBoxFinished(
|
||||
env:PJNIEnv; this:jobject; AResult: jint): jint; cdecl;
|
||||
begin
|
||||
@ -146,6 +147,7 @@ var
|
||||
AWideText: widestring;
|
||||
AUTF8Text: string;
|
||||
AUTF8Char: TUTF8Char;
|
||||
lForm: TCDNonNativeForm;
|
||||
begin
|
||||
{$ifdef VerboseCDEvents}
|
||||
__android_log_write(ANDROID_LOG_INFO,'lclapp',PChar(
|
||||
@ -174,6 +176,17 @@ begin
|
||||
AUTF8Char := AUTF8Text;
|
||||
LCLSendUTF8KeyPress(lTarget, AUTF8Char, False);
|
||||
end;
|
||||
|
||||
// Handle the Back hardware key
|
||||
if AKeyCode = AKEYCODE_BACK then
|
||||
begin
|
||||
// The back hardware key hides the current form and shows the one bellow it
|
||||
lForm := GetCurrentForm();
|
||||
HideForm(lForm);
|
||||
// If all forms got hidden, exit the application
|
||||
lForm := GetCurrentForm();
|
||||
if lForm = nil then eventResult := eventResult or 2;
|
||||
end;
|
||||
end;
|
||||
//ACTION_MULTIPLE:
|
||||
end;
|
||||
|
@ -13,7 +13,7 @@ uses
|
||||
// LCL
|
||||
GraphType, Controls, LCLMessageGlue, WSControls, LCLType, LCLProc,
|
||||
StdCtrls, ExtCtrls, Forms, Graphics, customdrawncontrols,
|
||||
InterfaceBase;
|
||||
InterfaceBase, LCLIntf;
|
||||
|
||||
type
|
||||
TUpdateLazImageFormat = (
|
||||
@ -64,6 +64,7 @@ type
|
||||
|
||||
TCDNonNativeForm = class(TCDForm)
|
||||
public
|
||||
Visible: Boolean;
|
||||
end;
|
||||
|
||||
TCDBitmap = class
|
||||
@ -83,6 +84,7 @@ type
|
||||
procedure AddCDWinControlToForm(const AForm: TCustomForm; ACDWinControl: TCDWinControl);
|
||||
function GetCDWinControlList(const AForm: TCustomForm): TFPList;
|
||||
|
||||
// Routines for non-native form managing
|
||||
procedure InitNonNativeForms();
|
||||
function GetCurrentForm(): TCDNonNativeForm;
|
||||
function AddNewForm(AForm: TCustomForm): TCDNonNativeForm;
|
||||
@ -90,6 +92,9 @@ procedure AddFormWithCDHandle(AHandle: TCDForm);
|
||||
function FindFormWithNativeHandle(AHandle: HWND): TCDForm;
|
||||
procedure ShowForm(ACDForm: TCDNonNativeForm);
|
||||
procedure HideForm(ACDForm: TCDNonNativeForm);
|
||||
procedure BringFormToFront(ACDForm: TCDNonNativeForm);
|
||||
procedure SendFormToBack(ACDForm: TCDNonNativeForm);
|
||||
function FindTopMostVisibleForm: TCDNonNativeForm;
|
||||
|
||||
// Routines for non-native wincontrol
|
||||
|
||||
@ -131,6 +136,7 @@ implementation
|
||||
var
|
||||
// List with the Z-order of non-native forms, index=0 is the bottom-most form
|
||||
NonNativeForms: TFPList = nil;
|
||||
lCurrentForm: TCDNonNativeForm = nil;
|
||||
|
||||
// List of timers
|
||||
TimersList: TFPList = nil;
|
||||
@ -160,16 +166,11 @@ begin
|
||||
end;
|
||||
|
||||
function GetCurrentForm(): TCDNonNativeForm;
|
||||
var
|
||||
lCount: Integer;
|
||||
begin
|
||||
{$IFDEF VerboseCDForms}
|
||||
DebugLn('GetCurrentForm');
|
||||
{$ENDIF}
|
||||
InitNonNativeForms();
|
||||
lCount := NonNativeForms.Count;
|
||||
if lCount = 0 then Result := nil
|
||||
else Result := TCDNonNativeForm(NonNativeForms.Items[lCount-1]);
|
||||
Result := lCurrentForm;
|
||||
end;
|
||||
|
||||
function AddNewForm(AForm: TCustomForm): TCDNonNativeForm;
|
||||
@ -211,6 +212,24 @@ begin
|
||||
end;
|
||||
|
||||
procedure ShowForm(ACDForm: TCDNonNativeForm);
|
||||
begin
|
||||
ACDForm.Visible := True;
|
||||
BringFormToFront(ACDForm);
|
||||
lCurrentForm := ACDForm;
|
||||
end;
|
||||
|
||||
procedure HideForm(ACDForm: TCDNonNativeForm);
|
||||
begin
|
||||
ACDForm.Visible := False;
|
||||
// update the Current Form if required, and invalidate too
|
||||
if lCurrentForm = ACDForm then
|
||||
begin
|
||||
lCurrentForm := FindTopMostVisibleForm();
|
||||
LCLIntf.InvalidateRect(lCurrentForm.NativeHandle, nil, True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure BringFormToFront(ACDForm: TCDNonNativeForm);
|
||||
var
|
||||
lCount, lCurIndex: Integer;
|
||||
begin
|
||||
@ -218,24 +237,45 @@ begin
|
||||
lCount := NonNativeForms.Count;
|
||||
lCurIndex := NonNativeForms.IndexOf(ACDForm);
|
||||
{$IFDEF VerboseCDForms}
|
||||
DebugLn(Format('ShowForm lOldIndex=%d lNewIndex=%d', [lCurIndex, lCount-1]));
|
||||
DebugLn(Format('BringFormToFront lOldIndex=%d lNewIndex=%d', [lCurIndex, lCount-1]));
|
||||
{$ENDIF}
|
||||
NonNativeForms.Move(lCurIndex, lCount-1);
|
||||
end;
|
||||
|
||||
procedure HideForm(ACDForm: TCDNonNativeForm);
|
||||
procedure SendFormToBack(ACDForm: TCDNonNativeForm);
|
||||
var
|
||||
lCount, lCurIndex: Integer;
|
||||
begin
|
||||
// Hide the form
|
||||
ACDForm.Visible := False;
|
||||
|
||||
InitNonNativeForms();
|
||||
lCount := NonNativeForms.Count;
|
||||
lCurIndex := NonNativeForms.IndexOf(ACDForm);
|
||||
{$IFDEF VerboseCDForms}
|
||||
DebugLn(Format('HideForm lOldIndex=%d lNewIndex=0', [lCurIndex]));
|
||||
DebugLn(Format('SendFormToBack lOldIndex=%d lNewIndex=0', [lCurIndex]));
|
||||
{$ENDIF}
|
||||
NonNativeForms.Move(lCurIndex, 0);
|
||||
end;
|
||||
|
||||
function FindTopMostVisibleForm: TCDNonNativeForm;
|
||||
var
|
||||
lCount: Integer;
|
||||
lForm: TCDNonNativeForm;
|
||||
i: Integer;
|
||||
begin
|
||||
Result := nil;
|
||||
InitNonNativeForms();
|
||||
// Iterate starting from Count to zero until we find a visible form
|
||||
lCount := NonNativeForms.Count;
|
||||
|
||||
for i := lCount-1 downto 0 do
|
||||
begin
|
||||
lForm := TCDNonNativeForm(NonNativeForms.Items[i]);
|
||||
if lForm.Visible then Exit(lForm);
|
||||
end;
|
||||
end;
|
||||
|
||||
// If AForceUpdate=True then it will update even if the width and height remain the same
|
||||
procedure UpdateControlLazImageAndCanvas(var AImage: TLazIntfImage;
|
||||
var ACanvas: TLazCanvas; AWidth, AHeight: Integer; AFormat: TUpdateLazImageFormat;
|
||||
|
Loading…
Reference in New Issue
Block a user