* * *

Author Topic: Thistoryfiles on OSX (carbon)  (Read 150 times)

apeoperaio

  • Jr. Member
  • **
  • Posts: 75
Thistoryfiles on OSX (carbon)
« on: February 06, 2018, 09:16:57 am »
Dear all,
I am using THistoryFiles (http://wiki.freepascal.org/HistoryFiles) in a project running on linux/win/osx.
I have an issue with THistoryFiles on Carbon.
Specifically, the issue is related to historyfiles.pas when clicking on a recent menu item.
When a recent menu item is clicked an event is raised in HistoryFiles:

Code: Pascal  [Select]
  1. procedure THistoryFiles.OnMainMenuClickHistoryItem(Sender:TObject);
  2. var
  3.   thefile : string;
  4. begin
  5.   thefile:='';
  6.   If Assigned(FOnHistoryItemClick) Then
  7.   begin
  8.    thefile := FItems.Strings[TMenuItem(sender).tag-1];
  9.    if thefile<>'' then
  10.      FLastItemIndex := TMenuItem(sender).tag;
  11.  
  12.      LastItemIndex_WriteIni;
  13.  
  14.      FOnHistoryItemClick(Self, TMenuItem(sender), thefile);
  15.  
  16.      UpdateParentMenu;
  17.   end;
  18. end;

Before the event is raised the following function is executed (in carbonobject.inc)
function CarbonApp_CommandProcess(ANextHandler: EventHandlerCallRef;
  AEvent: EventRef;
  {%H-}AWidget: TCarbonWidget): OSStatus; {$IFDEF darwin}mwpascal;{$ENDIF}
 
Staring from line 271 the following code is executed:

Code: Pascal  [Select]
  1.           if CarbonMenu.Parent.Dismissed=kHIMenuDismissedBySelection then begin
  2.             FillChar(Msg{%H-}, SizeOf(Msg), 0);
  3.             Msg.msg := LM_ACTIVATE;
  4.             DeliverMessage(CarbonMenu.LCLMenuItem, Msg);
  5.             if assigned(CarbonMenu.Parent) then  // if parent not closed
  6.               CarbonMenu.Parent.Dismissed:=0;
  7.             Result := noErr;
  8.             Exit;
  9.           end else
  10.             Result:=CallNextEventHandler(ANextHandler, AEvent);
  11.  

Specifically THistoryFiles.OnMainMenuClickHistoryItem is executed on DeliverMessage, the issue is that in THistoryFiles.OnMainMenuClickHistoryItem the menu is deleted and replaced by thistoryfiles, so when executing the instructions after DeliverMessage the CarbonMenu does not exists anymore.

Any hint?
Andrea Mauri


 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus