331 lines
8.3 KiB
C++
331 lines
8.3 KiB
C++
// Implementation of the CTL_Editor_BaseFormView class
|
|
///////////////////////////////////////////////////////////////////
|
|
#include "StdAfx.h"
|
|
|
|
#include "WControls\CTL_VBas.hpp"
|
|
|
|
#include "Controls\CTL_Cnst.hpp"
|
|
#include "Others\CTL_Pri.hpp"
|
|
#include "CTL_Res.h"
|
|
|
|
//For Init
|
|
static BOOL s_g_pri_bBaseViewInitDone = FALSE;;
|
|
|
|
//Screen Height
|
|
static unsigned short s_g_uwScreenHeight;
|
|
|
|
//#define _CTL_BASE_VIEW_ACCELERATION_
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CTL_Editor_BaseFormView
|
|
|
|
IMPLEMENT_DYNCREATE(CTL_Editor_BaseFormView, CFormView)
|
|
|
|
BEGIN_MESSAGE_MAP(CTL_Editor_BaseFormView, CFormView)
|
|
//{{AFX_MSG_MAP(CTL_Editor_BaseFormView)
|
|
ON_WM_MOUSEMOVE()
|
|
ON_WM_LBUTTONDOWN()
|
|
ON_WM_LBUTTONUP()
|
|
ON_WM_SIZE()
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CTL_Editor_BaseFormView construction/destruction
|
|
|
|
//***************************************************************************
|
|
CTL_Editor_BaseFormView::CTL_Editor_BaseFormView( UINT Id,
|
|
BOOL bMustDisplayClosedHand )
|
|
: CFormView( Id )
|
|
{
|
|
m_bMustDisplayClosedHand = bMustDisplayClosedHand;
|
|
|
|
m_bUserWantsToScroll = FALSE;
|
|
|
|
if ( !s_g_pri_bBaseViewInitDone )
|
|
{
|
|
//Gets screen's height
|
|
HDC hdc;
|
|
hdc = ::GetWindowDC(NULL);
|
|
s_g_uwScreenHeight = GetDeviceCaps(hdc, VERTRES);
|
|
::ReleaseDC(NULL,hdc);
|
|
|
|
//Loads Cursors
|
|
HINSTANCE hOldInstance = AfxGetResourceHandle();
|
|
AfxSetResourceHandle(CTL_g_hModule);
|
|
|
|
CTL_g_hcursor_CloseHand = AfxGetApp()->LoadCursor(IDC_CURSOR_CLOSED_HAND);
|
|
CTL_g_hcursor_UpDownHand = AfxGetApp()->LoadCursor(IDC_CURSOR_UP_DOWN_HAND);
|
|
|
|
AfxSetResourceHandle(hOldInstance);
|
|
|
|
//Ints are now done
|
|
s_g_pri_bBaseViewInitDone = TRUE;
|
|
}
|
|
}
|
|
|
|
//***************************************************************************
|
|
//***************************************************************************
|
|
// SHOULD NOT BE USED //
|
|
//***************************************************************************
|
|
//***************************************************************************
|
|
CTL_Editor_BaseFormView::CTL_Editor_BaseFormView()
|
|
: CFormView(-1)
|
|
{
|
|
|
|
}
|
|
|
|
//***************************************************************************
|
|
CTL_Editor_BaseFormView::~CTL_Editor_BaseFormView()
|
|
{
|
|
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CTL_Editor_BaseFormView public functions
|
|
|
|
//***************************************************************************
|
|
void CTL_Editor_BaseFormView::m_fn_vSetViewHeight(unsigned short uwViewHeight)
|
|
{
|
|
m_uwViewHeight = uwViewHeight;
|
|
unsigned short uwScrollBarHeight = GetSystemMetrics(SM_CYHSCROLL);
|
|
|
|
//Protection...
|
|
//ANNECY CB
|
|
// short wXSize = m_uwWindowWidth - 5;
|
|
short wXSize = m_uwWindowWidth - 5 - GetSystemMetrics(SM_CXVSCROLL);
|
|
//END ANNECY
|
|
SetScrollSizes(MM_TEXT, CSize(max(0, wXSize), max(0, m_uwViewHeight /*- uwScrollBarHeight*/)));
|
|
|
|
if ( m_uwViewHeight > m_uwWindowHeight )
|
|
m_bScrollIsPossible = TRUE;
|
|
else
|
|
m_bScrollIsPossible = FALSE;
|
|
|
|
//Supresses the scroll bar
|
|
if ( m_bScrollIsPossible )
|
|
{
|
|
//ANNECY CB
|
|
// EnableScrollBarCtrl(SB_VERT, FALSE);
|
|
//END ANNECY
|
|
EnableScrollBarCtrl(SB_HORZ, FALSE);
|
|
|
|
::SetClassLong(m_hWnd, GCL_HCURSOR, 0L);
|
|
}
|
|
else
|
|
::SetClassLong(m_hWnd, GCL_HCURSOR, m_lInitialClassLong);
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CTL_Editor_BaseFormView private functions
|
|
|
|
//***************************************************************************
|
|
void CTL_Editor_BaseFormView::OnInitialUpdate()
|
|
{
|
|
CFormView::OnInitialUpdate();
|
|
|
|
m_uwViewHeight = 0;
|
|
CRect crWindowRect;
|
|
GetClientRect(crWindowRect);
|
|
m_uwWindowHeight = crWindowRect.Height();
|
|
m_uwWindowWidth = crWindowRect.Width();
|
|
|
|
m_bScrollIsPossible = FALSE;
|
|
|
|
//To avoid cursor flashing
|
|
m_lInitialClassLong = ::GetClassLong(m_hWnd, GCL_HCURSOR);
|
|
}
|
|
|
|
//*******************************************************************************
|
|
void CTL_Editor_BaseFormView::OnMouseMove(UINT nFlags, CPoint point)
|
|
{
|
|
//Remove comments if acceleration is wanted...
|
|
#ifdef _CTL_BASE_VIEW_ACCELERATION_
|
|
static const short cs_wAcceleration = 1;
|
|
static const short cs_wMaxCounterForAccel = 5;
|
|
static const short cs_wInitialAddValue = 2;
|
|
static short s_wCounterForAccel = 0;
|
|
static short s_wCurrentAddValue = cs_wInitialAddValue;
|
|
static BOOL s_bWasGoingUp = FALSE;
|
|
|
|
if ( m_bScrollIsPossible )
|
|
{
|
|
if ( nFlags & MK_LBUTTON )
|
|
{
|
|
CPoint cpScrollPos = GetScrollPosition();
|
|
|
|
if ( point.y - s_cpOldPoint.y < 0 )
|
|
{
|
|
if ( !s_bWasGoingUp )
|
|
{
|
|
s_wCounterForAccel = 0;
|
|
s_wCurrentAddValue = cs_wInitialAddValue;
|
|
}
|
|
|
|
SetCursor(g_hcursor_UpHand);
|
|
cpScrollPos.y += s_wCurrentAddValue;
|
|
s_bWasGoingUp = TRUE;
|
|
}
|
|
else if ( point.y - s_cpOldPoint.y > 0 )
|
|
{
|
|
if ( s_bWasGoingUp )
|
|
{
|
|
s_wCounterForAccel = 0;
|
|
s_wCurrentAddValue = cs_wInitialAddValue;
|
|
}
|
|
|
|
SetCursor(g_hcursor_DownHand);
|
|
cpScrollPos.y -= s_wCurrentAddValue;
|
|
s_bWasGoingUp = FALSE;
|
|
}
|
|
else
|
|
SetCursor(g_hcursor_CloseHand);
|
|
|
|
s_wCounterForAccel++;
|
|
|
|
if ( s_wCounterForAccel >= cs_wMaxCounterForAccel )
|
|
{
|
|
s_wCounterForAccel = 0;
|
|
s_wCurrentAddValue += cs_wAcceleration;
|
|
}
|
|
|
|
ScrollToPosition(cpScrollPos);
|
|
}
|
|
else
|
|
{
|
|
SetCursor(g_hcursor_CloseHand);
|
|
s_wCounterForAccel = 0;
|
|
s_wCurrentAddValue = cs_wInitialAddValue;
|
|
}
|
|
}
|
|
#endif //_CTL_BASE_VIEW_ACCELERATION_
|
|
|
|
CPoint cpScreenPos = point;
|
|
ClientToScreen(&cpScreenPos);
|
|
|
|
if ( m_bScrollIsPossible )
|
|
{
|
|
if ( nFlags & MK_LBUTTON )
|
|
{
|
|
//If window must scroll
|
|
if ( m_bUserWantsToScroll )
|
|
{
|
|
//For Up and Down exits
|
|
if ( cpScreenPos.y == 0 )
|
|
{
|
|
SetCursorPos(cpScreenPos.x, s_g_uwScreenHeight-2);
|
|
cpScreenPos.y = m_uwOldPosition = s_g_uwScreenHeight-2;
|
|
|
|
}
|
|
|
|
if ( cpScreenPos.y == (s_g_uwScreenHeight-1) )
|
|
{
|
|
SetCursorPos(cpScreenPos.x, 1);
|
|
cpScreenPos.y = m_uwOldPosition = 1;
|
|
}
|
|
|
|
//Scrolls
|
|
CPoint cpScrollPos = GetScrollPosition();
|
|
|
|
cpScrollPos.y -= (cpScreenPos.y - m_uwOldPosition);
|
|
|
|
ScrollToPosition(cpScrollPos);
|
|
|
|
//Forces Repaint
|
|
MSG message;
|
|
while ( ::PeekMessage(&message, NULL, WM_PAINT, WM_PAINT, PM_REMOVE) )
|
|
::DispatchMessage(&message);
|
|
}
|
|
}
|
|
//Displays the closed hand to see where you can scroll
|
|
else if ( m_bMustDisplayClosedHand )
|
|
SetCursor(CTL_g_hcursor_CloseHand);
|
|
}
|
|
else
|
|
CFormView::OnMouseMove(nFlags, point);
|
|
|
|
m_uwOldPosition = (unsigned short)cpScreenPos.y ;
|
|
}
|
|
|
|
//*******************************************************************************
|
|
void CTL_Editor_BaseFormView::OnLButtonDown(UINT nFlags, CPoint point)
|
|
{
|
|
if ( m_bScrollIsPossible )
|
|
{
|
|
SetCapture();
|
|
SetCursor(CTL_g_hcursor_UpDownHand);
|
|
m_bUserWantsToScroll = TRUE;
|
|
|
|
ClientToScreen(&point);
|
|
m_uwOldPosition = (unsigned short)point.y;
|
|
}
|
|
|
|
CFormView::OnLButtonDown(nFlags, point);
|
|
}
|
|
|
|
//*******************************************************************************
|
|
void CTL_Editor_BaseFormView::OnLButtonUp(UINT nFlags, CPoint point)
|
|
{
|
|
ReleaseCapture();
|
|
m_bUserWantsToScroll = FALSE;
|
|
|
|
CFormView::OnLButtonUp(nFlags, point);
|
|
}
|
|
|
|
//*******************************************************************************
|
|
void CTL_Editor_BaseFormView::OnSize(UINT nType, int cx, int cy)
|
|
{
|
|
m_uwWindowHeight = cy;
|
|
|
|
//Looks if scroll is possible
|
|
if ( m_uwViewHeight > m_uwWindowHeight )
|
|
m_bScrollIsPossible = TRUE;
|
|
else
|
|
m_bScrollIsPossible = FALSE;
|
|
|
|
//Supresses the scroll bar
|
|
if ( m_bScrollIsPossible )
|
|
{
|
|
//ANNECY CB
|
|
// EnableScrollBarCtrl(SB_VERT, FALSE);
|
|
//END ANNECY
|
|
EnableScrollBarCtrl(SB_HORZ, FALSE);
|
|
|
|
::SetClassLong(m_hWnd, GCL_HCURSOR, 0L);
|
|
}
|
|
else
|
|
::SetClassLong(m_hWnd, GCL_HCURSOR, m_lInitialClassLong);
|
|
|
|
CFormView::OnSize(nType, cx, cy);
|
|
}
|
|
|
|
|
|
//*******************************************************************************
|
|
//*******************************************************************************
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CTL_Editor_BaseFormView diagnostics
|
|
|
|
#ifdef _DEBUG
|
|
void CTL_Editor_BaseFormView::AssertValid() const
|
|
{
|
|
CFormView::AssertValid();
|
|
}
|
|
|
|
void CTL_Editor_BaseFormView::Dump(CDumpContext& dc) const
|
|
{
|
|
CFormView::Dump(dc);
|
|
}
|
|
#endif //_DEBUG
|
|
|
|
|
|
|
|
|