unit ManagerEvents;

interface

uses
  Windows,
  LDefin2D,
  ksAuto,
  contnrs,
  ComObj,
  classes,
  ActiveX,
  ksConstTLB,
  LibTool,
  forms,
  Sysutils,
  GaykaRC,
{$IFDEF __LIGHT_VERSION__}
  klAPI7;
{$ELSE}
  ksAPI7;
{$ENDIF}

//function LibMessage( str : PChar; flags : LongInt ) : Integer;

type

////////////////////////////////////////////////////////////////////////////////
//
//      
//
// ctrlID         
//  
//
////////////////////////////////////////////////////////////////////////////////
PBaseEvent = ^BaseEvent;
BaseEvent = class( TInterfacedObject, IDispatch )

private
  m_dwCookie  : LongInt;
  m_iidEvents : TGUID;

protected
  m_pContainer: IDispatch;

public
  constructor Create( const pObject : IDispatch; iidEvents : TGUID ); overload;
  destructor  Destroy(); override;
  function    Advise() : boolean; virtual; stdcall;
  procedure   Unadvise(); stdcall;

  class procedure TerminateEvents();

  function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult; stdcall;
  function GetTypeInfoCount(out Count: Integer): HResult; stdcall;
  function GetIDsOfNames(const IID: TGUID; Names: Pointer; NameCount,
                           LocaleID: Integer; DispIDs: Pointer): HResult; stdcall;

  function Invoke(eventID: Integer; const IID: TGUID; LocaleID: Integer;
                  Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult;
                  stdcall;
  function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
protected
  function OnEvent( commandID : Integer; var Params : tagDISPPARAMS; var eventRes : boolean  ) : boolean; virtual;

end;

_DVCHatch = dispinterface
    ['{3FFE9799-DF8D-4936-980C-BEA28964A3A7}']
    property Angle:  Double   dispid 1;
    property Step:   Double   dispid 2;
    property Enable: WordBool dispid 3;
  end;

////////////////////////////////////////////////////////////////////////////////
//
//     
//
// ctrlID         
//  
//
////////////////////////////////////////////////////////////////////////////////
PPropertyManagerObject = ^PropertyManagerObject;
PropertyManagerObject = class
protected
  m_flagMode       : Boolean;               //    -
  m_changed        : Boolean;               //   
  procParam        : IProcessParam;     //  
  propTabs         : IPropertyTabs;     // 
  curentCollection : IPropertyControls; //     
  hatchCtrl        : _DVCHatch;             //  -  
  paramGrid        : IPropertyGrid;     //      
  slideBox         : IPropertySlideBox; //  
  rowIndex         : Integer;               //  
  posLiaderParam   : IProcessParam;     //     
public
  constructor Create;
  destructor  Destroy; override;
//   ############################################################
  // 
  // prButtonClick -  .
  procedure OnButtonClick( buttonID : LongInt );  virtual;

  // prChangeControlValue -   
  procedure OnChangeControlValue( {var cntrl : IPropertyControl,} ctrlID : LongInt; const Val: Variant ); virtual;

  // prControlCommand   
//  procedure OnControlCommand( var ctrl : IUnknown ) : boolean; virtual;

//    //prButtonUpdate        -    .
//  procedure OnButtonUpdate(long buttonID, long* check, WordBool* _enable) { return true; }
//   ActiveX Control-a
  procedure OnCreateOCX( ctrlID : LongInt; var control : IDispatch ); virtual;

  //   ActiveX Control-a
  procedure OnDestroyOCX( ctrlID : LongInt{; var control :IDispatch} ); virtual;

  //   
  property  Changed : Boolean  read m_changed  write m_changed;

protected
          //   
  function InitProcessParam( toolBarID, firstTabID : LongInt; toolBarType : SpecPropertyToolBarEnum ) : Boolean;
          //       
  function InitPosLeaderParam : Boolean;
          //  
  function CreateTab( tabID : LongInt; {visible,} active : Boolean ) : Boolean;
//            //    
//    void    /*   IPropertyRealEdit* */ CreateRealEdit( long ctrlID, double value, double minVal = 0, double maxVal = 100, bool enable = true );

  //    
  function CreateList( minVal, maxVal : Double )                : IPropertyList;
  //  
  function CreateSeparator( _type : SeparatorTypeEnum )         : IPropertySeparator;
  //  CheckBox-
  function CreateCheckBox( checked : Boolean )                  : IPropertyCheckBox;
  //   
  function CreateMultiButton( _type : ButtonTypeEnum )          : IPropertyMultiButton;
  //  ActiveX Control 
  function CreateUserControl( ctrlID, height, width : LongInt ) : IPropertyUserControl;

  //    
  procedure AddButton( var buttons : IPropertyMultiButton; btnID : LongInt; cheched, enable : Boolean );
  //    
  procedure AddButton2( var buttons : IPropertyMultiButton; btnID, bmpID : LongInt; cheched, enable : Boolean );

  //    Control    (   )
  function GetPropertyControl( ctrlID : LongInt ) : IPropertyControl;
  //   
  procedure SetControlEnable( ctrlID : LongInt; enabled : Boolean );

  //  -  
//  procedure   SetTabVisible( long tabID, bool visible );
  //    
  procedure InitPropertyControl( var control : IPropertyControl; _ctrlID, _hintID, _tipsID : LongInt;
                             _name_Visibility  : PropertyControlNameVisibility;
                             _enable, _visible : Boolean );

  //     
  procedure ShowControls;          virtual;
  //  
  procedure RedrawPhantom;         virtual;

  //     
  function GetParamCount: Integer; virtual;
  //   
  procedure ShowParam;             virtual;
  //     
  procedure AddStringToGrig( paramID : LongInt; value : string ); //   
  procedure AddDoubleToGrig( paramID : LongInt; value : Double ); //    

  //     
  function  IsHatchObject : Boolean; virtual;

  //      
  procedure ShowHatchControl;        virtual;

  //   
  procedure EndProcess();
  //   ##########################################################
  function  GetPreviewGroup : Reference; virtual;

// :
  //  
  property  ParamCount : Integer read GetParamCount;

end;

////////////////////////////////////////////////////////////////////////////////
//
// PropertyManagerEvent -      
//
////////////////////////////////////////////////////////////////////////////////
PropertyManagerEvent = class( BaseEvent )

protected
  obj : PropertyManagerObject;           //    
  // Attributes
public
	constructor Create( const manager: IDispatch; const _obj: PropertyManagerObject );
  destructor  Destroy; override;

// Operations

protected
  function OnEvent( commandID : Integer; var Params : tagDISPPARAMS; var eventRes : boolean  ) : Boolean; override;

  // prButtonClick        -  .  " OCX ."
  function OnButtonClick( buttonID : LongInt ) : Boolean; virtual;

  // prChangeControlValue - " OCX ."
  function OnChangeControlValue( var ctrl : IDispatch ) : Boolean; virtual;

  // prControlCommand     -   
  function OnControlCommand( var ctrl : IDispatch; buttonID : LongInt ) : Boolean; virtual;

  // prButtonUpdate        -    .
  // function OnButtonUpdate ( buttonID : LongInt; var check : LongInt; var _enable : WordBool ) : Boolean; virtual;

  // prProcessActivate    -  
  // function OnProcessActivate : Boolean; virtual;

  // prProcessDeactivate  -  
  // function OnProcessDeactivate : Boolean; virtual;
end;

EventList = class ( TObjectList ) // (TInterfaceList)
public
  constructor Create; overload;
  procedure Notify(Ptr: Pointer; Action: TListNotification); override;
end;

procedure MyDLLProc(Reason: Integer);

var
  newKompasAPI : IApplication;

implementation
uses
  Base,
  UserControlEvent;

var
  m_BaseEventList : EventList; // static BaseEvent

//    
procedure EventList.Notify(Ptr: Pointer; Action: TListNotification);
begin
  if OwnsObjects then
    if Action = lnDeleted then begin
      BaseEvent(Ptr).UnAdvise;
      exit;
    end;
  inherited Notify(Ptr, Action);
end;

//------------------------------------------------------------------------------
//  
// ---
constructor EventList.Create();
begin
  inherited Create;
end;

//------------------------------------------------------------------------------
// 
//---
constructor BaseEvent.Create( const pObject : IDispatch; iidEvents : TGUID );
begin
  if  m_BaseEventList = nil then
    m_BaseEventList := EventList.Create;
  m_pContainer := pObject;
  m_pContainer._AddRef;
  m_iidEvents  := iidEvents;
  m_dwCookie   := 0;
  m_BaseEventList.Add( Self );
end;

//------------------------------------------------------------------------------
// 
//---
destructor BaseEvent.Destroy();
//var
//  index : integer;
begin
  if ( m_BaseEventList <> nil ) then begin
    m_BaseEventList.Remove( Self );
    Unadvise;              //    
    m_pContainer := nil;
  end
end;

//------------------------------------------------------------------------------
//   Invoke IDispatch
//---
function BaseEvent.Invoke( eventID: Integer; const IID: TGUID; LocaleID: Integer;
                           Flags: Word; var Params; VarResult, ExcepInfo,
                           ArgErr: Pointer): HResult;
var
  ProcParams: tagDISPPARAMS;
  Res: ^OleVariant;
  fResult : boolean;
begin
  Result     := S_OK;
  Res        := VarResult;
  ProcParams := TDispParams(Params);
  fResult    := true;

  OnEvent( eventID, ProcParams, fResult );

//  if not find then begin
//    Result  := S_OK;
//    fResult := true;
//  end;

  if Res <> nil then begin
    Res^ := fResult;
  end;
end;

//------------------------------------------------------------------------------
//   GetTypeInfo IDispatch
//---
function BaseEvent.GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult;
begin
  Result := E_NOTIMPL;
end;

//------------------------------------------------------------------------------
//   GetTypeInfoCount IDispatch
//---
function BaseEvent.GetTypeInfoCount(out Count: Integer): HResult;
begin
  Count:=0; Result:=S_OK;
end;

//------------------------------------------------------------------------------
//   GetIDsOfNames IDispatch
//---
function BaseEvent.GetIDsOfNames(const IID: TGUID; Names: Pointer; NameCount,
                                  LocaleID: Integer; DispIDs: Pointer): HResult;
begin
  Result := S_OK;
end;

//------------------------------------------------------------------------------
//    
//---
function  BaseEvent.Advise() : boolean; stdcall;
begin
  if ( m_dwCookie = 0) And  (m_pContainer <> nil) then
    InterfaceConnect( m_pContainer, m_iidEvents, IDispatch( self ), m_dwCookie );
	Result := m_dwCookie <> 0;
end;

//------------------------------------------------------------------------------
//    
//---
procedure BaseEvent.Unadvise(); stdcall;
var
  cock : integer;
begin
  if ( m_pContainer <> nil ) and ( m_dwCookie <> 0 ) then begin
    cock := m_dwCookie;
    m_dwCookie := 0;  //    InterfaceDisconnect
    InterfaceDisconnect( m_pContainer, m_iidEvents, cock );
  end;
end;

//------------------------------------------------------------------------------
//  
//---
class procedure BaseEvent.TerminateEvents();
begin
  if  m_BaseEventList <> nil then begin
    m_BaseEventList.Free;
    m_BaseEventList := nil;
  end
end;

//------------------------------------------------------------------------------
// QueryInterface
//---
function BaseEvent.QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
begin
  if GetInterface(IID, Obj) then
    Result := S_OK
  else
    if IsEqualGUID(IID, m_iidEvents) then
    begin
      IDispatch(Obj) := Self;
      Result := S_OK;
    end
    else
      Result := E_NOINTERFACE;
end;

//------------------------------------------------------------------------------
// 
//---
function BaseEvent.OnEvent( commandID : Integer; var Params : tagDISPPARAMS; var eventRes : boolean ) : boolean;
begin
  eventRes := true;
  Result   := true;
end;

//------------------------------------------------------------------------------
// 
//---
constructor PropertyManagerEvent.Create( const manager: IDispatch; const _obj: PropertyManagerObject );
begin
  inherited Create( manager, DIID_ksPropertyManagerNotify );
  obj := _obj;
  Advise;
end;

procedure OpenHelp( id : Integer );
  var
    gaykaHlp : array [0..260] of Char;
begin
  if ( GetFullName( 'gayka.hlp', gaykaHlp ) > 0 ) then
      ksOpenHelpFile( gaykaHlp, HELP_CONTEXT, id );
end;

//------------------------------------------------------------------------------
// prButtonClick -  .
//---
function PropertyManagerEvent.OnButtonClick( buttonID : LongInt ) : Boolean;
begin
  if buttonID = pbHelp then
    OpenHelp( 1 );
//  else
//    if ( obj.OnButtonClick( buttonID ) )
//      obj.RedrawPhantom();
  Result := true;
end;

//------------------------------------------------------------------------------
// prChangeControlValue -   
//---
function PropertyManagerEvent.OnChangeControlValue( var ctrl : IDispatch ) : boolean;
var
  control : IPropertyControl;
  ctrlID  : LongInt;
begin
  if ( ctrl <> nil ) then begin
    control := ctrl As IPropertyControl;
    if control <> nil then begin
      ctrlID := control.Id;
      obj.OnChangeControlValue(ctrlID, control.Value );
      if obj.Changed then
        obj.RedrawPhantom();
    end;
  end;
  Result := true;
end;

//------------------------------------------------------------------------------
// koOpenDocumen -  
//---
function PropertyManagerEvent.OnControlCommand( var ctrl : IDispatch; buttonID : LongInt ) : Boolean;
begin
  obj.OnButtonClick( buttonID );
  if obj.Changed then
     obj.RedrawPhantom();
  Result := true;
end;

//------------------------------------------------------------------------------
// prButtonUpdate        -    .
//---
//function PropertyManagerEvent.OnButtonUpdate( buttonID : LongInt; var check : LongInt; var _enable : WordBool ) : Boolean; virtual;
//begin
//  Result := true;
//end;

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

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


//------------------------------------------------------------------------------
//  
//---
destructor PropertyManagerEvent.Destroy();
begin
  inherited Destroy;
end;

//------------------------------------------------------------------------------
//  
//---
function PropertyManagerEvent.OnEvent( commandID : Integer; var Params : tagDISPPARAMS; var eventRes : boolean ) : boolean;
begin
  Result := (boolean( commandID >= prButtonClick ) and boolean( commandID <= prControlCommand )) or ( commandID = prCommandHelp);
  case commandID of

    prButtonClick:                       //   
      eventRes := OnButtonClick( Params.rgvarg^[0].lVal );

    prChangeControlValue :              //   
      eventRes := OnChangeControlValue( IDispatch(Params.rgvarg^[0].dispVal ) );

    prControlCommand:                   //   
      eventRes := OnControlCommand( IDispatch(Params.rgvarg^[1].dispVal), LongInt(Params.rgvarg^[0].lVal) );

//    prButtonUpdate:                     //     
//      eventRes := OnButtonUpdate( Params.rgvarg^[0].intVal, Params.rgvarg^[1].pIntVal^, Params.rgvarg^[2].pbool^ );

//    prProcessActivate:                  //  
//      eventRes := OnProcessActivate;

//    prProcessDeactivate:                //  
//      eventRes := OnProcessDeactivate
    prCommandHelp :
    begin
      OpenHelp( 1 ); // Params.rgvarg^[0].lVal );
      eventRes := true;
    end;
  end;

end;

//------------------------------------------------------------------------------
//  ,    
// ---
//procedure DumpError( var e : TOleError );
//begin
//end;

//------------------------------------------------------------------------------
//  ,    
// ---
//procedure ShowError()
//begin
//  IErrorInfoPtr ef;
//  GetErrorInfo( NULL, &ef );
//  BSTR                bstrDescription;
//  ef->GetDescription( &bstrDescription );
//  USES_CONVERSION;
//  LibMessage( OLE2T(bstrDescription), MB_OK | MB_ICONERROR );
//end;


//------------------------------------------------------------------------------
//     API
// ---
procedure GetNewKompasAPI;
 var
    disp : IDispatch;
begin
	if newKompasAPI = nil then
  begin
    disp := IDispatch( CreateKompasApplication );
    newKompasAPI := disp As IApplication;
  end
end;

//------------------------------------------------------------------------------
// 
// ---
constructor PropertyManagerObject.Create;
begin
  procParam        := nil;  //  
  propTabs         := nil;  //  
  curentCollection := nil;  //  
  hatchCtrl        := nil;  //  -  
  paramGrid        := nil;  //      
  slideBox         := nil;  //  
  rowIndex         := 0;    //  
  posLiaderParam   := nil;  //
  m_flagMode       := False;//
end;

//------------------------------------------------------------------------------
// 
// ---
destructor PropertyManagerObject.Destroy;
begin
  BaseEvent.TerminateEvents;
  hatchCtrl        := nil;  //  -  
  paramGrid        := nil;  //      
  slideBox         := nil;  //  
  curentCollection := nil;  //  
  propTabs         := nil;  //  
  procParam        := nil;  //  
  posLiaderParam   := nil;  //
  rowIndex         := 0;    //  
  m_flagMode       := False;//
end;

//------------------------------------------------------------------------------
//   
// ---
function PropertyManagerObject.InitProcessParam( toolBarID, firstTabID: LongInt; toolBarType : SpecPropertyToolBarEnum ) : Boolean;
var
  gr       : reference;
  parCount : Integer;
begin
  Result := false;
  GetNewKompasAPI();                                                            //   Api
  if newKompasAPI <> nil then
  begin
    procParam := newKompasAPI.CreateProcessParam;          // newKompasAPI->CreateProcessParam();                 //   
    if procParam <> nil then
    begin
      PropertyManagerEvent.Create( IDispatch(procParam), Self );                //    
      with procParam do
      begin
        //    
        SpecToolbar := toolBarType;                                 //     
        Caption     := WideString( LoadStr_(toolBarID) );           //    
        AutoReduce  := not m_flagMode;                              //  

        if m_flagMode then
          DefaultControlFix := ksAllFix;

        //     
        propTabs := PropertyTabs;

        //    
        if firstTabID <> 0 then
          CreateTab( firstTabID, {true,} true );
        //       
        ShowControls();
        //   
        //     
        gr := GetPreviewGroup();
        if gr <> 0 then
        begin
          slideBox := curentCollection.Add( ksControlSlideBox ) As IPropertySlideBox;
          if slideBox <> nil then
          begin
            with slideBox do
            begin
              SlideType    := ksGroup;           //  
              DrawingSlide := gr;                //  reference 
              Hint         := 'Hint  ';
              Tips         := 'Tips  ';
              Id           := 10000;
              Name         := ' ';
              height       := 100;
              width        := 150;
            end
          end
        end;
        parCount := ParamCount;                               //     ?
        if ( parCount <> 0 ) or IsHatchObject then
        begin
          CreateTab( IDP_ELEMENT_PARAM, false );              //      
          if IsHatchObject then
            ShowHatchControl();

          if paramCount <> 0 then
          begin
            //  
            paramGrid := curentCollection.Add( ksControlGrid ) as IPropertyGrid;
            if paramGrid <> nil then
            begin
              with paramGrid do
              begin
                ColumnCount      := 2;                        //   
                FixedColumnCount := 1;                        //     
                FixedRowCount    := 1;                        //  
                RowCount         := paramCount + 1;           //     
                AutoSizeColumns  := true;                     //    
                Hint             := 'Hint  ';
                Tips             := 'Tips  ';
                Id               := 10001;
                rowIndex := 0;                                           //  

                AddStringToGrig( IDS_PARAM_CAPTION, LoadStr_(IDS_VALUE_CAPTION) );
                ShowParam();                                            //    
                RowCount         := rowIndex;
                Height           := rowIndex * 20;
                Name             := ' ';
              end;
              //  

            end
          end
        end;

      Result := true;
      end
    end
  end;
end;

//------------------------------------------------------------------------------
//    
//   
// ---
function PropertyManagerObject.InitPosLeaderParam : Boolean;
var
  liaderPropTabs : IPropertyTabs;
  propTab        : IPropertyTab;
  ctrlCollection : IPropertyControls;
  buttons        : IPropertyMultiButton;
begin
  Result := posLiaderParam <> nil;
  //        
  if (newKompasAPI <> nil) and ( posLiaderParam = nil ) then
  begin
    posLiaderParam := newKompasAPI.CreateProcessParam;                 // newKompasAPI->CreateProcessParam();                 //   
    if posLiaderParam <> nil then
    begin
      PropertyManagerEvent.Create( IDispatch(posLiaderParam), Self );                 //    

      //     
      liaderPropTabs := posLiaderParam.PropertyTabs;
      if liaderPropTabs <> nil then
      begin
        propTab := liaderPropTabs.Add( WideString( LoadStr_(IDP_POS_LEADER) ) );
        if propTab <> nil then
        begin

          ctrlCollection := propTab.PropertyControls;
          if ctrlCollection <> nil then
          begin
            buttons := ctrlCollection.Add(ksControlMultiButton) as IPropertyMultiButton;
            if buttons <> nil then
            begin
              InitPropertyControl( IPropertyControl(buttons), ID_LEADER_CREATE, IDS_LEADER_HINT, IDS_LEADER_TIPS,  ksNameAlwaysVisible, true, true );
              buttons.ButtonsType := ksPushButton;
              buttons.ResModule   := OleVariant( LongInt(hInstance) );
            end
          end
        end;

        Result := true;
      end
    end
  end
end;


//------------------------------------------------------------------------------
//    
// ---
procedure PropertyManagerObject.AddStringToGrig( paramID : LongInt; value : string );
begin
  if paramGrid <> nil then
  begin
    paramGrid.CellText[ rowIndex, 1 ] := value;
    paramGrid.CellText[ rowIndex, 0 ] := LoadStr_(paramID); //    
    Inc(rowIndex);
  end
end;

//------------------------------------------------------------------------------
//    
// ---
function DoubleToStr( value : double ) : string;
  var
    str  : string;
    dSep : Char;
begin
  dSep := DecimalSeparator;
  DecimalSeparator := '.';
  str := Format('%0.3f',[value]);
  Result := Format('%g', [StrToFloat( str )] );
  DecimalSeparator := dSep;
end;

//------------------------------------------------------------------------------
//    
// ---
procedure PropertyManagerObject.AddDoubleToGrig( paramID: LongInt; value : double );
begin
  if paramGrid <> nil then begin
    paramGrid.CellText[ rowIndex, 1 ] := DoubleToStr(value);  //  
    paramGrid.CellText[ rowIndex, 0 ] := LoadStr(paramID);      //  
    Inc(rowIndex);
  end
end;

//------------------------------------------------------------------------------
//  
// ---
function PropertyManagerObject.CreateTab( tabID : LongInt; {visible,}active : Boolean ) : Boolean;
var
  propTab : IPropertyTab;
begin
  Result := false;
  if ( tabID <> 0 ) and ( propTabs <> nil ) then
  begin
    propTab := propTabs.Add( WideString( LoadStr(tabID) ) );
    if propTab <> nil then
    begin
      curentCollection := propTab.PropertyControls;
//      if not visible then
//        propTab.Visible := visible;
      propTab.Active  := active;
      Result          := true;
    end
  end
end;

//------------------------------------------------------------------------------
//  
// ---
procedure PropertyManagerObject.InitPropertyControl( var control : IPropertyControl; _ctrlID, _hintID, _tipsID : LongInt;
                             _name_Visibility  : PropertyControlNameVisibility;
                             _enable, _visible : Boolean );
begin
  if control <> nil then
  begin
    with control do
    begin
      Id      := _ctrlID;
      if _ctrlID <> 0 then
        Name  := WideString( LoadStr(_ctrlID) );
      if _hintID <> 0 then
        Hint  := WideString( LoadStr(_hintID) );
      if _tipsID <> 0 then
        Tips  := WideString( LoadStr(_tipsID) );;
      Enable  := _enable;
      Visible := _visible;
      NameVisibility := _name_Visibility;
    end
  end
end;

//------------------------------------------------------------------------------
//  
// ---
function PropertyManagerObject.CreateList( minVal, maxVal : Double ) : IPropertyList;
begin
  Result := nil;
  if curentCollection <> nil then
  begin
    Result := curentCollection.Add( ksControlListReal ) As IPropertyList;
    if ( minVal <> maxVal ) and ( Result <> nil ) then
    begin
      Result.SetValueRange( minVal, maxVal );
      Result.ReadOnly := true;
    end
  end
end;

//------------------------------------------------------------------------------
//  
// ---
function PropertyManagerObject.CreateSeparator( _type : SeparatorTypeEnum ) : IPropertySeparator;
begin
  Result := nil;
  if curentCollection <> nil then
  begin
    Result := curentCollection.Add( ksControlSeparator ) As IPropertySeparator;
    if Result <> nil then
      Result.SeparatorType := _type;
  end;
end;

//------------------------------------------------------------------------------
//  CheckBox-
// ---
function PropertyManagerObject.CreateCheckBox( checked : Boolean ) : IPropertyCheckBox;
begin
  Result := nil;
  if curentCollection <> nil then
  begin
    Result := curentCollection.Add( ksControlCheckBox ) As IPropertyCheckBox;
    if Result <> nil then
      Result.Value := checked;
  end;
end;

//------------------------------------------------------------------------------
//   
// ---
function PropertyManagerObject.CreateMultiButton( _type : ButtonTypeEnum ) : IPropertyMultiButton;
begin
  Result := nil;
  if curentCollection <> nil then
  begin
    Result := curentCollection.Add( ksControlMultiButton ) As IPropertyMultiButton;
    if Result <> nil then
    begin
      Result.ButtonsType := _type;
      Result.ResModule   := LongInt( hInstance );
    end
  end
end;

//------------------------------------------------------------------------------
//    
// ---
procedure PropertyManagerObject.AddButton( var buttons: IPropertyMultiButton; btnID : LongInt; cheched, enable : Boolean );
begin
  AddButton2( buttons, btnID, btnID, cheched, enable );
end;

//------------------------------------------------------------------------------
//    
// ---
procedure PropertyManagerObject.AddButton2( var buttons : IPropertyMultiButton; btnID, bmpID : LongInt; cheched, enable : Boolean );
begin
  if buttons <> nil then
  begin
    with buttons do
    begin
      AddButton    ( btnID, OleVariant(bmpID), -1 );
      ButtonEnable [ btnID ] := enable;
      ButtonChecked[ btnID ] := cheched;
      ButtonTips   [ btnID ] := LoadStr(btnID);
    end;
  end
end;


//------------------------------------------------------------------------------
//    
// ---
procedure PropertyManagerObject.EndProcess;
begin
  BaseEvent.TerminateEvents;
end;

//------------------------------------------------------------------------------
//  
// ---
function PropertyManagerObject.GetPropertyControl( ctrlID : LongInt ) : IPropertyControl;
var
  i, count : Integer;
  tab      : IPropertyTab;
  ctrls    : IPropertyControls;
begin
  Result := nil;
  if propTabs <> nil then
  begin
    i     := 0;
    count := propTabs.Count;
    while ( i < count ) and ( Result <> nil ) do
    begin
      tab   := propTabs.Item[i];
      if tab <> nil then
      begin
        ctrls := tab.PropertyControls;
        if ctrls <> nil then
          Result := ctrls.Item[WideString(LoadStr(ctrlID))];
      end
    end
  end
end;

//------------------------------------------------------------------------------
//   
// ---
procedure PropertyManagerObject.SetControlEnable( ctrlID : Integer; enabled : Boolean );
var
  control : IPropertyControl;
begin
  control := GetPropertyControl(ctrlID);
  if control <> nil then
    control.Enable := enabled;
end;

//------------------------------------------------------------------------------
//   
// ---
function PropertyManagerObject.CreateUserControl( ctrlID, height, width : LongInt ) : IPropertyUserControl;
begin
  Result := nil;
  if curentCollection <> nil then
  begin
    Result := curentCollection.Add( ksControlUser ) As IPropertyUserControl;
    if Result <> nil then
    begin
      with Result do
      begin
        NameVisibility := ksNameHorizontalVisible;
        SetOCXControl( WideString( LoadStr(ctrlID+2000) ) );
        Name           := WideString( LoadStr(ctrlID+2001) );
        Height := height;
        Width  := width;
        Id     := ctrlID;
        PropertyUserControlEvent.Create( IDispatch(Result), ctrlID, self );
      end;
    end;
  end
end;

//------------------------------------------------------------------------------
//     
// ---
procedure PropertyManagerObject.OnDestroyOCX( ctrlID : LongInt{; var control : IDispatch} );
begin
  if ctrlID = IDP_HATCH_PARAM then
    hatchCtrl := nil;
end;

//------------------------------------------------------------------------------
//       
//---
procedure PropertyManagerObject.OnButtonClick( buttonID : LongInt );
begin
end;

//prChangeControlValue -   
procedure PropertyManagerObject.OnChangeControlValue( {var cntrl : IPropertyControl;} ctrlID : LongInt; const Val: Variant );
begin
end;

//   ActiveX Control-a
procedure PropertyManagerObject.OnCreateOCX( ctrlID : LongInt; var control : IDispatch );
begin
end;

//     
procedure  PropertyManagerObject.ShowControls;
begin
end;

//  
procedure  PropertyManagerObject.RedrawPhantom;
begin
end;

//     
function PropertyManagerObject.GetParamCount : Integer;
begin
  Result:= 0;
end;

//   
procedure  PropertyManagerObject.ShowParam;
begin
end;

//     
function PropertyManagerObject.IsHatchObject : Boolean;
begin
  Result:= false;
end;

//      
procedure PropertyManagerObject.ShowHatchControl;
begin
end;

//      
function PropertyManagerObject.GetPreviewGroup : Reference;
begin
 Result := 0;
end;

// prControlCommand   
//function PropertyManagerObject.OnControlCommand( var ctrl : IUnknown ) : boolean;
//begin
//  Result := true;
//end;
//------------------------------------------------------------------------------
// LibraryName
//---
procedure MyDLLProc(Reason: Integer);
begin
  if Reason = DLL_PROCESS_DETACH then begin
    BaseEvent.TerminateEvents;
    newKompasAPI       := nil;
    Application.Handle := 0;
  end;
end;

end.



