1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
|
{
/***************************************************************************
GTKINT.pp - GTKInterface Object
-------------------
Initial Revision : Thu July 1st CST 1999
***************************************************************************/
*****************************************************************************
This file is part of the Lazarus Component Library (LCL)
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
}
unit GtkInt;
{$mode objfpc}
{$LONGSTRINGS ON}
interface
{$ifdef Trace}
{$ASSERTIONS ON}
{$endif}
{$I gtkdefines.inc}
uses
{$IFDEF WIN32}
// use windows unit first,
// if not, Rect and Point are taken from the windows unit instead of classes.
Windows,
{$ENDIF}
{$IFDEF UNIX}
// use unix units first,
// if not, TSize is taken from the unix unit instead of types.
ctypes, baseunix, unix,
{$ENDIF}
{$IFDEF TraceGdiCalls}
LineInfo,
{$ENDIF}
// rtl+fcl
Types, Classes, SysUtils,
// LazUtils
FPCAdds, LazUTF8,
// gtk
{$IFDEF gtk2}
glib2, gdk2pixbuf, gdk2, gtk2, Pango, gtk2proc,
{$ifdef HasGdk2X}
gdk2x,
{$endif}
{$ELSE}
glib, gdk, gtk, gdkpixbuf,
{$ENDIF}
// Target OS specific
{$ifdef HasX}
x, xlib,
{$endif}
Math, // after gtk to get the correct Float type
// LCL
LCLPlatformDef, InterfaceBase,
FileUtil, Translations, ExtDlgs, Dialogs, Controls, Forms, LCLStrConsts,
LMessages, LCLProc, LCLIntf, LCLType, DynHashArray, GraphType, GraphMath,
Graphics, Menus, Maps, LazLoggerBase, LazFileUtils, LazStringUtils, Themes,
// widgetset
GtkDebug, GtkFontCache, gtkDef, GtkProc, gtkMsgQueue, GtkExtra, WSLCLClasses;
type
{ TGTKWidgetSet }
TGTKWidgetSet = class(TWidgetSet)
private
FMultiThreadingEnabled: boolean;
FocusTimer: cardinal;
FAppActive: Boolean;
FLastFocusIn: PGtkWidget;
FLastFocusOut: PGtkWidget;
function GetAppActive: Boolean;
procedure SetAppActive(const AValue: Boolean);
protected
FKeyStateList_: TFPList; // Keeps track of which keys are pressed
FDeviceContexts: TDynHashArray;// hasharray of HDC
FGDIObjects: TDynHashArray; // hasharray of PGdiObject
FMessageQueue: TGtkMessageQueue; // queue of PMsg (must be thread safe!)
WaitingForMessages: boolean;
MovedPaintMessageCount: integer;// how many paint messages moved to he end of the queue
FRCFilename: string;
FRCFileParsed: boolean;
FRCFileAge: integer;
FGTKToolTips: PGtkToolTips;
FLogHandlerID: guint; // ID returend by set_handler
FStockNullBrush: HBRUSH;
FStockBlackBrush: HBRUSH;
FStockLtGrayBrush: HBRUSH;
FStockGrayBrush: HBRUSH;
FStockDkGrayBrush: HBRUSH;
FStockWhiteBrush: HBRUSH;
FStockNullPen: HPEN;
FStockBlackPen: HPEN;
FStockWhitePen: HPEN;
FSysColorBrushes: array[0..MAX_SYS_COLORS] of HBrush;
FWaitHandles: PWaitHandleEventHandler;
{$ifdef unix}
FChildSignalHandlers: PChildSignalEventHandler;
{$else}
{$IFDEF VerboseGtkToDos}{$warning no declaration of FChildSignalHandlers for this OS}{$ENDIF}
{$endif}
{$Ifdef GTK2}
FDefaultFontDesc: PPangoFontDescription;
{$Endif}
FDefaultFont: TGtkIntfFont;
FStockSystemFont: HFONT;
FExtUTF8OutCache: Pointer;
FExtUTF8OutCacheSize: integer;
FGlobalCursor: HCursor;
FDCManager: TDeviceContextMemManager;
FDockImage: PGtkWidget;
FDragImageList: PGtkWidget;
FDragImageListIcon: PGtkWidget;
FDragHotStop: TPoint;
function CreateThemeServices: TThemeServices; override;
function GetDeviceContextClass: TGtkDeviceContextClass; virtual; abstract;
public
procedure InitStockItems; virtual;
procedure FreeStockItems; virtual;
procedure InitSystemColors;
procedure InitSystemBrushes; virtual;
procedure FreeSystemBrushes; virtual;
procedure PassCmdLineOptions; override;
{$ifdef Unix}
procedure InitSynchronizeSupport;
procedure ProcessChildSignal;
procedure PrepareSynchronize(AObject: TObject);
{$endif}
procedure HandlePipeEvent(AData: PtrInt; AFlags: dword);
// styles
procedure FreeAllStyles; virtual;
function GetCompStyle(Sender : TObject) : Longint; virtual;
// create and destroy
function CreateAPIWidget(AWinControl: TWinControl): PGtkWidget;
function OldCreateStatusBarPanel(StatusBar: TObject; Index: integer): PGtkWidget;
function CreateSimpleClientAreaWidget(Sender: TObject;
NotOnParentsClientArea: boolean): PGtkWidget;
procedure DestroyEmptySubmenu(Sender: TObject);virtual;
procedure DestroyConnectedWidget(Widget: PGtkWidget;
CheckIfDestroying: boolean);virtual;
function RecreateWnd(Sender: TObject): Integer; virtual;
// clipboard
procedure SetClipboardWidget(TargetWidget: PGtkWidget);virtual;
// device contexts
function IsValidDC(const DC: HDC): Boolean;virtual;
function NewDC: TGtkDeviceContext;virtual;
function FindDCWithGDIObject(GDIObject: PGdiObject): TGtkDeviceContext;virtual;
procedure DisposeDC(aDC: TGtkDeviceContext);virtual;
function CreateDCForWidget(AWidget: PGtkWidget; AWindow: PGdkWindow;
AWithChildWindows: Boolean; ADoubleBuffer: PgdkDrawable = nil): HDC;
function GetDoubleBufferedDC(Handle: HWND): HDC;
// GDIObjects
function IsValidGDIObject(const AGDIObj: HGDIOBJ): Boolean; virtual;
function IsValidGDIObjectType(const GDIObject: HGDIOBJ;
const GDIType: TGDIType): Boolean;virtual;
function NewGDIObject(const GDIType: TGDIType): PGdiObject;virtual;
procedure DisposeGDIObject(GdiObject: PGdiObject);virtual;
function ReleaseGDIObject(GdiObject: PGdiObject): boolean;virtual;
procedure ReferenceGDIObject(GdiObject: PGdiObject);virtual;
function CreateDefaultBrush: PGdiObject;virtual;
function CreateDefaultFont: PGdiObject;virtual;
function CreateDefaultPen: PGdiObject;virtual;
function CreateDefaultGDIBitmap: PGdiObject;virtual;
procedure UpdateDCTextMetric(DC: TGtkDeviceContext); virtual;
{$Ifdef GTK2}
function GetDefaultFontDesc(IncreaseReferenceCount: boolean): PPangoFontDescription;
{$Endif}
function GetDefaultGtkFont(IncreaseReferenceCount: boolean): TGtkIntfFont;
function GetGtkFont(DC: TGtkDeviceContext): TGtkIntfFont;
function CreateRegionCopy(SrcRGN: hRGN): hRGN; override;
function DCClipRegionValid(DC: HDC): boolean; override;
function CreateEmptyRegion: hRGN; override;
// images
procedure LoadPixbufFromLazResource(const ResourceName: string;
var Pixbuf: PGdkPixbuf);
function InternalGetDIBits(DC: HDC; Bitmap: HBitmap; StartScan, NumScans: UINT;
BitSize : Longint; Bits: Pointer; var BitInfo: BitmapInfo; Usage: UINT; DIB : Boolean): Integer;virtual;
function RawImage_DescriptionFromDrawable(out ADesc: TRawImageDescription; ADrawable: PGdkDrawable; ACustomAlpha: Boolean): boolean;
function RawImage_DescriptionFromPixbuf(out ADesc: TRawImageDescription; APixbuf: PGdkPixbuf): boolean;
function RawImage_FromDrawable(out ARawImage: TRawImage; ADrawable, AAlpha: PGdkDrawable; ARect: PRect = nil): boolean;
function RawImage_FromPixbuf(out ARawImage: TRawImage; APixbuf: PGdkPixbuf; ARect: PRect = nil): boolean;
function RawImage_SetAlpha(var ARawImage: TRawImage; AAlpha: PGdkPixmap; ARect: PRect = nil): boolean;
function RawImage_AddMask(var ARawImage: TRawImage; AMask: PGdkBitmap; ARect: PRect = nil): boolean;
function StretchCopyArea(DestDC: HDC; X, Y, Width, Height: Integer;
SrcDC: HDC; XSrc, YSrc, SrcWidth, SrcHeight: Integer;
Mask: HBITMAP; XMask, YMask: Integer;
Rop: Cardinal): Boolean;
// RC file
procedure SetRCFilename(const AValue: string);virtual;
procedure CheckRCFilename;virtual;
procedure ParseRCFile;virtual;
// forms and dialogs
procedure BringFormToFront(Sender: TObject);
procedure UntransientWindow(GtkWindow: PGtkWindow);
// misc
function GetCaption(Sender : TObject) : String; virtual;
procedure WordWrap(DC: HDC; AText: PChar; MaxWidthInPixel: integer;
var Lines: PPChar; var LineCount: integer);
procedure ResizeChild(Sender : TObject; Left,Top,Width,Height : Integer);virtual;
procedure RemoveCallbacks(Widget: PGtkWidget); virtual;
// for gtk specific components:
procedure SetLabelCaption(const ALabel: PGtkLabel; const ACaption: String
{$IFDEF Gtk1}
; const AComponent: TComponent = nil;
const ASignalWidget: PGTKWidget = nil;
const ASignal: PChar = nil{$ENDIF}); virtual; abstract;
procedure SetWidgetColor(const AWidget: PGtkWidget;
const FGColor, BGColor: TColor;
const Mask: tGtkStateEnum);
procedure SetWidgetFont(const AWidget : PGtkWidget;const AFONT : tFont); virtual; abstract;
procedure SetCallbackEx(const AMsg: LongInt; const AGTKObject: PGTKObject;
const ALCLObject: TObject; Direct: boolean); virtual;
procedure SetCallbackDirect(const AMsg: LongInt; const AGTKObject: PGTKObject;
const ALCLObject: TObject);
procedure SetCallback(const AMsg: LongInt; const AGTKObject: PGTKObject;
const ALCLObject: TObject);
procedure SetCommonCallbacks(const AGTKObject: PGTKObject; const ALCLObject: TObject); virtual;
function LCLtoGtkMessagePending: boolean;virtual;
procedure SendCachedGtkMessages;virtual;
// show, hide and invalidate
procedure SetVisible(Sender: TObject; const AVisible: Boolean); virtual;
// Drag ImageLsit
function DragImageList_BeginDrag(APixmap: PGdkPixmap; AMask: PGdkBitmap; AHotSpot: TPoint): Boolean;
procedure DragImageList_EndDrag;
function DragImageList_DragMove(X, Y: Integer): Boolean;
function DragImageList_SetVisible(NewVisible: Boolean): Boolean;
public
function LCLPlatform: TLCLPlatform; override;
// Application
procedure AppInit(var ScreenInfo: TScreenInfo); override;
procedure AppProcessMessages; override;
procedure AppWaitMessage; override;
procedure AppTerminate; override;
procedure AppMinimize; override;
procedure AppRestore; override;
procedure AppBringToFront; override;
procedure AppSetTitle(const ATitle: string); override;
// notebook
procedure AddDummyNoteBookPage(NoteBookWidget: PGtkNoteBook);virtual;
public
constructor Create; override;
destructor Destroy; override;
procedure SendCachedLCLMessages; override;
function DCGetPixel(CanvasHandle: HDC; X, Y: integer): TGraphicsColor; override;
procedure DCSetPixel(CanvasHandle: HDC; X, Y: integer; AColor: TGraphicsColor); override;
procedure DCRedraw(CanvasHandle: HDC); override;
procedure SetDesigning(AComponent: TComponent); override;
// helper routines needed by interface methods
// |-forms
procedure UpdateTransientWindows; virtual;
// |-listbox
procedure SetSelectionMode(Sender: TObject; Widget: PGtkWidget;
MultiSelect, ExtendedSelect: boolean); virtual;
function ForceLineBreaks(DC : hDC; Src: PChar; MaxWidthInPixels : Longint;
ConvertAmpersandsToUnderScores: Boolean) : PChar;
// create and destroy
function CreateTimer(Interval: integer; TimerProc: TWSTimerProc) : TLCLHandle; override;
function DestroyTimer(TimerHandle: TLCLHandle) : boolean; override;
procedure DestroyLCLComponent(Sender: TObject);virtual;
// for gtk controls not part of the LCL:
procedure FinishCreateHandle(const AWinControl: TWinControl; Widget: PGtkWidget; const AParams: TCreateParams);
{$I gtkwinapih.inc}
{$I gtklclintfh.inc}
public
// special methods and properties to track app activation / deactivation
procedure StartFocusTimer;
property AppActive: Boolean read GetAppActive write SetAppActive;
property LastFocusIn: PGtkWidget read FLastFocusIn write FLastFocusIn;
property LastFocusOut: PGtkWidget read FLastFocusOut write FLastFocusOut;
property RCFilename: string read FRCFilename write SetRCFilename;
property MultiThreadingEnabled: boolean read FMultiThreadingEnabled;
end;
{$I gtklistslh.inc}
{$I gtkfiledialogutilsh.inc}
var
GTKWidgetSet: TGTKWidgetSet;
implementation
uses
////////////////////////////////////////////////////
// I M P O R T A N T
////////////////////////////////////////////////////
// To get as little as possible circles,
// uncomment only those units with implementation
////////////////////////////////////////////////////
// GtkWSActnList,
GtkWSButtons,
GtkWSCalendar,
GtkWSCheckLst,
GtkWSComCtrls,
GtkWSControls,
// GtkWSDbCtrls,
// GtkWSDBGrids,
GtkWSDialogs,
// GtkWSEditBtn,
GtkWSExtCtrls,
GtkWSExtDlgs,
// GtkWSFileCtrl,
GtkWSForms,
GtkWSGrids,
// GtkWSImgList,
// GtkWSMaskEdit,
GtkWSMenus,
GtkWSPairSplitter,
GtkWSSpin,
GtkWSStdCtrls,
// GtkWSToolwin,
////////////////////////////////////////////////////
GtkWSPrivate,
GtkThemes,
Buttons, StdCtrls, PairSplitter,
GTKWinApiWindow, ComCtrls, Calendar, Spin,
ExtCtrls, FileCtrl, LResources, gtkglobals,
LazUtilities;
{$I gtklistsl.inc}
{$I gtkfiledialogutils.inc}
{$I gtkwidgetset.inc}
{$I gtkwinapi.inc}
{$I gtklclintf.inc}
procedure InternalInit;
var
c: TClipboardType;
begin
gtk_handler_quark := g_quark_from_static_string('gtk-signal-handlers');
MouseCaptureWidget := nil;
MouseCaptureType := mctGTK;
LastLeft:=EmptyLastMouseClick;
LastMiddle:=EmptyLastMouseClick;
LastRight:=EmptyLastMouseClick;
// clipboard
ClipboardSelectionData:=TFPList.Create;
for c:=Low(TClipboardType) to High(TClipboardType) do begin
ClipboardTypeAtoms[c]:=0;
ClipboardHandler[c]:=nil;
//ClipboardIgnoreLossCount[c]:=0;
ClipboardTargetEntries[c]:=nil;
ClipboardTargetEntryCnt[c]:=0;
end;
// charset encodings
{$IFDEF Gtk1}
SystemCharSetIsUTF8:=not NeedRTLAnsi;
{$ENDIF}
CharSetEncodingList := TList.Create;
CreateDefaultCharsetEncodings;
InitDesignSignalMasks;
end;
procedure InternalFinal;
var i: integer;
ced: PClipboardEventData;
c: TClipboardType;
begin
// clipboard
for i:=0 to ClipboardSelectionData.Count-1 do begin
ced:=PClipboardEventData(ClipboardSelectionData[i]);
if ced^.Data.Data<>nil then FreeMem(ced^.Data.Data);
Dispose(ced);
end;
for c:=Low(TClipboardType) to High(TClipboardType) do
FreeClipboardTargetEntries(c);
ClipboardSelectionData.Free;
ClipboardSelectionData:=nil;
// charset encodings
if CharSetEncodingList<>nil then begin
ClearCharSetEncodings;
CharSetEncodingList.Free;
CharSetEncodingList:=nil;
end;
end;
initialization
{$IFDEF GTK1}
{$I gtkimages.lrs}
{$ENDIF}
InternalInit;
finalization
InternalFinal;
end.
|