1
{ $Id: gtk2wsprivate.pp 29456 2011-02-10 22:22:30Z vincents $ }
1
{ $Id: gtk2wsprivate.pp 36862 2012-04-17 07:55:52Z zeljko $ }
3
3
------------------------------------------
4
4
gtk2wsprivate.pp - Gtk2 internal classes
5
5
------------------------------------------
7
7
@created(Thu Feb 1st WET 2007)
8
@lastmod($Date: 2011-02-10 22:22:30 +0000 (Thu, 10 Feb 2011) $)
8
@lastmod($Date: 2012-04-17 09:55:52 +0200 (Tue, 17 Apr 2012) $)
9
9
@author(Marc Weustink <marc@@lazarus.dommelstein.net>)
11
11
This unit contains the private classhierarchy for the gtk implemetations
261
259
function GetWidgetWithWindow(const AHandle: THandle): PGtkWidget;
262
procedure SetWindowCursor(AWindow: PGdkWindow; ACursor: HCursor; ARecursive: Boolean);
263
procedure SetCursorForWindowsWithInfo(AWindow: PGdkWindow; AInfo: PWidgetInfo);
260
procedure SetWindowCursor(AWindow: PGdkWindow; ACursor: HCursor;
261
ARecursive: Boolean; ASetDefault: Boolean);
262
procedure SetCursorForWindowsWithInfo(AWindow: PGdkWindow; AInfo: PWidgetInfo;
263
ASetDefault: Boolean);
264
procedure SetGlobalCursor(Cursor: HCURSOR);
267
271
{$I Gtk2PrivateWidget.inc}
268
272
{$I Gtk2PrivateList.inc}
372
376
{------------------------------------------------------------------------------
373
377
procedure: SetWindowCursor
378
Params: AWindow : PGDkWindow, ACursor: PGdkCursor, ASetDefault: Boolean
381
Sets the cursor for a window.
382
Tries to avoid messing with the cursors of implicitly created
383
child windows (e.g. headers in TListView) with the following logic:
384
- If Cursor <> nil, saves the old cursor (if not already done or ASetDefault = true)
385
before setting the new one.
386
- If Cursor = nil, restores the old cursor (if not already done).
388
Unfortunately gdk_window_get_cursor is only available from
389
version 2.18, so it needs to be retrieved dynamically.
390
If gdk_window_get_cursor is not available, the cursor is set
391
according to LCL widget data.
392
------------------------------------------------------------------------------}
393
procedure SetWindowCursor(AWindow: PGdkWindow; Cursor: PGdkCursor; ASetDefault: Boolean);
395
OldCursor: PGdkCursor;
400
gdk_window_get_user_data(AWindow, @Data);
401
if (Data <> nil) and GTK_IS_WIDGET(Data) then
403
Info := GetWidgetInfo(PGtkWidget(Data), False);
405
if not Assigned(gdk_window_get_cursor) and (Info = nil)
407
if ASetDefault then //and ((Cursor <> nil) or ( <> nil)) then
409
// Override any old default cursor
410
g_object_steal_data(PGObject(AWindow), 'havesavedcursor'); // OK?
411
g_object_steal_data(PGObject(AWindow), 'savedcursor');
412
gdk_window_set_cursor(AWindow, Cursor);
415
if Cursor <> nil then
417
if Assigned(gdk_window_get_cursor)
418
then OldCursor := gdk_window_get_cursor(AWindow)
419
else OldCursor := {%H-}PGdkCursor(Info^.ControlCursor);
420
// As OldCursor can be nil, use a separate key to indicate whether it
422
if ASetDefault or (g_object_get_data(PGObject(AWindow), 'havesavedcursor') = nil) then
424
g_object_set_data(PGObject(AWindow), 'havesavedcursor', gpointer(1));
425
g_object_set_data(PGObject(AWindow), 'savedcursor', gpointer(OldCursor));
427
gdk_pointer_grab(AWindow, False, 0, AWindow, Cursor, 1);
429
gdk_window_set_cursor(AWindow, Cursor);
431
gdk_pointer_ungrab(0);
435
if g_object_steal_data(PGObject(AWindow), 'havesavedcursor') <> nil then
437
Cursor := g_object_steal_data(PGObject(AWindow), 'savedcursor');
438
gdk_window_set_cursor(AWindow, Cursor);
443
{------------------------------------------------------------------------------
444
procedure: SetWindowCursor
374
445
Params: AWindow : PGDkWindow, ACursor: HCursor, ARecursive: Boolean
377
448
Sets the cursor for a window (or recursively for window with children)
378
449
------------------------------------------------------------------------------}
379
procedure SetWindowCursor(AWindow: PGdkWindow; ACursor: HCursor; ARecursive: Boolean);
450
procedure SetWindowCursor(AWindow: PGdkWindow; ACursor: HCursor;
451
ARecursive: Boolean; ASetDefault: Boolean);
381
453
Cursor: PGdkCursor;
453
525
if AInfo = nil then Exit;
454
Cursor := PGdkCursor(AInfo^.ControlCursor);
455
if Cursor = nil then Exit;
526
Cursor := {%H-}PGdkCursor(AInfo^.ControlCursor);
456
527
SetCursorRecursive(AWindow);
530
{------------------------------------------------------------------------------
531
procedure: SetGlobalCursor
532
Params: ACursor: HCursor
535
Sets the cursor for all toplevel windows. Also sets the cursor for all child
536
windows recursively provided gdk_get_window_cursor is available.
537
------------------------------------------------------------------------------}
538
procedure SetGlobalCursor(Cursor: HCURSOR);
540
TopList, List: PGList;
542
TopList := gdk_window_get_toplevels;
546
if (List^.Data <> nil) then
547
SetWindowCursor(PGDKWindow(List^.Data), Cursor,
548
Assigned(gdk_window_get_cursor), False);
549
list := g_list_next(list);
552
if TopList <> nil then
553
g_list_free(TopList);