From 78187ac487fc992ca02f4d45512b8309c21cf49c Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 30 Mar 2007 05:22:36 +0000 Subject: [PATCH] - added WsWinControl.CanFocus that inform about ability of control to be focused with default widgetset value = True (overrided for gtk) - changed CanTab of TWinControl to use TWSWinControlClass.CanFocus - published TRadioGroup.TabStop git-svn-id: trunk@10829 - --- lcl/extctrls.pp | 1 + lcl/include/customgroupbox.inc | 5 -- lcl/include/wincontrol.inc | 2 +- lcl/interfaces/gtk/gtkproc.inc | 86 +++++++++++++++++++++++++++ lcl/interfaces/gtk/gtkproc.pp | 1 + lcl/interfaces/gtk/gtkwinapi.inc | 90 ----------------------------- lcl/interfaces/gtk/gtkwscontrols.pp | 19 +++++- lcl/stdctrls.pp | 1 - lcl/widgetset/wscontrols.pp | 8 +++ lcl/widgetset/wsstdctrls.pp | 2 +- 10 files changed, 114 insertions(+), 101 deletions(-) diff --git a/lcl/extctrls.pp b/lcl/extctrls.pp index 8377bbdfa8..c3a5e94ef8 100644 --- a/lcl/extctrls.pp +++ b/lcl/extctrls.pp @@ -751,6 +751,7 @@ type property PopupMenu; property ShowHint; property TabOrder; + property TabStop; property Visible; end; diff --git a/lcl/include/customgroupbox.inc b/lcl/include/customgroupbox.inc index 3e3921b80c..a725ead696 100644 --- a/lcl/include/customgroupbox.inc +++ b/lcl/include/customgroupbox.inc @@ -26,9 +26,4 @@ begin Height:= 105; end; -function TCustomGroupBox.CanTab: boolean; -begin - Result:=false; -end; - // included by stdctrls.pp diff --git a/lcl/include/wincontrol.inc b/lcl/include/wincontrol.inc index 5409db725f..db649a013f 100644 --- a/lcl/include/wincontrol.inc +++ b/lcl/include/wincontrol.inc @@ -2184,7 +2184,7 @@ end; ------------------------------------------------------------------------------} Function TWinControl.CanTab: Boolean; begin - Result := CanFocus; + Result := CanFocus and TWSWinControlClass(WidgetSetClass).CanFocus(Self); end; procedure TWinControl.DoDragMsg(var DragMsg: TCMDrag); diff --git a/lcl/interfaces/gtk/gtkproc.inc b/lcl/interfaces/gtk/gtkproc.inc index de22686fa1..2bf9f6a534 100644 --- a/lcl/interfaces/gtk/gtkproc.inc +++ b/lcl/interfaces/gtk/gtkproc.inc @@ -8690,7 +8690,93 @@ begin end; {$ENDIF} +function FindFocusWidget(AWidget: PGtkWidget): PGtkWidget; +var + WinWidgetInfo: PWinWidgetInfo; + ImplWidget: PGtkWidget; + GList: PGlist; + LastFocusWidget: PGtkWidget; +begin + // Default to the widget, try to find other + Result := AWidget; + // Combo + if GtkWidgetIsA(AWidget, gtk_combo_get_type) + then begin + // handle is a gtk combo + {$IfDef VerboseFocus} + DebugLn(' D taking gtkcombo entry'); + {$EndIf} + Result := PgtkWidget(PGtkCombo(AWidget)^.entry); + Exit; + end; + + // check if widget has a WinWidgetInfo record + WinWidgetInfo := GetWidgetInfo(AWidget, false); + if WinWidgetInfo = nil then Exit; + + ImplWidget:= WinWidgetInfo^.CoreWidget; + if ImplWidget = nil then Exit; + // set default to the implementation widget + Result := ImplWidget; + + // handle has an ImplementationWidget + if GtkWidgetIsA(ImplWidget, gtk_list_get_type) + then begin + {$IfDef VerboseFocus} + DebugLn(' E using list'); + {$EndIf} + // Try the last added selected + if not (selection_mode(PGtkList(ImplWidget)^) in [GTK_SELECTION_SINGLE, GTK_SELECTION_BROWSE]) + and (PGtkList(ImplWidget)^.last_focus_child <> nil) + then begin + LastFocusWidget:=PGtkList(ImplWidget)^.last_focus_child; + if g_list_find(PGtkList(ImplWidget)^.selection,LastFocusWidget)<>nil + then begin + Result := PGtkList(ImplWidget)^.last_focus_child; + {$IfDef VerboseFocus} + DebugLn(' E.1 using last_focus_child'); + {$EndIf} + Exit; + end; + end; + + // If there is a selection, try the first + GList := PGtkList(ImplWidget)^.selection; + if (GList <> nil) and (GList^.data <> nil) + then begin + Result := GList^.data; + {$IfDef VerboseFocus} + DebugLn(' E.2 using 1st selection'); + {$EndIf} + Exit; + end; + + // If not in browse mode, set focus to the first child + // in browsemode, the focused item cannot be selected by mouse +// if selection_mode(PGtkList(ImplWidget)^) = GTK_SELECTION_BROWSE +// then begin +// {$IfDef VerboseFocus} +// DebugLn(' E.3 Browse mode -> using ImplWidget'); +// {$EndIf} +// Exit; +// end; + + GList := PGtkList(ImplWidget)^.children; + if GList = nil then Exit; + if GList^.Data = nil then Exit; + Result := GList^.Data; + {$IfDef VerboseFocus} + DebugLn(' E.4 using 1st child'); + {$EndIf} + + Exit; + end; + + {$IfDef VerboseFocus} + DebugLn(' E taking ImplementationWidget'); + {$EndIf} +end; {$IFDEF ASSERT_IS_ON} diff --git a/lcl/interfaces/gtk/gtkproc.pp b/lcl/interfaces/gtk/gtkproc.pp index 455a0eeea5..494e859a23 100644 --- a/lcl/interfaces/gtk/gtkproc.pp +++ b/lcl/interfaces/gtk/gtkproc.pp @@ -789,6 +789,7 @@ function GetGtkContainerBorderWidth(Widget: PGtkContainer): gint; // X functions function FormToX11Window(const AForm: TCustomForm): X.TWindow; {$endif} +function FindFocusWidget(AWidget: PGtkWidget): PGtkWidget; implementation diff --git a/lcl/interfaces/gtk/gtkwinapi.inc b/lcl/interfaces/gtk/gtkwinapi.inc index b098658e6b..e7744bdad3 100644 --- a/lcl/interfaces/gtk/gtkwinapi.inc +++ b/lcl/interfaces/gtk/gtkwinapi.inc @@ -8703,96 +8703,6 @@ end; ------------------------------------------------------------------------------} function TGtkWidgetSet.SetFocus(hWnd: HWND): HWND; {off $DEFINE VerboseFocus} - - - function FindFocusWidget(AWidget: PGtkWidget): PGtkWidget; - var - WinWidgetInfo: PWinWidgetInfo; - ImplWidget: PGtkWidget; - GList: PGlist; - LastFocusWidget: PGtkWidget; - begin - // Default to the widget, try to find other - Result := AWidget; - - // Combo - if GtkWidgetIsA(AWidget, gtk_combo_get_type) - then begin - // handle is a gtk combo - {$IfDef VerboseFocus} - DebugLn(' D taking gtkcombo entry'); - {$EndIf} - Result := PgtkWidget(PGtkCombo(AWidget)^.entry); - Exit; - end; - - // check if widget has a WinWidgetInfo record - WinWidgetInfo := GetWidgetInfo(AWidget, false); - if WinWidgetInfo = nil then Exit; - - ImplWidget:= WinWidgetInfo^.CoreWidget; - if ImplWidget = nil then Exit; - // set default to the implementation widget - Result := ImplWidget; - - // handle has an ImplementationWidget - if GtkWidgetIsA(ImplWidget, gtk_list_get_type) - then begin - {$IfDef VerboseFocus} - DebugLn(' E using list'); - {$EndIf} - // Try the last added selected - if not (selection_mode(PGtkList(ImplWidget)^) in [GTK_SELECTION_SINGLE, GTK_SELECTION_BROWSE]) - and (PGtkList(ImplWidget)^.last_focus_child <> nil) - then begin - LastFocusWidget:=PGtkList(ImplWidget)^.last_focus_child; - if g_list_find(PGtkList(ImplWidget)^.selection,LastFocusWidget)<>nil - then begin - Result := PGtkList(ImplWidget)^.last_focus_child; - {$IfDef VerboseFocus} - DebugLn(' E.1 using last_focus_child'); - {$EndIf} - Exit; - end; - end; - - // If there is a selection, try the first - GList := PGtkList(ImplWidget)^.selection; - if (GList <> nil) and (GList^.data <> nil) - then begin - Result := GList^.data; - {$IfDef VerboseFocus} - DebugLn(' E.2 using 1st selection'); - {$EndIf} - Exit; - end; - - // If not in browse mode, set focus to the first child - // in browsemode, the focused item cannot be selected by mouse -// if selection_mode(PGtkList(ImplWidget)^) = GTK_SELECTION_BROWSE -// then begin -// {$IfDef VerboseFocus} -// DebugLn(' E.3 Browse mode -> using ImplWidget'); -// {$EndIf} -// Exit; -// end; - - GList := PGtkList(ImplWidget)^.children; - if GList = nil then Exit; - if GList^.Data = nil then Exit; - Result := GList^.Data; - {$IfDef VerboseFocus} - DebugLn(' E.4 using 1st child'); - {$EndIf} - - Exit; - end; - - {$IfDef VerboseFocus} - DebugLn(' E taking ImplementationWidget'); - {$EndIf} - end; - var Widget, TopLevel, NewFocusWidget: PGtkWidget; {$IfDef VerboseFocus} diff --git a/lcl/interfaces/gtk/gtkwscontrols.pp b/lcl/interfaces/gtk/gtkwscontrols.pp index 6a0fb7b784..8be68288aa 100644 --- a/lcl/interfaces/gtk/gtkwscontrols.pp +++ b/lcl/interfaces/gtk/gtkwscontrols.pp @@ -72,13 +72,13 @@ type class procedure SetCallbacks(const AGTKObject: PGTKObject; const AComponent: TComponent); public class procedure AddControl(const AControl: TControl); override; - - class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; override; - + class function CanFocus(const AWinControl: TWinControl): Boolean; override; class procedure ConstraintsChange(const AWinControl: TWinControl); override; class procedure DestroyHandle(const AWinControl: TWinControl); override; class procedure Invalidate(const AWinControl: TWinControl); override; + class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; override; + class procedure SetBorderStyle(const AWinControl: TWinControl; const ABorderStyle: TBorderStyle); override; class procedure SetBounds(const AWinControl: TWinControl; const ALeft, ATop, AWidth, AHeight: Integer); override; class procedure SetChildZPosition(const AWinControl, AChild: TWinControl; const AOldPos, ANewPos: Integer; const AChildren: TFPList); override; @@ -188,6 +188,19 @@ begin end; end; +class function TGtkWSWinControl.CanFocus(const AWinControl: TWinControl): Boolean; +var + Widget, FocusWidget: PGtkWidget; +begin + if AWinControl.HandleAllocated then + begin + Widget := PGtkWidget(AWinControl.Handle); + FocusWidget := FindFocusWidget(Widget); + Result := (FocusWidget <> nil) and GTK_WIDGET_CAN_FOCUS(FocusWidget); + end else + Result := False; +end; + class procedure TGtkWSWinControl.ConstraintsChange(const AWinControl: TWinControl); var Widget: PGtkWidget; diff --git a/lcl/stdctrls.pp b/lcl/stdctrls.pp index 695a897adf..768201d3cd 100644 --- a/lcl/stdctrls.pp +++ b/lcl/stdctrls.pp @@ -160,7 +160,6 @@ type protected public constructor Create(AOwner: TComponent); Override; - function CanTab: boolean; override; end; diff --git a/lcl/widgetset/wscontrols.pp b/lcl/widgetset/wscontrols.pp index 677154fc05..6efd49fa64 100644 --- a/lcl/widgetset/wscontrols.pp +++ b/lcl/widgetset/wscontrols.pp @@ -72,6 +72,8 @@ type { TWSWinControl } TWSWinControl = class(TWSControl) + class function CanFocus(const AWincontrol: TWinControl): Boolean; virtual; + class function GetClientBounds(const AWincontrol: TWinControl; var ARect: TRect): Boolean; virtual; class function GetClientRect(const AWincontrol: TWinControl; var ARect: TRect): Boolean; virtual; class procedure GetPreferredSize(const AWinControl: TWinControl; var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); virtual; @@ -147,6 +149,12 @@ class procedure TWSWinControl.DestroyHandle(const AWinControl: TWinControl); begin end; +class function TWSWinControl.CanFocus(const AWincontrol: TWinControl): Boolean; +begin + // lets consider that by deafult all WinControls can be focused + Result := True; +end; + class function TWSWinControl.GetClientBounds(const AWincontrol: TWinControl; var ARect: TRect): Boolean; begin // for now default to the WinAPI version diff --git a/lcl/widgetset/wsstdctrls.pp b/lcl/widgetset/wsstdctrls.pp index 4e6b5b57c9..b007e1c7d2 100644 --- a/lcl/widgetset/wsstdctrls.pp +++ b/lcl/widgetset/wsstdctrls.pp @@ -51,10 +51,10 @@ uses type { TWSScrollBar } - TWSScrollBarClass = class of TWSScrollBar; TWSScrollBar = class(TWSWinControl) class procedure SetParams(const AScrollBar: TCustomScrollBar); virtual; end; + TWSScrollBarClass = class of TWSScrollBar; { TWSCustomGroupBox }