unit PropMen;

interface
uses
  Windows,
  Libtool,
  LDefin2D,
  classes,
  cBaseEvents,
  ks2DCOM_TLB,
  ksConstTLB,
  ComObj,
  ActiveX,
  LtDefine,
  step12_1,
{$IFDEF __LIGHT_VERSION__}
  klAPI7;
{$ELSE}
  ksApi7;
{$ENDIF}

type
////////////////////////////////////////////////////////////////////////////////
//
// PropertyManagerEvent -      
//
////////////////////////////////////////////////////////////////////////////////
PPropertyManagerEvent = ^PropertyManagerEvent;
PropertyManagerEvent = class( cBaseEvent, IPropertyManagerNotify )

public
	constructor Create( var manager: IDispatch );
  destructor  Destroy; override;
  function    Advise(): boolean; override;

  protected
  //    true   notifyType  
  function IsNotifyProcess(notifyType: SYSINT): WORDBOOL; virtual; stdcall;

  // prButtonClick        -  .  " OCX ."
  function ButtonClick( buttonID : Integer ) : WORDBOOL; virtual; stdcall;
  // prChangeControlValue - " OCX ."
  function ChangeControlValue( const ctrl : IUnknown ) : WORDBOOL; virtual; stdcall;
  // prControlCommand     -   
  function ControlCommand( const ctrl : IUnknown; buttonID : Integer ) : WORDBOOL; virtual; stdcall;
  //prButtonUpdate        -    .
  function ButtonUpdate ( buttonID : Integer; var check : Integer; var _enable : WordBool ) : WORDBOOL; virtual; stdcall;
  //prProcessActivate    -  
  function ProcessActivate : WORDBOOL; virtual; stdcall;
  // prProcessDeactivate  -  
  function ProcessDeactivate : WORDBOOL; virtual; stdcall;
  // prCommandHelp -    
  function CommandHelp(Id: Integer): WORDBOOL; virtual; stdcall;
  // prSelectItem -   
  function  SelectItem(const Control: IUnknown; Index: Integer; Select: WordBool): WordBool; virtual; stdcall;
  // prCheckItem -   
  function  CheckItem(const Control: IUnknown; Index: Integer; check: WordBool): WordBool; virtual; stdcall;
  // prChangeActiveTab -   
  function  ChangeActiveTab(TabIndex: Integer): WordBool; virtual; stdcall;
  // prEditFocus -  \  
  function  EditFocus(const ctrl: IUnknown; Set_: WordBool): WordBool; virtual; stdcall;
  // prUserMenuCommand -    
  function  UserMenuCommand(const ctrl: IUnknown; menuID: Integer): WordBool; virtual; stdcall;

end;


function NewPropertyManagerEvent( var manager: IDispatch ) : PropertyManagerEvent;

implementation



////////////////////////////////////////////////////////////////////////////////
//
// PropertyManagerEvent -      
//
////////////////////////////////////////////////////////////////////////////////
constructor PropertyManagerEvent.Create( var manager: IDispatch );
begin
  inherited CreateByObj( ntPropertyManagerNotify, IUnknown(manager) );
end;

destructor PropertyManagerEvent.Destroy;
begin
  inherited Destroy;
end;

//------------------------------------------------------------------------------
// Advise
//---
function PropertyManagerEvent.Advise() : boolean;
begin
  if not m_advise and ( m_params.ifType <> 0 ) then
    m_advise := boolean( ksConnectionAdvise( @m_params, PIUnknown(IPropertyManagerNotify(self)) ) );
	Result := m_advise;
end;

// prButtonClick        -  .  
function PropertyManagerEvent.ButtonClick( buttonID : Integer ) : WORDBOOL;
begin
//  if ( buttonID = pbHelp )
//    OpenHelp( 1 );
  if ( buttonID = pbEnter ) Or ( buttonID = pbEsc ) then
    ClosePropertyManager( false );

  Result := true;
end;


function PropertyManagerEvent.ChangeControlValue( const ctrl : IUnknown ) : WORDBOOL;
begin
  Result := true;
end;


function PropertyManagerEvent.ControlCommand( const ctrl : IUnknown; buttonID : Integer ) : WORDBOOL;
begin
  Result := true;
end;

//prButtonUpdate        -    .
function PropertyManagerEvent.ButtonUpdate ( buttonID : Integer; var check : Integer; var _enable : WORDBOOL ) : WORDBOOL;
begin
  _enable := true;
  Result := true;
end;

//prProcessActivate    -  
function PropertyManagerEvent.ProcessActivate : WORDBOOL;
begin
  Result := true;
end;

// prProcessDeactivate  -  
function PropertyManagerEvent.ProcessDeactivate : WORDBOOL;
begin
  Result := true;
end;

// prCommandHelp -    
function PropertyManagerEvent.CommandHelp(Id: Integer): WORDBOOL;
begin
  Result := true;
end;

// prSelectItem -   
function PropertyManagerEvent.SelectItem(const Control: IUnknown; Index: Integer; Select: WordBool): WordBool; stdcall;
begin
  Result := true;
end;

// prCheckItem -   
function PropertyManagerEvent.CheckItem(const Control: IUnknown; Index: Integer; check: WordBool): WordBool; stdcall;
begin
  Result := true;
end;

// prChangeActiveTab -   
function  PropertyManagerEvent.ChangeActiveTab(TabIndex: Integer): WordBool; stdcall;
begin
  Result := true;
end;

// prEditFocus -  \  
function PropertyManagerEvent.EditFocus(const ctrl: IUnknown; Set_: WordBool): WordBool; stdcall;
begin
  Result := true;
end;

// prUserMenuCommand -    
function PropertyManagerEvent.UserMenuCommand(const ctrl: IUnknown; menuID: Integer): WordBool; stdcall;
begin
  Result := true;
end;

function PropertyManagerEvent.IsNotifyProcess( notifyType: SYSINT ) : WORDBOOL;
begin
  Result := ( notifyType >= prButtonClick ) And ( notifyType <= prCommandHelp )
end;

function NewPropertyManagerEvent( var manager: IDispatch ) : PropertyManagerEvent;
begin
	Result := PropertyManagerEvent.Create( manager );
	if not Result.Advise() then begin
    Result.Free;
		Result := nil;
	end
end;

end.
