/*  Project Tec3270

	 SUBSYSTEM:    Tec3270.exe (Tec3270 application)
	 FILE:         alffnope.cpp
	 AUTHOR:       Alcindo Ferreira Filho

	 OVERVIEW:
	 Tec3270Open Class Implementation, the overture dialog of Tec3270
    application.

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

    LICENSE:      Tec3270_License (docs/Tec3270_License.txt)
*/
#include "alffnall.h"

//{{Tec3270 Open Dialog Implementation}}

//////////////////////////////////////////////////////////
// Tec3270Open Dialog
// ==================
//
// Define Dialog Response Table
//
DEFINE_RESPONSE_TABLE1(Tec3270Open,ALFFDialog)
  EV_BN_CLICKED(IDOK,CmOk),
  EV_WM_LBUTTONDOWN,
  EV_WM_RBUTTONDOWN,
  EV_WM_PAINT,
  EV_WM_TIMER,
END_RESPONSE_TABLE;
////////////////////////////////////////////////////////////
// Construction/Destruction handling.
Tec3270Open::Tec3270Open(TWindow* parent, char* appVer, char* versionDate,
														char* cpRight):
								 ALFFDialog(parent,IDD_TEC3270OPEN),
								 dateCompiled(versionDate)
{
 tec3270BitMap = new TDib(TBitmap(GetModule()->GetInstance(),IDB_TEC3270));
 applVersion = new char[strlen(appVer)+1];
 strcpy(applVersion,appVer);
 copyRight   = new char[strlen(cpRight)+1];
 strcpy(copyRight,cpRight);
}


Tec3270Open::~Tec3270Open()
{
 delete tec3270BitMap;
 delete [] applVersion;
 delete [] copyRight;
}

void
Tec3270Open::SetupWindow()
{
 TRect dlgRect;
 dlgRect.left  = 0;
 dlgRect.top   = 0;
 dlgRect.right = tec3270BitMap->Width();
 dlgRect.bottom = tec3270BitMap->Height();
 MoveWindow(dlgRect);
 SetCaption("Tec3270");
 ALFFDialog::SetupWindow();
 SetTimer(9998, 2000);
}

void
Tec3270Open::EvLButtonDown(uint /*modKeys*/, TPoint& /*point*/)
{
 CmOk();
}

void
Tec3270Open::EvRButtonDown(uint /*modKeys*/, TPoint& /*point*/)
{
 CmOk();
}

void
Tec3270Open::CmOk()
{
 ALFFDialog::CmOk();
}

void
Tec3270Open::EvPaint()
{
 TPaintDC dc(*this);
 TRect&   rect = *(TRect*)&dc.Ps.rcPaint;
 Paint(dc, dc.Ps.fErase, rect);
}

void
Tec3270Open::Paint(TDC& dc, bool, TRect&)
{
 /* Show Tec3270 BitMap Presentation */
 TRect rectALFFOpen = GetClientRect();
 TPoint source(0,0);
 dc.SetDIBitsToDevice(rectALFFOpen,source,*tec3270BitMap);

 /* Set Product Information and CopyRight */
 dc.SetTextColor(RGB(0,0,128));  // it was TColor::Black

 TRect textRect;
 TPoint textPoint(0,0);

 /* White Background */
 //dc.SetBkColor(RGB(255,255,255));  // it was 255,255,128
 dc.SetBkMode(TRANSPARENT);

 // Product Name
 char productName[8] = "Tec3270";

 /* Set Tec3270 Specific Font To Write Product Name On BitMap */
 dc.SelectObject(TFont("Verdana",64,0,0,0,700,
   							DEFAULT_PITCH|FF_DONTCARE,600) );

 TSize textSize = dc.GetTextExtent(productName,strlen(productName));
 textRect.left = rectALFFOpen.left+rectALFFOpen.Width()/14;
 textRect.top  = rectALFFOpen.Height()/18;
 textRect.right = textRect.left + textSize.cx + 3;
 textRect.bottom = textRect.top + textSize.cy;
 dc.ExtTextOut(textRect.left,textRect.top,
					ETO_CLIPPED,
					&textRect,
					productName,strlen(productName));

 /* Set Tec3270 Specific Font To Write Product Version On BitMap */
 dc.SelectObject(TFont("Verdana",18,0,0,0,700,
 								DEFAULT_PITCH|FF_DONTCARE,600) );

 textSize = dc.GetTextExtent(applVersion,strlen(applVersion));
 //textRect.left = (same as above - it do not need to be repeated)
 textRect.top  = rectALFFOpen.Height()/6;
 textRect.right = textRect.left + textSize.cx + 3;
 textRect.bottom = textRect.top + textSize.cy;
 dc.ExtTextOut(textRect.left,textRect.top,
					ETO_CLIPPED,
					&textRect,
					applVersion,strlen(applVersion));

 /* Version Compiled Date */
 char versionDate[16];
 strcpy(versionDate,dateCompiled.c_str());

 /* Set Tec3270 Specific Font To Write Version Date On BitMap */
 dc.SelectObject(TFont("Arial",15,0,0,0,400,
								DEFAULT_PITCH|FF_DONTCARE,400));

 textSize = dc.GetTextExtent(versionDate,strlen(versionDate));
 //textRect.left = (same as above - it do not need to be repeated)
 textRect.top  = rectALFFOpen.Height()/5;
 textRect.right = textRect.left + textSize.cx + 3;
 textRect.bottom = textRect.top + textSize.cy;
 dc.ExtTextOut(textRect.left,textRect.top,
					ETO_CLIPPED,
					&textRect,
					versionDate,strlen(versionDate));


 /* White Background */
 dc.SetTextColor(RGB(225,172,83));  
 textSize = dc.GetTextExtent(copyRight,strlen(copyRight));
 textRect.left = (rectALFFOpen.right - textSize.cx)/2;
 textRect.top  = rectALFFOpen.bottom - textSize.cy - GetSystemMetrics(SM_CYDLGFRAME);
 textRect.right = textRect.left + textSize.cx;
 textRect.bottom = textRect.top + textSize.cy;
 dc.ExtTextOut(textRect.left,textRect.top,
					ETO_CLIPPED,
					&textRect,
					copyRight,strlen(copyRight));
}

void
Tec3270Open::EvTimer(uint timerId)
{
 KillTimer(timerId);
 CmOk();
}

