- 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 -
This commit is contained in:
paul 2007-03-30 05:22:36 +00:00
parent c44f23e18d
commit 78187ac487
10 changed files with 114 additions and 101 deletions

View File

@ -751,6 +751,7 @@ type
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
end;

View File

@ -26,9 +26,4 @@ begin
Height:= 105;
end;
function TCustomGroupBox.CanTab: boolean;
begin
Result:=false;
end;
// included by stdctrls.pp

View File

@ -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);

View File

@ -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}

View File

@ -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

View File

@ -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}

View File

@ -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;

View File

@ -160,7 +160,6 @@ type
protected
public
constructor Create(AOwner: TComponent); Override;
function CanTab: boolean; override;
end;

View File

@ -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

View File

@ -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 }