ExtControlsCommon.cpp
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:275k
- }
- else
- {
- if( ( TreeGetStyle() & __EXT_TREE_SUBTRACT_SELECTION ) != 0 )
- TreeModifyStyle( 0, __EXT_TREE_SUBTRACT_SELECTION );
- }
- }
- bool CExtTreeCtrl::FullRowSelectionGet() const
- {
- ASSERT_VALID(this);
- return ( ( GetStyle() & TVS_FULLROWSELECT ) != 0 ) ? true : false;
- }
- void CExtTreeCtrl::FullRowSelectionSet( bool bSet /*= true*/ )
- {
- ASSERT_VALID(this);
- if( bSet )
- {
- if( ( GetStyle() & TVS_FULLROWSELECT ) == 0 )
- ModifyStyle( 0, TVS_FULLROWSELECT );
- }
- else
- {
- if( ( GetStyle() & TVS_FULLROWSELECT ) != 0 )
- ModifyStyle( TVS_FULLROWSELECT, 0 );
- }
- }
- bool CExtTreeCtrl::HasButtonsGet() const
- {
- ASSERT_VALID(this);
- return ( ( GetStyle() & TVS_HASBUTTONS ) != 0 ) ? true : false;
- }
- void CExtTreeCtrl::HasButtonsSet( bool bSet /*= true*/ )
- {
- ASSERT_VALID(this);
- if( bSet )
- {
- if( ( GetStyle() & TVS_HASBUTTONS ) == 0 )
- ModifyStyle( 0, TVS_HASBUTTONS );
- }
- else
- {
- if( ( GetStyle() & TVS_HASBUTTONS ) != 0 )
- ModifyStyle( TVS_HASBUTTONS, 0 );
- }
- }
- bool CExtTreeCtrl::HasLinesGet() const
- {
- ASSERT_VALID(this);
- return ( ( GetStyle() & TVS_HASLINES ) != 0 ) ? true : false;
- }
- void CExtTreeCtrl::HasLinesSet( bool bSet /*= true*/ )
- {
- ASSERT_VALID(this);
- if( bSet )
- {
- if( ( GetStyle() & TVS_HASLINES ) == 0 )
- ModifyStyle( 0, TVS_HASLINES );
- }
- else
- {
- if( ( GetStyle() & TVS_HASLINES ) != 0 )
- ModifyStyle( TVS_HASLINES, 0 );
- }
- }
- bool CExtTreeCtrl::LinesAtRootGet() const
- {
- ASSERT_VALID(this);
- return ( ( GetStyle() & TVS_LINESATROOT ) != 0 ) ? true : false;
- }
- void CExtTreeCtrl::LinesAtRootSet( bool bSet /*= true*/ )
- {
- ASSERT_VALID(this);
- if( bSet )
- {
- if( ( GetStyle() & TVS_LINESATROOT ) == 0 )
- ModifyStyle( 0, TVS_LINESATROOT );
- }
- else
- {
- if( ( GetStyle() & TVS_LINESATROOT ) != 0 )
- ModifyStyle( TVS_LINESATROOT, 0 );
- }
- }
- bool CExtTreeCtrl::ShowSelectionAlwaysGet() const
- {
- ASSERT_VALID(this);
- return ( ( GetStyle() & TVS_SHOWSELALWAYS ) != 0 ) ? true : false;
- }
- void CExtTreeCtrl::ShowSelectionAlwaysSet( bool bSet /*= true*/ )
- {
- ASSERT_VALID(this);
- if( bSet )
- {
- if( ( GetStyle() & TVS_SHOWSELALWAYS ) == 0 )
- ModifyStyle( 0, TVS_SHOWSELALWAYS );
- }
- else
- {
- if( ( GetStyle() & TVS_SHOWSELALWAYS ) != 0 )
- ModifyStyle( TVS_SHOWSELALWAYS, 0 );
- }
- }
- bool CExtTreeCtrl::SingleExpandGet() const
- {
- ASSERT_VALID(this);
- return ( ( GetStyle() & TVS_SINGLEEXPAND ) != 0 ) ? true : false;
- }
- void CExtTreeCtrl::SingleExpandSet( bool bSet /*= true*/ )
- {
- ASSERT_VALID(this);
- if( bSet )
- {
- if( ( GetStyle() & TVS_SINGLEEXPAND ) == 0 )
- ModifyStyle( 0, TVS_SINGLEEXPAND );
- }
- else
- {
- if( ( GetStyle() & TVS_SINGLEEXPAND ) != 0 )
- ModifyStyle( TVS_SINGLEEXPAND, 0 );
- }
- }
- bool CExtTreeCtrl::TrackSelectionGet() const
- {
- ASSERT_VALID(this);
- return ( ( GetStyle() & TVS_TRACKSELECT ) != 0 ) ? true : false;
- }
- void CExtTreeCtrl::TrackSelectionSet( bool bSet /*= true*/ )
- {
- ASSERT_VALID(this);
- if( bSet )
- {
- if( ( GetStyle() & TVS_TRACKSELECT ) == 0 )
- ModifyStyle( 0, TVS_TRACKSELECT );
- }
- else
- {
- if( ( GetStyle() & TVS_TRACKSELECT ) != 0 )
- ModifyStyle( TVS_TRACKSELECT, 0 );
- }
- }
- //bool CExtTreeCtrl::CheckBoxesGet() const
- //{
- // ASSERT_VALID(this);
- // return ( ( GetStyle() & TVS_CHECKBOXES ) != 0 ) ? true : false;
- //}
- //void CExtTreeCtrl::CheckBoxesSet( bool bSet /*= true*/ )
- //{
- // ASSERT_VALID(this);
- // if( bSet )
- // {
- // if( ( GetStyle() & TVS_CHECKBOXES ) == 0 )
- // ModifyStyle( 0, TVS_CHECKBOXES );
- // }
- // else
- // {
- // if( ( GetStyle() & TVS_CHECKBOXES ) != 0 )
- // ModifyStyle( TVS_CHECKBOXES, 0 );
- // }
- //}
- bool CExtTreeCtrl::HoverDisabledItemsGet() const
- {
- ASSERT_VALID(this);
- return ( ( TreeGetStyle() & __EXT_TREE_HOVER_DISABLE_ITEMS ) != 0 ) ? true : false;
- }
- void CExtTreeCtrl::HoverDisabledItemsSet( bool bSet /*= true*/ )
- {
- ASSERT_VALID(this);
- if( bSet )
- {
- if( ( TreeGetStyle() & __EXT_TREE_HOVER_DISABLE_ITEMS ) == 0 )
- TreeModifyStyle( __EXT_TREE_HOVER_DISABLE_ITEMS, 0 );
- }
- else
- {
- if( ( TreeGetStyle() & __EXT_TREE_HOVER_DISABLE_ITEMS ) != 0 )
- TreeModifyStyle( 0, __EXT_TREE_HOVER_DISABLE_ITEMS );
- }
- }
- bool CExtTreeCtrl::AutoDisableChildrenItemsGet() const
- {
- ASSERT_VALID(this);
- return ( ( TreeGetStyle() & __EXT_TREE_AUTO_DISABLE_ITEMS_BY_PARENT ) != 0 ) ? true : false;
- }
- void CExtTreeCtrl::AutoDisableChildrenItemsSet( bool bSet /*= true*/ )
- {
- ASSERT_VALID(this);
- if( bSet )
- {
- if( ( TreeGetStyle() & __EXT_TREE_AUTO_DISABLE_ITEMS_BY_PARENT ) == 0 )
- TreeModifyStyle( __EXT_TREE_AUTO_DISABLE_ITEMS_BY_PARENT, 0 );
- }
- else
- {
- if( ( TreeGetStyle() & __EXT_TREE_AUTO_DISABLE_ITEMS_BY_PARENT ) != 0 )
- TreeModifyStyle( 0, __EXT_TREE_AUTO_DISABLE_ITEMS_BY_PARENT );
- }
- }
- bool CExtTreeCtrl::HoverTreeBoxesGet() const
- {
- ASSERT_VALID(this);
- return ( ( TreeGetStyleEx() & __EXT_TREE_EX_HOVER_TREE_BOXES ) != 0 ) ? true : false;
- }
- void CExtTreeCtrl::HoverTreeBoxesSet( bool bSet /*= true*/ )
- {
- ASSERT_VALID(this);
- if( bSet )
- {
- if( ( TreeGetStyleEx() & __EXT_TREE_EX_HOVER_TREE_BOXES ) == 0 )
- TreeModifyStyleEx( __EXT_TREE_EX_HOVER_TREE_BOXES, NULL );
- }
- else
- {
- if( ( TreeGetStyleEx() & __EXT_TREE_EX_HOVER_TREE_BOXES ) != 0 )
- TreeModifyStyleEx( NULL, __EXT_TREE_EX_HOVER_TREE_BOXES );
- }
- }
- bool CExtTreeCtrl::HoverCheckBoxesGet() const
- {
- ASSERT_VALID(this);
- return ( ( TreeGetStyleEx() & __EXT_TREE_EX_HOVER_CHECK_BOXES ) != 0 ) ? true : false;
- }
- void CExtTreeCtrl::HoverCheckBoxesSet( bool bSet /*= true*/ )
- {
- ASSERT_VALID(this);
- if( bSet )
- {
- if( ( TreeGetStyleEx() & __EXT_TREE_EX_HOVER_CHECK_BOXES ) == 0 )
- TreeModifyStyleEx( __EXT_TREE_EX_HOVER_CHECK_BOXES, NULL );
- }
- else
- {
- if( ( TreeGetStyleEx() & __EXT_TREE_EX_HOVER_CHECK_BOXES ) != 0 )
- TreeModifyStyleEx( NULL, __EXT_TREE_EX_HOVER_CHECK_BOXES );
- }
- }
- bool CExtTreeCtrl::HoverRadioBoxesGet() const
- {
- ASSERT_VALID(this);
- return ( ( TreeGetStyleEx() & __EXT_TREE_EX_HOVER_RADIO_BUTTONS ) != 0 ) ? true : false;
- }
- void CExtTreeCtrl::HoverRadioBoxesSet( bool bSet /*= true*/ )
- {
- ASSERT_VALID(this);
- if( bSet )
- {
- if( ( TreeGetStyleEx() & __EXT_TREE_EX_HOVER_RADIO_BUTTONS ) == 0 )
- TreeModifyStyleEx( __EXT_TREE_EX_HOVER_RADIO_BUTTONS, NULL );
- }
- else
- {
- if( ( TreeGetStyleEx() & __EXT_TREE_EX_HOVER_RADIO_BUTTONS ) != 0 )
- TreeModifyStyleEx( NULL, __EXT_TREE_EX_HOVER_RADIO_BUTTONS );
- }
- }
- INT CExtTreeCtrl::OnTreeItemCalcCheckBoxAreaWidth() const
- {
- ASSERT_VALID(this);
- INT nLevelIndent = (INT)GetIndent();
- INT nCheckBoxWidth = max( nLevelIndent, 16 );
- return nCheckBoxWidth;
- }
- bool CExtTreeCtrl::TreeItemRectsGet(
- HTREEITEM hti,
- CRect * pRectEntire,
- CRect * pRectLinesArea, // = NULL
- CRect * pRectExpandCollapseButton, // = NULL
- CRect * pRectCheckBox, // = NULL
- CRect * pRectIcon, // = NULL
- CRect * pRectLabel, // = NULL
- CRect * pRectControl, // = NULL
- CRect * pRectRightPart // = NULL
- ) const
- {
- ASSERT_VALID(this);
- CRect rcDefItemLabel;
- if( ! CTreeCtrl::GetItemRect( hti, &rcDefItemLabel, true ) )
- return false;
- CRect rcClient;
- GetClientRect( &rcClient );
- ((CWnd*)this)->CWnd::RepositionBars( 0, 0xFFFF, 0, CWnd::reposQuery, &rcClient, &rcClient );
- CRect rcEntire(
- rcClient.left,
- rcDefItemLabel.top,
- rcClient.right,
- rcDefItemLabel.bottom
- );
- if( pRectEntire != NULL )
- (*pRectEntire) = rcEntire;
- CRect rcLinesArea(
- rcClient.left,
- rcDefItemLabel.top - 1,
- rcDefItemLabel.left, // - nLevelIndent,
- rcDefItemLabel.bottom + 1
- );
- if( pRectLinesArea != NULL )
- (*pRectLinesArea) = rcLinesArea;
- INT nLevelIndent = (INT)GetIndent();
- CRect rcTreeBox(
- rcDefItemLabel.left - nLevelIndent,
- rcDefItemLabel.top - 1,
- rcDefItemLabel.left,
- rcDefItemLabel.bottom + 1
- );
- if( pRectExpandCollapseButton != NULL )
- (*pRectExpandCollapseButton) = rcTreeBox;
- const CExtCmdIcon * pIcon = OnTreeItemQueryIcon( hti );
- const TREEITEMINFO_t & _TII = TreeItemInfoGet( hti );
- INT _marginCheckBoxLeft = ( ( _TII.m_eCheckBoxType != e_cbt_none ) ? MarginCheckBoxLeftGet() : 0 ),
- _marginCheckBoxRight = ( ( _TII.m_eCheckBoxType != e_cbt_none ) ? MarginCheckBoxRightGet() : 0 ),
- _marginIconLeft = ( ( pIcon != NULL ) ? MarginIconLeftGet() : 0 ),
- _marginIconRight = ( ( pIcon != NULL ) ? MarginIconRightGet() : 0 ),
- _marginControlLabelLeft = ( ( _TII.m_nControlWidth > 0 && ( ! _TII.m_strEditText.IsEmpty() ) ) ? MarginControlLabelLeftGet() : 0 ),
- _marginControlLabelRight = ( ( _TII.m_nControlWidth > 0 && ( ! _TII.m_strEditText.IsEmpty() ) ) ? MarginControlLabelRightGet() : 0 );
- CRect rcCheckBox(
- rcDefItemLabel.left + _marginCheckBoxLeft,
- rcDefItemLabel.top,
- rcDefItemLabel.left + _marginCheckBoxLeft,
- rcDefItemLabel.bottom
- );
- if( _TII.m_eCheckBoxType != e_cbt_none )
- {
- INT nCheckBoxWidth = OnTreeItemCalcCheckBoxAreaWidth();
- rcCheckBox.right += nCheckBoxWidth;
- if( pRectCheckBox != NULL )
- (*pRectCheckBox) = rcCheckBox;
- }
- CRect rcIcon(
- rcCheckBox.right + _marginIconLeft + _marginCheckBoxRight,
- rcCheckBox.top,
- rcCheckBox.right + _marginIconLeft + _marginCheckBoxRight,
- rcCheckBox.bottom
- );
- if( pIcon != NULL )
- {
- CSize _sizeIcon = pIcon->GetSize();
- rcIcon.right += _sizeIcon.cx;
- if( pRectIcon != NULL )
- (*pRectIcon) = rcIcon;
- }
- CRect rcLabel(
- rcIcon.right + MarginLabelLeftGet() + ( ( pIcon != NULL ) ? _marginIconRight : _marginCheckBoxRight ),
- rcIcon.top,
- rcIcon.right + TreeItemCalcLabelWidth( hti ) + MarginLabelLeftGet() + ( ( pIcon != NULL ) ? _marginIconRight : _marginCheckBoxRight ),
- rcIcon.bottom
- );
- if( pRectLabel != NULL )
- (*pRectLabel) = rcLabel;
- CRect rcControl(
- rcLabel.right + _marginControlLabelLeft + MarginLabelRightGet(),
- rcLabel.top,
- rcLabel.right + _marginControlLabelLeft + MarginLabelRightGet(),
- rcLabel.bottom + __EXT_TREE_CTRL_BORDER_GAP
- );
- if( _TII.m_nControlWidth > 0 )
- rcControl.right += _TII.m_nControlWidth; // + 6
- if( pRectControl != NULL )
- (*pRectControl) = rcControl;
- CRect rcRightPart(
- rcControl.right + ( ( _TII.m_nControlWidth > 0 && ( ! _TII.m_strEditText.IsEmpty() ) ) ? _marginControlLabelRight : 0 ),
- rcControl.top,
- rcClient.right,
- rcControl.bottom
- );
- if( pRectRightPart != NULL )
- (*pRectRightPart) = rcRightPart;
- return true;
- }
- bool CExtTreeCtrl::TreeItemRectGet(
- HTREEITEM hti,
- CRect & rcRetVal,
- CExtTreeCtrl::e_tree_item_rect_type_t eTIRT
- ) const
- {
- ASSERT_VALID(this);
- bool bRetVal = false;
- switch( eTIRT )
- {
- case e_tirt_entire:
- bRetVal = TreeItemRectsGet( hti, &rcRetVal );
- break;
- case e_tirt_line_area:
- bRetVal = TreeItemRectsGet( hti, NULL, &rcRetVal );
- break;
- case e_tirt_tree_box:
- bRetVal = TreeItemRectsGet( hti, NULL, NULL, &rcRetVal );
- break;
- case e_tirt_check_box:
- {
- const TREEITEMINFO_t & _TII = TreeItemInfoGet( hti );
- if( _TII.m_eCheckBoxType != e_cbt_none )
- bRetVal = TreeItemRectsGet( hti, NULL, NULL, NULL, &rcRetVal );
- }
- break;
- case e_tirt_icon:
- {
- const CExtCmdIcon * pIcon = OnTreeItemQueryIcon( hti );
- if( pIcon != NULL )
- bRetVal = TreeItemRectsGet( hti, NULL, NULL, NULL, NULL, &rcRetVal );
- }
- break;
- case e_tirt_label:
- bRetVal = TreeItemRectsGet( hti, NULL, NULL, NULL, NULL, NULL, &rcRetVal );
- break;
- case e_tirt_control:
- bRetVal = TreeItemRectsGet( hti, NULL, NULL, NULL, NULL, NULL, NULL, &rcRetVal );
- break;
- case e_tirt_right_part:
- bRetVal = TreeItemRectsGet( hti, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &rcRetVal );
- break;
- }; // switch( eTIRT )
- return bRetVal;
- }
- INT CExtTreeCtrl::TreeItemCalcLabelWidth(
- HTREEITEM hti
- ) const
- {
- ASSERT_VALID(this);
- INT nWidth = 0;
- CWindowDC dc( NULL );
- CExtSafeString strItemText = GetItemText( hti );
- if( ! strItemText.IsEmpty() )
- {
- const TREEITEMINFO_t & _TII = TreeItemInfoGet( hti );
- CFont * pFont = &m_fontNormal;
- if( _TII.m_bBold || _TII.m_bItalic )
- {
- if( _TII.m_bBold && _TII.m_bItalic )
- pFont = &m_fontBoldItalic;
- else if( _TII.m_bBold )
- pFont = &m_fontBold;
- else if( _TII.m_bItalic )
- pFont = &m_fontItalic;
- if( _TII.m_bItalic )
- nWidth += 3;
- }
- pFont = dc.SelectObject( pFont );
- CRect rcText( 0, 0, 0, 0 );
- dc.DrawText( LPCTSTR(strItemText), strItemText.GetLength(), rcText, DT_SINGLELINE | DT_LEFT | DT_TOP | DT_CALCRECT );
- dc.SelectObject( pFont );
- nWidth += rcText.Width();
- }
- return nWidth + PaddingLabelLeftGet() + PaddingLabelRightGet(); // + 6
- }
- HTREEITEM CExtTreeCtrl::TreeItemHitTest(
- CPoint ptClient,
- DWORD & dwHitTestFlags
- ) const
- {
- ASSERT_VALID(this);
- dwHitTestFlags = __EXT_TVHT_NOWHERE;
- CRect rcClient, rc;
- GetClientRect( &rcClient );
- HTREEITEM hti = GetNextItem( NULL, TVGN_FIRSTVISIBLE );
- for( ; hti != NULL; hti = GetNextItem( hti, TVGN_NEXTVISIBLE ) )
- {
- CRect rcEntire, rcLinesArea, rcTreeBox, rcCheckBox,
- rcIcon, rcLabel, rcControl, rcRightPart;
- if( ! CExtTreeCtrl::TreeItemRectsGet(
- hti,
- &rcEntire,
- &rcLinesArea,
- &rcTreeBox,
- &rcCheckBox,
- &rcIcon,
- &rcLabel,
- &rcControl,
- &rcRightPart
- )
- )
- continue;
- if( rcEntire.top > rcClient.bottom )
- break;
- if( ! rcEntire.PtInRect( ptClient ) )
- continue;
- if( (! rcLabel.IsRectEmpty() )
- && rcLabel.PtInRect( ptClient )
- )
- {
- dwHitTestFlags = __EXT_TVHT_ONITEMLABEL;
- return hti;
- }
- if( (! rcIcon.IsRectEmpty() )
- && rcIcon.PtInRect( ptClient )
- )
- {
- dwHitTestFlags = __EXT_TVHT_ONITEMICON;
- return hti;
- }
- if( (! rcCheckBox.IsRectEmpty() )
- && rcCheckBox.PtInRect( ptClient )
- )
- {
- dwHitTestFlags = __EXT_TVHT_ONCHECKBOX;
- return hti;
- }
- if( (! rcTreeBox.IsRectEmpty() )
- && rcTreeBox.PtInRect( ptClient )
- )
- {
- dwHitTestFlags = __EXT_TVHT_ONITEMBUTTON|__EXT_TVHT_ONITEMINDENT;
- return hti;
- }
- if( (! rcLinesArea.IsRectEmpty() )
- && rcLinesArea.PtInRect( ptClient )
- )
- {
- dwHitTestFlags = __EXT_TVHT_ONITEMINDENT;
- return hti;
- }
- if( (! rcControl.IsRectEmpty() )
- && rcControl.PtInRect( ptClient )
- )
- {
- dwHitTestFlags = __EXT_TVHT_ONCONTROL;
- return hti;
- }
- if( (! rcRightPart.IsRectEmpty() )
- && rcRightPart.PtInRect( ptClient )
- )
- {
- dwHitTestFlags = __EXT_TVHT_ONITEMRIGHT;
- return hti;
- }
- return hti;
- }
- return NULL;
- }
- void CExtTreeCtrl::_DoDelayedTreeIconInit()
- {
- ASSERT_VALID( this );
- }
- INT CExtTreeCtrl::TreeIconGetCount() const
- {
- ASSERT_VALID( this );
- ( const_cast < CExtTreeCtrl * > ( this ) ) -> _DoDelayedTreeIconInit();
- return (INT)m_arrIcons.GetSize();
- }
- void CExtTreeCtrl::TreeIconInsert(
- const CExtCmdIcon & _icon,
- INT nPos
- )
- {
- ASSERT_VALID( this );
- _DoDelayedTreeIconInit();
- if( nPos < 0 || nPos > TreeIconGetCount() )
- {
- ASSERT( FALSE );
- ::AfxThrowUserException();
- }
- m_arrIcons.InsertAt( nPos, new CExtCmdIcon( _icon ) );
- }
- void CExtTreeCtrl::TreeIconAdd(
- const CExtCmdIcon & _icon
- )
- {
- ASSERT_VALID( this );
- TreeIconInsert( _icon, TreeIconGetCount() );
- }
- void CExtTreeCtrl::TreeIconRemove(
- INT nPos,
- INT nCount // = 1
- )
- {
- ASSERT_VALID( this );
- if( nPos < 0 || nCount <= 0 )
- return;
- _DoDelayedTreeIconInit();
- INT nInconIndex, nIconCount = TreeIconGetCount();
- if( ( nPos + nCount ) > nIconCount )
- nCount = nIconCount - nPos;
- if( nCount <= 0 )
- return;
- for( nInconIndex = 0; nInconIndex < nCount; nInconIndex ++ )
- {
- CExtCmdIcon * pIcon = m_arrIcons[ nPos + nInconIndex ];
- ASSERT( pIcon != NULL );
- delete pIcon;
- }
- m_arrIcons.RemoveAt( nPos, nCount );
- }
- void CExtTreeCtrl::TreeIconRemoveAll()
- {
- ASSERT_VALID( this );
- TreeIconRemove( 0, TreeIconGetCount() );
- }
- CExtCmdIcon & CExtTreeCtrl::TreeIconGetAt( INT nPos )
- {
- ASSERT_VALID( this );
- _DoDelayedTreeIconInit();
- if( nPos < 0 || nPos >= TreeIconGetCount() )
- {
- ASSERT( FALSE );
- ::AfxThrowUserException();
- }
- CExtCmdIcon * pIcon = m_arrIcons[ nPos ];
- ASSERT( pIcon != NULL );
- return (*pIcon);
- }
- const CExtCmdIcon & CExtTreeCtrl::TreeIconGetAt( INT nPos ) const
- {
- ASSERT_VALID( this );
- return ( const_cast < CExtTreeCtrl * > ( this ) ) -> TreeIconGetAt( nPos );
- }
- LRESULT CExtTreeCtrl::OnSetFont( WPARAM wParam, LPARAM lParam )
- {
- ASSERT_VALID( this );
- wParam;
- lParam;
- LRESULT lr = Default();
- _FontsSync();
- return lr;
- }
- LRESULT CExtTreeCtrl::OnSettingChange( WPARAM wParam, LPARAM lParam )
- {
- ASSERT_VALID( this );
- wParam;
- lParam;
- LRESULT lr = Default();
- _FontsSync();
- return lr;
- }
- void CExtTreeCtrl::OnHScroll( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar )
- {
- ASSERT_VALID( this );
- if( m_hWndChildControl != NULL )
- {
- SendMessage( WM_CANCELMODE );
- if( ::GetFocus() != m_hWnd )
- SetFocus();
- }
- CTreeCtrl::OnHScroll(nSBCode, nPos, pScrollBar);
- Invalidate();
- }
- void CExtTreeCtrl::OnVScroll( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar )
- {
- ASSERT_VALID( this );
- if( m_hWndChildControl != NULL )
- {
- SendMessage( WM_CANCELMODE );
- if( ::GetFocus() != m_hWnd )
- SetFocus();
- }
- CTreeCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
- }
- void CExtTreeCtrl::OnSize( UINT nType, int cx, int cy )
- {
- ASSERT_VALID( this );
- CTreeCtrl::OnSize(nType, cx, cy);
- if( nType == SIZE_MINIMIZED )
- return;
- CWnd::RepositionBars( 0, 0xFFFF, 0 );
- }
- LRESULT CExtTreeCtrl::OnStyleChanging( WPARAM wParam, LPARAM lParam )
- {
- ASSERT_VALID( this );
- wParam;
- lParam;
- m_wndContentExpand.Deactivate();
- LRESULT lr = Default();
- return lr;
- }
- LRESULT CExtTreeCtrl::OnStyleChanged( WPARAM wParam, LPARAM lParam )
- {
- ASSERT_VALID( this );
- wParam;
- lParam;
- LRESULT lr = Default();
- return lr;
- }
- void CExtTreeCtrl::_FontsSync()
- {
- ASSERT_VALID( this );
- _FontsDestroy();
- ASSERT( GetSafeHwnd() != NULL );
- HFONT hFont = (HFONT)SendMessage( WM_GETFONT );
- if( hFont == NULL )
- {
- hFont = (HFONT)::GetStockObject( DEFAULT_GUI_FONT );
- if( hFont == NULL )
- {
- hFont = (HFONT)::GetStockObject( SYSTEM_FONT );
- ASSERT( hFont != NULL );
- }
- }
- LOGFONT _lf;
- ::memset( &_lf, 0, sizeof(LOGFONT) );
- ::GetObject( (HANDLE)hFont, sizeof(LOGFONT), &_lf );
- LONG lfWeightSaved = _lf.lfWeight;
- m_fontNormal.CreateFontIndirect( &_lf );
- _lf.lfUnderline = TRUE;
- m_fontNormalUnderline.CreateFontIndirect( &_lf );
- _lf.lfUnderline = FALSE;
- if( _lf.lfWeight >= 700 )
- _lf.lfWeight = 900;
- else
- _lf.lfWeight = 700; // bold
- m_fontBold.CreateFontIndirect( &_lf );
- _lf.lfUnderline = TRUE;
- m_fontBoldUnderline.CreateFontIndirect( &_lf );
- _lf.lfUnderline = FALSE;
- _lf.lfItalic = BYTE(!0);
- m_fontBoldItalic.CreateFontIndirect( &_lf );
- _lf.lfUnderline = TRUE;
- m_fontBoldItalicUnderline.CreateFontIndirect( &_lf );
- _lf.lfUnderline = FALSE;
- _lf.lfWeight = lfWeightSaved;
- m_fontItalic.CreateFontIndirect( &_lf );
- _lf.lfUnderline = TRUE;
- m_fontItalicUnderline.CreateFontIndirect( &_lf );
- _lf.lfUnderline = FALSE;
- }
- void CExtTreeCtrl::_FontsDestroy()
- {
- ASSERT_VALID( this );
- if( m_fontNormal.GetSafeHandle() != NULL )
- m_fontNormal.DeleteObject();
- if( m_fontBold.GetSafeHandle() != NULL )
- m_fontBold.DeleteObject();
- if( m_fontItalic.GetSafeHandle() != NULL )
- m_fontItalic.DeleteObject();
- if( m_fontBoldItalic.GetSafeHandle() != NULL )
- m_fontBoldItalic.DeleteObject();
- if( m_fontNormalUnderline.GetSafeHandle() != NULL )
- m_fontNormalUnderline.DeleteObject();
- if( m_fontBoldUnderline.GetSafeHandle() != NULL )
- m_fontBoldUnderline.DeleteObject();
- if( m_fontItalicUnderline.GetSafeHandle() != NULL )
- m_fontItalicUnderline.DeleteObject();
- if( m_fontBoldItalicUnderline.GetSafeHandle() != NULL )
- m_fontBoldItalicUnderline.DeleteObject();
- }
- void CExtTreeCtrl::PreSubclassWindow()
- {
- ::memset( &m_nLastMouseButtonEventType, 0, sizeof(m_nLastMouseButtonEventType) );
- CTreeCtrl::PreSubclassWindow();
- _FontsSync();
- ModifyStyle( 0, WS_CLIPCHILDREN|WS_CLIPSIBLINGS, SWP_FRAMECHANGED );
- CWnd::RepositionBars( 0, 0xFFFF, 0 );
- }
- const CExtCmdIcon * CExtTreeCtrl::OnTreeItemQueryIcon(
- HTREEITEM hti
- ) const
- {
- ASSERT_VALID( this );
- if( hti == NULL )
- return NULL;
- const TREEITEMINFO_t & _TII = TreeItemInfoGet( hti );
- if( TreeItemIsExpanded( hti ) )
- {
- if( _TII.m_nIconIndexExpanded < 0 || _TII.m_nIconIndexExpanded >= TreeIconGetCount() )
- return NULL;
- const CExtCmdIcon & _icon = TreeIconGetAt( _TII.m_nIconIndexExpanded );
- if( _icon.IsEmpty() )
- return NULL;
- return (&_icon);
- }
- else
- {
- if( _TII.m_nIconIndexCollapsed < 0 || _TII.m_nIconIndexCollapsed >= TreeIconGetCount() )
- return NULL;
- const CExtCmdIcon & _icon = TreeIconGetAt( _TII.m_nIconIndexCollapsed );
- if( _icon.IsEmpty() )
- return NULL;
- return (&_icon);
- }
- }
- HWND CExtTreeCtrl::OnInplaceControlCreate(
- HTREEITEM hti,
- CRect rcControl
- )
- {
- ASSERT_VALID( this );
- const TREEITEMINFO_t & _TII = TreeItemInfoGet( hti );
- switch( _TII.m_eICT )
- {
- case __EICT_EDIT:
- {
- CInplaceEdit * pEdit = new CInplaceEdit( false );
- if( ! pEdit->Create(
- WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN
- | ES_AUTOHSCROLL
- | _TII.m_dwAdditionalControlStyles
- ,
- rcControl,
- this,
- UINT(IDC_STATIC)
- )
- )
- return NULL;
- pEdit->SetFont( GetFont() );
- pEdit->SetWindowText( _TII.m_strEditText );
- pEdit->SetSel(0, -1);
- pEdit->SetFocus();
- return pEdit->m_hWnd;
- } // __EICT_EDIT
- case __EICT_DROPDOWN_COMBOBOX:
- case __EICT_DROPLIST_COMBOBOX:
- {
- CRect rcComboBox = rcControl;
- rcComboBox.bottom += _TII.m_nDropDownHeight;
- CInplaceComboBox * pCombo = new CInplaceComboBox;
- if( ! pCombo->Create(
- WS_CHILD | WS_VISIBLE | WS_BORDER | WS_CLIPSIBLINGS | WS_CLIPCHILDREN
- | CBS_AUTOHSCROLL
- | _TII.m_dwAdditionalControlStyles
- | ( ( _TII.m_eICT == __EICT_DROPDOWN_COMBOBOX ) ? CBS_DROPDOWN : CBS_DROPDOWNLIST )
- ,
- rcComboBox,
- this,
- UINT(IDC_STATIC)
- )
- )
- return NULL;
- pCombo->SetFont( GetFont() );
- INT nCount = _TII.ComboBoxItem_GetCount();
- if( nCount > 0 )
- {
- INT nIndex = 0;
- for( ; nIndex < nCount; nIndex ++ )
- {
- const COMBOBOXITEMDATA_t & _CID = _TII.ComboBoxItem_GetRefAt( nIndex );
- INT nY = pCombo->AddString( LPCTSTR(_CID.m_strLabel) );
- if( nY >= 0 )
- pCombo->SetItemData( nY, _CID.m_lParam );
- }
- nIndex = pCombo->FindStringExact( -1, LPCTSTR(_TII.m_strEditText) );
- if( nIndex < 0 )
- nIndex = pCombo->FindString( -1, LPCTSTR(_TII.m_strEditText) );
- if( nIndex < 0 )
- nIndex = 0;
- pCombo->SetCurSel( nIndex );
- } // if( nCount > 0 )
- pCombo->SetFocus();
- return pCombo->m_hWnd;
- } // __EICT_DROPDOWN_COMBOBOX
- case __EICT_PROGRESS_BAR_THEMED:
- case __EICT_PROGRESS_BAR_WITH_BOXES:
- case __EICT_PROGRESS_BAR_SMOOTH:
- case __EICT_PROGRESS_BAR_ENDLESS:
- return NULL;
- } // switch( _TII.m_eICT )
- return NULL;
- }
- void CExtTreeCtrl::OnInplaceControlCancel()
- {
- ASSERT_VALID( this );
- if( m_hWndChildControl == NULL )
- return;
- ::SendMessage( m_hWndChildControl, WM_CANCELMODE, 0L, 0L );
- if( ::IsWindow( m_hWndChildControl ) )
- ::DestroyWindow( m_hWndChildControl );
- m_hWndChildControl = NULL;
- m_htiInplaceEdited = NULL;
- }
- void CExtTreeCtrl::OnInplaceControlComplete(
- __EXT_MFC_SAFE_LPCTSTR strEditedText,
- bool bEditingLabel
- )
- {
- ASSERT_VALID( this );
- HTREEITEM hti = GetInPlaceEditedItem();
- if( hti == NULL )
- return;
- if( ! bEditingLabel )
- {
- TREEITEMINFO_t & _TII = TreeItemInfoGet( hti );
- _TII.m_strEditText = LPCTSTR(strEditedText);
- } // if( ! bEditingLabel )
- else
- {
- 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_ENDLABELEDIT;
- _data.item.mask = TVIF_CHILDREN|TVIF_HANDLE|TVIF_PARAM|TVIF_STATE;
- _data.item.hItem = hti;
- GetItem( &_data.item );
- strItemText = GetItemText( hti );
- bool bModeNotNULL = true;
- if( strItemText == LPCTSTR(strEditedText) )
- {
- bModeNotNULL = false;
- _data.item.cchTextMax = 0;
- _data.item.pszText = 0;
- }
- else
- {
- _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 )
- {
- if( bModeNotNULL )
- return;
- }
- SetItemText( hti, LPCTSTR(strEditedText) );
- } // else from if( ! bEditingLabel )
- }
- bool CExtTreeCtrl::OnQueryWindowFocusedState() const
- {
- ASSERT_VALID( this );
- HWND hWndOwn = GetSafeHwnd();
- if( hWndOwn == NULL )
- return false;
- HWND hWndFocus = ::GetFocus();
- if( hWndFocus == NULL )
- return false;
- if( hWndOwn == hWndFocus )
- return true;
- if( ::IsChild( hWndOwn, hWndFocus ) )
- return true;
- return false;
- }
- INT CExtTreeCtrl::MarginCheckBoxLeftGet() const
- {
- ASSERT_VALID( this );
- return m_nMarginCheckBoxLeft;
- }
- void CExtTreeCtrl::MarginCheckBoxLeftSet( INT nMargin )
- {
- ASSERT_VALID( this );
- m_nMarginCheckBoxLeft = nMargin;
- }
- INT CExtTreeCtrl::MarginCheckBoxRightGet() const
- {
- ASSERT_VALID( this );
- return m_nMarginCheckBoxRight;
- }
- void CExtTreeCtrl::MarginCheckBoxRightSet( INT nMargin )
- {
- ASSERT_VALID( this );
- m_nMarginCheckBoxRight = nMargin;
- }
- INT CExtTreeCtrl::MarginIconLeftGet() const
- {
- ASSERT_VALID( this );
- return m_nMarginIconLeft;
- }
- void CExtTreeCtrl::MarginIconLeftSet( INT nMargin )
- {
- ASSERT_VALID( this );
- m_nMarginIconLeft = nMargin;
- }
- INT CExtTreeCtrl::MarginIconRightGet() const
- {
- ASSERT_VALID( this );
- return m_nMarginIconRight;
- }
- void CExtTreeCtrl::MarginIconRightSet( INT nMargin )
- {
- ASSERT_VALID( this );
- m_nMarginIconRight = nMargin;
- }
- INT CExtTreeCtrl::MarginLabelLeftGet() const
- {
- ASSERT_VALID( this );
- return m_nMarginLabelLeft;
- }
- void CExtTreeCtrl::MarginLabelLeftSet( INT nMargin )
- {
- ASSERT_VALID( this );
- m_nMarginLabelLeft = nMargin;
- }
- INT CExtTreeCtrl::MarginLabelRightGet() const
- {
- ASSERT_VALID( this );
- return m_nMarginLabelRight;
- }
- void CExtTreeCtrl::MarginLabelRightSet( INT nMargin )
- {
- ASSERT_VALID( this );
- m_nMarginLabelRight = nMargin;
- }
- INT CExtTreeCtrl::MarginControlLabelLeftGet() const
- {
- ASSERT_VALID( this );
- return m_nMarginControlLabelLeft;
- }
- void CExtTreeCtrl::MarginControlLabelLeftSet( INT nMargin )
- {
- ASSERT_VALID( this );
- m_nMarginControlLabelLeft = nMargin;
- }
- INT CExtTreeCtrl::MarginControlLabelRightGet() const
- {
- ASSERT_VALID( this );
- return m_nMarginControlLabelRight;
- }
- void CExtTreeCtrl::MarginControlLabelRightSet( INT nMargin )
- {
- ASSERT_VALID( this );
- m_nMarginControlLabelRight = nMargin;
- }
- INT CExtTreeCtrl::PaddingLabelLeftGet() const
- {
- ASSERT_VALID( this );
- return m_nPaddingLabelLeft;
- }
- void CExtTreeCtrl::PaddingLabelLeftSet( INT nPadding )
- {
- ASSERT_VALID( this );
- m_nPaddingLabelLeft = nPadding;
- }
- INT CExtTreeCtrl::PaddingLabelRightGet() const
- {
- ASSERT_VALID( this );
- return m_nPaddingLabelRight;
- }
- void CExtTreeCtrl::PaddingLabelRightSet( INT nPadding )
- {
- ASSERT_VALID( this );
- m_nPaddingLabelRight = nPadding;
- }
- void CExtTreeCtrl::OnMouseMove( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- OnTreeMouseMove( nFlags, point );
- }
- void CExtTreeCtrl::OnTreeMouseMove( UINT nFlags, CPoint point )
- {
- ASSERT_VALID( this );
- nFlags;
- bool bTrackSelection =
- ( ( ( GetStyle() & TVS_TRACKSELECT ) != 0)
- || ( ( TreeGetStyleEx() & (__EXT_TREE_EX_HOVER_TREE_BOXES|__EXT_TREE_EX_HOVER_CHECK_BOXES|__EXT_TREE_EX_HOVER_RADIO_BUTTONS) ) != 0 )
- )
- ? true: false;
- if( ! bTrackSelection )
- return;
- bool bInfoTip = ( ( GetStyle() & TVS_INFOTIP ) != 0 ) ? true: false;
- DWORD dwHitTestFlagsNew = 0;
- HTREEITEM htiHoverNew = NULL;
- CPoint ptScreen = point;
- ClientToScreen( &ptScreen );
- HWND hWndFromPoint = ::WindowFromPoint( ptScreen );
- if( hWndFromPoint != NULL
- && ( hWndFromPoint == m_hWnd
- || hWndFromPoint == m_wndContentExpand.GetSafeHwnd()
- )
- )
- htiHoverNew = TreeItemHitTest( point, dwHitTestFlagsNew );
- if( htiHoverNew == m_htiHover
- && dwHitTestFlagsNew == m_dwLastHoverHitTestFlags
- )
- return;
- if( m_htiHover != NULL )
- {
- CRect rcItemEntire;
- TreeItemRectGet( m_htiHover, rcItemEntire, e_tirt_entire );
- InvalidateRect( &rcItemEntire );
- }
- if( htiHoverNew != NULL )
- {
- if( m_htiHover != htiHoverNew )
- {
- CRect rcItemEntire;
- TreeItemRectGet( htiHoverNew, rcItemEntire, e_tirt_entire );
- InvalidateRect( &rcItemEntire );
- }
- if( GetCapture() != this )
- SetCapture();
- }
- else
- {
- if( GetCapture() == this )
- ReleaseCapture();
- }
- if ( htiHoverNew != NULL )
- CWnd::SetCapture();
- else
- ReleaseCapture();
- OnTreeItemSetCursor(
- htiHoverNew,
- dwHitTestFlagsNew
- );
- OnTreeItemHoverChanged(
- htiHoverNew,
- dwHitTestFlagsNew,
- m_htiHover,
- m_dwLastHoverHitTestFlags
- );
- m_htiHover = htiHoverNew;
- m_dwLastHoverHitTestFlags = dwHitTestFlagsNew;
- if( bInfoTip )
- {
- bool bDeactivate = true;
- if( htiHoverNew != NULL )
- {
- CRect rcLabel;
- TreeItemRectGet( htiHoverNew, rcLabel, e_tirt_label );
- if( rcLabel.PtInRect( point ) )
- {
- CRect rcClient;
- GetClientRect( &rcClient );
- CWnd::RepositionBars( 0, 0xFFFF, 0, CWnd::reposQuery, &rcClient, &rcClient );
- if( rcLabel.left < rcClient.left
- || rcLabel.right > rcClient.right
- )
- {
- bDeactivate = false;
- m_wndContentExpand.Activate(
- rcLabel,
- this,
- __ECWAF_DEF_EXPANDED_ITEM_PAINTER|__ECWAF_NO_CAPTURE
- );
- SetTimer( __EXT_TREE_CONTROL_TIMER_ID_TRACKHOVER, 100, NULL );
- }
- }
- }
- if( bDeactivate )
- m_wndContentExpand.Deactivate();
- } // if( bInfoTip )
- }
- BOOL CExtTreeCtrl::OnSetCursor( CWnd* pWnd, UINT nHitTest, UINT message )
- {
- // return CTreeCtrl::OnSetCursor(pWnd, nHitTest, message);
- pWnd;
- nHitTest;
- message;
- CPoint ptScreen;
- if( ! ::GetCursorPos( &ptScreen ) )
- return FALSE;
- if( ::WindowFromPoint( ptScreen ) != m_hWnd )
- return FALSE;
- CPoint point = ptScreen;
- ScreenToClient( &point );
- DWORD dwHitTestFlags = 0;
- HTREEITEM htiHover = TreeItemHitTest( point, dwHitTestFlags );
- OnTreeItemSetCursor( htiHover, dwHitTestFlags );
- return TRUE;
- }
- void CExtTreeCtrl::OnTreeItemHoverChanged(
- HTREEITEM htiHoverNew,
- DWORD dwHitTestFlagsNew,
- HTREEITEM htiHoverOld,
- DWORD dwHitTestFlagsOld
- )
- {
- ASSERT_VALID( this );
- htiHoverNew;
- dwHitTestFlagsNew;
- htiHoverOld;
- dwHitTestFlagsOld;
- }
- void CExtTreeCtrl::OnTreeItemSetCursor(
- HTREEITEM htiHover,
- DWORD dwHitTestFlags
- )
- {
- ASSERT_VALID( this );
- HCURSOR hCursor = NULL;
- if( htiHover != NULL
- && ( dwHitTestFlags & __EXT_TVHT_ONITEMLABEL ) != 0
- && ( GetStyle() & TVS_TRACKSELECT ) != 0
- && ( ( TreeGetStyleEx() & __EXT_TREE_HOVER_DISABLE_ITEMS ) != 0
- || OnQueryItemEnabledState( htiHover )
- )
- )
- {
- hCursor = m_hCursorHand;
- }
- if( hCursor == NULL )
- hCursor = ::LoadCursor( NULL, IDC_ARROW );
- ::SetCursor( hCursor );
- }
- void CExtTreeCtrl::LoadWinXPTreeBox()
- {
- ASSERT_VALID( this );
- VERIFY( m_bmpTreeBoxCollapsed .LoadBMP_Resource( MAKEINTRESOURCE( IDB_EXT_BITMAP_TREE_BOX_COLLAPSED_XP ) ) );
- VERIFY( m_bmpTreeBoxCollapsedHover .LoadBMP_Resource( MAKEINTRESOURCE( IDB_EXT_BITMAP_TREE_BOX_COLLAPSED_HOVER_XP ) ) );
- VERIFY( m_bmpTreeBoxExpanded .LoadBMP_Resource( MAKEINTRESOURCE( IDB_EXT_BITMAP_TREE_BOX_EXPANDED_XP ) ) );
- VERIFY( m_bmpTreeBoxExpandedHover .LoadBMP_Resource( MAKEINTRESOURCE( IDB_EXT_BITMAP_TREE_BOX_EXPANDED_HOVER_XP ) ) );
- }
- void CExtTreeCtrl::LoadWinVistaTreeBox()
- {
- ASSERT_VALID( this );
- VERIFY( m_bmpTreeBoxCollapsed .LoadBMP_Resource( MAKEINTRESOURCE( IDB_EXT_BITMAP_TREE_BOX_COLLAPSED_VISTA ) ) );
- VERIFY( m_bmpTreeBoxCollapsedHover .LoadBMP_Resource( MAKEINTRESOURCE( IDB_EXT_BITMAP_TREE_BOX_COLLAPSED_HOVER_VISTA ) ) );
- VERIFY( m_bmpTreeBoxExpanded .LoadBMP_Resource( MAKEINTRESOURCE( IDB_EXT_BITMAP_TREE_BOX_EXPANDED_VISTA ) ) );
- VERIFY( m_bmpTreeBoxExpandedHover .LoadBMP_Resource( MAKEINTRESOURCE( IDB_EXT_BITMAP_TREE_BOX_EXPANDED_HOVER_VISTA ) ) );
- }
- #if _MFC_VER < 0x700
- void CExtTreeCtrl::OnActivateApp(BOOL bActive, HTASK hTask)
- #else
- void CExtTreeCtrl::OnActivateApp(BOOL bActive, DWORD hTask)
- #endif
- {
- ASSERT_VALID( this );
- CTreeCtrl::OnActivateApp(bActive, hTask);
- if( ! bActive )
- SendMessage( WM_CANCELMODE );
- }
- void CExtTreeCtrl::OnCancelMode()
- {
- ASSERT_VALID( this );
- CTreeCtrl::OnCancelMode();
- if( m_bCanceling )
- return;
- m_bCanceling = true;
- KillTimer( m_nDelayedEditingTimerID );
- OnInplaceControlCancel();
- HWND hWndCapture = ::GetCapture();
- if( hWndCapture == m_hWnd )
- ::ReleaseCapture();
- // m_wndContentExpand.Deactivate();
- m_bCanceling = false;
- }
- BOOL CExtTreeCtrl::OnMouseWheel( UINT nFlags, short zDelta, CPoint pt )
- {
- ASSERT_VALID( this );
- if( m_hWndChildControl != NULL )
- SendMessage( WM_CANCELMODE );
- BOOL bRetVal = CTreeCtrl::OnMouseWheel(nFlags, zDelta, pt);
- return bRetVal;
- }
- UINT CExtTreeCtrl::OnGetDlgCode()
- {
- return CTreeCtrl::OnGetDlgCode();
- //return DLGC_WANTALLKEYS;
- }
- LRESULT CExtTreeCtrl::_OnPaintExpanedItemContent( WPARAM wParam, LPARAM lParam )
- {
- ASSERT_VALID( this );
- lParam;
- CExtContentExpandWnd::PAINT_ITEM_CONTENT_DATA * p_picd =
- (CExtContentExpandWnd::PAINT_ITEM_CONTENT_DATA *)wParam;
- ASSERT( p_picd != NULL );
- ASSERT( p_picd->m_dc.GetSafeHdc() != NULL );
- if( m_htiHover != NULL )
- {
- COLORREF clrTreeBkColor = TreeBkColorGet();
- if( clrTreeBkColor == COLORREF(-1L) )
- clrTreeBkColor = ::GetSysColor( COLOR_WINDOW );
- //p_picd->m_dc.FillSolidRect( &rcClient, clrTreeBkColor );
- CFont * pOldFont = p_picd->m_dc.SelectObject( &m_fontNormal );
- COLORREF clrBackgroundOld = p_picd->m_dc.SetBkColor( clrTreeBkColor );
- COLORREF clrText = ::GetSysColor( COLOR_BTNTEXT );
- COLORREF clrTextOld = p_picd->m_dc.SetTextColor( clrText );
- int nOldBkMode = p_picd->m_dc.SetBkMode( TRANSPARENT );
- bool bFocusedWindow = OnQueryWindowFocusedState();
- bool bDisabledItem = ! OnQueryItemEnabledState( m_htiHover );
- bool bFocusedItem = ( m_htiHover == GetFocusedItem() ) ? true : false;
- bool bSelectedItem = IsItemSelected( m_htiHover );
- CRect rcItemEntire, rcItemLabel;
- // TreeItemRectGet( m_htiHover, rcItemEntire, e_tirt_entire );
- TreeItemRectGet( m_htiHover, rcItemLabel, e_tirt_label );
- m_wndContentExpand.GetClientRect( &rcItemEntire );
- m_wndContentExpand.ClientToScreen( &rcItemEntire );
- ScreenToClient( &rcItemEntire );
- p_picd->m_dc.OffsetViewportOrg( -rcItemLabel.left, -rcItemLabel.top );
- OnPaintTreeItem(
- m_htiHover,
- p_picd->m_dc,
- rcItemEntire,
- bFocusedWindow,
- bDisabledItem,
- bSelectedItem,
- bFocusedItem,
- false
- );
- p_picd->m_dc.OffsetViewportOrg( rcItemLabel.left, rcItemLabel.top );
- p_picd->m_dc.SetBkMode( nOldBkMode );
- p_picd->m_dc.SetTextColor( clrTextOld );
- p_picd->m_dc.SetBkColor( clrBackgroundOld );
- p_picd->m_dc.SelectObject( pOldFont );
- }
- return (!0);
- }
- void CExtTreeCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
- {
- if (pWnd->GetSafeHwnd() != m_hWnd)
- {
- Default();
- return;
- }
- DWORD dwHitTestFlags = 0;
- ScreenToClient( &point );
- HTREEITEM hti = TreeItemHitTest( point, dwHitTestFlags );
- if( hti == NULL )
- return;
- SelectDropTarget( hti );
- OnTreeItemContextMenu( hti, point, dwHitTestFlags );
- SelectDropTarget( NULL );
- }
- void CExtTreeCtrl::OnTreeItemContextMenu(
- HTREEITEM hti,
- CPoint point, // client coordinates
- DWORD dwHitTestFlags
- )
- {
- ASSERT_VALID( this );
- hti;
- point;
- dwHitTestFlags;
- }
- void CExtTreeCtrl::OnTimer( __EXT_MFC_UINT_PTR nIDEvent )
- {
- ASSERT_VALID( this );
- if( nIDEvent == m_nDelayedFocusTimerID )
- {
- KillTimer( m_nDelayedFocusTimerID );
- if( m_htiDelayedFocus == NULL )
- return;
- HTREEITEM htiDelayedFocus = m_htiDelayedFocus;
- m_htiDelayedFocus = NULL;
- if( GetFocusedItem() != htiDelayedFocus )
- return;
- //CString sTmp = GetItemText( htiDelayedFocus );
- //TRACE1( "Delated focus event for "%s" tree itemrn", LPCTSTR(sTmp) );
- OnTreeItemDelayedFocus( htiDelayedFocus, false );
- return;
- } // if( nIDEvent == m_nDelayedFocusTimerID )
- if( nIDEvent == __EXT_TREE_CONTROL_TIMER_ID_TRACKHOVER )
- {
- if( m_wndContentExpand.GetSafeHwnd() != NULL )
- {
- CPoint ptCursor;
- if( GetCursorPos( &ptCursor ) )
- {
- CPoint point = ptCursor;
- ScreenToClient( &point );
- HWND hWndFromPoint = ::WindowFromPoint( ptCursor );
- if( hWndFromPoint == m_hWndChildControl
- || hWndFromPoint == m_wndContentExpand.m_hWnd
- )
- {
- CRect rcClient;
- GetClientRect( &rcClient );
- CWnd::RepositionBars( 0, 0xFFFF, 0, CWnd::reposQuery, &rcClient, &rcClient );
- if( rcClient.PtInRect( point ) )
- return;
- }
- KillTimer( __EXT_TREE_CONTROL_TIMER_ID_TRACKHOVER );
- OnTreeMouseMove( 0, point );
- return;
- }
- }
- KillTimer( __EXT_TREE_CONTROL_TIMER_ID_TRACKHOVER );
- m_wndContentExpand.Deactivate();
- return;
- }
- if( nIDEvent == m_nDelayedEditingTimerID )
- {
- HTREEITEM hti = GetFocusedItem();
- EditLabel( hti );
- return;
- }
- CTreeCtrl::OnTimer( nIDEvent );
- }
- void CExtTreeCtrl::OnTreeItemDelayedFocus(
- HTREEITEM hti,
- bool bStartWaiting,
- bool bMouseClickEvent // = false
- )
- {
- ASSERT_VALID( this );
- if( bStartWaiting )
- {
- m_htiDelayedFocus = hti;
- KillTimer( m_nDelayedFocusTimerID );
- SetTimer( m_nDelayedFocusTimerID, m_nDelayedFocusTime, NULL );
- LPARAM lParam = LPARAM(__PARM_DELAYED_FOCUS_BEGIN_WAITING);
- if( bMouseClickEvent )
- lParam |= LPARAM(__PARM_DELAYED_FOCUS_MOUSE_CLICK);
- GetParent()->SendMessage( g_nMsgTreeItemDelayedFocus, WPARAM(this), lParam );
- }
- else
- {
- KillTimer( m_nDelayedFocusTimerID );
- m_htiDelayedFocus = NULL;
- GetParent()->SendMessage( g_nMsgTreeItemDelayedFocus, (WPARAM)this, 0L );
- }
- }
- bool CExtTreeCtrl::_NeedsChildren( HTREEITEM hti ) const
- {
- ASSERT_VALID( this );
- return ( GetChildItem( hti ) == NULL ) ? true : false;
- }
- void CExtTreeCtrl::_DeleteChildren( HTREEITEM hti )
- {
- ASSERT_VALID( this );
- HTREEITEM hti2 = GetChildItem( hti );
- for( ; hti2 != NULL; )
- {
- HTREEITEM hti3 = GetNextSiblingItem( hti2 );
- DeleteItem( hti2 );
- hti2 = hti3;
- }
- }
- bool CExtTreeCtrl::ReadOnlyLabelsGet() const
- {
- ASSERT_VALID( this );
- return m_bReadOnlyLabels;
- }
- void CExtTreeCtrl::ReadOnlyLabelsSet( bool bReadOnlyLabels )
- {
- ASSERT_VALID( this );
- m_bReadOnlyLabels = bReadOnlyLabels;
- }
- void CExtTreeCtrl::_CheckDeepFocusBegin(
- CList < HTREEITEM, HTREEITEM > & _listFocusPath
- )
- {
- ASSERT_VALID( this );
- _listFocusPath.RemoveAll();
- if( GetSafeHwnd() == NULL )
- return;
- HTREEITEM hti = GetFocusedItem();
- if( hti == NULL )
- return;
- ASSERT( HasItem( hti ) );
- for( ; hti != NULL; hti = GetNextItem( hti, TVGN_PARENT ) )
- _listFocusPath.AddHead( hti );
- }
- HTREEITEM CExtTreeCtrl::_CheckDeepFocusEnd(
- CList < HTREEITEM, HTREEITEM > & _listFocusPath
- )
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return NULL;
- HTREEITEM htiRetVal = NULL;
- POSITION pos = _listFocusPath.GetHeadPosition();
- for( ; pos != NULL; )
- {
- HTREEITEM hti = _listFocusPath.GetNext( pos );
- if( hti == NULL
- || ( ! HasItem( hti ) )
- )
- break;
- htiRetVal = hti;
- }
- return htiRetVal;
- }
- HTREEITEM CExtTreeCtrl::FindItemByText(
- HTREEITEM htiStartWalk,
- __EXT_MFC_SAFE_LPCTSTR strText,
- UINT nStartWalkCode, // = TVGN_CHILD
- UINT nContinueWalkCode // = TVGN_NEXT
- )
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return NULL;
- if( htiStartWalk == NULL || htiStartWalk == TVI_ROOT )
- {
- htiStartWalk = GetRootItem();
- if( htiStartWalk == NULL )
- return NULL;
- }
- if( strText == NULL )
- strText = _T("");
- HTREEITEM hti = GetNextItem( htiStartWalk, nStartWalkCode );
- for( ; hti != NULL; hti = GetNextItem( hti, nContinueWalkCode ) )
- {
- CString s = GetItemText( hti );
- if( s == LPCTSTR(strText) )
- return hti;
- }
- return NULL;
- }
- CExtTreeCtrl::COMBOBOXITEMDATA_t::COMBOBOXITEMDATA_t(
- __EXT_MFC_SAFE_LPCTSTR strLabel, // = NULL
- LPARAM lParam // = 0L
- )
- : m_strLabel( ( strLabel == NULL) ? _T("") : strLabel )
- , m_lParam( lParam )
- {
- }
- CExtTreeCtrl::COMBOBOXITEMDATA_t::COMBOBOXITEMDATA_t( const CExtTreeCtrl::COMBOBOXITEMDATA_t & other )
- {
- m_strLabel = other.m_strLabel;
- m_lParam = other.m_lParam;
- }
- CExtTreeCtrl::COMBOBOXITEMDATA_t::~COMBOBOXITEMDATA_t()
- {
- }
- CExtTreeCtrl::COMBOBOXITEMDATA_t & CExtTreeCtrl::COMBOBOXITEMDATA_t::operator = ( const CExtTreeCtrl::COMBOBOXITEMDATA_t & other )
- {
- m_strLabel = other.m_strLabel;
- m_lParam = other.m_lParam;
- return (*this);
- }
- CExtTreeCtrl::TREEITEMINFO_t::TREEITEMINFO_t()
- {
- Init();
- }
- CExtTreeCtrl::TREEITEMINFO_t::TREEITEMINFO_t( const CExtTreeCtrl::TREEITEMINFO_t & other )
- {
- Init();
- AssignFromOther( other );
- }
- CExtTreeCtrl::TREEITEMINFO_t::~TREEITEMINFO_t()
- {
- ComboBoxItem_RemoveAt();
- }
- void CExtTreeCtrl::TREEITEMINFO_t::Init()
- {
- m_clrTextNormal = COLORREF(-1L);
- m_clrBackgroundNormal = COLORREF(-1L);
- m_clrTextSelected = COLORREF(-1L);
- m_clrBackgroundSelected = COLORREF(-1L);
- m_clrTextDisabled = COLORREF(-1L);
- m_clrBackgroundDisabled = COLORREF(-1L);
- m_clrTextHover = COLORREF(-1L);
- m_bSelected = false;
- m_bDisabled = false;
- m_bBold = false;
- m_bItalic = false;
- m_bUnderline = false;
- m_eCheckBoxType = e_cbt_none;
- m_eICT = __EICT_NONE;
- m_nCheckBoxState = 0;
- m_strRadioGroupName.Empty();
- m_lParam = 0L;
- m_nIconIndexCollapsed = -1;
- m_nIconIndexExpanded = -1;
- m_nControlWidth = 0;
- m_nDropDownHeight = 200;
- m_dwAdditionalControlStyles = 0;
- m_dwAdditionalLabelEditorStyles = 0;
- m_strEditText.Empty();
- m_nProgressMin = 0;
- m_nProgressMax = 100;
- m_nProgressPos = 0;
- }
- void CExtTreeCtrl::TREEITEMINFO_t::AssignFromOther( const CExtTreeCtrl::TREEITEMINFO_t & other )
- {
- m_clrTextNormal = other.m_clrTextNormal;
- m_clrBackgroundNormal = other.m_clrBackgroundNormal;
- m_clrTextSelected = other.m_clrTextSelected;
- m_clrBackgroundSelected = other.m_clrBackgroundSelected;
- m_clrTextDisabled = other.m_clrTextDisabled;
- m_clrBackgroundDisabled = other.m_clrBackgroundDisabled;
- m_clrTextHover = other.m_clrTextHover;
- m_bSelected = other.m_bSelected;
- m_bDisabled = other.m_bDisabled;
- m_bBold = other.m_bBold;
- m_bItalic = other.m_bItalic;
- m_bUnderline = other.m_bUnderline;
- m_eCheckBoxType = other.m_eCheckBoxType;
- m_eICT = other.m_eICT;
- m_nCheckBoxState = other.m_nCheckBoxState;
- m_strRadioGroupName = other.m_strRadioGroupName;
- m_lParam = other.m_lParam;
- m_nIconIndexCollapsed = other.m_nIconIndexCollapsed;
- m_nIconIndexExpanded = other.m_nIconIndexExpanded;
- m_nControlWidth = other.m_nControlWidth;
- m_nDropDownHeight = other.m_nDropDownHeight;
- m_dwAdditionalControlStyles = other.m_dwAdditionalControlStyles;
- m_dwAdditionalLabelEditorStyles = other.m_dwAdditionalLabelEditorStyles;
- m_strEditText = other.m_strEditText;
- m_nProgressMin = other.m_nProgressMin;
- m_nProgressMax = other.m_nProgressMax;
- m_nProgressPos = other.m_nProgressPos;
- ComboBoxItem_RemoveAt();
- INT nCount = other.ComboBoxItem_GetCount();
- if( nCount > 0 )
- {
- try
- {
- m_arrComboBoxItems.InsertAt( 0, NULL, nCount );
- INT nIndex = 0;
- for( ; nIndex < nCount; nIndex++ )
- {
- const COMBOBOXITEMDATA_t & _CID = other.ComboBoxItem_GetRefAt( nIndex );
- COMBOBOXITEMDATA_t * pCID = new COMBOBOXITEMDATA_t( _CID );
- m_arrComboBoxItems.SetAt( nIndex, pCID );
- }
- }
- catch( CException * pException )
- {
- pException->Delete();
- ComboBoxItem_RemoveAt();
- }
- }
- }
- CExtTreeCtrl::TREEITEMINFO_t & CExtTreeCtrl::TREEITEMINFO_t::operator = ( const CExtTreeCtrl::TREEITEMINFO_t & other )
- {
- AssignFromOther( other );
- return ( * this );
- }
- INT CExtTreeCtrl::TREEITEMINFO_t::ComboBoxItem_GetCount() const
- {
- return INT( m_arrComboBoxItems.GetSize() );
- }
- CExtTreeCtrl::COMBOBOXITEMDATA_t * CExtTreeCtrl::TREEITEMINFO_t::ComboBoxItem_GetAt( INT nIndex )
- {
- if( nIndex < 0 || nIndex >= ComboBoxItem_GetCount() )
- return NULL;
- COMBOBOXITEMDATA_t * pCID = m_arrComboBoxItems[ nIndex ];
- ASSERT( pCID != NULL );
- return pCID;
- }
- const CExtTreeCtrl::COMBOBOXITEMDATA_t * CExtTreeCtrl::TREEITEMINFO_t::ComboBoxItem_GetAt( INT nIndex ) const
- {
- return ( const_cast < TREEITEMINFO_t * > ( this ) ) -> ComboBoxItem_GetAt( nIndex );
- }
- CExtTreeCtrl::COMBOBOXITEMDATA_t & CExtTreeCtrl::TREEITEMINFO_t::ComboBoxItem_GetRefAt( INT nIndex )
- {
- COMBOBOXITEMDATA_t * pCID = ComboBoxItem_GetAt( nIndex );
- if( pCID == NULL )
- ::AfxThrowUserException();
- return (*pCID);
- }
- const CExtTreeCtrl::COMBOBOXITEMDATA_t & CExtTreeCtrl::TREEITEMINFO_t::ComboBoxItem_GetRefAt( INT nIndex ) const
- {
- return ( const_cast < TREEITEMINFO_t * > ( this ) ) -> ComboBoxItem_GetRefAt( nIndex );
- }
- void CExtTreeCtrl::TREEITEMINFO_t::ComboBoxItem_InsertAt(
- INT nIndex,
- CExtTreeCtrl::COMBOBOXITEMDATA_t * pCID,
- bool bInsertClonedCopy // = true
- )
- {
- ASSERT( pCID != NULL );
- INT nCount = ComboBoxItem_GetCount();
- if( nIndex < 0 || nIndex > nCount )
- nIndex = nCount;
- if( bInsertClonedCopy )
- pCID = new COMBOBOXITEMDATA_t( *pCID );
- m_arrComboBoxItems.InsertAt( nIndex, pCID );
- }
- void CExtTreeCtrl::TREEITEMINFO_t::ComboBoxItem_InsertAt(
- INT nIndex,
- const CExtTreeCtrl::COMBOBOXITEMDATA_t & _CID
- )
- {
- COMBOBOXITEMDATA_t * pCID = new CExtTreeCtrl::COMBOBOXITEMDATA_t( _CID );
- ComboBoxItem_InsertAt( nIndex, pCID, false );
- }
- void CExtTreeCtrl::TREEITEMINFO_t::ComboBoxItem_Add(
- CExtTreeCtrl::COMBOBOXITEMDATA_t * pCID,
- bool bInsertClonedCopy // = true
- )
- {
- ASSERT( pCID != NULL );
- ComboBoxItem_InsertAt( -1, pCID, bInsertClonedCopy );
- }
- void CExtTreeCtrl::TREEITEMINFO_t::ComboBoxItem_Add( const CExtTreeCtrl::COMBOBOXITEMDATA_t & _CID )
- {
- COMBOBOXITEMDATA_t * pCID = new COMBOBOXITEMDATA_t( _CID );
- ComboBoxItem_InsertAt( -1, pCID, false );
- }
- INT CExtTreeCtrl::TREEITEMINFO_t::ComboBoxItem_RemoveAt(
- INT nIndex, // = 0
- INT nCountToRemove // = -1
- ) // default parameters - remove all, returns removed count
- {
- INT nCount = ComboBoxItem_GetCount();
- if( nCountToRemove < 0 )
- nCountToRemove = nCount;
- if( nIndex < 0 || nIndex >= nCountToRemove || nCountToRemove == 0 )
- return 0;
- if( ( nIndex + nCountToRemove ) > nCount )
- {
- nCountToRemove = nCount - nIndex;
- ASSERT( nCountToRemove > 0 );
- }
- INT nPos = nIndex, nLast = nIndex + nCountToRemove - 1;
- for( ; nPos <= nLast; nPos ++ )
- {
- COMBOBOXITEMDATA_t * pCID = ComboBoxItem_GetAt( nPos );
- if( pCID != NULL )
- delete pCID;
- }
- m_arrComboBoxItems.RemoveAt( nIndex, nCountToRemove );
- return nCountToRemove;
- }
- CExtTreeCtrl::CInplaceEdit::CInplaceEdit( bool bEditingLabel )
- : m_bEditingLabel( bEditingLabel )
- , m_bResultSaved( false )
- {
- }
- void CExtTreeCtrl::CInplaceEdit::PreSubclassWindow()
- {
- CExtEdit::PreSubclassWindow();
- HookSpyRegister( __EHSEF_KEYBOARD );
- }
- void CExtTreeCtrl::CInplaceEdit::PostNcDestroy()
- {
- HookSpyUnregister();
- CExtEdit::PostNcDestroy();
- delete this;
- }
- bool CExtTreeCtrl::CInplaceEdit::OnHookSpyKeyMsg(
- MSG * pMSG
- )
- {
- if( pMSG->hwnd == m_hWnd
- && ( GetStyle() & WS_VISIBLE ) != 0
- )
- {
- if( pMSG->message == WM_KEYDOWN )
- {
- if( pMSG->wParam == VK_RETURN || pMSG->wParam == VK_ESCAPE )
- {
- HWND hWndParent = ::GetParent( m_hWnd );
- HWND hWndOwn = m_hWnd;
- if( hWndParent != NULL )
- {
- if( pMSG->wParam == VK_RETURN )
- {
- if( ! m_bResultSaved )
- {
- m_bResultSaved = true;
- CString strText;
- GetWindowText( strText );
- ((CExtTreeCtrl*)CWnd::FromHandlePermanent(hWndParent)) ->
- OnInplaceControlComplete( LPCTSTR(strText), m_bEditingLabel );
- }
- }
- ::InvalidateRect( hWndParent, NULL, FALSE );
- }
- if( ::IsWindow( hWndOwn ) )
- DestroyWindow();
- ::SendMessage( hWndParent, WM_CANCELMODE, 0L, 0L );
- return true;
- }
- }
- }
- return false;
- }
- LRESULT CExtTreeCtrl::CInplaceEdit::WindowProc( UINT message, WPARAM wParam, LPARAM lParam )
- {
- LRESULT lResult = CExtEdit::WindowProc( message, wParam, lParam );
- switch( message )
- {
- case WM_ACTIVATEAPP:
- if( wParam == 0 )
- SendMessage( WM_CANCELMODE );
- break;
- case WM_NCCALCSIZE:
- {
- if( wParam )
- {
- NCCALCSIZE_PARAMS * myNCSIZE = (NCCALCSIZE_PARAMS*)lParam;
- myNCSIZE->rgrc[0].left += 3 * __EXT_TREE_CTRL_BORDER_GAP;
- myNCSIZE->rgrc[0].top += 2 * __EXT_TREE_CTRL_BORDER_GAP;
- myNCSIZE->rgrc[0].right -= 2 * __EXT_TREE_CTRL_BORDER_GAP;
- myNCSIZE->rgrc[0].bottom -= 2 * __EXT_TREE_CTRL_BORDER_GAP;
- }
- else
- {
- RECT * myRect2 = (RECT*)lParam;
- myRect2->left += 3 * __EXT_TREE_CTRL_BORDER_GAP;
- myRect2->top += 2 * __EXT_TREE_CTRL_BORDER_GAP;
- myRect2->right -= 2 * __EXT_TREE_CTRL_BORDER_GAP;
- myRect2->bottom -= 2 * __EXT_TREE_CTRL_BORDER_GAP;
- }
- return 0;
- }
- break;
- case WM_NCPAINT:
- {
- CRect nonClientRect;
- CRect clientRect;
- CWindowDC dc( this );
- GetWindowRect( &nonClientRect );
- GetClientRect( &clientRect );
- ClientToScreen( &clientRect );
- OffsetRect( &clientRect, - nonClientRect.left, - nonClientRect.top );
- dc.ExcludeClipRect( clientRect.left, clientRect.top, clientRect.right, clientRect.bottom );
- dc.Rectangle( 0, 0, nonClientRect.right - nonClientRect.left, nonClientRect.bottom - nonClientRect.top );
- }
- break;
- case WM_CANCELMODE:
- case WM_KILLFOCUS:
- {
- HWND hWndParent = ::GetParent( m_hWnd );
- if( hWndParent != NULL )
- ::InvalidateRect( hWndParent, NULL, FALSE );
- //((CExtTreeCtrl*)CWnd::FromHandlePermanent(hWndParent)) ->
- // OnInplaceControlCancel();
- if( ! m_bResultSaved )
- {
- m_bResultSaved = true;
- CString strText;
- GetWindowText( strText );
- ((CExtTreeCtrl*)CWnd::FromHandlePermanent(hWndParent)) ->
- OnInplaceControlComplete( LPCTSTR(strText), m_bEditingLabel );
- }
- DestroyWindow();
- ::SendMessage( hWndParent, WM_CANCELMODE, 0L, 0L );
- }
- break;
- case WM_GETDLGCODE:
- return ( lResult | DLGC_WANTALLKEYS );
- } // switch( message )
- return lResult;
- }
- CExtTreeCtrl::CInplaceComboBox::CInplaceComboBox()
- : m_bResultSaved( false )
- {
- }
- void CExtTreeCtrl::CInplaceComboBox::PreSubclassWindow()
- {
- CExtComboBox::PreSubclassWindow();
- //HookSpyRegister();
- }
- void CExtTreeCtrl::CInplaceComboBox::PostNcDestroy()
- {
- //HookSpyUnregister();
- CExtComboBox::PostNcDestroy();
- delete this;
- }
- bool CExtTreeCtrl::CInplaceComboBox::OnHookSpyKeyMsg(
- MSG * pMSG
- )
- {
- if( ( pMSG->hwnd == m_hWnd
- || ::IsChild( m_hWnd, pMSG->hwnd )
- )
- && ( GetStyle() & WS_VISIBLE ) != 0
- )
- {
- if( pMSG->message == WM_KEYDOWN )
- {
- if( pMSG->wParam == VK_RETURN || pMSG->wParam == VK_ESCAPE )
- {
- HWND hWndParent = ::GetParent( m_hWnd );
- if( hWndParent != NULL )
- {
- if( pMSG->wParam == VK_RETURN )
- {
- if( ! m_bResultSaved )
- {
- m_bResultSaved = true;
- CString strText;
- GetWindowText( strText );
- ((CExtTreeCtrl*)CWnd::FromHandlePermanent(hWndParent)) ->
- OnInplaceControlComplete( LPCTSTR(strText), false );
- }
- }
- ::InvalidateRect( hWndParent, NULL, FALSE );
- }
- DestroyWindow();
- return TRUE;
- }
- }
- }
- return CExtComboBox::OnHookSpyKeyMsg( pMSG );
- }
- LRESULT CExtTreeCtrl::CInplaceComboBox::WindowProc( UINT message, WPARAM wParam, LPARAM lParam )
- {
- HWND hWndOwn = m_hWnd;
- switch( message )
- {
- case WM_ACTIVATEAPP:
- if( wParam == 0 )
- SendMessage( WM_CANCELMODE );
- return 0;
- case WM_CANCELMODE:
- if( ! m_bResultSaved )
- {
- m_bResultSaved = true;
- HWND hWndParent = ::GetParent( m_hWnd );
- if( hWndParent != NULL )
- {
- if( ! m_bResultSaved )
- {
- m_bResultSaved = true;
- CString strText;
- GetWindowText( strText );
- ((CExtTreeCtrl*)CWnd::FromHandlePermanent(hWndParent)) ->
- OnInplaceControlComplete( LPCTSTR(strText), false );
- }
- }
- }
- DestroyWindow();
- return 0;
- case WM_KILLFOCUS:
- {
- HWND hWndParent = ::GetParent( hWndOwn );
- if( hWndParent != NULL )
- {
- ::InvalidateRect( hWndParent, NULL, FALSE );
- HWND hWndFocus = (HWND)wParam;
- if( ! ( hWndFocus == m_hWnd
- || ::IsChild( m_hWnd, hWndFocus )
- )
- )
- {
- PostMessage( WM_CANCELMODE );
- if( ! m_bResultSaved )
- {
- m_bResultSaved = true;
- CString strText;
- GetWindowText( strText );
- ((CExtTreeCtrl*)CWnd::FromHandlePermanent(hWndParent)) ->
- OnInplaceControlComplete( LPCTSTR(strText), false );
- }
- return 0L;
- }
- }
- }
- break;
- } // switch( message )
- if( ! ::IsWindow( hWndOwn ) )
- return 0L;
- LRESULT lResult = CExtComboBox::WindowProc( message, wParam, lParam );
- switch( message )
- {
- case WM_GETDLGCODE:
- return ( lResult | DLGC_WANTALLKEYS );
- } // switch( message )
- return lResult;
- }
- #endif // ( ! defined __EXT_MFC_NO_TREE_VIEW_CTRL )
- #if (! defined __EXT_MFC_NO_MSG_BOX )
- //////////////////////////////////////////////////////////////////////////////
- // CExtMsgBox window
- IMPLEMENT_DYNCREATE( CExtMsgBox, CExtResizableDialog );
- __EXT_MFC_SAFE_LPCTSTR CExtMsgBox::g_strRegSectionName = _T("ExtMsgBox");
- CExtMsgBox::CExtMsgBox(
- HWND hWndParent, // = NULL
- __EXT_MFC_SAFE_LPCTSTR strUniqueID // = NULL // for __EXT_MB_DO_NOT_DISPLAY_AGAIN and __EXT_MB_DO_NOT_ASK_AGAIN
- )
- : m_wndEditMsgBoxMessageText( true )
- , m_hWndParentFromCTOR( hWndParent )
- , m_nMsgBoxStyle( __EXT_MB_DEFAULT_STYLES )
- , m_nMsgBoxStyleEx( __EXT_MB_EX_DEFAULT_STYLES )
- , m_nHelpID( 0 )
- , m_nTimeoutSeconds( 0 )
- , m_bIsDisabledTimeout( false )
- , m_nTimeoutTimer( 0 )
- , m_nDefaultButtonDlgCtrlID( UINT(IDC_STATIC) )
- , m_nEscapeButtonDlgCtrlID( UINT(IDC_STATIC) )
- , m_sizeMessageText( 0, 0 )
- , m_sizeCheckBox( 0, 0 )
- , m_sizeButton( 0, 0 )
- , m_strUniqueID( LPCTSTR(strUniqueID) != NULL ? LPCTSTR(strUniqueID) : _T("") ) // for __EXT_MB_DO_NOT_DISPLAY_AGAIN and __EXT_MB_DO_NOT_ASK_AGAIN
- , m_sizeBorder( __EXT_MSG_BOX_DEFAULT_WINDOW_BORDER_WIDTH, __EXT_MSG_BOX_DEFAULT_WINDOW_BORDER_HEIGHT )
- , m_sizeStdButton( __EXT_MSG_BOX_DEFAULT_BUTTON_WIDTH, __EXT_MSG_BOX_DEFAULT_BUTTON_HEIGHT )
- , m_sizeStdButtonBorder( __EXT_MSG_BOX_DEFAULT_BUTTON_BORDER_WIDTH, __EXT_MSG_BOX_DEFAULT_BUTTON_BORDER_HEIGHT )
- , m_nCheckBoxGap( __EXT_MSG_BOX_CHECK_BOX_ADDITIONAL_SPACE )
- , m_nButtonSpace( __EXT_MSG_BOX_BTN_SPACE )
- , m_nMinEditCtrlHeight( __EXT_MSG_BOX_DEFAULT_EDITOR_MIN_HEIGHT_PX )
- , m_nMaxEditCtrlHeight( __EXT_MSG_BOX_DEFAULT_EDITOR_MAX_HEIGHT_PX )
- , m_bDynamicIcon( false )
- , m_clrEditorText( __EXT_MSG_BOX_DEFAULT_EDITOR_COLOR_TEXT )
- , m_clrEditorBkgnd( __EXT_MSG_BOX_DEFAULT_EDITOR_COLOR_BKGND )
- {
- _AddDefaultIconStyle();
- SetAutoSubclassChildControls();
- }
- CExtMsgBox::CExtMsgBox(
- HWND hWndParent,
- __EXT_MFC_SAFE_LPCTSTR strMessageText,
- __EXT_MFC_SAFE_LPCTSTR strCaption, // = NULL
- UINT nMsgBoxStyle, // = __EXT_MB_DEFAULT_STYLES
- UINT nHelpID, // = 0
- __EXT_MFC_SAFE_LPCTSTR strUniqueID, // = NULL // for __EXT_MB_DO_NOT_DISPLAY_AGAIN and __EXT_MB_DO_NOT_ASK_AGAIN
- UINT nMsgBoxStyleEx // = __EXT_MB_EX_DEFAULT_STYLES
- )
- : m_wndEditMsgBoxMessageText( true )
- , m_hWndParentFromCTOR( hWndParent )
- , m_strMessageText( ( strMessageText == NULL ) ? _T("") : LPCTSTR(strMessageText) )
- , m_strCaption( ( strCaption == NULL || _tcslen(strCaption) == 0 ) ? LPCTSTR( ::AfxGetAppName() ) : LPCTSTR(strCaption) )
- , m_nMsgBoxStyle( nMsgBoxStyle )
- , m_nMsgBoxStyleEx( nMsgBoxStyleEx )
- , m_nHelpID( nHelpID )
- , m_nTimeoutSeconds( 0 )
- , m_bIsDisabledTimeout( false )
- , m_nTimeoutTimer( 0 )
- , m_nDefaultButtonDlgCtrlID( UINT(IDC_STATIC) )
- , m_nEscapeButtonDlgCtrlID( UINT(IDC_STATIC) )
- , m_sizeMessageText( 0, 0 )
- , m_sizeCheckBox( 0, 0 )
- , m_sizeButton( 0, 0 )
- , m_strUniqueID( LPCTSTR(strUniqueID) != NULL ? LPCTSTR(strUniqueID) : _T("") ) // for __EXT_MB_DO_NOT_DISPLAY_AGAIN and __EXT_MB_DO_NOT_ASK_AGAIN
- , m_sizeBorder( __EXT_MSG_BOX_DEFAULT_WINDOW_BORDER_WIDTH, __EXT_MSG_BOX_DEFAULT_WINDOW_BORDER_HEIGHT )
- , m_sizeStdButton( __EXT_MSG_BOX_DEFAULT_BUTTON_WIDTH, __EXT_MSG_BOX_DEFAULT_BUTTON_HEIGHT )
- , m_sizeStdButtonBorder( __EXT_MSG_BOX_DEFAULT_BUTTON_BORDER_WIDTH, __EXT_MSG_BOX_DEFAULT_BUTTON_BORDER_HEIGHT )
- , m_nCheckBoxGap( __EXT_MSG_BOX_CHECK_BOX_ADDITIONAL_SPACE )
- , m_nButtonSpace( __EXT_MSG_BOX_BTN_SPACE )
- , m_nMinEditCtrlHeight( __EXT_MSG_BOX_DEFAULT_EDITOR_MIN_HEIGHT_PX )
- , m_nMaxEditCtrlHeight( __EXT_MSG_BOX_DEFAULT_EDITOR_MAX_HEIGHT_PX )
- , m_bDynamicIcon( false )
- , m_clrEditorText( __EXT_MSG_BOX_DEFAULT_EDITOR_COLOR_TEXT )
- , m_clrEditorBkgnd( __EXT_MSG_BOX_DEFAULT_EDITOR_COLOR_BKGND )
- {
- _AddDefaultIconStyle();
- SetAutoSubclassChildControls();
- }
- CExtMsgBox::CExtMsgBox(
- HWND hWndParent,
- UINT nMessageResourceID,
- UINT nCaptionResourceID, // = 0
- UINT nMsgBoxStyle, // = __EXT_MB_DEFAULT_STYLES
- UINT nHelpID, // = 0
- __EXT_MFC_SAFE_LPCTSTR strUniqueID, // = NULL // for __EXT_MB_DO_NOT_DISPLAY_AGAIN and __EXT_MB_DO_NOT_ASK_AGAIN
- UINT nMsgBoxStyleEx // = __EXT_MB_EX_DEFAULT_STYLES
- )
- : m_wndEditMsgBoxMessageText( true )
- , m_hWndParentFromCTOR( hWndParent )
- , m_nMsgBoxStyle( nMsgBoxStyle )
- , m_nMsgBoxStyleEx( nMsgBoxStyleEx )
- , m_nHelpID( nHelpID )
- , m_nTimeoutSeconds( 0 )
- , m_bIsDisabledTimeout( false )
- , m_nTimeoutTimer( 0 )
- , m_nDefaultButtonDlgCtrlID( UINT(IDC_STATIC) )
- , m_nEscapeButtonDlgCtrlID( UINT(IDC_STATIC) )
- , m_sizeMessageText( 0, 0 )
- , m_sizeCheckBox( 0, 0 )
- , m_sizeButton( 0, 0 )
- , m_strUniqueID( LPCTSTR(strUniqueID) != NULL ? LPCTSTR(strUniqueID) : _T("") ) // for __EXT_MB_DO_NOT_DISPLAY_AGAIN and __EXT_MB_DO_NOT_ASK_AGAIN
- , m_sizeBorder( __EXT_MSG_BOX_DEFAULT_WINDOW_BORDER_WIDTH, __EXT_MSG_BOX_DEFAULT_WINDOW_BORDER_HEIGHT )
- , m_sizeStdButton( __EXT_MSG_BOX_DEFAULT_BUTTON_WIDTH, __EXT_MSG_BOX_DEFAULT_BUTTON_HEIGHT )
- , m_sizeStdButtonBorder( __EXT_MSG_BOX_DEFAULT_BUTTON_BORDER_WIDTH, __EXT_MSG_BOX_DEFAULT_BUTTON_BORDER_HEIGHT )
- , m_nCheckBoxGap( __EXT_MSG_BOX_CHECK_BOX_ADDITIONAL_SPACE )
- , m_nButtonSpace( __EXT_MSG_BOX_BTN_SPACE )
- , m_nMinEditCtrlHeight( __EXT_MSG_BOX_DEFAULT_EDITOR_MIN_HEIGHT_PX )
- , m_nMaxEditCtrlHeight( __EXT_MSG_BOX_DEFAULT_EDITOR_MAX_HEIGHT_PX )
- , m_bDynamicIcon( false )
- , m_clrEditorText( __EXT_MSG_BOX_DEFAULT_EDITOR_COLOR_TEXT )
- , m_clrEditorBkgnd( __EXT_MSG_BOX_DEFAULT_EDITOR_COLOR_BKGND )
- {
- _AddDefaultIconStyle();
- SetAutoSubclassChildControls();
- if( nCaptionResourceID == 0 )
- m_strCaption = LPCTSTR( ::AfxGetAppName() );
- else
- {
- VERIFY( g_ResourceManager->LoadString( m_strCaption, nCaptionResourceID ) );
- }
- VERIFY( g_ResourceManager->LoadString( m_strMessageText, nMessageResourceID ) );
- }
- CExtMsgBox::~CExtMsgBox()
- {
- m_bmpIcon.Empty();
- UnRegisterAllButtons();
- }
- void CExtMsgBox::_AddDefaultIconStyle()
- {
- ASSERT_VALID( this );
- if( ! m_bmpIcon.IsEmpty() )
- return;
- UINT nMsgBoxStyleEx = MsgBoxStyleExGet();
- if( ( nMsgBoxStyleEx & __EXT_MB_EX_NO_DEFAULT_ICON_STYLE ) != 0 )
- return;
- UINT nMsgBoxStyle = MsgBoxStyleGet();
- UINT nMsgBoxIconType = nMsgBoxStyle & __EXT_MB_ICONMASK;
- if( nMsgBoxIconType == 0 )
- {
- UINT nMsgBoxType = nMsgBoxStyle & __EXT_MB_TYPEMASK;
- switch( nMsgBoxType )
- {
- case __EXT_MB_OK:
- case __EXT_MB_OKCANCEL:
- case __EXT_MB_YESNO:
- case __EXT_MB_YESNOCANCEL:
- MsgBoxStyleSet( nMsgBoxStyle | __EXT_MB_ICONEXCLAMATION );
- break;
- }
- }
- }
- void CExtMsgBox::DoDataExchange( CDataExchange * pDX )
- {
- #if ( _MFC_VER == 0x700 )
- CExtResizableDialog
- #else
- CExtNCW < CExtResizableDialog >
- #endif
- :: DoDataExchange( pDX );
- //{{AFX_DATA_MAP(CExtNCW)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP( CExtMsgBox, CExtResizableDialog )
- //{{AFX_MSG_MAP(CExtShellDialogCreateFolder)
- //}}AFX_MSG_MAP
- ON_WM_TIMER()
- END_MESSAGE_MAP()
- UINT CExtMsgBox::MsgBoxStyleGet() const
- {
- ASSERT_VALID( this );
- return m_nMsgBoxStyle;
- }
- void CExtMsgBox::MsgBoxStyleSet( UINT nMsgBoxStyle )
- {
- ASSERT_VALID( this );
- m_nMsgBoxStyle = nMsgBoxStyle;
- }
- UINT CExtMsgBox::MsgBoxStyleExGet() const
- {
- ASSERT_VALID( this );
- return m_nMsgBoxStyleEx;
- }
- void CExtMsgBox::MsgBoxStyleExSet( UINT nMsgBoxStyleEx )
- {
- ASSERT_VALID( this );
- m_nMsgBoxStyleEx = nMsgBoxStyleEx;
- }
- INT CExtMsgBox::MinEditCtrlHeightGet() const
- {
- ASSERT_VALID( this );
- return m_nMinEditCtrlHeight;
- }
- void CExtMsgBox::MinEditCtrlHeightSet( INT nMinEditCtrlHeight )
- {
- ASSERT_VALID( this );
- m_nMinEditCtrlHeight = nMinEditCtrlHeight;
- }
- INT CExtMsgBox::MaxEditCtrlHeightGet() const
- {
- ASSERT_VALID( this );
- return m_nMaxEditCtrlHeight;
- }
- void CExtMsgBox::MaxEditCtrlHeightSet( INT nMaxEditCtrlHeight )
- {
- ASSERT_VALID( this );
- m_nMaxEditCtrlHeight = nMaxEditCtrlHeight;
- }
- CExtSafeString CExtMsgBox::MessageGet() const
- {
- ASSERT_VALID( this );
- return m_strMessageText;
- }
- void CExtMsgBox::MessageSet( __EXT_MFC_SAFE_LPCTSTR strMessageText )
- {
- ASSERT_VALID( this );
- m_strMessageText = ( strMessageText == NULL ) ? _T("") : LPCTSTR(strMessageText);
- }
- void CExtMsgBox::MessageSet( UINT nMessageResourceID )
- {
- ASSERT_VALID( this );
- CExtSafeString str;
- VERIFY( g_ResourceManager->LoadString( str, nMessageResourceID ) );
- MessageSet( LPCTSTR(str) );
- }
- CExtSafeString CExtMsgBox::CaptionGet() const
- {
- ASSERT_VALID( this );
- return m_strCaption;
- }
- void CExtMsgBox::CaptionSet( __EXT_MFC_SAFE_LPCTSTR strCaption )
- {
- ASSERT_VALID( this );
- m_strCaption = ( strCaption == NULL ) ? _T("") : LPCTSTR(strCaption);
- }
- void CExtMsgBox::CaptionSet( UINT nCaptionResourceID )
- {
- ASSERT_VALID( this );
- CExtSafeString str;
- VERIFY( g_ResourceManager->LoadString( str, nCaptionResourceID ) );
- CaptionSet( LPCTSTR(str) );
- }
- UINT CExtMsgBox::TimeoutGet(
- bool * p_bIsDisabled // = NULL
- ) const
- {
- ASSERT_VALID( this );
- if( p_bIsDisabled != NULL )
- (*p_bIsDisabled) = m_bIsDisabledTimeout;
- return m_nTimeoutSeconds;
- }
- void CExtMsgBox::TimeoutSet(
- UINT nTimeoutSeconds,
- bool bIsDisabledTimeout // = false
- )
- {
- ASSERT_VALID( this );
- m_nTimeoutSeconds = nTimeoutSeconds;
- m_bIsDisabledTimeout = bIsDisabledTimeout;
- }
- bool CExtMsgBox::IsDisabledTimeout() const
- {
- ASSERT_VALID( this );
- bool bIsDisabledTimeout = true;
- TimeoutGet( &bIsDisabledTimeout );
- return bIsDisabledTimeout;
- }
- bool CExtMsgBox::OnMsgBoxTimeoutDecrease()
- {
- bool bIsDisabledTimeout = true;
- UINT nTimeoutSeconds = TimeoutGet( &bIsDisabledTimeout );
- if( nTimeoutSeconds == 0 )
- return true;
- nTimeoutSeconds --;
- TimeoutSet( nTimeoutSeconds, bIsDisabledTimeout );
- if( nTimeoutSeconds == 0 )
- return true;
- else
- return false;
- }
- __EXT_MFC_INT_PTR CExtMsgBox::DoModal()
- {
- __PROF_UIS_MANAGE_STATE;
- ASSERT_VALID( this );
- UINT nMsgBoxStyle = MsgBoxStyleGet();
- if( ( nMsgBoxStyle & (__EXT_MB_DO_NOT_DISPLAY_AGAIN|__EXT_MB_DO_NOT_ASK_AGAIN) ) != 0 )
- {
- CExtSafeString strRegVarName = OnMsgBoxGetRegVarName();
- int nResult = ::AfxGetApp()->GetProfileInt( g_strRegSectionName, LPCTSTR(strRegVarName), (-1) );
- if( nResult != (-1) )
- return nResult;
- }
- __EXT_MFC_INT_PTR nRetVal = (__EXT_MFC_INT_PTR)m_nEscapeButtonDlgCtrlID;
- const WORD nDlgItems = 0;
- DLGTEMPLATE dlgTmpl;
- dlgTmpl.x = 0;
- dlgTmpl.y = 0;
- dlgTmpl.cx = 225;
- dlgTmpl.cy = 152;
- dlgTmpl.style = WS_CAPTION|WS_POPUP|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_SYSMENU|DS_3DLOOK|DS_MODALFRAME|DS_SETFONT;
- bool bRTL = ( (g_ResourceManager->OnQueryLangLayout()&LAYOUT_RTL) != 0 ) ? true : false;
- dlgTmpl.dwExtendedStyle = bRTL ? WS_EX_LAYOUTRTL : 0;
- dlgTmpl.cdit = nDlgItems; // nDlgItems dialog items in the dialog
- // The first step is to allocate memory to define the dialog. The information to be stored in the allocated buffer is the following:
- // 1. DLGTEMPLATE structure
- // 2. 0x0000 (Word) indicating the dialog has no menu
- // 3. 0x0000 (Word) Let windows assign default class to the dialog
- // 4. (Caption) Null terminated UNICODE string
- WCHAR szBoxCaption[] = L"";
- WCHAR szFontName[] = L"MS Sans Serif";
- TRY
- {
- // The following expressions have unnecessary parenthesis trying to make the comments more clear.
- int nBufferSize = sizeof(DLGTEMPLATE) + (2 * sizeof(WORD)) /*menu and class*/ + sizeof(szBoxCaption);
- nBufferSize += sizeof(WORD) + sizeof(szFontName); /* font information*/
- HLOCAL hLocal = ::LocalAlloc( LHND, nBufferSize );
- if( hLocal == NULL )
- ::AfxThrowMemoryException();
- BYTE * pBuffer = (BYTE*)::LocalLock( hLocal );
- if( pBuffer == NULL )
- {
- ::LocalFree( hLocal );
- ::AfxThrowMemoryException();
- }
- BYTE * pdest = pBuffer;
- // transfer DLGTEMPLATE structure to the buffer
- __EXT_MFC_MEMCPY( pdest, nBufferSize, &dlgTmpl, sizeof(DLGTEMPLATE) );
- pdest += sizeof(DLGTEMPLATE);
- *(WORD*)pdest = 0; // no menu
- *(WORD*)(pdest + sizeof(WORD)) = 0; // use default window class
- pdest += 2 * sizeof(WORD);
- __EXT_MFC_MEMCPY( pdest, nBufferSize, szBoxCaption, sizeof(szBoxCaption) );
- pdest += sizeof(szBoxCaption);
- *(WORD*)pdest = 8; // font size
- pdest += sizeof(WORD);
- __EXT_MFC_MEMCPY( pdest, nBufferSize, szFontName, sizeof(szFontName) );
- pdest += sizeof(szFontName);
- HWND hWndParent = m_hWndParentFromCTOR;
- if( hWndParent == NULL || (! ::IsWindow( hWndParent ) ) )
- hWndParent = ::AfxGetMainWnd() -> GetSafeHwnd();
- InitModalIndirect( (DLGTEMPLATE*)pBuffer, CWnd::FromHandle( hWndParent ) );
- #if (defined _DEBUG)
- #if (_MFC_VER < 0x700)
- CWinThread * pWT = ::AfxGetThread();
- int nSavedWTDisablePumpCount = pWT->m_nDisablePumpCount;
- pWT->m_nDisablePumpCount = 0;
- #else
- _AFX_THREAD_STATE * pATH = ::AfxGetThreadState();
- int nSavedWTDisablePumpCount = pATH->m_nDisablePumpCount;
- pATH->m_nDisablePumpCount = 0;
- #endif
- #endif
- nRetVal = CDialog::DoModal();
- #if (defined _DEBUG)
- #if (_MFC_VER < 0x700)
- pWT->m_nDisablePumpCount = nSavedWTDisablePumpCount;
- #else
- pATH->m_nDisablePumpCount = nSavedWTDisablePumpCount;
- #endif
- #endif
- ::LocalUnlock( hLocal );
- ::LocalFree( hLocal );
- }
- CATCH( CMemoryException, e)
- {
- TRACE0("Memory allocation for dialog template failed in CExtMsgBox::DoModal().");
- }
- END_CATCH
- return nRetVal;
- }
- void CExtMsgBox::EndDialog( int nResult )
- {
- ASSERT_VALID( this );
- bool bDoNotDisplayAgain = false;
- CExtCheckBox * pWndCheckBoxDoNotDisplayAgain = DYNAMIC_DOWNCAST( CExtCheckBox, GetDlgItem( ID_EXT_MBB_CHECK_BOX ) );
- if( pWndCheckBoxDoNotDisplayAgain != NULL )
- {
- ASSERT_VALID( pWndCheckBoxDoNotDisplayAgain );
- bDoNotDisplayAgain = ( pWndCheckBoxDoNotDisplayAgain->GetCheck() == BST_CHECKED ) ? true : false;
- }
- UINT nMsgBoxStyle = MsgBoxStyleGet();
- if( ( ( nMsgBoxStyle & __EXT_MB_DO_NOT_DISPLAY_AGAIN ) != 0 && bDoNotDisplayAgain )
- || ( ( nMsgBoxStyle & __EXT_MB_DO_NOT_ASK_AGAIN ) != 0 && bDoNotDisplayAgain )
- )
- {
- CExtSafeString strRegVarName = OnMsgBoxGetRegVarName();
- ::AfxGetApp()->WriteProfileInt( g_strRegSectionName, LPCTSTR(strRegVarName), nResult );
- }
- if( m_bDynamicIcon )
- {
- m_bmpIcon.Empty();
- m_bDynamicIcon = false;
- }
- #if ( _MFC_VER == 0x700 )
- CExtResizableDialog
- #else
- CExtNCW < CExtResizableDialog >
- #endif
- :: EndDialog(nResult);
- }
- BOOL CExtMsgBox::OnInitDialog()
- {
- if ( !
- #if ( _MFC_VER == 0x700 )
- CExtResizableDialog
- #else
- CExtNCW < CExtResizableDialog >
- #endif
- :: OnInitDialog()
- )
- return FALSE;
- ModifyStyle( 0, WS_CLIPCHILDREN|WS_CLIPSIBLINGS );
- SetWindowText( LPCTSTR(CaptionGet()) );
- SetHelpID( m_nHelpID );
- OnMsgBoxRegisterButtons();
- VERIFY( OnMsgBoxCreateIconLabel() );
- VERIFY( OnMsgBoxCreateMessageLabel() );
- VERIFY( OnMsgBoxCreateCheckBox() );
- VERIFY( OnMsgBoxCreateButtons() );
- SubclassChildControls();
- OnMsgBoxLayout();
- UINT nMsgBoxStyle = MsgBoxStyleGet();
- if( ( nMsgBoxStyle & __EXT_MB_NO_SOUND ) == 0 )
- {
- UINT nMsgBoxIconType = nMsgBoxStyle & __EXT_MB_ICONMASK;
- MessageBeep( nMsgBoxIconType );
- }
- if( ( nMsgBoxStyle & __EXT_MB_SYSTEMMODAL ) != 0 )
- ModifyStyle(0, DS_SYSMODAL);
- if( ( nMsgBoxStyle & __EXT_MB_SETFOREGROUND ) != 0 )
- SetForegroundWindow();
- if( ( nMsgBoxStyle & __EXT_MB_TOPMOST ) != 0 )
- ModifyStyleEx(0, WS_EX_TOPMOST);
- if( m_nEscapeButtonDlgCtrlID == UINT(IDC_STATIC) )
- GetSystemMenu( FALSE ) -> EnableMenuItem( SC_CLOSE, MF_GRAYED );
- bool bIsDisabledTimeout = true;
- UINT nTimeoutSeconds = TimeoutGet( &bIsDisabledTimeout );
- if( nTimeoutSeconds > 0 )
- {
- if( bIsDisabledTimeout )
- {
- INT nButtonIndex, nButtonsCount( INT( m_arrMsgBoxButtons.GetSize() ) );
- for( nButtonIndex = 0; nButtonIndex < nButtonsCount; nButtonIndex ++ )
- {
- CWnd * pWndButton = GetDlgItem( m_arrMsgBoxButtons[ nButtonIndex ] -> m_nButtonDlgCtrlID );
- if( pWndButton != NULL )
- {
- ASSERT_VALID( pWndButton );
- pWndButton->EnableWindow( FALSE );
- }
- }
- CExtCheckBox * pWndCheckBoxDoNotDisplayAgain = DYNAMIC_DOWNCAST( CExtCheckBox, GetDlgItem( ID_EXT_MBB_CHECK_BOX ) );
- if( pWndCheckBoxDoNotDisplayAgain != NULL )
- {
- ASSERT_VALID( pWndCheckBoxDoNotDisplayAgain );
- pWndCheckBoxDoNotDisplayAgain->EnableWindow( FALSE );
- }
- }
- m_nTimeoutTimer = (UINT)SetTimer( 678, 1000, NULL );
- }
- if( m_nDefaultButtonDlgCtrlID != UINT(IDC_STATIC) )
- {
- CWnd * pWndButton = GetDlgItem( m_nDefaultButtonDlgCtrlID );
- if( pWndButton != NULL )
- {
- ASSERT_VALID( pWndButton );
- pWndButton->SetFocus();
- }
- //SetDefID( m_nDefaultButtonDlgCtrlID );
- return FALSE; // focus is set
- }
- return TRUE;
- }
- BOOL CExtMsgBox::OnCmdMsg( UINT nID, int nCode, void * pExtra, AFX_CMDHANDLERINFO * pHandlerInfo )
- {
- ASSERT_VALID( this );
- if( ( nID == ID_EXT_MBB_HELP ) && ( nCode == CN_COMMAND ) )
- {
- OnMsgBoxHelp();
- return TRUE;
- }
- if( ( nID != UINT(IDC_STATIC) ) && ( nID != ID_EXT_MBB_CHECK_BOX ) && ( nCode == CN_COMMAND ) )
- {
- if( nID == ID_EXT_MBB_EX_COPY_BUTTON )
- OnMsgBoxCopyToClipboard();
- else
- EndDialog( nID );
- return TRUE;
- }
- return
- #if ( _MFC_VER == 0x700 )
- CExtResizableDialog
- #else
- CExtNCW < CExtResizableDialog >
- #endif
- :: OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
- }
- BOOL CExtMsgBox::PreTranslateMessage( MSG * pMsg )
- {
- if( pMsg->message == WM_KEYDOWN )
- {
- bool bIsDisabledTimeout = true;
- UINT nTimeoutSeconds = TimeoutGet( &bIsDisabledTimeout );
- if ( bIsDisabledTimeout && nTimeoutSeconds > 0 )
- return TRUE;
- if( pMsg->wParam == VK_RETURN )
- {
- CWnd * pFocusWnd = GetFocus();
- if( pFocusWnd != NULL )
- {
- UINT nDlgCtrlID = UINT( pFocusWnd->GetDlgCtrlID() );
- INT nButtonIndex, nButtonsCount( INT( m_arrMsgBoxButtons.GetSize() ) );
- for( nButtonIndex = 0; nButtonIndex < nButtonsCount; nButtonIndex ++ )
- {
- if ( m_arrMsgBoxButtons[ nButtonIndex ] -> m_nButtonDlgCtrlID == nDlgCtrlID )
- {
- m_nDefaultButtonDlgCtrlID = nDlgCtrlID;
- break;
- }
- }
- EndDialog( m_nDefaultButtonDlgCtrlID );
- return TRUE;
- }
- }
- else if( pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_CANCEL )
- {
- if( m_nEscapeButtonDlgCtrlID != UINT(IDC_STATIC) )
- EndDialog( m_nEscapeButtonDlgCtrlID );
- return TRUE;
- }
- else if(
- ( pMsg->wParam == WPARAM('C') || pMsg->wParam == VK_INSERT )
- && ( HIWORD(pMsg->lParam) & KF_ALTDOWN ) == 0
- && ( ::GetKeyState(VK_SHIFT) & 0x80000000 ) == 0
- && ( ::GetKeyState(VK_CONTROL) & 0x80000000 ) != 0
- )
- {
- UINT nMsgBoxStyleEx = MsgBoxStyleExGet();
- if( ( nMsgBoxStyleEx & __EXT_MB_EX_DISABLE_KEYBOARD_COPY_ACCEL ) == 0 )
- OnMsgBoxCopyToClipboard();
- return TRUE;
- }
- else if( pMsg->wParam == VK_F1 )
- {
- UINT nMsgBoxStyle = MsgBoxStyleExGet();
- if( ( nMsgBoxStyle & __EXT_MB_HELP ) != 0 )
- OnMsgBoxHelp();
- return TRUE;
- }
- }
- return
- #if ( _MFC_VER == 0x700 )
- CExtResizableDialog
- #else
- CExtNCW < CExtResizableDialog >
- #endif
- :: PreTranslateMessage( pMsg );
- }
- void CExtMsgBox::OnTimer( __EXT_MFC_UINT_PTR nIDEvent )
- {
- if( nIDEvent == 678 )
- {
- INT nButtonIndex, nButtonsCount( INT( m_arrMsgBoxButtons.GetSize() ) );
- if( OnMsgBoxTimeoutDecrease() )
- {
- KillTimer( m_nTimeoutTimer );
- if ( IsDisabledTimeout() )
- {
- for( nButtonIndex = 0; nButtonIndex < nButtonsCount; nButtonIndex ++ )
- {
- CWnd * pWndButton = GetDlgItem( m_arrMsgBoxButtons[ nButtonIndex ] -> m_nButtonDlgCtrlID );
- if( pWndButton != NULL )
- {
- ASSERT_VALID( pWndButton );
- pWndButton->EnableWindow( TRUE );
- }
- }
- CExtCheckBox * pWndCheckBoxDoNotDisplayAgain = DYNAMIC_DOWNCAST( CExtCheckBox, GetDlgItem( ID_EXT_MBB_CHECK_BOX ) );
- if( pWndCheckBoxDoNotDisplayAgain != NULL )
- {
- ASSERT_VALID( pWndCheckBoxDoNotDisplayAgain );
- pWndCheckBoxDoNotDisplayAgain->EnableWindow( TRUE );
- }
- }
- else
- EndDialog( m_nDefaultButtonDlgCtrlID );
- }
- for( nButtonIndex = 0; nButtonIndex < nButtonsCount; nButtonIndex ++ )
- {
- if ( m_arrMsgBoxButtons[ nButtonIndex ] -> m_nButtonDlgCtrlID == m_nDefaultButtonDlgCtrlID )
- {
- CExtSafeString strButtonText = m_arrMsgBoxButtons[ nButtonIndex ] -> m_strCaption;
- CExtSafeString strFullText = strButtonText;
- UINT nTimeoutSeconds = TimeoutGet();
- if( nTimeoutSeconds > 0 )
- strFullText.Format( _T("%s = %d"), strButtonText, nTimeoutSeconds );
- CWnd * pWndButton = GetDlgItem( m_arrMsgBoxButtons[ nButtonIndex ] -> m_nButtonDlgCtrlID );
- if( pWndButton != NULL )
- {
- ASSERT_VALID( pWndButton );
- pWndButton->SetWindowText( strFullText );
- }
- }
- }
- }
- #if ( _MFC_VER == 0x700 )
- CExtResizableDialog
- #else
- CExtNCW < CExtResizableDialog >
- #endif
- :: OnTimer( nIDEvent );
- }
- BOOL CExtMsgBox::OnWndMsg( UINT message, WPARAM wParam, LPARAM lParam, LRESULT * pResult )
- {
- ASSERT_VALID( this );
- if ( message == WM_CLOSE )
- {
- bool bIsDisabledTimeout = true;
- UINT nTimeoutSeconds = TimeoutGet( &bIsDisabledTimeout );
- if ( bIsDisabledTimeout && nTimeoutSeconds > 0 )
- return TRUE;
- if( m_nEscapeButtonDlgCtrlID != UINT(IDC_STATIC) )
- EndDialog( m_nEscapeButtonDlgCtrlID );
- return TRUE;
- }
- return
- #if ( _MFC_VER == 0x700 )
- CExtResizableDialog
- #else
- CExtNCW < CExtResizableDialog >
- #endif
- :: OnWndMsg( message, wParam, lParam, pResult );
- }
- void CExtMsgBox::RegisterButton(
- UINT nButtonDlgCtrlID,
- __EXT_MFC_SAFE_LPCTSTR strCaption,
- bool bIsDefault, // = false
- bool bIsEscape // = false
- )
- {
- ASSERT_VALID( this );
- msgbox_button_info_t * p_mbbi = new msgbox_button_info_t( nButtonDlgCtrlID, strCaption );
- m_arrMsgBoxButtons.Add( p_mbbi );
- if( bIsDefault )
- m_nDefaultButtonDlgCtrlID = nButtonDlgCtrlID;
- if( bIsEscape )
- m_nEscapeButtonDlgCtrlID = nButtonDlgCtrlID;
- }
- void CExtMsgBox::RegisterButton(
- UINT nButtonDlgCtrlID,
- UINT nCaptionResourceID,
- bool bIsDefault, // = false
- bool bIsEscape // = false
- )
- {
- ASSERT_VALID( this );
- CExtSafeString strCaption;
- VERIFY( g_ResourceManager->LoadString( strCaption, nCaptionResourceID ) );
- RegisterButton( nButtonDlgCtrlID, LPCTSTR(strCaption), bIsDefault, bIsEscape );
- }
- void CExtMsgBox::UnRegisterAllButtons()
- {
- ASSERT_VALID( this );
- INT nButtonIndex, nButtonsCount( INT( m_arrMsgBoxButtons.GetSize() ) );
- for( nButtonIndex = 0; nButtonIndex < nButtonsCount; nButtonIndex ++ )
- {
- msgbox_button_info_t * p_mbbi = m_arrMsgBoxButtons[ nButtonIndex ];
- ASSERT( p_mbbi != NULL );
- delete p_mbbi;
- }
- m_arrMsgBoxButtons.RemoveAll();
- }
- CExtSafeString CExtMsgBox::OnMsgBoxGetRegVarName() const // for __EXT_MB_DO_NOT_DISPLAY_AGAIN and __EXT_MB_DO_NOT_ASK_AGAIN
- {
- ASSERT_VALID( this );
- CExtSafeString strMessageText = MessageGet();
- INT nChar, nLen = INT( strMessageText.GetLength() ), nChecksum = 0;
- for( nChar = 0; nChar < nLen; nChar++ )
- nChecksum += INT(strMessageText.GetAt(nChar)) * nChar;
- CExtSafeString strRegVarName;
- strRegVarName.Format(
- _T("msgbox-%s-helpid-%d-chksum-%d"),
- m_strUniqueID.IsEmpty() ? _T("not-unique") : LPCTSTR(m_strUniqueID),
- m_nHelpID,
- nChecksum
- );
- return strRegVarName;
- }
- void CExtMsgBox::OnMsgBoxRegisterButtons()
- {
- ASSERT_VALID( this );
- UINT nMsgBoxStyle = MsgBoxStyleGet();
- UINT nMsgBoxStyleEx = MsgBoxStyleExGet();
- if( ( nMsgBoxStyleEx & (__EXT_MB_EX_COPY_BUTTON|__EXT_MB_EX_COPY_BTN_FIRST) ) == (__EXT_MB_EX_COPY_BUTTON|__EXT_MB_EX_COPY_BTN_FIRST) )
- RegisterButton( ID_EXT_MBB_EX_COPY_BUTTON, IDS_EX_MB_EX_COPY_BUTTON );
- UINT nMsgBoxType = nMsgBoxStyle & __EXT_MB_TYPEMASK;
- switch( nMsgBoxType )
- {
- case __EXT_MB_OKCANCEL:
- RegisterButton( ID_EXT_MBB_OK, IDS_EX_MB_OK, true );
- RegisterButton( ID_EXT_MBB_CANCEL, IDS_EX_MB_CANCEL, false, true );
- break;
- case __EXT_MB_ABORTRETRYIGNORE:
- RegisterButton( ID_EXT_MBB_ABORT, IDS_EX_MB_ABORT, true );
- RegisterButton( ID_EXT_MBB_RETRY, IDS_EX_MB_RETRY );
- RegisterButton( ID_EXT_MBB_IGNORE, IDS_EX_MB_IGNORE );
- break;
- case __EXT_MB_YESNOCANCEL:
- RegisterButton( ID_EXT_MBB_YES, IDS_EX_MB_YES, true );
- if( ( nMsgBoxStyle & __EXT_MB_YES_TO_ALL ) != 0 )
- RegisterButton( ID_EXT_MBB_YES_TO_ALL, IDS_EX_MB_YES_TO_ALL );
- RegisterButton( ID_EXT_MBB_NO, IDS_EX_MB_NO );
- if( ( nMsgBoxStyle & __EXT_MB_NO_TO_ALL ) != 0 )
- RegisterButton( ID_EXT_MBB_NO_TO_ALL, IDS_EX_MB_NO_TO_ALL );
- RegisterButton( ID_EXT_MBB_CANCEL, IDS_EX_MB_CANCEL, false, true );
- break;
- case __EXT_MB_YESNO:
- RegisterButton( ID_EXT_MBB_YES, IDS_EX_MB_YES, true );
- if( ( nMsgBoxStyle & __EXT_MB_YES_TO_ALL ) != 0 )
- RegisterButton( ID_EXT_MBB_YES_TO_ALL, IDS_EX_MB_YES_TO_ALL );
- RegisterButton( ID_EXT_MBB_NO, IDS_EX_MB_NO );
- if( ( nMsgBoxStyle & __EXT_MB_NO_TO_ALL ) != 0 )
- RegisterButton( ID_EXT_MBB_NO_TO_ALL, IDS_EX_MB_NO_TO_ALL );
- break;
- case __EXT_MB_RETRYCANCEL:
- RegisterButton( ID_EXT_MBB_RETRY, IDS_EX_MB_RETRY, true );
- RegisterButton( ID_EXT_MBB_CANCEL, IDS_EX_MB_CANCEL, false, true );
- break;
- case __EXT_MB_CANCELTRYCONTINUE:
- RegisterButton( ID_EXT_MBB_CANCEL, IDS_EX_MB_CANCEL, true, true );
- RegisterButton( ID_EXT_MBB_TRY_AGAIN, IDS_EX_MB_RETRY );
- RegisterButton( ID_EXT_MBB_CONTINUE, IDS_EX_MB_CONTINUE );
- break;
- case __EXT_MB_CONTINUEABORT:
- RegisterButton( ID_EXT_MBB_CONTINUE, IDS_EX_MB_CONTINUE, true );
- RegisterButton( ID_EXT_MBB_ABORT, IDS_EX_MB_ABORT );
- break;
- case __EXT_MB_SKIPSKIPALLCANCEL:
- RegisterButton( ID_EXT_MBB_SKIP, IDS_EX_MB_SKIP, true );
- RegisterButton( ID_EXT_MBB_SKIP_ALL, IDS_EX_MB_SKIPALL );
- RegisterButton( ID_EXT_MBB_CANCEL, IDS_EX_MB_CANCEL, false, true );
- break;
- case __EXT_MB_IGNOREIGNOREALLCANCEL:
- RegisterButton( ID_EXT_MBB_IGNORE, IDS_EX_MB_IGNORE, true );
- RegisterButton( ID_EXT_MBB_IGNORE_ALL, IDS_EX_MB_IGNOREALL );
- RegisterButton( ID_EXT_MBB_CANCEL, IDS_EX_MB_CANCEL, FALSE, true );
- break;
- case __EXT_MB_OK:
- default:
- RegisterButton( ID_EXT_MBB_OK, IDS_EX_MB_OK, true, true );
- break;
- }
- if( ( nMsgBoxStyle & __EXT_MB_HELP ) != 0 )
- RegisterButton( ID_EXT_MBB_HELP, IDS_EX_MB_HELP );
- if( ( nMsgBoxStyleEx & (__EXT_MB_EX_COPY_BUTTON|__EXT_MB_EX_COPY_BTN_FIRST) ) == __EXT_MB_EX_COPY_BUTTON )
- RegisterButton( ID_EXT_MBB_EX_COPY_BUTTON, IDS_EX_MB_EX_COPY_BUTTON );
- UINT nDefStyle = nMsgBoxStyle & __EXT_MB_DEFMASK;
- if( nDefStyle != 0 )
- {
- int nDefaultIndex = 0;
- switch( nDefStyle )
- {
- case __EXT_MB_DEFBUTTON1: nDefaultIndex = 0; break;
- case __EXT_MB_DEFBUTTON2: nDefaultIndex = 1; break;
- case __EXT_MB_DEFBUTTON3: nDefaultIndex = 2; break;
- case __EXT_MB_DEFBUTTON4: nDefaultIndex = 3; break;
- case __EXT_MB_DEFBUTTON5: nDefaultIndex = 4; break;
- case __EXT_MB_DEFBUTTON6: nDefaultIndex = 5; break;
- }
- if ( m_arrMsgBoxButtons.GetSize() >= ( nDefaultIndex + 1 ) )
- m_nDefaultButtonDlgCtrlID = m_arrMsgBoxButtons[ nDefaultIndex ] -> m_nButtonDlgCtrlID;
- }
- m_bDynamicIcon = m_bmpIcon.IsEmpty() ? true : false;
- if( m_bDynamicIcon )
- {
- UINT nMsgBoxIconType = nMsgBoxStyle & __EXT_MB_ICONMASK;
- if( nMsgBoxIconType != 0 )
- {
- LPCTSTR strStdIconID = NULL;
- switch( nMsgBoxIconType )
- {
- case __EXT_MB_ICONEXCLAMATION: strStdIconID = IDI_EXCLAMATION; break;
- case __EXT_MB_ICONHAND: strStdIconID = IDI_HAND; break;
- case __EXT_MB_ICONQUESTION: strStdIconID = IDI_QUESTION; break;
- case __EXT_MB_ICONASTERISK: strStdIconID = IDI_ASTERISK; break;
- }
- if( strStdIconID != NULL )
- {
- HICON hIcon = ::AfxGetApp() -> LoadStandardIcon( strStdIconID );
- if( hIcon != NULL )
- {
- m_bmpIcon.AssignFromHICON( hIcon );
- ::DestroyIcon( hIcon );
- }
- }
- }
- }
- m_bDynamicIcon = m_bmpIcon.IsEmpty() ? true : false;
- }
- bool CExtMsgBox::OnMsgBoxCreateIconLabel()
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- if( m_bmpIcon.IsEmpty() )
- return true;
- CRect rc( 0, 0, 0, 0 );
- DWORD dwStyle =
- WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_DISABLED
- |SS_CENTER|SS_CENTERIMAGE;
- if( ! m_wndLabelMsgBoxIcon.Create( NULL, dwStyle, rc, this, UINT(IDC_STATIC) ) )
- return false;
- m_wndLabelMsgBoxIcon.SetBitmapEx( &m_bmpIcon );
- m_wndLabelMsgBoxIcon.SetImageMode( CExtLabel::eAlign );
- return true;
- }
- bool CExtMsgBox::OnMsgBoxCreateMessageLabel()
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- CDC dcDisplay;
- if( ! dcDisplay.CreateDC(_T("DISPLAY"), NULL, NULL, NULL) )
- return false;
- UINT nMsgBoxStyle = MsgBoxStyleGet();
- UINT nMsgBoxStyleEx = MsgBoxStyleExGet();
- CFont * pOldFont = dcDisplay.SelectObject( GetFont() );
- int nMaxWidth = ( ::GetSystemMetrics( SM_CXSCREEN ) / 2 ) + 100;
- CSize sizeIcon = m_bmpIcon.GetSize();
- if( sizeIcon.cx > 0 )
- nMaxWidth -= sizeIcon.cx + 2 * _DLU2PxHorz( m_sizeBorder.cx );
- CRect rcMessage( 0, 0, nMaxWidth, nMaxWidth );
- dcDisplay.DrawText( LPCTSTR(m_strMessageText), m_strMessageText.GetLength(), rcMessage, DT_LEFT|DT_NOPREFIX|DT_WORDBREAK|DT_EXPANDTABS|DT_CALCRECT );
- m_sizeMessageText = rcMessage.Size();
- dcDisplay.SelectObject( pOldFont );
- dcDisplay.DeleteDC();
- if( ( nMsgBoxStyleEx & __EXT_MB_EX_USE_EDIT_CONTROL ) != 0 )
- {
- if( ( nMsgBoxStyleEx & __EXT_MB_EX_SCROLLABLE_EDIT ) !=0 )
- m_sizeMessageText.cx += ::GetSystemMetrics( SM_CXVSCROLL );
- INT nMinEditCtrlHeight = MinEditCtrlHeightGet();
- if( nMinEditCtrlHeight > 0 )
- m_sizeMessageText.cy = max( m_sizeMessageText.cy, nMinEditCtrlHeight );
- INT nMaxEditCtrlHeight = MaxEditCtrlHeightGet();
- if( nMaxEditCtrlHeight > 0 )
- m_sizeMessageText.cy = min( m_sizeMessageText.cy, nMaxEditCtrlHeight );
- }
- CRect rc( 0, 0, 0, 0 );
- DWORD dwStyle = WS_CHILD|WS_VISIBLE;
- CExtSafeString strMessageText = MessageGet();
- if( ( nMsgBoxStyleEx & __EXT_MB_EX_USE_EDIT_CONTROL ) != 0 )
- {
- if( ( nMsgBoxStyle & __EXT_MB_RIGHT ) != 0 )
- dwStyle |= ES_RIGHT;
- else
- dwStyle |= ES_LEFT;
- dwStyle |=
- WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_TABSTOP
- |ES_MULTILINE|ES_NOHIDESEL|ES_READONLY|ES_AUTOVSCROLL;
- if( ( nMsgBoxStyleEx & __EXT_MB_EX_SCROLLABLE_EDIT ) != 0 )
- dwStyle |= WS_VSCROLL;
- if( ! m_wndEditMsgBoxMessageText.Create( dwStyle, rc, this, UINT(IDC_STATIC) ) )
- return false;
- if( m_clrEditorText != COLORREF(-1L) )
- m_wndEditMsgBoxMessageText.SetTextColor( m_clrEditorText );
- if( m_clrEditorBkgnd != COLORREF(-1L) )
- m_wndEditMsgBoxMessageText.SetBkColor( m_clrEditorBkgnd );
- if( ( nMsgBoxStyle & __EXT_MB_RTLREADING ) != 0 )
- m_wndEditMsgBoxMessageText.ModifyStyleEx( 0, WS_EX_RTLREADING );
- m_wndEditMsgBoxMessageText.SetFont( GetFont() );
- m_wndEditMsgBoxMessageText.SetWindowText( LPCTSTR(strMessageText) );
- }
- else
- {
- dwStyle |= SS_NOPREFIX;
- if( ( nMsgBoxStyle & __EXT_MB_RIGHT ) != 0 )
- dwStyle |= SS_RIGHT;
- else
- dwStyle |= SS_LEFT;
- if( ! m_wndLabelMsgBoxMessageText.Create( LPCTSTR(strMessageText), dwStyle|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, rc, this, UINT(IDC_STATIC) ) )
- return false;
- if( ( nMsgBoxStyle & __EXT_MB_RTLREADING ) != 0 )
- m_wndLabelMsgBoxMessageText.ModifyStyleEx( 0, WS_EX_RTLREADING );
- m_wndLabelMsgBoxMessageText.SetFont( GetFont() );
- }
- return true;
- }
- bool CExtMsgBox::OnMsgBoxCreateCheckBox()
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- UINT nMsgBoxStyle = MsgBoxStyleGet();
- UINT nMsgBoxStyleEx = MsgBoxStyleExGet();
- if( ( nMsgBoxStyle & (__EXT_MB_DO_NOT_DISPLAY_AGAIN|__EXT_MB_DO_NOT_ASK_AGAIN) ) != 0 )
- {
- CExtSafeString strCheckboxCaption;
- if( ( nMsgBoxStyle & __EXT_MB_DO_NOT_DISPLAY_AGAIN ) != 0 )
- {
- VERIFY( g_ResourceManager->LoadString( strCheckboxCaption, IDS_EX_MB_DO_NOT_DISPLAY_AGAIN ) );
- }
- else if( ( nMsgBoxStyle & __EXT_MB_DO_NOT_ASK_AGAIN ) != 0 )
- {
- VERIFY( g_ResourceManager->LoadString( strCheckboxCaption, IDS_EX_MB_DO_NOT_ASK_AGAIN ) );
- }
- CClientDC dc( this );
- CFont * pWndFont = GetFont();
- CFont * pOldFont = dc.SelectObject( pWndFont );
- m_sizeCheckBox = dc.GetTextExtent( LPCTSTR(strCheckboxCaption), strCheckboxCaption.GetLength() );
- m_sizeCheckBox.cx += _DLU2PxHorz( m_nCheckBoxGap );
- dc.SelectObject( pOldFont );
- CRect rc( 0, 0, 0, 0 );
- CButton wnd;
- if( ! wnd.Create( LPCTSTR(strCheckboxCaption), WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_TABSTOP|BS_AUTOCHECKBOX, rc, this, ID_EXT_MBB_CHECK_BOX ) )
- return false;
- if( ( nMsgBoxStyle & __EXT_MB_CHECK_BOX_PRESENT ) != 0 )
- wnd.SetCheck( ( ( nMsgBoxStyleEx & __EXT_MB_EX_CHECK_BOX_IS_NOT_CHECKED_INTIALLY ) == 0 ) ? BST_CHECKED : BST_UNCHECKED );
- wnd.SetFont( pWndFont );
- wnd.UnsubclassWindow();
- }
- return true;
- }
- bool CExtMsgBox::OnMsgBoxCreateButtons()
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- m_sizeButton.cx = _DLU2PxHorz( m_sizeStdButton.cx );
- m_sizeButton.cy = _DLU2PxVert( m_sizeStdButton.cy );
- CClientDC dc( this );
- CFont * pWndFont = GetFont();
- CFont * pOldFont = dc.SelectObject( pWndFont );
- CRect rc( 0, 0, 0, 0 );
- INT nButtonIndex, nButtonsCount( INT( m_arrMsgBoxButtons.GetSize() ) );
- for( nButtonIndex = 0; nButtonIndex < nButtonsCount; nButtonIndex ++ )
- {
- CExtSafeString strButtonCaption = m_arrMsgBoxButtons[ nButtonIndex ] -> m_strCaption;
- CExtSafeString strLengthTest = strButtonCaption;
- UINT nTimeoutSeconds = TimeoutGet();
- if ( nTimeoutSeconds > 0 )
- {
- CString strTimeoutText;
- strTimeoutText.Format( _T("%s = %d"), strLengthTest, nTimeoutSeconds );
- strLengthTest = strTimeoutText;
- }
- CSize sButtonText = dc.GetTextExtent( LPCTSTR(strLengthTest), strLengthTest.GetLength() );
- m_sizeButton.cx = max( m_sizeButton.cx, sButtonText.cx );
- m_sizeButton.cy = max( m_sizeButton.cy, sButtonText.cy );
- CButton wnd;
- if( ! wnd.Create(
- LPCTSTR(strButtonCaption),
- WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_TABSTOP
- | ( ( m_arrMsgBoxButtons[ nButtonIndex ] -> m_nButtonDlgCtrlID == m_nDefaultButtonDlgCtrlID ) ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON )
- ,
- rc,
- this,
- m_arrMsgBoxButtons[ nButtonIndex ] -> m_nButtonDlgCtrlID
- )
- )
- return false;
- wnd.SetFont( pWndFont );
- wnd.UnsubclassWindow();
- }
- m_sizeButton.cx += 2 * _DLU2PxHorz( m_sizeStdButtonBorder.cx );
- m_sizeButton.cy += 2 * _DLU2PxVert( m_sizeStdButtonBorder.cy );
- dc.SelectObject( pOldFont );
- return true;
- }
- void CExtMsgBox::OnMsgBoxHelp()
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- OnHelp();
- }
- void CExtMsgBox::OnMsgBoxLayout()
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- INT nButtonIndex, nButtonsCount( INT( m_arrMsgBoxButtons.GetSize() ) );
- CSize sizeBorderPX( _DLU2PxHorz( m_sizeBorder.cx ), _DLU2PxVert( m_sizeBorder.cy ) );
- CSize sizeClient = CSize( 2 * sizeBorderPX.cx, 2 * sizeBorderPX.cy );
- CPoint ptPos( sizeBorderPX.cx, sizeBorderPX.cy );
- CSize sizeIcon = m_bmpIcon.GetSize();
- if( sizeIcon.cx > 0 )
- {
- m_wndLabelMsgBoxIcon.MoveWindow( sizeBorderPX.cx, sizeBorderPX.cy, sizeIcon.cx, sizeIcon.cy );
- sizeClient.cx += sizeIcon.cx + sizeBorderPX.cx;
- sizeClient.cy += sizeIcon.cy + sizeBorderPX.cy;
- ptPos.x += sizeIcon.cx + sizeBorderPX.cx;
- }
- sizeClient.cx += m_sizeMessageText.cx + sizeBorderPX.cx;
- sizeClient.cy = max( sizeClient.cy, m_sizeMessageText.cy + 2 * sizeBorderPX.cy + _DLU2PxVert( m_sizeBorder.cy / 2 ) );
- if( m_wndLabelMsgBoxMessageText.GetSafeHwnd() != NULL )
- m_wndLabelMsgBoxMessageText.MoveWindow( ptPos.x, ptPos.y, m_sizeMessageText.cx, m_sizeMessageText.cy );
- if( m_wndEditMsgBoxMessageText.GetSafeHwnd() != NULL )
- m_wndEditMsgBoxMessageText.MoveWindow( ptPos.x, ptPos.y, m_sizeMessageText.cx, m_sizeMessageText.cy );
- ptPos.y += m_sizeMessageText.cy + sizeBorderPX.cy + _DLU2PxVert( m_sizeBorder.cy / 2 );
- UINT nMsgBoxStyle = MsgBoxStyleGet();
- if( ( nMsgBoxStyle & (__EXT_MB_DO_NOT_DISPLAY_AGAIN|__EXT_MB_DO_NOT_ASK_AGAIN) ) != 0 )
- {
- CExtCheckBox * pWndCheckBoxDoNotDisplayAgain = DYNAMIC_DOWNCAST( CExtCheckBox, GetDlgItem( ID_EXT_MBB_CHECK_BOX ) );
- if( pWndCheckBoxDoNotDisplayAgain != NULL )
- {
- ASSERT_VALID( pWndCheckBoxDoNotDisplayAgain );
- pWndCheckBoxDoNotDisplayAgain->MoveWindow( ptPos.x, ptPos.y, m_sizeCheckBox.cx, m_sizeCheckBox.cy );
- sizeClient.cx = max( sizeClient.cx, ptPos.x + m_sizeCheckBox.cx + sizeBorderPX.cx );
- sizeClient.cy = max( sizeClient.cy, ptPos.y + m_sizeCheckBox.cy + sizeBorderPX.cy );
- ptPos.y += m_sizeCheckBox.cy + sizeBorderPX.cy;
- }
- }
- INT nButtonSpacePX = _DLU2PxHorz( m_nButtonSpace );
- INT cxButtons = ( nButtonsCount - 1 ) * nButtonSpacePX + nButtonsCount * m_sizeButton.cx;
- INT cyButtons = m_sizeButton.cy;
- sizeClient.cx = max(sizeClient.cx, 2 * sizeBorderPX.cx + cxButtons);
- sizeClient.cy += cyButtons + sizeBorderPX.cy;
- INT nXButtonPosition = ( sizeClient.cx - cxButtons ) / 2;
- INT nYButtonPosition = sizeClient.cy - sizeBorderPX.cy - m_sizeButton.cy;
- if( ( nMsgBoxStyle & __EXT_MB_RIGHT_ALIGN ) != 0 )
- nXButtonPosition = sizeClient.cx - cxButtons - sizeBorderPX.cx;
- for( nButtonIndex = 0; nButtonIndex < nButtonsCount; nButtonIndex ++ )
- {
- CWnd * pWndButton = GetDlgItem( m_arrMsgBoxButtons[ nButtonIndex ] -> m_nButtonDlgCtrlID );
- if ( pWndButton != NULL )
- {
- ASSERT_VALID( pWndButton );
- pWndButton->MoveWindow( nXButtonPosition, nYButtonPosition, m_sizeButton.cx, m_sizeButton.cy );
- nXButtonPosition += m_sizeButton.cx + nButtonSpacePX;
- }
- }
- CRect rcClient( 0, 0, sizeClient.cx, sizeClient.cy );
- CalcWindowRect( rcClient );
- MoveWindow( rcClient );
- CenterWindow();
- }
- bool CExtMsgBox::OnMsgBoxCopyToClipboard()
- {
- ASSERT_VALID( this );
- ASSERT( GetSafeHwnd() != NULL );
- CExtSafeString strMessageText = MessageGet();
- INT nMessageTextLength = INT( strMessageText.GetLength() );
- if( ! ::OpenClipboard( m_hWnd ) )
- return false;
- ::EmptyClipboard();
- bool bRetVal = false;
- HGLOBAL hGlobal =
- ::GlobalAlloc(
- GMEM_DDESHARE,
- ( nMessageTextLength + 1 ) * sizeof(TCHAR)
- );
- ASSERT( hGlobal != NULL );
- if( hGlobal != NULL )
- {
- LPTSTR lpszBuffer =
- (LPTSTR) ::GlobalLock( hGlobal );
- __EXT_MFC_STRCPY(
- lpszBuffer,
- nMessageTextLength + 1,
- ( nMessageTextLength == 0 ) ? _T("") : LPCTSTR(strMessageText)
- );
- ::GlobalUnlock( hGlobal );
- if( ::SetClipboardData(
- #if (defined _UNICODE)
- CF_UNICODETEXT
- #else
- CF_TEXT
- #endif
- ,
- hGlobal
- ) != NULL
- )
- bRetVal = true;
- }
- ::CloseClipboard();
- return bRetVal;
- }
- void CExtMsgBox::ResetAllMsgBoxes()
- {
- CWinApp * pApp = ::AfxGetApp();
- ASSERT_VALID( pApp );
- CString strKey = _T("Software\");
- strKey += pApp->m_pszRegistryKey;
- strKey += _T("\");
- strKey += pApp->m_pszProfileName;
- strKey += _T("\");
- strKey += g_strRegSectionName;
- pApp->DelRegTree( HKEY_CURRENT_USER, strKey );
- }
- void CExtMsgBox::ResetMsgBox()
- {
- ASSERT_VALID( this );
- CExtSafeString strRegVarName = OnMsgBoxGetRegVarName();
- ::AfxGetApp()->WriteProfileInt( g_strRegSectionName, LPCTSTR(strRegVarName), -1 );
- }
- int CExtMsgBox::DoMsgBox(
- HWND hWndParent,
- UINT nMessageResourceID,
- UINT nCaptionResourceID, // = 0
- UINT nMsgBoxStyle, // = __EXT_MB_DEFAULT_STYLES
- UINT nHelpID, // = 0
- __EXT_MFC_SAFE_LPCTSTR strUniqueID, // = NULL // for __EXT_MB_DO_NOT_DISPLAY_AGAIN and __EXT_MB_DO_NOT_ASK_AGAIN
- UINT nMsgBoxStyleEx, // = __EXT_MB_EX_DEFAULT_STYLES
- UINT nTimeoutSeconds, // = 0
- bool bIsDisabledTimeout, // = false
- CExtBitmap * pBmpIcon // = NULL
- )
- {
- __PROF_UIS_MANAGE_STATE;
- CExtSafeString strCaption, strMessageText;
- if( nCaptionResourceID == 0 )
- strCaption = LPCTSTR( ::AfxGetAppName() );
- else
- {
- VERIFY( g_ResourceManager->LoadString( strCaption, nCaptionResourceID ) );
- }
- VERIFY( g_ResourceManager->LoadString( strMessageText, nMessageResourceID ) );
- return DoMsgBox( hWndParent, strMessageText, strCaption, nMsgBoxStyle, nHelpID, strUniqueID, nMsgBoxStyleEx, nTimeoutSeconds, bIsDisabledTimeout, pBmpIcon );
- }
- int CExtMsgBox::DoMsgBox(
- HWND hWndParent,
- __EXT_MFC_SAFE_LPCTSTR strMessageText,
- __EXT_MFC_SAFE_LPCTSTR strCaption, // = NULL
- UINT nMsgBoxStyle, // = __EXT_MB_DEFAULT_STYLES
- UINT nHelpID, // = 0
- __EXT_MFC_SAFE_LPCTSTR strUniqueID, // = NULL // for __EXT_MB_DO_NOT_DISPLAY_AGAIN and __EXT_MB_DO_NOT_ASK_AGAIN
- UINT nMsgBoxStyleEx, // = __EXT_MB_EX_DEFAULT_STYLES
- UINT nTimeoutSeconds, // = 0
- bool bIsDisabledTimeout, // = false
- CExtBitmap * pBmpIcon // = NULL
- )
- {
- __PROF_UIS_MANAGE_STATE;
- if( ::GetCapture() != NULL )
- ::ReleaseCapture(); // force release mouse capture
- CExtMsgBox dlg( hWndParent, strMessageText, strCaption, nMsgBoxStyle, nHelpID, strUniqueID, nMsgBoxStyleEx );
- if( nTimeoutSeconds > 0 )
- dlg.TimeoutSet( nTimeoutSeconds, bIsDisabledTimeout );
- if( pBmpIcon != NULL && ( ! pBmpIcon->IsEmpty() ) )
- dlg.m_bmpIcon = (*pBmpIcon);
- //HWND hWndFocusRestore = ::GetFocus();
- int nRetVal = int( dlg.DoModal() );
- // if( hWndFocusRestore != NULL
- // && ::IsWindow( hWndFocusRestore )
- // && ::IsWindowEnabled( hWndFocusRestore )
- // && ( ( ::__EXT_MFC_GetWindowLong( hWndFocusRestore, GWL_STYLE ) ) & WS_VISIBLE ) != 0
- // && ::GetFocus() != hWndFocusRestore
- // )
- // {
- // CExtPopupMenuWnd::PassMsgLoop( false );
- // if( ::IsWindow( hWndFocusRestore )
- // && ::IsWindowEnabled( hWndFocusRestore )
- // && ( ( ::__EXT_MFC_GetWindowLong( hWndFocusRestore, GWL_STYLE ) ) & WS_VISIBLE ) != 0
- // && ::GetFocus() != hWndFocusRestore
- // )
- // ::SetFocus( hWndFocusRestore );
- // }
- return nRetVal;
- }
- int ProfUISMsgBox(
- HWND hWndParent,
- UINT nMessageResourceID,
- UINT nCaptionResourceID, // = 0
- UINT nMsgBoxStyle, // = __EXT_MB_DEFAULT_STYLES
- UINT nHelpID, // = 0
- __EXT_MFC_SAFE_LPCTSTR strUniqueID, // = NULL // for __EXT_MB_DO_NOT_DISPLAY_AGAIN and __EXT_MB_DO_NOT_ASK_AGAIN
- UINT nMsgBoxStyleEx, // = __EXT_MB_EX_DEFAULT_STYLES
- UINT nTimeoutSeconds, // = 0
- bool bIsDisabledTimeout, // = false
- CExtBitmap * pBmpIcon // = NULL
- )
- {
- __PROF_UIS_MANAGE_STATE;
- return CExtMsgBox::DoMsgBox( hWndParent, nMessageResourceID, nCaptionResourceID, nMsgBoxStyle, nHelpID, strUniqueID, nMsgBoxStyleEx, nTimeoutSeconds, bIsDisabledTimeout, pBmpIcon );
- }
- int ProfUISMsgBox(
- HWND hWndParent,
- __EXT_MFC_SAFE_LPCTSTR strMessageText,
- __EXT_MFC_SAFE_LPCTSTR strCaption, // = NULL
- UINT nMsgBoxStyle, // = __EXT_MB_DEFAULT_STYLES
- UINT nHelpID, // = 0
- __EXT_MFC_SAFE_LPCTSTR strUniqueID, // = NULL // for __EXT_MB_DO_NOT_DISPLAY_AGAIN and __EXT_MB_DO_NOT_ASK_AGAIN
- UINT nMsgBoxStyleEx, // = __EXT_MB_EX_DEFAULT_STYLES
- UINT nTimeoutSeconds, // = 0
- bool bIsDisabledTimeout, // = false
- CExtBitmap * pBmpIcon // = NULL
- )
- {
- __PROF_UIS_MANAGE_STATE;
- return CExtMsgBox::DoMsgBox( hWndParent, strMessageText, strCaption, nMsgBoxStyle, nHelpID, strUniqueID, nMsgBoxStyleEx, nTimeoutSeconds, bIsDisabledTimeout, pBmpIcon );
- }
- #endif // (! defined __EXT_MFC_NO_MSG_BOX )