You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
120 lines
3.3 KiB
120 lines
3.3 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: DialogItemsPosition.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of DialogItemsPosition.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "DialogItemsPosition.h"
|
|
#include "..\LgLib\Version.h"
|
|
|
|
CDialogItemsPosition::CDialogItemsPosition()
|
|
{
|
|
m_pCtrlPosition = NULL;
|
|
m_nCtrlPositionCount = 0;
|
|
memset( &m_Rect, 0, sizeof(m_Rect) );
|
|
}
|
|
|
|
CDialogItemsPosition::~CDialogItemsPosition()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
BOOL CDialogItemsPosition::Create( HWND hWnd )
|
|
{
|
|
m_hWnd = hWnd;
|
|
::GetClientRect( m_hWnd, &m_Rect );
|
|
return ::EnumChildWindows( m_hWnd, EnumChildProc_, (LPARAM)this );
|
|
}
|
|
|
|
BOOL CALLBACK CDialogItemsPosition::EnumChildProc_( HWND hwnd, LPARAM lParam )
|
|
{
|
|
CDialogItemsPosition *pThis = (CDialogItemsPosition*) lParam;
|
|
return pThis->EnumChildProc( hwnd );
|
|
}
|
|
|
|
BOOL CDialogItemsPosition::EnumChildProc( HWND hWnd )
|
|
{
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CDialogItemsPosition::EnumChildProc", "%d", GetDlgCtrlID( hWnd ) );
|
|
|
|
for( INT i = 0; i < m_nCtrlPositionCount; i++ )
|
|
{
|
|
if( m_pCtrlPosition[i].hWnd == hWnd )
|
|
{
|
|
::GetClientRect( m_pCtrlPosition[i].hWnd, &m_pCtrlPosition[i].rect );
|
|
::MapWindowPoints( hWnd, m_hWnd, (LPPOINT)&m_pCtrlPosition[i].rect, 2 );
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
m_pCtrlPosition = (PCTRL_POSITION)realloc( m_pCtrlPosition, sizeof(CTRL_POSITION) * (m_nCtrlPositionCount + 1) );
|
|
if( !m_pCtrlPosition )
|
|
{
|
|
m_nCtrlPositionCount = 0;
|
|
return FALSE;
|
|
}
|
|
|
|
i = m_nCtrlPositionCount++;
|
|
m_pCtrlPosition[i].hWnd = hWnd;
|
|
::GetClientRect( m_pCtrlPosition[i].hWnd, &m_pCtrlPosition[i].rect );
|
|
::MapWindowPoints( hWnd, m_hWnd, (LPPOINT)&m_pCtrlPosition[i].rect, 2 );
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CDialogItemsPosition::Center() const
|
|
{
|
|
if( !m_nCtrlPositionCount )
|
|
return;
|
|
|
|
// get client rect
|
|
RECT rClient;
|
|
::GetClientRect( m_hWnd, &rClient );
|
|
|
|
// calculate union rect
|
|
RECT rUnion;
|
|
for( INT i = 0; i < m_nCtrlPositionCount; i++ )
|
|
{
|
|
if( i == 0 )
|
|
rUnion = m_pCtrlPosition[i].rect;
|
|
else
|
|
::UnionRect( &rUnion, &rUnion, &m_pCtrlPosition[i].rect );
|
|
}
|
|
|
|
// calculate delta
|
|
SIZE sDelta = { ((rClient.right - rClient.left) - (rUnion.right - rUnion.left)) / 2,
|
|
((rClient.bottom - rClient.top) - (rUnion.bottom - rUnion.top)) / 2 };
|
|
|
|
// move all controls to the center
|
|
for( i = 0; i < m_nCtrlPositionCount; i++ )
|
|
{
|
|
RECT rect = { 0, 0,
|
|
m_pCtrlPosition[i].rect.right - m_pCtrlPosition[i].rect.left,
|
|
m_pCtrlPosition[i].rect.bottom - m_pCtrlPosition[i].rect.top };
|
|
|
|
// add shift within union rect
|
|
::OffsetRect( &rect, m_pCtrlPosition[i].rect.left - rUnion.left, m_pCtrlPosition[i].rect.top - rUnion.top );
|
|
// add shift within client rect
|
|
::OffsetRect( &rect, sDelta.cx, sDelta.cy );
|
|
// move control
|
|
::MoveWindow( m_pCtrlPosition[i].hWnd, rect.left, rect.top,
|
|
rect.right - rect.left, rect.bottom - rect.top, TRUE );
|
|
}
|
|
}
|
|
|
|
void CDialogItemsPosition::Destroy()
|
|
{
|
|
if( m_pCtrlPosition )
|
|
{
|
|
free( m_pCtrlPosition );
|
|
m_pCtrlPosition = NULL;
|
|
}
|
|
m_nCtrlPositionCount = 0;
|
|
}
|