- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# PropPageFrame.cpp

    00001 /********************************************************************
    00002 *
    00003 * Copyright (c) 2002 Sven Wiegand <mail@sven-wiegand.de>
    00004 *
    00005 * You can use this and modify this in any way you want,
    00006 * BUT LEAVE THIS HEADER INTACT.
    00007 *
    00008 * Redistribution is appreciated.
    00009 *
    00010 * $Workfile:$
    00011 * $Revision: 1.1 $
    00012 * $Modtime:$
    00013 * $Author: gabest $
    00014 *
    00015 * Revision History:
    00016 *       $History:$
    00017 *
    00018 *********************************************************************/
    00019
    00020 #include "stdafx.h"
    00021 #include "PropPageFrame.h"
    00022
    00023 #ifdef _DEBUG
    00024 #define new DEBUG_NEW
    00025 #undef THIS_FILE
    00026 static char THIS_FILE[] = __FILE__;
    00027 #endif
    00028
    00029
    00030
    00031 namespace TreePropSheet
    00032 {
    00033
    00034
    00035 //-------------------------------------------------------------------
    00036 // class CPropPageFrame
    00037 //-------------------------------------------------------------------
    00038
    00039 CPropPageFrame::CPropPageFrame()
    00040 :       m_bShowCaption(FALSE),
    00041         m_nCaptionHeight(0),
    00042         m_hCaptionIcon(NULL),
    00043         m_dwMsgFormat(DT_CENTER|DT_VCENTER|DT_NOPREFIX|DT_SINGLELINE)
    00044 {
    00045 }
    00046
    00047
    00048 CPropPageFrame::~CPropPageFrame()
    00049 {
    00050 }
    00051
    00052
    00054 // Operations
    00055
    00056
    00057 void CPropPageFrame::ShowCaption(BOOL bEnable)
    00058 {
    00059         m_bShowCaption = bEnable;
    00060         SafeUpdateWindow(CalcCaptionArea());
    00061 }
    00062
    00063
    00064 BOOL CPropPageFrame::GetShowCaption() const
    00065 {
    00066         return m_bShowCaption;
    00067 }
    00068
    00069
    00070 void CPropPageFrame::SetCaption(LPCTSTR lpszCaption, HICON hIcon /*= NULL*/)
    00071 {
    00072         m_strCaption = lpszCaption;
    00073         m_hCaptionIcon = hIcon;
    00074         SafeUpdateWindow(CalcCaptionArea());
    00075 }
    00076
    00077
    00078 CString CPropPageFrame::GetCaption(HICON *pIcon /* = NULL */) const
    00079 {
    00080         if (pIcon)
    00081                 *pIcon = m_hCaptionIcon;
    00082         return m_strCaption;
    00083 }
    00084
    00085
    00086 void CPropPageFrame::SetCaptionHeight(int nCaptionHeight)
    00087 {
    00088         m_nCaptionHeight = nCaptionHeight;
    00089         SafeUpdateWindow(CalcCaptionArea());
    00090 }
    00091
    00092
    00093 int CPropPageFrame::GetCaptionHeight() const
    00094 {
    00095         return m_nCaptionHeight;
    00096 }
    00097
    00098
    00099 void CPropPageFrame::SetMsgText(LPCTSTR lpszMsg)
    00100 {
    00101         m_strMsg = lpszMsg;
    00102         SafeUpdateWindow(CalcMsgArea());
    00103 }
    00104
    00105
    00106 CString CPropPageFrame::GetMsgText() const
    00107 {
    00108         return m_strMsg;
    00109 }
    00110
    00111
    00112 void CPropPageFrame::SetMsgFormat(DWORD dwFormat)
    00113 {
    00114         m_dwMsgFormat = dwFormat;
    00115         SafeUpdateWindow(CalcMsgArea());
    00116 }
    00117
    00118
    00119 DWORD CPropPageFrame::GetMsgFormat() const
    00120 {
    00121         return m_dwMsgFormat;
    00122 }
    00123
    00124
    00126 // Overridable implementation helpers
    00127
    00128 void CPropPageFrame::Draw(CDC *pDc)
    00129 {
    00130         if (GetShowCaption())
    00131                 DrawCaption(pDc, CalcCaptionArea(), m_strCaption, m_hCaptionIcon);
    00132         DrawMsg(pDc, CalcMsgArea(), m_strMsg, m_dwMsgFormat);
    00133 }
    00134
    00135
    00136 CRect CPropPageFrame::CalcMsgArea()
    00137 {
    00138         ASSERT(IsWindow(GetWnd()->GetSafeHwnd()));
    00139
    00140         CRect   rectMsg;
    00141         GetWnd()->GetClientRect(rectMsg);
    00142         if (GetShowCaption())
    00143                 rectMsg.top+= GetCaptionHeight();
    00144
    00145         return rectMsg;
    00146 }
    00147
    00148
    00149 void CPropPageFrame::DrawMsg(CDC *pDc, CRect rect, LPCTSTR lpszMsg, DWORD dwFormat)
    00150 {
    00151         CFont   *pPrevFont = dynamic_cast<CFont*>(pDc->SelectStockObject(DEFAULT_GUI_FONT));
    00152         int             nPrevBkMode = pDc->SetBkMode(TRANSPARENT);
    00153
    00154         pDc->DrawText(GetMsgText(), rect, GetMsgFormat());
    00155
    00156         pDc->SetBkMode(nPrevBkMode);
    00157         pDc->SelectObject(pPrevFont);
    00158 }
    00159
    00160
    00161 CRect   CPropPageFrame::CalcCaptionArea()
    00162 {
    00163         ASSERT(IsWindow(GetWnd()->GetSafeHwnd()));
    00164
    00165         CRect   rectCaption;
    00166         GetWnd()->GetClientRect(rectCaption);
    00167         if (!GetShowCaption())
    00168                 rectCaption.bottom = rectCaption.top;
    00169         else
    00170                 rectCaption.bottom = rectCaption.top+GetCaptionHeight();
    00171
    00172         return rectCaption;
    00173 }
    00174
    00175
    00176 void CPropPageFrame::DrawCaption(CDC *pDc, CRect rect, LPCTSTR lpszCaption, HICON hIcon)
    00177 {
    00178         // should be implemented by specialized classes
    00179 }
    00180
    00181
    00183 // Implementation helpers
    00184
    00185 void CPropPageFrame::SafeUpdateWindow(LPCRECT lpRect /* = NULL */)
    00186 {
    00187         if (!IsWindow(GetWnd()->GetSafeHwnd()))
    00188                 return;
    00189
    00190         GetWnd()->InvalidateRect(lpRect, TRUE);
    00191 }
    00192
    00193
    00194
    00195 } //namespace TreePropSheet