unit wDialogCreatorLOW2;

{ Feel free to use this unit as you want.
  First developped by Bernard Gisin
  This unit uses object programming to simplify the developpment
  of programs.

  This unit Creates a dialogbox from a description made in
  a text message file '.msg'
  This helps a lot creating dialog boxes.

  This unit has nearly no code, but the unit  wDialogCreatorLOW2.pp
  will overwrite all important methods.

  To create a dialog box, which description is in a  .msg  file,
  just call :
  DialogExecMSG(msgNumber, poParent);
  where  msgNumber  is the number in the  .msg  file describing the dialog,
  poParent  is the object window owning the dialog.
  It will return an int32, the value returned by dialog boxes.
  Usually,  IDOK (=1)  if the dialog was terminated with the  OK  button,
  IDCANCEL (=2) if the dialog was terminated with the  CANCEL  buton.

  Conclusion :
  1) This unit uses only low level units, i.e. units which doesn't use
     many units.
  2) But the methods of this unit will create dialog boxes, because they
     are overridden by the high level unit  wDialogCreatorLOW2.pp
----------------------------------}

// To tell FreePascal that the application is a Graphical User Interface
// i.e. is running in windows, not in text mode.
{$APPTYPE GUI}

INTERFACE
//"""""""

uses wWindowBase0, wGlobals2;

type
  PDialogCreatorLOW2 = ^TDialogCreatorLOW2;
  TDialogCreatorLOW2 = object
  //"""""""""""""""""""""""""

  constructor Init;
  // Call Init; at the beggining of a new Init constructor.

  destructor  Done; virtual;
  // Call Done; at the end of a new destructor.

  function DialogCreation(wMsgNum:word32; poParentP:PWindowBase):PWindowBase; virtual;
  // Will be overridden in the descendent  wDialogCreator2
  // It will create a dialog box from its description in the message file
  // and return a pointer on a  PDialog  object.
  // wMsgNum  is the number in the  .msg  file describing the dialog.
  // poParentP is a pointer on the object window owining this dialog.

  function ToolBarCreation(wMsgNum:word32; poParentP:PWindowBase):PWindowBase; virtual;
  // This is the main function, which creates the ToolBar object.
  // From a word32 number designing lines in the message file,
  // create a ToolBar, with controls in it,
  // and return a pointer on it.
  // poParentP is a pointer on the object window owning this ToolBar

  end; // TDialogCreator2 = object(DialogCreatorLOW2)
  TDialogCreatorLOW =  TDialogCreatorLOW2;
  PDialogCreatorLOW = ^TDialogCreatorLOW;

function DialogExecMSG(msgDial:word32; poParentP:PWindowBase):int32;
//==================================================================
// First creates a dialog creator.
// Then, with it and the number  msgDial  indicating a text dialog
// descriptor in the  .msg  file, creates an object dialog.
// Then execute the dialog window, and when the dialog is finished
// return the response of the dialog.
// poParentP = Owner of the dialog box.
// While the dialog exists,
// gglpoActiveDialog  will point on the object modal dialog

function DialogCreateMSG(msgDial:word32; poParentP:PWindowBase):PWindowBase;
//==========================================================================
// First creates a dialog creator.
// Then, with it and the number  msgDial  indicating a text dialog
// descriptor in the  .msg  file, creates an object dialog.
// Then create a Modeless dialog window.
// return a pointer on the modeless dialog.
// Usually it is useless, since the object dialog is disposed
// when the dilog window is destroyed.
// poParentP = Owner of the dialog box.
// While the dialog exists,
// gglpoActiveDialog  will point on the object dialog.

function ToolBarCreateMSG(msgTB:word32; poParentP:PWindowBase):PWindowBase;
//==============================================================
// First creates a dialog creator.
// Then, with it and the number  msgTB  indicating a text tool bar
// descriptor in the  .msg  file, creates an object ToolBar.
// Then create a ToolBar window.
// It will be a child object window of poParentP
// return a pointer on the ToolBar.
// Usually it is useless, since the object ToolBar is disposed
// when the Parent is destroyed.
// poParentP = Owner of the ToolBar.

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

uses wObjectCreatorLow2;

var glnNotUsed : integer; // To avoid an error in the DevPascal 1.9 environment

function DialogExecMSG(msgDial:word32; poParentP:PWindowBase):int32;
//==================================================================
// First creates a dialog creator.
// Then, with it and the number  msgDial  indicating a text dialog
// descriptor in the  .msg  file, creates an object dialog.
// Then execute the dialog window, and when the dialog is finished
// return the response of the dialog.
// poParentP = Owner of the dialog box.
// While the dialog exists,
// gglpoActiveDialog  will point on the object modal dialog
var
  poDialCr    : PDialogCreatorLOW;
  poDialogL   : PWindowBase;
begin
// Creates the dialog creator, and initialises it.
poDialCr:=gglpoObjCreate^.CreateDialogCreator;

// Creates the dialog, and return a pointer on it.
poDialogL:=poDialCr^.DialogCreation(msgDial, poParentP);

// We have the dialog, the dialog creator can be disposed.
dispose(poDialCr, Done);

// Test if the dialog was well created.
DialogExecMSG:=-1;
if (poDialogL = NIL) then exit; // error creating the dialog.

// Here I have a pointer on an object dialog,
// I want to execute the corresponding dialog,
// but I don't want to "uses" the  wDialog0.pp  unit.
// Thus I will ask the object creator to execute the dialog.
DialogExecMSG:=gglpoObjCreate^.DialogExecute(poDialogL);

// I don't need the dialog any more
// dispose(poDialogL, Done); it is disposed automatically
end;  // DialogExecMSG

function DialogCreateMSG(msgDial:word32; poParentP:PWindowBase):PWindowBase;
//==========================================================================
// First creates a dialog creator.
// Then, with it and the number  msgDial  indicating a text dialog
// descriptor in the  .msg  file, creates an object dialog.
// Then create a Modeless dialog window.
// return a pointer on the modeless dialog.
// Usually it is useless, since the object dialog is disposed
// when the dilog window is destroyed.
// poParentP = Owner of the dialog box.
// While the dialog exists,
// gglpoActiveDialog  will point on the object dialog.
var
  poDialCr    : PDialogCreatorLOW;
  poDialogL   : PWindowBase;
begin
// Creates the dialog creator, and initialises it.
poDialCr:=gglpoObjCreate^.CreateDialogCreator;

// Creates the dialog, and return a pointer on it.
poDialogL:=poDialCr^.DialogCreation(msgDial, poParentP);

// We have the dialog, the dialog creator can be disposed.
dispose(poDialCr, Done);

// Return a pointer on the created object dialog.
DialogCreateMSG:=poDialogL;

// Test if the dialog was well created.
if (poDialogL = NIL) then exit; // error creating the dialog.

// Here I have a pointer on an object dialog,
// I want to create the corresponding dialog window,
// but I don't want to "uses" the  wDialog0.pp  unit.
// Thus I will ask the object creator to create the dialog window.
gglpoObjCreate^.DialogCreate(poDialogL);

// I don't need the dialog any more
// dispose(poDialogL, Done); it is disposed automatically
end;  // DialogCreateMSG

function ToolBarCreateMSG(msgTB:word32; poParentP:PWindowBase):PWindowBase;
//=========================================================================
// First creates a dialog creator.
// Then, with it and the number  msgTB  indicating a text tool bar
// descriptor in the  .msg  file, creates an object ToolBar.
// Then create a ToolBar window.
// It will be a child object window of poParentP
// return a pointer on the ToolBar.
// Usually it is useless, since the object ToolBar is disposed
// when the Parent is destroyed.
// poParentP = Owner of the ToolBar.
var
  poDialCr    : PDialogCreatorLOW;
  poTBarL     : PWindowBase;

begin
// Creates the dialog & ToolBar creator, and initialises it.
poDialCr:=gglpoObjCreate^.CreateDialogCreator;

// Creates the ToolBar, and return a pointer on it.
poTBarL:=poDialCr^.ToolBarCreation(msgTB, poParentP);

// We have the ToolBar, the dialog & ToolBar creator can be disposed.
dispose(poDialCr, Done);

// Return a pointer on it, if one want to use it.
// It will be disposed automatically, when the window owner is disposed.
ToolBarCreateMSG:=poTBarL;

// Test if the ToolBar was well created.
if (poTBarL = NIL) then exit; // error creating the ToolBar.

// Here I have a pointer on an object ToolBar,
// I want to create the corresponding ToolBar window,
// but I don't want to "uses" the  wToolBar0.pp  unit.
// Thus I will ask the object creator to create the ToolBar window.
gglpoObjCreate^.ToolBarCreate(poTBarL);
end;  // ToolBarCreateMSG

//***************************************************
// TDialogCreatorLOW2 = object
//***************************************************

constructor TDialogCreatorLOW2.Init;
//==================================
begin
end;  // TDialogCreatorLOW2.Init

destructor TDialogCreatorLOW2.Done;
//=================================
begin
end;  // TDialogCreatorLOW2.Done

function TDialogCreatorLOW2.DialogCreation(wMsgNum:word32; poParentP:PWindowBase):PWindowBase;
//============================================================================================
begin
wMsgNum:=wMsgNum;  poParentP:=poParentP;  // to avoid hints.
DialogCreation:=NIL;
end;  // TDialogCreatorLOW2.DialogCreation

function TDialogCreatorLOW2.ToolBarCreation(wMsgNum:word32; poParentP:PWindowBase):PWindowBase;
//=============================================================================================
begin
wMsgNum:=wMsgNum;  poParentP:=poParentP;  // to avoid hints.
ToolBarCreation:=NIL;
end;  // TDialogCreatorLOW2.ToolBarCreation


end.  // unit wDialogCreatorLOW2;

