/*******************************************************************

Copyright (c) 2004 Open Mobile Alliance, Ltd.  All Rights Reserved.

This software is made available under the usage and distribution terms 
covered by the Common Public License 1.0 and by using this software you
are bound by the terms and conditions of the same.

EXCEPT AS EXPRESSLY SET FORTH IN THE COMMON PUBLIC LICENSE,
THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, 
ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
   
Each recipient is solely responsible for determining the 
appropriateness of using and distributing this program and assumes 
all risks associated with its exercise of rights under the Common 
Public License, including but not limited to the risks and 
costs of program errors, compliance with applicable laws, 
damage to or loss of data, programs or equipment, and 
unavailability or interruption of operations.

********************************************************************/
// RightPane.cpp : implementation file
//

#include "stdafx.h"
#include "SCTS3DevMan.h"
#include "RightPane.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CRightPane dialog


CRightPane::CRightPane(CWnd* pParent /*=NULL*/)
	: CDialog(CRightPane::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRightPane)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	centerVertical=true;
	centerHorizontal=true;
}

void CRightPane::SetResizeLogic(bool _centerHorizontal,bool _centerVertical,bool repaint)
{
	int cx,cy;
	centerHorizontal=_centerHorizontal;
	centerVertical=_centerVertical;
	if (!m_hWnd) return;
	/* Centre child window */
	if (repaint && mainPane->currentRightChildPane && mainPane->currentRightChildPane->m_hWnd)
	{
		RECT rect;
		GetClientRect(&rect);
		if (centerVertical)
			cy=(rect.bottom-rect.top)/2;
		else
			cy=rect.bottom-rect.top;
		if (centerHorizontal)
			cx=(rect.right-rect.left)/2;
		else
			cx=rect.right-rect.left;
		mainPane->currentRightChildPane->GetWindowRect(&rect);
		if (centerVertical)
			cy-=(rect.bottom-rect.top)/2;
		else
		{
			rect.top=0;
			rect.bottom=cy;
			cy=0;
		}
		if (centerHorizontal)
			cx-=(rect.right-rect.left)/2;
		else
		{
			rect.left=0;
			rect.right=cx;
			cx=0;
		}
		mainPane->currentRightChildPane->MoveWindow(cx,cy,rect.right-rect.left,rect.bottom-rect.top);
	}

}

void CRightPane::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRightPane)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CRightPane, CDialog)
	//{{AFX_MSG_MAP(CRightPane)
	ON_WM_SIZE()
	ON_WM_SIZING()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRightPane message handlers

void CRightPane::OnSize(UINT nType, int cx, int cy) 
{
	RECT rect;
	CDialog::OnSize(nType, cx, cy);
	GetWindowRect(&rect);
	cx=rect.right-rect.left;
	cy=rect.bottom-rect.top;
	mainPane->GetClientRect(&rect);
	if (!(rect.right-rect.left)) return;
	if (mainPane->currentLeftPane && mainPane->currentLeftPane->m_hWnd) mainPane->currentLeftPane->MoveWindow(0,mainPane->toolbarHeight,rect.right-cx,cy);
	SetResizeLogic(centerHorizontal,centerVertical,true);
	cx=rect.right-rect.left;
	cy=rect.bottom-rect.top;
	GetClientRect(&rect);
}

void CRightPane::OnSizing(UINT fwSide, LPRECT pRect) 
{
	RECT rect;
	GetWindowRect(&rect);
	if (fwSide!=1)
	{
		pRect->bottom=rect.bottom;
		pRect->right=rect.right;
		pRect->left=rect.left;
		pRect->top=rect.top;
		return;
	}
	CDialog::OnSizing(fwSide, pRect);
}

BOOL CRightPane::PreTranslateMessage(MSG* pMsg) 
{
	/* Disable ESC  and Enter */
	if (pMsg->message==WM_KEYDOWN && (pMsg->wParam==VK_ESCAPE || pMsg->wParam==VK_RETURN)) return TRUE;

	return CDialog::PreTranslateMessage(pMsg);
}
