summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2DlgItemTab.cpp
blob: fdf0d2f88413148af2ecd24a82faf8bf18a9cd25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#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;
}