-
Notifications
You must be signed in to change notification settings - Fork 33
/
InstrumentGridCtrl.cpp
127 lines (100 loc) · 3.46 KB
/
InstrumentGridCtrl.cpp
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
// InstrumentGridCtrl.cpp
#include "InstrumentGridCtrl.h"
#include "DataConverter.h"
BEGIN_MESSAGE_MAP(CInstrumentGridCtrl, CGridCtrl)
END_MESSAGE_MAP()
CInstrumentGridCtrl::CInstrumentGridCtrl(CWnd* pParent)
:columnCount(5),
fixedRow(1),
fixedColumn(1),
fontSize(13){
this->parentDlg = (CDlgInstrumentManager*)pParent;
COLORREF black = RGB(0, 0, 0);
this->SetListMode(TRUE);
this->SetGridLines(GVL_BOTH);
this->SetGridLineColor(black);
this->SetSingleRowSelection(TRUE);
this->SetSingleColSelection(TRUE);
}
CInstrumentGridCtrl::~CInstrumentGridCtrl(){
}
void CInstrumentGridCtrl::InitGrid(int itemCount){
this->DeleteAllItems();
this->SetRowCount(itemCount+1);
this->SetColumnCount(this->columnCount);
this->SetFixedRowCount(this->fixedRow);
this->SetFixedColumnCount(this->fixedColumn);
this->InitHeader();
}
void CInstrumentGridCtrl::InsertInstrumentList(const InstrumentList& instrumentList){
int rowIndex=0;
for(int i=0; i<instrumentList.GetLength(); i++){
rowIndex = i+1;
Instrument& instrument = const_cast<InstrumentList&>(instrumentList).GetAt(i);
this->InsertInstrument(rowIndex, instrument);
}
}
void CInstrumentGridCtrl::InitHeader(){
const tchar* columnTitles[] = {_T("Type"), _T("Name"), _T("Code"), _T("Contract"), _T("LimitOrderBook")};
const COLORREF GREY = RGB(160, 160, 160);
int colCount = this->GetColumnCount();
for (int i = 0; i < colCount; i++){
GV_ITEM item;
item.mask = GVIF_TEXT;
item.row = 0;
item.col = i;
item.crBkClr = GREY;
item.strText = columnTitles[i];
BOOL temp = this->SetItem(&item);
CGridCellBase* cellBase = this->GetCell(0, i);
LOGFONT* tempLogFont = cellBase->GetFont();
tempLogFont->lfHeight= this->fontSize;;
cellBase->SetFont(tempLogFont);
}
}
void CInstrumentGridCtrl::InsertInstrument(int rowIndex, const Instrument& instrument){
int columnIndex = 0;
GV_ITEM item;
item.mask = GVIF_TEXT;
item.row = rowIndex;
item.col = columnIndex;
item.strText = DataConverter::ConvertIntToString(rowIndex).c_str();
this->SetItem(&item);
columnIndex++;
item.col = columnIndex;
item.strText = instrument.GetInstrumentType().c_str();
this->SetItem(&item);
this->SetItemState(rowIndex, columnIndex, GVIS_READONLY);
columnIndex++;
item.col = columnIndex;
item.strText = instrument.GetInstrumentName().c_str();
this->SetItem(&item);
this->SetItemState(rowIndex, columnIndex, GVIS_READONLY);
columnIndex++;
item.col = columnIndex;
item.strText = instrument.GetInstrumentCode().c_str();
this->SetItem(&item);
this->SetItemState(rowIndex, columnIndex, GVIS_READONLY);
columnIndex++;
item.col = columnIndex;
item.strText = DataConverter::ConvertIntToString(instrument.GetContract().GetFeedingSourceID()).c_str();
this->SetItem(&item);
this->SetItemState(rowIndex, columnIndex, GVIS_READONLY);
columnIndex++;
item.col = columnIndex;
item.strText = DataConverter::ConvertIntToString(instrument.GetLimitOrderBook().GetFeedingSourceID()).c_str();
this->SetItem(&item);
this->SetItemState(rowIndex, columnIndex, GVIS_READONLY);
columnIndex++;
for(int i=0; i<this->columnCount; i++){
CGridCellBase* cellBase = this->GetCell(rowIndex, i);
LOGFONT* tempLogFont = cellBase->GetFont();
tempLogFont->lfHeight= this->fontSize;
cellBase->SetFont(tempLogFont);
}
}
void CInstrumentGridCtrl::DeleteAllInstruments(){
for(int i=0; i<this->GetRowCount(); i++){
this->DeleteRow(i);
}
}