#if !defined(__alffnmdc_h)              // Sentry, use file only if it's not already included.
#define __alffnmdc_h
/*  Project Tec3270

	 SUBSYSTEM:    Tec3270.exe (Tec3270 application)
	 FILE:         alffnmdc.h
	 AUTHOR:       Alcindo Ferreira Filho

	 OVERVIEW:

    ALFFMDIClient Class Definition, the Tec3270 MDI sessions,
    class manager. Sessions are childs of this class.

    COPYRIGHT:    © 1998-2007
                  Alcindo Ferreira Filho
                  <alcindo@inttec.com.br>

    LICENSE:      Tec3270_License (docs/Tec3270_License.txt)
*/

#include <owl\owlall.h>
#include "alffnaux.h"  /* Auxiliary Definitions Print/Screen Fields */
#include "alffprtn.h"  /* Printer Definitions */
#include "alffntsc.h"  /* Screen Definitions*/
#include "alff3270.h"  /* 3270 Buffer Manager Object */
#include "ALFFNvt.h"   /* NVT Buffer Manager Object */

/* TecLib Includes */
#include "alffmsgs.h"  /* StringTable Mngmt and Messages */
#include "alffkpad.h"  /* Keyboard Pad Class */
#include "alffinif.h"  /* IniFile Base Class */
#include "alffddes.h"

/* TecSecurity Library Includes */
#include "alffcertadm.h"  /* StringTable Mngmt and Messages */

/* WHLLAPI Lib */
#include "whllcli.h"

// Tec3270 WHLLAPI controls
#define MAXWHLLSESSIONS    8
#define MAXWHLLAPPS        4


//{{TMDIClient = ALFFMDIClient}}
class ALFFMDIClient : public TMDIClient, public ALFFDdeServer
{
 public:
	 ALFFMDIClient(TModule* module = 0);
	 virtual ~ALFFMDIClient ();

    /* End of Tec3270 */
	 void CmExit();

	 /* Windows Movement Control Event */
	 void CmMove(bool maximized, bool iconic);
	 void CreateChildList(TWindow* win);

	 bool IsMonitoring();
    void DecrementNumChild() {ChildActive--;};
	 ALFFPrtData*    prtData;

/* ------------ DDE Server Inherited Methods --------------- */
 public:

    bool IsAdvising() {return (advising != 0); }

 protected:

    bool far StartServerAdvise(HCONV convId, HSZ item);
    bool far StopServerAdvise(HCONV convId, HSZ item);
    bool far ProvidesItem(HSZ queryItem);
    HDDEDATA far ReturnData(HCONV convId, HSZ item);
    int      GetHLLSessionPtr(char* sessName);
    int      GetHLLAppPtr(HCONV appId);
    HDDEDATA far ReceivedData(HCONV convId, HSZ item, HDDEDATA hCommand);

    // Cleanup: DDE Client App Disconnect
    void NotifyDisconnect(HCONV appId);
    void CleanupHLLSession(int appHLLSession);

    int advising;
    HSZ itemWHLLCommand;
    int wHllSessionCount;

    // User Certificate FilePath and Password (it will be destructed after
    //  being used on CONNECTPS):
    char*              hllCertPath;
    char*              hllCertPwd;

    // WHLL Client Applications controls
    HCONV              hllApp[MAXWHLLAPPS];
    int                hllSessionIndex[MAXWHLLAPPS];
    bool               hllAppConnected[MAXWHLLAPPS];
    HDDEDATA           outData[MAXWHLLAPPS+1];
    TecWHLLAppParms*   wHllAppOptions[MAXWHLLAPPS];

    // WHLL Sessions controls
    TMDIChild*         hllSessions[MAXWHLLSESSIONS];
    char*              hllSessionName[MAXWHLLSESSIONS];
    int                hllSessionPsShare[MAXWHLLSESSIONS];
    int                appsConnected[MAXWHLLSESSIONS];
    HCONV              ownerAppId[MAXWHLLSESSIONS];
    int                ownerAppIndex[MAXWHLLSESSIONS];
/*-----------------------------------------------------------*/

//{{ALFFMDIClientVIRTUAL_BEGIN}}
 protected:
	 virtual void 	SetupWindow ();
	 void         	SaveKeyPadStatus();
	 int  			ChildCount;  /* Number of child window already created */
	 int  			ChildActive; /* Number of child actually active */

//{{ALFFMDIClientVIRTUAL_END}}

//{{ALFFMDIClientRSP_TBL_BEGIN}}
 protected:
	 ALFFDate::DateFormat  	dateFormat;
	 ALFFMsgs* 					pMsgs;
	 ALFFKeyPad*  				KeyPad;
	 bool             		monitoring;
	 TArray<long>     		childList;
	 uint             		childPtr;
	 long             		monitorTimeOut;
	 long             		monitorTimeInterval;

    // Internal Methods
	 void Monitor(long win );//TWindow* win);
    void SetToolsMonitorMenu(bool onstatus, TMDIChild* curChild);
	 bool CreatePrinter();
    bool CreatePrinterBuffer();
	 bool StorePrtPageHdr(const char * hdrText, int lineSize);
	 bool DeletePageHdr();
	 bool StorePrtFields(ALFFVirtualTerm* pTerm, ALFFNvt* pNVT,
								ALFF3270* p3270);
	 bool StorePrtSelText(ALFFVirtualTerm* pTerm,ALFFNvt* pNVT,
	                      ALFF3270* p3270);

	 /* Session Menu Command Handlers */
    char* sessName;  		// Session Name used on Automated and WHLLApi Sessions
	 void  CmNewSession ();
    TMDIChild* CreateSession(char* sessionName, bool isWHLL=false,
                             char* certPath=NULL, char* certPwd=NULL); // called from CmNewSession
	 void  CmCloseSession ();
    bool  CloseSession(TMDIChild* child);
	 void  CmPrint ();
	 void  CmPrintSetup ();
	 void  CmPrintPreview ();
	 void  CmOneChildEnable (TCommandEnabler &ce);
	 void  CmPrintEnable (TCommandEnabler &tce);
	 void  CmPrintPreviewEnable (TCommandEnabler &tce);

	 /* Options Menu Command Handlers */
	 void  CmChooseFont();
	 void  CmChoosePrtFont();
	 void  CmChooseColors();
	 void  CmKeyboard();
	 void  CmOptionsKeyPad();
	 void  CmOptionsConfigSessions();
	 void  CmOptionsAutomat();
	 void  CmToolsMonitor();
    void  CmSecurityAdminCerts();
    void  CmSecurityOptions();

	 void  CmToolsMonitorEnable(TCommandEnabler &ce);
	 void  CmMonitorEnable(TCommandEnabler &ce);
	 void  EvTimer(uint timerId);

	 LRESULT EvMsgKeyPad(WPARAM command, LPARAM lParam);
	 LRESULT DoMDIInit(WPARAM, LPARAM);
	 LRESULT CloseChild(WPARAM, LPARAM);

	 /* Windows Menu Command Handlers */
	 void CmCascadeChildren();
	 void CmTileChildrenHoriz();
    void CmTileChildrenVert();
	 void CmArrangeIcons();
	 void CmCloseChildren();
	 void CmTwoChildEnable(TCommandEnabler &ce);

//{{ALFFMDIClientRSP_TBL_END}}

DECLARE_RESPONSE_TABLE(ALFFMDIClient);
};    //{{ALFFMDIClient}}


#endif                                      // __alffnmdc_h sentry.
