// (C) Copyright 2008 by Autodesk, Inc. 
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted, 
// provided that the above copyright notice appears in all copies and 
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting 
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. 
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC. 
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to 
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
//
/////////////////////////////////////////////////////////////////////
// includes from ObjectARX Wizard

#include "StdAfx.h"

//#include <afxtempl.h>
// TODO: add your own includes here

// Entry Point of this Application
extern "C" AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void*);
// message handlers
static void OnkEndMsg(void);
static void OnkQuitMsg(void);
static void OnkDependencyMsg(void);
static void OnkNoDependencyMsg(void);
static void OnkPreQuitMsg  (void);
static void OnkLoadDwgMsg  (void);
static void OnkUnloadDwgMsg(void);
static void OnkInvkSubrMsg (void);

//help functions
void createRevList();
void deleteRevList();
void modifyRevLine();
void addRevLine();

static void initApp();
static void unLoadApp();

//MFC support
extern "C" HINSTANCE _hdllInstance;
extern HWND _adsw_acadMainWnd();
extern void InitMFC();
extern void EndMFC();
BOOL InitModule(HINSTANCE, DWORD, LPVOID);

/////////////////////////////////////////////////////////////////////
// acrxEntryPoint(internal)
// This function is the entry point for your application.
/////////////////////////////////////////////////////////////////////
AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* ptr)
{
  switch(msg)
  {
  case AcRx::kInitAppMsg:
    acrxDynamicLinker->unlockApplication(ptr);
    acrxDynamicLinker->registerAppMDIAware(ptr);
    initApp();
    break;
  case AcRx::kUnloadAppMsg:
    unLoadApp();
    break;
  case AcRx::kEndMsg:
    OnkEndMsg();
    break;
  case AcRx::kQuitMsg:
    OnkQuitMsg();
    break;
  case AcRx::kDependencyMsg:
    OnkDependencyMsg();
    break;
  case AcRx::kNoDependencyMsg:
    OnkNoDependencyMsg();
    break;
  case AcRx::kPreQuitMsg:
    OnkPreQuitMsg();
    break;
  case AcRx::kLoadDwgMsg:
    OnkLoadDwgMsg();
    break;
  case AcRx::kUnloadDwgMsg:
    OnkUnloadDwgMsg();
    break;
  case AcRx::kInvkSubrMsg:
    OnkInvkSubrMsg();
    break;
  default:
    break;
  }

  return AcRx::kRetOK;
}

static void OnkEndMsg(void)
{
  // TODO: add your message handler code here

  // end of message handler
}
static void OnkQuitMsg(void)
{
  // TODO: add your message handler code here

  // end of message handler
}
static void OnkDependencyMsg(void)
{
  // TODO: add your message handler code here

  // end of message handler
}
static void OnkNoDependencyMsg(void)
{
  // TODO: add your message handler code here

  // end of message handler
}
static void OnkPreQuitMsg(void)
{
  // TODO: add your message handler code here

  // end of message handler
}
static void OnkLoadDwgMsg(void)
{
  // TODO: add your message handler code here

  // end of message handler
}
static void OnkUnloadDwgMsg(void)
{
  // TODO: add your message handler code here

  // end of message handler
}
static void OnkInvkSubrMsg(void)
{
  // TODO: add your message handler code here

  // end of message handler
}

static void initApp()
{
  InitMFC();

  // TODO: init your application
  acedRegCmds->addCommand(_T("REVLISTSAMPLEAPP"), _T("CREATEREVLIST"), _T("CREATEREVLIST"), ACRX_CMD_MODAL, createRevList);
  acedRegCmds->addCommand(_T("REVLISTSAMPLEAPP"), _T("DELREVLIST"), _T("DELREVLIST"), ACRX_CMD_MODAL, deleteRevList);  
  acedRegCmds->addCommand(_T("REVLISTSAMPLEAPP"), _T("MODIFYREVLINE"), _T("MODIFYREVLINE"), ACRX_CMD_MODAL, modifyRevLine); 
  acedRegCmds->addCommand(_T("REVLISTSAMPLEAPP"), _T("ADDREVLINE"), _T("ADDREVLINE"), ACRX_CMD_MODAL, addRevLine); 
  
  // end initApp()
}

static void unLoadApp()
{
  acedRegCmds->removeGroup(_T(/*MSG0*/"REVLISTSAMPLEAPP"));

  // TODO: clean up your application

  // END unloadApp()
  EndMFC();
}

// MFC Initialization

#define APP_ARX_NAME _T(/*MSG0*/"TestRevisionList.arx")

void InitMFC()
{
  InitModule(GetModuleHandle(APP_ARX_NAME), DLL_PROCESS_ATTACH, NULL);
}

void EndMFC()
{
  InitModule(GetModuleHandle(APP_ARX_NAME), DLL_PROCESS_DETACH, NULL);
}

static AFX_EXTENSION_MODULE arxmfcDLL;

extern BOOL InitModule(HINSTANCE hInstance, DWORD dwReason, LPVOID)
{
  if (dwReason == DLL_PROCESS_ATTACH) {
    if (!AfxInitExtensionModule(arxmfcDLL, hInstance))
      return 0;

    CTemporaryResourceOverride::SetDefaultResource(GetModuleHandle(APP_ARX_NAME));
    // TODO: add other initialization tasks here

    // end of initialization
  } else if (dwReason == DLL_PROCESS_DETACH) {
    AfxTermExtensionModule(arxmfcDLL);
    // TODO: perform other cleanup tasks here

    // end of cleanup
  }
  return 1;
}

// END