gtk2 intf: fixed gtk2GrabNotify, added comment

git-svn-id: trunk@37290 -
This commit is contained in:
mattias 2012-05-15 11:41:09 +00:00
parent 7f05ade0fb
commit 3bcdf39bcb
5 changed files with 65 additions and 24 deletions

View File

@ -245,6 +245,7 @@ const
{$ifdef GTK_2_10}
function gdk_screen_is_composited(screen: PGdkScreen): gboolean; cdecl; external gdklib;
{$endif}
function gtk_window_get_group(window:PGtkWindow):PGtkWindowGroup; cdecl; external gtklib;
type
TGtkTreeViewGridLines = cardinal;

View File

@ -4703,6 +4703,21 @@ begin
ReleaseMouseCapture;
end;
function GetGtkWindowGroup(Widget: PGtkWidget): PGtkWindowGroup;
var
toplevel: PGtkWidget;
begin
if Widget<>nil then
toplevel:=gtk_widget_get_toplevel(Widget)
else
toplevel:=nil;
if GTK_IS_WINDOW (toplevel) then
Result:=gtk_window_get_group(GTK_WINDOW(toplevel))
else
Result:=gtk_window_get_group(nil);
end;
{-------------------------------------------------------------------------------
procedure: SignalConnect
Params: AWidget: PGTKWidget

View File

@ -474,6 +474,8 @@ function GetDefaultMouseCaptureWidget(Widget: PGtkWidget): PGtkWidget;
procedure ReleaseMouseCapture;
procedure ReleaseCaptureWidget(Widget : PGtkWidget);
// window group
function GetGtkWindowGroup(Widget: PGtkWidget): PGtkWindowGroup;
const
// for now return the same value, in the future we may want to return an

View File

@ -149,24 +149,28 @@ begin
end;
function gtk2GrabNotify(widget: PGtkWidget; grabbed: GBoolean; {%H-}data: GPointer): GBoolean; cdecl;
// called for all widgets on every gtk_grab_add and gtk_grab_remove
// grabbed = true if called by gtk_grab_remove
// grabbed = false if called by gtk_grab_add
var
W: PGtkWidget;
WidgetInfo: PWidgetInfo;
CurCaptureWidget: PGtkWidget;
begin
{$IFDEF VerboseMouseCapture}
//debugln(['gtk2GrabNotify ',GetWidgetDebugReport(widget),' grabbed=',grabbed,' MouseCaptureWidget=',dbgs(MouseCaptureWidget)]);
{$ENDIF}
Result := CallBackDefaultReturn;
if Grabbed then
begin
w := gtk_grab_get_current;
if MouseCaptureWidget <> nil then
WidgetInfo := GetWidgetInfo(MouseCaptureWidget)
else
WidgetInfo := nil;
if (WidgetInfo <> nil) and (W = MouseCaptureWidget) and (W <> Widget)
and (WidgetInfo^.ClientWidget = nil) then
// grab release
CurCaptureWidget := gtk_grab_get_current;
if (MouseCaptureWidget<>nil)
and ((CurCaptureWidget=nil) or (CurCaptureWidget = MouseCaptureWidget)) then
begin
Result := True;
ReleaseCaptureWidget(W);
{$IFDEF VerboseMouseCapture}
debugln(['gtk2GrabNotify ungrab ',GetWidgetDebugReport(widget),' grabbed=',grabbed,' MouseCaptureWidget=',dbgs(MouseCaptureWidget)]);
{$ENDIF}
//Result := True;
ReleaseCaptureWidget(MouseCaptureWidget);
end;
end;
end;

View File

@ -8278,6 +8278,8 @@ var
CaptureWidget: PGtkWidget;
{$IfDef VerboseMouseCapture}
toplevel: PGtkWidget;
WndGroup: PGtkWindowGroup;
DefWndGroup: PGtkWindowGroup;
{$EndIf}
begin
Widget := {%H-}PGtkWidget(AHandle);
@ -8288,12 +8290,20 @@ begin
// return old capture handle
Result := GetCapture;
if Result <> 0 then begin
if (Result <> 0) then begin
{$IfDef VerboseMouseCapture}
DebugLn('TGtk2WidgetSet.SetCapture gtk_grab_remove=[',GetWidgetDebugReport(gtk_grab_get_current),']');
{$EndIf}
gtk_grab_remove(gtk_grab_get_current);
end;
if (MouseCaptureWidget<>nil) and (gtk_grab_get_current=nil)
and (GTK_WIDGET_HAS_GRAB(MouseCaptureWidget))
then begin
{$IfDef VerboseMouseCapture}
DebugLn('TGtk2WidgetSet.SetCapture gtk_grab_get_current=nil, but GTK_WIDGET_HAS_GRAB(MouseCaptureWidget)=true => gtk_grab_remove=[',GetWidgetDebugReport(MouseCaptureWidget),']');
{$EndIf}
gtk_grab_remove(MouseCaptureWidget);
end;
MouseCaptureWidget := nil;
@ -8312,13 +8322,11 @@ begin
// ToDo: find out how to grab LCLWinapiClient with ubuntu liboverlay
if GtkWidgetIsA(Widget,GTK_TYPE_SCROLLED_WINDOW) then
begin
debugln(['TGtk2WidgetSet.SetCapture AAA1 is api widget ',
debugln(['TGtk2WidgetSet.SetCapture is api widget ',
' widget=',GetWidgetClassName(Widget),
' container.container.focus_child=',GetWidgetClassName(PGtkScrolledWindow(Widget)^.container.container.focus_child),
' container.child=',GetWidgetClassName(PGtkScrolledWindow(Widget)^.container.child),
'']);
debugln(['TGtk2WidgetSet.SetCapture gtk_widget_is_sensitive=',gtk_widget_is_sensitive(CaptureWidget)]);
debugln(['TGtk2WidgetSet.SetCapture gtk_widget_has_grab=',gtk_widget_has_grab (CaptureWidget)]);
//CaptureWidget:=PGtkScrolledWindow(Widget)^.container;
end;
{$EndIf}
@ -8331,18 +8339,29 @@ begin
then begin
debugln(['WARNING: TGtk2WidgetSet.SetCapture capturewidget is offscreen']);
end;
WndGroup := GetGtkWindowGroup(CaptureWidget);
DefWndGroup:=GetGtkWindowGroup(CaptureWidget);
debugln(['TGtk2WidgetSet.SetCapture WndGroup=',dbgs(WndGroup),' DefWndGroup=',dbgs(DefWndGroup),' same=',WndGroup=DefWndGroup]);
// Note: liboverlay: gtk_grab_add sets gtk_widget_has_grab, but gtk_grab_get_current returns nil
// ToDo: check window group
{$EndIf}
gtk_grab_add(CaptureWidget);
{$IfDef VerboseMouseCapture}
if gtk_grab_get_current=CaptureWidget then
DebugLn('TGtk2WidgetSet.SetCapture success gtk_grab_get_current=[',GetWidgetDebugReport(gtk_grab_get_current),']')
else
DebugLn('WARNING: TGtk2WidgetSet.SetCapture failed gtk_grab_get_current=[',GetWidgetDebugReport(gtk_grab_get_current),']');
{$EndIf}
MouseCaptureWidget := CaptureWidget;
gtk_grab_add(CaptureWidget);
if gtk_grab_get_current=CaptureWidget then
begin
{$IfDef VerboseMouseCapture}
DebugLn('TGtk2WidgetSet.SetCapture gtk_grab_add success: gtk_grab_get_current=[',GetWidgetDebugReport(gtk_grab_get_current),']')
{$EndIf}
end
else begin
{$IfDef VerboseMouseCapture}
if gtk_widget_has_grab(CaptureWidget) then
DebugLn('WARNING: TGtk2WidgetSet.SetCapture gtk_grab_add failed (partial success): gtk_grab_get_current=[',GetWidgetDebugReport(gtk_grab_get_current),'] has_grab=true')
else
DebugLn('WARNING: TGtk2WidgetSet.SetCapture gtk_grab_add failed (complete): gtk_grab_get_current=[',GetWidgetDebugReport(gtk_grab_get_current),'] has_grab=false');
{$EndIf}
end;
if MouseCaptureWidget<>nil then
SendMessage(HWnd({%H-}PtrUInt(MouseCaptureWidget)), LM_CAPTURECHANGED, 0, Result);
end;