Registriert seit: 26. Nov 2003
Ort: Halle/Saale
4.343 Beiträge
Delphi 11 Alexandria
|
AW: FireMonkey Sammelthread
4. Mai 2013, 16:36
Eigentlich müssten nur "focused handler" und "change focus" getauscht werden.
Dann könnte man Key auf 0 setzen wenn man vkTab selbst behandeln will.
Wenn das in XE4 noch nicht geändert ist werde ich mal einen QC-Eintrag schreiben.
Delphi-Quellcode:
procedure TCommonCustomForm.KeyDown(var Key: Word; var KeyChar: System.WideChar; Shift: TShiftState);
var
List: TInterfaceList;
i, CurIdx: Integer;
TabDirection : Integer;
FocusObj: TFmxObject;
Done: boolean;
FocusPopup: TCustomPopupMenu;
lIsDialog: boolean;
NewFocus: IControl;
procedure TraverseChildren(Container: TFmxObject);
var I: integer;
begin
if (Container is TControl) and
(not TControl(Container).Enabled) then Exit;
for I := 0 to Container.ComponentCount - 1 do
if (Container.Components[I] is TCustomActionList) and
(TCustomActionList(Container.Components[I]).DialogKey(Key, Shift)) then
begin
Done := True;
Exit;
end;
if (Container.ChildrenCount > 0) then
for I := 0 to Container.ChildrenCount - 1 do
begin
TraverseChildren(Container.Children[I]);
if Done then
Exit;
end;
end;
procedure OtherForms(IsMain: boolean);
var I, J: integer;
F: TCommonCustomForm;
begin
if Done then Exit;
for I := 0 to Screen.FormCount - 1 do
if (Screen.Forms[I] <> self) and
(Screen.Forms[I].Visible) and
(IsMain xor (Screen.Forms[I] <> Application.MainForm)) then
begin
F := Screen.Forms[I];
for J := F.ChildrenCount - 1 downto 0 do
begin
if F.Children[J] is TMainMenu then
TMainMenu(F.Children[J]).DialogKey(Key, Shift);
if Key = 0 then
begin
Done := True;
Exit;
end;
end;
TraverseChildren(F);
if Done then Exit;
end;
end;
begin
{ dialog key }
FocusPopup := nil;
lIsDialog := False;
IsDialogKey(Key, KeyChar, Shift, lIsDialog);
try
if lIsDialog then
begin
Done := False;
// 1. perform key in Focus Control
if Assigned(FFocused) then
begin
FFocused.DialogKey(Key, Shift);
if Key = 0 then
Exit;
FocusObj := FFocused.GetObject;
end
else
FocusObj := nil;
// 2. perform key in PopupMenu of Focus Control
if (FocusObj is TControl) then
begin
FocusPopup := TControl(FocusObj).PopupMenu;
if FocusPopup is TPopupMenu then
begin
TPopupMenu(FocusPopup).DialogKey(Key, Shift);
if Key = 0 then
Exit;
end
else
FocusPopup := nil;
end;
// 3. perform key in other Menus
for i := ChildrenCount - 1 downto 0 do
if Children[i] <> FocusPopup then
begin
if Children[i] is TMainMenu then
TMainMenu(Children[i]).DialogKey(Key, Shift)
else if Children[i] is TPopupMenu then
TPopupMenu(Children[i]).DialogKey(Key, Shift);
if Key = 0 then
Exit;
end;
// 4. perform key in other, no focus controls
for i := ChildrenCount - 1 downto 0 do
if Children[i] <> FocusObj then
begin
if Children[i].IsIControl then
Children[i].AsIControl.DialogKey(Key, Shift);
if Key = 0 then
Exit;
end;
// 5. perform key in all ActionLists in Childrens
TraverseChildren(self);
// 6. perform key in all main menus and ActionLists in other forms
OtherForms(True);
OtherForms(False);
if Done then Exit;
end;
{ change focus } // DANN DAS ******************************************************
if (Key = vkTab) then
begin
NewFocus := nil;
Key := 0;
List := TInterfaceList.Create;
try
GetTabOrderList(List, True);
if ssShift in Shift then
TabDirection := -1
else
TabDirection := 1;
CurIdx := List.IndexOf(FFocused);
for i := 0 to List.Count-1 do
begin
Inc(CurIdx, TabDirection);
if (TabDirection > 0) and (CurIdx >= List.Count) then
CurIdx := 0
else
if (TabDirection < 0) and (CurIdx < 0) then
CurIdx := List.Count - 1;
if IControl(List[CurIdx]).CheckForAllowFocus then
begin
NewFocus := IControl(List[CurIdx]);
break;
end;
end;
finally
FreeAndNil(List);
end;
if Assigned(NewFocus) then
NewFocus.SetFocus;
Exit;
end;
{ focused handler } // ERST DAS *****************************************************
if ((Key <> 0) or (KeyChar <> #0)) then
begin
if Assigned(FFocused) then
FFocused.KeyDown(Key, KeyChar, Shift);
if Assigned(FOnKeyDown) then
FOnKeyDown(Self, Key, KeyChar, Shift);
end;
finally
Application.FLastKeyPress := Now;
Application.FLastUserActive := Application.FLastKeyPress;
end;
end;
|
|
Zitat
|