#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 clientRect; GetClientRect(clientRect); MapWindowPoints(GetParent(), clientRect); GetParent()->InvalidateRect(clientRect); } /*virtual*/ BOOL T2DlgItemText::OnT2DlgItemEraseBkgnd(CDC* pDC) { CRect rect; GetClientRect(rect); int theSave = 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 just = GetJustification(); UINT format = DT_WORDBREAK | DT_NOPREFIX; if (isupper(just)) { format |= DT_VCENTER; just = tolower(just); } switch (just) { case 'c': format |= DT_CENTER; break; case 'l': format |= DT_LEFT; break; case 'r': format |= DT_RIGHT; break; } pDC->DrawText(str, rect, format); pDC->RestoreDC(theSave); 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); } }