////////////////////////////////////////////////////////////////////////////////
//
// ApplicationEvent.cpp
// ApplicationEvent -     (COM)
//
////////////////////////////////////////////////////////////////////////////////

#include <vcl.h>
#pragma hdrstop

#ifndef _DOCUMENTEVENT_H
#include "DocumentEvent.h"
#endif

#include <ksConstants.h>

#ifndef _APPLICATIONEVENT_H
#include "ApplicationEvent.h"
#endif

extern int LibMessage( char* str, int flags = MB_OK );
//-------------------------------------------------------------------------------
//
// ---
ApplicationEvent::ApplicationEvent() :
  TBaseEvent<IKompasObjectNotify, & IID_IKompasObjectNotify>( ntKompasObjectNotify, 0 )
{
}

//-----------------------------------------------------------------------------
//      notifyType
// ---
VARIANT_BOOL STDMETHODCALLTYPE ApplicationEvent::IsNotifyProcess( int notifyType )
{
	return  notifyType >= koCreateDocument && notifyType <= koBeginCloseAllDocument;
}

//-------------------------------------------------------------------------------
//  
// ---
VARIANT_BOOL STDMETHODCALLTYPE ApplicationEvent::CreateDocument( long pDoc, int docType )
{
  LibMessage( "ApplicationEvent -  " );
  return TRUE;
}

//-------------------------------------------------------------------------------
//   
// ---
VARIANT_BOOL STDMETHODCALLTYPE ApplicationEvent::BeginOpenDocument( LPCSTR docName )
{
  return LibMessage( "ApplicationEvent -   \n ?", MB_YESNO ) == IDYES;
}

//-------------------------------------------------------------------------------
//  
// ---
VARIANT_BOOL STDMETHODCALLTYPE ApplicationEvent::OpenDocument( long pDoc, int docType)
{
  LibMessage( "ApplicationEvent -  " );
  return TRUE;
}


//-------------------------------------------------------------------------------
//     
// ---
VARIANT_BOOL STDMETHODCALLTYPE ApplicationEvent::ChangeActiveDocument( long pDoc, int docType)
{
  LibMessage( "ApplicationEvent -     " );
  return TRUE;
}


//-------------------------------------------------------------------------------
//  
// ---
VARIANT_BOOL STDMETHODCALLTYPE ApplicationEvent::ApplicationDestroy( void )
{
  LibMessage( "ApplicationEvent -  " );
  return TRUE;
}

//-----------------------------------------------------------------------------
// koBeginCreate -   
// ---
VARIANT_BOOL STDMETHODCALLTYPE ApplicationEvent::BeginCreate(long type){
  bool res = true;
  int com = YesNo( "ApplicationEvent::BeginCreate\n "
		               " -  \n"
		               " -     \n"
									 " -   " );
	switch ( com ) {
	  case 1: {
      DocumentParam docParam;
			memset( &docParam, 0, sizeof(docParam) );
			docParam.type = type ? type : lt_DocSheetStandart;
			reference doc = ::CreateDocument( &docParam );
      res = !doc;
//			if ( doc )
//				AdviseDoc( doc );
			break;
		}
		case 0:
			res = true;
			break;
		case -1:
			res = false;
	}
	return res;
}

//-----------------------------------------------------------------------------
// koBeginOpenFile -   
// ---
VARIANT_BOOL STDMETHODCALLTYPE ApplicationEvent::BeginOpenFile(){
  bool res = true;
  int com = YesNo( "ApplicationEvent::BeginOpenFile\n "
		               " -  \n"
		               " -     \n"
									 " -   " );
	switch ( com ) {
	  case 1: {
      DocumentParam docParam;
			memset( &docParam, 0, sizeof(docParam) );
      docParam.type = lt_DocSheetStandart;
      reference doc = ::CreateDocument( &docParam );
      res = !doc; //       
//      if ( doc && theApp.m_auto )
//        AdviseDoc( doc );
      break;
    }
    case 0:
      res = true;
      break;
    case -1:
      res = false;
  }
	return res;
}

//-----------------------------------------------------------------------------
// BeginCloseAllDocument -    
// ---
VARIANT_BOOL STDMETHODCALLTYPE ApplicationEvent::BeginCloseAllDocument() {
  return YesNo( "EventCom::ApplicationEvent::BeginCloseAllDocument\n ?" ) == 1;
}

VARIANT_BOOL STDMETHODCALLTYPE ApplicationEvent::KeyDown( long __RPC_FAR *key,
                                                  long flags,
                                                  VARIANT_BOOL sysKey)
{
  return true;
}

VARIANT_BOOL STDMETHODCALLTYPE ApplicationEvent::KeyUp( long __RPC_FAR *key,
                                                        long flags,
                                                        VARIANT_BOOL sysKey)
{
  return true;
}


VARIANT_BOOL STDMETHODCALLTYPE ApplicationEvent::KeyPress( long __RPC_FAR *key,
                                                           VARIANT_BOOL sysKey)
{
  return true;
}

VARIANT_BOOL STDMETHODCALLTYPE ApplicationEvent::BeginRequestFiles(  long requestID, VARIANT __RPC_FAR *files )
{
  return true;
}



