📄 cformeditorview.cpp
字号:
// CFormEditorView.cpp : implementation of the CCFormEditorView class
//
#include "stdafx.h"
#include "CFormEditor.h"
#include "memdc.h"
#include "CFormEditorDoc.h"
#include "CFormEditorView.h"
#include "sizedlg.h"
#include "FormEditorRulerBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCFormEditorView
IMPLEMENT_DYNCREATE(CCFormEditorView, CView)
BEGIN_MESSAGE_MAP(CCFormEditorView, CView)
//{{AFX_MSG_MAP(CCFormEditorView)
ON_COMMAND(ID_OPTION, OnOption)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
ON_REGISTERED_MESSAGE(
CFormEditorRulerBar::g_nMsgDrawRuler,
OnDrawRuler
)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCFormEditorView construction/destruction
CCFormEditorView::CCFormEditorView()
{
// TODO: add construction code here
m_sizeGridStep=CSize( 8, 8 );
m_sizeDropArea=CSize( 100, 25 );
m_rcLastDropArea=CRect( 0, 0, 0, 0 );
m_bTabOrderMode=FALSE;
m_bTrackingCreation=FALSE;
m_rcTrackingCreation=CRect(0,0,0, 0 );
}
int CCFormEditorView::g_nGripBoxMetric = 7;
CCFormEditorView::~CCFormEditorView()
{
}
BOOL CCFormEditorView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCFormEditorView drawing
void CCFormEditorView::ExcludeControlAreas( HDC hDC )
{
if( hDC == NULL )
return;
HWND hWndChild = ::GetWindow(m_hWnd,GW_CHILD);
for( ; hWndChild != NULL; hWndChild = ::GetWindow(hWndChild,GW_HWNDNEXT))
{
if( ! ::IsWindowVisible(hWndChild) )
continue;
RECT rc;
if( !::GetWindowRect(hWndChild,&rc) )
continue;
if( !::ScreenToClient(m_hWnd, (LPPOINT)(&rc)) )
continue;
if( !::ScreenToClient(m_hWnd, ((LPPOINT)(&rc))+1) )
continue;
::DPtoLP( hDC, (LPPOINT)&rc, 2 );
ExcludeClipRect(
hDC,
rc.left,rc.top,
rc.right,rc.bottom
);
} // for(; hWndChild != NULL; hWndChild = GetWindow(hWndChild,GW_HWNDNEXT))
}
CRect CCFormEditorView::CalcActualViewRect( CDC * pDC )
{
ASSERT_VALID( this );
return
CRect(
CPoint( 20, 40 ),
CalcActualViewSize(pDC)
);
}
void CCFormEditorView::CalcGripBoxes(
CRect rcSrc,
CRect * pRcOut
)
{
ASSERT( pRcOut != NULL );
pRcOut[0] = rcSrc;
pRcOut[0].right = rcSrc.left;
pRcOut[0].bottom = rcSrc.top;
pRcOut[0].left -= g_nGripBoxMetric;
pRcOut[0].top -= g_nGripBoxMetric;
pRcOut[1] = pRcOut[0];
pRcOut[1].OffsetRect( (rcSrc.Width() + g_nGripBoxMetric)/2, 0 );
pRcOut[2] = pRcOut[0];
pRcOut[2].OffsetRect( rcSrc.Width() + g_nGripBoxMetric, 0 );
pRcOut[3] = pRcOut[2];
pRcOut[3].OffsetRect( 0, (rcSrc.Height() + g_nGripBoxMetric)/2 );
pRcOut[7] = pRcOut[0];
pRcOut[7].OffsetRect( 0, (rcSrc.Height() + g_nGripBoxMetric)/2 );
pRcOut[4] = pRcOut[2];
pRcOut[4].OffsetRect( 0, rcSrc.Height() + g_nGripBoxMetric );
pRcOut[6] = pRcOut[0];
pRcOut[6].OffsetRect( 0, rcSrc.Height() + g_nGripBoxMetric );
pRcOut[5] = pRcOut[1];
pRcOut[5].OffsetRect( 0, rcSrc.Height() + g_nGripBoxMetric );
}
CString CCFormEditorView::GetTabText( int nTabNo )
{
ASSERT_VALID( this );
CString sTabText;
sTabText.Format( _T("%d"), nTabNo );
return sTabText;
}
CSize CCFormEditorView::CalcActualViewSize( CDC * pDC )
{
ASSERT_VALID( this );
CCFormEditorDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if( pDC != NULL )
return pDoc->CalcActualLayoutSize( pDC );
CClientDC dc( this );
CSize sizeLayout = pDoc->CalcActualLayoutSize( &dc );
sizeLayout.cx += 4;
sizeLayout.cy += 4;
return sizeLayout;
}
CRect CCFormEditorView::CalcTabNoRect( HWND hWndChild, int nTabNo, bool bLogicDcMode )
{
ASSERT_VALID( this );
ASSERT( hWndChild != NULL );
ASSERT( ::IsWindow(hWndChild) );
CRect rc;
VERIFY( ::GetWindowRect(hWndChild,&rc) );
ScreenToClient( &rc );
CClientDC dc( this );
if( bLogicDcMode )
{
OnPrepareDC( &dc, NULL );
dc.DPtoLP( &rc );
}
CString sTabText = GetTabText( nTabNo );
CRect rcText( 0, 0, 0, 0 );
//CFont * pOldFont =
// dc.SelectObject( &g_PaintManager->m_FontBold );
dc.DrawText(
sTabText,
rcText,
DT_SINGLELINE|DT_CALCRECT
);
// dc.SelectObject( pOldFont );
rcText.InflateRect( 0, 0, 4, 4 );
rcText.SetRect(
rc.left,
rc.top - rcText.Height() - 1,
rc.left + rcText.Width(),
rc.top - 1
);
if( rcText.Width() < (rcText.Height()+2) )
rcText.right = rcText.left + rcText.Height() + 2;
return rcText;
}
void CCFormEditorView::OnDraw(CDC* pDC)
{
ASSERT_VALID( this );
if( pDC->IsPrinting() )
return;
ExcludeControlAreas( pDC->GetSafeHdc() );
CMemDC dc( pDC );
CRect rcMrg = CalcActualViewRect();
// draw dots
CPoint ptStart = rcMrg.TopLeft();
CPoint ptEnd = rcMrg.BottomRight();
CPoint ptCurr;
COLORREF clrDot = RGB(192,192,192);//g_PaintManager->GetColor( COLOR_BTNTEXT );
for( ptCurr.x = ptStart.x; ptCurr.x <= ptEnd.x; ptCurr.x += m_sizeGridStep.cx )
{
for( ptCurr.y = ptStart.y; ptCurr.y <= ptEnd.y; ptCurr.y += m_sizeGridStep.cy )
dc.SetPixel( ptCurr, clrDot );
}
// draw frame
COLORREF clr3dHilight = ::GetSysColor(COLOR_3DHILIGHT);//g_PaintManager->GetColor(COLOR_3DHILIGHT);
COLORREF clr3dFace = ::GetSysColor(COLOR_3DFACE);
COLORREF clr3dShadow = ::GetSysColor(COLOR_3DSHADOW);
COLORREF clr3dDkShadow = ::GetSysColor(COLOR_3DDKSHADOW);
CRect rcFrame( &rcMrg );
rcFrame.InflateRect( 3, 23, 3, 0 );
CRect rcCaption( rcFrame );
rcCaption.bottom = rcMrg.top - 1;
rcCaption.DeflateRect( 3, 3, 2, 2 );
dc.Draw3dRect(
&rcFrame,
clr3dHilight,
clr3dShadow
);
rcFrame.InflateRect( 1, 1 );
dc.Draw3dRect(
&rcFrame,
clr3dFace,
clr3dDkShadow
);
#ifdef COLOR_GRADIENTACTIVECAPTION
ASSERT( (COLOR_GRADIENTACTIVECAPTION) == 27 );
#endif // COLOR_GRADIENTACTIVECAPTION
stat_PaintGradientRect(
dc,
&rcCaption,
::GetSysColor(COLOR_ACTIVECAPTION),
::GetSysColor(27)
);
// draw selected layout
if( (!m_bTabOrderMode) && m_mapSelection.GetCount() > 0 )
{
COLORREF clrGripBoxOuter = ::GetSysColor( COLOR_3DDKSHADOW );
COLORREF clrGripBoxInner =
::GetSysColor(
(m_mapSelection.GetCount() == 1)
? COLOR_WINDOW
: COLOR_3DDKSHADOW
);
POSITION pos = m_mapSelection.GetStartPosition();
for( ; pos != NULL; )
{
HWND hWndChild;
int nTmp;
m_mapSelection.GetNextAssoc(pos,hWndChild,nTmp);
ASSERT( hWndChild != NULL );
ASSERT( ::IsWindow(hWndChild) );
CRect rc;
if( !::GetWindowRect(hWndChild,&rc) )
continue;
ScreenToClient( &rc );
dc.DPtoLP( &rc );
CRect rcGripBoxes[8];
CalcGripBoxes( rc, rcGripBoxes );
// for( int i = 0; i < g_nGripBoxMetric; i++ )
// {
// rc.InflateRect( 1, 1 );
// dc.DrawFocusRect( &rc );
// }
for( int i = 0; i < 8; i++ )
{
dc.FillSolidRect(
rcGripBoxes[i],
clrGripBoxInner
);
dc.Draw3dRect(
rcGripBoxes[i],
clrGripBoxOuter,
clrGripBoxOuter
);
}
}
} // if( (!m_bTabOrderMode) && m_mapSelection.GetCount() > 0 )
// draw tab orders
if( m_bTabOrderMode )
{
COLORREF clrTabNoBk =
::GetSysColor( COLOR_HIGHLIGHT );
COLORREF clrTabNoText =
::GetSysColor( COLOR_HIGHLIGHTTEXT );
int nIndex = 0;
// CFont * pOldFont =
// dc.SelectObject( &g_PaintManager->m_FontBold );
int nOldBkMode = dc.SetBkMode(OPAQUE);
COLORREF clrOldBkColor = dc.SetBkColor( clrTabNoBk );
COLORREF clrOldTextColor = dc.SetTextColor( clrTabNoText );
for( HWND hWndChild = ::GetWindow(m_hWnd,GW_CHILD);
hWndChild != NULL;
hWndChild = ::GetWindow(hWndChild,GW_HWNDNEXT),
nIndex++
)
{
ASSERT( hWndChild != NULL );
ASSERT( ::IsWindow(hWndChild) );
CString sTabText = GetTabText( nIndex+1 );
CRect rcText = CalcTabNoRect( hWndChild, nIndex+1, true );
dc.FillSolidRect(
rcText,
clrTabNoBk
);
dc.DrawText(
sTabText,
rcText,
DT_SINGLELINE|DT_CENTER|DT_VCENTER
);
}
dc.SetTextColor( clrOldTextColor );
dc.SetBkColor( clrOldBkColor );
dc.SetBkMode(nOldBkMode);
// dc.SelectObject( pOldFont );
}
// draw drop area
if( !m_rcLastDropArea.IsRectEmpty() )
{
CRect rect( &m_rcLastDropArea );
dc.DrawFocusRect( &rect );
rect.DeflateRect( 1, 1 );
dc.DrawFocusRect( &rect );
rect.DeflateRect( 1, 1 );
dc.DrawFocusRect( &rect );
}
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CCFormEditorView printing
BOOL CCFormEditorView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCFormEditorView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCFormEditorView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
int CCFormEditorView::stat_GetBPP()
{
// return 4; // <-- test
// return 8; // <-- test
CWindowDC dc_desktop(NULL);
int nBitsPerPixel =
dc_desktop.GetDeviceCaps(BITSPIXEL);
return nBitsPerPixel;
}
/////////////////////////////////////////////////////////////////////////////
// CCFormEditorView diagnostics
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -