Finishes the basic implementation of dpi and screen rotation adjustment for Android. Not 100% perfect, but in general already functional.

git-svn-id: trunk@34279 -
This commit is contained in:
sekelsenmat 2011-12-19 13:51:13 +00:00
parent 1b32e584ad
commit cc0e04b161
24 changed files with 344 additions and 224 deletions

View File

@ -8,6 +8,7 @@ import android.util.*;
import android.graphics.*;
import android.view.*;
import android.view.inputmethod.InputMethodManager;
import android.content.res.Configuration;
public class LCLActivity extends Activity
{
@ -33,6 +34,13 @@ public class LCLActivity extends Activity
int lWidth = getWidth();
int lHeight = getHeight();
// Check if we rotated in the draw event, OnConfigurationChanged can't return the new form width =(
// see http://stackoverflow.com/questions/2524683/how-to-get-new-width-height-of-root-layout-in-onconfigurationchanged
if (lWidth != lclformwidth) LCLOnConfigurationChanged(lclxdpi, lWidth); // we send xdpi because thats what the LCL uses for Screen.PixelsPerInch
lclformwidth = lWidth;
lclformheight = lHeight;
//Log.v("lclproject", "LCLSurface.onDraw width=" + Integer.toString(lWidth)
// + " height=" + Integer.toString(lHeight));
@ -94,10 +102,35 @@ public class LCLActivity extends Activity
lclsurface = new LCLSurface(this);
setContentView(lclsurface);
lclsurface.postInvalidate();
// Tell the LCL that an OnCreate has happened and what is our instance
lclformwidth = lclsurface.getWidth();
lclformheight = lclsurface.getHeight();
lclscreenwidth = lclformwidth;
lclscreenheight = lclformheight;
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
lclxdpi = (int) metrics.xdpi;
lclydpi = (int) metrics.ydpi;
LCLOnCreate(this);
}
@Override public void onConfigurationChanged (Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
lclformwidth = lclsurface.getWidth();
lclformheight = lclsurface.getHeight();
lclscreenwidth = lclformwidth;
lclscreenheight = lclformheight;
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
lclxdpi = (int) metrics.xdpi;
lclydpi = (int) metrics.ydpi;
// Don't call LCLOnConfigurationChanged, wait for a onDraw instead
lclsurface.postInvalidate();
}
// -------------------------------------------
// JNI table of Pascal functions
// -------------------------------------------
@ -107,6 +140,7 @@ public class LCLActivity extends Activity
public native int LCLOnMessageBoxFinished(int Result);
public native int LCLOnKey(int kind, int keyCode, KeyEvent event, char AChar);
public native int LCLOnTimer(Runnable timerid);
public native int LCLOnConfigurationChanged(int ANewDPI, int ANewWidth);
// -------------------------------------------
// Functions exported to the Pascal side
@ -275,6 +309,13 @@ public class LCLActivity extends Activity
//
public int lcltimerinterval;
public Runnable lcltimerid;
//
public int lclxdpi;
public int lclydpi;
public int lclformwidth;
public int lclformheight;
public int lclscreenwidth;
public int lclscreenheight;
static
{

View File

@ -19,6 +19,7 @@ exports
Java_com_pascal_lclproject_LCLActivity_LCLOnMessageBoxFinished name 'Java_com_pascal_lcltest_LCLActivity_LCLOnMessageBoxFinished',
Java_com_pascal_lclproject_LCLActivity_LCLOnKey name 'Java_com_pascal_lcltest_LCLActivity_LCLOnKey',
Java_com_pascal_lclproject_LCLActivity_LCLOnTimer name 'Java_com_pascal_lcltest_LCLActivity_LCLOnTimer',
Java_com_pascal_lclproject_LCLActivity_LCLOnConfigurationChanged name 'Java_com_pascal_lclproject_LCLActivity_LCLOnConfigurationChanged',
JNI_OnLoad name 'JNI_OnLoad',
JNI_OnUnload name 'JNI_OnUnload';
{$endif}

View File

@ -6,7 +6,7 @@ interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
LCLProc, Arrow, StdCtrls, ComCtrls, LCLType, LCLIntf;
LCLProc, Arrow, StdCtrls, ComCtrls, LCLType, LCLIntf, InterfaceBase;
type
TSubControl = class;
@ -143,6 +143,7 @@ procedure TForm1.Button1Click(Sender: TObject);
begin
DebugLn('Button1Click');
ProgressBar1.Position := ProgressBar1.Position + 10;
// Self.AutoAdjustLayout(lapAutoAdjustWithoutHorizontalScrolling, 96, 150, 220, 600);
end;
procedure TForm1.Button1KeyDown(Sender: TObject; var Key: Word;

View File

@ -134,7 +134,9 @@
<Unit2>
<Filename Value="secondform.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form2"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="secondform"/>
</Unit2>
</Units>

View File

@ -880,14 +880,7 @@ type
chtOnKeyDown
);
TLayoutAdjustmentPolicy = (
lapDefault, // widgetset dependent
lapFixedLayout, // A fixed absolute layout in all platforms
lapAutoAdjustWithoutHorizontalScrolling, // Smartphone platforms use this one,
// the x axis is stretched to fill the screen and
// the y is scaled to fit the DPI
lapAutoAdjustForDPI // For desktops using High DPI, scale x and y to fit the DPI
);
TLayoutAdjustmentPolicy = InterfaceBase.TLayoutAdjustmentPolicy;
{* Note on TControl.Caption
* The VCL implementation relies on the virtual Get/SetTextBuf to
@ -1358,8 +1351,8 @@ type
procedure WriteLayoutDebugReport(const Prefix: string); virtual;
procedure AutoAdjustLayout(AMode: TLayoutAdjustmentPolicy;
const AFromDPI, AToDPI, AOldFormWidth, ANewFormWidth: Integer); virtual;
function ShouldAutoAdjustLayout: Boolean; virtual;
function ShouldAutoAdjustLeftAndTop: Boolean; virtual;
function ShouldAutoAdjustWidthAndHeight: Boolean; virtual;
public
constructor Create(TheOwner: TComponent);override;
destructor Destroy; override;

View File

@ -453,6 +453,7 @@ type
FRestoredHeight: integer;
FShowInTaskbar: TShowInTaskbar;
FWindowState: TWindowState;
FDesignTimeDPI: Integer;
function GetClientHandle: HWND;
function GetEffectiveShowInTaskBar: TShowInTaskBar;
function GetMonitor: TMonitor;
@ -655,6 +656,7 @@ type
property DefaultMonitor: TDefaultMonitor read FDefaultMonitor
write FDefaultMonitor default dmActiveForm;
property Designer: TIDesigner read FDesigner write FDesigner;
property DesignTimeDPI: Integer read FDesignTimeDPI write FDesignTimeDPI;
property FormState: TFormState read FFormState;
property FormStyle: TFormStyle read FFormStyle write SetFormStyle
default fsNormal;

View File

@ -3447,23 +3447,31 @@ procedure TControl.AutoAdjustLayout(AMode: TLayoutAdjustmentPolicy;
var
lXProportion, lYProportion: Double;
NewLeft, NewTop, NewHeight, NewWidth: Integer;
lMode: TLayoutAdjustmentPolicy;
begin
// X-axis adjustment
if AMode = lapAutoAdjustWithoutHorizontalScrolling then
// First resolve ladDefault
lMode := AMode;
if lMode = lapDefault then Widgetset.ResolveDefaultLayoutAdjustmentPolicy(lMode);
// X-axis adjustment proportion
if lMode = lapAutoAdjustWithoutHorizontalScrolling then
begin
lXProportion := ANewFormWidth / AOldFormWidth;
if AOldFormWidth > 0 then lXProportion := ANewFormWidth / AOldFormWidth
else lXProportion := 1.0;
end
else if AMode = lapAutoAdjustForDPI then
else if lMode = lapAutoAdjustForDPI then
begin
lXProportion := AToDPI / AFromDPI;
if AFromDPI > 0 then lXProportion := AToDPI / AFromDPI
else lXProportion := 1.0;
end;
// y-axis adjustment
lYProportion := AToDPI / AFromDPI;
// y-axis adjustment proportion
if AFromDPI > 0 then lYProportion := AToDPI / AFromDPI
else lYProportion := 1.0;
// Apply the changes
if (AMode = lapAutoAdjustWithoutHorizontalScrolling) or
(AMode = lapAutoAdjustForDPI) then
if (lMode = lapAutoAdjustWithoutHorizontalScrolling) or
(lMode = lapAutoAdjustForDPI) then
begin
if ShouldAutoAdjustLeftAndTop then
begin
@ -3475,22 +3483,30 @@ begin
NewLeft := Left;
NewTop := Top;
end;
NewWidth := Round(Width * lXProportion);
NewHeight := Round(Height * lYProportion);
if ShouldAutoAdjustWidthAndHeight then
begin
NewWidth := Round(Width * lXProportion);
NewHeight := Round(Height * lYProportion);
end
else
begin
NewWidth := Width;
NewHeight := Height;
end;
SetBounds(NewLeft, NewTop, NewWidth, NewHeight);
end;
end;
// The layout should only be auto-adjusted for controls with the most simple
// default absolute positioning
function TControl.ShouldAutoAdjustLayout: Boolean;
begin
Result := (Align = alNone) and (Anchors = [akTop, akLeft])
end;
function TControl.ShouldAutoAdjustLeftAndTop: Boolean;
begin
Result := Parent <> nil;
Result := (Align = alNone) and (Anchors = [akTop, akLeft]) and (Parent <> nil);
end;
function TControl.ShouldAutoAdjustWidthAndHeight: Boolean;
begin
Result := AutoSize = False;
end;
procedure TControl.UpdateAnchorRules;

View File

@ -1905,6 +1905,7 @@ begin
FShowInTaskbar := stDefault;
FAlphaBlend := False;
FAlphaBlendValue := 255;
FDesignTimeDPI := 96;
// set border style before handle is allocated
if not (fsBorderStyleChanged in FFormState) then
FFormBorderStyle:= bsSizeable;

View File

@ -1215,6 +1215,11 @@ begin
Result := (Shift = []) and (Key = VK_F1);
end;
procedure TWidgetSet.ResolveDefaultLayoutAdjustmentPolicy(var AMode: TLayoutAdjustmentPolicy);
begin
AMode := lapFixedLayout;
end;
procedure TWidgetSet.InitializeCriticalSection(var CritSection: TCriticalSection);
begin
DebugLn('TWidgetSet.InitializeCriticalSection Not implemented yet');

View File

@ -3780,9 +3780,7 @@ procedure TWinControl.AutoAdjustLayout(AMode: TLayoutAdjustmentPolicy;
var
i: Integer;
begin
// Only auto-adjust self if required, but always auto-adjust child objects
if ShouldAutoAdjustLayout then
inherited AutoAdjustLayout(AMode, AFromDPI, AToDPI, AOldFormWidth, ANewFormWidth);
inherited AutoAdjustLayout(AMode, AFromDPI, AToDPI, AOldFormWidth, ANewFormWidth);
for i:=0 to ControlCount-1 do
Controls[i].AutoAdjustLayout(AMode, AFromDPI, AToDPI, AOldFormWidth, ANewFormWidth);

View File

@ -37,6 +37,16 @@ uses
GraphType, GraphMath, Themes;
type
// Needs to be here to avoid circular unit references
TLayoutAdjustmentPolicy = (
lapDefault, // widgetset dependent
lapFixedLayout, // A fixed absolute layout in all platforms
lapAutoAdjustWithoutHorizontalScrolling, // Smartphone platforms use this one,
// the x axis is stretched to fill the screen and
// the y is scaled to fit the DPI
lapAutoAdjustForDPI // For desktops using High DPI, scale x and y to fit the DPI
);
PEventHandler = type Pointer;
PProcessEventHandler = type Pointer;
PPipeEventHandler = type Pointer;
@ -171,6 +181,8 @@ type
function InitStockFont(AFont: TObject; AStockFont: TStockFont): Boolean; virtual;
function IsHelpKey(Key: Word; Shift: TShiftState): Boolean; virtual;
procedure ResolveDefaultLayoutAdjustmentPolicy(var AMode: TLayoutAdjustmentPolicy); virtual;
// create and destroy
function CreateTimer(Interval: integer; TimerProc: TWSTimerProc): THandle; virtual; abstract;
function DestroyTimer(TimerHandle: THandle): boolean; virtual; abstract;

View File

@ -209,6 +209,8 @@ type
procedure DCSetAntialiasing(CanvasHandle: HDC; AEnabled: Boolean); override;
procedure SetDesigning(AComponent: TComponent); override;
procedure ResolveDefaultLayoutAdjustmentPolicy(var AMode: TLayoutAdjustmentPolicy); virtual;
// create and destroy
function CreateTimer(Interval: integer; TimerFunc: TWSTimerProc): THandle; override;
function DestroyTimer(TimerHandle: THandle): boolean; override;
@ -240,6 +242,8 @@ function Java_com_pascal_lclproject_LCLActivity_LCLOnKey(
AEvent: jobject; AChar: jchar): jint; cdecl;
function Java_com_pascal_lclproject_LCLActivity_LCLOnTimer(
env:PJNIEnv; this:jobject; ATimer: jobject): jint; cdecl;
function Java_com_pascal_lclproject_LCLActivity_LCLOnConfigurationChanged(
env:PJNIEnv; this:jobject; ANewDPI, ANewWidth: jint): jint; cdecl;
function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint; cdecl;
procedure JNI_OnUnload(vm:PJavaVM;reserved:pointer); cdecl;
@ -273,6 +277,13 @@ var
// Timer
javaField_lcltimerinterval: JfieldID=nil;
javaField_lcltimerid: JfieldID=nil;
// Screen Metrics
javaField_lclxdpi: JfieldID=nil;
javaField_lclydpi: JfieldID=nil;
javaField_lclformwidth: JfieldID=nil;
javaField_lclformheight: JfieldID=nil;
javaField_lclscreenwidth: JfieldID=nil;
javaField_lclscreenheight: JfieldID=nil;
// Methods of our Activity
javaMethod_LCLDoGetTextBounds: jmethodid = nil;

View File

@ -254,7 +254,7 @@ end;
MWE: exept for the desktop, there is always a bitmep selected in the DC.
So get this internal bitmap and pass it to RawImage_FromBitmap
------------------------------------------------------------------------------}
function TQtWidgetSet.RawImage_FromDevice(out ARawImage: TRawImage; ADC: HDC; const ARect: TRect): Boolean;
function TCDWidgetSet.RawImage_FromDevice(out ARawImage: TRawImage; ADC: HDC; const ARect: TRect): Boolean;
begin
{$ifdef VerboseCDWinAPI}
DebugLn('Trace:> [WinAPI GetRawImageFromDevice] SrcDC: ', dbghex(ADC),

View File

@ -116,6 +116,7 @@ begin
__android_log_write(ANDROID_LOG_INFO, 'lclapp', 'LCLOnCreate called by LCLActivity.onCreate');
Result := 0;
javaActivityObject := alclactivity;
Screen.UpdateScreen(); // Any values read before LCLOnCreate are wrong
Application.Run;
end;
@ -219,7 +220,25 @@ begin
Result := eventResult;
end;
const NativeMethods: array[0..5] of JNINativeMethod=
function Java_com_pascal_lclproject_LCLActivity_LCLOnConfigurationChanged(
env:PJNIEnv; this:jobject; ANewDPI, ANewWidth: jint): jint; cdecl;
var
lForm: TCDNonNativeForm;
lOldDPI, lNewDPI, lOldFormWidth, lNewFormWidth: Integer;
begin
lForm := GetCurrentForm();
if lForm.LayoutAutoAdjusted then lOldDPI := Screen.PixelsPerInch
else lOldDPI := lForm.LCLForm.DesignTimeDPI;
lNewDPI := ANewDPI;
lOldFormWidth := lForm.LCLForm.Width;
lNewFormWidth := ANewWidth;
DebugLn(Format('[LCLOnConfigurationChanged] lOldDPI=%d lNewDPI=%d lOldFormWidth=%d lNewFormWidth=%d',
[lOldDPI, lNewDPI, lOldFormWidth, lNewFormWidth]));
lForm.LCLForm.AutoAdjustLayout(lapAutoAdjustWithoutHorizontalScrolling,
lOldDPI, lNewDPI, lOldFormWidth, lNewFormWidth);
end;
const NativeMethods: array[0..6] of JNINativeMethod=
((name:'LCLDrawToBitmap';
signature:'(IILandroid/graphics/Bitmap;)I';
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLDrawToBitmap;),
@ -237,7 +256,10 @@ const NativeMethods: array[0..5] of JNINativeMethod=
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnKey;),
(name:'LCLOnTimer';
signature:'(Ljava/lang/Runnable;)I';
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnTimer;)
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnTimer;),
(name:'LCLOnConfigurationChanged';
signature:'(II)I';
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnConfigurationChanged;)
);
function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint; cdecl;
@ -298,6 +320,13 @@ begin
// Timer
javaField_lcltimerinterval := javaEnvRef^^.GetFieldID(javaEnvRef, javaActivityClass, 'lcltimerinterval', 'I');
javaField_lcltimerid := javaEnvRef^^.GetFieldID(javaEnvRef, javaActivityClass, 'lcltimerid', 'Ljava/lang/Runnable;');
// Screen Metrics
javaField_lclxdpi := javaEnvRef^^.GetFieldID(javaEnvRef, javaActivityClass, 'lclxdpi', 'I');
javaField_lclydpi := javaEnvRef^^.GetFieldID(javaEnvRef, javaActivityClass, 'lclydpi', 'I');
javaField_lclformwidth := javaEnvRef^^.GetFieldID(javaEnvRef, javaActivityClass, 'lclformwidth', 'I');
javaField_lclformheight := javaEnvRef^^.GetFieldID(javaEnvRef, javaActivityClass, 'lclformheight', 'I');
javaField_lclscreenwidth := javaEnvRef^^.GetFieldID(javaEnvRef, javaActivityClass, 'lclscreenwidth', 'I');
javaField_lclscreenheight := javaEnvRef^^.GetFieldID(javaEnvRef, javaActivityClass, 'lclscreenheight', 'I');
//
if not assigned(JavaField_lcltext) then
begin
@ -731,6 +760,11 @@ procedure TCDWidgetSet.AppSetMainFormOnTaskBar(const DoSet: Boolean);
begin
end;
procedure TCDWidgetSet.ResolveDefaultLayoutAdjustmentPolicy(var AMode: TLayoutAdjustmentPolicy);
begin
AMode := lapAutoAdjustWithoutHorizontalScrolling;
end;
{------------------------------------------------------------------------------
function: CreateTimer
Params: Interval:

View File

@ -353,6 +353,10 @@ begin
if Assigned(ScreenContext) then ScreenContext.Free;
end;*)
procedure TCDWidgetSet.ResolveDefaultLayoutAdjustmentPolicy(var AMode: TLayoutAdjustmentPolicy);
begin
AMode := lapFixedLayout;
end;
{ TCDAppDelegate }

View File

@ -554,6 +554,11 @@ begin
RecreateWnd(Application.MainForm);
end;
procedure TCDWidgetSet.ResolveDefaultLayoutAdjustmentPolicy(var AMode: TLayoutAdjustmentPolicy);
begin
AMode := lapFixedLayout;
end;
{------------------------------------------------------------------------------
function: CreateTimer
Params: Interval:

View File

@ -439,6 +439,11 @@ procedure TCDWidgetSet.AppSetMainFormOnTaskBar(const DoSet: Boolean);
begin
end;
procedure TCDWidgetSet.ResolveDefaultLayoutAdjustmentPolicy(var AMode: TLayoutAdjustmentPolicy);
begin
AMode := lapFixedLayout;
end;
{------------------------------------------------------------------------------
function: CreateTimer
Params: Interval:

View File

@ -51,6 +51,7 @@ type
//
LastMouseDownControl: TWinControl; // Stores the control which should receive the next MouseUp
FocusedControl: TWinControl; // The control focused in the form
LayoutAutoAdjusted: Boolean; // Indicates if the form layout was already auto-adjusted once
// Counter to keep track of when we requested Invalidate
// Some systems like X11 and Win32 will keep sending unnecessary paint messages
// so for them we just throw the previously painted image

View File

@ -2829,64 +2829,62 @@ begin
OriginDiff.X := Round(QTransform_Dx(Matrix)) - P.X;
OriginDiff.Y := Round(QTransform_Dy(Matrix)) - P.Y;
end;
end;
end;*)
{------------------------------------------------------------------------------
Function: GetDeviceCaps
Params: DC: HDC; Index: Integer
Returns: Integer
------------------------------------------------------------------------------}
function TQtWidgetSet.GetDeviceCaps(DC: HDC; Index: Integer): Integer;
function TCDWidgetSet.GetDeviceCaps(DC: HDC; Index: Integer): Integer;
var
QtDC: TQtDeviceContext;
PaintDevice: QPaintDeviceH;
PaintEngine: QPaintEngineH;
LazDC: TLazCanvas;
begin
{$ifdef VerboseQtWinAPI}
WriteLn('[WinAPI GetDeviceCaps] DC ' + dbghex(DC));
{$ifdef VerboseCDWinAPI}
DebugLn(':>[WinAPI GetDeviceCaps] DC ' + dbghex(DC));
{$endif}
Result := 0;
if DC = 0 then
DC := HDC(QtScreenContext);
if not IsValidDC(DC) then exit;
QtDC := TQtDeviceContext(DC);
PaintEngine := QtDC.PaintEngine;
if PaintEngine = nil then
exit;
PaintDevice := QPaintEngine_paintDevice(PaintEngine);
if DC = 0 then DC := HDC(ScreenDC);
LazDC := TLazCanvas(DC);
case Index of
HORZSIZE:
Result := QPaintDevice_widthMM(PaintDevice);
VERTSIZE:
Result := QPaintDevice_heightMM(PaintDevice);
HORZRES:
Result := QPaintDevice_width(PaintDevice);
BITSPIXEL:
Result := QPaintDevice_depth(PaintDevice);
// HORZSIZE:
// Result := QPaintDevice_widthMM(PaintDevice);
// VERTSIZE:
// Result := QPaintDevice_heightMM(PaintDevice);
// HORZRES:
// Result := QPaintDevice_width(PaintDevice);
// BITSPIXEL:
// Result := QPaintDevice_depth(PaintDevice);
PLANES:
Result := 1;
SIZEPALETTE:
Result := QPaintDevice_numColors(PaintDevice);
// SIZEPALETTE:
// Result := QPaintDevice_numColors(PaintDevice);
LOGPIXELSX:
Result := QPaintDevice_logicalDpiX(PaintDevice);
begin
if javaEnvRef = nil then Exit;
Result := javaEnvRef^^.GetLongField(javaEnvRef, javaActivityObject, javaField_lclxdpi);
end;
LOGPIXELSY:
Result := QPaintDevice_logicalDpiY(PaintDevice);
VERTRES:
Result := QPaintDevice_height(PaintDevice);
begin
if javaEnvRef = nil then Exit;
Result := javaEnvRef^^.GetLongField(javaEnvRef, javaActivityObject, javaField_lclydpi);
end;
// VERTRES:
// Result := QPaintDevice_height(PaintDevice);
NUMRESERVED:
Result := 0;
else
Result := 0;
end;
{$ifdef VerboseCDWinAPI}
DebugLn(':<[WinAPI GetDeviceCaps] Result=' + dbghex(Result));
{$endif}
end;
function TQtWidgetSet.GetDIBits(DC: HDC; Bitmap: HBitmap; StartScan, NumScans: UINT; Bits: Pointer; var BitInfo: BitmapInfo; Usage: UINT): Integer;
(*function TQtWidgetSet.GetDIBits(DC: HDC; Bitmap: HBitmap; StartScan, NumScans: UINT; Bits: Pointer; var BitInfo: BitmapInfo; Usage: UINT): Integer;
begin
Result := 0;
{$ifdef VerboseQtWinAPI_MISSING_IMPLEMENTATION}
@ -3756,7 +3754,7 @@ begin
end
else
Result := FSysColorBrushes[nIndex];
end;
end;*)
{------------------------------------------------------------------------------
Function: GetSystemMetrics
@ -3765,12 +3763,12 @@ end;
------------------------------------------------------------------------------}
function TQtWidgetSet.GetSystemMetrics(nIndex: Integer): Integer;
function TCDWidgetSet.GetSystemMetrics(nIndex: Integer): Integer;
var
R: TRect;
begin
{$ifdef VerboseQtWinAPI}
WriteLn(Format('Trace:> [TQtWidgetSet.GetSystemMetrics] %d', [nIndex]));
{$ifdef VerboseCDWinAPI}
DebugLn(Format(':>[TCDWidgetSet.GetSystemMetrics] nIndex=%d javaEnvRef=%x', [nIndex, PtrInt(javaEnvRef)]));
{$endif}
Result := 0;
case nIndex of
@ -3787,17 +3785,17 @@ begin
{$endif}
end;
SM_CMONITORS:
Result := QDesktopWidget_numScreens(QApplication_desktop());
Result := 1;
SM_CMOUSEBUTTONS:
begin
//DebugLn('Trace:TODO: [TQtWidgetSet.GetSystemMetrics] --> SM_CMOUSEBUTTONS ');
end;
SM_CXBORDER, SM_CYBORDER:
{ SM_CXBORDER, SM_CYBORDER:
begin
// size of frame around controls
Result := QStyle_pixelMetric(QApplication_style(),
QStylePM_DefaultFrameWidth, nil, nil);
end;
end;}
SM_CXCURSOR:
begin
Result := 32; // recomended in docs
@ -3887,14 +3885,14 @@ begin
begin
//DebugLn('Trace:TODO: [TQtWidgetSet.GetSystemMetrics] --> SM_CYMENUCHECK ');
end;
SM_CXMENUSIZE:
{ SM_CXMENUSIZE:
begin
Result := QStyle_pixelMetric(QApplication_style(), QStylePM_IndicatorWidth, nil, nil);
end;
SM_CYMENUSIZE:
begin
Result := QStyle_pixelMetric(QApplication_style(), QStylePM_IndicatorHeight, nil, nil);
end;
end;}
SM_CXMIN:
begin
//DebugLn('Trace:TODO: [TQtWidgetSet.GetSystemMetrics] --> SM_CXMIN ');
@ -3928,15 +3926,19 @@ begin
//DebugLn('Trace:TODO: [TQtWidgetSet.GetSystemMetrics] --> SM_CYMINTRACK ');
end;
SM_CXSCREEN:
begin
QDesktopWidget_screenGeometry(QApplication_desktop(), @R, QDesktopWidget_primaryScreen(QApplication_desktop()));
Result := R.Right - R.Left;
end;
begin
Result := 100; // avoid errors if this is called too early
if javaEnvRef = nil then Exit;
Result := javaEnvRef^^.GetLongField(javaEnvRef, javaActivityObject, javaField_lclscreenwidth);
if Result = 0 then Result := 100;
end;
SM_CYSCREEN:
begin
QDesktopWidget_screenGeometry(QApplication_desktop(), @R, QDesktopWidget_primaryScreen(QApplication_desktop()));
Result := R.Bottom - R.Top;
end;
begin
Result := 100; // avoid errors if this is called too early
if javaEnvRef = nil then Exit;
Result := javaEnvRef^^.GetLongField(javaEnvRef, javaActivityObject, javaField_lclscreenheight);
if Result = 0 then Result := 100;
end;
SM_CXSIZE:
begin
//DebugLn('Trace:TODO: [TQtWidgetSet.GetSystemMetrics] --> SM_CXSIZE ');
@ -3945,11 +3947,11 @@ begin
begin
//DebugLn('Trace:TODO: [TQtWidgetSet.GetSystemMetrics] --> SM_CYSIZE ');
end;
SM_CXSIZEFRAME,
{ SM_CXSIZEFRAME,
SM_CYSIZEFRAME:
begin
Result := QStyle_pixelMetric(QApplication_style(), QStylePM_MDIFrameWidth, nil, nil);
end;
end;}
SM_CXSMICON,
SM_CYSMICON:
begin
@ -3964,24 +3966,26 @@ begin
//DebugLn('Trace:TODO: [TQtWidgetSet.GetSystemMetrics] --> SM_CYSMSIZE ');
end;
SM_CXVIRTUALSCREEN:
begin
Result := QWidget_width(QApplication_desktop);
end;
begin
if javaEnvRef = nil then Exit;
Result := javaEnvRef^^.GetLongField(javaEnvRef, javaActivityObject, javaField_lclscreenwidth);
end;
SM_CYVIRTUALSCREEN:
begin
Result := QWidget_height(QApplication_desktop);
end;
begin
if javaEnvRef = nil then Exit;
Result := javaEnvRef^^.GetLongField(javaEnvRef, javaActivityObject, javaField_lclscreenheight);
end;
SM_CXVSCROLL,
SM_CYVSCROLL,
SM_CXHSCROLL,
SM_CYHSCROLL:
begin
Result := QStyle_pixelMetric(QApplication_Style, QStylePM_ScrollBarExtent, nil, nil);
end;
{ SM_CYHSCROLL:
begin
Result := QStyle_pixelMetric(QApplication_Style, QStylePM_ScrollBarExtent, nil, nil);
end;
SM_CYCAPTION:
begin
Result := QStyle_pixelMetric(QApplication_Style, QStylePM_TitleBarHeight, nil, nil);
end;
begin
Result := QStyle_pixelMetric(QApplication_Style, QStylePM_TitleBarHeight, nil, nil);
end;}
SM_CYKANJIWINDOW:
begin
//DebugLn('Trace:TODO: [TQtWidgetSet.GetSystemMetrics] --> SM_CYKANJIWINDOW ');
@ -4047,33 +4051,10 @@ begin
//DebugLn('Trace:TODO: [TQtWidgetSet.GetSystemMetrics] --> SM_SWAPBUTTON ');
end;
end;
end;
{------------------------------------------------------------------------------
Function: GetTextColor
Params: DC - A device context
Returns: TColorRef
Gets the Font Color currently assigned to the Device Context
------------------------------------------------------------------------------}
function TQtWidgetSet.GetTextColor(DC: HDC) : TColorRef;
var
Color: TQColor;
QtDC: TQtDeviceContext;
begin
{$ifdef VerboseQtWinAPI}
WriteLn('[WinAPI GetTextColor]');
{$ifdef VerboseCDWinAPI}
DebugLn(':<[TCDWidgetSet.GetSystemMetrics] Result=' + dbghex(Result));
{$endif}
Result := 0;
if IsValidDC(DC) then
begin
QtDC := TQtDeviceContext(DC);
ColorRefToTQColor(TColorRef(QtDC.vTextColor), Color);
TQColorToColorRef(Color, Result);
end;
end;*)
end;
{$ifdef CD_UseNativeText}
{------------------------------------------------------------------------------

View File

@ -386,44 +386,52 @@ begin
end;
{$endif}
(*function TCocoaWidgetSet.FillRect(DC: HDC; const Rect: TRect; Brush: HBRUSH): Boolean;
var
ctx : TCocoaContext;
br : TCocoaGDIObject;
begin
ctx:=CheckDC(DC);
br:=CheckGDIOBJ(Brush);
Result:=Assigned(ctx) and (not Assigned(br) or (br is TCocoaBrush));
if not Result then Exit;
with Rect do
ctx.Rectangle(Left, Top, Right, Bottom, True, TCocoaBrush(br));
end;
{------------------------------------------------------------------------------
function ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean;
nCmdShow:
SW_SHOWNORMAL, SW_MINIMIZE, SW_SHOWMAXIMIZED
------------------------------------------------------------------------------}
function TCocoaWidgetSet.ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean;
Function: GetDeviceCaps
Params: DC: HDC; Index: Integer
Returns: Integer
------------------------------------------------------------------------------}
function TCDWidgetSet.GetDeviceCaps(DC: HDC; Index: Integer): Integer;
var
LazDC: TLazCanvas;
begin
{$ifdef VerboseCocoaWinAPI}
DebugLn('TCocoaWidgetSet.ShowWindow');
{$ifdef VerboseCDWinAPI}
DebugLn('[WinAPI GetDeviceCaps] DC ' + dbghex(DC));
{$endif}
case nCmdShow of
SW_SHOW, SW_SHOWNORMAL:
NSWindow(hwnd).orderFront(nil);
SW_HIDE:
NSWindow(hwnd).orderOut(nil);
SW_MINIMIZE:
NSWindow(hwnd).miniaturize(nil);
end;
Result:=true;
Result := 0;
{ if DC = 0 then DC := HDC(ScreenDC);
LazDC := TLazCanvas(DC);
case Index of
// HORZSIZE:
// Result := QPaintDevice_widthMM(PaintDevice);
// VERTSIZE:
// Result := QPaintDevice_heightMM(PaintDevice);
// HORZRES:
// Result := QPaintDevice_width(PaintDevice);
// BITSPIXEL:
// Result := QPaintDevice_depth(PaintDevice);
PLANES:
Result := 1;
// SIZEPALETTE:
// Result := QPaintDevice_numColors(PaintDevice);
LOGPIXELSX:
Result := javaEnvRef^^.GetLongField(javaEnvRef, javaActivityObject, javaField_lclxdpi;
LOGPIXELSY:
Result := javaEnvRef^^.GetLongField(javaEnvRef, javaActivityObject, javaField_lclydpi;
// VERTRES:
// Result := QPaintDevice_height(PaintDevice);
NUMRESERVED:
Result := 0;
else
Result := 0;
end;}
end;
{------------------------------------------------------------------------------
(*{------------------------------------------------------------------------------
Method: GetWindowRect
Params: Handle - Handle of window
Rect - Record for window coordinates
@ -670,50 +678,6 @@ begin
Result:=True;
end;
{------------------------------- SYNC OBJECTS ---------------------------------}
procedure TCocoaWidgetSet.InitializeCriticalSection(var CritSection: TCriticalSection);
begin
CritSection:=TCriticalSection(NSRecursiveLock.alloc);
end;
procedure TCocoaWidgetSet.DeleteCriticalSection(var CritSection: TCriticalSection);
begin
if CritSection=0 then Exit;
NSRecursiveLock(CritSection).release;
CritSection:=0;
end;
procedure TCocoaWidgetSet.EnterCriticalSection(var CritSection: TCriticalSection);
begin
if CritSection=0 then Exit;
NSRecursiveLock(CritSection).lock;
end;
procedure TCocoaWidgetSet.LeaveCriticalSection(var CritSection: TCriticalSection);
begin
if CritSection=0 then Exit;
NSRecursiveLock(CritSection).unlock;
end;
{------------------------------- DEVICE CONTEXT -------------------------------}
function TCDWidgetSet.BackendGetDC(hWnd: HWND): HDC;
{var
lFormHandle: TCDNonNativeForm;}
begin
// lFormHandle := TCDNonNativeForm(hWnd);
Result := 0;
// Screen DC
if hWnd = 0 then Exit;
{ // Form DC
if lFormHandle.Canvas = nil then lFormHandle.Canvas := TLazCanvas.create(nil);
Result := HDC(lFormHandle.Canvas);}
end;
function TCDWidgetSet.MessageBox(hWnd: HWND; lpText, lpCaption: PChar; uType: Cardinal): integer;
begin
Result := 0;
@ -766,6 +730,29 @@ begin
{$ENDIF}
end;
{------------------------------------------------------------------------------
function ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean;
nCmdShow:
SW_SHOWNORMAL, SW_MINIMIZE, SW_SHOWMAXIMIZED
------------------------------------------------------------------------------}
function TCocoaWidgetSet.ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean;
begin
{$ifdef VerboseCocoaWinAPI}
DebugLn('TCocoaWidgetSet.ShowWindow');
{$endif}
case nCmdShow of
SW_SHOW, SW_SHOWNORMAL:
NSWindow(hwnd).orderFront(nil);
SW_HIDE:
NSWindow(hwnd).orderOut(nil);
SW_MINIMIZE:
NSWindow(hwnd).miniaturize(nil);
end;
Result:=true;
end;
function TCocoaWidgetSet.RectVisible(DC: HDC; const ARect: TRect): Boolean;
var
ClipBox: CGRect;

View File

@ -1680,7 +1680,7 @@ begin
DebugLn('Trace:< [WinAPI GetDC] Result: ', dbghex(Result));
{$endif}
end;
begin
*)
{------------------------------------------------------------------------------
Method: GetDeviceCaps
@ -1689,12 +1689,13 @@ begin
Returns device specific information
------------------------------------------------------------------------------}
function TWin32WidgetSet.GetDeviceCaps(DC: HDC; Index: Integer): Integer;
function TCDWidgetSet.GetDeviceCaps(DC: HDC; Index: Integer): Integer;
begin
Result := Windows.GetDeviceCaps(DC, Index);
Result := 0;
if DC = 0 then Result := Windows.GetDeviceCaps(0, Index);
end;
function TWin32WidgetSet.GetDCOriginRelativeToWindow(PaintDC: HDC;
(*function TWin32WidgetSet.GetDCOriginRelativeToWindow(PaintDC: HDC;
WindowHandle: HWND; var OriginDiff: TPoint): boolean;
var
DCOrg, winOrg: Windows.POINT;

View File

@ -2768,7 +2768,7 @@ begin
OriginDiff.X := Round(QTransform_Dx(Matrix)) - P.X;
OriginDiff.Y := Round(QTransform_Dy(Matrix)) - P.Y;
end;
end;
end;*)
{------------------------------------------------------------------------------
Function: GetDeviceCaps
@ -2776,18 +2776,16 @@ end;
Returns: Integer
------------------------------------------------------------------------------}
function TQtWidgetSet.GetDeviceCaps(DC: HDC; Index: Integer): Integer;
function TCDWidgetSet.GetDeviceCaps(DC: HDC; Index: Integer): Integer;
var
QtDC: TQtDeviceContext;
PaintDevice: QPaintDeviceH;
PaintEngine: QPaintEngineH;
LazDC: TLazCanvas;
begin
{$ifdef VerboseQtWinAPI}
WriteLn('[WinAPI GetDeviceCaps] DC ' + dbghex(DC));
{$endif}
Result := 0;
if DC = 0 then
(* if DC = 0 then
DC := HDC(QtScreenContext);
if not IsValidDC(DC) then exit;
@ -2822,10 +2820,10 @@ begin
Result := 0;
else
Result := 0;
end;
end;*)
end;
function TQtWidgetSet.GetDIBits(DC: HDC; Bitmap: HBitmap; StartScan, NumScans: UINT; Bits: Pointer; var BitInfo: BitmapInfo; Usage: UINT): Integer;
(*function TQtWidgetSet.GetDIBits(DC: HDC; Bitmap: HBitmap; StartScan, NumScans: UINT; Bits: Pointer; var BitInfo: BitmapInfo; Usage: UINT): Integer;
begin
Result := 0;
{$ifdef VerboseQtWinAPI_MISSING_IMPLEMENTATION}
@ -3695,7 +3693,7 @@ begin
end
else
Result := FSysColorBrushes[nIndex];
end;
end;*)
{------------------------------------------------------------------------------
Function: GetSystemMetrics
@ -3704,7 +3702,7 @@ end;
------------------------------------------------------------------------------}
function TQtWidgetSet.GetSystemMetrics(nIndex: Integer): Integer;
function TCDWidgetSet.GetSystemMetrics(nIndex: Integer): Integer;
var
R: TRect;
begin
@ -3712,7 +3710,7 @@ begin
WriteLn(Format('Trace:> [TQtWidgetSet.GetSystemMetrics] %d', [nIndex]));
{$endif}
Result := 0;
case nIndex of
(* case nIndex of
SM_ARRANGE:
begin
{$ifdef VerboseQtWinAPI}
@ -3985,10 +3983,10 @@ begin
begin
//DebugLn('Trace:TODO: [TQtWidgetSet.GetSystemMetrics] --> SM_SWAPBUTTON ');
end;
end;
end;*)
end;
{------------------------------------------------------------------------------
(*{------------------------------------------------------------------------------
Function: GetTextColor
Params: DC - A device context
Returns: TColorRef

View File

@ -113,9 +113,9 @@ function GetCmdLineParamDescForInterface: string; override;
function GetCurrentObject(DC: HDC; uObjectType: UINT): HGDIOBJ; override;
function GetCursorPos(var lpPoint: TPoint ): Boolean; override;*)
function GetDC(hWnd: HWND): HDC; override;
(*function GetDCOriginRelativeToWindow(PaintDC: HDC; WindowHandle: HWND; var OriginDiff: TPoint): boolean; override;
//function GetDCOriginRelativeToWindow(PaintDC: HDC; WindowHandle: HWND; var OriginDiff: TPoint): boolean; override;
function GetDeviceCaps(DC: HDC; Index: Integer): Integer; override;
function GetDeviceSize(DC: HDC; var P: TPoint): Boolean; Override;
(*function GetDeviceSize(DC: HDC; var P: TPoint): Boolean; Override;
function GetDIBits(DC: HDC; Bitmap: HBitmap; StartScan, NumScans: UINT; Bits: Pointer; var BitInfo: BitmapInfo; Usage: UINT): Integer; Override;
function GetDoubleClickTime: UINT; override;*)
function GetFocus: HWND; override;
@ -133,8 +133,8 @@ function GetScrollbarVisible(Handle: HWND; SBStyle: Integer): boolean; override;
function GetScrollInfo(Handle: HWND; BarFlag: Integer; Var ScrollInfo: TScrollInfo): Boolean; override;
function GetStockObject(Value: Integer): THandle; override;*)
function GetSysColor(nIndex: Integer): DWORD; override;
(*function GetSysColorBrush(nIndex: Integer): HBrush; override;
function GetSystemMetrics(nIndex: Integer): Integer; override;*)
//function GetSysColorBrush(nIndex: Integer): HBrush; override;
function GetSystemMetrics(nIndex: Integer): Integer; override;
function GetTextColor(DC: HDC) : TColorRef; Override;
function GetTextExtentExPoint(DC: HDC; Str: PChar; Count, MaxWidth: Integer; MaxCount, PartialWidths: PInteger; var Size: TSize): Boolean; override;
function GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean; override;

View File

@ -66,21 +66,42 @@ begin
end;
class procedure TCDWSCustomForm.ShowHide(const AWinControl: TWinControl);
var
lForm: TCDNonNativeForm;
begin
{$ifdef VerboseCDForms}
DebugLn(Format(':>[TCDWSCustomForm.ShowHide] AWinControl=%x Handle=%x',
[PtrInt(AWinControl), PtrInt(AWinControl.Handle)]));
{$endif}
lForm := TCDNonNativeForm(AWinControl.Handle);
if AWinControl.Visible then
begin
{$ifdef VerboseCDForms}
DebugLn(':<[TCDWSCustomForm.ShowHide] Showed');
{$endif}
ShowForm(TCDNonNativeForm(AWinControl.Handle));
ShowForm(lForm);
// if this is the first time we are showing the form adjust its layout
if not lForm.LayoutAutoAdjusted then
begin
DebugLn(Format('[TCDWSCustomForm.ShowHide] First form layout adjustment '
+ 'lOldDPI=%d lNewDPI=%d lOldFormWidth=%d lNewFormWidth=%d',
[lForm.LCLForm.DesignTimeDPI, Screen.PixelsPerInch, lForm.LCLForm.Width, Screen.Width]));
lForm.LayoutAutoAdjusted := True;
lForm.LCLForm.AutoAdjustLayout(lapAutoAdjustWithoutHorizontalScrolling,
lForm.LCLForm.DesignTimeDPI,
Screen.PixelsPerInch, lForm.LCLForm.Width, Screen.Width);
// if necessary adjust the form coordinates
if not (lForm.LCLForm.BorderStyle in [bsDialog, bsNone]) then
begin
lForm.LCLForm.Left := 0;
lForm.LCLForm.Top := 0;
end;
end;
end
else
begin
HideForm(TCDNonNativeForm(AWinControl.Handle));
HideForm(lForm);
{$ifdef VerboseCDForms}
DebugLn(':<[TCDWSCustomForm.ShowHide] Hided');
{$endif}