summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2DlgItemEdit.cpp
blob: 093cbd28884c02ab45c1b8a0d68b30689aaae693 (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
#include "StdAfx.h"
#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);
}