ExtControlsCommon.cpp
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:275k
- // This is part of the Professional User Interface Suite library.
- // Copyright (C) 2001-2009 FOSS Software, Inc.
- // All rights reserved.
- //
- // http://www.prof-uis.com
- // mailto:support@prof-uis.com
- //
- // This source code can be used, modified and redistributed
- // under the terms of the license agreement that is included
- // in the Professional User Interface Suite package.
- //
- // Warranties and Disclaimers:
- // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND
- // INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- // IN NO EVENT WILL FOSS SOFTWARE INC. BE LIABLE FOR ANY DIRECT,
- // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES,
- // INCLUDING DAMAGES FOR LOSS OF PROFITS, LOSS OR INACCURACY OF DATA,
- // INCURRED BY ANY PERSON FROM SUCH PERSON'S USAGE OF THIS SOFTWARE
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- #include "stdafx.h"
- #if (!defined __EXT_CONTROLS_COMMON_H)
- #include <ExtControlsCommon.h>
- #endif
- #if (!defined __EXT_LOCALIZATION_H)
- #include <../Src/ExtLocalization.h>
- #endif
- #include <Resources/Resource.h>
- #if (!defined __PROF_UIS_RES_CC_SC_H)
- #include <Resources/ResCommonControls/ResCommonControls.h>
- #endif
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #if ( ! defined __EXT_MFC_NO_LIST_VIEW_CTRL )
- /////////////////////////////////////////////////////////////////////////////
- // CExtListCtrlDataSortOrder
- IMPLEMENT_SERIAL( CExtListCtrlDataSortOrder, CObject, VERSIONABLE_SCHEMA|1 );
- CExtListCtrlDataSortOrder::CExtListCtrlDataSortOrder()
- {
- }
- CExtListCtrlDataSortOrder::CExtListCtrlDataSortOrder(
- const CExtListCtrlDataSortOrder & other
- )
- {
- _AssignFromOther( other );
- }
- CExtListCtrlDataSortOrder::~CExtListCtrlDataSortOrder()
- {
- Empty();
- }
- void CExtListCtrlDataSortOrder::_AssignFromOther(
- const CExtListCtrlDataSortOrder & other
- )
- {
- ASSERT_VALID( this );
- ASSERT_VALID( (&other) );
- Empty();
- LONG nCount = (LONG)other.m_arrItems.GetSize();
- for( LONG i = 0L; i < nCount; i++ )
- {
- COLUMN_INFO _itemDst( other.m_arrItems[ i ] );
- m_arrItems.Add( _itemDst );
- }
- ASSERT( nCount == m_arrItems.GetSize() );
- }
- CExtListCtrlDataSortOrder & CExtListCtrlDataSortOrder::operator =(
- const CExtListCtrlDataSortOrder & other
- )
- {
- ASSERT_VALID( this );
- ASSERT_VALID( (&other) );
- _AssignFromOther( other );
- return (*this);
- }
- bool CExtListCtrlDataSortOrder::operator == (
- const CExtListCtrlDataSortOrder & other
- ) const
- {
- ASSERT_VALID( this );
- ASSERT_VALID( (&other) );
- LONG nCount = (LONG)m_arrItems.GetSize();
- LONG i = (LONG)other.m_arrItems.GetSize();
- if( nCount != i )
- return false;
- for( i = 0L; i < nCount; i++ )
- {
- const COLUMN_INFO & _itemSrc = m_arrItems[ i ];
- const COLUMN_INFO & _itemDst = other.m_arrItems[ i ];
- if( _itemSrc != _itemDst )
- return false;
- }
- return true;
- }
- bool CExtListCtrlDataSortOrder::operator != (
- const CExtListCtrlDataSortOrder & other
- ) const
- {
- ASSERT_VALID( this );
- ASSERT_VALID( (&other) );
- if( (*this) == other )
- return false;
- return true;
- }
- #ifdef _DEBUG
- void CExtListCtrlDataSortOrder::AssertValid() const
- {
- CObject::AssertValid();
- }
- void CExtListCtrlDataSortOrder::Dump( CDumpContext & dc ) const
- {
- CObject::Dump( dc );
- }
- #endif // _DEBUG
- void CExtListCtrlDataSortOrder::Serialize( CArchive & ar )
- {
- CObject::Serialize( ar );
- DWORD i, dwCount;
- if( ar.IsStoring() )
- {
- dwCount = (DWORD)m_arrItems.GetSize();
- ar << dwCount;
- for( i = 0; i < dwCount; i++ )
- {
- COLUMN_INFO & _itemSrc = m_arrItems[ i ];
- _itemSrc.Serialize( ar );
- }
- } // if( ar.IsStoring() )
- else
- {
- m_arrItems.RemoveAll();
- ar >> dwCount;
- for( i = 0; i < dwCount; i++ )
- {
- COLUMN_INFO _itemSrc;
- _itemSrc.Serialize( ar );
- m_arrItems.Add( _itemSrc );
- }
- ASSERT( DWORD( m_arrItems.GetSize() ) == dwCount );
- } // else from if( ar.IsStoring() )
- }
- bool CExtListCtrlDataSortOrder::ItemsUnique() const
- {
- ASSERT_VALID( this );
- LONG nCount = (LONG)m_arrItems.GetSize();
- for( LONG i = 0L; i < (nCount - 1L); i++ )
- {
- const COLUMN_INFO & _itemSrc = m_arrItems[ i ];
- for( LONG j = (i + 1L); j < nCount; j++ )
- {
- const COLUMN_INFO & _itemDst = m_arrItems[ j ];
- if( _itemSrc == _itemDst )
- return false;
- }
- }
- return true;
- }
- void CExtListCtrlDataSortOrder::MakeItemsUnique()
- {
- ASSERT_VALID( this );
- LONG nCount = (LONG)m_arrItems.GetSize();
- for( LONG i = 0L; i < (nCount - 1L); i++ )
- {
- const COLUMN_INFO & _itemSrc = m_arrItems[ i ];
- for( LONG j = (i + 1L); j < nCount; )
- {
- const COLUMN_INFO & _itemDst = m_arrItems[ j ];
- if( _itemSrc != _itemDst )
- {
- j++;
- continue;
- }
- nCount--;
- m_arrItems.RemoveAt( j, 1 );
- }
- }
- }
- bool CExtListCtrlDataSortOrder::IsEmpty() const
- {
- ASSERT_VALID( this );
- if( m_arrItems.GetSize() > 0L )
- return false;
- else
- return true;
- }
- void CExtListCtrlDataSortOrder::Empty()
- {
- ASSERT_VALID( this );
- m_arrItems.RemoveAll();
- }
- LONG CExtListCtrlDataSortOrder::GetColPos( LONG nColNo ) const
- {
- ASSERT_VALID( this );
- LONG nCount = (LONG)m_arrItems.GetSize();
- for( LONG i = 0L; i < nCount; i++ )
- {
- const COLUMN_INFO & _itemSrc = m_arrItems[ i ];
- if( _itemSrc.m_nColNo == nColNo )
- return i;
- }
- return -1L;
- }
- void CExtListCtrlDataSortOrder::SetupOrder(
- const CExtListCtrlDataSortOrder & _gdsoUpdate,
- bool bInvertIntersectionSortOrder
- )
- {
- ASSERT_VALID( this );
- ASSERT( ItemsUnique() );
- ASSERT_VALID( (&_gdsoUpdate) );
- ASSERT( _gdsoUpdate.ItemsUnique() );
- LONG nCount = (LONG)m_arrItems.GetSize();
- if( nCount == 0 )
- {
- (*this) = _gdsoUpdate;
- return;
- } // if( nCount == 0 )
- LONG nCountUpdate = (LONG)_gdsoUpdate.m_arrItems.GetSize();
- for( LONG u = 0L; u < nCountUpdate; u++ )
- {
- const COLUMN_INFO & _itemUpdate = _gdsoUpdate.m_arrItems[ u ];
- COLUMN_INFO _itemSetup( _itemUpdate );
- LONG i = GetColPos( _itemUpdate.m_nColNo );
- if( i < 0L )
- {
- m_arrItems.Add( _itemSetup );
- continue;
- }
- COLUMN_INFO & _itemDst = m_arrItems[ i ];
- ASSERT( _itemDst.m_nColNo == _itemUpdate.m_nColNo );
- if( _itemDst == _itemUpdate
- && (! bInvertIntersectionSortOrder )
- )
- continue;
- if( bInvertIntersectionSortOrder )
- _itemSetup.m_bAscending = (! _itemDst.m_bAscending);
- m_arrItems.SetAt( i, _itemSetup );
- }
- ASSERT_VALID( this );
- ASSERT( ItemsUnique() );
- }
- void CExtListCtrlDataSortOrder::UpdateIndices(
- LONG nColNo,
- LONG nInsertRemoveCount,
- bool bInsert
- )
- {
- ASSERT_VALID( this );
- ASSERT( nColNo >= 0L );
- ASSERT( nInsertRemoveCount >= 0L );
- if( nInsertRemoveCount == 0L )
- return;
- LONG nCount = (LONG)m_arrItems.GetSize();
- for( LONG i = 0L; i < nCount; )
- {
- COLUMN_INFO _itemUpdate( m_arrItems[ i ] );
- if( bInsert )
- {
- if( _itemUpdate.m_nColNo >= nColNo )
- {
- _itemUpdate.m_nColNo += nInsertRemoveCount;
- m_arrItems.SetAt( i, _itemUpdate );
- }
- i++;
- }
- else
- {
- if( _itemUpdate.m_nColNo >= (nColNo+nInsertRemoveCount) )
- {
- _itemUpdate.m_nColNo -= nInsertRemoveCount;
- m_arrItems.SetAt( i, _itemUpdate );
- i++;
- }
- else if( _itemUpdate.m_nColNo >= nColNo )
- {
- m_arrItems.RemoveAt( i, 1 );
- nCount--;
- }
- else
- i++;
- }
- }
- }
- void CExtListCtrlDataSortOrder::SwapDroppedSeries(
- LONG nColNoSrc,
- LONG nColNoDropBefore
- )
- {
- ASSERT_VALID( this );
- ASSERT( nColNoSrc >= 0L );
- ASSERT( nColNoDropBefore >= 0L );
- if( nColNoSrc == nColNoDropBefore
- || (nColNoSrc+1L) == nColNoDropBefore
- )
- return;
- LONG nCount = (LONG)m_arrItems.GetSize();
- for( LONG i = 0L; i < nCount; i++ )
- {
- COLUMN_INFO _itemUpdate( m_arrItems[ i ] );
- if( nColNoSrc < nColNoDropBefore )
- {
- if( _itemUpdate.m_nColNo > nColNoSrc
- && _itemUpdate.m_nColNo < nColNoDropBefore
- )
- {
- _itemUpdate.m_nColNo --;
- m_arrItems.SetAt( i, _itemUpdate );
- }
- else if( _itemUpdate.m_nColNo == nColNoSrc )
- {
- _itemUpdate.m_nColNo = nColNoDropBefore - 1L;
- m_arrItems.SetAt( i, _itemUpdate );
- }
- } // if( nColNoSrc < nColNoDropBefore )
- else
- {
- ASSERT( nColNoSrc > nColNoDropBefore );
- if( _itemUpdate.m_nColNo < nColNoSrc
- && _itemUpdate.m_nColNo >= nColNoDropBefore
- )
- {
- _itemUpdate.m_nColNo ++;
- m_arrItems.SetAt( i, _itemUpdate );
- }
- else if( _itemUpdate.m_nColNo == nColNoSrc )
- {
- _itemUpdate.m_nColNo = nColNoDropBefore;
- m_arrItems.SetAt( i, _itemUpdate );
- }
- } // else from if( nColNoSrc < nColNoDropBefore )
- } // for( LONG i = 0L; i < nCount; i++ )
- }
- CExtListCtrlDataSortOrder::COLUMN_INFO::COLUMN_INFO(
- LONG nColNo, // = -1L
- bool bAscending // = true
- )
- : m_nColNo( nColNo )
- , m_bAscending( bAscending )
- {
- }
- CExtListCtrlDataSortOrder::COLUMN_INFO::COLUMN_INFO( const CExtListCtrlDataSortOrder::COLUMN_INFO & other )
- : m_nColNo( other.m_nColNo )
- , m_bAscending( other.m_bAscending )
- {
- }
- CExtListCtrlDataSortOrder::COLUMN_INFO & CExtListCtrlDataSortOrder::COLUMN_INFO::operator = ( const CExtListCtrlDataSortOrder::COLUMN_INFO & other )
- {
- m_nColNo = other.m_nColNo;
- m_bAscending = other.m_bAscending;
- return (*this);
- }
- void CExtListCtrlDataSortOrder::COLUMN_INFO::Serialize( CArchive & ar )
- {
- BYTE nFlags = 0;
- if( ar.IsStoring() )
- {
- if( m_bAscending )
- nFlags |= 0x01;
- ar.Write( &m_nColNo, sizeof(m_nColNo) );
- ar.Write( &nFlags, sizeof(nFlags) );
- } // if( ar.IsStoring() )
- else
- {
- ar.Read( &m_nColNo, sizeof(m_nColNo) );
- ar.Read( &nFlags, sizeof(nFlags) );
- if( (nFlags&0x01) != 0 )
- m_bAscending = true;
- else
- m_bAscending = false;
- } // else from if( ar.IsStoring() )
- }
- int CExtListCtrlDataSortOrder::COLUMN_INFO::Cmp( const CExtListCtrlDataSortOrder::COLUMN_INFO & other ) const
- {
- if( m_nColNo < other.m_nColNo )
- return -1;
- if( m_nColNo > other.m_nColNo )
- return 1;
- if( m_bAscending )
- {
- if( ! other.m_bAscending )
- return 1;
- } // if( m_bAscending )
- else
- {
- if( other.m_bAscending )
- return -1;
- } // else from if( m_bAscending )
- return 0;
- }
- bool CExtListCtrlDataSortOrder::COLUMN_INFO::operator == ( const CExtListCtrlDataSortOrder::COLUMN_INFO & other ) const
- {
- return ( (Cmp(other) == 0) ? true : false );
- }
- bool CExtListCtrlDataSortOrder::COLUMN_INFO::operator != ( const CExtListCtrlDataSortOrder::COLUMN_INFO & other ) const
- {
- return ( (Cmp(other) != 0) ? true : false );
- }
- bool CExtListCtrlDataSortOrder::COLUMN_INFO::operator <= ( const CExtListCtrlDataSortOrder::COLUMN_INFO & other ) const
- {
- return ( (Cmp(other) <= 0) ? true : false );
- }
- bool CExtListCtrlDataSortOrder::COLUMN_INFO::operator >= ( const CExtListCtrlDataSortOrder::COLUMN_INFO & other ) const
- {
- return ( (Cmp(other) >= 0) ? true : false );
- }
- bool CExtListCtrlDataSortOrder::COLUMN_INFO::operator < ( const CExtListCtrlDataSortOrder::COLUMN_INFO & other ) const
- {
- return ( (Cmp(other) < 0) ? true : false );
- }
- bool CExtListCtrlDataSortOrder::COLUMN_INFO::operator > ( const CExtListCtrlDataSortOrder::COLUMN_INFO & other ) const
- {
- return ( (Cmp(other) > 0) ? true : false );
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtHeaderCtrl
- IMPLEMENT_DYNCREATE( CExtHeaderCtrl, CHeaderCtrl );
- const UINT CExtHeaderCtrl::g_nMsgHeaderButtonClick =
- ::RegisterWindowMessage( _T("CExtHeaderCtrl::g_nMsgHeaderButtonClick") );
- bool CExtHeaderCtrl::g_bEnableOnIdleCalls = false;
- CExtHeaderCtrl::CExtHeaderCtrl()
- : m_nHoverColNo( -1 )
- , m_nHoverIndex( -1 )
- , m_nPressingColNo( -1 )
- , m_nPressingIndex( -1 )
- , m_ptScreenPressing( -32767, -32767 )
- , m_nHelperInitialResizingExtent( -32767 )
- , m_bOnButton( false )
- , m_bOnDividerAtRight( false )
- , m_bCancelingActions( false )
- , m_nDividerHalfExtent( 2 )
- , m_nAdvancedTipStyle( INT(CExtPopupMenuTipWnd::__ETS_RECTANGLE_NO_ICON) )
- , m_bShowTipsOverHeader( true )
- {
- m_hCursorDefault = ::LoadCursor( NULL, IDC_ARROW );
- ASSERT( m_hCursorDefault != NULL );
- CExtLocalResourceHelper _LRH;
- CWinApp * pApp = ::AfxGetApp();
- ASSERT_VALID( pApp );
- m_hCursorResizingH1 = pApp->LoadCursor( MAKEINTRESOURCE( IDC_EXT_RESIZE_H1 ) );
- ASSERT( m_hCursorResizingH1 != NULL );
- m_hCursorResizingH2 = pApp->LoadCursor( MAKEINTRESOURCE( IDC_EXT_RESIZE_H2 ) );
- ASSERT( m_hCursorResizingH2 != NULL );
- m_hCursorOuterDragOK = ::LoadCursor( NULL, IDC_ARROW );
- ASSERT( m_hCursorOuterDragOK != NULL );
- m_hCursorOuterDragCancel = pApp->LoadCursor( MAKEINTRESOURCE( IDC_EXT_BIG_X_CROSS ) );
- ASSERT( m_hCursorOuterDragCancel != NULL );
- PmBridge_Install( true );
- }
- CExtHeaderCtrl::~CExtHeaderCtrl()
- {
- PmBridge_Uninstall();
- if( m_hCursorDefault != NULL )
- ::DestroyCursor( m_hCursorDefault );
- if( m_hCursorResizingH1 != NULL )
- ::DestroyCursor( m_hCursorResizingH1 );
- if( m_hCursorResizingH2 != NULL )
- ::DestroyCursor( m_hCursorResizingH2 );
- if( m_hCursorOuterDragOK != NULL )
- ::DestroyCursor( m_hCursorOuterDragOK );
- if( m_hCursorOuterDragCancel != NULL )
- ::DestroyCursor( m_hCursorOuterDragCancel );
- }
- void CExtHeaderCtrl::PmBridge_OnPaintManagerChanged(
- CExtPaintManager * pGlobalPM
- )
- {
- ASSERT_VALID( this );
- CExtPmBridge::PmBridge_OnPaintManagerChanged( pGlobalPM );
- if( GetSafeHwnd() == NULL )
- return;
- Invalidate();
- }
- void CExtHeaderCtrl::_CancelActions()
- {
- ASSERT_VALID( this );
- if( m_bCancelingActions )
- return;
- m_bCancelingActions = true;
- if( m_bOnDividerAtRight )
- {
- HWND hWndParent = ::GetParent( m_hWnd );
- if( hWndParent != NULL )
- {
- UINT nOwnID = UINT( GetDlgCtrlID() );
- HD_NOTIFY _data, _data2;
- ::memset( &_data, 0, sizeof(HD_NOTIFY) );
- ::memset( &_data2, 0, sizeof(HD_NOTIFY) );
- _data.hdr.hwndFrom = m_hWnd;
- _data.hdr.idFrom = nOwnID;
- _data.iButton = 0;
- _data.iItem = m_nPressingColNo; //nColNo;
- _data.hdr.code = HDN_ENDTRACK;
- HDITEM hdItemBuffer; // to avoid common controls crashing
- ::memset( &hdItemBuffer, 0, sizeof(HDITEM) );
- _data.pitem = &hdItemBuffer;
- ::memcpy( &_data2, &_data, sizeof(HD_NOTIFY) );
- ::SendMessage( hWndParent, WM_NOTIFY, WPARAM(nOwnID), LPARAM(&_data) );
- _data2.hdr.code = HDN_ITEMCHANGED;
- ::SendMessage( hWndParent, WM_NOTIFY, WPARAM(nOwnID), LPARAM(&_data2) );
- if( ::IsWindow( hWndParent ) && ::IsWindowVisible( hWndParent ) )
- ::InvalidateRect( hWndParent, NULL, TRUE );
- } // if( hWndParent != NULL )
- } // if( m_bOnDividerAtRight )
- if( ( m_nHoverColNo >= 0 || m_nPressingColNo >= 0 )
- && GetSafeHwnd() != NULL
- )
- Invalidate();
- m_ptScreenPressing.x = m_ptScreenPressing.y = m_nHelperInitialResizingExtent = -32767;
- m_nHoverColNo = m_nHoverIndex = m_nPressingColNo = m_nPressingIndex = -1;
- m_bOnButton = m_bOnDividerAtRight = false;
- if( ::GetCapture() == m_hWnd )
- ReleaseCapture();
- m_bCancelingActions = false;
- }
- BEGIN_MESSAGE_MAP( CExtHeaderCtrl, CHeaderCtrl )
- //{{AFX_MSG_MAP(CExtHeaderCtrl)
- ON_WM_PAINT()
- ON_WM_ERASEBKGND()
- ON_WM_WINDOWPOSCHANGING()
- ON_WM_SETCURSOR()
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_WM_LBUTTONDBLCLK()
- ON_WM_RBUTTONDOWN()
- ON_WM_RBUTTONUP()
- ON_WM_RBUTTONDBLCLK()
- ON_WM_MBUTTONDOWN()
- ON_WM_MBUTTONUP()
- ON_WM_MBUTTONDBLCLK()
- ON_WM_CANCELMODE()
- ON_WM_CAPTURECHANGED()
- //}}AFX_MSG_MAP
- ON_REGISTERED_MESSAGE(
- CExtContentExpandWnd::g_nMsgPaintItemContent,
- _OnPaintExpandedItemContent
- )
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CExtHeaderCtrl message handlers
- LRESULT CExtHeaderCtrl::_OnPaintExpandedItemContent( WPARAM wParam, LPARAM lParam )
- {
- ASSERT_VALID( this );
- lParam;
- CExtContentExpandWnd::PAINT_ITEM_CONTENT_DATA * p_picd =
- (CExtContentExpandWnd::PAINT_ITEM_CONTENT_DATA *)wParam;
- ASSERT( p_picd != NULL );
- ASSERT( p_picd->m_dc.GetSafeHdc() != NULL );
- if( ! _PaintExpandedItemContent(*p_picd) )
- return 0;
- return (!0);
- }
- void CExtHeaderCtrl::SortRulesGet(
- CExtListCtrlDataSortOrder & _sortOrder
- ) const
- {
- ASSERT_VALID( this );
- _sortOrder = m_sortOrder;
- }
- void CExtHeaderCtrl::SortRulesSet(
- const CExtListCtrlDataSortOrder & _sortOrder
- )
- {
- ASSERT_VALID( this );
- m_sortOrder = _sortOrder;
- if( GetSafeHwnd() != NULL )
- Invalidate();
- }
- void CExtHeaderCtrl::OnPaint()
- {
- ASSERT_VALID( this );
- CRect rcClient;
- GetClientRect( &rcClient );
- CPaintDC dcPaint( this );
- CExtMemoryDC dc( &dcPaint, &rcClient );
- OnEraseHeaderBackground( dc, rcClient );
- INT nColNo, nColCount = INT(GetItemCount());
- for( nColNo = 0; nColNo < nColCount; nColNo++ )
- {
- CRect _rcItemEntire;
- if( ! GetItemRect( nColNo, &_rcItemEntire ) )
- continue;
- if( ! dc.RectVisible( &_rcItemEntire ) )
- continue;
- HD_ITEM _item;
- ::memset( &_item, 0, sizeof(HD_ITEM) );
- _item.mask = UINT(-1);
- TCHAR strText[ 1024 ];
- _item.cchTextMax = sizeof( strText ) / sizeof( strText[0] );
- _item.pszText = strText;
- GetItem( nColNo, &_item );
- OnPaintHeaderItem( dc, _item, nColNo, _rcItemEntire );
- }
- }
- void CExtHeaderCtrl::OnEraseHeaderBackground(
- CDC & dc,
- const CRect & rcClient
- ) const
- {
- ASSERT_VALID( this );
- ASSERT( dc.GetSafeHdc() != NULL );
- PmBridge_GetPM()->Header_PaintBackground(
- dc,
- rcClient,
- (CObject*)this
- );
- }
- CSize CExtHeaderCtrl::OnCalcHeaderItemSize(
- INT nColNo
- ) const
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return CSize( 0, 0 );
- INT nColCount = INT( GetItemCount() );
- ASSERT( 0 <= nColNo && nColNo < nColCount );
- CExtPaintManager * pPM = PmBridge_GetPM();
- ASSERT_VALID( pPM );
- const EXTENDED_ITEM_DATA & _eii = ExtendedItemDataGet( nColNo );
- CSize _sizeEntireItem( 0, 0 );
- if( ! _eii.m_iconButton.IsEmpty() )
- {
- CSize sizeButton = _eii.m_iconButton.GetSize();
- INT nButtonPaddingBefore = 0, nButtonPaddingAfter = 0;
- pPM->Header_GetButtonPadding( nButtonPaddingBefore, nButtonPaddingAfter, nColNo, nColCount, (CObject*)this );
- sizeButton.cx += nButtonPaddingBefore + nButtonPaddingAfter;
- _sizeEntireItem.cx += sizeButton.cx;
- _sizeEntireItem.cy = max( _sizeEntireItem.cy, sizeButton.cy );
- }
- if( ! _eii.m_iconItem.IsEmpty() )
- {
- INT nBetweenIconAndText = pPM->Header_GetDistanceBetweenIconAndText( nColNo, nColCount, (CObject*)this );
- CSize _sizeIcon = _eii.m_iconItem.GetSize();
- _sizeIcon.cx += nBetweenIconAndText;
- _sizeEntireItem.cx += _sizeIcon.cx;
- _sizeEntireItem.cy = max( _sizeEntireItem.cy, _sizeIcon.cy );
- }
- INT nSortRuleNo = m_sortOrder.GetColPos( nColNo );
- if( nSortRuleNo >= 0 )
- {
- INT nBetweenIconAndSortArrow = pPM->Header_GetDistanceBetweenIconAndSortArrow( nColNo, nColCount, (CObject*)this );
- INT nSortArrowExtent = pPM->Header_GetSortArrowWidth( nColNo, nColCount, (CObject*)this );
- _sizeEntireItem.cx += nSortArrowExtent + nBetweenIconAndSortArrow;
- }
- HD_ITEM _item;
- ::memset( &_item, 0, sizeof(HD_ITEM) );
- _item.mask = UINT(HDI_TEXT);
- TCHAR strText[ 1024 ];
- _item.cchTextMax = sizeof( strText ) / sizeof( strText[0] );
- _item.pszText = strText;
- GetItem( nColNo, &_item );
- CExtSafeString s;
- s = _item.pszText;
- CFont * pFont = &pPM->m_FontNormal; //GetFont();
- if( pFont->GetSafeHandle() == NULL )
- pFont = &(pPM->m_FontNormal);
- CClientDC dc( (CWnd*)this );
- CSize _sizeText = CExtPaintManager::stat_CalcTextDimension( dc, *pFont, s ).Size();
- _sizeEntireItem.cx += _sizeText.cx;
- _sizeEntireItem.cy = max( _sizeEntireItem.cy, _sizeText.cy );
- CRect rcItemPadding = pPM->Header_GetItemPadding( nColNo, nColCount, (CObject*)this );
- _sizeEntireItem.cx += rcItemPadding.left + rcItemPadding.right;
- _sizeEntireItem.cy += rcItemPadding.top + rcItemPadding.bottom;
- return _sizeEntireItem;
- }
- void CExtHeaderCtrl::OnCalcHeaderItemLayout(
- INT nColNo,
- const CRect & _rcItemEntire,
- CRect & _rcItem,
- CRect & _rcIcon,
- CRect & _rcText,
- CRect & _rcSortArrow,
- CRect & _rcButton,
- CRect & _rcButtonIcon,
- bool * p_bSorted, // = NULL
- bool * p_bSortedAscending // = NULL
- ) const
- {
- ASSERT_VALID( this );
- INT nColCount = INT( GetItemCount() );
- ASSERT( 0 <= nColNo && nColNo < nColCount );
- CExtPaintManager * pPM = PmBridge_GetPM();
- ASSERT_VALID( pPM );
- _rcItem = _rcItemEntire;
- const EXTENDED_ITEM_DATA & _eii = ExtendedItemDataGet( nColNo );
- _rcButton.SetRect( 0, 0, 0, 0 );
- _rcButtonIcon.SetRect( 0, 0, 0, 0 );
- if( ! _eii.m_iconButton.IsEmpty() )
- {
- CSize sizeButton = _eii.m_iconButton.GetSize();
- INT nButtonPaddingBefore = 0, nButtonPaddingAfter = 0;
- pPM->Header_GetButtonPadding( nButtonPaddingBefore, nButtonPaddingAfter, nColNo, nColCount, (CObject*)this );
- INT nButtonExtent = sizeButton.cx + nButtonPaddingBefore + nButtonPaddingAfter;
- _rcButton = _rcItem;
- _rcItem.right -= nButtonExtent;
- _rcButton.left = _rcItem.right;
- _rcButtonIcon = _rcButton;
- _rcButtonIcon.DeflateRect( nButtonPaddingBefore, 0, nButtonPaddingAfter, 0 );
- if( _rcButtonIcon.Height() != sizeButton.cy )
- {
- _rcButtonIcon.top += ( _rcButtonIcon.Height() - sizeButton.cy ) / 2;
- _rcButtonIcon.bottom = _rcButtonIcon.top + sizeButton.cy;
- }
- }
- CRect rcItemPadding = pPM->Header_GetItemPadding( nColNo, nColCount, (CObject*)this );
- _rcItem.DeflateRect( &rcItemPadding );
- _rcText = _rcItem;
- _rcIcon.SetRect( 0, 0, 0, 0 );
- if( ! _eii.m_iconItem.IsEmpty() )
- {
- INT nBetweenIconAndText = pPM->Header_GetDistanceBetweenIconAndText( nColNo, nColCount, (CObject*)this );
- CSize _sizeIcon = _eii.m_iconItem.GetSize();
- _rcText.left += _sizeIcon.cx + nBetweenIconAndText;
- _rcIcon = _rcItem;
- _rcIcon.right = _rcIcon.left + _sizeIcon.cx;
- if( _rcIcon.Height() != _sizeIcon.cy )
- {
- _rcIcon.top += ( _rcIcon.Height() - _sizeIcon.cy ) / 2;
- _rcIcon.bottom = _rcIcon.top + _sizeIcon.cy;
- }
- }
- _rcSortArrow.SetRect( 0, 0, 0, 0 );
- bool bSorted = false, bSortedAscending = false;
- INT nSortRuleNo = m_sortOrder.GetColPos( nColNo );
- if( nSortRuleNo >= 0 )
- {
- INT nSortArrowExtent = pPM->Header_GetSortArrowWidth( nColNo, nColCount, (CObject*)this );
- const CExtListCtrlDataSortOrder::COLUMN_INFO & _columnInfo = m_sortOrder.m_arrItems[ nSortRuleNo ];
- _rcSortArrow = _rcText;
- _rcSortArrow.left = _rcSortArrow.right - nSortArrowExtent;
- if( _rcSortArrow.left >= _rcText. left )
- {
- INT nBetweenIconAndSortArrow = pPM->Header_GetDistanceBetweenIconAndSortArrow( nColNo, nColCount, (CObject*)this );
- _rcText.right = _rcSortArrow.left - nBetweenIconAndSortArrow;
- bSorted = true;
- bSortedAscending = _columnInfo.m_bAscending;
- }
- }
- if( p_bSorted != NULL )
- (*p_bSorted) = bSorted;
- if( p_bSortedAscending != NULL )
- (*p_bSortedAscending) = bSortedAscending;
- }
- void CExtHeaderCtrl::OnPaintHeaderItem(
- CDC & dc,
- const HD_ITEM & _item,
- INT nColNo,
- const CRect & _rcItemEntire,
- bool bDND // = false
- ) const
- {
- ASSERT_VALID( this );
- ASSERT( dc.GetSafeHdc() != NULL );
- INT nColCount = INT( GetItemCount() );
- ASSERT( 0 <= nColNo && nColNo < nColCount );
- CExtPaintManager * pPM = PmBridge_GetPM();
- ASSERT_VALID( pPM );
- CRect _rcItem, _rcIcon, _rcText, _rcSortArrow, _rcButton, _rcButtonIcon;
- bool bSorted = false, bSortedAscending = false;
- OnCalcHeaderItemLayout(
- nColNo,
- _rcItemEntire,
- _rcItem,
- _rcIcon,
- _rcText,
- _rcSortArrow,
- _rcButton,
- _rcButtonIcon,
- &bSorted,
- &bSortedAscending
- );
- const EXTENDED_ITEM_DATA & _eii = ExtendedItemDataGet( nColNo );
- bool bHover = ( (!bDND) && (!m_bOnDividerAtRight) && nColNo == m_nHoverColNo && ( nColNo == m_nPressingColNo || m_nPressingColNo < 0 ) ) ? true : false;
- bool bPressed = ( (!bDND) && (!m_bOnDividerAtRight) && nColNo == m_nPressingColNo ) ? true : false;
- bool bButtonEvent = ( (!bDND) && (!m_bOnDividerAtRight) && m_bOnButton ) ? true : false;
- pPM->Header_PaintItem(
- dc,
- _rcItemEntire,
- _rcItem,
- _rcIcon,
- _rcText,
- _rcSortArrow,
- _rcButton,
- _rcButtonIcon,
- bSorted,
- bSortedAscending,
- nColNo,
- nColCount,
- _eii.m_iconItem,
- _eii.m_iconButton,
- bHover,
- bPressed,
- bButtonEvent,
- __EXT_MFC_SAFE_LPCTSTR(_item.pszText),
- (CObject*)this
- );
- }
- void CExtHeaderCtrl::OnCancelMode()
- {
- ASSERT_VALID( this );
- _CancelActions();
- CHeaderCtrl::OnCancelMode();
- }
- void CExtHeaderCtrl::OnCaptureChanged( CWnd * pWnd )
- {
- ASSERT_VALID( this );
- _CancelActions();
- CHeaderCtrl::OnCaptureChanged( pWnd );
- }
- CExtPopupMenuTipWnd * CExtHeaderCtrl::OnAdvancedPopupMenuTipWndGet() const
- {
- if( m_nAdvancedTipStyle == INT(CExtPopupMenuTipWnd::__ETS_NONE) )
- return NULL;
- return (&( CExtPopupMenuSite::g_DefPopupMenuSite.GetTip() ));
- }
- void CExtHeaderCtrl::OnAdvancedPopupMenuTipWndDisplay(
- CExtPopupMenuTipWnd & _ATTW,
- const RECT & rcExcludeArea,
- __EXT_MFC_SAFE_LPCTSTR strToolTipText
- ) const
- {
- ASSERT_VALID( this );
- if( ( ! m_bShowTipsOverHeader ) || LPCTSTR(strToolTipText) == NULL || _tcslen( LPCTSTR(strToolTipText) ) == 0 )
- {
- _ATTW.Hide();
- return;
- }
- _ATTW.SetText( LPCTSTR(strToolTipText) );
- _ATTW.SetTipStyle( (CExtPopupMenuTipWnd::e_tip_style_t)m_nAdvancedTipStyle );
- _ATTW.Show( (CWnd*)this, rcExcludeArea );
- }
- INT CExtHeaderCtrl::ColNo2VisualIndex( INT nColNo ) const // convert column number to visual index
- {
- ASSERT_VALID( this );
- if( nColNo < 0 || GetSafeHwnd() == NULL )
- return -1;
- INT nColCount = INT(GetItemCount());
- ASSERT( nColCount >= 0 );
- if( nColNo >= nColCount )
- return -1;
- INT * pArr = NULL, nIndex = -1;
- try
- {
- pArr = new INT[ nColCount ];
- if( ! ( const_cast < CExtHeaderCtrl * > ( this ) ) -> GetOrderArray( pArr, nColCount ) )
- ::AfxThrowUserException();
- for( nIndex = 0; nIndex < nColCount; nIndex ++ )
- {
- if( pArr[nIndex] == nColNo )
- break;
- }
- }
- catch( CException * pException )
- {
- pException->Delete();
- }
- if( pArr != NULL )
- delete pArr;
- if( nIndex >= nColCount )
- return -1;
- return nIndex;
- }
- INT CExtHeaderCtrl::VisualIndex2ColNo( INT nIndex ) const // convert visual index to column number
- {
- ASSERT_VALID( this );
- if( nIndex < 0 || GetSafeHwnd() == NULL )
- return -1;
- INT nColCount = INT(GetItemCount());
- ASSERT( nColCount >= 0 );
- if( nIndex >= nColCount )
- return -1;
- INT * pArr = NULL, nColNo = -1;
- try
- {
- pArr = new INT[ nColCount ];
- if( ! ( const_cast < CExtHeaderCtrl * > ( this ) ) -> GetOrderArray( pArr, nColCount ) )
- ::AfxThrowUserException();
- nColNo = pArr[nIndex];
- }
- catch( CException * pException )
- {
- pException->Delete();
- }
- if( pArr != NULL )
- delete pArr;
- if( nColNo >= nColCount )
- return -1;
- return nColNo;
- }
- INT CExtHeaderCtrl::HitTestHeaderItem(
- const POINT & ptClient,
- bool * p_bOnButton, // = NULL
- bool * p_bOnDividerAtRight, // = NULL
- bool bComputeZeroWidthItem // = true
- ) const
- {
- ASSERT_VALID( this );
- if( p_bOnButton != NULL )
- (*p_bOnButton) = false;
- if( p_bOnDividerAtRight != NULL )
- (*p_bOnDividerAtRight) = false;
- if( GetSafeHwnd() == NULL )
- return -1;
- INT nColCount = INT(GetItemCount());
- ASSERT( nColCount >= 0 );
- if( nColCount == 0 )
- return -1;
- bool bOnButton = false, bOnDividerAtRight = false;
- HDHITTESTINFO _hdhti;
- ::memset( &_hdhti, 0, sizeof(HDHITTESTINFO) );
- _hdhti.pt = ptClient;
- ::SendMessage( m_hWnd, HDM_HITTEST, 0, LPARAM( &_hdhti ) );
- INT nColNo = INT(_hdhti.iItem);
- CRect _rcItemEntire, _rcItem, _rcIcon, _rcText, _rcSortArrow, _rcButton, _rcButtonIcon;
- bool bCheckLast = false;
- if( nColNo >= 0 )
- {
- if( ! GetItemRect( nColNo, &_rcItemEntire ) )
- return -1;
- OnCalcHeaderItemLayout(
- nColNo,
- _rcItemEntire,
- _rcItem,
- _rcIcon,
- _rcText,
- _rcSortArrow,
- _rcButton,
- _rcButtonIcon
- );
- if( _rcButton.PtInRect( ptClient ) )
- bOnButton = true;
- CRect rc = _rcItemEntire;
- rc.left = rc.right - m_nDividerHalfExtent;
- if( rc.PtInRect( ptClient ) )
- bOnDividerAtRight = true;
- else
- {
- INT nIndex = ColNo2VisualIndex( nColNo );
- if( nIndex > 0 )
- {
- rc = _rcItemEntire;
- rc.right = rc.left + m_nDividerHalfExtent;
- if( rc.PtInRect( ptClient ) )
- {
- bOnDividerAtRight = true;
- nIndex --;
- nColNo = VisualIndex2ColNo( nIndex );
- } // if( rc.PtInRect( ptClient ) )
- else if( nIndex < ( nColCount - 1 ) )
- {
- INT nColNoNext = VisualIndex2ColNo( nIndex + 1 );
- if( nColNoNext >= 0 )
- {
- CRect rcNext;
- if( GetItemRect( nColNoNext, &rcNext ) )
- {
- CRect rc = rcNext;
- rc.right = rc.left + m_nDividerHalfExtent;
- if( rc.PtInRect( ptClient ) )
- bOnDividerAtRight = true;
- } // if( GetItemRect( nColNoNext, &rcNext ) )
- } // if( nColNoNext >= 0 )
- } // else if( nIndex < ( nColCount - 1 ) )
- else if( nIndex == ( nColCount - 1 ) )
- bCheckLast = true;
- } // if( nIndex > 0 )
- } // else from if( rc.PtInRect( ptClient ) )
- } // if( nColNo >= 0 )
- if( bCheckLast )
- {
- INT nColNoLast = VisualIndex2ColNo( nColCount - 1 );
- if( ! GetItemRect( nColNoLast, &_rcItemEntire ) )
- return -1;
- OnCalcHeaderItemLayout(
- nColNoLast,
- _rcItemEntire,
- _rcItem,
- _rcIcon,
- _rcText,
- _rcSortArrow,
- _rcButton,
- _rcButtonIcon
- );
- CRect rc = _rcItemEntire;
- rc.left = rc.right;
- rc.right += m_nDividerHalfExtent;
- if( rc.PtInRect( ptClient ) )
- {
- bOnDividerAtRight = true;
- nColNo = nColNoLast;
- } // if( rc.PtInRect( ptClient ) )
- } // if( bCheckLast )
- if( bOnDividerAtRight )
- {
- const EXTENDED_ITEM_DATA & _eii = m_arrExtendedData.ElementAt( nColNo );
- if( ! _eii.CanBeResized() )
- bOnDividerAtRight = false;
- }
- if( bOnDividerAtRight )
- {
- bOnButton = false;
- if( nColNo >= 0 && bComputeZeroWidthItem )
- {
- INT nIndex = ColNo2VisualIndex( nColNo );
- if( nIndex >= 0 )
- {
- for( nIndex ++; nIndex < nColCount; nIndex++ )
- {
- CRect _rcItemEntire( 0, 32767, 0, 0 );
- INT nTmpColNo = VisualIndex2ColNo( nIndex );
- if( nTmpColNo <= 0 )
- break;
- if( ! GetItemRect( nTmpColNo, &_rcItemEntire ) )
- break;
- if( _rcItemEntire.Width() > 0 )
- break;
- nColNo = nTmpColNo;
- }
- } // if( nIndex >= 0 )
- } // if( nColNo >= 0 && bComputeZeroWidthItem )
- } // if( bOnDividerAtRight )
- else
- {
- if( nColNo >= 0 && bComputeZeroWidthItem )
- {
- INT nIndex = ColNo2VisualIndex( nColNo );
- for( ; 0 <= nIndex && nIndex < nColCount; nIndex++ )
- {
- CRect _rcItemEntire( 0, 32767, 0, 0 );
- INT nTmpColNo = VisualIndex2ColNo( nIndex );
- if( nTmpColNo <= 0 )
- break;
- if( ! GetItemRect( nTmpColNo, &_rcItemEntire ) )
- break;
- if( _rcItemEntire.Width() > 0 )
- break;
- nColNo = nTmpColNo;
- bOnButton = false;
- bOnDividerAtRight = true;
- } // for( ; 0 <= nIndex && nIndex < nColCount; nIndex++ )
- }
- } // else from if( bOnDividerAtRight )
- if( p_bOnButton != NULL )
- (*p_bOnButton) = bOnButton;
- if( p_bOnDividerAtRight != NULL )
- (*p_bOnDividerAtRight) = bOnDividerAtRight;
- return nColNo;
- }
- bool CExtHeaderCtrl::_DndIsAllowed(
- INT nColNo // = -1
- ) const
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return false;
-
- CWnd * pWndParent = GetParent();
- if( pWndParent != NULL
- && pWndParent->IsKindOf( RUNTIME_CLASS(CListCtrl) )
- )
- {
- if( ( ((CListCtrl*)pWndParent)->GetExtendedStyle() & LVS_EX_HEADERDRAGDROP ) == 0 )
- return false;
- }
- else
- {
- if( ( GetStyle() & HDS_DRAGDROP ) == 0 )
- return false;
- }
- if( nColNo < 0 )
- return true;
- INT nColCount = INT( GetItemCount() );
- if( nColNo >= nColCount )
- return false;
- const EXTENDED_ITEM_DATA & _eii = ExtendedItemDataGet( nColNo );
- if( _eii.m_bDisableDnd )
- return false;
- return true;
- }
- CPoint CExtHeaderCtrl::_DndGetStartOffset() const
- {
- ASSERT_VALID( this );
- return CPoint( 3, 3 );
- }
- INT CExtHeaderCtrl::_DndCalcOuterDropTarget( CPoint point ) const
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- INT nColCount = INT( GetItemCount() );
- if( nColCount == 0 )
- return -1;
- INT nColNoToDropBefore = HitTestHeaderItem( point, NULL, NULL, false );
- if( nColNoToDropBefore < 0 )
- {
- CRect rcClient;
- GetClientRect( &rcClient);
- if( rcClient.top <= point.y && point.y <= rcClient.bottom )
- {
- INT nColNoLast = VisualIndex2ColNo( nColCount - 1 );
- if( nColNoLast >= 0 )
- {
- CRect rcItem;
- if( GetItemRect( nColNoLast, &rcItem )
- && point.x >= rcItem.right
- )
- return nColCount;
- } // if( nColNoLast >= 0 )
- } // if( rcClient.top <= point.y && point.y <= rcClient.bottom )
- return -1;
- } // if( nColNoToDropBefore < 0 )
- CRect rcItem;
- if( ! GetItemRect( nColNoToDropBefore, &rcItem ) )
- return -1;
- INT nDistanceLeft = abs( point.x - rcItem.left );
- INT nDistanceRight = abs( point.x - rcItem.right );
- if( nDistanceLeft > nDistanceRight )
- {
- INT nIndexToDropBefore = ColNo2VisualIndex( nColNoToDropBefore );
- if( nIndexToDropBefore >= 0 )
- {
- ASSERT( nIndexToDropBefore < nColCount );
- nIndexToDropBefore ++;
- ASSERT( nIndexToDropBefore <= nColCount );
- if( nIndexToDropBefore == nColCount )
- nColNoToDropBefore = nColCount;
- else
- nColNoToDropBefore = VisualIndex2ColNo( nIndexToDropBefore );
- } // if( nIndexToDropBefore >= 0 )
- } // if( nDistanceLeft > nDistanceRight )
- ASSERT( nColNoToDropBefore <= nColCount );
- return nColNoToDropBefore;
- }
- void CExtHeaderCtrl::_DndDo(
- INT nColNo,
- CPoint ptStartDrag,
- bool bNotify // = true // send HDN_BEGINDRAG and HDN_ENDDRAG messages
- )
- {
- ASSERT_VALID( this );
- HWND hWndOwn = GetSafeHwnd();
- ASSERT( hWndOwn != NULL );
- INT nColCount = INT( GetItemCount() );
- if( nColCount == 0 )
- return;
- ASSERT( 0 <= nColNo && nColNo <= nColCount );
- HWND hWndParent = ::GetParent( hWndOwn );
- if( hWndParent == NULL )
- bNotify = false;
- UINT nOwnID = UINT( GetDlgCtrlID() );
- HD_NOTIFY _data;
- ::memset( &_data, 0, sizeof(HD_NOTIFY) );
- _data.hdr.hwndFrom = hWndOwn;
- _data.hdr.idFrom = nOwnID;
- _data.hdr.code = NM_CLICK;
- _data.iButton = 0;
- _data.iItem = nColNo;
- HDITEM hdItemBuffer; // to avoid common controls crashing
- ::memset( &hdItemBuffer, 0, sizeof(HDITEM) );
- _data.pitem = &hdItemBuffer;
- if( bNotify )
- {
- HD_NOTIFY _dataA;
- ::memcpy( &_dataA, &_data, sizeof(HD_NOTIFY) );
- _dataA.hdr.code = HDN_BEGINDRAG;
- if( ::SendMessage( hWndParent, WM_NOTIFY, WPARAM(nOwnID), LPARAM(&_dataA) ) != 0 )
- return;
- }
- CExtPopupMenuTipWnd * pATTW = OnAdvancedPopupMenuTipWndGet();
- if( pATTW != NULL )
- pATTW->Hide();
- CRect rcDND;
- if( ! GetItemRect( nColNo, &rcDND ) )
- return;
- ClientToScreen( &rcDND );
- CExtContentExpandWnd wndDND, wndArrows;
- if( ! wndDND.Activate(
- rcDND,
- this,
- __ECWAF_DEF_EXPANDED_ITEM_PAINTER
- |__ECWAF_NO_CAPTURE
- |__ECWAF_REDIRECT_MOUSE
- |__ECWAF_REDIRECT_NO_DEACTIVATE
- |__ECWAF_REDIRECT_AND_HANDLE
- |__ECWAF_HANDLE_MOUSE_ACTIVATE
- |__ECWAF_MA_NOACTIVATE
- )
- )
- {
- ASSERT( FALSE );
- return;
- }
- CPoint ptShiftLast( 0, 0 );
- CRect rcInitialWndDND;
- wndDND.GetWindowRect( &rcInitialWndDND );
- ASSERT( m_hCursorOuterDragOK != NULL );
- ASSERT( m_hCursorOuterDragCancel != NULL );
- ::SetCursor( m_hCursorOuterDragOK );
- bool bStopFlag = false;
- INT nLastTargetColNoToDropBefore = -1;
- INT nLastTargetIndexToDropBefore = -1;
- CRect rcArrows( 0, 0, 0, 0 );
- for( MSG msg;
- ::IsWindow( hWndOwn )
- && (!bStopFlag)
- ;
- )
- { // main message loop
- if( ! ::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
- {
- if( ( ! ::IsWindow( hWndOwn ) )
- || bStopFlag
- )
- break;
- if( g_bEnableOnIdleCalls )
- {
- for( LONG nIdleCounter = 0L;
- ::AfxGetThread()->OnIdle(nIdleCounter);
- nIdleCounter ++
- );
- }
- ::WaitMessage();
- continue;
- } // if( ! ::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
- switch( msg.message )
- {
- case WM_KILLFOCUS:
- if( msg.hwnd == hWndOwn )
- bStopFlag = true;
- break;
- case WM_CANCELMODE:
- case WM_ACTIVATEAPP:
- case WM_SYSCOMMAND:
- case WM_SETTINGCHANGE:
- case WM_SYSCOLORCHANGE:
- bStopFlag = true;
- break;
- case WM_COMMAND:
- if( (HIWORD(msg.wParam)) == 0
- || (HIWORD(msg.wParam)) == 1
- )
- bStopFlag = true;
- break;
- case WM_CAPTURECHANGED:
- if( (HWND)msg.wParam != hWndOwn )
- bStopFlag = true;
- break;
- case WM_MOUSEWHEEL:
- if( msg.hwnd != hWndOwn )
- bStopFlag = true;
- else
- {
- ::PeekMessage(&msg,NULL,msg.message,msg.message,PM_REMOVE);
- continue;
- } // else from if( msg.hwnd != hWndOwn )
- break;
- case WM_MOUSEMOVE:
- if( msg.hwnd != hWndOwn )
- bStopFlag = true;
- else
- {
- ASSERT_VALID( this );
- ::PeekMessage(&msg,NULL,msg.message,msg.message,PM_REMOVE);
- CPoint point;
- point = DWORD( msg.lParam );
- CPoint ptShift = point - ptStartDrag;
- if( ptShift != ptShiftLast )
- {
- INT nColNoDropBefore = _DndCalcOuterDropTarget( point );
- INT nIndexDropBefore = -1;
- ASSERT( nColNoDropBefore <= nColCount );
- if( nColNoDropBefore >= 0 )
- {
- if( nColNoDropBefore == nColCount )
- nIndexDropBefore = nColCount;
- else
- {
- nIndexDropBefore = ColNo2VisualIndex( nColNoDropBefore );
- if( nIndexDropBefore < 0 )
- nColNoDropBefore = -1;
- }
- }
- if( nLastTargetIndexToDropBefore != nIndexDropBefore )
- {
- nLastTargetColNoToDropBefore = nColNoDropBefore;
- nLastTargetIndexToDropBefore = nIndexDropBefore;
- rcArrows.SetRect( 0, 0, 0, 0 );
- if( nLastTargetIndexToDropBefore >= 0 )
- {
- if( nLastTargetIndexToDropBefore == nColCount )
- {
- INT nColNoLast = VisualIndex2ColNo( nColCount - 1 );
- if( GetItemRect( nColNoLast, &rcArrows ) )
- rcArrows.left = rcArrows.right;
- else
- rcArrows.SetRect( 0, 0, 0, 0 );
- }
- else
- {
- if( GetItemRect( nLastTargetColNoToDropBefore, &rcArrows ) )
- rcArrows.right = rcArrows.left;
- else
- rcArrows.SetRect( 0, 0, 0, 0 );
- }
- if( rcArrows.Height() == 0 )
- nLastTargetColNoToDropBefore = -1;
- } // if( nLastTargetColNoToDropBefore >= 0 )
- if( nLastTargetColNoToDropBefore >= 0 )
- {
- VERIFY(
- wndArrows.Activate(
- rcArrows,
- this,
- __ECWAF_DRAW_RED_ARROWS
- |__ECWAF_TRANSPARENT_ITEM
- |__ECWAF_NO_CAPTURE
- |__ECWAF_REDIRECT_MOUSE
- |__ECWAF_REDIRECT_NO_DEACTIVATE
- |__ECWAF_REDIRECT_AND_HANDLE
- |__ECWAF_HANDLE_MOUSE_ACTIVATE
- |__ECWAF_MA_NOACTIVATE
- )
- );
- if( wndArrows.GetSafeHwnd() != NULL )
- {
- wndArrows.SetWindowPos(
- &wndDND, 0, 0, 0, 0,
- SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE
- );
- ::SetCursor( m_hCursorOuterDragOK );
- }
- else
- nLastTargetColNoToDropBefore = -1;
- } // if( nLastTargetColNoToDropBefore >= 0 )
- } // if( nLastTargetIndexToDropBefore != nIndexDropBefore )
- if( nLastTargetColNoToDropBefore < 0 )
- {
- wndArrows.Deactivate();
- ::SetCursor( m_hCursorOuterDragCancel );
- }
- ptShiftLast = ptShift;
- CRect rcWnd( rcInitialWndDND );
- rcWnd.OffsetRect( ptShift );
- wndDND.MoveWindow( &rcWnd );
- wndDND.UpdateWindow();
- if( wndArrows.GetSafeHwnd() != NULL )
- wndArrows.UpdateWindow();
- UpdateWindow();
- CExtPaintManager::stat_PassPaintMessages();
- } // if( ptShift != ptShiftLast )
- continue;
- } // else from if( msg.hwnd != hWndOwn )
- break;
- case WM_LBUTTONUP:
- case WM_RBUTTONUP:
- case WM_MBUTTONUP:
- bStopFlag = true;
- ::PeekMessage(&msg,NULL,msg.message,msg.message,PM_REMOVE);
- break;
- case WM_LBUTTONDBLCLK:
- case WM_LBUTTONDOWN:
- case WM_RBUTTONDBLCLK:
- case WM_RBUTTONDOWN:
- case WM_MBUTTONDBLCLK:
- case WM_MBUTTONDOWN:
- case WM_CONTEXTMENU:
- case WM_NCLBUTTONUP:
- case WM_NCLBUTTONDBLCLK:
- case WM_NCLBUTTONDOWN:
- case WM_NCRBUTTONUP:
- case WM_NCRBUTTONDBLCLK:
- case WM_NCRBUTTONDOWN:
- case WM_NCMBUTTONUP:
- case WM_NCMBUTTONDBLCLK:
- case WM_NCMBUTTONDOWN:
- bStopFlag = true;
- break;
- default:
- if( WM_KEYFIRST <= msg.message
- && msg.message <= WM_KEYLAST
- )
- {
- bStopFlag = true;
- ::PeekMessage(&msg,NULL,msg.message,msg.message,PM_REMOVE);
- }
- break;
- } // switch( msg.message )
- if( bStopFlag )
- break;
- if( ! ::AfxGetThread() -> PumpMessage() )
- break;
- } // message loop
- wndDND.Deactivate();
- wndArrows.Deactivate();
- if( ! ::IsWindow( hWndOwn ) )
- return;
- _CancelActions();
- _DoSetCursor();
- if( nLastTargetColNoToDropBefore >= 0 )
- _DndSwap( nColNo, nLastTargetColNoToDropBefore );
- if( bNotify && (! ::IsWindow( hWndParent ) ) )
- bNotify = false;
- if( bNotify )
- {
- HD_NOTIFY _dataA;
- HDITEM hdItemBuffer; // to avoid common controls crashing
- ::memset( &hdItemBuffer, 0, sizeof(HDITEM) );
- _data.pitem = &hdItemBuffer;
- ::memcpy( &_dataA, &_data, sizeof(HD_NOTIFY) );
- _dataA.hdr.code = HDN_ENDDRAG;
- ::SendMessage( hWndParent, WM_NOTIFY, WPARAM(nOwnID), LPARAM(&_dataA) );
- }
- Invalidate();
- UpdateWindow();
- }
- void CExtHeaderCtrl::_DndSwap( INT nColNo, INT nColNoToDropBefore )
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- if( nColNo < 0 || nColNoToDropBefore < 0 )
- return;
- INT nColCount = INT( GetItemCount() );
- if( nColCount == 0 )
- return;
- INT nIndex = ColNo2VisualIndex( nColNo );
- if( nIndex < 0 )
- return;
- INT nIndexToDropBefore = ( nColNoToDropBefore == nColCount ) ? nColCount : ColNo2VisualIndex( nColNoToDropBefore );
- if( nIndexToDropBefore < 0 )
- return;
- if( nIndexToDropBefore == nIndex || nIndexToDropBefore == (nIndex+1) )
- return;
- if( nColNo >= nColCount || nColNoToDropBefore > nColCount )
- return;
- if( nIndex >= nColCount || nIndexToDropBefore > nColCount )
- return;
- INT * pArr = NULL;
- try
- {
- pArr = new INT[ nColCount ];
- if( ! GetOrderArray( pArr, nColCount ) )
- ::AfxThrowUserException();
- if( nIndexToDropBefore < nIndex )
- {
- INT nVal = pArr[nIndex];
- INT nPos = nIndex;
- for( ; nPos > nIndexToDropBefore; nPos -- )
- pArr[nPos] = pArr[nPos-1];
- pArr[nIndexToDropBefore] = nVal;
- }
- else
- {
- ASSERT( nIndexToDropBefore > (nIndex+1) );
- INT nVal = pArr[nIndex];
- INT nPos = nIndexToDropBefore-1;
- for( ; nPos > nIndex; nPos -- )
- pArr[nPos] = pArr[nPos-1];
- pArr[nIndexToDropBefore-1] = nVal;
- }
- VERIFY( SetOrderArray( nColCount, pArr ) );
- }
- catch( CException * pException )
- {
- pException->Delete();
- }
- if( pArr != NULL )
- delete pArr;
- }
- bool CExtHeaderCtrl::_PaintExpandedItemContent(
- CExtContentExpandWnd::PAINT_ITEM_CONTENT_DATA & picd
- ) const
- {
- ASSERT_VALID( this );
- ASSERT( picd.m_dc.GetSafeHdc() != NULL );
- if( m_nPressingColNo >= 0 )
- { // drag-n-dropped item
- OnEraseHeaderBackground( picd.m_dc, picd.m_rcItem );
- HD_ITEM _item;
- ::memset( &_item, 0, sizeof(HD_ITEM) );
- _item.mask = UINT(-1);
- TCHAR strText[ 1024 ];
- ::memset( strText, 0, sizeof( strText ) );
- _item.cchTextMax = sizeof( strText ) / sizeof( strText[0] );
- _item.pszText = strText;
- GetItem( m_nPressingColNo, &_item );
- OnPaintHeaderItem( picd.m_dc, _item, m_nPressingColNo, picd.m_rcItem, true );
- return true;
- } // drag-n-dropped item
- return false;
- }
- bool CExtHeaderCtrl::_DoSetCursor()
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- return _DoSetCursor( CPoint(-32767,-32767) );
- }
- bool CExtHeaderCtrl::_DoSetCursor( const POINT ptScreen ) // CPoint(-32767,-32767) means invoke ::GetCursorPos()
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- CPoint point = ptScreen;
- if( point.x == -32767 || point.y == -32767 )
- {
- if( ! ::GetCursorPos( &point ) )
- return false;
- }
- HCURSOR hCursor = NULL;
- HWND hWndFromPoint = ::WindowFromPoint( point );
- if( hWndFromPoint == m_hWnd )
- {
- ScreenToClient( &point );
- bool bZeroResizing = false, bResizing = ( m_nPressingColNo >= 0 && m_bOnDividerAtRight ) ? true : false;
- if( ! bResizing )
- {
- bool bOnButton = false, bOnDividerAtRight = false;
- INT nColNo = -1, nIndex = -1;
- if( CExtPopupMenuWnd::TestHoverEnabledFromActiveHWND( m_hWnd ) )
- {
- nColNo = HitTestHeaderItem( point, &bOnButton, &bOnDividerAtRight );
- nIndex = ColNo2VisualIndex( nColNo );
- }
- bResizing = ( nIndex >= 0 && bOnDividerAtRight ) ? true : false;
- if( bResizing )
- {
- CRect rcItem( 0, 32767, 0, 0 );
- if( GetItemRect( nColNo, &rcItem )
- && rcItem.Width() == 0
- )
- bZeroResizing = true;
- }
- } // if( ! bResizing )
- hCursor =
- bResizing
- ? ( bZeroResizing ? m_hCursorResizingH2 : m_hCursorResizingH1 )
- : m_hCursorDefault
- ;
- if( hCursor == NULL )
- hCursor = ::LoadCursor( NULL, bResizing ? IDC_SIZEWE : IDC_ARROW );
- } // if( hWndFromPoint == m_hWnd )
- if( hCursor == NULL )
- return false;
- ::SetCursor( hCursor );
- return true;
- }
- BOOL CExtHeaderCtrl::OnSetCursor( CWnd * pWnd, UINT nHitTest, UINT message )
- {
- ASSERT_VALID( this );
- pWnd;
- nHitTest;
- message;
- return _DoSetCursor() ? TRUE : FALSE;
- }
- INT CExtHeaderCtrl::HeaderItemExtentGet( INT nColNo ) const
- {
- ASSERT_VALID( this );
- ASSERT( 0 <= nColNo && nColNo < INT(GetItemCount()) );
- if( GetSafeHwnd() == NULL )
- return 0;
- HD_ITEM _item;
- ::memset( &_item, 0, sizeof(HD_ITEM) );
- _item.mask = HDI_WIDTH;
- GetItem( nColNo, &_item );
- INT nCurrentItemExtent = INT(_item.cxy);
- return nCurrentItemExtent;
- }
- void CExtHeaderCtrl::HeaderItemExtentSet(
- INT nColNo,
- INT nExtent,
- bool bRedraw // = true
- )
- {
- ASSERT_VALID( this );
- ASSERT( 0 <= nColNo && nColNo < INT(GetItemCount()) );
- if( GetSafeHwnd() == NULL )
- return;
- const EXTENDED_ITEM_DATA & _eii = m_arrExtendedData.ElementAt( nColNo );
- if( nExtent < _eii.m_nExtentMin )
- nExtent = _eii.m_nExtentMin;
- if( nExtent > _eii.m_nExtentMax )
- nExtent = _eii.m_nExtentMax;
- if( nExtent < 0 )
- nExtent = 0;
- HD_ITEM _item;
- ::memset( &_item, 0, sizeof(HD_ITEM) );
- _item.mask = HDI_WIDTH;
- GetItem( nColNo, &_item );
- INT nCurrentItemExtent = INT(_item.cxy);
- if( nCurrentItemExtent == nExtent )
- return;
- _item.mask = HDI_WIDTH;
- _item.cxy = nExtent;
- SetItem( nColNo, &_item );
- if( bRedraw )
- Invalidate();
- }
- void CExtHeaderCtrl::OnMouseMove( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- // CHeaderCtrl::OnMouseMove( nFlags, point );
- nFlags;
- if( m_nPressingColNo >= 0 )
- {
- CExtPopupMenuTipWnd * pATTW = OnAdvancedPopupMenuTipWndGet();
- if( pATTW != NULL )
- pATTW->Hide();
- if( m_bOnDividerAtRight )
- {
- CPoint ptScreenPressing = point;
- ClientToScreen( &ptScreenPressing );
- INT nExtent = ptScreenPressing.x - m_ptScreenPressing.x + m_nHelperInitialResizingExtent;
- HeaderItemExtentSet( m_nPressingColNo, nExtent );
- _DoSetCursor();
- if( m_bOnDividerAtRight )
- {
- HWND hWndParent = ::GetParent( m_hWnd );
- if( hWndParent != NULL )
- {
- UINT nOwnID = UINT( GetDlgCtrlID() );
- HD_NOTIFY _data, _data2;
- ::memset( &_data, 0, sizeof(HD_NOTIFY) );
- ::memset( &_data2, 0, sizeof(HD_NOTIFY) );
- _data.hdr.hwndFrom = m_hWnd;
- _data.hdr.idFrom = nOwnID;
- _data.iButton = 0;
- _data.iItem = m_nPressingColNo; // nColNo;
- _data.hdr.code = HDN_TRACK;
- HDITEM hdItemBuffer; // to avoid common controls crashing
- ::memset( &hdItemBuffer, 0, sizeof(HDITEM) );
- _data.pitem = &hdItemBuffer;
- ::memcpy( &_data2, &_data, sizeof(HD_NOTIFY) );
- ::SendMessage( hWndParent, WM_NOTIFY, WPARAM(nOwnID), LPARAM(&_data) );
- _data2.hdr.code = HDN_ITEMCHANGED;
- ::SendMessage( hWndParent, WM_NOTIFY, WPARAM(nOwnID), LPARAM(&_data2) );
- if( ::IsWindow( hWndParent ) && ::IsWindowVisible( hWndParent ) )
- ::InvalidateRect( hWndParent, NULL, TRUE );
- } // if( hWndParent != NULL )
- } // if( m_bOnDividerAtRight )
- return;
- }
- else if( ! m_bOnButton )
- {
- if( _DndIsAllowed( m_nPressingColNo ) )
- {
- CPoint ptOffset = _DndGetStartOffset();
- CPoint ptClientPressing;
- ptClientPressing = m_ptScreenPressing;
- ScreenToClient( &ptClientPressing );
- CPoint ptDiff = ptClientPressing - point;
- if( abs(ptDiff.x) >= ptOffset.x || abs(ptDiff.y) >= ptOffset.y )
- {
- _DndDo( m_nPressingColNo, m_ptScreenPressing );
- return;
- }
- }
- }
- }
- bool bOnButton = false, bOnDividerAtRight = false;
- INT nColNo = -1;
- if( CExtPopupMenuWnd::TestHoverEnabledFromActiveHWND( m_hWnd ) )
- {
- CPoint ptScreen;
- ptScreen = point;
- ClientToScreen( &ptScreen );
- if( ::WindowFromPoint( ptScreen ) == m_hWnd )
- nColNo = HitTestHeaderItem( point, &bOnButton, &bOnDividerAtRight );
- }
- bool bHoverChanged = false;
- if( m_nHoverColNo != nColNo
- || m_bOnButton != bOnButton
- || ( m_bOnDividerAtRight != bOnDividerAtRight && ( ! CExtPopupMenuWnd::IsKeyPressed( VK_LBUTTON ) ) )
- )
- {
- bHoverChanged = true;
- m_nHoverColNo = nColNo;
- m_nHoverIndex = ColNo2VisualIndex( m_nHoverColNo );
- m_bOnButton = bOnButton;
- m_bOnDividerAtRight = bOnDividerAtRight;
- if( m_bOnDividerAtRight )
- {
- HWND hWndParent = ::GetParent( m_hWnd );
- if( hWndParent != NULL )
- {
- UINT nOwnID = UINT( GetDlgCtrlID() );
- HD_NOTIFY _data;
- ::memset( &_data, 0, sizeof(HD_NOTIFY) );
- _data.hdr.hwndFrom = m_hWnd;
- _data.hdr.idFrom = nOwnID;
- _data.iButton = 0;
- _data.iItem = nColNo;
- _data.hdr.code = HDN_BEGINTRACK;
- HDITEM hdItemBuffer; // to avoid common controls crashing
- ::memset( &hdItemBuffer, 0, sizeof(HDITEM) );
- _data.pitem = &hdItemBuffer;
- ::SendMessage( hWndParent, WM_NOTIFY, WPARAM(nOwnID), LPARAM(&_data) );
- } // if( hWndParent != NULL )
- } // if( m_bOnDividerAtRight )
- }
- if( bHoverChanged )
- {
- if( m_nPressingColNo < 0 )
- {
- HWND hWndCapture = ::GetCapture();
- if( m_nHoverColNo >= 0 )
- {
- if( m_hWnd != hWndCapture )
- SetCapture();
- if( m_nAdvancedTipStyle != INT(CExtPopupMenuTipWnd::__ETS_NONE)
- && (! CExtPopupMenuWnd::IsMenuTracking() )
- )
- {
- CExtPopupMenuTipWnd * pATTW = OnAdvancedPopupMenuTipWndGet();
- if( pATTW != NULL )
- {
- const CExtHeaderCtrl::EXTENDED_ITEM_DATA & _eii = ExtendedItemDataGet( m_nHoverColNo );
- CRect rcArea;
- if( GetItemRect( m_nHoverColNo, rcArea ) )
- {
- CRect _rcItem, _rcIcon, _rcText, _rcSortArrow, _rcButton, _rcButtonIcon;
- bool bSorted = false, bSortedAscending = false;
- OnCalcHeaderItemLayout(
- m_nHoverColNo,
- rcArea,
- _rcItem,
- _rcIcon,
- _rcText,
- _rcSortArrow,
- _rcButton,
- _rcButtonIcon,
- &bSorted,
- &bSortedAscending
- );
- if( m_bOnButton )
- {
- rcArea.left = _rcButton.left;
- rcArea.right = _rcButton.right;
- }
- else
- {
- rcArea.left = _rcItem.left;
- rcArea.right = _rcItem.right;
- }
- ClientToScreen( &rcArea );
- OnAdvancedPopupMenuTipWndDisplay(
- *pATTW,
- rcArea,
- m_bOnButton ? LPCTSTR(_eii.m_strTipTextButton) : LPCTSTR(_eii.m_strTipTextItem)
- );
- }
- } // if( pATTW != NULL )
- }
- }
- else
- {
- if( m_hWnd == hWndCapture )
- ReleaseCapture();
- }
- } // if( m_nPressingColNo < 0 )
- Invalidate();
- _DoSetCursor();
- } // if( bHoverChanged )
- }
- void CExtHeaderCtrl::OnLButtonDown( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- // CHeaderCtrl::OnLButtonDown( nFlags, point );
- nFlags;
- m_ptScreenPressing.x = m_ptScreenPressing.y = m_nHelperInitialResizingExtent = -32767;
- ActivateTopParent();
- _DoSetCursor();
- bool bOnButton = false, bOnDividerAtRight = false;
- INT nColNo = HitTestHeaderItem( point, &bOnButton, &bOnDividerAtRight );
- if( nColNo < 0 )
- return;
- m_nPressingColNo = nColNo;
- m_nPressingIndex = ColNo2VisualIndex( m_nPressingColNo );
- m_bOnButton = bOnButton;
- m_bOnDividerAtRight = bOnDividerAtRight;
- m_ptScreenPressing = point;
- ClientToScreen( &m_ptScreenPressing );
- m_nHelperInitialResizingExtent = HeaderItemExtentGet( nColNo );
- Invalidate();
- HWND hWndCapture = ::GetCapture();
- if( m_hWnd != hWndCapture )
- SetCapture();
- CExtPopupMenuTipWnd * pATTW = OnAdvancedPopupMenuTipWndGet();
- if( pATTW != NULL )
- pATTW->Hide();
- if( m_bOnDividerAtRight )
- {
- HWND hWndParent = ::GetParent( m_hWnd );
- if( hWndParent != NULL )
- {
- UINT nOwnID = UINT( GetDlgCtrlID() );
- HD_NOTIFY _data;
- ::memset( &_data, 0, sizeof(HD_NOTIFY) );
- _data.hdr.hwndFrom = m_hWnd;
- _data.hdr.idFrom = nOwnID;
- _data.iButton = 0;
- _data.iItem = nColNo;
- _data.hdr.code = HDN_BEGINTRACK;
- HDITEM hdItemBuffer; // to avoid common controls crashing
- ::memset( &hdItemBuffer, 0, sizeof(HDITEM) );
- _data.pitem = &hdItemBuffer;
- ::SendMessage( hWndParent, WM_NOTIFY, WPARAM(nOwnID), LPARAM(&_data) );
- } // if( hWndParent != NULL )
- } // if( m_bOnDividerAtRight )
- }
- void CExtHeaderCtrl::OnLButtonUp( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- // CHeaderCtrl::OnLButtonUp( nFlags, point );
- nFlags;
- point;
- if( m_nPressingColNo < 0 )
- return;
- bool bOnButton = false, bOnDividerAtRight = false;
- INT nColNo = -1;
- CPoint ptScreen;
- ptScreen = point;
- ClientToScreen( &ptScreen );
- if( ::WindowFromPoint( ptScreen ) == m_hWnd )
- nColNo = HitTestHeaderItem( point, &bOnButton, &bOnDividerAtRight );
- if( nColNo == m_nPressingColNo )
- {
- bool bResizing = m_bOnDividerAtRight;
- bool bButtonClick = ( m_bOnButton && (!m_bOnDividerAtRight) ) ? true : false;
- if( bResizing )
- {
- _CancelActions();
- return;
- }
- if( m_bOnButton && bButtonClick )
- {
- _CancelActions();
- OnHeaderItemButtonClick( nColNo );
- return;
- }
- _CancelActions();
- OnHeaderItemClick( nColNo, 0 );
- }
- else
- _CancelActions();
- }
- void CExtHeaderCtrl::OnHeaderItemClick(
- INT nColNo,
- INT nMouseButton // 0 - left button, 1 - right button, 2 - middle button
- )
- {
- ASSERT_VALID( this );
- ASSERT( 0 <= nColNo && nColNo < INT(GetItemCount()) );
- nColNo;
- HWND hWndParent = ::GetParent( m_hWnd );
- if( hWndParent == NULL )
- return;
- UINT nOwnID = UINT( GetDlgCtrlID() );
- HD_NOTIFY _data;
- ::memset( &_data, 0, sizeof(HD_NOTIFY) );
- _data.hdr.hwndFrom = m_hWnd;
- _data.hdr.idFrom = nOwnID;
- _data.hdr.code = HDN_ITEMCLICK;
- _data.iButton = nMouseButton;
- _data.iItem = nColNo;
- HDITEM hdItemBuffer; // to avoid common controls crashing
- ::memset( &hdItemBuffer, 0, sizeof(HDITEM) );
- _data.pitem = &hdItemBuffer;
- ::SendMessage( hWndParent, WM_NOTIFY, WPARAM(nOwnID), LPARAM(&_data) );
- }
- void CExtHeaderCtrl::OnHeaderItemButtonClick( INT nColNo )
- {
- ASSERT_VALID( this );
- ASSERT( 0 <= nColNo && nColNo < INT(GetItemCount()) );
- nColNo;
- GetParent()->SendMessage( CExtHeaderCtrl::g_nMsgHeaderButtonClick, WPARAM(nColNo), LPARAM(this) );
- }
- void CExtHeaderCtrl::OnHeaderItemDividerAtRightDoubleClick( INT nColNo )
- {
- ASSERT_VALID( this );
- ASSERT( 0 <= nColNo && nColNo < INT(GetItemCount()) );
- HWND hWndParent = ::GetParent( m_hWnd );
- if( hWndParent == NULL )
- return;
- UINT nOwnID = UINT( GetDlgCtrlID() );
- HD_NOTIFY _data;
- ::memset( &_data, 0, sizeof(HD_NOTIFY) );
- _data.hdr.hwndFrom = m_hWnd;
- _data.hdr.idFrom = nOwnID;
- _data.hdr.code = HDN_ITEMDBLCLICK;
- _data.iButton = 0;
- _data.iItem = nColNo;
- HDITEM hdItemBuffer; // to avoid common controls crashing
- ::memset( &hdItemBuffer, 0, sizeof(HDITEM) );
- _data.pitem = &hdItemBuffer;
- ::SendMessage( hWndParent, WM_NOTIFY, WPARAM(nOwnID), LPARAM(&_data) );}
- void CExtHeaderCtrl::OnLButtonDblClk( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- // CHeaderCtrl::OnLButtonDown( nFlags, point );
- nFlags;
- bool bOnButton = false, bOnDividerAtRight = false;
- INT nColNo = HitTestHeaderItem( point, &bOnButton, &bOnDividerAtRight );
- if( nColNo < 0 )
- return;
- if( ! bOnDividerAtRight )
- return;
- OnHeaderItemDividerAtRightDoubleClick( nColNo );
- }
- void CExtHeaderCtrl::OnRButtonDown( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- // CHeaderCtrl::OnRButtonDown( nFlags, point );
- nFlags;
- INT nColNo = HitTestHeaderItem( point, NULL, NULL, false );
- if( nColNo >= 0 )
- {
- _CancelActions();
- OnHeaderItemClick( nColNo, 1 );
- }
- }
- void CExtHeaderCtrl::OnRButtonUp( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- // CHeaderCtrl::OnRButtonUp( nFlags, point );
- nFlags;
- point;
- }
- void CExtHeaderCtrl::OnRButtonDblClk( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- // CHeaderCtrl::OnRButtonDown( nFlags, point );
- nFlags;
- point;
- }
- void CExtHeaderCtrl::OnMButtonDown( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- // CHeaderCtrl::OnMButtonDown( nFlags, point );
- nFlags;
- INT nColNo = HitTestHeaderItem( point, NULL, NULL, false );
- if( nColNo >= 0 )
- {
- _CancelActions();
- OnHeaderItemClick( nColNo, 2 );
- }
- }
- void CExtHeaderCtrl::OnMButtonUp( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- // CHeaderCtrl::OnMButtonUp( nFlags, point );
- nFlags;
- point;
- }
- void CExtHeaderCtrl::OnMButtonDblClk( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- // CHeaderCtrl::OnMButtonDown( nFlags, point );
- nFlags;
- point;
- }
- void CExtHeaderCtrl::OnWindowPosChanging( WINDOWPOS FAR * lpwndpos )
- {
- CHeaderCtrl::OnWindowPosChanging(lpwndpos);
- Invalidate();
- }
- BOOL CExtHeaderCtrl::OnEraseBkgnd( CDC * pDC )
- {
- ASSERT_VALID( this );
- pDC;
- return TRUE;
- }
- LRESULT CExtHeaderCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch( message )
- {
- case HDM_INSERTITEM:
- {
- ASSERT( m_arrExtendedData.GetSize() == GetItemCount() );
- static EXTENDED_ITEM_DATA g_eii;
- m_arrExtendedData.InsertAt( (INT) wParam, g_eii, 1 );
- //ASSERT( m_arrExtendedData.GetSize() == GetItemCount() );
- _CancelActions();
- }
- break;
- case HDM_DELETEITEM:
- {
- //ASSERT( m_arrExtendedData.GetSize() == GetItemCount() );
- m_arrExtendedData.RemoveAt( ( int ) wParam );
- //ASSERT( m_arrExtendedData.GetSize() == GetItemCount() );
- _CancelActions();
- }
- break;
- case HDM_HITTEST:
- {
- HDHITTESTINFO * pHDHTI = reinterpret_cast < HDHITTESTINFO * > ( lParam );
- if( pHDHTI == NULL )
- return -1;
- pHDHTI->iItem = -1;
- pHDHTI->flags = HHT_NOWHERE;
- CRect rcClient;
- GetClientRect( &rcClient );
- if( pHDHTI->pt.y < rcClient.top )
- {
- pHDHTI->flags = HHT_ABOVE;
- return -1;
- }
- if( pHDHTI->pt.y > rcClient.bottom )
- {
- pHDHTI->flags = HHT_BELOW;
- return -1;
- }
- INT nColNo, nColCount = INT(GetItemCount()), nWalkWay = 0;
- for( nColNo = 0; nColNo < nColCount; nColNo++ )
- {
- CRect _rcItemEntire;
- if( ! GetItemRect( nColNo, &_rcItemEntire ) )
- continue;
- if( ! _rcItemEntire.PtInRect( pHDHTI->pt ) )
- continue;
- pHDHTI->iItem = nColNo;
- pHDHTI->flags = 0;
- CRect rc = _rcItemEntire;
- rc.right = rc.left + m_nDividerHalfExtent;
- if( rc.PtInRect( pHDHTI->pt ) )
- {
- nWalkWay = -1;
- pHDHTI->flags |= HHT_ONDIVIDER;
- }
- else
- {
- rc = _rcItemEntire;
- rc.left = rc.right - m_nDividerHalfExtent;
- if( rc.PtInRect( pHDHTI->pt ) )
- {
- nWalkWay = 1;
- pHDHTI->flags |= HHT_ONDIVIDER;
- }
- }
- INT nTestColNo = VisualIndex2ColNo( ColNo2VisualIndex( nColNo ) + nWalkWay );
- if( nTestColNo >= 0 )
- {
- CRect rcTest;
- if( GetItemRect( nTestColNo, &rcTest )
- && rcTest.Width() == 0
- )
- pHDHTI->flags |= HHT_ONDIVOPEN;
- }
- break;
- } // for( nColNo = 0; nColNo < nColCount; nColNo++ )
- return pHDHTI->iItem;
- }
- //break;
- } // switch( message )
- // __try
- // {
- return CHeaderCtrl::WindowProc(message, wParam, lParam);
- // }
- // __except( EXCEPTION_EXECUTE_HANDLER )
- // {
- // }
- // return 0L;
- }
- void CExtHeaderCtrl::PreSubclassWindow()
- {
- m_arrExtendedData.RemoveAll();
- m_bCancelingActions = false;
- m_ptScreenPressing.x = m_ptScreenPressing.y = m_nHelperInitialResizingExtent = -32767;
- m_nHoverColNo = m_nHoverIndex = m_nPressingColNo = m_nPressingIndex = -1;
- m_bOnButton = m_bOnDividerAtRight = false;
- CHeaderCtrl::PreSubclassWindow();
- }
- void CExtHeaderCtrl::PostNcDestroy()
- {
- m_bCancelingActions = false;
- m_ptScreenPressing.x = m_ptScreenPressing.y = m_nHelperInitialResizingExtent = -32767;
- m_nHoverColNo = m_nHoverIndex = m_nPressingColNo = m_nPressingIndex = -1;
- m_bOnButton = m_bOnDividerAtRight = false;
- CHeaderCtrl::PostNcDestroy();
- m_arrExtendedData.RemoveAll();
- }
- const CExtHeaderCtrl::EXTENDED_ITEM_DATA & CExtHeaderCtrl::ExtendedItemDataGet( INT nColNo ) const
- {
- ASSERT_VALID( this );
- return ( const_cast < CExtHeaderCtrl * > ( this ) ) -> ExtendedItemDataGet( nColNo );
- }
- CExtHeaderCtrl::EXTENDED_ITEM_DATA & CExtHeaderCtrl::ExtendedItemDataGet( INT nColNo )
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- INT nArraySize = INT( m_arrExtendedData.GetSize() );
- INT nItemCount = INT( GetItemCount() );
- for( ; nArraySize < nItemCount; nArraySize ++ )
- {
- static EXTENDED_ITEM_DATA g_eii;
- m_arrExtendedData.InsertAt( nArraySize, g_eii, 1 );
- }
- if( nArraySize > nItemCount )
- m_arrExtendedData.RemoveAt( nArraySize - nItemCount, nArraySize - nItemCount );
- EXTENDED_ITEM_DATA & _eii = m_arrExtendedData.ElementAt( nColNo );
- // if( _eii.m_iconItem.IsEmpty() )
- // {
- // HICON hIconTest = AfxGetApp()->LoadIcon( IDR_MAINFRAME );
- // _eii.m_iconItem.AssignFromHICON( hIconTest, false );
- // _eii.m_iconItem.Scale( CSize(13,13) );
- // }
- // if( _eii.m_iconButton.IsEmpty() )
- // {
- // HICON hIconTest = AfxGetApp()->LoadIcon( IDR_MAINFRAME );
- // _eii.m_iconButton.AssignFromHICON( hIconTest, false );
- // _eii.m_iconButton.Scale( CSize(13,13) );
- // }
- return _eii;
- }
- CExtHeaderCtrl::EXTENDED_ITEM_DATA::EXTENDED_ITEM_DATA()
- : m_nExtentMin( 0 )
- , m_nExtentMax( 32767 )
- , m_bDisableDnd( false )
- {
- }
- CExtHeaderCtrl::EXTENDED_ITEM_DATA::EXTENDED_ITEM_DATA( const CExtHeaderCtrl::EXTENDED_ITEM_DATA & other )
- {
- AssignFromOther( other );
- }
- CExtHeaderCtrl::EXTENDED_ITEM_DATA::~EXTENDED_ITEM_DATA()
- {
- }
- void CExtHeaderCtrl::EXTENDED_ITEM_DATA::AssignFromOther( const CExtHeaderCtrl::EXTENDED_ITEM_DATA & other )
- {
- m_iconItem = other.m_iconItem;
- m_iconButton = other.m_iconButton;
- m_strTipTextItem = other.m_strTipTextItem;
- m_strTipTextButton = other.m_strTipTextButton;
- m_nExtentMin = other.m_nExtentMin;
- m_nExtentMax = other.m_nExtentMax;
- m_bDisableDnd = other.m_bDisableDnd;
- }
- CExtHeaderCtrl::EXTENDED_ITEM_DATA & CExtHeaderCtrl::EXTENDED_ITEM_DATA::operator = ( const CExtHeaderCtrl::EXTENDED_ITEM_DATA & other )
- {
- AssignFromOther( other );
- return ( *this );
- }
- bool CExtHeaderCtrl::EXTENDED_ITEM_DATA::CanBeResized() const
- {
- if( m_nExtentMin < m_nExtentMax )
- return true;
- else
- return false;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtListCtrl
- CExtListCtrl::CExtListCtrl()
- : m_bSortEnabled( true )
- , m_bSortEnabledMultiple( true )
- , m_bColumnAutoSizingByData( false )
- , m_bColumnAutoSizingByHeader( true )
- , m_bReadOnlyLabels( false )
- {
- PmBridge_Install( true );
- }
- CExtListCtrl::~CExtListCtrl()
- {
- PmBridge_Uninstall();
- }
- void CExtListCtrl::PmBridge_OnPaintManagerChanged(
- CExtPaintManager * pGlobalPM
- )
- {
- CExtPmBridge::PmBridge_OnPaintManagerChanged( pGlobalPM );
- if( GetSafeHwnd() == NULL )
- return;
- Invalidate();
- }
- IMPLEMENT_DYNCREATE( CExtListCtrl, CListCtrl );
- BEGIN_MESSAGE_MAP(CExtListCtrl, CListCtrl)
- //{{AFX_MSG_MAP(CExtListCtrl)
- ON_NOTIFY(HDN_ITEMCLICK, 0, OnHeaderItemClick)
- ON_NOTIFY(HDN_ITEMDBLCLICK, 0, OnHeaderItemDoubleClick)
- ON_WM_DESTROY()
- ON_WM_CREATE()
- ON_WM_WINDOWPOSCHANGING()
- ON_NOTIFY_REFLECT(LVN_DELETEITEM, OnDeleteItem)
- ON_NOTIFY_REFLECT(LVN_DELETEALLITEMS, OnDeleteAllItems)
- ON_NOTIFY_REFLECT(LVN_BEGINLABELEDIT, OnBeginLabelEdit)
- ON_NOTIFY(HDN_BEGINDRAG, 0, OnBeginDrag)
- ON_NOTIFY(HDN_ENDDRAG, 0, OnEndDrag)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CExtListCtrl message handlers
- void CExtListCtrl::OnHeaderItemClick( NMHDR * pNMHDR, LRESULT * pResult )
- {
- ASSERT_VALID( this );
- (*pResult) = 0;
- if( ! m_bSortEnabled )
- return;
- HD_NOTIFY * pHdNotify = (HD_NOTIFY *)pNMHDR;
- if( pHdNotify->iButton == 0 )
- {
- CExtListCtrlDataSortOrder _sortOrder;
- CExtHeaderCtrl & wndHeader = GetHeaderCtrl();
- wndHeader.SortRulesGet( _sortOrder );
- if( m_bSortEnabledMultiple
- && CExtPopupMenuWnd::IsKeyPressed( VK_SHIFT )
- )
- {
- CExtListCtrlDataSortOrder _sortOrderUpdateFrom;
- CExtListCtrlDataSortOrder::COLUMN_INFO _columnInfo( INT(pHdNotify->iItem), true );
- _sortOrderUpdateFrom.m_arrItems.Add( _columnInfo );
- _sortOrder.SetupOrder( _sortOrderUpdateFrom, true );
- }
- else
- {
- if( _sortOrder.m_arrItems.GetSize() == 1
- && _sortOrder.m_arrItems[ 0 ] == INT(pHdNotify->iItem)
- )
- _sortOrder.m_arrItems.ElementAt( 0 ).m_bAscending =
- ! _sortOrder.m_arrItems[ 0 ].m_bAscending;
- else
- {
- _sortOrder.m_arrItems.RemoveAll();
- CExtListCtrlDataSortOrder::COLUMN_INFO _columnInfo( INT(pHdNotify->iItem), true );
- _sortOrder.m_arrItems.Add( _columnInfo );
- }
- }
- SortItems( _sortOrder );
- Invalidate();
- wndHeader.SortRulesSet( _sortOrder );
- } // if( pHdNotify->iButton == 0 )
- }
- void CExtListCtrl::OnHeaderItemDoubleClick( NMHDR * pNMHDR, LRESULT * pResult )
- {
- ASSERT_VALID( this );
- (*pResult) = 0;
- HD_NOTIFY * pHdNotify = (HD_NOTIFY *)pNMHDR;
- if( pHdNotify->iButton == 0 )
- {
- INT nColNo = INT( pHdNotify->iItem );
- ColumnAutoSize(
- nColNo,
- m_bColumnAutoSizingByData,
- m_bColumnAutoSizingByHeader
- );
- return;
- }
- }
- CExtHeaderCtrl & CExtListCtrl::_OnQueryHeaderCtrl()
- {
- ASSERT_VALID( this );
- _Init();
- return m_wndHeaderCtrl;
- }
- CExtHeaderCtrl & CExtListCtrl::GetHeaderCtrl()
- {
- ASSERT_VALID( this );
- return _OnQueryHeaderCtrl();
- }
- const CExtHeaderCtrl & CExtListCtrl::GetHeaderCtrl() const
- {
- ASSERT_VALID( this );
- return ( const_cast < CExtListCtrl * > ( this ) ) -> GetHeaderCtrl();
- }
- void CExtListCtrl::GetSelectedItemsList(
- CList < INT, INT > & _listSelectedItems,
- bool bAddToTail // = true
- )
- {
- ASSERT_VALID( this );
- _listSelectedItems.RemoveAll();
- POSITION posSelItems = GetFirstSelectedItemPosition();
- if( posSelItems == NULL )
- return;
- for( ; posSelItems != NULL ; )
- {
- INT nSelItem = (INT)GetNextSelectedItem( posSelItems );
- if( bAddToTail )
- _listSelectedItems.AddTail( nSelItem );
- else
- _listSelectedItems.AddHead( nSelItem );
- }
- }
- bool CExtListCtrl::VerifySortOrder(
- const CExtListCtrlDataSortOrder & _sortOrder
- ) const
- {
- ASSERT_VALID( this );
- const CExtHeaderCtrl & wndHeader = GetHeaderCtrl();
- ASSERT( wndHeader.GetSafeHwnd() != NULL );
- INT nColCount = INT( wndHeader.GetItemCount() );
- INT nSortColNo, nSortColCount = INT(_sortOrder.m_arrItems.GetSize());
- for( nSortColNo = 0; nSortColNo < nSortColCount; nSortColNo ++ )
- {
- const CExtListCtrlDataSortOrder::COLUMN_INFO & _columnInfo = _sortOrder.m_arrItems[ nSortColNo ];
- if( _columnInfo.m_nColNo < 0 )
- return false;
- if( _columnInfo.m_nColNo >= nColCount )
- return false;
- }
- return true;
- }
- INT CExtListCtrl::CompareItems(
- const CExtListCtrlDataSortOrder & _sortOrder,
- INT nItemIndex1,
- INT nItemIndex2
- ) const
- {
- ASSERT_VALID( this );
- ASSERT( ! _sortOrder.IsEmpty() );
- if( nItemIndex1 == nItemIndex2 )
- return 0;
- INT nSortColNo, nSortColCount = INT(_sortOrder.m_arrItems.GetSize());
- for( nSortColNo = 0; nSortColNo < nSortColCount; nSortColNo ++ )
- {
- const CExtListCtrlDataSortOrder::COLUMN_INFO & _columnInfo = _sortOrder.m_arrItems[ nSortColNo ];
- CExtSafeString strText1 = GetItemText( nItemIndex1, _columnInfo.m_nColNo );
- CExtSafeString strText2 = GetItemText( nItemIndex2, _columnInfo.m_nColNo );
- int nCmpResult = strText1.Compare( strText2 );
- if( nCmpResult == 0 )
- continue;
- return _columnInfo.m_bAscending ? (nCmpResult) : (-nCmpResult);
- }
- return 0;
- }
- void CExtListCtrl::SwapItems(
- INT nItemIndex1,
- INT nItemIndex2
- )
- {
- ASSERT_VALID( this );
- ASSERT( nItemIndex1 != nItemIndex2 );
- LV_ITEM _item1, _item2;
- ::memset( &_item1, 0, sizeof(LV_ITEM) );
- ::memset( &_item2, 0, sizeof(LV_ITEM) );
- CExtHeaderCtrl & wndHeader = GetHeaderCtrl();
- ASSERT( wndHeader.GetSafeHwnd() != NULL );
- INT nColNo, nColCount = INT( wndHeader.GetItemCount() );
- CStringArray arrItemTextValues;
- arrItemTextValues.SetSize( nColCount );
- for( nColNo = 0; nColNo < nColCount; nColNo ++ )
- arrItemTextValues[nColNo] = GetItemText( nItemIndex1, nColNo );
- _item1.mask = LVIF_IMAGE|LVIF_PARAM|LVIF_STATE;
- _item1.iItem = nItemIndex1;
- _item1.iSubItem = 0;
- _item1.stateMask = LVIS_CUT|LVIS_DROPHILITED|LVIS_FOCUSED|LVIS_SELECTED|LVIS_OVERLAYMASK|LVIS_STATEIMAGEMASK;
- _item2 = _item1;
- _item2.iItem = nItemIndex2;
- GetItem( &_item1 );
- GetItem( &_item2 );
- for( nColNo = 0; nColNo < nColCount; nColNo ++ )
- SetItemText( nItemIndex1, nColNo, GetItemText( nItemIndex2, nColNo ) );
- _item2.iItem = nItemIndex1;
- SetItem( &_item2 );
- for( nColNo = 0; nColNo < nColCount; nColNo ++ )
- SetItemText(nItemIndex2, nColNo, arrItemTextValues[nColNo]);
- _item1.iItem = nItemIndex2;
- SetItem( &_item1 );
- }
- bool CExtListCtrl::SortItems(
- INT nItemIndexLow, //= 0
- INT nItemIndexHigh // -1
- )
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return false;
- CExtHeaderCtrl & wndHeader = GetHeaderCtrl();
- ASSERT( wndHeader.GetSafeHwnd() != NULL );
- return SortItems( wndHeader.m_sortOrder, nItemIndexLow, nItemIndexHigh );
- }
- bool CExtListCtrl::SortItems(
- const CExtListCtrlDataSortOrder & _sortOrder,
- INT nItemIndexLow, //= 0
- INT nItemIndexHigh // -1
- )
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return false;
- //ASSERT( m_bSortEnabled );
- if( _sortOrder.IsEmpty() || GetItemCount() == 0 )
- return true;
- if( ! VerifySortOrder( _sortOrder ) )
- return false;
- if( nItemIndexHigh < 0 )
- nItemIndexHigh = GetItemCount() - 1;
- INT nReviewIndexLow = nItemIndexLow;
- INT nReviewIndexHigh = nItemIndexHigh;
- if( nReviewIndexHigh <= nReviewIndexLow )
- return false;
- LONG nViewMin = nItemIndexLow, nViewMax = nItemIndexHigh, nViewMiddle = ( nItemIndexLow + nItemIndexHigh ) / 2L;
- for( ; nViewMin <= nViewMax; )
- {
- for( ; ( nViewMin < nItemIndexHigh ) && ( CompareItems( _sortOrder, nViewMin, nViewMiddle ) < 0 ); ++ nViewMin );
- for( ; ( nViewMax > nItemIndexLow ) && ( CompareItems( _sortOrder, nViewMax, nViewMiddle ) > 0 ); -- nViewMax );
- if( nViewMin <= nViewMax )
- {
- if( nViewMin != nViewMax && CompareItems( _sortOrder, nViewMin, nViewMax ) != 0 )
- {
- if( nViewMiddle == nViewMin )
- nViewMiddle = nViewMax;
- else if( nViewMiddle == nViewMax )
- nViewMiddle = nViewMin;
- SwapItems( nViewMin, nViewMax );
- }
- ++ nViewMin;
- -- nViewMax;
- }
- }
- if( nItemIndexLow < nViewMax )
- {
- if( ! SortItems( _sortOrder, nItemIndexLow, nViewMax ) )
- {
- ASSERT( FALSE );
- return false;
- }
- }
- if( nViewMin < nItemIndexHigh )
- {
- if( ! SortItems( _sortOrder, nViewMin, nItemIndexHigh ) )
- {
- ASSERT( FALSE );
- return false;
- }
- }
- return true;
- }
- void CExtListCtrl::StateSerialize(
- CArchive & ar,
- bool bExtents, // = true
- bool bOrder, // = true
- bool bSortOrder, // = true
- bool bListViewMode // = true
- )
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- DWORD dwSerializedDataMask = 0;
- if( bExtents )
- dwSerializedDataMask |= ( 1 << 0 );
- if( bOrder )
- dwSerializedDataMask |= ( 1 << 1 );
- if( bSortOrder )
- dwSerializedDataMask |= ( 1 << 2 );
- if( bListViewMode )
- dwSerializedDataMask |= ( 1 << 3 );
- if( dwSerializedDataMask == 0 )
- ::AfxThrowUserException();
- CExtHeaderCtrl & wndHeader = GetHeaderCtrl();
- ASSERT( wndHeader.GetSafeHwnd() != NULL );
- INT nColNo, nColCount = INT( wndHeader.GetItemCount() );
- DWORD dwGap = 0;
- INT * pArr = NULL;
- try
- {
- if( ar.IsStoring() )
- {
- ar << dwGap;
- ar << dwSerializedDataMask;
- ar << DWORD( nColCount );
- if( bExtents )
- {
- for( nColNo = 0; nColNo < nColCount; nColNo ++ )
- {
- const CExtHeaderCtrl::EXTENDED_ITEM_DATA & _eii = wndHeader.ExtendedItemDataGet( nColNo );
- DWORD dwExtent = (DWORD)ColumnExtentGet( nColNo );
- ar << dwExtent;
- ar << DWORD(_eii.m_nExtentMin);
- ar << DWORD(_eii.m_nExtentMax);
- } // for( nColNo = 0; nColNo < nColCount; nColNo ++ )
- } // if( bExtents )
- if( bOrder )
- {
- try
- {
- pArr = new INT[ nColCount ];
- if( ! wndHeader.GetOrderArray( pArr, nColCount ) )
- ::AfxThrowUserException();
- for( nColNo = 0; nColNo < nColCount; nColNo ++ )
- ar << DWORD( pArr[nColNo] );
- }
- catch( CException * pException )
- {
- pException->Delete();
- }
- } // if( bOrder )
- if( bListViewMode )
- {
- DWORD dwMode = (DWORD)( GetStyle() & LVS_TYPEMASK );
- ar << dwMode;
- }
- } // if( ar.IsStoring() )
- else
- {
- ar >> dwGap;
- DWORD dwSerializedDataMask2 = 0;
- ar >> dwSerializedDataMask2;
- if( dwSerializedDataMask2 == 0 || dwSerializedDataMask2 != dwSerializedDataMask )
- ::AfxThrowUserException();
- DWORD dwColCountToLoad;
- ar >> dwColCountToLoad;
- if( INT(dwColCountToLoad) != nColCount )
- ::AfxThrowArchiveException( CArchiveException::badSchema );
- if( bExtents )
- {
- for( nColNo = 0; nColNo < nColCount; nColNo ++ )
- {
- CExtHeaderCtrl::EXTENDED_ITEM_DATA & _eii = wndHeader.ExtendedItemDataGet( nColNo );
- DWORD dwExtent;
- ar >> dwExtent;
- ColumnExtentSet( nColNo, INT(dwExtent) );
- ar >> dwExtent;
- _eii.m_nExtentMin = INT(dwExtent);
- ar >> dwExtent;
- _eii.m_nExtentMax = INT(dwExtent);
- } // for( nColNo = 0; nColNo < nColCount; nColNo ++ )
- } // if( bExtents )
- if( bOrder )
- {
- try
- {
- pArr = new INT[ nColCount ];
- for( nColNo = 0; nColNo < nColCount; nColNo ++ )
- {
- DWORD dwTmp;
- ar >> dwTmp;
- pArr[nColNo] = INT(dwTmp);
- } // for( nColNo = 0; nColNo < nColCount; nColNo ++ )
- if( ! wndHeader.SetOrderArray( nColCount, pArr ) )
- ::AfxThrowUserException();
- }
- catch( CException * pException )
- {
- pException->Delete();
- }
- } // if( bOrder )
- if( bListViewMode )
- {
- DWORD dwMode = 0;
- ar >> dwMode;
- if( ( dwMode & LVS_TYPEMASK ) != dwMode )
- ::AfxThrowUserException();
- ModifyStyle( LVS_TYPEMASK, 0 );
- ModifyStyle( 0, dwMode );
- }
- } // else from if( ar.IsStoring() )
- if( bSortOrder )
- {
- wndHeader.m_sortOrder.Serialize( ar );
- if( ar.IsLoading()
- && (! wndHeader.m_sortOrder.IsEmpty() )
- && VerifySortOrder( wndHeader.m_sortOrder )
- )
- SortItems( wndHeader.m_sortOrder );
- } // if( bSortOrder )
- } // try
- catch( ... )
- {
- if( pArr != NULL )
- delete [] pArr;
- throw;
- } // catch( ... )
- if( pArr != NULL )
- delete [] pArr;
- }
- static CExtSafeString productsection2regkeypath(
- __EXT_MFC_SAFE_LPCTSTR sCppClassName,
- __EXT_MFC_SAFE_LPCTSTR sProfileName,
- __EXT_MFC_SAFE_LPCTSTR sSectionNameCompany, // under HKEY_CURRENT_USERSoftware
- __EXT_MFC_SAFE_LPCTSTR sSectionNameProduct // under HKEY_CURRENT_USERSoftware%sSectionNameCompany%
- )
- {
- return CExtCmdManager::GetSubSystemRegKeyPath(
- sCppClassName,
- sProfileName,
- sSectionNameCompany,
- sSectionNameProduct
- );
- }
- bool CExtListCtrl::StateLoad(
- __EXT_MFC_SAFE_LPCTSTR sSectionNameCompany, // under HKEY_CURRENT_USERSoftware
- __EXT_MFC_SAFE_LPCTSTR sSectionNameProduct, // under HKEY_CURRENT_USERSoftware%sSectionNameCompany%
- __EXT_MFC_SAFE_LPCTSTR sSectionNameProfile, // under HKEY_CURRENT_USERSoftware%sSectionNameCompany%%sSectionNameProfile%
- HKEY hKeyRoot, // = HKEY_CURRENT_USER
- bool bExtents, // = true
- bool bOrder, // = true
- bool bSortOrder, // = true
- bool bListViewMode // = true
- )
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- CExtSafeString sRegKeyPath=
- productsection2regkeypath(
- _T("CExtListCtrl"),
- sSectionNameProfile,
- sSectionNameCompany,
- sSectionNameProduct
- );
- try
- {
- CMemFile _file;
- if( ! CExtCmdManager::FileObjFromRegistry( _file, sRegKeyPath, hKeyRoot, false ) )
- return false;
- CArchive ar( &_file, CArchive::load );
- StateSerialize( ar, bExtents, bOrder, bSortOrder, bListViewMode );
- return true;
- }
- catch( CException * pXept )
- {
- pXept->Delete();
- }
- catch( ... )
- {
- }
- return false;
- }
- bool CExtListCtrl::StateSave(
- __EXT_MFC_SAFE_LPCTSTR sSectionNameCompany, // under HKEY_CURRENT_USERSoftware
- __EXT_MFC_SAFE_LPCTSTR sSectionNameProduct, // under HKEY_CURRENT_USERSoftware%sSectionNameCompany%
- __EXT_MFC_SAFE_LPCTSTR sSectionNameProfile, // under HKEY_CURRENT_USERSoftware%sSectionNameCompany%%sSectionNameProfile%
- HKEY hKeyRoot, // = HKEY_CURRENT_USER
- bool bExtents, // = true
- bool bOrder, // = true
- bool bSortOrder, // = true
- bool bListViewMode // = true
- )
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- CExtSafeString sRegKeyPath =
- productsection2regkeypath(
- _T("CExtListCtrl"),
- sSectionNameProfile,
- sSectionNameCompany,
- sSectionNameProduct
- );
- try
- {
- CMemFile _file;
- CArchive ar( &_file, CArchive::store );
- StateSerialize( ar, bExtents, bOrder, bSortOrder, bListViewMode );
- ar.Flush();
- ar.Close();
- if( ! CExtCmdManager::FileObjToRegistry( _file, sRegKeyPath, hKeyRoot, false ) )
- return false;
- return true;
- }
- catch( CException * pXept )
- {
- pXept->Delete();
- }
- catch( ... )
- {
- }
- return false;
- }
- INT CExtListCtrl::ColumnExtentGet( INT nColNo ) const
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- const CExtHeaderCtrl & wndHeader = GetHeaderCtrl();
- ASSERT( wndHeader.GetSafeHwnd() != NULL );
- //#ifdef _DEBUG
- //INT nColCount = INT( wndHeader.GetItemCount() );
- // ASSERT( 0 <= nColNo && nColNo < nColCount );
- //#endif // _DEBUG
- INT nColCount = INT( wndHeader.GetItemCount() );
- if( ! ( 0 <= nColNo && nColNo < nColCount ) )
- return 120; // some default width
- INT nExtent = CListCtrl::GetColumnWidth( nColNo );
- return nExtent;
- }
- void CExtListCtrl::ColumnExtentSet( INT nColNo, INT nExtent )
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- CExtHeaderCtrl & wndHeader = GetHeaderCtrl();
- ASSERT( wndHeader.GetSafeHwnd() != NULL );
- //#ifdef _DEBUG
- //INT nColCount = INT( wndHeader.GetItemCount() );
- // ASSERT( 0 <= nColNo && nColNo < nColCount );
- //#endif // _DEBUG
- INT nColCount = INT( wndHeader.GetItemCount() );
- if( ! ( 0 <= nColNo && nColNo < nColCount ) )
- return;
- CListCtrl::SetColumnWidth( nColNo, nExtent );
- }
- void CExtListCtrl::ColumnAutoSize(
- INT nColNo,
- bool bAutoSizeByData, // = true,
- bool bAutoSizeByHeader // = true
- )
- {
- ASSERT_VALID( this );
- if( ! ( bAutoSizeByData || bAutoSizeByHeader ) )
- return;
- if( GetSafeHwnd() == NULL )
- return;
- CExtHeaderCtrl & wndHeader = GetHeaderCtrl();
- ASSERT( wndHeader.GetSafeHwnd() != NULL );
- #ifdef _DEBUG
- INT nColCount = INT( wndHeader.GetItemCount() );
- ASSERT( 0 <= nColNo && nColNo < nColCount );
- #endif // _DEBUG
- SetRedraw( FALSE );
- INT nInitialWidth = CListCtrl::GetColumnWidth( nColNo );
- INT nResultWidth = 0;
- if( bAutoSizeByHeader )
- {
- //CListCtrl::SetColumnWidth( nColNo, LVSCW_AUTOSIZE_USEHEADER );
- //INT nWidth = CListCtrl::GetColumnWidth( nColNo );
- INT nWidth = wndHeader.OnCalcHeaderItemSize( nColNo ).cx;
- nResultWidth = max( nResultWidth, nWidth );
- }
- if( bAutoSizeByData )
- {
- CListCtrl::SetColumnWidth( nColNo, LVSCW_AUTOSIZE );
- INT nWidth = CListCtrl::GetColumnWidth( nColNo );
- nResultWidth = max( nResultWidth, nWidth );
- }
- if( nInitialWidth != nResultWidth )
- CListCtrl::SetColumnWidth( nColNo, nResultWidth );
- SetRedraw( TRUE );
- if( nInitialWidth != nResultWidth )
- Invalidate();
- }
- void CExtListCtrl::OnDestroy()
- {
- CListCtrl::OnDestroy();
- }
- void CExtListCtrl::ModifyExtendedStyle( DWORD dwRemove, DWORD dwAdd )
- {
- LPARAM nStyleOld = (LPARAM) ::SendMessage( m_hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0 );
- LPARAM nStyleNew = nStyleOld;
- nStyleNew &= ~( (LPARAM) dwRemove );
- nStyleNew |= (LPARAM) dwAdd;
- if( nStyleNew != nStyleOld )
- ::SendMessage( m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, nStyleNew );
- }
- int CExtListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if( CListCtrl::OnCreate( lpCreateStruct ) == -1 )
- return -1;
- //return _Init() ? 0 : -1;
- PostMessage( (WM_USER+123) );
- return 0;
- }
- void CExtListCtrl::PreSubclassWindow()
- {
- CListCtrl::PreSubclassWindow();
- PostMessage( (WM_USER+123) );
- //_Init();
- }
- LRESULT CExtListCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- HWND hWndOwn = GetSafeHwnd();
- switch( message )
- {
- case (WM_USER+123):
- _Init();
- break;
- case WM_ERASEBKGND:
- return FALSE;
- case WM_PAINT:
- {
- CPaintDC dcPaint( this );
- CExtPaintManager::stat_ExcludeChildAreas(
- dcPaint.GetSafeHdc(),
- GetSafeHwnd()
- );
- CRect rcClient;
- GetClientRect( &rcClient );
- CExtMemoryDC dc( &dcPaint, &rcClient );
- DefWindowProc(
- WM_ERASEBKGND,
- WPARAM( dc.GetSafeHdc() ),
- LPARAM(0)
- );
- DefWindowProc(
- WM_PAINT,
- WPARAM( dc.GetSafeHdc() ),
- LPARAM(0)
- );
- }
- return TRUE;
- case WM_KEYDOWN:
- {
- switch( wParam )
- {
- case VK_F2:
- if( ( GetStyle() & LVS_EDITLABELS ) != 0
- && ( ! ReadOnlyLabelsGet() )
- )
- {
- int nItemIndex = FocusedItemGet();
- if( nItemIndex >= 0 )
- EditLabel( nItemIndex );
- return 0L;
- }
- break;
- case VK_APPS:
- {
- CRect rcItem;
- int nItemFocused = FocusedItemGet();
- if( nItemFocused < 0 )
- return 0L;
- EnsureVisible( nItemFocused, TRUE );
- GetItemRect( nItemFocused, &rcItem, TRUE );
- CPoint ptScreen = rcItem.CenterPoint();
- ClientToScreen( &ptScreen );
- SendMessage( WM_CONTEXTMENU, WPARAM(m_hWnd), MAKELPARAM(ptScreen.x, ptScreen.y) );
- }
- break;
- case VK_TAB:
- if( ( GetStyle() & WS_TABSTOP ) != 0 )
- {
- GetParent()->SendMessage(
- WM_NEXTDLGCTL,
- CExtPopupMenuWnd::IsKeyPressed(VK_SHIFT) ? 1 : 0,
- 0
- );
- return 0L;
- }
- break;
- } // switch( wParam )
- }
- break;
- default:
- if( message == CExtHeaderCtrl::g_nMsgHeaderButtonClick )
- return GetParent()->SendMessage( CExtHeaderCtrl::g_nMsgHeaderButtonClick, wParam, lParam );
- break;
- } // switch( message )
- LRESULT lResult = CListCtrl::WindowProc(message , wParam, lParam );
- switch( message )
- {
- case WM_GETDLGCODE:
- lResult |= DLGC_WANTMESSAGE;
- break;
- case WM_KEYDOWN:
- switch( wParam )
- {
- case VK_RETURN:
- case VK_ESCAPE:
- if( (!( CExtPopupMenuWnd::IsKeyPressed( VK_MENU )
- || CExtPopupMenuWnd::IsKeyPressed( VK_CONTROL )
- || CExtPopupMenuWnd::IsKeyPressed( VK_SHIFT )
- ))
- && ::IsWindow( hWndOwn )
- && IsWindowEnabled()
- && ( GetStyle() & WS_VISIBLE ) != 0
- )
- {
- UINT nCmdID = ( wParam == VK_RETURN ) ? IDOK : IDCANCEL;
- bool bSendOkCancel = true;
- CWnd * pWndParent = GetParent();
- for( ; pWndParent != NULL
- && ( pWndParent->GetStyle() & WS_CHILD ) != 0
- ;
- )
- {
- if( ( ! pWndParent->IsWindowEnabled() )
- || ( pWndParent->GetStyle() & WS_VISIBLE ) == 0
- )
- {
- bSendOkCancel = false;
- break;
- }
- pWndParent = pWndParent->GetParent();
- }
- if( bSendOkCancel && pWndParent != NULL )
- {
- CWnd * pWndOkCancel = pWndParent->GetDlgItem( nCmdID );
- if( pWndOkCancel != NULL
- && ( (! pWndOkCancel->IsWindowEnabled() )
- || ( pWndOkCancel->GetStyle() & WS_VISIBLE ) == 0
- )
- )
- bSendOkCancel = false;
- else if( ( pWndParent->GetStyle() & WS_CHILD ) == 0 )
- {
- MENUITEMINFO _mii;
- ::memset( &_mii, 0, sizeof(MENUITEMINFO) );
- _mii.cbSize = sizeof(MENUITEMINFO);
- _mii.fMask = MIIM_STATE;
- CMenu * pMenu = pWndParent->GetSystemMenu( FALSE );
- if( pMenu->GetSafeHmenu() != NULL
- && pMenu->GetMenuItemInfo( SC_CLOSE, &_mii, FALSE )
- && ( _mii.fState & ( MF_DISABLED | MF_GRAYED ) ) != 0
- )
- bSendOkCancel = false;
- } // else if( ( pWndParent->GetStyle() & WS_CHILD ) == 0 )
- } // if( bSendOkCancel && pWndParent != NULL )
- if( bSendOkCancel )
- pWndParent->SendMessage( WM_COMMAND, WPARAM(nCmdID) );
- }
- break;
- } // switch( wParam )
- break;
- case WM_HSCROLL:
- {
- CExtHeaderCtrl & wndHeader = GetHeaderCtrl();
- if( wndHeader.GetSafeHwnd() != NULL
- && ( wndHeader.GetStyle() & WS_VISIBLE ) != 0
- )
- {
- wndHeader.Invalidate();
- wndHeader.UpdateWindow();
- }
- }
- break;
- } // switch( message )
- return lResult;
- }
- bool CExtListCtrl::_Init()
- {
- CExtHeaderCtrl & wndHeader = m_wndHeaderCtrl; // GetHeaderCtrl();
- if( wndHeader.GetSafeHwnd() != NULL )
- return true;
- if( ! wndHeader.SubclassWindow( GetDlgItem(0)->GetSafeHwnd()) )
- return false;
- return true;
- }
- void CExtListCtrl::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
- {
- CListCtrl::OnWindowPosChanging(lpwndpos);
- Invalidate(FALSE);
- }
- void CExtListCtrl::OnDeleteItem( NMHDR * pNMHDR, LRESULT * pResult )
- {
- pNMHDR;
- //NM_LISTVIEW * pNMListView = (NM_LISTVIEW *)pNMHDR;
- (*pResult) = 0;
- }
- void CExtListCtrl::OnDeleteAllItems( NMHDR * pNMHDR, LRESULT * pResult )
- {
- pNMHDR;
- //NM_LISTVIEW * pNMListView = (NM_LISTVIEW *)pNMHDR;
- (*pResult) = 0;
- }
- bool CExtListCtrl::ReadOnlyLabelsGet() const
- {
- ASSERT_VALID( this );
- return m_bReadOnlyLabels;
- }
- void CExtListCtrl::ReadOnlyLabelsSet( bool bReadOnlyLabels )
- {
- ASSERT_VALID( this );
- m_bReadOnlyLabels = bReadOnlyLabels;
- }
- void CExtListCtrl::OnBeginLabelEdit( NMHDR * pNMHDR, LRESULT * pResult )
- {
- pNMHDR;
- //NMLVDISPINFO * pNMDI = (NMLVDISPINFO*)pNMHDR;
- (*pResult) = 0;
- if( ReadOnlyLabelsGet() )
- {
- CEdit * pEdit = GetEditControl();
- if( pEdit->GetSafeHwnd() != NULL )
- pEdit->SetReadOnly( TRUE );
- }
- }
- void CExtListCtrl::SelectedItemsListGet(
- CList < INT, INT > & _listSelectedItems,
- bool bAddToTail // = true
- ) const
- {
- ASSERT_VALID( this );
- _listSelectedItems.RemoveAll();
- if( GetSafeHwnd() == NULL )
- return;
- POSITION pos = GetFirstSelectedItemPosition();
- for( ; pos != NULL; )
- {
- INT nItemIndex = GetNextSelectedItem( pos );
- if( bAddToTail )
- _listSelectedItems.AddTail( nItemIndex );
- else
- _listSelectedItems.AddHead( nItemIndex );
- }
- }
- void CExtListCtrl::SelectedItemsListSet(
- const CList < INT, INT > & _listSelectedItems
- )
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return;
- INT nItemIndex, nItemCount = GetItemCount();
- if( nItemCount <= 0 )
- return;
- CList < INT, INT > _listSelectedItems2;
- _listSelectedItems2.AddTail( const_cast < CList < INT, INT > * > ( &_listSelectedItems ) );
- for( nItemIndex = 0; nItemIndex < nItemCount; nItemIndex ++ )
- {
- POSITION pos = _listSelectedItems2.Find( nItemIndex );
- SetItemState( nItemIndex, ( pos != NULL ) ? LVIS_SELECTED : 0, LVIS_SELECTED );
- if( pos != NULL )
- _listSelectedItems2.RemoveAt( pos );
- }
- }
- bool CExtListCtrl::IsItemSelected(
- INT nItemIndex
- ) const
- {
- ASSERT_VALID( this );
- if( nItemIndex < 0 )
- return false;
- if( GetSafeHwnd() == NULL )
- return false;
- INT nItemCount = INT( GetItemCount() );
- if( nItemIndex >= nItemCount )
- return false;
- bool bSelected = ( GetItemState( nItemIndex, LVIS_SELECTED ) != 0 ) ? true : false;
- return bSelected;
- }
- void CExtListCtrl::SelectItem(
- INT nItemIndex,
- bool bSelect // = true
- )
- {
- ASSERT_VALID( this );
- if( nItemIndex < 0 )
- return;
- if( GetSafeHwnd() == NULL )
- return;
- INT nItemCount = INT( GetItemCount() );
- if( nItemIndex >= nItemCount )
- return;
- bool bSelected = ( GetItemState( nItemIndex, LVIS_SELECTED ) != 0 ) ? true : false;
- if( ( bSelected && bSelect ) || ( (!bSelected) && (!bSelect) ) )
- return;
- SetItemState( nItemIndex, bSelect ? LVIS_SELECTED : 0, LVIS_SELECTED );
- }
- INT CExtListCtrl::FocusedItemGet() const
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return -1;
- INT nItemIndex = GetNextItem( -1, LVNI_FOCUSED );
- return nItemIndex;
- }
- INT CExtListCtrl::FocusedItemSet( // returns previous focused item index
- INT nItemIndex,
- bool bSelectFocusedItem, // = true
- bool bUnselectOtherItems // = true
- )
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return -1;
- INT nPrevFocusedItemIndex = GetNextItem( -1, LVNI_FOCUSED );
- if( nItemIndex < 0 )
- return nPrevFocusedItemIndex;
- INT nItemCount = INT( GetItemCount() );
- if( nItemIndex >= nItemCount )
- return nPrevFocusedItemIndex;
- if( nPrevFocusedItemIndex == nItemIndex
- && ( ! ( bSelectFocusedItem || bUnselectOtherItems ) )
- )
- return nPrevFocusedItemIndex;
- if( bUnselectOtherItems )
- {
- INT nWalkIndex;
- for( nWalkIndex = 0; nWalkIndex < nItemCount; nWalkIndex ++ )
- {
- if( bSelectFocusedItem && nWalkIndex == nItemIndex )
- SetItemState( nWalkIndex, LVIS_SELECTED, LVIS_SELECTED );
- else
- SetItemState( nWalkIndex, 0, LVIS_SELECTED );
- }
- }
- else if( bSelectFocusedItem )
- SetItemState( nItemIndex, LVIS_SELECTED, LVIS_SELECTED );
- SetItemState( nItemIndex, LVIS_FOCUSED, LVIS_FOCUSED );
- return nPrevFocusedItemIndex;
- }
- void CExtListCtrl::OnBeginDrag( NMHDR * pNMHDR, LRESULT * pResult )
- {
- ASSERT_VALID( this );
- pNMHDR;
- //HD_NOTIFY * phdn = (HD_NOTIFY *) pNMHDR;
- *pResult = 0;
- }
- void CExtListCtrl::OnEndDrag( NMHDR * pNMHDR, LRESULT * pResult )
- {
- ASSERT_VALID( this );
- pNMHDR;
- //HD_NOTIFY * phdn = (HD_NOTIFY *) pNMHDR;
- *pResult = 0;
- Invalidate();
- UpdateWindow();
- }
- CExtNCSB < CExtListCtrl > :: CExtNCSB(
- bool bNcsbDelayedInitialization, // = false
- bool bNcsbForceMiddleContainerMode // = false
- )
- : CExtNCSB_Impl < CExtListCtrl > (
- bNcsbDelayedInitialization,
- bNcsbForceMiddleContainerMode
- )
- {
- }
- CExtNCSB < CExtListCtrl > :: ~CExtNCSB()
- {
- }
- void CExtNCSB < CExtListCtrl > :: AdjustScrollMetrics()
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return;
- DWORD dwType = DWORD( GetStyle() & LVS_TYPEMASK );
- CExtNCSB_ScrollContainer * pWndH = NCSB_GetContainer( CExtNCSB_ScrollContainer::__EM_HORIZONTAL_SCROLL_BAR );
- CExtNCSB_ScrollContainer * pWndV = NCSB_GetContainer( CExtNCSB_ScrollContainer::__EM_VERTICAL_SCROLL_BAR );
- CExtScrollBar * pSBH = ( pWndH != NULL ) ? pWndH->GetScrollBarInContainer() : NULL;
- CExtScrollBar * pSBV = ( pWndV != NULL ) ? pWndV->GetScrollBarInContainer() : NULL;
- INT m_nStepSizeH = -1, m_nStepSizeV = -1;
- switch( dwType )
- {
- case LVS_ICON:
- m_nStepSizeV = 64;
- break;
- case LVS_SMALLICON:
- case LVS_LIST:
- m_nStepSizeV = 16;
- break;
- case LVS_REPORT:
- m_nStepSizeV = 1;
- break;
- } // switch( dwType )
- if( m_nStepSizeH > 0 && pSBH != NULL )
- pSBH->m_nStepSize = m_nStepSizeH;
- if( m_nStepSizeV > 0 && pSBV != NULL )
- pSBV->m_nStepSize = m_nStepSizeV;
- }
- LRESULT CExtNCSB < CExtListCtrl > :: WindowProc( UINT message, WPARAM wParam, LPARAM lParam )
- {
- switch( message )
- {
- case WM_HSCROLL:
- {
- UINT nSBCode = UINT(LOWORD(DWORD(wParam))), nPos = UINT(HIWORD(DWORD(wParam)));
- //TRACE2( "WM_HSCROLL, nSBCode = %d, nPos = %drn", nSBCode, nPos );
- INT nItemExtent = 1;
- DWORD dwStyle = GetStyle();
- DWORD dwListCtrlType = dwStyle&LVS_TYPEMASK;
- switch( dwListCtrlType )