ExtControlsCommon.cpp
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:275k
- {
- case LVS_ICON:
- case LVS_SMALLICON:
- case LVS_REPORT:
- break;
- case LVS_LIST:
- {
- CRect rcItem( 0, 0, 0, 0 );
- INT nTopIndex = GetTopIndex();
- if( nTopIndex >= 0
- && CExtListCtrl::GetItemRect( nTopIndex, &rcItem, LVIR_BOUNDS )
- )
- nItemExtent = rcItem.Width();
- }
- break;
- } // switch( dwListCtrlType )
- if( nSBCode == SB_THUMBTRACK || nSBCode == SB_THUMBPOSITION )
- {
- INT nPosOld = GetScrollPos( SB_HORZ );
- INT nPosShift = nPos*nItemExtent - nPosOld*nItemExtent;
- Scroll( CSize( nPosShift, 0 ) );
- return 0L;
- }
- if( nSBCode == SB_LINELEFT
- || nSBCode == SB_LINERIGHT
- || nSBCode == SB_PAGELEFT
- || nSBCode == SB_PAGERIGHT
- || nSBCode == SB_LEFT
- || nSBCode == SB_RIGHT
- || nSBCode == SB_ENDSCROLL
- )
- return 0L;
- } // case WM_HSCROLL:
- break; // case WM_VSCROLL
- case WM_VSCROLL:
- {
- UINT nSBCode = UINT(LOWORD(DWORD(wParam))), nPos = UINT(HIWORD(DWORD(wParam)));
- //TRACE2( "WM_VSCROLL, nSBCode = %d, nPos = %drn", nSBCode, nPos );
- INT nItemExtent = 1;
- DWORD dwStyle = GetStyle();
- DWORD dwListCtrlType = dwStyle&LVS_TYPEMASK;
- switch( dwListCtrlType )
- {
- case LVS_ICON:
- case LVS_SMALLICON:
- case LVS_LIST:
- break;
- case LVS_REPORT:
- {
- CRect rcItem( 0, 0, 0, 0 );
- INT nTopIndex = GetTopIndex();
- if( nTopIndex >= 0
- && CExtListCtrl::GetItemRect( nTopIndex, &rcItem, LVIR_BOUNDS )
- )
- nItemExtent = rcItem.Height();
- else
- {
- TEXTMETRIC _tm;
- ::memset( &_tm, 0, sizeof(TEXTMETRIC) );
- CClientDC dc( this );
- CFont * pFont = GetFont();
- int nSave = dc.SaveDC();
- dc.SelectObject( pFont );
- dc.GetTextMetrics( &_tm );
- nItemExtent = _tm.tmHeight + _tm.tmExternalLeading + 1;
- dc.RestoreDC( nSave );
- }
- }
- break;
- } // switch( dwListCtrlType )
- if( nSBCode == SB_THUMBTRACK || nSBCode == SB_THUMBPOSITION )
- {
- INT nPosOld = GetScrollPos( SB_VERT );
- INT nPosShift = nPos*nItemExtent - nPosOld*nItemExtent;
- Scroll( CSize( 0, nPosShift ) );
- return 0L;
- }
- if( nSBCode == SB_LINEUP
- || nSBCode == SB_LINEDOWN
- || nSBCode == SB_PAGEUP
- || nSBCode == SB_PAGEDOWN
- || nSBCode == SB_TOP
- || nSBCode == SB_BOTTOM
- || nSBCode == SB_ENDSCROLL
- )
- return 0L;
- }
- break; // case WM_VSCROLL
- } // switch( message )
- LRESULT lResult = CExtNCSB_Impl < CExtListCtrl > :: WindowProc( message, wParam, lParam );
- switch( message )
- {
- case WM_STYLECHANGED:
- if( wParam == GWL_STYLE )
- {
- STYLESTRUCT * ptr = (STYLESTRUCT *)lParam;
- ASSERT( ptr != NULL );
- DWORD dwOldType = DWORD( ptr->styleOld & LVS_TYPEMASK );
- DWORD dwNewType = DWORD( ptr->styleNew & LVS_TYPEMASK );
- if( dwOldType != dwNewType )
- AdjustScrollMetrics();
- } // if( wParam == GWL_STYLE )
- break; // case WM_STYLECHANGED
- } // switch( message )
- return lResult;
- }
- #endif // ( ! defined __EXT_MFC_NO_LIST_VIEW_CTRL )
- #if ( ! defined __EXT_MFC_NO_TREE_VIEW_CTRL )
- /////////////////////////////////////////////////////////////////////////////
- // CExtTreeCtrl
- IMPLEMENT_DYNCREATE( CExtTreeCtrl, CTreeCtrl )
- const UINT CExtTreeCtrl::g_nMsgTreeItemDelayedFocus = ::RegisterWindowMessage( _T("CExtTreeCtrl::g_nMsgTreeItemDelayedFocus") );
- CExtTreeCtrl::CExtTreeCtrl()
- : m_eOS( CExtTreeCtrl::line_style_dots )
- , m_eTBS( CExtTreeCtrl::tree_box_style_square )
- , m_clrExpandCollapseButtonSign( COLORREF(-1L) )
- , m_clrExpandCollapseButtonFill( COLORREF(-1L) )
- , m_clrLines( COLORREF(-1L) )
- , m_clrTreeBkColor( COLORREF(-1L) )
- , m_clrProgressBackgroundColor( COLORREF(-1L) )
- , m_clrProgressBorder( COLORREF(-1L) )
- , m_clrProgressBoxColor( COLORREF(-1L) )
- , m_dwTreeStyle( __EXT_TREE_DEFAULT_STYLES )
- , m_dwTreeStyleEx( __EXT_TREE_EX_DEFAULT_STYLES )
- , m_htiAnchorItem( NULL )
- , m_htiInsertMark( NULL )
- , m_bInsertMarkAfter( false )
- , m_hWndChildControl( NULL )
- , m_nMarginCheckBoxLeft( 1 )
- , m_nMarginCheckBoxRight( 1 )
- , m_nMarginIconLeft( 1 )
- , m_nMarginIconRight( 1 )
- , m_nMarginLabelLeft( 1 )
- , m_nMarginLabelRight( 1 )
- , m_nMarginControlLabelLeft( 1 )
- , m_nMarginControlLabelRight( 1 )
- , m_nPaddingLabelLeft( 3 )
- , m_nPaddingLabelRight( 3 )
- , m_htiHover( NULL )
- , m_dwLastHoverHitTestFlags( 0 )
- , m_hCursorHand( NULL )
- , m_htiInplaceEdited( NULL )
- , m_bCanceling( false )
- // , m_bSynchronizingBarH( false )
- // , m_bSynchronizingBarV( false )
- , m_nDelayedFocusTimerID( 666 )
- , m_nDelayedFocusTime( 500 )
- , m_nDelayedEditingTimerID( 667 )
- , m_htiDelayedFocus( NULL )
- , m_bReadOnlyLabels( false )
- , m_dwCheckBoxAreaFlags( __EXT_TVHT_ONCHECKBOX )
- {
- ::memset( &m_nLastMouseButtonEventType, 0, sizeof(m_nLastMouseButtonEventType) );
- if( g_PaintManager.m_bIsWin2000orLater )
- m_hCursorHand = ::LoadCursor( NULL, MAKEINTRESOURCE(32649) );
- if( m_hCursorHand == NULL )
- {
- HRSRC hRSRC = NULL;
- HINSTANCE hInst = g_ResourceManager->FindResourceHandle( RT_GROUP_CURSOR, IDC_EXT_HAND, NULL, &hRSRC );
- if( hInst != NULL)
- m_hCursorHand = ::LoadCursor( hInst, MAKEINTRESOURCE(IDC_EXT_HAND) );
- }
- }
- CExtTreeCtrl::~CExtTreeCtrl()
- {
- _UnregisterItemsFromMap();
- TreeIconRemoveAll();
- }
- BEGIN_MESSAGE_MAP( CExtTreeCtrl, CTreeCtrl )
- //{{AFX_MSG_MAP(CExtTreeCtrl)
- ON_WM_ERASEBKGND()
- ON_WM_PAINT()
- 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_MOUSEMOVE()
- ON_WM_MOUSEWHEEL()
- ON_WM_KEYDOWN()
- ON_WM_KEYUP()
- ON_WM_SETFOCUS()
- ON_WM_KILLFOCUS()
- ON_MESSAGE( WM_SETFONT, OnSetFont )
- ON_MESSAGE( WM_SETTINGCHANGE, OnSettingChange )
- ON_MESSAGE( WM_STYLECHANGING, OnStyleChanging )
- ON_MESSAGE( WM_STYLECHANGED, OnStyleChanged )
- ON_WM_SETCURSOR()
- ON_WM_ACTIVATEAPP()
- ON_WM_CANCELMODE()
- ON_WM_HSCROLL()
- ON_WM_VSCROLL()
- ON_WM_SIZE()
- ON_WM_MOUSEWHEEL()
- ON_WM_GETDLGCODE()
- ON_WM_TIMER()
- ON_WM_CONTEXTMENU()
- //}}AFX_MSG_MAP
- ON_REGISTERED_MESSAGE(
- CExtContentExpandWnd::g_nMsgPaintItemContent,
- _OnPaintExpanedItemContent
- )
- END_MESSAGE_MAP()
- BOOL CExtTreeCtrl::OnEraseBkgnd( CDC* pDC )
- {
- pDC;
- return TRUE;
- }
- void CExtTreeCtrl::OnPaint()
- {
- CPaintDC dcPaint(this);
- CExtMemoryDC dc( &dcPaint );
- OnPaintEntireTree( dc );
- }
- void CExtTreeCtrl::OnPaintEntireTree( CDC & dc )
- {
- ASSERT_VALID( this );
- ASSERT( dc.GetSafeHdc() != NULL );
- CRect rcClient;
- GetClientRect( &rcClient );
- COLORREF clrTreeBkColor = TreeBkColorGet();
- if( clrTreeBkColor == COLORREF(-1L) )
- clrTreeBkColor = ::GetSysColor( COLOR_WINDOW );
- dc.FillSolidRect( &rcClient, clrTreeBkColor );
- CFont * pOldFont = dc.SelectObject( &m_fontNormal );
- COLORREF clrBackgroundOld = dc.SetBkColor( clrTreeBkColor );
- COLORREF clrText = ::GetSysColor( COLOR_BTNTEXT );
- COLORREF clrTextOld = dc.SetTextColor( clrText );
- int nOldBkMode = dc.SetBkMode( TRANSPARENT );
- bool bFocusedWindow = OnQueryWindowFocusedState();
- HTREEITEM htiFirst = GetNextItem( NULL, TVGN_FIRSTVISIBLE );
- HTREEITEM htiFocus = GetFocusedItem();
- HTREEITEM htiDH = GetNextItem( NULL, TVGN_DROPHILITE );
- HTREEITEM hti = htiFirst;
- for( ; hti != NULL; hti = GetNextItem( hti, TVGN_NEXTVISIBLE ) )
- {
- bool bDisabledItem = ! OnQueryItemEnabledState( hti );
- bool bFocusedItem = ( hti == htiFocus ) ? true : false;
- bool bSelectedItem = IsItemSelected( hti );
- bool bDH = ( hti == htiDH ) ? true : false;
- CRect rcItemEntire;
- TreeItemRectGet( hti, rcItemEntire, e_tirt_entire );
- if( rcItemEntire.top > rcClient.bottom )
- break;
- OnPaintTreeItem(
- hti,
- dc,
- rcItemEntire,
- bFocusedWindow,
- bDisabledItem,
- bSelectedItem,
- bFocusedItem,
- bDH/*,
- clrBackground*/
- );
- dc.SetBkColor( clrTreeBkColor );
- dc.SetTextColor( clrText );
- }
- dc.SetBkMode( nOldBkMode );
- dc.SetTextColor( clrTextOld );
- dc.SetBkColor( clrBackgroundOld );
- dc.SelectObject( pOldFont );
- }
- void CExtTreeCtrl::OnPaintTreeItem(
- HTREEITEM hti,
- CDC & dc,
- CRect rcItemEntire,
- bool bFocusedWindow,
- bool bDisabledItem,
- bool bSelectedItem,
- bool bFocusedItem,
- bool bDH
- )
- {
- ASSERT_VALID( this );
- ASSERT( hti != NULL );
- ASSERT( dc.GetSafeHdc() != NULL );
- if( ! dc.RectVisible( &rcItemEntire ) )
- return;
- bool bShowSelectionAlways = ShowSelectionAlwaysGet();
- bool bHoverDisabledItems = ( ( TreeGetStyle() & __EXT_TREE_HOVER_DISABLE_ITEMS ) != 0 ) ? true : false;
- const TREEITEMINFO_t & _TII = TreeItemInfoGet( hti );
- INT nLevelIndent = (INT)GetIndent();
- COLORREF clrItemBk = _TII.m_clrBackgroundNormal;
- COLORREF clrItemText = _TII.m_clrTextNormal;
- if( bDisabledItem )
- {
- if( _TII.m_clrTextDisabled != COLORREF(-1L) )
- clrItemText = _TII.m_clrTextDisabled;
- else
- clrItemText = ::GetSysColor( COLOR_3DSHADOW );
- if( _TII.m_clrBackgroundDisabled != COLORREF(-1L) )
- clrItemBk = _TII.m_clrBackgroundDisabled;
- else
- {
- clrItemBk = TreeBkColorGet();
- if( clrItemBk == COLORREF(-1L) )
- clrItemBk = ::GetSysColor( COLOR_WINDOW );
- }
- if( bSelectedItem && ( bFocusedWindow || bShowSelectionAlways ) )
- {
- /*if( _TII.m_clrTextSelected != COLORREF(-1L) )
- clrItemText = _TII.m_clrTextSelected;
- else
- clrItemText = ::GetSysColor( bFocusedWindow ? COLOR_HIGHLIGHTTEXT : COLOR_BTNTEXT );*/
- if( _TII.m_clrBackgroundSelected != COLORREF(-1L) )
- clrItemBk = _TII.m_clrBackgroundSelected;
- else
- {
- clrItemBk = ::GetSysColor( bFocusedWindow ? COLOR_HIGHLIGHT : COLOR_BTNFACE );
- if( ( ! bFocusedWindow )
- && g_PaintManager.m_bIsWinVista
- && g_PaintManager.m_UxTheme.IsControlsThemed()
- )
- clrItemBk = CExtPaintManager::stat_HLS_Adjust( clrItemBk, 0.0, -0.10, 0.0 );
- }
- }
- }
- else if( bSelectedItem && ( bFocusedWindow || bShowSelectionAlways ) )
- {
-
- if( _TII.m_clrTextSelected != COLORREF(-1L) )
- clrItemText = _TII.m_clrTextSelected;
- else
- clrItemText = ::GetSysColor( bFocusedWindow ? COLOR_HIGHLIGHTTEXT : COLOR_BTNTEXT );
- if( _TII.m_clrBackgroundSelected != COLORREF(-1L) )
- clrItemBk = _TII.m_clrBackgroundSelected;
- else
- {
- clrItemBk = ::GetSysColor( bFocusedWindow ? COLOR_HIGHLIGHT : COLOR_BTNFACE );
- if( ( ! bFocusedWindow )
- && g_PaintManager.m_bIsWinVista
- && g_PaintManager.m_UxTheme.IsControlsThemed()
- )
- clrItemBk = CExtPaintManager::stat_HLS_Adjust( clrItemBk, 0.0, -0.10, 0.0 );
- }
-
- }
- else if( bDH )
- {
- if( _TII.m_clrTextSelected != COLORREF(-1L) )
- clrItemText = _TII.m_clrTextSelected;
- else
- clrItemText = ::GetSysColor( COLOR_HIGHLIGHTTEXT );
- if( _TII.m_clrBackgroundSelected != COLORREF(-1L) )
- clrItemBk = _TII.m_clrBackgroundSelected;
- else
- {
- clrItemBk = ::GetSysColor( COLOR_HIGHLIGHT );
- if( ( ! bFocusedWindow )
- && g_PaintManager.m_bIsWinVista
- && g_PaintManager.m_UxTheme.IsControlsThemed()
- )
- clrItemBk = CExtPaintManager::stat_HLS_Adjust( clrItemBk, 0.0, -0.10, 0.0 );
- }
- }
- if( hti == m_htiHover
- && ( bHoverDisabledItems || (! bDisabledItem ) )
- && ( (!bSelectedItem) || ( (!bShowSelectionAlways) && (!bFocusedWindow) ) )
- && ( GetStyle() & TVS_TRACKSELECT ) != 0
- && ( ( m_dwLastHoverHitTestFlags & __EXT_TVHT_ONITEMLABEL ) != 0
- || ( GetStyle() & TVS_FULLROWSELECT ) != 0
- )
- )
- {
- if( _TII.m_clrTextHover != COLORREF(-1L) )
- clrItemText = _TII.m_clrTextHover;
- else
- clrItemText = RGB(0,0,255);
- }
- // item background
- CRect rcItemLabel;
- TreeItemRectGet( hti, rcItemLabel, e_tirt_label );
- bool bFullRowSelection = ( ( GetStyle() & TVS_FULLROWSELECT ) != 0 ) ? true : false;
- CRect rcItemBackground = bFullRowSelection ? rcItemEntire : rcItemLabel;
- OnPaintTreeItemBackground(
- hti,
- dc,
- rcItemBackground,
- bFocusedWindow,
- bDisabledItem,
- bSelectedItem,
- bFocusedItem,
- bDH,
- clrItemBk
- );
- // tree lines
- CRect rcLinesArea;
- VERIFY( TreeItemRectGet( hti, rcLinesArea, e_tirt_line_area ) );
- COLORREF clrForceLines = ( bFullRowSelection && bSelectedItem ) ? clrItemText : COLORREF(-1L);
- OnPaintTreeItemLines(hti, dc, nLevelIndent, rcLinesArea, clrForceLines );
- // tree box
- CRect rcTreeBoxArea;
- VERIFY( TreeItemRectGet( hti, rcTreeBoxArea, e_tirt_tree_box ) );
- COLORREF clrForceBoxLines = ( bFullRowSelection && bSelectedItem ) ? clrItemText : COLORREF(-1L);
- COLORREF clrForceBoxBackground = ( bFullRowSelection && bSelectedItem ) ? clrItemBk : COLORREF(-1L);
- COLORREF clrForceBoxBk = COLORREF(-1L);
- if( bFullRowSelection && ( bFocusedWindow || bShowSelectionAlways ) )
- clrForceBoxBk = clrItemBk;
- OnPaintTreeItemExpandCollapseButton(
- hti,
- dc,
- rcTreeBoxArea,
- clrForceBoxLines,
- clrForceBoxBackground,
- clrForceBoxBk
- );
- // check box
- if( _TII.m_eCheckBoxType == e_cbt_check_box
- || _TII.m_eCheckBoxType == e_cbt_tri_state_check_box
- )
- {
- CRect rcTreeCheckBoxArea;
- VERIFY( TreeItemRectGet( hti, rcTreeCheckBoxArea, e_tirt_check_box ) );
- OnPaintTreeItemCheckBox( hti, dc, rcTreeCheckBoxArea );
- }
- // radio box
- if( _TII.m_eCheckBoxType == e_cbt_radio )
- {
- CRect rcTreeRadioBoxArea;
- VERIFY( TreeItemRectGet( hti, rcTreeRadioBoxArea, e_tirt_check_box ) );
- OnPaintTreeItemRadioBox( hti, dc, rcTreeRadioBoxArea );
- }
- // icon
- CRect rcTreeIconArea;
- if( TreeItemRectGet( hti, rcTreeIconArea, e_tirt_icon ) )
- {
- if( dc.RectVisible( &rcTreeIconArea ) )
- {
- const CExtCmdIcon * pIcon = OnTreeItemQueryIcon( hti );
- if( pIcon != NULL
- && ( ! pIcon->IsEmpty() )
- )
- OnPaintTreeItemIcon( hti, dc, *pIcon, rcTreeIconArea );
- }
- }
- // control text
- if( _TII.m_nControlWidth > 0
- //&& ( ! _TII.m_strEditText.IsEmpty() )
- )
- {
- CRect rcTreeControlArea;
- TreeItemRectGet( hti, rcTreeControlArea, e_tirt_control );
- COLORREF clrControlText = COLORREF(-1L);
- if( bFullRowSelection )
- clrControlText = clrItemText;
- OnPaintTreeItemControl( hti, dc, rcTreeControlArea, clrControlText );
- }
- // text
- OnPaintTreeItemText( hti, dc, rcItemLabel, clrItemText );
- // focus rect
- if( bFocusedItem && bFocusedWindow )
- dc.DrawFocusRect( &rcItemBackground );
- // insert mark
- if( hti == m_htiInsertMark )
- {
- COLORREF clrInsertMark = GetInsertMarkColor();
- OnPaintTreeItemInsertMark( hti, dc, m_bInsertMarkAfter, clrInsertMark, rcItemEntire, rcItemLabel );
- }
- }
- void CExtTreeCtrl::OnPaintTreeItemLines(
- HTREEITEM hti,
- CDC & dc,
- INT nLevelIndent,
- CRect rcLinesArea,
- COLORREF clrForceLines
- )
- {
- ASSERT_VALID( this );
- ASSERT( hti != NULL );
- ASSERT( dc.GetSafeHdc() != NULL );
- bool bHasLines = ( ( GetStyle() & TVS_HASLINES ) != 0 ) ? true : false;
- //bool bLinesAtRoot = ( ( GetStyle() & TVS_LINESATROOT ) != 0 ) ? true : false;
- if( bHasLines )
- {
- CRect rcLines = rcLinesArea;
- rcLines.left = rcLines.right - nLevelIndent;
- HTREEITEM htiWalk = hti;
- COLORREF clrLines = clrForceLines;
- if( clrLines == COLORREF(-1L) )
- clrLines = LineColorGet();
- if( clrLines == COLORREF(-1L) )
- clrLines = RGB(0,0,0);
- CPen pen( PS_SOLID, 1, clrLines );
- CPen * pOldPen = dc.SelectObject( &pen );
- e_line_style_t eOS = LineStyleGet();
- for( ; htiWalk != NULL; htiWalk = GetNextItem( htiWalk, TVGN_PARENT ) )
- {
- if( dc.RectVisible( &rcLines ) )
- {
- e_line_type_t eOT = line_empty;
- if( GetNextItem( htiWalk, TVGN_NEXT ) == NULL )
- {
- if( htiWalk == hti )
- eOT = line_corner;
- }
- else
- {
- if( htiWalk == hti )
- eOT = line_branch;
- else
- eOT = line_beam;
- }
- CPoint pointCenter = rcLines.CenterPoint();
- CPoint pointTop( pointCenter.x, rcLines.top );
- CPoint pointBottom( pointCenter.x, rcLines.bottom );
- CPoint pointRight( rcLines.right, pointCenter.y );
- if( eOT != line_empty )
- { // top ray
- switch( eOS )
- {
- case line_style_solid:
- dc.MoveTo( pointCenter );
- dc.LineTo( pointTop );
- break;
- case line_style_dots:
- {
- for( int y = pointTop.y; y <= pointCenter.y; y++ )
- {
- if( ( y & 1 ) == 0 )
- dc.SetPixel( pointCenter.x, y, clrLines );
- }
- }
- break;
- }
- }
- if( eOT == line_branch || eOT == line_beam )
- { // bottom ray
- switch( eOS )
- {
- case line_style_solid:
- dc.MoveTo( pointCenter );
- dc.LineTo( pointBottom );
- break;
- case line_style_dots:
- {
- for( int y = pointCenter.y; y <= pointBottom.y; y++ )
- {
- if( ( y & 1 ) == 0 )
- dc.SetPixel( pointCenter.x, y, clrLines );
- }
- }
- break;
- }
- }
- if( eOT == line_branch || eOT == line_corner )
- { // right ray
- switch( eOS )
- {
- case line_style_solid:
- dc.MoveTo( pointCenter );
- dc.LineTo( pointRight );
- break;
- case line_style_dots:
- {
- for( int x = pointCenter.x; x <= pointRight.x; x++ )
- {
- if( ( ( ( pointCenter.y & 1 ) != 0 ) && ( x & 1 ) == 0 )
- || ( ( ( pointCenter.y & 1 ) == 0 ) && ( x & 1 ) != 0 )
- )
- dc.SetPixel( x, pointCenter.y, clrLines );
- }
- }
- break;
- }
- }
- }
- rcLines.OffsetRect( - nLevelIndent, 0 );
- }
- dc.SelectObject( pOldPen );
- }
- }
- void CExtTreeCtrl::OnPaintTreeItemExpandCollapseButton(
- HTREEITEM hti,
- CDC & dc,
- CRect rcTreeBoxArea,
- COLORREF clrForceBoxLines,
- COLORREF clrForceBoxBackground,
- COLORREF clrForceBoxBk
- )
- {
- ASSERT_VALID( this );
- ASSERT( hti != NULL );
- ASSERT( dc.GetSafeHdc() != NULL );
- bool bHasButtons = ( ( GetStyle() & TVS_HASBUTTONS ) != 0 ) ? true : false;
- if( ! bHasButtons )
- return;
- if( ! dc.RectVisible( &rcTreeBoxArea ) )
- return;
- bool bHoveredState = false;
- if( hti == m_htiHover
- && ( TreeGetStyleEx() & __EXT_TREE_EX_HOVER_TREE_BOXES ) != 0
- && ( m_dwLastHoverHitTestFlags & __EXT_TVHT_ONITEMBUTTON ) != 0
- )
- bHoveredState = true;
- e_tree_box_style_t eTBS = TreeBoxStyleGet();
- CPoint ptTreeBoxCenter = rcTreeBoxArea.CenterPoint();
- CRect rcTreeBox(
- ptTreeBoxCenter.x, ptTreeBoxCenter.y,
- ptTreeBoxCenter.x + 1, ptTreeBoxCenter.y + 1
- );
- rcTreeBox.InflateRect( 4, 4 );
- if( eTBS == tree_box_style_bitmap )
- {
- if( ! ItemHasChildren( hti ) )
- return;
- COLORREF clrBoxBk = clrForceBoxBk;
- if( clrBoxBk == COLORREF(-1L) )
- clrBoxBk = TreeBkColorGet();
- if( clrBoxBk == COLORREF(-1L) )
- clrBoxBk = ::GetSysColor( COLOR_WINDOW );
- CBrush _brush( clrBoxBk );
- CBrush * pOldBrush = dc.SelectObject( &_brush );
- CPen * pOldPen = dc.SelectObject( CPen::FromHandle( HPEN( ::GetStockObject( NULL_PEN ) ) ) );
- CRect rcEraseUnderBmp = rcTreeBox;
- rcEraseUnderBmp.InflateRect( 2, 2 );
- dc.Ellipse( &rcEraseUnderBmp );
- dc.SelectObject( pOldPen );
- dc.SelectObject( pOldBrush );
- if( ! TreeItemIsExpanded( hti ) )
- {
- if( bHoveredState )
- m_bmpTreeBoxCollapsedHover.AlphaBlend( dc, rcTreeBox );
- else
- m_bmpTreeBoxCollapsed.AlphaBlend( dc, rcTreeBox );
- }
- else
- {
- if( bHoveredState )
- m_bmpTreeBoxExpandedHover.AlphaBlend( dc, rcTreeBox );
- else
- m_bmpTreeBoxExpanded.AlphaBlend( dc, rcTreeBox );
- }
- return;
- } // if( eTBS == tree_box_style_bitmap )
- COLORREF clrSign = clrForceBoxLines;
- if( clrSign == COLORREF(-1L) )
- clrSign = ExpandCollapseButtonSignColorGet();
- COLORREF clrFill = clrForceBoxBackground;
- if( clrFill == COLORREF(-1L) )
- clrFill = ExpandCollapseButtonFillColorGet();
- if( bHoveredState )
- clrFill = ::GetSysColor( COLOR_3DFACE );
- COLORREF clrBoxBorder = clrForceBoxLines;
- if( clrBoxBorder == COLORREF(-1L) )
- clrBoxBorder = LineColorGet();
- if( clrSign == COLORREF(-1L) )
- clrSign = RGB(0,0,0);
- if( clrFill == COLORREF(-1L) )
- clrFill = RGB(255,255,255);
- if( clrBoxBorder == COLORREF(-1L) )
- clrBoxBorder = RGB(0,0,0);
- CPen penSign( PS_SOLID, 1, clrSign );
- CPen penBorder( PS_SOLID, 1, clrBoxBorder );
- CPen * pOldPen = dc.SelectObject( &penBorder );
- CBrush brushFill (clrFill);
- CBrush * pOldBrush = dc.SelectObject( &brushFill );
- if( ItemHasChildren( hti ) )
- {
- switch(eTBS)
- {
- case tree_box_style_square:
- dc.Rectangle( &rcTreeBox );
- break;
- case tree_box_style_round:
- dc.Ellipse( &rcTreeBox );
- break;
- } // switch(eTBS)
- dc.SelectObject( &penSign );
- dc.MoveTo( rcTreeBox.left + 2, ptTreeBoxCenter.y );
- dc.LineTo( rcTreeBox.right - 2, ptTreeBoxCenter.y );
- if( ! TreeItemIsExpanded( hti ) )
- {
- dc.MoveTo( ptTreeBoxCenter.x, rcTreeBox.top + 2 );
- dc.LineTo( ptTreeBoxCenter.x, rcTreeBox.bottom - 2 );
- }
- } // if( ItemHasChildren( hti ) )
- dc.SelectObject( pOldPen );
- dc.SelectObject( pOldBrush );
- }
- void CExtTreeCtrl::OnPaintTreeItemBackground(
- HTREEITEM hti,
- CDC & dc,
- CRect rcItemLabel,
- bool bFocusedWindow,
- bool bDisabledItem,
- bool bSelectedItem,
- bool bFocusedItem,
- bool bDH,
- COLORREF clrItemBk
- )
- {
- ASSERT_VALID( this );
- ASSERT( hti != NULL );
- ASSERT( dc.GetSafeHdc() != NULL );
- hti;
- bFocusedWindow;
- bDisabledItem;
- bSelectedItem;
- bFocusedItem;
- bDH;
- if( ! dc.RectVisible( &rcItemLabel ) )
- return;
- if( clrItemBk != COLORREF(-1L) )
- dc.FillSolidRect( &rcItemLabel, clrItemBk );
- }
- void CExtTreeCtrl::OnPaintTreeItemText(
- HTREEITEM hti,
- CDC & dc,
- CRect rcItemLabel,
- COLORREF clrItemText
- )
- {
- ASSERT_VALID( this );
- ASSERT( hti != NULL );
- ASSERT( dc.GetSafeHdc() != NULL );
- if( ! dc.RectVisible( &rcItemLabel ) )
- return;
- CExtSafeString strItemText = GetItemText( hti );
- if( strItemText.IsEmpty() )
- return;
- if( clrItemText != COLORREF(-1L) )
- dc.SetTextColor( clrItemText );
- CRect rcText = rcItemLabel;
- rcText.DeflateRect( PaddingLabelLeftGet(), 0, PaddingLabelRightGet(), 0 ); // INNER L/R MARGINS
- CFont * pFont = NULL;
- pFont = dc.SelectObject( OnQueryItemFont( hti ) );
- dc.DrawText( LPCTSTR(strItemText), strItemText.GetLength(), rcText, DT_SINGLELINE | DT_LEFT | DT_VCENTER );
- dc.SelectObject( pFont );
- }
- void CExtTreeCtrl::OnPaintTreeItemInsertMark(
- HTREEITEM hti,
- CDC & dc,
- bool bInsertMarkAfter,
- COLORREF clrInsertMark,
- CRect rcItemEntire,
- CRect rcItemLabel
- )
- {
- ASSERT_VALID( this );
- ASSERT( hti != NULL );
- ASSERT( dc.GetSafeHdc() != NULL );
- hti;
- if( ! dc.RectVisible( &rcItemLabel ) )
- return;
- LONG nVerticalLocation = bInsertMarkAfter ? rcItemEntire.bottom : rcItemEntire.top;
- CRect rcInsertMark( rcItemLabel.left, nVerticalLocation, rcItemEntire.right, nVerticalLocation );
- if( bInsertMarkAfter )
- rcInsertMark.top -= 2;
- else
- rcInsertMark.bottom += 2;
- CBrush brush( clrInsertMark );
- dc.FillRect( &rcInsertMark, &brush );
- CRect rcV1( rcInsertMark ), rcV2( rcInsertMark );
- rcV1.right = rcV1.left + 1;
- rcV2.left = rcV2.right - 1;
- rcV1.InflateRect( 0, 3 );
- rcV2.InflateRect( 0, 3 );
- dc.FillRect( &rcV1, &brush );
- dc.FillRect( &rcV2, &brush );
- rcV1.DeflateRect( 0, 1 );
- rcV2.DeflateRect( 0, 1 );
- rcV1.OffsetRect( 1, 0 );
- rcV2.OffsetRect( -1, 0 );
- dc.FillRect( &rcV1, &brush );
- dc.FillRect( &rcV2, &brush );
- rcV1.DeflateRect( 0, 1 );
- rcV2.DeflateRect( 0, 1 );
- rcV1.OffsetRect( 1, 0 );
- rcV2.OffsetRect( -1, 0 );
- dc.FillRect( &rcV1, &brush );
- dc.FillRect( &rcV2, &brush );
- }
- CFont * CExtTreeCtrl::OnQueryItemFont( HTREEITEM hti )
- {
- ASSERT_VALID( this );
- ASSERT( hti != NULL );
- bool bHoverDisabledItems = ( ( TreeGetStyle() & __EXT_TREE_HOVER_DISABLE_ITEMS ) != 0 ) ? true : false;
- TREEITEMINFO_t & _TII = TreeItemInfoGet( hti );
- CFont * pFont = NULL;
- bool bBold = _TII.m_bBold;
- bool bItalic = _TII.m_bItalic;
- bool bUnderline = _TII.m_bUnderline;
- bool bItemIsEnabled = OnQueryItemEnabledState( hti );
- if( hti == m_htiHover
- && ( bItemIsEnabled || ( bHoverDisabledItems && (! bItemIsEnabled ) ) )
- && ( GetStyle() & TVS_TRACKSELECT ) != 0
- && ( ( m_dwLastHoverHitTestFlags & __EXT_TVHT_ONITEMLABEL ) != 0
- || ( GetStyle() & TVS_FULLROWSELECT ) != 0
- )
- )
- bUnderline = (!bUnderline);
- if( bBold && (!bItalic) )
- return bUnderline ? (&m_fontBoldUnderline) : (&m_fontBold);
- else if( (!bBold) && bItalic )
- return bUnderline ? (&m_fontItalicUnderline) : (&m_fontItalic);
- else if( bBold && bItalic )
- return bUnderline ? (&m_fontBoldItalicUnderline) : (&m_fontBoldItalic);
- else if( (!bBold) && (!bItalic) && bUnderline )
- return (&m_fontNormalUnderline);
- return pFont;
- }
- void CExtTreeCtrl::OnPaintTreeItemCheckBox(
- HTREEITEM hti,
- CDC & dc,
- CRect rcTreeCheckBoxArea
- )
- {
- ASSERT_VALID( this );
- ASSERT( hti != NULL );
- ASSERT( dc.GetSafeHdc() != NULL );
- if( ! dc.RectVisible( &rcTreeCheckBoxArea ) )
- return;
- bool bHoveredState = false;
- if( hti == m_htiHover
- && ( TreeGetStyleEx() & __EXT_TREE_EX_HOVER_CHECK_BOXES ) != 0
- && ( m_dwLastHoverHitTestFlags & __EXT_TVHT_ONCHECKBOX) != 0
- )
- bHoveredState = true;
- TREEITEMINFO_t & _TII = TreeItemInfoGet( hti );
- CExtPaintManager::eBoxState_t eBS = CExtPaintManager::BOX_UNCHECKED;
- bool bItemEnabled = OnQueryItemEnabledState( hti );
- if( ! bItemEnabled )
- {
- if( _TII.m_nCheckBoxState == 1 )
- eBS = CExtPaintManager::BOX_DISABLED_CHECKED;
- else if( _TII.m_nCheckBoxState == 2 )
- eBS = CExtPaintManager::BOX_DISABLED_INDETERMINATE;
- else
- eBS = CExtPaintManager::BOX_DISABLED_UNCHECKED;
- }
- else
- {
- if( _TII.m_nCheckBoxState == 1 )
- eBS = bHoveredState ? CExtPaintManager::BOX_MOUSE_HOVER_CHECKED : CExtPaintManager::BOX_CHECKED;
- else if( _TII.m_nCheckBoxState == 2 )
- eBS = bHoveredState ? CExtPaintManager::BOX_MOUSE_HOVER_INDETERMINATE : CExtPaintManager::BOX_INDETERMINATE;
- else if( bHoveredState )
- eBS = CExtPaintManager::BOX_MOUSE_HOVER_UNCHECKED;
- }
- CExtPaintManager::PAINTCHECKRADIOBUTTONDATA _pcrbd(
- this,
- eBS,
- true,
- false,
- rcTreeCheckBoxArea,
- _T(""),
- false,
- false,
- bItemEnabled,
- false,
- 0,
- NULL,
- true
- );
- g_PaintManager->PaintCheckButton( dc, _pcrbd );
- }
- void CExtTreeCtrl::OnPaintTreeItemRadioBox(
- HTREEITEM hti,
- CDC & dc,
- CRect rcTreeRadioBoxArea
- )
- {
- ASSERT_VALID( this );
- ASSERT( hti != NULL );
- ASSERT( dc.GetSafeHdc() != NULL );
- if( ! dc.RectVisible( &rcTreeRadioBoxArea ) )
- return;
- bool bHoveredState = false;
- if( hti == m_htiHover
- && ( TreeGetStyleEx() & __EXT_TREE_EX_HOVER_RADIO_BUTTONS ) != 0
- && ( m_dwLastHoverHitTestFlags & __EXT_TVHT_ONCHECKBOX) != 0
- )
- bHoveredState = true;
- TREEITEMINFO_t & _TII = TreeItemInfoGet( hti );
- CExtPaintManager::eBoxState_t eBS = CExtPaintManager::BOX_UNCHECKED;
- bool bItemEnabled = OnQueryItemEnabledState( hti );
- if( ! bItemEnabled )
- {
- if( _TII.m_nCheckBoxState == 1 )
- eBS = CExtPaintManager::BOX_DISABLED_CHECKED;
- else if( _TII.m_nCheckBoxState == 2 )
- eBS = CExtPaintManager::BOX_DISABLED_INDETERMINATE;
- else
- eBS = CExtPaintManager::BOX_DISABLED_UNCHECKED;
- }
- else
- {
- if( _TII.m_nCheckBoxState == 1 )
- eBS = bHoveredState ? CExtPaintManager::BOX_MOUSE_HOVER_CHECKED : CExtPaintManager::BOX_CHECKED;
- else if( _TII.m_nCheckBoxState == 2 )
- eBS = bHoveredState ? CExtPaintManager::BOX_MOUSE_HOVER_INDETERMINATE : CExtPaintManager::BOX_INDETERMINATE;
- else if( bHoveredState )
- eBS = CExtPaintManager::BOX_MOUSE_HOVER_UNCHECKED;
- }
- CExtPaintManager::PAINTCHECKRADIOBUTTONDATA _pcrbd(
- this,
- eBS,
- true,
- false,
- rcTreeRadioBoxArea,
- _T(""),
- false,
- false,
- bItemEnabled,
- false,
- 0,
- NULL,
- true
- );
- g_PaintManager->PaintRadioButton( dc, _pcrbd );
- }
- void CExtTreeCtrl::OnPaintTreeItemIcon(
- HTREEITEM hti,
- CDC & dc,
- const CExtCmdIcon & _icon,
- CRect rcTreeIconArea,
- BYTE nSCA // = BYTE(255)
- )
- {
- ASSERT_VALID( this );
- ASSERT( hti != NULL );
- ASSERT( dc.GetSafeHdc() != NULL );
- ASSERT( ! _icon.IsEmpty() );
- CExtCmdIcon::e_paint_type_t ePT = IsItemEnabled( hti ) ? CExtCmdIcon::__PAINT_NORMAL : CExtCmdIcon::__PAINT_DISABLED;
- _icon.Paint( g_PaintManager.GetPM(), dc.m_hDC, rcTreeIconArea, ePT, nSCA );
- }
- void CExtTreeCtrl::OnPaintTreeItemControl(
- HTREEITEM hti,
- CDC & dc,
- CRect rcTreeControlArea,
- COLORREF clrControlText
- )
- {
- ASSERT_VALID( this );
- ASSERT( hti != NULL );
- ASSERT( dc.GetSafeHdc() != NULL );
- if( ! dc.RectVisible( &rcTreeControlArea ) )
- return;
- TREEITEMINFO_t & _TII = TreeItemInfoGet( hti );
- e_item_control_type_t eICT = _TII.m_eICT;
- switch( eICT )
- {
- case __EICT_PROGRESS_BAR_THEMED:
- case __EICT_PROGRESS_BAR_WITH_BOXES:
- case __EICT_PROGRESS_BAR_SMOOTH:
- case __EICT_PROGRESS_BAR_ENDLESS:
- {
- if( eICT == __EICT_PROGRESS_BAR_THEMED )
- {
- CExtPaintManager::PAINTPROGRESSDATA _ppd(
- _TII.m_nProgressPos - _TII.m_nProgressMin,
- _TII.m_nProgressMax - _TII.m_nProgressMin,
- rcTreeControlArea,
- true,
- false,
- true,
- this
- );
- if( g_PaintManager->PaintProgress( dc, _ppd ) )
- return;
- eICT = __EICT_PROGRESS_BAR_SMOOTH;
- }
- COLORREF clrProgressBorderColor = ProgressBorderColorGet();
- if( clrProgressBorderColor == COLORREF(-1L) )
- clrProgressBorderColor = ::GetSysColor( COLOR_3DDKSHADOW );
- COLORREF clrProgressBackgroundColor = ProgressBackgroundColorGet();
- if( clrProgressBackgroundColor == COLORREF(-1L) )
- clrProgressBackgroundColor = ::GetSysColor( COLOR_HIGHLIGHTTEXT );
- COLORREF clrProgressBoxColor = ProgressBoxColorGet();
- if( clrProgressBoxColor == COLORREF(-1L) )
- clrProgressBoxColor = ::GetSysColor( COLOR_HIGHLIGHT );
- CRect rcBar = rcTreeControlArea;
- rcBar.DeflateRect( 0, 1, 0, 2 );
- CSize _sizeMargins( 2, 2 );
- CRect rcProgress = rcBar;
- rcProgress.DeflateRect( _sizeMargins );
-
- INT nBoxWidth = ::MulDiv( rcProgress.Height(), 3, 5 ), nDistanceBetweenBoxes = 2, nX;
- if( nBoxWidth <= 0 )
- nBoxWidth = 2;
- INT nBoxCount = ( rcProgress.Width() + nDistanceBetweenBoxes ) / ( nBoxWidth + nDistanceBetweenBoxes );
- if( eICT == __EICT_PROGRESS_BAR_WITH_BOXES )
- {
- rcProgress.right = rcProgress.left + nBoxCount * ( nBoxWidth + nDistanceBetweenBoxes ) - nDistanceBetweenBoxes;
- rcBar.right = rcBar.left + rcProgress.Width() + _sizeMargins.cx * 2;
- }
- dc.FillSolidRect( &rcBar, clrProgressBackgroundColor );
- CBrush * pOldBrush = dc.SelectObject( CBrush::FromHandle( (HBRUSH)::GetStockObject( HOLLOW_BRUSH ) ) );
- CPen _penBorder( PS_SOLID, 1, clrProgressBorderColor );
- CPen * pOldPen = dc.SelectObject( &_penBorder );
- dc.Rectangle( &rcBar );
- dc.SelectObject( pOldPen );
- dc.SelectObject( pOldBrush );
- if( _TII.m_nProgressMax <= _TII.m_nProgressMin
- || _TII.m_nProgressPos < _TII.m_nProgressMin
- || _TII.m_nProgressPos > _TII.m_nProgressMax
- )
- return;
-
- if( eICT == __EICT_PROGRESS_BAR_ENDLESS )
- {
- INT nBoxIndex, nBoxesDisplayed = ::MulDiv( nBoxCount, 1, 3 );
- if( nBoxesDisplayed <= 0 )
- nBoxesDisplayed = 1;
- CRect rcEndlessArea(
- rcProgress.left,
- rcProgress.top,
- rcProgress.left + nBoxesDisplayed * ( nBoxWidth + nDistanceBetweenBoxes ) - nDistanceBetweenBoxes,
- rcProgress.bottom
- );
- rcEndlessArea.OffsetRect(
- ::MulDiv(
- rcProgress.Width() - rcEndlessArea.Width(),
- _TII.m_nProgressPos - _TII.m_nProgressMin,
- _TII.m_nProgressMax - _TII.m_nProgressMin
- ),
- 0
- );
- if( dc.RectVisible( &rcEndlessArea ) )
- {
- CBrush _brushProgressArea( clrProgressBoxColor );
- CRect rcBox(
- rcEndlessArea.left,
- rcEndlessArea.top,
- rcEndlessArea.left + nBoxWidth,
- rcEndlessArea.bottom
- );
- for( nBoxIndex = 0; nBoxIndex < nBoxesDisplayed; nBoxIndex ++ )
- {
- dc.FillRect( &rcBox, &_brushProgressArea );
- rcBox.OffsetRect( nBoxWidth + nDistanceBetweenBoxes, 0 );
- }
- }
- }
- else
- {
- rcProgress.right = rcProgress.left
- + ::MulDiv(
- rcProgress.Width(),
- _TII.m_nProgressPos - _TII.m_nProgressMin,
- _TII.m_nProgressMax - _TII.m_nProgressMin
- );
- if( dc.RectVisible( &rcProgress ) )
- {
- CBrush _brushProgressArea( clrProgressBoxColor );
- if( eICT == __EICT_PROGRESS_BAR_SMOOTH )
- dc.FillRect( &rcProgress, &_brushProgressArea );
- else if( eICT == __EICT_PROGRESS_BAR_WITH_BOXES )
- {
- CRect rcBox(
- rcProgress.left,
- rcProgress.top,
- rcProgress.left + nBoxWidth,
- rcProgress.bottom
- );
- for( nX = rcProgress.left;
- nX < rcProgress.right;
- nX += nBoxWidth + nDistanceBetweenBoxes,
- rcBox.OffsetRect( nBoxWidth + nDistanceBetweenBoxes, 0 )
- )
- dc.FillRect( &rcBox, &_brushProgressArea );
- }
- }
- }
- }
- break;
- default:
- {
- CExtSafeString strEditText = GetItemText( hti );
- if( strEditText.IsEmpty() )
- return;
- CFont * pFont = dc.SelectObject( &m_fontNormal );
- COLORREF clrTextOld = COLORREF(-1L);
- if( clrControlText != COLORREF(-1L) )
- clrTextOld = dc.SetTextColor( clrControlText );
- dc.DrawText( LPCTSTR(_TII.m_strEditText), _TII.m_strEditText.GetLength(), rcTreeControlArea, DT_SINGLELINE | DT_LEFT | DT_VCENTER );
- if( clrControlText != COLORREF(-1L) )
- dc.SetTextColor( clrTextOld );
- dc.SelectObject( pFont );
- }
- break;
- } // switch( eICT )
- }
- LRESULT CExtTreeCtrl::WindowProc( UINT message, WPARAM wParam, LPARAM lParam )
- {
- switch( message )
- {
- case TVM_EDITLABEL:
- {
- KillTimer( m_nDelayedEditingTimerID );
- m_wndContentExpand.Deactivate();
- HTREEITEM hti = (HTREEITEM)lParam; //GetFocusedItem();
- if( hti == NULL
- || (! HasItem( hti ) )
- )
- return LRESULT(NULL);
- SendMessage( WM_CANCELMODE );
- EnsureVisible( hti );
- HWND hWndParent = ::GetParent( m_hWnd );
- UINT nOwnID = GetDlgCtrlID();
- CExtSafeString strItemText;
- TV_DISPINFO _data;
- ::memset( &_data, 0, sizeof(TV_DISPINFO) );
- _data.hdr.hwndFrom = m_hWnd;
- _data.hdr.idFrom = nOwnID;
- _data.hdr.code = TVN_BEGINLABELEDIT;
- _data.item.mask = TVIF_CHILDREN|TVIF_HANDLE|TVIF_PARAM|TVIF_STATE;
- _data.item.hItem = hti;
- GetItem( &_data.item );
- strItemText = GetItemText( hti );
- _data.item.cchTextMax = INT(strItemText.GetLength());
- _data.item.pszText = strItemText.IsEmpty() ? _T("") : LPTSTR(LPCTSTR(strItemText));
- _data.item.mask |= TVIF_TEXT;
- if( ::SendMessage( hWndParent, WM_NOTIFY, WPARAM(nOwnID), LPARAM(&_data) ) != 0 )
- return TRUE;
- CRect rcLabel;
- if( ! TreeItemRectGet( hti, rcLabel, e_tirt_label ) )
- return LRESULT(NULL);
- rcLabel.right += 6;
- CExtSafeString s;
- const TREEITEMINFO_t & _TII = TreeItemInfoGet( hti );
- CInplaceEdit * pEdit = new CInplaceEdit( true );
- if( ! pEdit->Create(
- WS_CHILD | WS_VISIBLE
- | WS_CLIPSIBLINGS | ES_AUTOHSCROLL | ES_WANTRETURN
- | ( ReadOnlyLabelsGet() ? ES_READONLY : 0 )
- | _TII.m_dwAdditionalLabelEditorStyles
- ,
- rcLabel,
- this,
- UINT(IDC_STATIC)
- )
- )
- return LRESULT(NULL);
- CFont * pFont = NULL;
- pFont = OnQueryItemFont( hti );
- if( pFont == NULL )
- pFont = GetFont();
- pEdit->SetFont( pFont );
- s = GetItemText( hti );
- pEdit->SetWindowText( s );
- pEdit->SetSel(0, -1);
- pEdit->SetFocus();
- m_hWndChildControl = pEdit->m_hWnd;
- if( m_hWndChildControl != NULL )
- m_htiInplaceEdited = hti;
- }
- // continue falling:
- case TVM_GETEDITCONTROL:
- return LRESULT(m_hWndChildControl);
- case WM_NCLBUTTONDOWN:
- case WM_NCMBUTTONDOWN:
- case WM_NCRBUTTONDOWN:
- SendMessage( WM_CANCELMODE );
- if( ::GetFocus() != m_hWnd )
- SetFocus();
- break;
- case TVM_SETINSERTMARK:
- {
- m_bInsertMarkAfter = ( wParam != 0 ) ? true : false;
- HTREEITEM htiInsertMarkOld = m_htiInsertMark;
- m_htiInsertMark = (HTREEITEM) lParam;
- if( ! HasItem( m_htiInsertMark ) )
- m_htiInsertMark = NULL;
- if( htiInsertMarkOld != m_htiInsertMark && IsWindowVisible() )
- Invalidate();
- }
- break;
- case TVM_SETINSERTMARKCOLOR:
- if( IsWindowVisible() )
- Invalidate();
- break;
- } // switch( message )
- LRESULT lResult = CTreeCtrl::WindowProc( message, wParam, lParam );
- switch( message )
- {
- case WM_COMMAND:
- m_wndContentExpand.Deactivate();
- if( HIWORD(wParam) == CBN_KILLFOCUS
- && m_hWndChildControl == ((HWND)lParam)
- )
- {
- SendMessage( WM_CANCELMODE );
- }
- break;
- case TVM_INSERTITEM:
- {
- m_wndContentExpand.Deactivate();
- if( m_hWndChildControl != NULL )
- SendMessage( WM_CANCELMODE );
- HTREEITEM hti = (HTREEITEM)lResult;
- if( hti != NULL )
- m_mapItemInfo.SetAt( hti, new TREEITEMINFO_t );
- }
- break;
- case TVM_DELETEITEM:
- {
- HTREEITEM hti = (HTREEITEM)lParam;
- if( m_htiDelayedFocus == hti )
- {
- m_htiDelayedFocus = NULL;
- KillTimer( m_nDelayedFocusTimerID );
- KillTimer( m_nDelayedEditingTimerID );
- }
- m_wndContentExpand.Deactivate();
- if( m_hWndChildControl != NULL )
- SendMessage( WM_CANCELMODE );
- _UnregisterItemsFromMap( hti );
- #ifdef _DEBUG
- if( hti == NULL || hti == TVI_ROOT )
- {
- ASSERT( m_mapItemInfo.GetCount() == 0 );
- }
- #endif // _DEBUG
- }
- break;
- case TVM_EXPAND:
- m_wndContentExpand.Deactivate();
- break;
- } // switch( message )
- return lResult;
- }
- void CExtTreeCtrl::PostNcDestroy()
- {
- ::memset( &m_nLastMouseButtonEventType, 0, sizeof(m_nLastMouseButtonEventType) );
- _UnregisterItemsFromMap();
- _FontsDestroy();
- m_htiInsertMark = m_htiAnchorItem = NULL;
- CTreeCtrl::PostNcDestroy();
- }
- void CExtTreeCtrl::OnTreeItemUnRegisterData(
- TREEITEMINFO_t & _TII
- )
- {
- ASSERT_VALID( this );
- _TII;
- }
- void CExtTreeCtrl::_UnregisterItemsFromMap(
- HTREEITEM hti // = NULL
- )
- {
- if( hti == NULL || hti == TVI_ROOT )
- {
- if( GetSafeHwnd() == NULL )
- {
- _UnregisterItemsFromMapLinear();
- return;
- } // if( GetSafeHwnd() == NULL )
- else
- {
- hti = GetRootItem();
- if( hti != NULL )
- _UnregisterOneItemFromMap( hti );
- else
- {
- _UnregisterItemsFromMapLinear();
- return;
- }
- } // else from if( GetSafeHwnd() == NULL )
- } // if( hti == NULL || hti == TVI_ROOT )
- else
- _UnregisterOneItemFromMap( hti );
- if( GetSafeHwnd() != NULL )
- {
- HTREEITEM htiChild = GetNextItem( hti, TVGN_CHILD );
- for( ; htiChild != NULL; htiChild = GetNextItem( htiChild, TVGN_NEXT ) )
- _UnregisterItemsFromMap( htiChild );
- } // if( GetSafeHwnd() != NULL )
- }
- void CExtTreeCtrl::_UnregisterItemsFromMapLinear()
- {
- ASSERT_VALID( this );
- POSITION pos = m_mapItemInfo.GetStartPosition();
- for( ; pos != NULL; pos = m_mapItemInfo.GetStartPosition() )
- {
- HTREEITEM hti = NULL;
- TREEITEMINFO_t * pTII = NULL;
- m_mapItemInfo.GetNextAssoc( pos, hti, pTII );
- ASSERT( hti != NULL );
- _UnregisterOneItemFromMap( hti );
- }
- ASSERT( m_mapItemInfo.GetCount() == 0 );
- }
- void CExtTreeCtrl::_UnregisterOneItemFromMap(
- HTREEITEM hti
- )
- {
- ASSERT_VALID( this );
- ASSERT( hti != NULL );
- TREEITEMINFO_t * pTII = NULL;
- if( m_mapItemInfo.Lookup( hti, pTII ) )
- {
- if( pTII != NULL )
- {
- OnTreeItemUnRegisterData( *pTII );
- delete pTII;
- } // if( pTII != NULL )
- m_mapItemInfo.RemoveKey( hti );
- } // if( m_mapItemInfo.Lookup( hti, pTII ) )
- if( hti == m_htiAnchorItem )
- m_htiAnchorItem = NULL;
- if( hti == m_htiInsertMark )
- m_htiInsertMark = NULL;
- }
- BOOL CExtTreeCtrl::Expand( HTREEITEM hti, UINT nCode )
- {
- ASSERT_VALID( this );
- HWND hWndOwn = m_hWnd;
- if( hWndOwn == NULL || ( ! ::IsWindow( hWndOwn ) ) )
- return FALSE;
- if( hti == TVI_ROOT )
- {
- hti = GetRootItem();
- if( hti == NULL )
- return FALSE;
- }
- HWND hWndParent = ::GetParent( m_hWnd );
- UINT nOwnID = GetDlgCtrlID();
- CExtSafeString strItemText;
- NM_TREEVIEW _data;
- ::memset( &_data, 0, sizeof(NM_TREEVIEW) );
- _data.hdr.hwndFrom = m_hWnd;
- _data.hdr.idFrom = nOwnID;
- _data.hdr.code = TVN_ITEMEXPANDING;
- _data.action = nCode;
- _data.itemOld.mask = TVIF_CHILDREN|TVIF_HANDLE|TVIF_PARAM|TVIF_STATE;
- _data.itemOld.hItem = hti;
- GetItem( &_data.itemOld );
- strItemText = GetItemText( hti );
- _data.itemOld.cchTextMax = INT(strItemText.GetLength());
- _data.itemOld.pszText = strItemText.IsEmpty() ? _T("") : LPTSTR(LPCTSTR(strItemText));
- _data.itemOld.mask |= TVIF_TEXT;
- ::memcpy( &_data.itemNew, &_data.itemOld, sizeof(TVITEM) );
- if( ! ::GetCursorPos( &_data.ptDrag ) )
- _data.ptDrag.x = _data.ptDrag.y = 0;
- if( ::SendMessage( hWndParent, WM_NOTIFY, WPARAM(nOwnID), LPARAM(&_data) ) != 0 )
- return TRUE;
- if( ! CTreeCtrl::Expand( hti, nCode ) )
- return FALSE;
- ::memset( &_data, 0, sizeof(NM_TREEVIEW) );
- _data.hdr.hwndFrom = m_hWnd;
- _data.hdr.idFrom = nOwnID;
- _data.hdr.code = TVN_ITEMEXPANDED;
- _data.action = nCode;
- _data.itemOld.mask = TVIF_CHILDREN|TVIF_HANDLE|TVIF_PARAM|TVIF_STATE;
- _data.itemOld.hItem = hti;
- GetItem( &_data.itemOld );
- strItemText = GetItemText( hti );
- _data.itemOld.cchTextMax = INT(strItemText.GetLength());
- _data.itemOld.pszText = strItemText.IsEmpty() ? _T("") : LPTSTR(LPCTSTR(strItemText));
- _data.itemOld.mask |= TVIF_TEXT;
- ::memcpy( &_data.itemNew, &_data.itemOld, sizeof(TVITEM) );
- if( ! ::GetCursorPos( &_data.ptDrag ) )
- _data.ptDrag.x = _data.ptDrag.y = 0;
- ::SendMessage( hWndParent, WM_NOTIFY, WPARAM(nOwnID), LPARAM(&_data) );
- return TRUE;
- }
- bool CExtTreeCtrl::TreeItemIsExpanded( HTREEITEM hti ) const
- {
- ASSERT_VALID( this );
- bool bExpanded = ( ( GetItemState( hti, UINT(-1) ) & TVIS_EXPANDED ) != 0 ) ? true : false;
- return bExpanded;
- }
- bool CExtTreeCtrl::HasItem( HTREEITEM hti ) const
- {
- ASSERT_VALID( this );
- if( hti == NULL )
- return false;
- TREEITEMINFO_t * pTII = NULL;
- if( ! m_mapItemInfo.Lookup( hti, pTII ) )
- return false;
- return true;
- }
- bool CExtTreeCtrl::HasAncestor(
- HTREEITEM htiParent,
- HTREEITEM htiChild,
- INT nMaxStepCount // = -1
- ) const
- {
- ASSERT_VALID( this );
- if( htiChild == NULL )
- return false;
- if( htiParent == NULL || htiParent == TVI_ROOT )
- htiParent = GetRootItem();
- if( htiParent == NULL )
- return false;
- INT nStepCount = 0;
- for( ; htiChild != NULL ; htiChild = GetNextItem(htiChild, TVGN_PARENT ), nStepCount ++ )
- {
- if( htiChild == htiParent )
- return true;
- if( nMaxStepCount >= 0 )
- {
- if( nStepCount >= nMaxStepCount )
- return false;
- }
- }
- return false;
- }
- CExtTreeCtrl::TREEITEMINFO_t * CExtTreeCtrl::TreeItemInfoGetPtr( HTREEITEM hti )
- {
- ASSERT_VALID( this );
- if( hti == NULL )
- {
- ASSERT( false );
- ::AfxThrowUserException();
- }
- TREEITEMINFO_t * pTII = NULL;
- if( ! m_mapItemInfo.Lookup( hti, pTII ) )
- return NULL;
- ASSERT( pTII != NULL );
- return pTII;
- }
- const CExtTreeCtrl::TREEITEMINFO_t * CExtTreeCtrl::TreeItemInfoGetPtr( HTREEITEM hti ) const
- {
- return ( const_cast < CExtTreeCtrl * > ( this ) ) -> TreeItemInfoGetPtr( hti );
- }
- CExtTreeCtrl::TREEITEMINFO_t & CExtTreeCtrl::TreeItemInfoGet( HTREEITEM hti )
- {
- TREEITEMINFO_t * pTII = TreeItemInfoGetPtr( hti );
- if( pTII == NULL )
- {
- ASSERT( false );
- ::AfxThrowUserException();
- }
- return (*pTII);
- }
- const CExtTreeCtrl::TREEITEMINFO_t & CExtTreeCtrl::TreeItemInfoGet( HTREEITEM hti ) const
- {
- return ( const_cast < CExtTreeCtrl * > ( this ) ) -> TreeItemInfoGet( hti );
- }
- CExtTreeCtrl::e_line_style_t CExtTreeCtrl::LineStyleGet() const
- {
- ASSERT_VALID( this );
- return m_eOS;
- }
- void CExtTreeCtrl::LineStyleSet( CExtTreeCtrl::e_line_style_t eOS )
- {
- ASSERT_VALID( this );
- m_eOS = eOS;
- }
- CExtTreeCtrl::e_tree_box_style_t CExtTreeCtrl::TreeBoxStyleGet() const
- {
- ASSERT_VALID( this );
- return m_eTBS;
- }
- void CExtTreeCtrl::TreeBoxStyleSet( CExtTreeCtrl::e_tree_box_style_t eTBS )
- {
- ASSERT_VALID( this );
- m_eTBS = eTBS;
- }
- COLORREF CExtTreeCtrl::ExpandCollapseButtonSignColorGet() const
- {
- ASSERT_VALID( this );
- return m_clrExpandCollapseButtonSign;
- }
- void CExtTreeCtrl::ExpandCollapseButtonSignColorSet( COLORREF clr )
- {
- ASSERT_VALID( this );
- m_clrExpandCollapseButtonSign = clr;
- }
- COLORREF CExtTreeCtrl::ExpandCollapseButtonFillColorGet() const
- {
- ASSERT_VALID( this );
- return m_clrExpandCollapseButtonFill;
- }
- void CExtTreeCtrl::ExpandCollapseButtonFillColorSet( COLORREF clr )
- {
- ASSERT_VALID( this );
- m_clrExpandCollapseButtonFill = clr;
- }
- COLORREF CExtTreeCtrl::LineColorGet() const
- {
- ASSERT_VALID( this );
- return m_clrLines;
- }
- void CExtTreeCtrl::LineColorSet( COLORREF clr )
- {
- ASSERT_VALID( this );
- m_clrLines = clr;
- }
- COLORREF CExtTreeCtrl::TreeBkColorGet() const
- {
- ASSERT_VALID( this );
- return m_clrTreeBkColor;
- }
- void CExtTreeCtrl::TreeBkColorSet( COLORREF clr )
- {
- ASSERT_VALID( this );
- m_clrTreeBkColor = clr;
- }
- COLORREF CExtTreeCtrl::ProgressBorderColorGet() const
- {
- ASSERT_VALID( this );
- return m_clrProgressBorder;
- }
- void CExtTreeCtrl::ProgressBorderColorSet( COLORREF clr )
- {
- ASSERT_VALID( this );
- m_clrProgressBorder = clr;
- }
- COLORREF CExtTreeCtrl::ProgressBackgroundColorGet() const
- {
- ASSERT_VALID( this );
- return m_clrProgressBackgroundColor;
- }
- void CExtTreeCtrl::ProgressBackgroundColorSet( COLORREF clr )
- {
- ASSERT_VALID( this );
- m_clrProgressBackgroundColor = clr;
- }
- COLORREF CExtTreeCtrl::ProgressBoxColorGet() const
- {
- ASSERT_VALID( this );
- return m_clrProgressBoxColor;
- }
- void CExtTreeCtrl::ProgressBoxColorSet( COLORREF clr )
- {
- ASSERT_VALID( this );
- m_clrProgressBoxColor = clr;
- }
- bool CExtTreeCtrl::OnQueryItemEnabledState( HTREEITEM hti ) const
- {
- ASSERT_VALID( this );
- if( hti == NULL )
- return false;
- if( ( TreeGetStyle() & __EXT_TREE_AUTO_DISABLE_ITEMS_BY_PARENT ) == 0 )
- return IsItemEnabled( hti );
- HTREEITEM htiWalk = hti;
- for( ; htiWalk != NULL; htiWalk = GetNextItem( htiWalk, TVGN_PARENT ) )
- {
- if( ! IsItemEnabled( htiWalk ) )
- return false;
- }
- return true;
- }
- bool CExtTreeCtrl::IsItemEnabled( HTREEITEM hti ) const
- {
- ASSERT_VALID( this );
- if( hti == NULL )
- return false;
- return ( ! TreeItemInfoGet( hti ).m_bDisabled );
- }
- void CExtTreeCtrl::EnableItem(
- HTREEITEM hti,
- bool bEnable // = true
- )
- {
- ASSERT_VALID( this );
- if( hti == NULL )
- return;
- TREEITEMINFO_t & _TII = TreeItemInfoGet( hti );
- if( ( _TII.m_bDisabled && (!bEnable) ) || ( (!_TII.m_bDisabled) && bEnable ) )
- return;
- _TII.m_bDisabled = ! bEnable;
- if( GetSafeHwnd() == NULL )
- return;
- CRect rcItemEntire;
- TreeItemRectGet( hti, rcItemEntire, e_tirt_entire );
- if( rcItemEntire.IsRectEmpty() )
- return;
- CRect rcClient;
- GetClientRect( &rcClient );
- if( ( rcClient.top <= rcItemEntire.top && rcItemEntire.top <= rcClient.bottom )
- || ( rcClient.top <= rcItemEntire.bottom && rcItemEntire.bottom <= rcClient.bottom )
- )
- InvalidateRect( &rcItemEntire );
- }
- bool CExtTreeCtrl::IsItemSelected( HTREEITEM hti ) const
- {
- ASSERT_VALID( this );
- if( hti == NULL )
- return false;
- return TreeItemInfoGet( hti ).m_bSelected;
- }
- void CExtTreeCtrl::SelectItem(
- HTREEITEM hti,
- bool bSelect, // = true
- bool bSubtract // = false
- )
- {
- ASSERT_VALID( this );
- if( hti == NULL )
- return;
- HWND hWndOwn = GetSafeHwnd();
- TREEITEMINFO_t & _TII = TreeItemInfoGet( hti );
- bool bWasSelected = _TII.m_bSelected;
- if( bSelect && bSubtract && _TII.m_bSelected )
- _TII.m_bSelected = false;
- else
- _TII.m_bSelected = bSelect;
- CList < HTREEITEM, HTREEITEM > _listInvalidateItems;
- if( _TII.m_bSelected && (! MultipleSelectionGet() ) )
- {
- CList < HTREEITEM, HTREEITEM > _listSelectedItems;
- GetSelectedItemsList( _listSelectedItems );
- POSITION pos = _listSelectedItems.GetHeadPosition();
- for( ; pos != NULL; )
- {
- HTREEITEM htiSel = _listSelectedItems.GetNext( pos );
- if( htiSel == hti )
- continue;
- TREEITEMINFO_t & _TII_Sel = TreeItemInfoGet( htiSel );
- _TII_Sel.m_bSelected = false;
- if( hWndOwn != NULL )
- _listInvalidateItems.AddTail( htiSel );
- }
- }
- if( hWndOwn == NULL || (! IsWindowVisible() ) )
- return;
- if( ( bWasSelected && (!_TII.m_bSelected) ) || ( (!bWasSelected) && _TII.m_bSelected ) )
- _listInvalidateItems.AddTail( hti );
- POSITION pos = _listInvalidateItems.GetHeadPosition();
- if( pos == NULL )
- return;
- CRect rcClient, rcItemEntire;
- GetClientRect( &rcClient );
- for( ; pos != NULL; )
- {
- HTREEITEM htiRedraw = _listInvalidateItems.GetNext( pos );
- TreeItemRectGet( htiRedraw, rcItemEntire, e_tirt_entire );
- if( rcItemEntire.IsRectEmpty() )
- continue;
- if( ( rcClient.top <= rcItemEntire.top && rcItemEntire.top <= rcClient.bottom )
- || ( rcClient.top <= rcItemEntire.bottom && rcItemEntire.bottom <= rcClient.bottom )
- )
- InvalidateRect( &rcItemEntire );
- }
- }
- void CExtTreeCtrl::GetSelectedItemsList(
- CList < HTREEITEM, HTREEITEM > & _listSelectedItems,
- HTREEITEM htiStart, // = NULL // NULL - root
- bool bDeep, // = true
- bool bAnalyseSelectedChildren, // = false
- bool bAddToTail // = true
- ) const
- {
- ASSERT_VALID( this );
- _listSelectedItems.RemoveAll();
- _GetSelectedItemsList_Impl( _listSelectedItems, htiStart, bDeep, bAnalyseSelectedChildren, bAddToTail );
- }
- void CExtTreeCtrl::_GetSelectedItemsList_Impl(
- CList < HTREEITEM, HTREEITEM > & _listSelectedItems,
- HTREEITEM htiStart, // = NULL // NULL - root
- bool bDeep, // = true
- bool bAnalyseSelectedChildren, // = false
- bool bAddToTail // = true
- ) const
- {
- ASSERT_VALID( this );
- if( htiStart == NULL )
- htiStart = TVI_ROOT;
- HTREEITEM hti = GetNextItem( htiStart, TVGN_CHILD );
- for( ; hti != NULL; hti = GetNextItem( hti, TVGN_NEXT ) )
- {
- if( IsItemSelected( hti ) )
- {
- if( bAddToTail )
- _listSelectedItems.AddTail( hti );
- else
- _listSelectedItems.AddHead( hti );
- if( ! bAnalyseSelectedChildren )
- continue;
- }
- if( bDeep )
- _GetSelectedItemsList_Impl( _listSelectedItems, hti, bDeep, bAnalyseSelectedChildren, bAddToTail );
- }
- }
- void CExtTreeCtrl::SelectItemRange(
- HTREEITEM htiFrom,
- HTREEITEM htiTo,
- bool bSelect,
- bool bExpandedOnly, // = true
- bool bIncludeDisabled, // = true
- bool bSubtract // = false
- )
- {
- ASSERT_VALID( this );
- if( htiFrom == NULL || htiTo == NULL )
- return;
- if( htiFrom == htiTo )
- {
- SelectItem( htiFrom, bSelect, bSubtract );
- return;
- }
- HTREEITEM hti;
- if( ! LinearItemIsBefore( htiTo, htiFrom, bExpandedOnly ) )
- {
- hti = htiFrom;
- htiFrom = htiTo;
- htiTo = hti;
- }
- HTREEITEM htiAnchor = AnchorItemGet();
- for( hti = htiFrom; true; hti = LinearItemGetNext( hti, bExpandedOnly ) )
- {
- if( bIncludeDisabled
- || OnQueryItemEnabledState( hti )
- )
- {
- if( bSubtract && bSelect && htiAnchor == hti )
- SelectItem( hti, true );
- else
- SelectItem( hti, bSelect, bSubtract );
- }
- if( hti == htiTo )
- break;
- }
- }
- HTREEITEM CExtTreeCtrl::GetInPlaceEditedItem() const
- {
- return m_htiInplaceEdited;
- }
- HTREEITEM CExtTreeCtrl::GetFocusedItem() const
- {
- ASSERT_VALID( this );
- HTREEITEM hti = GetNextItem( NULL, TVGN_CARET );
- if( hti != NULL && ( ! HasItem( hti ) ) )
- return NULL;
- return hti;
- }
- void CExtTreeCtrl::FocusItem(
- HTREEITEM hti,
- bool bSelect, // = false
- bool bUnselectOtherItems, // = false
- bool bMouseClickEvent // = false
- )
- {
- ASSERT_VALID( this );
- bMouseClickEvent;
- HTREEITEM htiOldFocus = GetNextItem( NULL, TVGN_CARET );
- bool bActuallyFocusChanged = ( htiOldFocus == hti ) ? false : true;
- //AnchorItemSet( htiOldFocus );
- if( hti == NULL )
- return;
- bool bAnyUnSelected = false;
- if( bUnselectOtherItems )
- {
- HTREEITEM htiWalk = NULL;
- POSITION pos = m_mapItemInfo.GetStartPosition();
- for( ; pos != NULL; )
- {
- TREEITEMINFO_t * pTII = NULL;
- m_mapItemInfo.GetNextAssoc( pos, htiWalk, pTII );
- if( htiWalk == hti || pTII == NULL )
- continue;
- pTII->m_bSelected = false;
- bAnyUnSelected = true;
- }
- }
- if( bSelect )
- SelectItem( hti, true );
- if( bActuallyFocusChanged )
- {
- CTreeCtrl::SelectItem( hti );
- if( bSelect)
- SelectItem( hti, true, false );
- }
- if( bActuallyFocusChanged || bSelect || bAnyUnSelected )
- CExtTreeCtrl::Invalidate();
- if( bActuallyFocusChanged )
- OnTreeItemDelayedFocus( hti, true, bMouseClickEvent );
- if( bMouseClickEvent
- && ( GetStyle() & TVS_SINGLEEXPAND ) != 0
- && (! TreeItemIsExpanded( hti ) )
- )
- Expand( hti, TVE_EXPAND );
- }
- void CExtTreeCtrl::OnLButtonDown( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- if( ! _OnTreeMouseClickImpl( VK_LBUTTON, 0, nFlags, point ) )
- CTreeCtrl::OnLButtonDown(nFlags, point);
- }
- void CExtTreeCtrl::OnLButtonUp( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- if( ! _OnTreeMouseClickImpl( VK_LBUTTON, 1, nFlags, point ) )
- CTreeCtrl::OnLButtonUp(nFlags, point);
- }
- void CExtTreeCtrl::OnLButtonDblClk( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- if( ! _OnTreeMouseClickImpl( VK_LBUTTON, 2, nFlags, point ) )
- CTreeCtrl::OnLButtonDblClk(nFlags, point);
- }
- void CExtTreeCtrl::OnRButtonDown( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- if( ! _OnTreeMouseClickImpl( VK_RBUTTON, 0, nFlags, point ) )
- CTreeCtrl::OnRButtonDown(nFlags, point);
- }
- void CExtTreeCtrl::OnRButtonUp( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- if( ! _OnTreeMouseClickImpl( VK_RBUTTON, 1, nFlags, point ) )
- CTreeCtrl::OnRButtonUp(nFlags, point);
- }
- void CExtTreeCtrl::OnRButtonDblClk( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- if( ! _OnTreeMouseClickImpl( VK_RBUTTON, 2, nFlags, point ) )
- CTreeCtrl::OnRButtonDblClk(nFlags, point);
- }
- void CExtTreeCtrl::OnMButtonDown( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- if( ! _OnTreeMouseClickImpl( VK_MBUTTON, 0, nFlags, point ) )
- CTreeCtrl::OnMButtonDown(nFlags, point);
- }
- void CExtTreeCtrl::OnMButtonUp( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- if( ! _OnTreeMouseClickImpl( VK_MBUTTON, 1, nFlags, point ) )
- CTreeCtrl::OnMButtonUp(nFlags, point);
- }
- void CExtTreeCtrl::OnMButtonDblClk( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- if( ! _OnTreeMouseClickImpl( VK_MBUTTON, 2, nFlags, point ) )
- CTreeCtrl::OnMButtonDblClk(nFlags, point);
- }
- bool CExtTreeCtrl::_OnTreeMouseClickImpl(
- int nMouseButton,
- int nClick,
- UINT nMouseEventFlags,
- CPoint point
- )
- {
- ASSERT_VALID( this );
- INT nLastMouseButtonEventIndex = 0;
- switch( nMouseButton )
- {
- case VK_LBUTTON: nLastMouseButtonEventIndex = 0; break;
- case VK_MBUTTON: nLastMouseButtonEventIndex = 1; break;
- case VK_RBUTTON: nLastMouseButtonEventIndex = 2; break;
- }
- DWORD dwHitTestFlags = 0;
- HTREEITEM hti = TreeItemHitTest( point, dwHitTestFlags );
- KillTimer( m_nDelayedEditingTimerID );
- HWND hWndOwn = m_hWnd;
- bool bRetVal =
- OnTreeMouseClick(
- hti,
- dwHitTestFlags,
- nMouseButton,
- nClick,
- nMouseEventFlags,
- point
- );
- if( ::IsWindow( hWndOwn ) )
- m_nLastMouseButtonEventType[ nLastMouseButtonEventIndex ] = nClick;
- return bRetVal;
- }
- bool CExtTreeCtrl::OnTreeItemDoDragDetect(
- HTREEITEM hti,
- DWORD dwHitTestFlags,
- int nMouseButton,
- int nClick,
- UINT nMouseEventFlags,
- CPoint point
- )
- {
- ASSERT_VALID( this );
- ASSERT( hti != NULL );
- ASSERT( GetSafeHwnd() != NULL );
- nMouseEventFlags;
- if( ! ( nMouseButton == VK_LBUTTON || nMouseButton == VK_RBUTTON ) )
- return false;
- UINT nUpMessage = ( nMouseButton == VK_LBUTTON ) ? WM_LBUTTONUP : WM_RBUTTONUP;
- if( ! CExtControlBar::stat_DoDragDetect( m_hWnd, point, nUpMessage ) )
- return false;
- if( nClick != 0 )
- return false;
- if( ( dwHitTestFlags & __EXT_TVHT_ONITEM ) == 0L )
- return false;
- if( ( GetStyle() & TVS_DISABLEDRAGDROP ) != 0L )
- return false;
- UINT nMessageID = ( nMouseButton == VK_LBUTTON ) ? TVN_BEGINDRAG : TVN_BEGINRDRAG;
- NM_TREEVIEW _data, _dataR;
- ::memset( &_data, 0, sizeof(NM_TREEVIEW) );
- ::memset( &_dataR, 0, sizeof(NM_TREEVIEW) );
- _data.hdr.hwndFrom = m_hWnd;
- _data.hdr.idFrom = GetDlgCtrlID();
- _data.hdr.code = nMessageID;
- _data.action = nMessageID;
- _data.itemNew.hItem = hti;
- _data.itemNew.mask = TVIF_IMAGE|TVIF_PARAM|TVIF_STATE|TVIF_HANDLE|TVIF_SELECTEDIMAGE|TVIF_CHILDREN;
- VERIFY( GetItem( &_data.itemNew ) );
- CString strItemText = GetItemText( hti );
- _data.itemNew.mask |= TVIF_TEXT;
- _data.itemNew.cchTextMax = strItemText.GetLength();
- _data.itemNew.pszText = strItemText.IsEmpty() ? _T("") : LPTSTR(LPCTSTR(strItemText));
- ::memcpy( &_data.itemOld, &_data.itemNew, sizeof(TVITEM) );
- _data.ptDrag.x = point.x;
- _data.ptDrag.y = point.y;
- SelectDropTarget( hti );
- ::SendMessage( ::GetParent(m_hWnd), WM_NOTIFY, WPARAM(_data.hdr.idFrom), LPARAM(&_data) );
- SelectDropTarget( NULL );
- return true;
- }
- bool CExtTreeCtrl::OnTreeMouseClick(
- HTREEITEM hti,
- DWORD dwHitTestFlags,
- int nMouseButton,
- int nClick,
- UINT nMouseEventFlags,
- CPoint point
- )
- {
- ASSERT_VALID( this );
- if( hti == NULL )
- return false;
- if( ( nMouseButton == VK_LBUTTON || nMouseButton == VK_RBUTTON )
- && ( nClick == 0 || nClick == 2 )
- )
- {
- HWND hWndParent = ::GetParent( m_hWnd );
- UINT nOwnID = UINT( GetDlgCtrlID() );
- NM_TREEVIEW _data;
- ::memset( &_data, 0, sizeof(NM_TREEVIEW) );
- _data.hdr.hwndFrom = m_hWnd;
- _data.hdr.idFrom = nOwnID;
- _data.hdr.code =
- ( nMouseButton == VK_LBUTTON )
- ? ( nClick == 0 ? NM_CLICK : NM_DBLCLK )
- : ( nClick == 0 ? NM_RCLICK : NM_RDBLCLK )
- ;
- _data.action = 0;
- _data.itemOld.mask = TVIF_CHILDREN|TVIF_HANDLE|TVIF_PARAM|TVIF_STATE;
- _data.itemOld.hItem = hti;
- GetItem( &_data.itemOld );
- CExtSafeString strItemText = GetItemText( hti );
- _data.itemOld.cchTextMax = INT(strItemText.GetLength());
- _data.itemOld.pszText = strItemText.IsEmpty() ? _T("") : LPTSTR(LPCTSTR(strItemText));
- _data.itemOld.mask |= TVIF_TEXT;
- ::memcpy( &_data.itemNew, &_data.itemOld, sizeof(TVITEM) );
- _data.ptDrag.x = point.x;
- _data.ptDrag.y = point.y;
- if( ::SendMessage( hWndParent, WM_NOTIFY, WPARAM(nOwnID), LPARAM(&_data) ) != 0 )
- return true;
- }
- DWORD dwTreeStyle = TreeGetStyle();
- bool bMultiSelection = ( ( dwTreeStyle & __EXT_TREE_MULTIPLE_SELECTION ) != 0 ) ? true : false;
- bool bSelectDisabledItems = ( ( dwTreeStyle & __EXT_TREE_SELECT_DISABLE_ITEMS ) != 0 ) ? true : false;
- bool bFocusDisabledItems = ( ( dwTreeStyle & __EXT_TREE_FOCUS_DISABLE_ITEMS ) != 0 ) ? true : false;
- bool bSelectCollapsedItems = ( ( dwTreeStyle & __EXT_TREE_SELECT_COLLAPSED_ITEMS ) != 0 ) ? true : false;
- bool bSubtractSelection = ( ( dwTreeStyle & __EXT_TREE_SUBTRACT_SELECTION ) != 0 ) ? true : false;
- bool bSingleExpand = ( ( GetStyle() & TVS_SINGLEEXPAND ) != 0 ) ? true : false;
- bool bEditLabels = ( ( GetStyle() & TVS_EDITLABELS ) != 0 ) ? true : false;
- bool bItemIsEnabled = OnQueryItemEnabledState( hti );
- switch( nMouseButton )
- {
- case VK_LBUTTON:
- {
- static HTREEITEM g_htiLastLButtonDownItem = NULL;
- switch( nClick )
- {
- case 0:
- g_htiLastLButtonDownItem = hti;
- // if( OnTreeItemDoDragDetect( hti, dwHitTestFlags, nMouseButton, nClick, nMouseEventFlags, point ) )
- // {
- // g_htiLastLButtonDownItem = NULL;
- // return true;
- // }
- //break;
- // continue falling after drag detection ...
- case 1:
- {
- if( ::GetFocus() != m_hWnd )
- SetFocus();
- if( g_htiLastLButtonDownItem != hti )
- return true;
- if( ( dwHitTestFlags & __EXT_TVHT_ONCONTROL ) != 0 )
- {
- CRect rcControl;
- VERIFY( TreeItemRectGet( hti, rcControl, e_tirt_control ) );
- ASSERT( ! rcControl.IsRectEmpty() );
- if( m_hWndChildControl != NULL )
- {
- CRect rc;
- ::GetWindowRect( m_hWndChildControl, &rc );
- if( rc == rcControl )
- return true;
- SendMessage( WM_CANCELMODE );
- }
- m_hWndChildControl = OnInplaceControlCreate( hti, rcControl );
- if( m_hWndChildControl != NULL )
- m_htiInplaceEdited = hti;
- return true;
- }
- if( ( dwHitTestFlags & __EXT_TVHT_ONITEMBUTTON ) != 0 )
- {
- if( nClick != 0 )
- return true;
- //if( ( nMouseEventFlags & (MK_CONTROL|MK_SHIFT) ) != 0 )
- // return true;
- HTREEITEM htiFocus = GetFocusedItem();
- if( htiFocus != NULL )
- {
- if( TreeItemIsExpanded( hti )
- && HasAncestor( hti, htiFocus )
- )
- {
- if( ( ! bFocusDisabledItems )
- && ( ! bItemIsEnabled )
- )
- FocusItem( NULL, false, false );
- else
- FocusItem( hti, bSelectDisabledItems || bItemIsEnabled, true );
- }
- }
- SendMessage( WM_CANCELMODE );
- Expand( hti, TVE_TOGGLE );
- Invalidate();
- return true;
- }
- DWORD dwSelectionAreaFlags =
- __EXT_TVHT_ONITEMICON|__EXT_TVHT_ONITEMLABEL
- |__EXT_TVHT_ONCONTROL|__EXT_TVHT_ONCHECKBOX;
- bool bFullRowSelection = ( ( GetStyle() & TVS_FULLROWSELECT ) != 0 ) ? true : false;
- if( bFullRowSelection )
- dwSelectionAreaFlags |= __EXT_TVHT_ONITEMINDENT|__EXT_TVHT_ONITEMRIGHT;
- static HTREEITEM stat_htiLastZeroFocusItem = NULL;
- if( ( dwHitTestFlags & dwSelectionAreaFlags ) != 0
- && ( bFocusDisabledItems || bItemIsEnabled )
- )
- {
- TREEITEMINFO_t & _TII = TreeItemInfoGet( hti );
-
- if( bEditLabels
- && ( hti != stat_htiLastZeroFocusItem && hti == GetFocusedItem() )
- && ( bFullRowSelection
- || ( dwHitTestFlags & __EXT_TVHT_ONITEMLABEL ) != 0
- )
- )
- {
- if( nClick != 0 )
- stat_htiLastZeroFocusItem = NULL;
- if( nClick != 1 )
- return true;
- if( ( m_hWndChildControl == NULL
- || ( ! ::IsWindow( m_hWndChildControl ) )
- )
- && ::GetFocus() == m_hWnd
- && m_nLastMouseButtonEventType[0] == 0 // if WM_LBUTTONUP after WM_LBUTTONDOWN, i.e. if not after WM_LBUTTONDBLCLK
- )
- {
- KillTimer( m_nDelayedEditingTimerID );
- m_wndContentExpand.Deactivate();
- SetTimer( m_nDelayedEditingTimerID, ::GetDoubleClickTime() + 1 , NULL );
- }
- return true;
- }
- if( ( dwHitTestFlags & m_dwCheckBoxAreaFlags ) != 0 && OnQueryItemEnabledState( hti ) )
- {
- if( nClick == 1 )
- {
- switch( _TII.m_eCheckBoxType )
- {
- case e_cbt_check_box:
- switch( _TII.m_nCheckBoxState )
- {
- case 0:
- _TII.m_nCheckBoxState = 1;
- break;
- case 1:
- _TII.m_nCheckBoxState = 0;
- break;
- }
- break;
- case e_cbt_tri_state_check_box:
- switch( _TII.m_nCheckBoxState )
- {
- case 0:
- _TII.m_nCheckBoxState = 1;
- break;
- case 1:
- _TII.m_nCheckBoxState = 2;
- break;
- case 2:
- _TII.m_nCheckBoxState = 0;
- break;
- }
- break;
- case e_cbt_radio:
- _CheckRadioBox( hti );
- break;
- } // switch( _TII.m_eCheckBoxType )
- }
- } // if( ( dwHitTestFlags & m_dwCheckBoxAreaFlags ) != 0 && OnQueryItemEnabledState( hti ) )
- HTREEITEM htiFocus = GetFocusedItem();
- if( bSingleExpand
- && htiFocus == hti
- && ( nMouseEventFlags & (MK_CONTROL|MK_SHIFT) ) == 0
- )
- {
- SendMessage( WM_CANCELMODE );
- Expand( hti, TVE_TOGGLE );
- Invalidate();
- if( nClick != 0 )
- stat_htiLastZeroFocusItem = NULL;
- return true;
- }
- bool bSelectFocusedFinally = true;
- if( bSubtractSelection
- && ( nMouseEventFlags & (MK_CONTROL|MK_SHIFT) ) == MK_CONTROL
- )
- {
- if( nClick == 1 )
- {
- //bSelectFocusedFinally = ! IsItemSelected( hti );
- AnchorItemSet( hti );
-
- SendMessage( WM_CANCELMODE );
- bool bSelectThisItem = false, bUnselectOtherItems = false;
- if( ( TreeGetStyle() & __EXT_TREE_MULTIPLE_SELECTION ) != 0 )
- {
- FocusItem( hti, bSelectThisItem, bUnselectOtherItems );
- //if( bSelectDisabledItems || bItemIsEnabled )
- SelectItem( hti, !IsItemSelected( hti ), IsItemSelected( hti ) );
- }
- else
- {
- bSelectThisItem = bUnselectOtherItems = true;
- FocusItem( hti, bSelectThisItem, bUnselectOtherItems );
- }
-
- Invalidate();
- if( m_wndContentExpand.GetSafeHwnd() != NULL )
- m_wndContentExpand.Invalidate();
- }
- if( nClick != 0 )
- stat_htiLastZeroFocusItem = NULL;
- return true;
- }
- HTREEITEM htiAnchor = AnchorItemGet();
- if( ( nMouseEventFlags & (MK_CONTROL|MK_SHIFT) ) != MK_SHIFT )
- AnchorItemSet( hti );
-
- if( htiFocus != NULL )
- {
- if( bMultiSelection
- && ( nMouseEventFlags & MK_SHIFT ) == MK_SHIFT
- )
- {
- if( bSubtractSelection && htiAnchor != NULL )
- SelectItemRange( htiAnchor, htiFocus, false, !bSelectCollapsedItems, bSelectDisabledItems );
- SelectItemRange( hti, htiAnchor, true, !bSelectCollapsedItems, bSelectDisabledItems );
- }
- }
- bool bUnselectOtherItems =
- (
- ( ! bMultiSelection )
- || ( ( nMouseEventFlags & (MK_CONTROL|MK_SHIFT) ) == 0 )
- )
- ? true : false;
- SendMessage( WM_CANCELMODE );
- if( ( ! bSelectDisabledItems ) && ( ! bItemIsEnabled ) )
- bSelectFocusedFinally = false;
- if( ! bSelectFocusedFinally )
- SelectItem( hti, false );
- if( nClick == 0 )
- stat_htiLastZeroFocusItem = hti;
- else
- stat_htiLastZeroFocusItem = NULL;
- FocusItem( hti, bSelectFocusedFinally, bUnselectOtherItems, true );
- Invalidate();
- if( m_wndContentExpand.GetSafeHwnd() != NULL )
- m_wndContentExpand.Invalidate();
- if( nClick == 0 && OnTreeItemDoDragDetect( hti, dwHitTestFlags, nMouseButton, nClick, nMouseEventFlags, point ) )
- {
- g_htiLastLButtonDownItem = NULL;
- return true;
- }
- return true;
- }
- if( nClick != 0 )
- stat_htiLastZeroFocusItem = NULL;
- }
- break;
- case 2:
- g_htiLastLButtonDownItem = NULL;
- if( ( dwHitTestFlags & (__EXT_TVHT_ONITEMICON|__EXT_TVHT_ONITEMLABEL) ) != 0
- && ( bFocusDisabledItems || bItemIsEnabled )
- && ! bSingleExpand
- )
- {
- if( ::GetFocus() != m_hWnd )
- SetFocus();
- SendMessage( WM_CANCELMODE );
- if( ItemHasChildren( hti ) )
- Expand( hti, TVE_TOGGLE );
- Invalidate();
- return true;
- }
- break;
- } // switch( nClick )
- }
- return true; // case VK_LBUTTON
- case VK_RBUTTON:
- {
- if( ::GetFocus() != m_hWnd )
- SetFocus();
- switch( nClick )
- {
- case 0:
- if( OnTreeItemDoDragDetect( hti, dwHitTestFlags, nMouseButton, nClick, nMouseEventFlags, point ) )
- return true;
- //break;
- // continue falling after drag detection ...
- case 1:
- {
- CPoint ptScreen = point;
- ClientToScreen( &ptScreen );
- SendMessage( WM_CONTEXTMENU, WPARAM(m_hWnd), MAKELPARAM(ptScreen.x,ptScreen.y) );
- }
- return true;
- } // switch( nClick )
- }
- break; // case VK_RBUTTON
- default:
- switch( nClick )
- {
- case 0:
- if( OnTreeItemDoDragDetect( hti, dwHitTestFlags, nMouseButton, nClick, nMouseEventFlags, point ) )
- return true;
- //break;
- // continue falling after drag detection ...
- } // switch( nClick )
- break;
- } // switch( nMouseButton )
- // return false;
- return true;
- }
- void CExtTreeCtrl::_CheckRadioBox( HTREEITEM hti )
- {
- ASSERT_VALID( this );
- TREEITEMINFO_t & _TII = TreeItemInfoGet( hti );
- if( _TII.m_eCheckBoxType != e_cbt_radio )
- return;
- _TII.m_nCheckBoxState = 1;
- _DeselectRadioBoxesNextPrev( hti, _TII.m_strRadioGroupName );
- }
- void CExtTreeCtrl::_DeselectRadioBoxesNextPrev(
- HTREEITEM hti,
- CExtSafeString m_strRadioGroupName
- )
- {
- ASSERT_VALID( this );
- if( hti == NULL )
- return;
- HTREEITEM htiNext = GetNextItem( hti, TVGN_NEXT );
- for( ; htiNext != NULL; htiNext = GetNextItem( htiNext, TVGN_NEXT ) )
- {
- TREEITEMINFO_t & _TII = TreeItemInfoGet( htiNext );
- if( _TII.m_strRadioGroupName != m_strRadioGroupName )
- break;
- _TII.m_nCheckBoxState = 0;
- }
- HTREEITEM htiPrev = GetNextItem( hti, TVGN_PREVIOUS );
- for( ; htiPrev != NULL; htiPrev = GetNextItem( htiPrev, TVGN_PREVIOUS ) )
- {
- TREEITEMINFO_t & _TII = TreeItemInfoGet( htiPrev );
- if( _TII.m_strRadioGroupName != m_strRadioGroupName )
- break;
- _TII.m_nCheckBoxState = 0;
- }
- }
- void CExtTreeCtrl::_SingleExpand( HTREEITEM hti, bool bSingleExpand )
- {
- ASSERT_VALID( this );
- HTREEITEM htiAnchor = AnchorItemGet();
- HTREEITEM htiFind = htiAnchor;
- HTREEITEM htiParent = GetNextItem( htiAnchor, TVGN_PARENT );
- HTREEITEM htiParentTwo = NULL;
- if( bSingleExpand && ( htiAnchor != NULL ) )
- {
- if( hti == htiAnchor )
- {
- Expand( hti, TVE_TOGGLE );
- return;
- }
- if( ItemHasChildren( htiAnchor ) && TreeItemIsExpanded( htiAnchor ) )
- Expand( htiAnchor, TVE_COLLAPSE );
- if( ItemHasChildren( hti ) )
- Expand( hti, TVE_TOGGLE );
- if( LinearItemIsAfter( htiAnchor, hti ) )
- {
- for( ; htiFind != hti; htiFind = LinearItemGetNext( htiFind ) )
- {
- htiParentTwo = GetNextItem( htiFind, TVGN_PARENT );
-
- Expand( htiParent, TVE_COLLAPSE );
- if( htiParent != htiParentTwo )
- htiParent = GetNextItem( htiParent, TVGN_PARENT );
- }
- }
- if( LinearItemIsBefore( htiAnchor, hti ) )
- {
- for( ; htiFind != hti; htiFind = LinearItemGetPrev( htiFind ) )
- {
- if( ItemHasChildren( htiFind ) && htiParent == htiFind )
- {
- Expand( htiFind, TVE_COLLAPSE );
- htiParent = GetNextItem( htiParent, TVGN_PARENT );
- }
- }
- }
- }
- }
- void CExtTreeCtrl::OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags )
- {
- ASSERT_VALID( this );
- nRepCnt;
- HTREEITEM htiOldFocus = GetFocusedItem();
- HWND hWndParent = ::GetParent( m_hWnd );
- UINT nOwnID = UINT( GetDlgCtrlID() );
- NMKEY _data;
- ::memset( &_data, 0, sizeof(NMKEY) );
- _data.hdr.hwndFrom = m_hWnd;
- _data.hdr.idFrom = nOwnID;
- _data.hdr.code = NM_KEYDOWN;
- _data.nVKey = nChar;
- _data.uFlags = nFlags;
- if( ::SendMessage( hWndParent, WM_NOTIFY, WPARAM(nOwnID), LPARAM(&_data) ) != 0 )
- return;
- HTREEITEM hti = htiOldFocus;
- if( hti == NULL )
- {
- hti = GetRootItem();
- if( hti == NULL )
- return;
- hti = GetNextItem( hti, TVGN_CHILD );
- if( hti == NULL )
- return;
- FocusItem( hti, true, true );
- return;
- }
- bool bMultiSelection = ( ( TreeGetStyle() & __EXT_TREE_MULTIPLE_SELECTION ) != 0 ) ? true : false;
- bool bShift = ( (::GetAsyncKeyState(VK_SHIFT)&0x8000) != 0 ) ? true : false;
- bool bCtrl = ( (::GetAsyncKeyState(VK_CONTROL)&0x8000) != 0 ) ? true : false;
- bool bSelectDisabledItems = ( ( TreeGetStyle() & __EXT_TREE_SELECT_DISABLE_ITEMS ) != 0 ) ? true : false;
- bool bFocusDisabledItems = ( ( TreeGetStyle() & __EXT_TREE_FOCUS_DISABLE_ITEMS ) != 0 ) ? true : false;
- bool bSelectCollapsedItems = ( ( TreeGetStyle() & __EXT_TREE_SELECT_COLLAPSED_ITEMS ) != 0 ) ? true : false;
- bool bSubtractSelection = ( ( TreeGetStyle() & __EXT_TREE_SUBTRACT_SELECTION ) != 0 ) ? true : false;
- HTREEITEM htiAnchor = AnchorItemGet();
- if( (! bShift) && htiAnchor == NULL )
- AnchorItemSet( htiOldFocus );
- HTREEITEM htiRoot = GetRootItem();
- switch( nChar )
- {
- case VK_F2:
- if( ( GetStyle() & TVS_EDITLABELS ) != 0 )
- {
- HTREEITEM htiFocused = GetFocusedItem();
- if( htiFocused != NULL )
- {
- HTREEITEM hti = GetInPlaceEditedItem();
- if( hti != htiFocused )
- {
- KillTimer( m_nDelayedEditingTimerID );
- SendMessage( WM_TIMER, WPARAM( m_nDelayedEditingTimerID ) );
- }
- }
- return;
- }
- break;
- case VK_APPS:
- {
- EnsureVisible( htiOldFocus );
- CRect rcItem;
- GetItemRect( htiOldFocus, &rcItem, TRUE );
- CPoint ptScreen = rcItem.CenterPoint();
- ClientToScreen( &ptScreen );
- SendMessage( WM_CONTEXTMENU, WPARAM(m_hWnd), MAKELPARAM(ptScreen.x,ptScreen.y) );
- }
- return;
- case VK_SPACE:
- {
- if( hti == NULL )
- return;
- TREEITEMINFO_t & _TII = TreeItemInfoGet( hti );
- if( ! ( bShift || bCtrl ) )
- {
- if( _TII.m_eCheckBoxType == e_cbt_check_box )
- {
- switch( _TII.m_nCheckBoxState )
- {
- case 0:
- _TII.m_nCheckBoxState = 1;
- break;
- case 1:
- _TII.m_nCheckBoxState = 0;
- break;
- }
- }
- if( _TII.m_eCheckBoxType == e_cbt_tri_state_check_box )
- {
- switch( _TII.m_nCheckBoxState )
- {
- case 0:
- _TII.m_nCheckBoxState = 1;
- break;
- case 1:
- _TII.m_nCheckBoxState = 2;
- break;
- case 2:
- _TII.m_nCheckBoxState = 0;
- break;
- }
- }
- }
- if( bSubtractSelection && bCtrl )
- {
- AnchorItemSet( hti );
-
- SelectItem( hti, !IsItemSelected( hti ), IsItemSelected( hti ) );
- FocusItem( hti );
- }
- Invalidate();
- }
- return;
- case VK_UP:
- {
- hti = LinearItemGetPrev( htiOldFocus, true, bFocusDisabledItems );
- if( hti == NULL )
- return;
- if( bMultiSelection )
- {
- if( bShift )
- {
- if( bSubtractSelection && htiAnchor != NULL )
- {
- SelectItemRange( htiAnchor, htiOldFocus, false, !bSelectCollapsedItems, bSelectDisabledItems );
- SelectItemRange( hti, htiAnchor, true, !bSelectCollapsedItems, bSelectDisabledItems );
- }
- else
- SelectItemRange( htiOldFocus, hti, true, !bSelectCollapsedItems, bSelectDisabledItems, bSubtractSelection );
- FocusItem( hti, bSelectDisabledItems || OnQueryItemEnabledState(hti), false );
- }
- else
- AnchorItemSet( hti );
- if( bCtrl )
- FocusItem( hti, false, false );
- if( (!bShift) && (!bCtrl) )
- FocusItem( hti, bSelectDisabledItems || OnQueryItemEnabledState(hti), true );
- _CheckRadioBox( hti );
- return;
- }
- else
- {
- FocusItem( hti, bSelectDisabledItems || OnQueryItemEnabledState(hti), true );
- _CheckRadioBox( hti );
- }
- }
- return;
- case VK_DOWN:
- {
- hti = LinearItemGetNext( htiOldFocus, true, bFocusDisabledItems );
- if( hti == NULL )
- return;
- if( bMultiSelection )
- {
- if( bShift )
- {
- if( bSubtractSelection && htiAnchor != NULL )
- {
- SelectItemRange( htiAnchor, htiOldFocus, false, !bSelectCollapsedItems, bSelectDisabledItems );
- SelectItemRange( hti, htiAnchor, true, !bSelectCollapsedItems, bSelectDisabledItems );
- }
- else
- SelectItemRange( htiOldFocus, hti, true, !bSelectCollapsedItems, bSelectDisabledItems, bSubtractSelection );
- FocusItem( hti, bSelectDisabledItems || OnQueryItemEnabledState(hti), false );
- }
- else
- AnchorItemSet( hti );
- if( bCtrl )
- FocusItem( hti, false, false );
- if( (!bShift) && (!bCtrl) )
- FocusItem( hti, bSelectDisabledItems || OnQueryItemEnabledState(hti), true );
- _CheckRadioBox( hti );
- return;
- }
- else
- {
- FocusItem( hti, bSelectDisabledItems || OnQueryItemEnabledState(hti), true );
- _CheckRadioBox( hti );
- }
- }
- return;
- case VK_LEFT:
- {
- if( bShift || bCtrl )
- return;
- if( TreeItemIsExpanded( hti ) )
- {
- Expand( hti, TVE_COLLAPSE );
- Invalidate();
- }
- else
- {
- hti = GetNextItem( hti, TVGN_PARENT );
- if( hti == NULL )
- return;
- if( ( bFocusDisabledItems )
- || ( OnQueryItemEnabledState( hti ) )
- )
- FocusItem( hti, true, true );
- }
- _CheckRadioBox( hti );
- }
- return;
- case VK_RIGHT:
- {
- if( bShift || bCtrl )
- return;
- if( TreeItemIsExpanded( hti ) )
- {
- hti = GetNextItem( hti, TVGN_CHILD );
- if( hti == NULL )
- return;
- if( ( bFocusDisabledItems )
- || ( OnQueryItemEnabledState( hti ) )
- )
- FocusItem( hti, true, true );
- }
- else
- {
- Expand( hti, TVE_EXPAND );
- Invalidate();
- }
- _CheckRadioBox( hti );
- }
- return;
- case VK_HOME:
- if( htiRoot != NULL )
- {
- HTREEITEM htiNewFocus = htiRoot;
- if( htiNewFocus == NULL )
- return;
- if( ! bFocusDisabledItems )
- {
- for( ; ! OnQueryItemEnabledState( htiNewFocus ); )
- {
- htiNewFocus =
- LinearItemFromItem(
- htiNewFocus,
- 1,
- NULL,
- true,
- false
- );
- if( htiNewFocus == NULL )
- return;
- }
- }
- if( bMultiSelection )
- {
- if( bShift )
- {
- if( bSubtractSelection && htiAnchor != NULL )
- {
- SelectItemRange( htiAnchor, htiOldFocus, false, !bSelectCollapsedItems, bSelectDisabledItems );
- SelectItemRange( htiNewFocus, htiAnchor, true, !bSelectCollapsedItems, bSelectDisabledItems );
- }
- else
- SelectItemRange( htiOldFocus, htiNewFocus, true, !bSelectCollapsedItems, bSelectDisabledItems, bSubtractSelection );
- FocusItem( htiNewFocus, bSelectDisabledItems || OnQueryItemEnabledState(htiNewFocus), false );
- }
- else
- AnchorItemSet( htiNewFocus );
- if( bCtrl )
- FocusItem( htiNewFocus, false, false );
- if( (!bShift) && (!bCtrl) )
- FocusItem( htiNewFocus, bSelectDisabledItems || OnQueryItemEnabledState(htiNewFocus), true );
- _CheckRadioBox( hti );
- }
- else
- {
- FocusItem( htiNewFocus, bSelectDisabledItems || OnQueryItemEnabledState(htiNewFocus), true );
- _CheckRadioBox( hti );
- }
- EnsureVisible( htiNewFocus );
- Invalidate();
- }
- return;
- case VK_END:
- if( htiRoot != NULL )
- {
- HTREEITEM htiNewFocus = htiRoot;
- if( htiNewFocus == NULL )
- return;
- HTREEITEM hti2 = htiRoot;
- for( ; hti2 != NULL; )
- {
- htiNewFocus = hti2;
- HTREEITEM hti3 = GetNextItem( hti2, TVGN_NEXT );
- if( hti3 != NULL )
- {
- hti2 = hti3;
- continue;
- }
- if( TreeItemIsExpanded( hti2 ) )
- {
- hti2 = GetNextItem( hti2, TVGN_CHILD );
- continue;
- }
- else
- break;
- }
- if( htiNewFocus == NULL )
- return;
- if( ! bFocusDisabledItems )
- {
- for( ; ! OnQueryItemEnabledState( htiNewFocus ); )
- {
- htiNewFocus =
- LinearItemFromItem(
- htiNewFocus,
- -1,
- NULL,
- true,
- false
- );
- if( htiNewFocus == NULL )
- return;
- }
- }
- if( bMultiSelection )
- {
- if( bShift )
- {
- if( bSubtractSelection && htiAnchor != NULL )
- {
- SelectItemRange( htiAnchor, htiOldFocus, false, !bSelectCollapsedItems, bSelectDisabledItems );
- SelectItemRange( htiNewFocus, htiAnchor, true, !bSelectCollapsedItems, bSelectDisabledItems );
- }
- else
- SelectItemRange( htiOldFocus, htiNewFocus, true, !bSelectCollapsedItems, bSelectDisabledItems, bSubtractSelection );
- FocusItem( htiNewFocus, bSelectDisabledItems || OnQueryItemEnabledState(htiNewFocus), false );
- }
- else
- AnchorItemSet( htiNewFocus );
- if( bCtrl )
- FocusItem( htiNewFocus, false, false );
- if( (!bShift) && (!bCtrl) )
- FocusItem( htiNewFocus, bSelectDisabledItems || OnQueryItemEnabledState(htiNewFocus), true );
- _CheckRadioBox( hti );
- }
- else
- {
- FocusItem( htiNewFocus, bSelectDisabledItems || OnQueryItemEnabledState(htiNewFocus), true );
- _CheckRadioBox( hti );
- }
- EnsureVisible( htiNewFocus );
- Invalidate();
- }
- return;
- case VK_PRIOR:
- case VK_NEXT:
- {
- bool bLastIsPartiallyVisible = false;
- INT nPageSize = TreeGetDisplayedItemCount( &bLastIsPartiallyVisible );
- if( bLastIsPartiallyVisible && nPageSize > 1 )
- nPageSize --;
- HTREEITEM htiNewFocus =
- LinearItemFromItem(
- hti,
- ( nChar == VK_PRIOR ) ? ( - nPageSize ) : nPageSize
- );
- if( htiNewFocus != NULL && htiNewFocus != hti )
- {
- if( ! bFocusDisabledItems )
- {
- for( ; ! OnQueryItemEnabledState( htiNewFocus ); )
- {
- htiNewFocus =
- LinearItemFromItem(
- htiNewFocus,
- ( nChar == VK_PRIOR ) ? -1 : 1,
- NULL,
- true,
- false
- );
- if( htiNewFocus == NULL )
- return;
- }
- }
- if( bMultiSelection )
- {
- if( bShift )
- {
- if( bSubtractSelection && htiAnchor != NULL )
- {
- SelectItemRange( htiAnchor, htiOldFocus, false, !bSelectCollapsedItems, bSelectDisabledItems );
- SelectItemRange( htiNewFocus, htiAnchor, true, !bSelectCollapsedItems, bSelectDisabledItems );
- }
- else
- SelectItemRange( htiOldFocus, htiNewFocus, true, !bSelectCollapsedItems, bSelectDisabledItems, bSubtractSelection );
- FocusItem( htiNewFocus, bSelectDisabledItems, false );
- }
- else
- AnchorItemSet( htiNewFocus );
- if( bCtrl )
- FocusItem( htiNewFocus, false, false );
- if( (!bShift) && (!bCtrl) )
- FocusItem( htiNewFocus, bSelectDisabledItems, true );
- _CheckRadioBox( hti );
- }
- else
- {
- FocusItem( htiNewFocus, bSelectDisabledItems, true );
- _CheckRadioBox( hti );
- }
- EnsureVisible( htiNewFocus );
- Invalidate();
- }
- }
- return;
- // case VK_TAB:
- // if( ( GetStyle() & WS_TABSTOP ) != 0 )
- // GetParent()->SendMessage(
- // WM_NEXTDLGCTL,
- // CExtPopupMenuWnd::IsKeyPressed(VK_SHIFT) ? 1 : 0,
- // 0
- // );
- // return;
- case VK_BACK:
- {
- HTREEITEM hti = GetFocusedItem();
- if( hti != NULL )
- {
- hti = GetNextItem( hti, TVGN_PARENT );
- if( hti != NULL )
- FocusItem( hti, true, true, false );
- }
- }
- return;
- case VK_RETURN:
- case VK_ESCAPE:
- if( (!( CExtPopupMenuWnd::IsKeyPressed( VK_MENU )
- || CExtPopupMenuWnd::IsKeyPressed( VK_CONTROL )
- || CExtPopupMenuWnd::IsKeyPressed( VK_SHIFT )
- ))
- && IsWindowEnabled()
- && ( GetStyle() & WS_VISIBLE ) != 0
- )
- {
- UINT nCmdID = ( nChar == 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) );
- return;
- }
- }
- break;
- } // switch( nChar )
- // CTreeCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- //void CExtTreeCtrl::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
- //{
- // ASSERT_VALID( this );
- // //CTreeCtrl::OnKeyUp(nChar, nRepCnt, nFlags);
- //}
- HTREEITEM CExtTreeCtrl::_LinearItemGetNext(
- HTREEITEM htiFrom,
- bool bExpandedOnly // = true
- ) const
- {
- ASSERT_VALID( this );
- if( ( ! bExpandedOnly ) || TreeItemIsExpanded( htiFrom ) )
- {
- HTREEITEM htiChild = GetNextItem( htiFrom, TVGN_CHILD );
- if ( htiChild != NULL )
- return htiChild;
- }
- HTREEITEM htiNext = GetNextItem( htiFrom, TVGN_NEXT );
- if( htiNext != NULL )
- return htiNext;
- HTREEITEM htiParent = _GetNextParent( htiFrom );
- htiNext = GetNextItem( htiParent, TVGN_NEXT );
- return htiNext;
- }
- HTREEITEM CExtTreeCtrl::_LinearItemGetPrev(
- HTREEITEM htiFrom,
- bool bExpandedOnly // = true
- ) const
- {
- ASSERT_VALID( this );
- HTREEITEM htiPrevious = GetNextItem( htiFrom, TVGN_PREVIOUS );
- if( htiPrevious != NULL )
- return _GetPreviousItem( htiPrevious, bExpandedOnly );
- HTREEITEM htiParent = GetNextItem( htiFrom, TVGN_PARENT );
- return htiParent;
- }
- HTREEITEM CExtTreeCtrl::LinearItemGetNext(
- HTREEITEM htiFrom,
- bool bExpandedOnly, // = true
- bool bIncludeDisabled // = true
- ) const
- {
- ASSERT_VALID( this );
- HTREEITEM hti = _LinearItemGetNext( htiFrom, bExpandedOnly );
- if( hti == NULL )
- return NULL;
- if( ! bIncludeDisabled )
- {
- for( ; ! OnQueryItemEnabledState(hti ); )
- {
- hti = _LinearItemGetNext( hti, bExpandedOnly );
- if( hti == NULL )
- break;
- }
- }
- return hti;
- }
- HTREEITEM CExtTreeCtrl::LinearItemGetPrev(
- HTREEITEM htiFrom,
- bool bExpandedOnly, // = true
- bool bIncludeDisabled // = true
- ) const
- {
- ASSERT_VALID( this );
- HTREEITEM hti = _LinearItemGetPrev( htiFrom, bExpandedOnly );
- if( hti == NULL )
- return NULL;
- if( ! bIncludeDisabled )
- {
- for( ; ! OnQueryItemEnabledState(hti ); )
- {
- hti = _LinearItemGetPrev( hti, bExpandedOnly );
- if( hti == NULL )
- break;
- }
- }
- return hti;
- }
- HTREEITEM CExtTreeCtrl::_GetNextParent( HTREEITEM hti ) const
- {
- ASSERT_VALID( this );
- HTREEITEM htiParent = GetNextItem( hti, TVGN_PARENT );
- if( htiParent == NULL )
- return NULL;
- HTREEITEM htiNextParent = GetNextItem( htiParent, TVGN_NEXT );
- if( htiNextParent == NULL )
- {
- HTREEITEM htiUpParent = _GetNextParent( htiParent );
- return htiUpParent;
- }
- return htiParent;
- }
- HTREEITEM CExtTreeCtrl::_GetPreviousItem( HTREEITEM hti, bool bExpandedOnly ) const
- {
- ASSERT_VALID( this );
- if( bExpandedOnly && ( ! TreeItemIsExpanded( hti ) ) )
- return hti;
- HTREEITEM htiChild = GetNextItem( hti, TVGN_CHILD );
- if( htiChild == NULL )
- return hti;
- HTREEITEM htiLastChild = _GetLastChildItem( htiChild );
- return _GetPreviousItem( htiLastChild, bExpandedOnly );
- }
- HTREEITEM CExtTreeCtrl::_GetLastChildItem( HTREEITEM hti ) const
- {
- ASSERT_VALID( this );
- HTREEITEM htiNext = GetNextItem( hti, TVGN_NEXT );
- if( htiNext == NULL )
- return hti;
- return _GetLastChildItem( htiNext );
- }
- bool CExtTreeCtrl::LinearItemIsBefore(
- HTREEITEM htiFrom,
- HTREEITEM htiBefore,
- bool bExpandedOnly // = true
- ) const
- {
- ASSERT_VALID( this );
- if( htiFrom == NULL || htiBefore == NULL || htiFrom == htiBefore )
- return false;
- HTREEITEM hti = LinearItemGetPrev( htiFrom, bExpandedOnly );
- for( ; hti != NULL; hti = LinearItemGetPrev( hti, bExpandedOnly ) )
- {
- if( hti == htiBefore )
- return true;
- }
- return false;
- }
- bool CExtTreeCtrl::LinearItemIsAfter(
- HTREEITEM htiFrom,
- HTREEITEM htiAfter,
- bool bExpandedOnly // = true
- ) const
- {
- ASSERT_VALID( this );
- if( htiFrom == NULL || htiAfter == NULL || htiFrom == htiAfter )
- return false;
- HTREEITEM hti = LinearItemGetNext( htiFrom, bExpandedOnly );
- for( ; hti != NULL; hti = LinearItemGetNext( hti, bExpandedOnly ) )
- {
- if( hti == htiAfter )
- return true;
- }
- return false;
- }
- HTREEITEM CExtTreeCtrl::LinearItemFromItem(
- HTREEITEM htiFrom,
- INT nOffset,
- INT * p_nResultShift, // = NULL
- bool bExpandedOnly, // = true
- bool bIncludeDisabled // = true
- )
- {
- ASSERT_VALID( this );
- if( p_nResultShift != NULL )
- (*p_nResultShift) = 0;
- if( htiFrom == NULL || nOffset == 0 )
- return htiFrom;
- HTREEITEM hti = htiFrom;
- HTREEITEM htiResult = htiFrom;
- INT nPassedOffset = 0;
- for( ; nPassedOffset != nOffset; )
- {
- if( nOffset > 0 )
- hti = LinearItemGetNext( hti, bExpandedOnly, bIncludeDisabled );
- else
- hti = LinearItemGetPrev( hti, bExpandedOnly, bIncludeDisabled );
- if( hti == NULL )
- break;
- htiResult = hti;
- if( nOffset > 0 )
- nPassedOffset ++;
- else
- nPassedOffset --;
- }
- if( p_nResultShift != NULL )
- (*p_nResultShift) = nPassedOffset;
- return htiResult;
- }
- DWORD CExtTreeCtrl::TreeGetStyle() const
- {
- ASSERT_VALID( this );
- return m_dwTreeStyle;
- }
- void CExtTreeCtrl::TreeModifyStyle(
- DWORD dwStyleAdd,
- DWORD dwStyleRemove // = 0
- )
- {
- ASSERT_VALID( this );
- m_dwTreeStyle &= ~dwStyleRemove;
- m_dwTreeStyle |= dwStyleAdd;
- }
- DWORD CExtTreeCtrl::TreeGetStyleEx() const
- {
- ASSERT_VALID( this );
- return m_dwTreeStyleEx;
- }
- void CExtTreeCtrl::TreeModifyStyleEx(
- DWORD dwStyleExAdd,
- DWORD dwStyleExRemove // = 0
- )
- {
- ASSERT_VALID( this );
- m_dwTreeStyleEx &= ~dwStyleExRemove;
- m_dwTreeStyleEx |= dwStyleExAdd;
- }
- INT CExtTreeCtrl::TreeGetDisplayedItemCount(
- bool * p_bLastIsPartiallyVisible // = NULL
- ) const
- {
- ASSERT_VALID( this );
- if( p_bLastIsPartiallyVisible != NULL )
- (*p_bLastIsPartiallyVisible) = false;
- HTREEITEM htiFirst = GetNextItem( NULL, TVGN_FIRSTVISIBLE );
- HTREEITEM hti = htiFirst;
- INT nCount = 0;
- CRect rcClient;
- GetClientRect( &rcClient );
- for( ; hti != NULL; )
- {
- CRect rcItemLabel;
- TreeItemRectGet( hti, rcItemLabel, e_tirt_label );
- if( rcItemLabel.top > rcClient.bottom )
- break;
- if( p_bLastIsPartiallyVisible != NULL
- && rcItemLabel.top < rcClient.bottom
- && rcItemLabel.bottom > rcClient.bottom
- )
- (*p_bLastIsPartiallyVisible) = true;
- nCount ++;
- hti = GetNextItem( hti, TVGN_NEXTVISIBLE );
- }
- return nCount;
- }
- HTREEITEM CExtTreeCtrl::AnchorItemGet() const
- {
- ASSERT_VALID(this);
- return m_htiAnchorItem;
- }
- void CExtTreeCtrl::AnchorItemSet( HTREEITEM hti )
- {
- ASSERT_VALID(this);
- m_htiAnchorItem = hti;
- }
- void CExtTreeCtrl::OnSetFocus( CWnd* pOldWnd )
- {
- CTreeCtrl::OnSetFocus(pOldWnd);
- Invalidate();
- UpdateWindow();
- SendMessage( WM_NCPAINT );
- }
- void CExtTreeCtrl::OnKillFocus( CWnd* pNewWnd )
- {
- CTreeCtrl::OnKillFocus(pNewWnd);
- Invalidate();
- UpdateWindow();
- SendMessage( WM_NCPAINT );
- m_wndContentExpand.Deactivate();
- }
- bool CExtTreeCtrl::MultipleSelectionGet() const
- {
- ASSERT_VALID(this);
- return ( ( TreeGetStyle() & __EXT_TREE_MULTIPLE_SELECTION ) != 0 ) ? true : false;
- }
- void CExtTreeCtrl::MultipleSelectionSet( bool bSet /*= true*/ )
- {
- ASSERT_VALID(this);
- if( bSet )
- {
- if( ( TreeGetStyle() & __EXT_TREE_MULTIPLE_SELECTION ) == 0 )
- TreeModifyStyle( __EXT_TREE_MULTIPLE_SELECTION, 0 );
- }
- else
- {
- if( ( TreeGetStyle() & __EXT_TREE_MULTIPLE_SELECTION ) != 0 )
- TreeModifyStyle( 0, __EXT_TREE_MULTIPLE_SELECTION );
- }
- }
- bool CExtTreeCtrl::SelectDisabledItemsGet() const
- {
- ASSERT_VALID(this);
- return ( ( TreeGetStyle() & __EXT_TREE_SELECT_DISABLE_ITEMS ) != 0 ) ? true : false;
- }
- void CExtTreeCtrl::SelectDisabledItemsSet( bool bSet /*= true*/ )
- {
- ASSERT_VALID(this);
- if( bSet )
- {
- if( ( TreeGetStyle() & __EXT_TREE_SELECT_DISABLE_ITEMS ) == 0 )
- TreeModifyStyle( __EXT_TREE_SELECT_DISABLE_ITEMS, 0 );
- }
- else
- {
- if( ( TreeGetStyle() & __EXT_TREE_SELECT_DISABLE_ITEMS ) != 0 )
- TreeModifyStyle( 0, __EXT_TREE_SELECT_DISABLE_ITEMS );
- }
- }
- bool CExtTreeCtrl::FocusDisabledItemsGet() const
- {
- ASSERT_VALID(this);
- return ( ( TreeGetStyle() & __EXT_TREE_FOCUS_DISABLE_ITEMS ) != 0 ) ? true : false;
- }
- void CExtTreeCtrl::FocusDisabledItemsSet( bool bSet /*= true*/ )
- {
- ASSERT_VALID(this);
- if( bSet )
- {
- if( ( TreeGetStyle() & __EXT_TREE_FOCUS_DISABLE_ITEMS ) == 0 )
- TreeModifyStyle( __EXT_TREE_FOCUS_DISABLE_ITEMS, 0 );
- }
- else
- {
- if( ( TreeGetStyle() & __EXT_TREE_FOCUS_DISABLE_ITEMS ) != 0 )
- TreeModifyStyle( 0, __EXT_TREE_FOCUS_DISABLE_ITEMS );
- }
- }
- bool CExtTreeCtrl::SelectCollapsedItemsGet() const
- {
- ASSERT_VALID(this);
- return ( ( TreeGetStyle() & __EXT_TREE_SELECT_COLLAPSED_ITEMS ) != 0 ) ? true : false;
- }
- void CExtTreeCtrl::SelectCollapsedItemsSet( bool bSet /*= true*/ )
- {
- ASSERT_VALID(this);
- if( bSet )
- {
- if( ( TreeGetStyle() & __EXT_TREE_SELECT_COLLAPSED_ITEMS ) == 0 )
- TreeModifyStyle( __EXT_TREE_SELECT_COLLAPSED_ITEMS, 0 );
- }
- else
- {
- if( ( TreeGetStyle() & __EXT_TREE_SELECT_COLLAPSED_ITEMS ) != 0 )
- TreeModifyStyle( 0, __EXT_TREE_SELECT_COLLAPSED_ITEMS );
- }
- }
- bool CExtTreeCtrl::SubtractSelectionGet() const
- {
- ASSERT_VALID(this);
- return ( ( TreeGetStyle() & __EXT_TREE_SUBTRACT_SELECTION ) != 0 ) ? true : false;
- }
- void CExtTreeCtrl::SubtractSelectionSet( bool bSet /*= true*/ )
- {
- ASSERT_VALID(this);
- if( bSet )
- {
- if( ( TreeGetStyle() & __EXT_TREE_SUBTRACT_SELECTION ) == 0 )
- TreeModifyStyle( __EXT_TREE_SUBTRACT_SELECTION, 0 );