carbon: implement keyboard processing before menu fire event (LCL compatible). fixes #17205 and probably some other issues

git-svn-id: trunk@27207 -
This commit is contained in:
dmitry 2010-08-26 23:25:31 +00:00
parent 8615b73bd3
commit c9c3967f42
4 changed files with 40 additions and 11 deletions

View File

@ -84,7 +84,6 @@ type
function CheckMenu(const Menu: HMENU; const AMethodName: String; AParamName: String = ''): Boolean;
implementation
{------------------------------------------------------------------------------
@ -769,6 +768,5 @@ begin
Result:=AnsiChar(KeyValue);
end;
end.

View File

@ -205,7 +205,7 @@ begin
{ Another possible solution of the problem, is to Post another custom event }
{ to the loop, and report LCL about Menu pressed after the event arrives, }
{ though it might seem, like interface is lagging }
if (HotChar<>#0) then
if (CarbonMenu.Parent.Dismissed<>kHIMenuDismissedBySelection) and (HotChar<>#0) then
begin
AllowMenu := True;
Focused:=GetFocus;
@ -215,17 +215,22 @@ begin
if not AllowMenu then
begin
Result:=eventNotHandledErr;
CarbonMenu.Parent.Dismissed:=0;
Exit;
end;
end;
end;
FillChar(Msg, SizeOf(Msg), 0);
Msg.msg := LM_ACTIVATE;
CarbonMenu.LCLMenuItem.Dispatch(Msg);
Result := noErr;
Exit;
if CarbonMenu.Parent.Dismissed=kHIMenuDismissedBySelection then begin
FillChar(Msg, SizeOf(Msg), 0);
Msg.msg := LM_ACTIVATE;
CarbonMenu.LCLMenuItem.Dispatch(Msg);
CarbonMenu.Parent.Dismissed:=0;
Result := noErr;
Exit;
end else
Result:=CallNextEventHandler(ANextHandler, AEvent);
end;
end;
end;

View File

@ -36,7 +36,7 @@ uses
// widgetset
WSControls, WSLCLClasses, WSProc,
// LCL Carbon
CarbonDef, CarbonGDIObjects,
CarbonDef, CarbonGDIObjects, CarbonMenus,
// LCL
LMessages, LCLMessageGlue, LCLProc, LCLType, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ComCtrls, ExtCtrls, Menus;

View File

@ -19,6 +19,24 @@
// H A N D L E R S
// ==================================================================
procedure SendMenuActivate(AMenu: MenuRef; MenuIdx: MenuItemIndex);
var
CarbonMenu : TCarbonMenu;
Msg : TLMessage;
S : ByteCount;
begin
if GetMenuItemProperty(AMenu, MenuIdx, LAZARUS_FOURCC,
WIDGETINFO_FOURCC, SizeOf(TCarbonMenu), S, @CarbonMenu) = noErr then
begin
FillChar(Msg, SizeOf(Msg), 0);
Msg.msg := LM_ACTIVATE;
CarbonMenu.LCLMenuItem.Dispatch(Msg);
end;
end;
{------------------------------------------------------------------------------
Name: CarbonWindow_Close
------------------------------------------------------------------------------}
@ -679,6 +697,9 @@ const
KeyMsg: TLMKeyDown;
CharMsg: TLMChar;
OrigChar: AnsiString;
Menu: MenuRef;
MenuIdx: MenuItemIndex;
begin
Result:=EventNotHandledErr;
{$IFDEF VerboseKeyboard}
@ -778,10 +799,15 @@ const
if CharMsg.CharCode<>ord(KeyChar) then
LCLCharToMacEvent(Char(CharMsg.CharCode));
if Result<>noErr then
Result:=CallNextEventHandler(ANextHandler, AEvent);
if IsMenuKeyEvent(nil, GetCurrentEvent, kMenuEventQueryOnly, @Menu, @MenuIdx) then
begin
// re-handling menu
SendMenuActivate(Menu, MenuIdx);
end;
//Send a LM_(SYS)CHAR
if IsSysKey then
begin