| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015 |
- /********************************************
- ** 工作室:S&P工作室
- ** 作者 :张东斌
- ** 日期 :2007年6月
- *********************************************/
- #include "stdafx.h"
- #include "SPDrawHelpers.h"
- #include "SPVC80Helpers.h"
- #include "resource.h"
- #include "SPPropertyGridInplaceEdit.h"
- #include "SPPropertyGridInplaceButton.h"
- #include "SPPropertyGridInplaceList.h"
- #include "SPPropertyGridItem.h"
- #include "SPPropertyGrid.h"
- #include "SPPropertyGridDefines.h"
- #include "SPPropertyGridPaintManager.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- const UINT PGV_HIT_SPLITTER = 0x100;
- /////////////////////////////////////////////////////////////////////////////
- // CSPPropertyGridToolTip
- BEGIN_MESSAGE_MAP(CSPPropertyGridToolTip, CWnd)
- //{{AFX_MSG_MAP(CSPPropertyGridView)
- ON_WM_ERASEBKGND()
- ON_WM_PAINT()
- ON_WM_NCHITTEST()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- LRESULT CSPPropertyGridToolTip::OnNcHitTest( CPoint point )
- {
- UNREFERENCED_PARAMETER( point );
- return ( LRESULT ) HTTRANSPARENT;
- }
- void CSPPropertyGridToolTip::Create( CSPPropertyGridView * pParentWnd )
- {
- CWnd::CreateEx( 0,AfxRegisterWndClass( 0,LoadCursor( 0,IDC_ARROW ) ),_T( "" ),WS_POPUP,CSPEmptyRect(),pParentWnd,0 );
- m_pGrid = pParentWnd;
- }
- void CSPPropertyGridToolTip::Activate( BOOL bActive )
- {
- if ( bActive )
- {
- CString strText;
- GetWindowText( strText );
- CWindowDC dc ( this );
- CSPFontDC font ( &dc,&m_pGrid->m_fontNormal );
- CSPWindowRect rc ( this );
- rc.right = rc.left + dc.GetTextExtent( strText ).cx + 8;
- CRect rcWork = CSPDrawHelpers::GetWorkArea( m_pGrid );
- if ( rc.right > rcWork.right )
- rc.OffsetRect( rcWork.right - rc.right,0 );
- MoveWindow( rc );
- }
- ShowWindow( bActive ? SW_SHOWNA : SW_HIDE );
- }
- BOOL CSPPropertyGridToolTip::OnEraseBkgnd( CDC * )
- {
- return TRUE;
- }
- void CSPPropertyGridToolTip::OnPaint()
- {
- CPaintDC dc ( this );
- CSPClientRect rc ( this );
- COLORREF clrText = GetXtremeColor( COLOR_INFOTEXT );
- dc.FillSolidRect( rc,GetXtremeColor( COLOR_INFOBK ) );
- dc.Draw3dRect( rc,clrText,clrText );
- CString strText;
- GetWindowText( strText );
- dc.SetTextColor( clrText );
- dc.SetBkMode( TRANSPARENT );
- CSPFontDC font ( &dc,&m_pGrid->m_fontNormal );
- CRect rcText ( rc );
- rcText.left += 4;
- dc.DrawText( strText,rcText,DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX );
- }
- /////////////////////////////////////////////////////////////////////////////
- // CSPPropertyGridView
- CSPPropertyGridView::CSPPropertyGridView()
- {
- m_properetySort = SPGridSortCategorized;
- m_dDivider = .5;
- m_bTracking = FALSE;
- LOGFONT lfIcon;
- VERIFY( ::SystemParametersInfo( SPI_GETICONTITLELOGFONT,sizeof( lfIcon ),&lfIcon,0 ) );
- lfIcon.lfWeight = FW_NORMAL;
- lfIcon.lfItalic = FALSE;
- VERIFY( m_fontNormal.CreateFontIndirect( &lfIcon ) );
- lfIcon.lfWeight = FW_BOLD;
- VERIFY( m_fontBold.CreateFontIndirect( &lfIcon ) );
- m_pSelected = NULL;
- m_pCategories = new CSPPropertyGridItems();
- m_pCategories->m_pGrid = this;
- m_hCursor = AfxGetApp()->LoadCursor( SP_IDC_HSPLITBAR );
- m_nLockUpdate = 0;
- m_pGrid = NULL;
- }
- CSPPropertyGridView::~CSPPropertyGridView()
- {
- m_pCategories->Clear();
- m_pCategories->InternalRelease();
- }
- IMPLEMENT_DYNAMIC( CSPPropertyGridView , CListBox )
- BEGIN_MESSAGE_MAP(CSPPropertyGridView, CListBox)
- //{{AFX_MSG_MAP(CSPPropertyGridView)
- ON_WM_ERASEBKGND()
- ON_WM_PAINT()
- ON_WM_NCPAINT()
- ON_WM_LBUTTONDOWN()
- ON_WM_RBUTTONDOWN()
- ON_WM_LBUTTONDBLCLK()
- ON_CONTROL_REFLECT(LBN_SELCHANGE, OnSelectionChanged)
- ON_WM_SETCURSOR()
- ON_WM_LBUTTONUP()
- ON_WM_CAPTURECHANGED()
- ON_WM_MOUSEMOVE()
- ON_WM_SIZE()
- ON_WM_KEYDOWN()
- ON_WM_SYSKEYDOWN()
- ON_WM_KEYUP()
- ON_WM_SYSKEYUP()
- ON_WM_CHAR()
- ON_WM_GETDLGCODE()
- ON_WM_VSCROLL()
- ON_WM_MOUSEWHEEL()
- ON_WM_SETFOCUS()
- ON_WM_KILLFOCUS()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSPPropertyGridView message handlers
- void CSPPropertyGridView::OnVScroll( UINT nSBCode , UINT nPos , CScrollBar * pScrollBar )
- {
- if ( GetScrollBarCtrl( SB_VERT ) == pScrollBar )
- {
- CListBox::OnVScroll( nSBCode,nPos,pScrollBar );
- Invalidate( FALSE );
- CWnd * pWnd = GetWindow( GW_CHILD );
- while ( pWnd )
- {
- pWnd->Invalidate( FALSE );
- pWnd = pWnd->GetWindow( GW_HWNDNEXT );
- }
- }
- else
- {
- CListBox::OnVScroll( nSBCode,nPos,pScrollBar );
- }
- }
- BOOL CSPPropertyGridView::OnMouseWheel( UINT nFlags , short zDelta , CPoint pt )
- {
- BOOL bResult = CWnd::OnMouseWheel( nFlags,zDelta,pt );
- Invalidate( FALSE );
- CWnd * pWnd = GetWindow( GW_CHILD );
- while ( pWnd )
- {
- pWnd->Invalidate( FALSE );
- pWnd = pWnd->GetWindow( GW_HWNDNEXT );
- }
- return bResult;
- }
- void CSPPropertyGridView::MeasureItem( LPMEASUREITEMSTRUCT lpMeasureItemStruct )
- {
- m_pGrid->m_pPaintManager->MeasureItem( lpMeasureItemStruct );
- }
- void CSPPropertyGridView::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
- {
- ASSERT( lpDrawItemStruct->CtlType == ODT_LISTBOX );
- CSPPropertyGridItem * pItem = ( CSPPropertyGridItem * ) lpDrawItemStruct->itemData;
- if ( pItem == NULL )
- {
- return;
- }
- if ( ( int ) lpDrawItemStruct->itemID == GetCount() - 1 )
- {
- CDC * pDC = CDC::FromHandle( lpDrawItemStruct->hDC );
- CSPClientRect rc ( this );
- rc.top = lpDrawItemStruct->rcItem.bottom;
- pDC->FillSolidRect( rc,m_clrBack );
- }
- if ( !( ( GetParent()->GetStyle() & SP_PGS_OWNERDRAW ) && ( GetParent()->GetOwner()->SendMessage( SPWM_PROPERTYGRID_NOTIFY,SP_PGN_DRAWITEM,( LPARAM ) lpDrawItemStruct ) == TRUE ) ) )
- {
- m_pGrid->m_pPaintManager->DrawItem( lpDrawItemStruct );
- }
- }
- BOOL CSPPropertyGridView::OnEraseBkgnd( CDC * )
- {
- return TRUE;
- }
- void CSPPropertyGridView::OnPaint()
- {
- CPaintDC dc ( this );
- CSPClientRect rc ( this );
- CSPBufferDC buffer ( dc,rc );
- ASSERT( m_pGrid );
- m_pGrid->m_pPaintManager->FillPropertyGridView( &buffer,TRUE );
- CWnd::DefWindowProc( WM_PAINT,( WPARAM ) buffer.m_hDC,0 );
- }
- void CSPPropertyGridView::OnNcPaint()
- {
- CWindowDC dc ( this );
- CWnd::DefWindowProc( WM_PRINT,( WPARAM ) dc.m_hDC,PRF_NONCLIENT );
- ASSERT( m_pGrid );
- m_pGrid->m_pPaintManager->FillPropertyGridView( &dc,FALSE );
- }
- CSPPropertyGridItem * CSPPropertyGridView::InsertCategory( int nIndex , CString strCaption , CSPPropertyGridItem * pCategory )
- {
- ASSERT( nIndex >= 0 && nIndex <= m_pCategories->GetCount() );
- if ( nIndex < 0 || nIndex > m_pCategories->GetCount() )
- {
- nIndex = m_pCategories->GetCount();
- }
- if ( pCategory == NULL )
- {
- pCategory = new CSPPropertyGridItem( strCaption );
- }
- SetPropertySort( SPGridSortCategorized );
- pCategory->m_pGrid = this;
- pCategory->m_bCategory = TRUE;
- pCategory->m_nFlags = 0;
- pCategory->m_pChilds->m_pGrid = this;
- m_pCategories->InsertAt( nIndex,pCategory );
- if ( m_hWnd )
- {
- int nInsertAt = ( nIndex >= m_pCategories->GetCount() - 1 ) ? GetCount() : m_pCategories->GetAt( nIndex + 1 )->m_nIndex;
- InsertItem( pCategory,nInsertAt );
- }
- _RefreshIndexes();
- return pCategory;
- }
- CSPPropertyGridItem * CSPPropertyGridView::AddCategory( CString strCaption , CSPPropertyGridItem * pCategory )
- {
- return InsertCategory( m_pCategories->GetCount(),strCaption,pCategory );
- }
- void CSPPropertyGridView::Refresh()
- {
- _RefreshIndexes();
- SetPropertySort( m_properetySort,TRUE );
- if ( GetSafeHwnd() )
- {
- GetParent()->Invalidate( FALSE );
- }
- }
- void CSPPropertyGridView::ResetContent()
- {
- if ( m_pSelected )
- {
- m_pSelected->OnDeselect();
- m_pSelected = NULL;
- }
- if ( m_hWnd )
- {
- for ( int i = 0; i < GetCount(); i++ )
- {
- CSPPropertyGridItem * pItem = ( CSPPropertyGridItem * ) GetItemDataPtr( i );
- ASSERT( pItem );
- pItem->SetVisible( FALSE );
- }
- CListBox::ResetContent();
- SetFont( &m_fontNormal,FALSE );
- CWindowDC dc ( this );
- CSPFontDC font ( &dc,&m_fontNormal );
- SetItemHeight( 0,dc.GetTextExtent( _T( " " ) ).cy + 4 );
- }
- }
- void CSPPropertyGridView::SetPropertySort( SPPropertyGridSortOrder sort , BOOL bRrefresh )
- {
- if ( m_nLockUpdate > 0 )
- {
- m_properetySort = sort;
- return;
- }
- if ( sort == m_properetySort && !bRrefresh )
- {
- return;
- }
- if ( !m_hWnd )
- {
- return;
- }
- CSPPropertyGridItem * pSelected = GetSelectedItem();
- ResetContent();
- if ( sort == SPGridSortCategorized )
- {
- for ( int i = 0; i < m_pCategories->GetCount(); i++ )
- {
- CSPPropertyGridItem * pCategory = m_pCategories->GetAt( i );
- InsertItem( pCategory,GetCount() );
- }
- }
- else if ( sort == SPGridSortAlphabetical || sort == SPGridSortNoSort )
- {
- CSPPropertyGridItems lstItems;
- int i;
- for ( i = 0; i < m_pCategories->GetCount(); i++ )
- {
- CSPPropertyGridItem * pCategory = m_pCategories->GetAt( i );
- lstItems.AddTail( pCategory->m_pChilds );
- }
- if ( sort != SPGridSortNoSort )
- lstItems.Sort();
- for ( i = 0; i < lstItems.GetCount(); i++ )
- {
- CSPPropertyGridItem * pItem = lstItems.GetAt( i );
- InsertItem( pItem,GetCount() );
- }
- }
- else
- {
- ASSERT( FALSE );
- }
- _RefreshIndexes();
- if ( pSelected )
- {
- pSelected->Select();
- }
- OnSelectionChanged();
- if ( sort != m_properetySort )
- {
- m_properetySort = sort;
- ( ( CSPPropertyGrid * ) GetParent() )->OnSortChanged();
- }
- }
- int CSPPropertyGridView::GetDividerPos()
- {
- CSPWindowRect rcWindow ( this );
- return int( m_dDivider * rcWindow.Width() );
- }
- int CSPPropertyGridView::InsertItem( CSPPropertyGridItem * pItem , int nIndex )
- {
- if ( m_nLockUpdate > 0 )
- {
- return 0;
- }
- if ( !m_hWnd )
- {
- return 0;
- }
- pItem->OnBeforeInsert();
- nIndex = ( int ) ::SendMessage( m_hWnd,LB_INSERTSTRING,nIndex,( LPARAM ) pItem );
- ASSERT( nIndex != -1 );
- SetItemDataPtr( nIndex,pItem );
- if ( GetStyle() & LBS_OWNERDRAWVARIABLE )
- {
- MEASUREITEMSTRUCT measureItemStruct ={ODT_LISTBOX, 0, nIndex, 0, 0, ( ULONG_PTR ) pItem};
- MeasureItem( &measureItemStruct );
- if ( measureItemStruct.itemHeight != 0 )
- {
- SetItemHeight( nIndex,measureItemStruct.itemHeight );
- }
- }
- pItem->SetVisible( TRUE );
- int nItemsInserted = 1;
- if ( pItem->m_bExpanded )
- {
- nItemsInserted += _DoExpand( pItem,nIndex );
- }
- return nItemsInserted;
- }
- int CSPPropertyGridView::_DoExpand( CSPPropertyGridItem * pItem , int nIndex )
- {
- int nStart = nIndex;
- for ( int i = 0; i < pItem->GetChilds()->GetCount(); i++ )
- {
- CSPPropertyGridItem * pChild = pItem->GetChilds()->GetAt( i );
- nIndex += InsertItem( pChild,nIndex + 1 );
- }
- return nIndex - nStart;
- }
- void CSPPropertyGridView::_RefreshIndexes()
- {
- if ( m_hWnd )
- {
- for ( int i = 0; i < GetCount(); i++ )
- {
- CSPPropertyGridItem * pItem = ( CSPPropertyGridItem * ) GetItemDataPtr( i );
- ASSERT( pItem );
- pItem->m_nIndex = i;
- }
- }
- }
- void CSPPropertyGridView::_DoCollapse( CSPPropertyGridItem * pItem )
- {
- ASSERT( pItem );
- ASSERT( pItem->m_bExpanded );
- int nIndex = pItem->m_nIndex + 1;
- while ( nIndex < GetCount() )
- {
- CSPPropertyGridItem * pChild = ( CSPPropertyGridItem * ) GetItemDataPtr( nIndex );
- ASSERT( pChild );
- if ( !pChild || !pChild->HasParent( pItem ) )
- break;
- pChild->SetVisible( FALSE );
- DeleteString( nIndex );
- }
- _RefreshIndexes();
- }
- CSPPropertyGridItem * CSPPropertyGridView::GetItem( int nIndex )
- {
- if ( nIndex < 0 || nIndex >= GetCount() )
- {
- return 0;
- }
- CSPPropertyGridItem * pItem = ( CSPPropertyGridItem * ) GetItemDataPtr( nIndex );
- if ( ( ULONG_PTR ) pItem == ( ULONG_PTR ) ( -1 ) )
- {
- return NULL;
- }
- ASSERT( pItem );
- return pItem;
- }
- void CSPPropertyGridView::SwitchExpandState( int nItem )
- {
- CSPPropertyGridItem * pItem = GetItem( nItem );
- if ( !pItem )
- {
- return;
- }
- if ( pItem->m_bExpanded )
- {
- pItem->Collapse();
- }
- else
- {
- pItem->Expand();
- }
- }
- void CSPPropertyGridView::OnLButtonDown( UINT nFlags , CPoint point )
- {
- if ( HitTest( point ) == PGV_HIT_SPLITTER )
- {
- SetFocus();
- SetCapture();
- if ( m_pSelected )
- m_pSelected->OnValidateEdit();
- m_bTracking = TRUE;
- return;
- }
- CSPPropertyGridItem * pItem = ItemFromPoint( point );
- if ( pItem )
- {
- SetFocus();
- if ( GetFocus() != this )
- return;
- if ( ( ItemFromPoint( point ) == pItem ) && pItem->OnLButtonDown( nFlags,point ) )
- return;
- }
- CListBox::OnLButtonDown( nFlags,point );
- }
- CSPPropertyGridItem * CSPPropertyGridView::ItemFromPoint( CPoint point )
- {
- BOOL bOutside = FALSE;
- int nIndex = CListBox::ItemFromPoint( point,bOutside );
- if ( nIndex != -1 && !bOutside )
- {
- return GetItem( nIndex );
- }
- return NULL;
- }
- void CSPPropertyGridView::OnMouseMove( UINT nFlags , CPoint point )
- {
- if ( m_bTracking )
- {
- CSPWindowRect rcWindow ( this );
- m_dDivider = ( double ) point.x / rcWindow.Width();
- m_dDivider = __max( m_dDivider,.1 );
- m_dDivider = __min( m_dDivider,.85 );
- if ( m_pSelected )
- m_pSelected->OnSelect();
- Invalidate( FALSE );
- }
- else
- {
- ShowToolTip( point );
- }
- CListBox::OnMouseMove( nFlags,point );
- }
- void CSPPropertyGridView::OnLButtonUp( UINT nFlags , CPoint point )
- {
- if ( m_bTracking )
- {
- ReleaseCapture();
- m_bTracking = FALSE;
- }
- CListBox::OnLButtonUp( nFlags,point );
- }
- void CSPPropertyGridView::OnCaptureChanged( CWnd * pWnd )
- {
- m_bTracking = FALSE;
- CListBox::OnCaptureChanged( pWnd );
- }
- void CSPPropertyGridView::OnLButtonDblClk( UINT nFlags , CPoint point )
- {
- CListBox::OnLButtonDblClk( nFlags,point );
- CSPPropertyGridItem * pItem = ItemFromPoint( point );
- if ( pItem )
- {
- pItem->OnLButtonDblClk();
- if ( pItem == ItemFromPoint( point ) )
- {
- GetParent()->GetOwner()->SendMessage( SPWM_PROPERTYGRID_NOTIFY,SP_PGN_DBLCLICK,( LPARAM ) pItem );
- }
- }
- }
- void CSPPropertyGridView::OnRButtonDown( UINT nFlags , CPoint point )
- {
- CListBox::OnRButtonDown( nFlags,point );
- CSPPropertyGridItem * pItem = ItemFromPoint( point );
- if ( pItem )
- {
- pItem->OnRButtonDown();
- if ( pItem == ItemFromPoint( point ) )
- {
- GetParent()->GetOwner()->SendMessage( SPWM_PROPERTYGRID_NOTIFY,SP_PGN_RCLICK,( LPARAM ) pItem );
- }
- }
- }
- CSPPropertyGridItem * CSPPropertyGridView::GetSelectedItem()
- {
- return m_hWnd ? GetItem( GetCurSel() ) : 0;
- }
- void CSPPropertyGridView::OnChar( UINT nChar , UINT nRepCntr , UINT nFlags )
- {
- if ( m_bTracking )
- {
- return;
- }
- CSPPropertyGridItem * pItem = GetSelectedItem();
- if ( nChar == '+' && pItem && pItem->HasChilds() && !pItem->m_bExpanded )
- {
- pItem->Expand();
- return;
- }
- if ( nChar == '-' && pItem && pItem->HasChilds() && pItem->m_bExpanded )
- {
- pItem->Collapse();
- return;
- }
- if ( nChar == VK_TAB )
- {
- m_pGrid->OnNavigate( SPGridUIView,GetKeyState( VK_SHIFT ) >= 0,pItem );
- return;
- }
- if ( pItem && ( nChar != VK_RETURN || !pItem->HasChilds() ) )
- {
- if ( pItem->OnChar( nChar ) )
- {
- return;
- }
- }
- CWnd::OnChar( nChar,nRepCntr,nFlags );
- }
- UINT CSPPropertyGridView::OnGetDlgCode()
- {
- return DLGC_WANTALLKEYS;
- }
- void CSPPropertyGridView::OnKeyUp( UINT nChar , UINT nRepCnt , UINT nFlags )
- {
- #ifdef SP_SITENOTIFY_KEY
- SP_SITENOTIFY_KEY( this,this,FALSE,nChar )
- #endif
- CListBox::OnKeyUp( nChar,nRepCnt,nFlags );
- }
- void CSPPropertyGridView::OnSysKeyUp( UINT nChar , UINT nRepCnt , UINT nFlags )
- {
- #ifdef SP_SITENOTIFY_KEY
- SP_SITENOTIFY_KEY( this,this,FALSE,nChar )
- #endif
- CListBox::OnSysKeyUp( nChar,nRepCnt,nFlags );
- }
- void CSPPropertyGridView::OnKeyDown( UINT nChar , UINT nRepCnt , UINT nFlags )
- {
- #ifdef SP_SITENOTIFY_KEY
- SP_SITENOTIFY_KEY( this,this,TRUE,nChar )
- #endif
- CSPPropertyGridItem * pItem = GetSelectedItem();
- if ( nChar == VK_RIGHT )
- {
- if ( GetKeyState( VK_CONTROL ) < 0 )
- {
- CSPWindowRect rcWindow ( this );
- m_dDivider = m_dDivider + 2.0 / rcWindow.Width();
- m_dDivider = __max( m_dDivider,.1 );
- m_dDivider = __min( m_dDivider,.85 );
- if ( m_pSelected )
- m_pSelected->OnSelect();
- Invalidate( FALSE );
- return;
- }
- if ( pItem && pItem->HasChilds() && !pItem->m_bExpanded )
- {
- pItem->Expand();
- return;
- }
- }
- else if ( nChar == VK_LEFT )
- {
- if ( GetKeyState( VK_CONTROL ) < 0 )
- {
- CSPWindowRect rcWindow ( this );
- m_dDivider = m_dDivider - 2.0 / rcWindow.Width();
- m_dDivider = __max( m_dDivider,.1 );
- m_dDivider = __min( m_dDivider,.85 );
- if ( m_pSelected )
- m_pSelected->OnSelect();
- Invalidate( FALSE );
- return;
- }
- if ( pItem && pItem->HasChilds() && pItem->m_bExpanded )
- {
- pItem->Collapse();
- return;
- }
- }
- if ( nChar == VK_RETURN )
- {
- SwitchExpandState( GetCurSel() );
- return ;
- }
- if ( nChar == VK_F4 )
- {
- if ( m_pSelected && m_pSelected->GetFlags() & SPGridItemHasComboButton )
- {
- m_pSelected->OnInplaceButtonDown();
- }
- }
- CListBox::OnKeyDown( nChar,nRepCnt,nFlags );
- }
- void CSPPropertyGridView::OnSysKeyDown( UINT nChar , UINT nRepCnt , UINT nFlags )
- {
- #ifdef SP_SITENOTIFY_KEY
- SP_SITENOTIFY_KEY( this,this,TRUE,nChar )
- #endif
- if ( nChar == VK_DOWN || nChar == VK_UP )
- {
- if ( m_pSelected && m_pSelected->GetFlags() & SPGridItemHasComboButton )
- {
- m_pSelected->OnInplaceButtonDown();
- }
- }
- CListBox::OnSysKeyDown( nChar,nRepCnt,nFlags );
- }
- BOOL CSPPropertyGridView::OnWndMsg( UINT message , WPARAM wParam , LPARAM lParam , LRESULT * pResult )
- {
- static BOOL bRelay = FALSE;
- if ( m_wndTip.GetSafeHwnd() && m_wndTip.IsWindowVisible() && !bRelay )
- {
- bRelay = TRUE;
- RelayToolTipEvent( message );
- bRelay = FALSE;
- }
- return CWnd::OnWndMsg( message,wParam,lParam,pResult );
- }
- void CSPPropertyGridView::OnSelectionChanged()
- {
- CSPPropertyGridItem * pItem = GetSelectedItem();
- if ( m_pSelected )
- {
- m_pSelected->OnDeselect();
- }
- if ( pItem )
- {
- pItem->OnSelect();
- }
- m_pSelected = pItem;
- if ( m_pSelected )
- {
- ( ( CSPPropertyGrid * ) GetParent() )->OnSelectionChanged( m_pSelected );
- }
- }
- int CSPPropertyGridView::HitTest( CPoint point )
- {
- CSPWindowRect rcWindow ( this );
- int nWidth = int( m_dDivider * rcWindow.Width() );
- if ( point.x > nWidth - 4 && point.x <= nWidth + 2 && GetCount() > 0 )
- {
- return PGV_HIT_SPLITTER;
- }
- return -1;
- }
- BOOL CSPPropertyGridView::OnSetCursor( CWnd * pWnd , UINT nHitTest , UINT message )
- {
- if ( nHitTest == HTCLIENT )
- {
- CPoint point;
- GetCursorPos( &point );
- ScreenToClient( &point );
- if ( HitTest( point ) == PGV_HIT_SPLITTER )
- {
- SetCursor( m_hCursor );
- return TRUE;
- }
- }
- return CListBox::OnSetCursor( pWnd,nHitTest,message );
- }
- void CSPPropertyGridView::OnSize( UINT nType , int cx , int cy )
- {
- CListBox::OnSize( nType,cx,cy );
- OnSelectionChanged();
- }
- // ToolTips routings
- void CSPPropertyGridView::_ShowToolTip( CRect rcBound , CRect rcText )
- {
- m_wndTip.SetWindowText( m_strTipText );
- m_wndTip.MoveWindow( rcText );
- m_wndTip.Activate( TRUE );
- m_rcToolTip = rcBound;
- TRACKMOUSEEVENT tme ={sizeof( TRACKMOUSEEVENT ), TME_LEAVE, m_hWnd, 0};
- _TrackMouseEvent( &tme );
- }
- CSize CSPPropertyGridView::_GetTextExtent( CString str )
- {
- CWindowDC dc ( this );
- CSPFontDC font ( &dc,GetFont() );
- return dc.GetTextExtent( str );
- }
- void CSPPropertyGridView::ShowToolTip( CPoint pt )
- {
- if ( !m_wndTip.GetSafeHwnd() )
- {
- m_wndTip.Create( this );
- }
- CSPPropertyGridItem * pItem = ItemFromPoint( pt );
- if ( !pItem || pItem->IsCategory() )
- {
- return;
- }
- CSPWindowRect rcWindow ( this );
- CRect rc = pItem->GetItemRect();
- CRect rcCaption ( rc.left,rc.top,rc.left + int( m_dDivider * rcWindow.Width() ),rc.bottom );
- if ( rcCaption.PtInRect( pt ) )
- {
- if ( m_strTipText == pItem->GetCaption() )
- return;
- m_strTipText = pItem->GetCaption();
- ClientToScreen( &rcCaption );
- CRect rcCaptionText ( rcCaption );
- rcCaptionText.left += pItem->m_nIndent * SP_PGI_EXPAND_BORDER + 3 - 3 - 1;
- rcCaptionText.top--;
- if ( _GetTextExtent( m_strTipText ).cx + 3 > rcCaptionText.Width() )
- {
- if ( GetExStyle() & WS_EX_LAYOUTRTL )
- {
- rcCaptionText.left = rcCaption.right - _GetTextExtent( m_strTipText ).cx - 7 - ( pItem->m_nIndent * SP_PGI_EXPAND_BORDER );
- }
- _ShowToolTip( rcCaption,rcCaptionText );
- }
- }
- else
- {
- if ( m_strTipText == pItem->GetViewValue() )
- return;
- m_strTipText = pItem->GetViewValue();
- if ( GetFocus() && GetFocus()->IsKindOf( RUNTIME_CLASS( CSPPropertyGridInplaceEdit ) ) )
- {
- if ( ( ( CSPPropertyGridInplaceEdit * ) ( GetFocus() ) )->GetItem() == pItem )
- return;
- }
- CRect rcValue ( rc.left + int( m_dDivider * rcWindow.Width() ),rc.top,rc.right,rc.bottom );
- ClientToScreen( &rcValue );
- CRect rcValueText = pItem->GetValueRect();
- rcValueText.InflateRect( 1,2,0,1 );
- ClientToScreen( &rcValueText );
- if ( _GetTextExtent( m_strTipText ).cx + 3 > rcValueText.Width() )
- {
- if ( GetExStyle() & WS_EX_LAYOUTRTL )
- {
- rcValueText.left = rcValueText.right - 8 - _GetTextExtent( m_strTipText ).cx;
- }
- _ShowToolTip( rcValue,rcValueText );
- }
- }
- }
- void CSPPropertyGridView::RelayToolTipEvent( UINT message )
- {
- if ( m_wndTip.GetSafeHwnd() && m_wndTip.IsWindowVisible() )
- {
- CRect rc;
- m_wndTip.GetWindowRect( rc );
- CPoint pt;
- GetCursorPos( &pt );
- if ( !m_rcToolTip.PtInRect( pt ) )
- {
- m_strTipText = "";
- m_wndTip.Activate( FALSE );
- }
- switch ( message )
- {
- case WM_MOUSEWHEEL:
- m_strTipText = "";
- case WM_KEYDOWN:
- case WM_SYSKEYDOWN:
- case WM_LBUTTONDOWN:
- case WM_RBUTTONDOWN:
- case WM_MBUTTONDOWN:
- case WM_LBUTTONUP:
- case WM_RBUTTONUP:
- case WM_MBUTTONUP:
- case WM_MOUSELEAVE:
- m_wndTip.Activate( FALSE );
- }
- }
- }
- void CSPPropertyGridView::OnSetFocus( CWnd * pOldWnd )
- {
- CListBox::OnSetFocus( pOldWnd );
- #ifdef SP_SITENOTIFY_ONFOCUS
- SP_SITENOTIFY_ONFOCUS( this,this,TRUE )
- #endif
- }
- void CSPPropertyGridView::OnKillFocus( CWnd * pNewWnd )
- {
- CListBox::OnKillFocus( pNewWnd );
- #ifdef SP_SITENOTIFY_ONFOCUS
- SP_SITENOTIFY_ONFOCUS( this,this,FALSE )
- #endif
- }
|