#define ATOI_KLUDGE #include "CEditWFocus.h" #include "T2DlgItemEdit.h" T2DlgItemEdit::T2DlgItemEdit(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) : T2DlgItem(inDoc, inImageObj, inPalette) , mSubItem(NULL) { } /*virtual*/ T2DlgItemEdit::~T2DlgItemEdit() { delete mSubItem; } /*virtual*/ void T2DlgItemEdit::SetFont(HFONT inFont) { T2DlgItem::SetFont(inFont); if (mSubItem) mSubItem->SetFont(CFont::FromHandle(inFont)); } /*virtual*/ void T2DlgItemEdit::CreateSubItem(void* inData) { mSubItem = new CEditWFocus; int value = *((int *) inData); CRect rect; GetClientRect(rect); if (rect.Height() < (value + 4)) value = rect.Height() - 4; rect.top += (rect.Height() - value) / 2; rect.left += 2; rect.bottom = rect.top + value; rect.right -= 2; mSubItem->Create(WS_VISIBLE | WS_CHILD, rect, this, 0); } #pragma var_order(brush3, brush2, rect, pen1, pen2, save, pen3, brush1) /*virtual*/ BOOL T2DlgItemEdit::OnT2DlgItemEraseBkgnd(CDC* pDC) { CRect rect; GetClientRect(rect); CPen pen1; pen1.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255)); CPen pen2; pen2.CreatePen(PS_SOLID, 0, PALETTERGB(133, 133, 133)); CPen pen3; pen3.CreatePen(PS_SOLID, 0, PALETTEINDEX(255)); CBrush brush1; CBrush brush2; CBrush brush3; int save = pDC->SaveDC(); pDC->SelectPalette(mPalette, false); pDC->RealizePalette(); if (IsWindowEnabled()) { pDC->SelectObject(pen2); pDC->MoveTo(rect.right - 1, rect.top); pDC->LineTo(rect.left, rect.top); pDC->LineTo(rect.left, rect.bottom); pDC->SelectObject(pen1); pDC->MoveTo(rect.right - 1, rect.top + 1); pDC->LineTo(rect.right - 1, rect.bottom - 1); pDC->LineTo(rect.left, rect.bottom - 1); rect.DeflateRect(1, 1); brush2.CreateSolidBrush(PALETTERGB(255, 255, 255)); pDC->SelectObject(brush2); pDC->SelectObject(pen3); pDC->Rectangle(rect); brush3.CreateSolidBrush(PALETTEINDEX(255)); pDC->FrameRect(rect, &brush3); } else { brush1.CreateSolidBrush(PALETTERGB(179, 179, 179)); pDC->FrameRect(rect, &brush1); } pDC->RestoreDC(save); return true; } /*virtual*/ void T2DlgItemEdit::GetDescriptor(CString& outStr) const { if (mSubItem) mSubItem->GetWindowText(outStr); } /*virtual*/ void T2DlgItemEdit::SetDescriptor(const CString& inStr) { if (mSubItem) mSubItem->SetWindowText(inStr); } /*virtual*/ int T2DlgItemEdit::GetValue() { int value = 0; CString str; GetDescriptor(str); if (str.GetLength() > 0) { value = atoi(str); mValue = value; } return value; } /*virtual*/ void T2DlgItemEdit::SetValue(int inValue) { T2DlgItem::SetValue(inValue); CString str; str.Format("%d", T2DlgItem::GetValue()); SetDescriptor(str); } void T2DlgItemEdit::SelectAll() { if (mSubItem) mSubItem->SetSel(0, -1); } /*virtual*/ void T2DlgItemEdit::OnT2SetFocus(CWnd* inWnd) { } /*virtual*/ void T2DlgItemEdit::OnT2KillFocus(CWnd* inWnd) { } /*virtual*/ void T2DlgItemEdit::OnT2DlgItemEnable(BOOL inEnable) { if (mSubItem) mSubItem->EnableWindow(inEnable); T2DlgItem::OnT2DlgItemEnable(inEnable); }