unit wObjectCreator2;

{ Feel free to use this unit as you want.
  First developped by Bernard Gisin

  The idea of this unit is that objects like  Windows  EditBox etc.
  which are created in the library, can be objects you defined
  in your main application.
  The library will call
  gglpoObjCreate^.xxx  to create a new object, where  'xxx'  represent
  the object to be created.
  Thus if  gglpoObjCreate  points to a descendent of  TObjectCreator2
  defined in your application, it will create the object as you want.

  For example, the  TApplication0  object creates  an TParamApplic2
  object. But by creating it through calling
  gglpoObjCreate^.
  you can make that a descendent of  TParamApplic2  is created insead.
  ----------------------------------------------------------------}

INTERFACE
//"""""""

uses wObjectCreatorLOW2;

type
  // usually, the object creator is overriden to allow the library to
  // create objects from your own application.
  PObjectCreator2 = ^TObjectCreator2;
  TObjectCreator2 = object(TObjectCreatorLOW2)
  //""""""""""""""""""""""""""""""""""""""""""
  constructor Init;
  destructor  Done; virtual;

  // All these methodes can be overriden to point on a descendent.

  function CreateParamApplic:Pointer; virtual;
  // the pointer will be on a TParamApplic or descendent object

  function CreateMDIClientWindow(poParent:Pointer):Pointer; virtual;
  // the pointer will be on a TMDIClientWindow or descendent object

  function CreateWindowText(strS:ShortString):Pointer; virtual;
  // the pointer will be on a TWindowText or descendent object

  function CreateMenu(poParent:Pointer):Pointer; virtual;
  // the pointer will be on a TMenus or descendent object

  function CreateDialogCreator:Pointer; virtual;
  // the pointer will be on a TDialogCreator or descendent object

  function CreateDialog(poParent:Pointer):Pointer; virtual;
  // the pointer will be on a TDialog or descendent object

  function CreateToolBar(poParent:Pointer):Pointer; virtual;
  // the pointer will be on a TToolBar or descendent object

  function DialogExecute(poDialogP:Pointer):longint; virtual;
  // This will execute the dialog box which is pointed by poDialogP
  // No type checking can be made to be sure that  poDialog
  // really points on a dialog. It is assumed that it does.

  procedure DialogCreate(poDialogP:Pointer); virtual;
  // This will create the dialog window which is pointed by poDialogP
  // No type checking can be made to be sure that  poDialog
  // really points on a dialog. It is assumed that it does.

  procedure ToolBarCreate(poTBarP:Pointer); virtual;
  // This will create the Toolbar window which is pointed by poTBarP
  // No type checking can be made to be sure that  poTBarP
  // really points on a Toolbar. It is assumed that it does.

  function CreateButtonPush(poParent:Pointer):Pointer; virtual;
  // the pointer will be on a TButtonPush or descendent object

  function CreateButtonBitMap(poParent:Pointer):Pointer; virtual;
  // the pointer will be on a TButtonBitMap or descendent object

  function CreateButtonRadio(poParent:Pointer):Pointer; virtual;
  // the pointer will be on a TButtonRadio or descendent object

  function CreateButtonCheck(poParent:Pointer):Pointer; virtual;
  // the pointer will be on a TButtonCheck or descendent object

  function CreateComboBox(poParent:Pointer):Pointer; virtual;
  // the pointer will be on a TComboBox or descendent object

  function CreateEditBox(poParent:Pointer):Pointer; virtual;
  // the pointer will be on a TEditBox or descendent object

  function CreateRichText(poParent:Pointer):Pointer; virtual;
  // the pointer will be on a TRichText or descendent object

  function CreateStatic(poParent:Pointer):Pointer; virtual;
  // the pointer will be on a TStatic or descendent object

  function CreatePopupWindow(poParent:Pointer):Pointer; virtual;
  // the pointer will be on a TPopupWindow or descendent object

  function CreateBody3D(poParent:Pointer):Pointer; virtual;
  // the pointer will be on a TBody3D0 or descendent object

  function CreateMatrixRNMFloat(bFamillyP:byte):Pointer; virtual;
  // the pointer will be on a TMatrixRNMFloat or descendent object

  end; // TObjectCreator2 = object
  TObjectCreator =  TObjectCreator2;
  PObjectCreator = ^TObjectCreator;

// pointer to the object creator. Defined in  wObjectCreaorLOW2
// const gglpoObjCreate : PObjectCreatorLOW2 = NIL;

IMPLEMENTATION
//""""""""""""

uses wDraw3DFrame0, wMDIClientWindow0, wWindowText0, wMenus0,
     wDialogCreator2, wToolBar0, wDialog0,
     wButtonPush0, wButtonBitMap0, wButtonRadio0, wButtonCheck0,
     wComboBox0, wEditBox0, wRichText0, wStatic0,
     wPopupWindow0, wParamApplic2,
     xMatrixRN, wErrors0, wDebug0, wGlobals2;

var nNotUsed : integer; // only to avoid an error message while compliling in DevPascal 1.9

constructor TObjectCreator2.Init;
//===============================
begin
inherited Init;
end;  // TObjectCreator2.Init

destructor  TObjectCreator2.Done;
//===============================
begin
inherited Done;
end;  // TObjectCreator2.Done

function TObjectCreator2.CreateParamApplic:Pointer;
//=================================================
var poObj : PParamApplic2;
begin
new(poObj, Init);
CreateParamApplic:=poObj;
end;  // TObjectCreator2.CreateParamApplic

function TObjectCreator2.CreateMDIClientWindow(poParent:Pointer):Pointer;
//==========================================================================
var poObj : PMDIClientWindow;
begin
new(poObj, Init(poParent));
CreateMDIClientWindow:=poObj;
end;  // TObjectCreator2.CreateMDIClientWindow

function TObjectCreator2.CreateWindowText(strS:ShortString):Pointer;
//==================================================================
var poObj : PWindowText;
begin
new(poObj, Init(strS));
CreateWindowText:=poObj;
end;  // TObjectCreator2.CreateWindowText

function TObjectCreator2.CreateMenu(poParent:Pointer):Pointer;
//============================================================
var poObj : PMenu;
begin
new(poObj, Init(poParent));
CreateMenu:=poObj;
end;  // TObjectCreator2.CreateMenu

function TObjectCreator2.CreateDialogCreator:Pointer;
//===================================================
var poObj : PDialogCreator2;
begin
new(poObj, Init);
CreateDialogCreator:=poObj;
end;  // TObjectCreator2.CreateDialogCreator

function TObjectCreator2.CreateDialog(poParent:Pointer):Pointer;
//==============================================================
var poObj : PDialog;
begin
new(poObj, Init(poParent));
CreateDialog:=poObj;
end;  // TObjectCreator2.CreateDialog

function TObjectCreator2.CreateToolBar(poParent:Pointer):Pointer;
//===============================================================
var poObj : PToolBar;
begin
new(poObj, Init(poParent));
CreateToolBar:=poObj;
end;  // TObjectCreator2.CreateToolBar

function TObjectCreator2.DialogExecute(poDialogP:Pointer):longint;
//================================================================
// This will execute the dialog box which is pointed by poDialogP
// No type checking can be made to be sure that  poDialog
// really points on a dialog. It is assumed that it does.
var
  poDial : PDialog;
begin
DialogExecute:=-1;
if (poDialogP = NIL) then exit; // Not normal

// We assume the pointer is on a object dialog.
poDial:=poDialogP;

// Check that  poDial^.wWindowType = GGLCTE_A_DIALOG_Modal or
// poDial^.wWindowType = GGLCTE_A_DIALOG_Modeless
if (poDial^.wWindowType <> GGLCTE_A_DIALOG_Modal) and
   (poDial^.wWindowType <> GGLCTE_A_DIALOG_Modeless) then begin
   // It is an error
   ErrorWrite(1, 'in TObjectCreator2.DialogExecute');
   ErrorComment(1, 'try to execute a dialog, but the pointer doesn''t point on a dialog');
   exit;
   end;

DialogExecute:=poDial^.DialogExec;
end;  // TObjectCreator2.DialogExecute

procedure TObjectCreator2.DialogCreate(poDialogP:Pointer);
//========================================================
// This will create the dialog window which is pointed by poDialogP
// No type checking can be made to be sure that  poDialog
// really points on a dialog. It is assumed that it does.
var
  poDial : PDialog;
begin
if (poDialogP = NIL) then exit; // Not normal

// We assume the pointer is on a object dialog.
poDial:=poDialogP;

// Check that  poDial^.wWindowType = GGLCTE_A_DIALOG_Modal or
// poDial^.wWindowType = GGLCTE_A_DIALOG_Modeless
if (poDial^.wWindowType <> GGLCTE_A_DIALOG_Modal) and
   (poDial^.wWindowType <> GGLCTE_A_DIALOG_Modeless) then begin
   // It is an error
   ErrorWrite(1, 'in TObjectCreator2.DialogCreate');
   ErrorComment(1, 'try to create a dialog, but the pointer doesn''t point on a dialog');
   exit;
   end;

poDial^.DialogCreate;
end;  // TObjectCreator2.DialogCreate

procedure TObjectCreator2.ToolBarCreate(poTBarP:Pointer);
//=======================================================
// This will create the Toolbar window which is pointed by poTBarP
// No type checking can be made to be sure that  poTBarP
// really points on a Toolbar. It is assumed that it does.
var
  poTBar : PToolBar;
begin
if (poTBarP = NIL) then exit; // Not normal

// We assume the pointer is on a object Toolbar.
poTBar:=poTBarP;

// Check that  poTBar^.wWindowType = GGLCTE_ToolBar
if (poTBar^.wWindowType <> GGLCTE_ToolBar) then begin
   // It is an error
   ErrorWrite(1, 'in TObjectCreator2.ToolBarCreate');
   ErrorComment(1, 'try to create a Toolbar, but the pointer doesn''t point on a Toolbar');
   exit;
   end;

// Create the toolBar
poTBar^.ToolBarCreate;
end;  // TObjectCreator2.ToolBarCreate

function TObjectCreator2.CreateButtonPush(poParent:Pointer):Pointer;
//==================================================================
var poObj : PButtonPush;
begin
new(poObj, Init(poParent));
CreateButtonPush:=poObj;
end;  // TObjectCreator2.CreateButtonPush

function TObjectCreator2.CreateButtonBitMap(poParent:Pointer):Pointer;
//====================================================================
var poObj : PButtonBitMap;
begin
new(poObj, Init(poParent));
CreateButtonBitMap:=poObj;
end;  // TObjectCreator2.CreateButtonBitMap

function TObjectCreator2.CreateButtonRadio(poParent:Pointer):Pointer;
//===================================================================
var poObj : PButtonRadio;
begin
new(poObj, Init(poParent));
CreateButtonRadio:=poObj;
end;  // TObjectCreatorLOW2.CreateButtonRadio

function TObjectCreator2.CreateButtonCheck(poParent:Pointer):Pointer;
//===================================================================
var poObj : PButtonCheck;
begin
new(poObj, Init(poParent));
CreateButtonCheck:=poObj;
end;  // TObjectCreator2.CreateButtonCheck

function TObjectCreator2.CreateComboBox(poParent:Pointer):Pointer;
//================================================================
var poObj : PComboBox;
begin
new(poObj, Init(poParent));
CreateComboBox:=poObj;
end;  // TObjectCreator2.CreateComboBox

function TObjectCreator2.CreateEditBox(poParent:Pointer):Pointer;
//================================================================
var poObj : PEditBox;
begin
new(poObj, Init(poParent));
CreateEditBox:=poObj;
end;  // TObjectCreator2.CreateEditBox

function TObjectCreator2.CreateRichText(poParent:Pointer):Pointer;
//================================================================
var poObj : PRichText;
begin
new(poObj, Init(poParent));
CreateRichText:=poObj;
end;  // TObjectCreator2.CreateRichText

function TObjectCreator2.CreateStatic(poParent:Pointer):Pointer;
//==============================================================
var poObj : PStatic;
begin
new(poObj, Init(poParent));
CreateStatic:=poObj;
end;  // TObjectCreator2.CreateStatic

function TObjectCreator2.CreatePopupWindow(poParent:Pointer):Pointer;
//==============================================================
var poObj : PPopupWindow;
begin
new(poObj, Init(poParent));
CreatePopupWindow:=poObj;
end;  // TObjectCreator2.CreatePopupWindow

function TObjectCreator2.CreateBody3D(poParent:Pointer):Pointer;
//==============================================================
var poObj : PBody3D0;
begin
new(poObj, Init(poParent));
CreateBody3D:=poObj;
end;  // TObjectCreator2.CreateBody3D

function TObjectCreator2.CreateMatrixRNMFloat(bFamillyP:byte):Pointer;
//====================================================================
var poObj : PMatrixRNMFloat;
begin
new(poObj, Init(bFamillyP));
CreateMatrixRNMFloat:=poObj;
end;  // TObjectCreator2.CreateMatrixRNMFloat

End.  // unit wObjectCreator2;

