8 #define MIN(x,y) ((x)<(y) ? (x) : (y)) 12 m_contentView(this, dataSource, 0, 1)
34 #if ESCHER_VIEW_LOGGING 35 const char * TableView::className()
const {
57 m_tableView(tableView),
58 m_dataSource(dataSource),
59 m_horizontalCellOverlap(horizontalCellOverlap),
60 m_verticalCellOverlap(verticalCellOverlap)
65 return KDSize(width(), height());
72 KDCoordinate TableView::ContentView::columnWidth(
int i)
const {
73 int columnWidth = m_dataSource->columnWidth(i);
74 columnWidth = columnWidth ? columnWidth : m_tableView->maxContentWidthDisplayableWithoutScrolling();
84 return m_dataSource->cumulatedHeightFromIndex(m_dataSource->numberOfRows())+m_verticalCellOverlap;
88 int result = m_dataSource->cumulatedWidthFromIndex(m_dataSource->numberOfColumns())+m_horizontalCellOverlap;
90 return result ? result : m_tableView->maxContentWidthDisplayableWithoutScrolling();
94 KDRect cellRect =
KDRect(m_dataSource->cumulatedWidthFromIndex(x), m_dataSource->cumulatedHeightFromIndex(y), columnWidth(x), m_dataSource->rowHeight(y));
95 m_tableView->scrollToContentRect(cellRect,
true);
99 m_dataSource->willDisplayCellAtLocation(
cellAtLocation(i, j), i, j);
102 int TableView::ContentView::typeOfSubviewAtIndex(
int index)
const {
104 int i = absoluteColumnNumberFromSubviewIndex(index);
105 int j = absoluteRowNumberFromSubviewIndex(index);
106 int type = m_dataSource->typeAtLocation(i, j);
110 int TableView::ContentView::typeIndexFromSubviewIndex(
int index,
int type)
const {
112 for (
int k = 0; k < index; k++) {
113 if (typeOfSubviewAtIndex(k) == type) {
117 assert(typeIndex < m_dataSource->reusableCellCount(type));
122 int relativeX = x-columnsScrollingOffset();
123 int relativeY = y-rowsScrollingOffset();
124 int type = m_dataSource->typeAtLocation(x, y);
125 int index = relativeY*numberOfDisplayableColumns()+relativeX;
126 int typeIndex = typeIndexFromSubviewIndex(index, type);
127 return m_dataSource->reusableCell(typeIndex, type);
130 #if ESCHER_VIEW_LOGGING 131 const char * TableView::ContentView::className()
const {
132 return "TableView::ContentView";
136 int TableView::ContentView::numberOfSubviews()
const {
137 int result = numberOfDisplayableRows() * numberOfDisplayableColumns();
141 int TableView::ContentView::absoluteColumnNumberFromSubviewIndex(
int index)
const {
144 int j = index / numberOfDisplayableColumns();
145 int i = index - j * numberOfDisplayableColumns();
146 int columnOffset = columnsScrollingOffset();
147 return i + columnOffset;
150 int TableView::ContentView::absoluteRowNumberFromSubviewIndex(
int index)
const {
151 int j = index / numberOfDisplayableColumns();
152 int rowOffset = rowsScrollingOffset();
153 return j + rowOffset;
156 View * TableView::ContentView::subviewAtIndex(
int index) {
157 int type = typeOfSubviewAtIndex(index);
158 int typeIndex = typeIndexFromSubviewIndex(index, type);
159 return m_dataSource->reusableCell(typeIndex, type);
162 void TableView::ContentView::layoutSubviews() {
163 for (
int index=0; index<numberOfSubviews(); index++) {
165 int i = absoluteColumnNumberFromSubviewIndex(index);
166 int j = absoluteRowNumberFromSubviewIndex(index);
167 m_dataSource->willDisplayCellAtLocation((
HighlightCell *)cell, i, j);
171 KDCoordinate verticalOffset = m_dataSource->cumulatedHeightFromIndex(j);
172 KDCoordinate horizontalOffset = m_dataSource->cumulatedWidthFromIndex(i);
173 KDRect cellFrame(horizontalOffset, verticalOffset,
174 columnWidth+m_horizontalCellOverlap, rowHeight+m_verticalCellOverlap);
180 int TableView::ContentView::numberOfFullyDisplayableRows()
const {
182 int rowOffsetWithMargin = m_dataSource->indexFromCumulatedHeight(m_tableView->contentOffset().y() +
183 m_tableView->topMargin());
184 int displayedHeightWithOffsetAndMargin = m_dataSource->indexFromCumulatedHeight(m_tableView->maxContentHeightDisplayableWithoutScrolling() +
185 m_tableView->contentOffset().y() + m_tableView->topMargin());
186 return displayedHeightWithOffsetAndMargin - rowOffsetWithMargin;
189 int TableView::ContentView::numberOfFullyDisplayableColumns()
const {
191 int columnOffsetWithMargin = m_dataSource->indexFromCumulatedWidth(m_tableView->contentOffset().x() +
192 m_tableView->leftMargin());
193 int displayedWidthWithOffsetAndMargin = m_dataSource->indexFromCumulatedWidth(m_tableView->maxContentWidthDisplayableWithoutScrolling() +
194 m_tableView->contentOffset().x() + m_tableView->leftMargin());
195 return displayedWidthWithOffsetAndMargin - columnOffsetWithMargin;
198 int TableView::ContentView::numberOfDisplayableRows()
const {
199 int rowOffset = rowsScrollingOffset();
200 int displayedHeightWithOffset = m_dataSource->indexFromCumulatedHeight(m_tableView->bounds().height() + m_tableView->contentOffset().y());
202 m_dataSource->numberOfRows(),
203 displayedHeightWithOffset + 1
207 int TableView::ContentView::numberOfDisplayableColumns()
const {
208 int columnOffset = columnsScrollingOffset();
209 int displayedWidthWithOffset = m_dataSource->indexFromCumulatedWidth(m_tableView->bounds().width() + m_tableView->contentOffset().x());
211 m_dataSource->numberOfColumns(),
212 displayedWidthWithOffset + 1
216 int TableView::ContentView::rowsScrollingOffset()
const {
219 KDCoordinate invisibleHeight = m_tableView->contentOffset().y()-m_tableView->topMargin();
220 invisibleHeight = invisibleHeight < 0 ? 0 : invisibleHeight;
221 return m_dataSource->indexFromCumulatedHeight(invisibleHeight);
224 int TableView::ContentView::columnsScrollingOffset()
const {
227 KDCoordinate invisibleWidth = m_tableView->contentOffset().x()-m_tableView->leftMargin();
228 invisibleWidth = invisibleWidth < 0 ? 0 : invisibleWidth;
229 return m_dataSource->indexFromCumulatedWidth(invisibleWidth);
void setFrame(KDRect frame)
ContentView(TableView *tableView, TableViewDataSource *dataSource, KDCoordinate horizontalCellOverlap, KDCoordinate verticalCellOverlap)
void layoutSubviews() override
virtual void scrollToCell(int i, int j)
KDSize minimalSizeForOptimalDisplay() const override
HighlightCell * cellAtLocation(int i, int j)
void scrollToCell(int i, int j) const
TableViewDataSource * dataSource()
void setSize(KDSize size)
void reloadCellAtLocation(int i, int j)
KDSize minimalSizeForOptimalDisplay() const override
TableViewDataSource * dataSource()
ContentView m_contentView
HighlightCell * cellAtLocation(int i, int j)
void reloadCellAtLocation(int i, int j)
TableView(TableViewDataSource *dataSource, ScrollViewDataSource *scrollDataSource)
void resizeToFitContent()
View * subview(int index)