#include "customgui_inexclude.h"
#include "c4d_string.h"
#include "c4d_gui.h"


static CustomGuiInExcludeLib *lib_inexclude = NULL;


static CustomGuiInExcludeLib *CheckLib(LONG offset)
{
	return (CustomGuiInExcludeLib*)CheckLib(CUSTOMGUI_INEXCLUDE_LIST, offset, (C4DLibrary**)&lib_inexclude);
}

#define InExcludeCall(b) 			CustomGuiInExcludeLib *lib = CheckLib(LIBOFFSET(CustomGuiInExcludeLib, b)); \
															if (!lib || !lib->b) return; \
															(((iIncludeExcludeData*)this)->*(lib->b))

#define InExcludeCallR(a,b) 		CustomGuiInExcludeLib *lib = CheckLib(LIBOFFSET(CustomGuiInExcludeLib, b)); \
															if (!lib || !lib->b) return a; \
															return (((iIncludeExcludeData*)this)->*(lib->b))

#define InExcludeGuiCall(b) 		CustomGuiInExcludeLib *lib = CheckLib(LIBOFFSET(CustomGuiInExcludeLib, b)); \
															if (!lib || !lib->b) return; \
															(((iInExcludeCustomGui*)this)->*(lib->b))

#define InExcludeGuiCallR(a,b) CustomGuiInExcludeLib *lib = CheckLib(LIBOFFSET(CustomGuiInExcludeLib, b)); \
															if (!lib || !lib->b) return a; \
															return (((iInExcludeCustomGui*)this)->*(lib->b))

#define IncludeTableCallR(a,b) 		CustomGuiInExcludeLib *lib = CheckLib(LIBOFFSET(CustomGuiInExcludeLib, b)); \
															if (!lib || !lib->b) return a; \
															return (((iInclusionTable*)this)->*(lib->b))

Bool InExcludeData::InsertObject(BaseList2D* pObject, LONG lFlags) { InExcludeCallR(NULL, InsertObject)(pObject, lFlags); }
LONG InExcludeData::GetObjectIndex(BaseDocument *doc, BaseList2D* pObject) { InExcludeCallR(-1, GetObjectIndex)(doc,pObject); }
Bool InExcludeData::DeleteObject(LONG lIndex) { InExcludeCallR(FALSE, DeleteObject)(lIndex); }
LONG InExcludeData::GetObjectCount() { InExcludeCallR(0, GetObjectCount)(); }
LONG InExcludeData::GetFlags(LONG lIndex) { InExcludeCallR(0, GetFlags)(lIndex); }
BaseList2D* InExcludeData::ObjectFromIndex(BaseDocument *doc, LONG lIndex) { InExcludeCallR(NULL, ObjectFromIndex)(doc,lIndex); }
InclusionTable* InExcludeData::BuildInclusionTable(BaseDocument *doc, LONG hierarchy_bit) { InExcludeCallR(NULL, BuildInclusionTable)(doc, hierarchy_bit); }
BaseContainer* InExcludeData::GetData(LONG lIndex) { InExcludeCallR(NULL, GetData)(lIndex); }

Bool InclusionTable::Check(BaseList2D *op) { IncludeTableCallR(FALSE, Check)(op); }
LONG InclusionTable::GetObjectCount() { IncludeTableCallR(FALSE, GetObjectCountT)(); }
BaseList2D* InclusionTable::GetObject(LONG lIndex) { IncludeTableCallR(FALSE, GetObject)(lIndex); }
void FreeInclusionTable(InclusionTable *&pTable)
{
	if (!pTable) return;
  CustomGuiInExcludeLib *lib = CheckLib(LIBOFFSET(CustomGuiInExcludeLib, LIB_FreeInclusionTable));
	if (!lib || !lib->LIB_FreeInclusionTable) return;
  InclusionTable* t = pTable;
  (lib->LIB_FreeInclusionTable)((iInclusionTable*)t);
  pTable = NULL;
}
