#include "T2DlgItemText.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif T2DlgItemText::T2DlgItemText(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) : T2DlgItem(inDoc, inImageObj, inPalette) , mHasTextColor(false) { } void T2DlgItemText::SetTextColor(COLORREF inColor) { mTextColor = inColor; mHasTextColor = true; } /*virtual*/ void T2DlgItemText::GetDescriptor(CString& outStr) const { GetContentText(outStr); } /*virtual*/ void T2DlgItemText::SetDescriptor(const CString& inStr) { CString str(GetJustification()); str += inStr; SetWindowText(str); CRect rect; GetClientRect(rect); MapWindowPoints(GetParent(), rect); GetParent()->InvalidateRect(rect); } /*virtual*/ BOOL T2DlgItemText::OnT2DlgItemEraseBkgnd(CDC* pDC) { CRect rect; GetClientRect(rect); int save = pDC->SaveDC(); pDC->SelectPalette(mPalette, false); pDC->RealizePalette(); pDC->SetTextColor(mHasTextColor ? mTextColor : PALETTEINDEX(255)); pDC->SetBkMode(TRANSPARENT); pDC->SelectObject(mFont); CString str; GetContentText(str); char justification = GetJustification(); UINT flags = DT_WORDBREAK | DT_NOPREFIX; if (isupper(justification)) { flags |= DT_VCENTER; justification = tolower(justification); } switch (justification) { case 'c': flags |= DT_CENTER; break; case 'l': flags |= DT_LEFT; break; case 'r': flags |= DT_RIGHT; break; } pDC->DrawText(str, rect, flags); pDC->RestoreDC(save); return true; } char T2DlgItemText::GetJustification() const { char result = 'l'; CString text; GetWindowText(text); if (text.GetLength() > 0) result = text[0]; return result; } void T2DlgItemText::GetContentText(CString& outStr) const { GetWindowText(outStr); if (outStr.GetLength() > 0) outStr = outStr.Mid(1); } void T2DlgItemText::InfoDialogMessage(CString& inStr, long inTime) { if (inTime != -1) { GetDescriptor(mPreviousString); mTimerID = SetTimer(1000, inTime, NULL); } else { mPreviousString.Empty(); mTimerID = 0; } SetDescriptor(inStr); } /*virtual*/ void T2DlgItemText::OnT2Timer(UINT id) { if (id == mTimerID && mPreviousString.GetLength() > 0) { SetDescriptor(mPreviousString); mPreviousString.Empty(); KillTimer(mTimerID); } }