2
/***************************************************************************
3
CustomDrawnInt.pas - CustomDrawn Interface Object
6
***************************************************************************/
8
*****************************************************************************
10
* This file is part of the Lazarus Component Library (LCL) *
12
* See the file COPYING.modifiedLGPL.txt, included in this distribution, *
13
* for details about the copyright. *
15
* This program is distributed in the hope that it will be useful, *
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
19
*****************************************************************************
26
{$I customdrawndefines.inc}
32
Types, Classes, SysUtils, Math,
33
fpimage, fpcanvas, fpimgcanv, ctypes, dateutils,
37
{$ifdef CD_Windows}Windows, customdrawn_WinProc,{$endif}
38
{$ifdef CD_Cocoa}MacOSAll, CocoaAll, customdrawn_cocoaproc, CocoaGDIObjects,{$endif}
39
{$ifdef CD_X11}X, XLib, XUtil, BaseUnix, customdrawn_x11proc, contnrs,{$ifdef CD_UseNativeText}xft, fontconfig,{$endif}{$endif}
41
customdrawn_androidproc, jni, bitmap, log, keycodes,
43
{$ifdef WinCE}aygshell,{$endif}
46
{$ifndef CD_UseNativeText}
48
LazFreeTypeIntfDrawer, LazFreeType, EasyLazFreeType, IniFiles,
53
customdrawn_common, customdrawncontrols, customdrawndrawers,
54
lazcanvas, lazregions, lazdeviceapis,
56
Controls, Forms, lclproc, IntfGraphics, GraphType,
57
LCLType, LMessages, Graphics, LCLStrConsts, Menus, LazLoggerBase;
61
TWinCETitlePolicy = (tpAlwaysUseOKButton, tpOKButtonOnlyOnDialogs, tpControlWithBorderIcons);
63
PPPipeEventInfo = ^PPipeEventInfo;
64
PPipeEventInfo = ^TPipeEventInfo;
65
TPipeEventInfo = record
76
OnEvent: TWaitHandleEvent;
79
TSocketEvent = function(ASocket: THandle; Flags: dword): Integer of object;
83
TCDTimerObject=objcclass(NSObject)
85
procedure timerEvent; message 'timerEvent';
86
class function initWithFunc(afunc: TWSTimerProc): TCDTimerObject; message 'initWithFunc:';
89
TCDAppDelegate = objcclass(NSObject, NSApplicationDelegateProtocol)
90
function applicationShouldTerminate(sender: NSApplication): NSApplicationTerminateReply; message 'applicationShouldTerminate:';
96
TLazCDCustomFont = class(TFPCustomFont)
98
{$ifndef CD_UseNativeText}
99
FTFont: TFreeTypeFont;
101
constructor Create; override;
102
destructor Destroy; override;
107
TCDWidgetSet = class(TWidgetSet)
109
FTerminating: Boolean;
112
// In win32 it is: The parent of all windows, represents the button of the taskbar
113
// In wince it is just an invisible window, but retains the following functions:
114
// * This window is also the owner of the clipboard.
115
// * Assoc. windowproc also acts as handler for popup menus
116
// * It is indispensable for popupmenus and thread synchronization
119
FMetrics: TNonClientMetrics;
120
FMetricsFailed: Boolean;
122
FStockNullBrush: HBRUSH;
123
FStockBlackBrush: HBRUSH;
124
FStockLtGrayBrush: HBRUSH;
125
FStockGrayBrush: HBRUSH;
126
FStockDkGrayBrush: HBRUSH;
127
FStockWhiteBrush: HBRUSH;
132
FWaitHandleCount: dword;
133
FWaitHandles: array of HANDLE;
134
FWaitHandlers: array of TWaitHandler;
135
FWaitPipeHandlers: PPipeEventInfo;
137
FOnAsyncSocketMsg: TSocketEvent;
139
function WinRegister: Boolean;
140
procedure CreateAppHandle;
144
FDisplayName: string;
147
LeaderWindow: X.TWindow;
148
ClientLeaderAtom: TAtom;
150
FWMProtocols: TAtom; // Atom for "WM_PROTOCOLS"
151
FWMDeleteWindow: TAtom; // Atom for "WM_DELETE_WINDOW"
152
FWMHints: TAtom; // Atom for "_MOTIF_WM_HINTS"
153
FWMPaint: TAtom; // Atom for "WM_PAINT"
155
// For composing character events
156
ComposeBuffer: string;
157
ComposeStatus: TStatus;
158
InputMethod: xlib.PXIM;
160
LastKeySym: TKeySym; // Used for KeyRelease event
161
LastKey: Word; // Used for KeyRelease event
163
ShiftState: TShiftState; // Keeps ShiftState from X
166
XConnections: TFPList;
168
XWindowList: TStringList;
170
// Functions to keep track of windows needing repaint
171
function CheckInvalidateWindowForX(XWIndowID: X.TWindow): Boolean;
172
procedure WindowUpdated(XWIndowID: X.TWindow);
174
function FindWindowByXID(XWindowID: X.TWindow; out AWindowInfo: TX11WindowInfo): TWinControl;
175
procedure AppProcessMessage;
176
procedure AppProcessInvalidates;
177
function XStateToLCLState(XKeyState: cuint): TShiftState;
180
CombiningAccent: Cardinal;
181
{$IFnDEF WithOldDebugln}
182
procedure AndroidDebugLn(ASender: TObject; AStr: string; var AHandled: Boolean;
183
Target: TLazLoggerWriteTarget; Data: Pointer);
185
procedure AndroidDebugLn(AStr: string);
187
function AndroidKeyCodeToLCLKeyCode(AAndroidKeyCode: Integer): Word;
190
pool : NSAutoreleasePool;
191
NSApp : NSApplication;
192
delegate : TCDAppDelegate;
193
ScreenBitmapContext: CGContextRef;
195
// For generic methods added in customdrawn
196
// They are used internally in LCL-CustomDrawn, LCL app should not use them
198
{$ifndef CD_UseNativeText}
200
FFontPaths: TstringList;
201
FFontList: THashedStringList;
202
// default fonts availability
203
LiberationFont: Boolean;
207
DefaultFontSize: Integer;
209
AccumulatedStr: string;
210
// The currently focused control
211
FocusedControl: TWinControl;
212
FocusedIntfControl: TWinControl;
214
DefaultFont: TFPCustomFont;
215
DefaultFontAndroidSize: Integer;
216
// Mobile emulator and mobile mode
217
MobileMainForm: TLCLIntfHandle;
218
// For unusual implementations of DebugLn/DebugOut
219
{$IFnDEF WithOldDebugln}
220
procedure AccumulatingDebugOut(ASender: TObject; AStr: string; var AHandled: Boolean;
221
Target: TLazLoggerWriteTarget; Data: Pointer);
223
procedure AccumulatingDebugOut(AStr: string);
226
procedure CDSetFocusToControl(ALCLControl, AIntfControl: TWinControl);
229
{function CreateThemeServices: TThemeServices; override;}
230
function GetAppHandle: THandle; override; //BackendSpecific
231
//procedure SetAppHandle(const AValue: THandle); override;
233
procedure BackendCreate;
234
procedure BackendDestroy;
236
procedure GenericAppInit;
238
// ScreenDC and Image for doing Canvas operations outside the Paint event
239
// and also for text drawing operations
240
ScreenDC: TLazCanvas;
241
ScreenBitmapRawImage: TRawImage;
242
ScreenBitmapHeight: Integer;
243
ScreenBitmapWidth: Integer;
244
ScreenImage: TLazIntfImage;
246
// Android Activity callbacks
247
ActivityOnCreate: TProcedure;
249
constructor Create; override;
250
destructor Destroy; override;
252
function LCLPlatform: TLCLPlatform; override;
253
function GetLCLCapability(ACapability: TLCLCapability): PtrUInt; override;
255
{ Initialize the API }
256
procedure AppInit(var ScreenInfo: TScreenInfo); override;
257
procedure AppRun(const ALoop: TApplicationMainLoop); override;
258
procedure AppWaitMessage; override;
259
procedure AppProcessMessages; override;
260
procedure AppTerminate; override;
261
procedure AppMinimize; override;
262
procedure AppRestore; override;
263
procedure AppBringToFront; override;
264
procedure AppSetIcon(const Small, Big: HICON); override;
265
procedure AppSetTitle(const ATitle: string); override;
266
procedure AppSetVisible(const AVisible: Boolean); override;
267
function AppRemoveStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; override;
268
function AppRestoreStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; override;
269
procedure AppSetMainFormOnTaskBar(const DoSet: Boolean); override;
271
//function InitStockFont(AFont: TObject; AStockFont: TStockFont): Boolean; override;
273
procedure DCSetPixel(CanvasHandle: HDC; X, Y: integer; AColor: TGraphicsColor); override;
274
function DCGetPixel(CanvasHandle: HDC; X, Y: integer): TGraphicsColor; override;
275
procedure DCRedraw(CanvasHandle: HDC); override;
276
procedure DCSetAntialiasing(CanvasHandle: HDC; AEnabled: Boolean); override;
277
procedure SetDesigning(AComponent: TComponent); override;
279
// create and destroy
280
function CreateTimer(Interval: integer; TimerFunc: TWSTimerProc): THandle; override;
281
function DestroyTimer(TimerHandle: THandle): boolean; override;
283
{$I customdrawnwinapih.inc}
284
{$I customdrawnlclintfh.inc}
286
{ Variables to be set by the user }
288
WinCETitlePolicy: TWinCETitlePolicy;
293
CDWidgetSet: TCDWidgetSet absolute WidgetSet;
295
function CDMessageBoxFunction(Text, Caption : PChar; Flags : Longint) : Integer;
298
function WindowProc(Window: HWnd; Msg: UInt; WParam: Windows.WParam;
299
LParam: Windows.LParam): LResult; {$ifdef WinCE}cdecl;{$else}stdcall;{$endif}
302
procedure MyXConnectionWatchProc(display: PDisplay; client_data: TXPointer;
303
fd: cint; opening: XLib.TBool; watch_data: PXPointer); cdecl;
306
function Java_com_pascal_lclproject_LCLActivity_LCLOnTouch(env:PJNIEnv;this:jobject; x, y: single; action: jint): jint; cdecl;
307
function Java_com_pascal_lclproject_LCLActivity_LCLDrawToBitmap(
308
env:PJNIEnv;this:jobject; width, height: jint; abitmap: jobject): jint; cdecl;
309
function Java_com_pascal_lclproject_LCLActivity_LCLOnCreate(
310
env:PJNIEnv; this:jobject; alclactivity: jobject): jint; cdecl;
311
function Java_com_pascal_lclproject_LCLActivity_LCLOnMessageBoxFinished(
312
env:PJNIEnv; this:jobject; AResult, ADialogType: jint): jint; cdecl;
313
function Java_com_pascal_lclproject_LCLActivity_LCLOnKey(
314
env:PJNIEnv; this:jobject; AKind: jint; AKeyCode: jint;
315
AEvent: jobject; AChar: jint): jint; cdecl;
316
function Java_com_pascal_lclproject_LCLActivity_LCLOnTimer(
317
env:PJNIEnv; this:jobject; ATimer: jobject): jint; cdecl;
318
function Java_com_pascal_lclproject_LCLActivity_LCLOnConfigurationChanged(
319
env:PJNIEnv; this:jobject; ANewDPI, ANewWidth: jint): jint; cdecl;
320
function Java_com_pascal_lclproject_LCLActivity_LCLOnSensorChanged(
321
env:PJNIEnv; this:jobject; ASensorKind: jint; AValues: JDoubleArray): jint; cdecl;
322
function Java_com_pascal_lclproject_LCLActivity_LCLOnMenuAction(
323
env:PJNIEnv; this:jobject; kind, itemIndex: jint): jint; cdecl;
324
function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint; cdecl;
325
procedure JNI_OnUnload(vm:PJavaVM;reserved:pointer); cdecl;
328
javaVMRef: PJavaVM=nil;
329
javaEnvRef: PJNIEnv=nil;
330
javaActivityClass: JClass = nil;
331
javaActivityObject: jobject = nil;
333
// Other classes and objects
334
javaAndroidAppActivityClass: JClass = nil;
335
javaJavaLangSystemClass: JClass = nil;
336
javaAndroidOSBuildClass: JClass = nil;
337
javaAndroidOSVibratorClass: JClass = nil;
338
javaAndroidContentContextClass: JClass = nil;
339
javaJavaLangStringClass: JClass = nil;
341
// Fields of our Activity
343
javaField_lcltext: JfieldID=nil;
344
javaField_lcltitle: JfieldID=nil;
345
javaField_lclbutton1str: JfieldID=nil;
346
javaField_lclbutton2str: JfieldID=nil;
347
javaField_lclbutton3str: JfieldID=nil;
349
javaField_lclwidth: JfieldID=nil;
350
javaField_lclheight: JfieldID=nil;
351
javaField_lclbutton1: JfieldID=nil;
352
javaField_lclbutton2: JfieldID=nil;
353
javaField_lclbutton3: JfieldID=nil;
354
javaField_lclbitmap: JfieldID=nil;
355
javaField_lcltextsize: JfieldID=nil;
357
javaField_lcltextascent: JfieldID=nil;
358
javaField_lcltextbottom: JfieldID=nil;
359
javaField_lcltextdescent: JfieldID=nil;
360
javaField_lcltextleading: JfieldID=nil;
361
javaField_lcltexttop: JfieldID=nil;
362
javaField_lclmaxwidth: JfieldID=nil;
363
javaField_lclmaxcount: JfieldID=nil;
364
javaField_lclpartialwidths: JfieldID=nil;
366
javaField_lcltimerinterval: JfieldID=nil;
367
javaField_lcltimerid: JfieldID=nil;
369
javaField_lclxdpi: JfieldID=nil;
370
javaField_lclydpi: JfieldID=nil;
371
javaField_lclformwidth: JfieldID=nil;
372
javaField_lclformheight: JfieldID=nil;
373
javaField_lclscreenwidth: JfieldID=nil;
374
javaField_lclscreenheight: JfieldID=nil;
376
javaField_lcldestination: JfieldID=nil;
377
javaField_lclkind: JfieldID=nil;
379
// Methods of our Activity
380
javaMethod_LCLDoGetTextBounds: jmethodid = nil;
381
javaMethod_LCLDoGetTextPartialWidths: jmethodid = nil;
382
javaMethod_LCLDoDrawText: jmethodid = nil;
383
javaMethod_LCLDoShowMessageBox: jmethodid = nil;
384
javaMethod_LCLDoCreateTimer: jmethodid = nil;
385
javaMethod_LCLDoDestroyTimer: jmethodid = nil;
386
javaMethod_LCLDoHideVirtualKeyboard: jmethodid = nil;
387
javaMethod_LCLDoShowVirtualKeyboard: jmethodid = nil;
388
javaMethod_LCLDoStartReadingAccelerometer: jmethodid = nil;
389
javaMethod_LCLDoStopReadingAccelerometer: jmethodid = nil;
390
javaMethod_LCLDoSendMessage: jmethodid = nil;
391
javaMethod_LCLDoRequestPositionInfo: jmethodid = nil;
392
// Methods from android.app.Activity
393
javaMethod_Activity_finish: jmethodid = nil;
394
// Methods from java.lang.System
395
javaMethod_System_exit: jmethodid = nil;
396
// Generic methods from Context
397
javaMethod_getSystemService: jmethodid = nil;
399
// This is utilized to store the information such as invalidate requests in events
407
CustomDrawnWSFactory,
414
////////////////////////////////////////////////////
421
CDBackendNativeHandle = nhtWindowsHWND;
422
{$define CD_HasNativeFormHandle}
426
CDBackendNativeHandle = nhtX11TWindow;
428
{$define CD_HasNativeFormHandle}
432
CDBackendNativeHandle = nhtCocoaNSWindow;
433
{$define CD_HasNativeFormHandle}
438
constructor TLazCDCustomFont.Create;
441
{$ifndef CD_UseNativeText}
442
FTFont := TFreeTypeFont.Create;
446
destructor TLazCDCustomFont.Destroy;
448
{$ifndef CD_UseNativeText}
454
{$I customdrawnobject.inc}
456
{$I customdrawnwinapi.inc}
457
{$I customdrawnlclintf.inc}
460
{$include wincallback.inc}
461
{$I customdrawnobject_win.inc}
462
{$I customdrawnwinapi_win.inc}
463
{$I customdrawnlclintf_win.inc}
466
{$I customdrawnobject_cocoa.inc}
467
{$I customdrawnwinapi_cocoa.inc}
468
{$I customdrawnlclintf_cocoa.inc}
471
{$I customdrawnobject_x11.inc}
472
{$I customdrawnwinapi_x11.inc}
473
{$I customdrawnlclintf_x11.inc}
476
{$I customdrawnobject_android.inc}
477
{$I customdrawnwinapi_android.inc}
478
{$I customdrawnlclintf_android.inc}