#include "StdAfx.h" #include "CTokenizer.h" #include "T2DlgItemTab.h" // oops, no name for this lad class CustomTabControl : public CTabCtrl { DECLARE_MESSAGE_MAP() virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); afx_msg BOOL OnEraseBkgnd(CDC* pDC); public: CPalette *mPalette; }; T2DlgItemTab::T2DlgItemTab(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) : T2DlgItem(inDoc, inImageObj, inPalette) , mSubItem(NULL) { } /*virtual*/ T2DlgItemTab::~T2DlgItemTab() { delete mSubItem; } /*virtual*/ int T2DlgItemTab::OnT2DlgItemCreate(CREATESTRUCT* cs) { T2DlgItem::OnT2DlgItemCreate(cs); return 0; } /*virtual*/ void T2DlgItemTab::SetFont(HFONT inFont) { T2DlgItem::SetFont(inFont); if (mSubItem) mSubItem->SetFont(CFont::FromHandle(inFont)); } /*virtual*/ void T2DlgItemTab::CreateSubItem(void* inData) { mSubItem = new CustomTabControl; mSubItem->mPalette = mPalette; CRect clientRect; GetClientRect(clientRect); clientRect.bottom = clientRect.top + 20; mSubItem->Create(WS_VISIBLE | WS_CHILD, clientRect, this, 0); char *buf = (char *) calloc(GetWindowTextLength() + 1, 1); GetWindowText(buf, GetWindowTextLength()); if (strlen(buf) != 0 && buf[0] != '-') { CTokenizer theTokenizer(buf, "|\r\n"); const char *itemText = theTokenizer.NextString(); int i = 0; while (itemText) { TCITEM item; item.mask = TCIF_TEXT | TCIF_PARAM; item.pszText = (LPSTR) itemText; item.cchTextMax = strlen(itemText); item.lParam = i; mSubItem->InsertItem(i, &item); i++; itemText = theTokenizer.NextString(); } } free(buf); } /*virtual*/ BOOL T2DlgItemTab::OnT2DlgItemEraseBkgnd(CDC* pDC) { #pragma var_order(rect, pen1, pen2, save, brush, pen3, pen4) CRect rect; GetClientRect(rect); rect.top += 20; 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)); CPen pen4; pen4.CreatePen(PS_SOLID, 0, PALETTERGB(224, 224, 224)); CBrush brush; int save = pDC->SaveDC(); pDC->SelectPalette(mPalette, false); pDC->RealizePalette(); if (IsWindowEnabled()) { pDC->SelectObject(pen3); pDC->MoveTo(rect.right - 2, rect.top - 2); pDC->LineTo(rect.right - 2, rect.top - 1); pDC->MoveTo(rect.right - 1, rect.top - 1); pDC->LineTo(rect.right - 1, rect.bottom - 1); pDC->LineTo(rect.left, rect.bottom - 1); pDC->SelectObject(pen2); pDC->MoveTo(rect.right - 2, rect.top + 1); pDC->LineTo(rect.right - 2, rect.bottom - 2); pDC->LineTo(rect.left + 1, rect.bottom - 2); pDC->SelectObject(pen1); pDC->MoveTo(rect.left, rect.bottom - 1); pDC->LineTo(rect.left, rect.top); pDC->SelectObject(pen4); pDC->MoveTo(rect.left + 1, rect.bottom - 2); pDC->LineTo(rect.left + 1, rect.top); } else { brush.CreateSolidBrush(PALETTERGB(179, 179, 179)); pDC->FrameRect(rect, &brush); } pDC->RestoreDC(save); return true; } /*virtual*/ LRESULT T2DlgItemTab::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { if (mSubItem) { switch (message) { case WM_NOTIFY: { NMHDR *hdr = (NMHDR *) lParam; if (hdr->code == TCN_SELCHANGE) { int num = mSubItem->GetCurSel() + 1; BroadcastMessage(-GetDlgCtrlID(), &num); return 0; } break; } default: return CWnd::WindowProc(message, wParam, lParam); } } return CWnd::WindowProc(message, wParam, lParam); } /*virtual*/ LRESULT CustomTabControl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { default: return CWnd::WindowProc(message, wParam, lParam); } } BEGIN_MESSAGE_MAP(CustomTabControl, CTabCtrl) ON_WM_ERASEBKGND() END_MESSAGE_MAP() afx_msg BOOL CustomTabControl::OnEraseBkgnd(CDC* pDC) { int save = pDC->SaveDC(); pDC->SelectPalette(mPalette, false); pDC->RealizePalette(); CRect clientRect; GetClientRect(clientRect); pDC->FillSolidRect(clientRect, PALETTERGB(204, 204, 204)); pDC->RestoreDC(save); return true; }