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

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

	 OVERVIEW:
	 Tec3270App and Tec3270MainWindow Classes Definition, the base
    classes for Tec3270 application. They include Menu, Tool Bar,
    Status Bar, etc...

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

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

#include "alffexpt.h"
#include "alffhelp.h"
#include "alffprev.h"
#include "alffprtn.h"
#include "alffnmdc.h"
#include "alffnmd1.h"
#include "alffinif.h"
#include "alffsbar.h"
#include "tec3270.rh"

//{{Tec3270 Main Window }}
class Tec3270MainWindow: public TDecoratedMDIFrame
{
 public:
	 Tec3270MainWindow(char* title, TResId menuResId,
							 ALFFMDIClient& clientWnd= *new ALFFMDIClient(),
							 bool trackMenuSelection = false,
							 TModule* module = 0);
	 ~Tec3270MainWindow();
    char far* GetClassName() {return "Tec3270MainWindow";}
	 void  SetFontMetrics();
	 TRect SetWindowCoordinates();
	 int   ResizeWindow();
 protected:
    void SetupWindow();
	 void EvClose();
	 void EvSize(uint sizeType, TSize& size);

	 /* Windows Movement Control Event */
	 void EvMove(TPoint &clientOrigin);
    LRESULT EvStatusBitmapPressed(WPARAM wParam, LPARAM lParam);
	 void CleanupWindow();
DECLARE_RESPONSE_TABLE(Tec3270MainWindow);
};

/*
 * Tec3270 Application Class
 */
class Tec3270App : public TApplication
{
 public:
	 Tec3270App(char* iniFilePath = NULL) throw (ALFFException);
	 virtual ~Tec3270App();
    char far* GetClassName() {return "Tec3270App";}
	 bool     IsAppEnded();
	 void     SetAppEnded();
	 bool     IsAutomaticWindowSizing() {return windowSizing;}
	 void     SetAutomaticWindowSizing(bool doSizing) {windowSizing=doSizing;}
	 bool     IsAutomaticFontSizing() {return fontSizing;}
	 void     SetAutomaticFontSizing(bool doSizing) {fontSizing=doSizing;}
	 TMDIClient* GetMDIClient();
	 ALFFIniFile* GetIniFile();
    ALFFHelp*    GetHelpFile();
    void     GetTimeStamp(char* timeStamp);
    TSize    GetFullScreenSize();
	 void     SetAppFont(LOGFONT logFont, bool wSizing, bool fSizing);
	 TFont*   GetPrtFont();
	 void     SetPrtFont(LOGFONT logFont);
	 TFont*   GetAppFont();
	 bool     ResizeFont();
	 int      GetFontCharWidth();
	 int      GetFontCharHeight();
	 int      GetFontSize();
	 void     SetFontCharWidth(const int width);
    int      SizeFontCharWidth(const int scrLineSize);//returns new Char Width
	 void     SetFontCharHeight(const int height);
    int      SizeFontCharHeight(const int scrNumLines); //returns new Char Height
	 int      GetTermLineSize();
	 int      GetTermNumLines();
	 void     SetTermLineSize(const int lSize);
	 void     SetTermNumLines(const int nLines);
	 ALFFStatusBar* GetStatusBar();
    bool     IsInsertModeOn() {return pINSERTKEY->GetEnabled();}
    void     SetInsertMode(bool mode) {pINSERTKEY->SetEnabled(mode);}
    void     ReSizeStatusBar();
    void     SetBaseWinWidth(int width);
    ALFFUseSecurity* GetSecurityObj() { return pSecurity; }
    bool     InitSecurity(bool securityOn);
    bool     SetSecurityOn();

    /* Status Bar Gadgets Methods */
    bool     UpdateSSLLock();
    bool     UpdateTN3270();
    bool     UpdateTermGadget();
    bool     UpdateTermNetname();
    bool     UpdatePrtGadget();
    bool     UpdatePrtNetname();

    //
    char*    GetClusterInfo();
    char*    GetComputerName();
    char*    GetComputerAddress();

	 /* Tec3270 Menu and MDI controls */
	 const TBitmap*    	markBitmap;
	 const TBitmap*  		unmarkBitmap;
	 ALFFMDIClient*		mdiClient;

	 /* Public data members used by the print menu commands  */
	 ALFFPrinter*        Printer;      // Printer support.
	 ALFFPrinterBuffer*  printerBuf;
	 bool                Printing;      // Printing in progress.

	 /* Printer Font Controls   */
	 char*  prtFontName;
	 int    prtCharWidth;
	 int    prtCharHeight;
	 int    prtFontSize;
	 int    prtFontWeight;
	 int    prtFontItalic;
	 int    prtFontCharset;
	 TFont* prtFont;

//{{Tec3270AppVIRTUAL_BEGIN}}
 public:
    virtual int  Run();
	 virtual void InitMainWindow();
	 virtual void InitInstance();
	 virtual bool ProcessAppMsg (MSG& msg);
 protected:
    /* Tec3270 Communications Object */
	 ALFFCommCluster*   alffCommCluster;

    /* Setup all the global Security stuff
     * (Need one per application)
     */
    ALFFUseSecurity*   pSecurity;


	 /* Computer Name and Address     */
	 char* pClusterInfo;
	 char* pLocalName;
	 char* pLocalAddress;

    /* Tec3270 Status Bar & its Controls */
	 ALFFStatusBar*      	sb;
    ALFFBitmapGadget*   	termGadget;
    ALFFTextGadget*        tNetName;
    TSeparatorGadget*   	termSeparator;
    ALFFBitmapGadget*   	prtGadget;
    ALFFTextGadget*        pNetName;
    TSeparatorGadget*   	prtSeparator;
    ALFFTextGadget*        tn3270TXT;
    ALFFBitmapGadget*   	sslLocker;
    TSeparatorGadget*   	padSeparator;
    ALFFModeGadget*        pNUMLOCK;
    ALFFModeGadget*        pCAPSLOCK;
    ALFFTextGadget*        pINSERTKEY;
    TSeparatorGadget*   	modeSeparator;
    TTimeGadget*        	pDateTime;
    TSeparatorGadget*   	timeSeparator;
    int                 	baseWinWidth;

    /* Tec3270 Main Window */
	 Tec3270MainWindow* 	appWindow;

	 bool    OpenTec3270(TWindow* parent, char* appVer, char* verDate,
													  char* cpRight);
	 void    MakeIniFileName(char* fileName);
    bool    IsValidIniFile(char* fileName, char* iniFileName);

	 /* Terminal Characteristics */
	 unsigned int termLineSize;
	 unsigned int termNumLines;
	 bool windowSizing;

	 /* Terminal Font Controls   */
	 char*  scrFontName;
	 int    scrCharWidth;
	 int    scrCharHeight;
	 int    scrFontSize;
	 int    scrFontWeight;
	 int    scrFontItalic;
	 int    scrFontCharset;
	 bool   fontSizing;
	 TFont* scrFont;

 private:
	 void SetupSpeedBar (Tec3270MainWindow* frame);
    void SetupStatusBar(ALFFStatusBar* sb, bool updateBar=false);

	 ALFFIniFile* 	iniFile;
    bool          appInited;
	 bool     		appEnded;

    ALFFHelp*    	helpFile;
	 bool     		HelpState;        // Has the help engine been used.
	 bool     		ContextHelp;      // SHIFT-F1 state (context sensitive HELP).
	 HCURSOR  		HelpCursor;       // Context sensitive help cursor.

//{{Tec3270AppVIRTUAL_END}}

//{{Tec3270AppRSP_TBL_BEGIN}}
protected:
	 void CmHelpContents ();
	 void CmHelpUsing ();
	 void CmHelpVersion ();
	 void CmHelpAbout ();
	 void CmGetCommClusterInfo();    // Show this computer Comm Cluster Info
	 void CmGetComputerInfo();       // Show this computer Comm Address
	 void EvWinIniChange (char far* section);
//{{Tec3270AppRSP_TBL_END}}
DECLARE_RESPONSE_TABLE(Tec3270App);
};    //{{Tec3270App}}


#endif                                      // __alffntap_h sentry.
