unit events;

interface
uses
  Windows;

/////////////////////////////////////////////////////////////////////////////
// ApplicationEvent command target

  procedure  LIBRARYENTRY( command: WORD  ); Pascal;
  function   LIBRARYNAME : PChar;         Pascal;
  function   LIBRARYID   : Cardinal;      Pascal;
  procedure  MyDLLProc(Reason: Integer);

implementation

uses
  LtDefine,
  LibTool,
  cBaseEvents,
  ApplicationEvents,
  DocumentEvents,
  ksConstTLB;

procedure MyDLLProc(Reason: Integer);

begin
  if Reason = DLL_PROCESS_DETACH then begin
    cBaseEvent.TerminateEvents;
  end;
end;


//------------------------------------------------------------------------------
// LibraryName
//---
function LIBRARYNAME: PChar; pascal;
begin
  Result := '    (Delphi COM)';
end;

//------------------------------------------------------------------------------
// LibraryId
//---
function LIBRARYID: UINT; pascal;
begin
  Result := 100;
end;

//------------------------------------------------------------------------------
// LibraryEntry
//---
procedure LIBRARYENTRY(command: WORD); pascal;
var
  doc : reference;
begin
//  ksMessage( '' );
  case command of
    10 : begin                                      //  1
      if cBaseEvent.FindEvents( ntKompasObjectNotify, 0, -1, nil ) = nil then begin
        if NewApplicationEvent <> nil then               //     
          ksMessage( '' )
        else
          ksMessage( ' ' );
      end
      else
        ksMessage( ' ' );
    end;
    11 : begin                                      //  2
      cBaseEvent.TerminateEventsByParam( ntKompasObjectNotify, 0, -1, nil );
      ksMessage( '' );
    end;
    20 : begin
      doc := ksGetCurrentDocument( 0 );
      if doc <> 0 then begin
        if  NewDocumentEvent( doc ) <> nil  then
          ksMessage( '' )
        else
          ksMessage( ' ' );
      end
      else
        ksMessage( '  ' );
    end;
    21 : begin
      doc := ksGetCurrentDocument( 0 );
      if doc <> 0 then begin
        cBaseEvent.TerminateEventsByParam( ntDocumentFileNotify, doc, -1, nil );
        if cBaseEvent.FindEvents( ntDocumentFileNotify, doc, -1, nil ) = nil then
          ksMessage( '' )
        else
          ksMessage( ' ' );
      end
      else
        ksMessage( '  ' );
    end;

  end;
end;

end.

