summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2HallEventTable.cpp
blob: 3bc08d76aec419aea90f66216347453207725ca8 (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#include "CFilePluginList.h"
#include "T2DateTime.h"
#include "T2HallEventTable.h"
#include "T2HallEventPlugin.h"
#include "T2TowerDoc.h"

/*virtual*/ int T2HallEventTable::OnT2DlgItemCreate(CREATESTRUCT* cs) {
    T2DlgItemTable::SetColWidth(cs->cx, 0, 0);
    return T2DlgItemTable::OnT2DlgItemCreate(cs);
}

T2HallEventTable::T2HallEventTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette)
    : T2VerticalTable(inDoc, inImageObj, inPalette)
{
    mClearBackground = true;
    mUserCon = 0;

    SetCellDataSize(sizeof(T2HallEventItem *));
    InsertCols(1, 0, NULL);
    SetHScrollerStyle(AlwaysHide);
    SetVScrollerStyle(AlwaysHide);
}

/*virtual*/ T2HallEventTable::~T2HallEventTable() {
    T2HallEventItem *item;
    TableCellT theCell;
    theCell.row = 0;
    theCell.col = 1;

    for (unsigned int i = 1; i <= mRows; i++) {
        theCell.row = i;
        GetCellData(theCell, &item);
        delete item;
    }
}

/*virtual*/ void T2HallEventTable::Add(T2HallEventPlugin* inPlugin) {
    unsigned int index = mRows;
    T2HallEventItem *item = new T2HallEventItem(inPlugin, NULL);
    InsertRows(1, index, &item);
}

/*virtual*/ void T2HallEventTable::Add(const char* inStr) {
    unsigned int index = mRows;
    T2HallEventItem *item = new T2HallEventItem(NULL, inStr);
    InsertRows(1, index, &item);

    if (mUserCon)
        SetVScrollerStyle(AlwaysShow);
}

/*virtual*/ void T2HallEventTable::Add(CFilePluginList* inList) {
    T2HallEventPlugin *thePlugin;
    T2HallEventItem *item;
    unsigned int index = mRows;
    POSITION pos = inList->GetHeadPosition();

    while (pos) {
        thePlugin = (T2HallEventPlugin *) inList->GetNext(pos);
        item = new T2HallEventItem(thePlugin, NULL);
        InsertRows(1, index, &item);
        index++;
    }
}

/*virtual*/ void T2HallEventTable::SetCellData(const TableCellT& inCell, T2HallEventPlugin* inPlugin, const char* inStr) {
    T2HallEventItem *item;
    GetCellData(inCell, &item);

    if (item) {
        item->mPlugin = inPlugin;
        strcpy(item->mStr, inStr);
    }
}

/*virtual*/ void T2HallEventTable::DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected) {
    DrawCell(pDC, inCell);
}

/*virtual*/ void T2HallEventTable::DrawCell(CDC* pDC, const TableCellT& inCell) {
    int save = pDC->SaveDC();
    pDC->SelectPalette(mPalette, false);
    pDC->RealizePalette();

    CFont font;
    RECT cellRect;

    if (FetchLocalCellFrame(inCell, cellRect)) {
        CString title;
        T2HallEventItem *item;
        T2HallEventPlugin *thePlugin;
        GetCellData(inCell, &item);
        if (item) {
            thePlugin = item->mPlugin;
            if (thePlugin)
                thePlugin->GetTitle(title);
            else
                title = item->mStr;
        }

        font.CreateFont(-9, 0, 0, 0, FW_DONTCARE, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY, DEFAULT_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E");
        pDC->SelectObject(&font);
        pDC->SetBkMode(TRANSPARENT);
        pDC->TextOut(cellRect.left + 4, cellRect.bottom - 12, title, strlen(title));

        if (GetUserCon() == 0) {
            if (inCell.row < 12)
                cellRect.bottom++;

            CBrush brush;
            brush.CreateSolidBrush(RGB(0, 0, 0));
            pDC->FrameRect(&cellRect, &brush);
        }
    }

    pDC->RestoreDC(save);
}

/*virtual*/ void T2HallEventTable::ClickCell(const TableCellT& inCell, const CPoint& inPt) {
    T2DlgItemTable::ClickCell(inCell, inPt);

    if (IsValidCell(mSelectedCell)) {
        T2HallEventItem *item;
        GetCellData(mSelectedCell, &item);

        T2HallEventPlugin *thePlugin = item ? item->mPlugin : NULL;
        BroadcastMessage(-GetDlgCtrlID(), thePlugin);
    }
}

/*virtual*/ void T2HallEventTable::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) {
    CPoint pt = inPt;
    ClientToView(&pt, 1);

    TableCellT cell;
    FetchCellHitBy(pt, cell);

    if (IsValidCell(cell))
        ClickCell(cell, inPt);
}

/*virtual*/ BOOL T2HallEventTable::OnT2DlgItemEraseBkgnd(CDC* pDC) {
    T2VerticalTable::OnT2DlgItemEraseBkgnd(pDC);

    unsigned int numOfRows, numOfColumns, theRow, theColumn;

    GetTableSize(numOfRows, numOfColumns);
    for (theColumn = 1; theColumn <= numOfColumns; theColumn++) {
        for (theRow = 1; theRow <= numOfRows; theRow++) {
            TableCellT cell;
            cell.row = theRow;
            cell.col = theColumn;
            DrawCell(pDC, cell);
        }
    }

    T2DlgItemTable::HiliteCell(pDC, mSelectedCell);
    return true;
}



/*virtual*/ int T2MonthlyTable::OnT2DlgItemCreate(CREATESTRUCT* cs) {
    return T2DlgItemTable::OnT2DlgItemCreate(cs);
}

T2MonthlyTable::T2MonthlyTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette)
    : T2VerticalTable(inDoc, inImageObj, inPalette)
{
    mStartMonth = 1;

    SetCellDataSize(sizeof(int));
    InsertCols(1, 0, NULL);
    int zero = 0;
    InsertRows(12, mRows, &zero);

    SetHScrollerStyle(AlwaysHide);
    SetVScrollerStyle(AlwaysHide);
}

/*virtual*/ T2MonthlyTable::~T2MonthlyTable() {
}

void T2MonthlyTable::SetStartMonth(T2TowerDoc* inDoc, int inMonth) {
    mStartMonth = inMonth;

    T2DateTime *theNow = inDoc->GetNow();
    T2DateTime date = *theNow;

    int months = 12;
    for (int month = 0; month < 12; month++) {
        date.mMonth = month + mStartMonth - 1;
        if (date.mMonth >= 12) {
            date.mYear = theNow->mYear + 1;
            date.mMonth -= 12;
        }

        mIsHoliday[month] = date.IsHoliday(inDoc);
    }
}

/*virtual*/ void T2MonthlyTable::DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected) {
    DrawCell(pDC, inCell);
}

/*virtual*/ void T2MonthlyTable::DrawCell(CDC* pDC, const TableCellT& inCell) {
    int save = pDC->SaveDC();
    pDC->SelectPalette(mPalette, false);
    pDC->RealizePalette();

    CFont font;
    RECT cellRect;

    if (FetchLocalCellFrame(inCell, cellRect)) {
        int n = (inCell.row - 1) + mStartMonth;
        CString str;
        str.Format("%d", (n > 12) ? (n - 12) : n);

        if (mIsHoliday[inCell.row - 1])
            pDC->FillSolidRect(&cellRect, RGB(255, 152, 152));

        font.CreateFont(-9, 0, 0, 0, FW_DONTCARE, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY, DEFAULT_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E");

        pDC->SelectObject(&font);
        pDC->SetBkMode(TRANSPARENT);
        pDC->TextOut(cellRect.left + 4, cellRect.bottom - 12, str, strlen(str));

        if (inCell.row < 12)
            cellRect.bottom++;

        CBrush brush;
        brush.CreateSolidBrush(RGB(0, 0, 0));
        pDC->FrameRect(&cellRect, &brush);
    }

    pDC->RestoreDC(save);
}

void T2MonthlyTable::ClickCell(const TableCellT& inCell, const CPoint& inPt) {
    TableCellT cell;
    cell.row = 0;
    cell.col = 0;
    SelectCell(cell);
}

/*virtual*/ void T2MonthlyTable::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) {
    CPoint pt = inPt;
    ClientToView(&pt, 1);

    TableCellT cell;
    FetchCellHitBy(pt, cell);

    if (IsValidCell(cell))
        ClickCell(cell, inPt);
}

/*virtual*/ BOOL T2MonthlyTable::OnT2DlgItemEraseBkgnd(CDC* pDC) {
    T2VerticalTable::OnT2DlgItemEraseBkgnd(pDC);

    unsigned int numOfRows, numOfColumns, theRow, theColumn;

    GetTableSize(numOfRows, numOfColumns);
    for (theColumn = 1; theColumn <= numOfColumns; theColumn++) {
        for (theRow = 1; theRow <= numOfRows; theRow++) {
            TableCellT cell;
            cell.row = theRow;
            cell.col = theColumn;
            DrawCell(pDC, cell);
        }
    }

    return true;
}