//
#ifndef ACMTITLE_H
#define ACMTITLE_H
//
//  (C) Copyright 1994-2008 by Autodesk, Inc.  All rights reserved.
//
// 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.
//

#include "rxsrvice.h"
#include "gepnt3d.h"
#include "dbid.h"
#include "dbidar.h"

// forward declarations
class AcMgTitleBorder;
class AcMgTitleSetting;
class AcMgTitleSpaceIterator;
class AcMgTitleBorderMgr;
class AcMgTitleOpSettings;
class AcMgTitleDatum;
class AcMgTitleEventReactor;

class AcDbBlockTableRecord;
class AcDbExtents;

#ifdef AMGTITLEBUILD
#define AMGTITLE_DLLSHARE __declspec(dllexport)
#else
#define AMGTITLE_DLLSHARE __declspec(dllimport)
#endif

// Class for one and only title border manager
class AMGTITLE_DLLSHARE AcMgTitleBorderMgr : public AcRxService
{
public:
  virtual ~AcMgTitleBorderMgr(){}
  virtual bool DeleteTitleBorder(AcDbObjectId) = 0;
  virtual AcMgTitleBorder* GetTitleBorderFromRef(AcDbObjectId&) = 0;
  virtual AcMgTitleBorder* GetTitleBorderFromObj(const AcDbObjectId) = 0;
  virtual AcDbObjectId CreateTitleBorder(AcMgTitleBorder *pTB = NULL,
    AcMgTitleOpSettings *pSet = NULL,AcDbDatabase *pDb = NULL) = 0;
  virtual AcMgTitleBorder *NewDescriptor(AcDbDatabase *pDb = NULL) = 0;
  virtual AcMgTitleOpSettings *NewContext(bool bNewTB = true,AcDbDatabase *pDb = NULL) = 0;
  virtual AcMgTitleSpaceIterator *newAmgTitleSpaceIterator() = 0;
  virtual AcMgTitleDatum *NewDatum(const TCHAR *key, const TCHAR *cval)= 0;
  virtual AcMgTitleSetting *NewSetting() = 0;
  virtual void addEventReactor( AcMgTitleEventReactor* pReac ) = 0;
  virtual void removeEventReactor() = 0;
};

// Interface class for handling all settings for inserting title block
class AMGTITLE_DLLSHARE AcMgTitleOpSettings
{
public:               
  virtual const AcMgTitleSetting&   Scale()      const = 0;
  virtual const AcMgTitleSetting&   Border()     const = 0;
  virtual const AcMgTitleSetting&   TitleBlock() const = 0;
  virtual const AcMgTitleSetting&   Move()       const = 0;
  virtual const AcMgTitleSetting&   Thaw()       const = 0;
  virtual const AcMgTitleSetting&   baseScale()  const = 0;
  virtual const AcMgTitleSetting&   dwgDefaultSet()      const = 0;
  virtual const AcMgTitleSetting&   automaticPlacement() const = 0;
  virtual const AcMgTitleSetting&   Rescale()  const = 0;
  virtual const AcMgTitleSetting&   Retrieve() const = 0;
  virtual const AcMgTitleSetting&   RetrieveA() const = 0;
  virtual const AcMgTitleSetting&   Additional(int iIndex) const = 0;

  virtual bool setAdditional(const AcMgTitleSetting&,bool check = true,int iIndex = 0) = 0;
  virtual bool setScale(const AcMgTitleSetting& set,bool check = true) = 0;
  virtual bool setScale(const TCHAR *pscale, bool check = true) = 0;
  virtual bool setBorder(const AcMgTitleSetting&,bool check = true) = 0;
  virtual bool setTitleBlock(const AcMgTitleSetting&,bool check = true) = 0;
  virtual bool setMove(const AcMgTitleSetting&) = 0;
  virtual bool setMoveObjects(const AcDbObjectIdArray&, const AcGePoint3d&) = 0;
  virtual bool setThaw(const AcMgTitleSetting&) = 0;
  virtual bool setBaseScale(const AcMgTitleSetting&) = 0;
  virtual bool setDwgDefaultSet(const AcMgTitleSetting&) = 0;
  virtual bool setAutomaticPlacement(const AcMgTitleSetting&) = 0;
  virtual bool setRescale(const AcMgTitleSetting&) = 0;
  virtual bool setRetrieve(const AcMgTitleSetting&) = 0;
  virtual bool setRetrievePartRef(const AcDbObjectId&) = 0;
  virtual bool setRetrieveA(const AcMgTitleSetting&) = 0;
  virtual bool enableMove(bool bMovEn = true) = 0;
  virtual bool enablePosInput(bool bPosEn = true) = 0;
  virtual bool enableTitleInput(bool bTitleEn = true) = 0;
  virtual bool enableBorderInput(bool bBorderEn = true) = 0;
  virtual bool enableAttrInput(bool bAttEn = true) = 0;
  virtual bool enableScaleInput(bool bScaleEn = true) = 0;
  virtual bool enableUserInput(bool bUserEn = true) = 0;
  virtual bool PosInput() = 0;
  virtual bool AttrInput() = 0;

  virtual bool userInput() const = 0;
  virtual bool movedObjects(AcDbObjectIdArray& objIds, AcGePoint3d& toPts) const = 0;
  virtual const AcDbObjectId retrievedPartRef() const = 0;

  virtual void addRef() = 0;
  virtual void release() = 0;
protected:
  ~AcMgTitleOpSettings(){}
};

// Interface class for handle one setting for inserting title block
class AMGTITLE_DLLSHARE AcMgTitleSetting
{
public:
  virtual ~AcMgTitleSetting(){}
  virtual bool isVisible() const = 0;
  virtual bool hasWriteAccess() const = 0;
  virtual VARIANT& value() const = 0;

  virtual void setVisible(bool) = 0;
  virtual bool setWriteAccess(bool) = 0;
  virtual bool setValue(VARIANT&) = 0;
  virtual bool setValue(const TCHAR *) = 0;
  virtual bool setValue(bool) = 0;
  virtual bool setValue(double) = 0;
};

// Interface class for handling data stored to title or border
class AMGTITLE_DLLSHARE AcMgTitleDatum
{
public:
  virtual ~AcMgTitleDatum(){}
  virtual CString key() const = 0;
  virtual void setKey(const TCHAR *) = 0;
  virtual bool IsProtected() = 0;
  virtual void Protect(bool) = 0;
  virtual bool isChanged() = 0;
};

// Interface class for handling strings stored to title or border
class AMGTITLE_DLLSHARE AcMgTitleString : public AcMgTitleDatum
{
public:
  virtual CString key() const = 0;
  virtual void setKey(const TCHAR *) = 0;
  virtual bool IsProtected() = 0;
  virtual void Protect(bool) = 0;
  virtual TCHAR *value() = 0;
  virtual void setValue(const TCHAR *pVal) = 0;
  virtual bool isChanged() = 0;
};

// Interface class for handling doubles stored to title or border
class AMGTITLE_DLLSHARE AcMgTitleReal : public AcMgTitleDatum
{
public:
  virtual CString key() const = 0;
  virtual void setKey(const TCHAR *) = 0;
  virtual bool IsProtected() = 0;
  virtual void Protect(bool) = 0;
  virtual double value() const = 0;
  virtual void setValue(double) = 0;
  virtual bool isChanged() = 0;
};

// Interface class for iterator of AcMgTitleDatum object
class AMGTITLE_DLLSHARE AcMgTitleDataIterator
{
public:
  virtual ~AcMgTitleDataIterator(){}
  virtual bool next() = 0;
  virtual bool toFirst() = 0;
  virtual AcMgTitleDatum* const & current() const = 0;
  virtual CString key() = 0;
};

// Interface class for a title/border component object
class AMGTITLE_DLLSHARE AcMgTitleComp
{
public:
  virtual    ~AcMgTitleComp(){}
  virtual    const CString& Name() const = 0;
  virtual    void setName(const CString& szName, bool check = true) = 0;
  virtual    AcMgTitleDatum* datumAt(const TCHAR *key) = 0;
  virtual    Acad::ErrorStatus removeDatum(const TCHAR *key) = 0;
  virtual    Acad::ErrorStatus insertDatum(AcMgTitleDatum* datum) = 0;
  virtual    AcMgTitleDataIterator *newIterator() = 0;
  virtual    bool isDataEmpty() = 0;
  virtual    int InitDatafromCompDef() = 0;
  virtual    AcDbObjectId ObjectId() = 0;
  virtual    Acad::ErrorStatus deactivate(AcDbObjectId ObjId = AcDbObjectId::kNull) = 0;
  virtual    Acad::ErrorStatus getPosition(AcGePoint3d&) = 0;
  virtual    int DataCount() = 0;
  virtual    void removeAllData() = 0;
};

// Interface class for a border component object
class AMGTITLE_DLLSHARE AcMgBorder :  public AcMgTitleComp                       
{
  virtual ~AcMgBorder(){}
};

// Interface class for a title component object
class AMGTITLE_DLLSHARE AcMgTitle : public AcMgTitleComp
{
  virtual ~AcMgTitle(){}
};

// Interface class for a title/border object
class AMGTITLE_DLLSHARE AcMgTitleBorder 
{
public:
  virtual Acad::ErrorStatus appendToSpace(AcDbBlockTableRecord* pBTR = NULL, 
    AcMgTitleOpSettings* pSettings = NULL,
    bool userAction = false,
    AcDbDatabase *pDb = NULL) = 0;
  virtual Acad::ErrorStatus modify(AcMgTitleOpSettings *pSet = NULL,
    bool  userAction = false) = 0;
  virtual Acad::ErrorStatus deactivateTitle(AcMgTitle *pTitle = NULL) = 0;
  virtual Acad::ErrorStatus activateTitle() = 0;
  virtual bool IsTitleDeactivated() = 0;
  virtual AcMgTitle& title() = 0;
  virtual AcMgTitle& additional(int iIndex) = 0;
  virtual AcMgBorder& border() = 0;
  virtual double scale() = 0;
  virtual void setScaleVal(double) = 0;
  virtual AcDbObjectId GetObjectId() = 0;
  virtual void setPosition(AcGePoint3d) = 0;
  virtual Acad::ErrorStatus getPosition(AcGePoint3d&) = 0;
  virtual Acad::ErrorStatus editAttr() = 0;
  virtual void addRef() = 0;
  virtual void release() = 0;
  virtual void GetExtents(AcDbExtents&) = 0;
  virtual AcDbObjectId GetLayoutId() const = 0;
protected:
  ~AcMgTitleBorder(){};
};

// Interface class for an iterator of all title/border objects
class AMGTITLE_DLLSHARE AcMgTitleSpaceIterator
{
public:
  virtual ~AcMgTitleSpaceIterator(){}
  virtual void setSuspend(bool) = 0;
  virtual Acad::ErrorStatus next() = 0;
  virtual bool done() = 0;
  virtual Acad::ErrorStatus toFirst() = 0;
  virtual Acad::ErrorStatus current(AcDbObjectId&) = 0;
  virtual int count() = 0;
  virtual Acad::ErrorStatus item(int) = 0;
};

// Interface for event notification callbacks for actions in title/border objects
class AcMgTitleEventReactor
{
public:
  virtual ~AcMgTitleEventReactor() {}
  virtual void eventTitleBorderCreateBegin(AcMgTitleBorder*,
    AcMgTitleOpSettings*,
    bool *veto)
  {
  }
  virtual void eventTitleBorderCreateStarts(AcMgTitleBorder*,
    bool *veto)
  {
  }
  virtual void eventTitleBorderCreateComplete(AcDbObjectId&)
  {
  }
  virtual void eventTitleBorderModifyBegin(AcMgTitleBorder*,
    AcMgTitleOpSettings*,
    bool *veto)
  {
  }
  virtual void eventTitleBorderModifyStarts(AcMgTitleBorder*,
    AcMgTitleOpSettings*,
    bool *veto)
  {
  }
  virtual void eventTitleBorderModifyComplete(AcDbObjectId&)
  {
  }
  virtual void eventTitleBorderModifyCancelled(AcDbObjectId&)
  {
  }
  virtual void eventTitleBorderBeforeDataEdit(AcMgBorder *, AcMgTitle *)
  {
  }
};

#define ACMG_TITLE_SERVICE _T(/*MSG0*/"AcMgTitleService")
#define pAcMgTitleBorderMgr ((AcMgTitleBorderMgr*)AcRxService::cast(acrxServiceDictionary->at( ACMG_TITLE_SERVICE )))

#endif //ACMTITLE_H
