mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-01 06:01:51 +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
@ -53,7 +53,10 @@ public class LCLActivity extends Activity
|
|||||||
{
|
{
|
||||||
int eventResult = LCLOnKey(KeyEvent.ACTION_UP, keyCode, event, event.getDisplayLabel());
|
int eventResult = LCLOnKey(KeyEvent.ACTION_UP, keyCode, event, event.getDisplayLabel());
|
||||||
if ((eventResult | 1) != 0) postInvalidate();
|
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)
|
@Override public boolean onTouchEvent (MotionEvent event)
|
||||||
|
@ -127,6 +127,7 @@ begin
|
|||||||
Application.Run;
|
Application.Run;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// This one is for all simple dialogs: MessageBox, PromptUser (MessageDlg) and AskUser
|
||||||
function Java_com_pascal_lclproject_LCLActivity_LCLOnMessageBoxFinished(
|
function Java_com_pascal_lclproject_LCLActivity_LCLOnMessageBoxFinished(
|
||||||
env:PJNIEnv; this:jobject; AResult: jint): jint; cdecl;
|
env:PJNIEnv; this:jobject; AResult: jint): jint; cdecl;
|
||||||
begin
|
begin
|
||||||
@ -146,6 +147,7 @@ var
|
|||||||
AWideText: widestring;
|
AWideText: widestring;
|
||||||
AUTF8Text: string;
|
AUTF8Text: string;
|
||||||
AUTF8Char: TUTF8Char;
|
AUTF8Char: TUTF8Char;
|
||||||
|
lForm: TCDNonNativeForm;
|
||||||
begin
|
begin
|
||||||
{$ifdef VerboseCDEvents}
|
{$ifdef VerboseCDEvents}
|
||||||
__android_log_write(ANDROID_LOG_INFO,'lclapp',PChar(
|
__android_log_write(ANDROID_LOG_INFO,'lclapp',PChar(
|
||||||
@ -174,6 +176,17 @@ begin
|
|||||||
AUTF8Char := AUTF8Text;
|
AUTF8Char := AUTF8Text;
|
||||||
LCLSendUTF8KeyPress(lTarget, AUTF8Char, False);
|
LCLSendUTF8KeyPress(lTarget, AUTF8Char, False);
|
||||||
end;
|
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;
|
end;
|
||||||
//ACTION_MULTIPLE:
|
//ACTION_MULTIPLE:
|
||||||
end;
|
end;
|
||||||
|
@ -13,7 +13,7 @@ uses
|
|||||||
// LCL
|
// LCL
|
||||||
GraphType, Controls, LCLMessageGlue, WSControls, LCLType, LCLProc,
|
GraphType, Controls, LCLMessageGlue, WSControls, LCLType, LCLProc,
|
||||||
StdCtrls, ExtCtrls, Forms, Graphics, customdrawncontrols,
|
StdCtrls, ExtCtrls, Forms, Graphics, customdrawncontrols,
|
||||||
InterfaceBase;
|
InterfaceBase, LCLIntf;
|
||||||
|
|
||||||
type
|
type
|
||||||
TUpdateLazImageFormat = (
|
TUpdateLazImageFormat = (
|
||||||
@ -64,6 +64,7 @@ type
|
|||||||
|
|
||||||
TCDNonNativeForm = class(TCDForm)
|
TCDNonNativeForm = class(TCDForm)
|
||||||
public
|
public
|
||||||
|
Visible: Boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TCDBitmap = class
|
TCDBitmap = class
|
||||||
@ -83,6 +84,7 @@ type
|
|||||||
procedure AddCDWinControlToForm(const AForm: TCustomForm; ACDWinControl: TCDWinControl);
|
procedure AddCDWinControlToForm(const AForm: TCustomForm; ACDWinControl: TCDWinControl);
|
||||||
function GetCDWinControlList(const AForm: TCustomForm): TFPList;
|
function GetCDWinControlList(const AForm: TCustomForm): TFPList;
|
||||||
|
|
||||||
|
// Routines for non-native form managing
|
||||||
procedure InitNonNativeForms();
|
procedure InitNonNativeForms();
|
||||||
function GetCurrentForm(): TCDNonNativeForm;
|
function GetCurrentForm(): TCDNonNativeForm;
|
||||||
function AddNewForm(AForm: TCustomForm): TCDNonNativeForm;
|
function AddNewForm(AForm: TCustomForm): TCDNonNativeForm;
|
||||||
@ -90,6 +92,9 @@ procedure AddFormWithCDHandle(AHandle: TCDForm);
|
|||||||
function FindFormWithNativeHandle(AHandle: HWND): TCDForm;
|
function FindFormWithNativeHandle(AHandle: HWND): TCDForm;
|
||||||
procedure ShowForm(ACDForm: TCDNonNativeForm);
|
procedure ShowForm(ACDForm: TCDNonNativeForm);
|
||||||
procedure HideForm(ACDForm: TCDNonNativeForm);
|
procedure HideForm(ACDForm: TCDNonNativeForm);
|
||||||
|
procedure BringFormToFront(ACDForm: TCDNonNativeForm);
|
||||||
|
procedure SendFormToBack(ACDForm: TCDNonNativeForm);
|
||||||
|
function FindTopMostVisibleForm: TCDNonNativeForm;
|
||||||
|
|
||||||
// Routines for non-native wincontrol
|
// Routines for non-native wincontrol
|
||||||
|
|
||||||
@ -131,6 +136,7 @@ implementation
|
|||||||
var
|
var
|
||||||
// List with the Z-order of non-native forms, index=0 is the bottom-most form
|
// List with the Z-order of non-native forms, index=0 is the bottom-most form
|
||||||
NonNativeForms: TFPList = nil;
|
NonNativeForms: TFPList = nil;
|
||||||
|
lCurrentForm: TCDNonNativeForm = nil;
|
||||||
|
|
||||||
// List of timers
|
// List of timers
|
||||||
TimersList: TFPList = nil;
|
TimersList: TFPList = nil;
|
||||||
@ -160,16 +166,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function GetCurrentForm(): TCDNonNativeForm;
|
function GetCurrentForm(): TCDNonNativeForm;
|
||||||
var
|
|
||||||
lCount: Integer;
|
|
||||||
begin
|
begin
|
||||||
{$IFDEF VerboseCDForms}
|
{$IFDEF VerboseCDForms}
|
||||||
DebugLn('GetCurrentForm');
|
DebugLn('GetCurrentForm');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
InitNonNativeForms();
|
Result := lCurrentForm;
|
||||||
lCount := NonNativeForms.Count;
|
|
||||||
if lCount = 0 then Result := nil
|
|
||||||
else Result := TCDNonNativeForm(NonNativeForms.Items[lCount-1]);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function AddNewForm(AForm: TCustomForm): TCDNonNativeForm;
|
function AddNewForm(AForm: TCustomForm): TCDNonNativeForm;
|
||||||
@ -211,6 +212,24 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure ShowForm(ACDForm: TCDNonNativeForm);
|
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
|
var
|
||||||
lCount, lCurIndex: Integer;
|
lCount, lCurIndex: Integer;
|
||||||
begin
|
begin
|
||||||
@ -218,24 +237,45 @@ begin
|
|||||||
lCount := NonNativeForms.Count;
|
lCount := NonNativeForms.Count;
|
||||||
lCurIndex := NonNativeForms.IndexOf(ACDForm);
|
lCurIndex := NonNativeForms.IndexOf(ACDForm);
|
||||||
{$IFDEF VerboseCDForms}
|
{$IFDEF VerboseCDForms}
|
||||||
DebugLn(Format('ShowForm lOldIndex=%d lNewIndex=%d', [lCurIndex, lCount-1]));
|
DebugLn(Format('BringFormToFront lOldIndex=%d lNewIndex=%d', [lCurIndex, lCount-1]));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
NonNativeForms.Move(lCurIndex, lCount-1);
|
NonNativeForms.Move(lCurIndex, lCount-1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure HideForm(ACDForm: TCDNonNativeForm);
|
procedure SendFormToBack(ACDForm: TCDNonNativeForm);
|
||||||
var
|
var
|
||||||
lCount, lCurIndex: Integer;
|
lCount, lCurIndex: Integer;
|
||||||
begin
|
begin
|
||||||
|
// Hide the form
|
||||||
|
ACDForm.Visible := False;
|
||||||
|
|
||||||
InitNonNativeForms();
|
InitNonNativeForms();
|
||||||
lCount := NonNativeForms.Count;
|
lCount := NonNativeForms.Count;
|
||||||
lCurIndex := NonNativeForms.IndexOf(ACDForm);
|
lCurIndex := NonNativeForms.IndexOf(ACDForm);
|
||||||
{$IFDEF VerboseCDForms}
|
{$IFDEF VerboseCDForms}
|
||||||
DebugLn(Format('HideForm lOldIndex=%d lNewIndex=0', [lCurIndex]));
|
DebugLn(Format('SendFormToBack lOldIndex=%d lNewIndex=0', [lCurIndex]));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
NonNativeForms.Move(lCurIndex, 0);
|
NonNativeForms.Move(lCurIndex, 0);
|
||||||
end;
|
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
|
// If AForceUpdate=True then it will update even if the width and height remain the same
|
||||||
procedure UpdateControlLazImageAndCanvas(var AImage: TLazIntfImage;
|
procedure UpdateControlLazImageAndCanvas(var AImage: TLazIntfImage;
|
||||||
var ACanvas: TLazCanvas; AWidth, AHeight: Integer; AFormat: TUpdateLazImageFormat;
|
var ACanvas: TLazCanvas; AWidth, AHeight: Integer; AFormat: TUpdateLazImageFormat;
|
||||||
|
Loading…
Reference in New Issue
Block a user