summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2DlgItemTable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/T2DLL/T2DlgItemTable.cpp')
-rw-r--r--src/T2DLL/T2DlgItemTable.cpp655
1 files changed, 581 insertions, 74 deletions
diff --git a/src/T2DLL/T2DlgItemTable.cpp b/src/T2DLL/T2DlgItemTable.cpp
index a550c75..4382ef4 100644
--- a/src/T2DLL/T2DlgItemTable.cpp
+++ b/src/T2DLL/T2DlgItemTable.cpp
@@ -1,172 +1,679 @@
+#include "T2DlgItemHScr.h"
#include "T2DlgItemTable.h"
+#include "T2DlgItemVScr.h"
+#include <MINMAX.H>
-T2DlgItemTable::T2DlgItemTable(T2TowerDoc*, T2ImageObj*, CPalette*) {
+T2DlgItemTable::T2DlgItemTable(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette)
+ : T2DlgItem(towerDoc, imageObj, palette)
+{
+ InitTable(0, 0, 16, 100, 0);
}
-T2DlgItemTable::T2DlgItemTable(int, int, int, int, int, T2TowerDoc*, T2ImageObj*, CPalette*) {
+T2DlgItemTable::T2DlgItemTable(int rows, int cols, int rowHeight, int colWidth, int cellDataSize, T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette)
+ : T2DlgItem(towerDoc, imageObj, palette)
+{
+ InitTable(rows, cols, rowHeight, colWidth, cellDataSize);
}
/*virtual*/ T2DlgItemTable::~T2DlgItemTable() {
+ delete mCellData;
+ delete mMultiSelectedCells;
}
-void T2DlgItemTable::InitTable(int, int, int, int, int) {
+void T2DlgItemTable::InitTable(int rows, int cols, int rowHeight, int colWidth, int cellDataSize) {
+ mVScrollerStyle = ShowIfNeeded;
+ mHScrollerStyle = ShowIfNeeded;
+
+ mScrollOffset.x = 0;
+ mScrollOffset.y = 0;
+
+ mShowHScroller = false;
+ mShowVScroller = false;
+
+ mResizeCount = 0;
+
+ mRowHeight = rowHeight;
+ mColWidth = colWidth;
+
+ mCellData = NULL;
+ mMultiSelectedCells = NULL;
+
+ mSelectedCell.col = 0;
+ mSelectedCell.row = 0;
+
+ mClickedCell.col = 1;
+ mClickedCell.row = 1;
+
+ mCols = 0;
+ mRows = 0;
+
+ InsertRows(rows, 0, NULL);
+ InsertCols(cols, 0, NULL);
+ SetCellDataSize(cellDataSize);
}
-/*virtual*/ int T2DlgItemTable::Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int) {
+/*virtual*/ BOOL T2DlgItemTable::Create(const char* windowName, DWORD style, const RECT& rect, CWnd* parentWnd, UINT nId) {
+ return T2DlgItem::Create(windowName, style | WS_CLIPCHILDREN, rect, parentWnd, nId);
}
-/*virtual*/ int T2DlgItemTable::OnT2DlgItemCreate(CREATESTRUCTA*) {
+/*virtual*/ BOOL T2DlgItemTable::OnT2DlgItemCreate(CREATESTRUCT*) {
+ CRect rect;
+
+ GetClientRect(rect);
+ rect.left = rect.right - 16;
+ mVScroller = new T2DlgItemVScr(mTowerDoc, mImageObj, mPalette);
+ mVScroller->Create("", WS_CHILD, rect, this, 100);
+
+ GetClientRect(rect);
+ rect.top = rect.bottom - 16;
+ mHScroller = new T2DlgItemHScr(mTowerDoc, mImageObj, mPalette);
+ mHScroller->Create("", WS_CHILD, rect, this, 101);
+
+ return false;
}
-void T2DlgItemTable::GetTableSize(unsigned int&, unsigned int&) const {
+void T2DlgItemTable::GetTableSize(UINT& outRows, UINT& outCols) const {
+ outRows = mRows;
+ outCols = mCols;
}
-int T2DlgItemTable::IsMultiSelectable() const {
+BOOL T2DlgItemTable::IsMultiSelectable() const {
+ return (mMultiSelectedCells != NULL);
}
-void T2DlgItemTable::EnableMultiSelect(int) {
+void T2DlgItemTable::EnableMultiSelect(BOOL enabled) {
+ if (IsMultiSelectable()) {
+ if (!enabled) {
+ delete mMultiSelectedCells;
+ mMultiSelectedCells = NULL;
+ }
+ } else {
+ if (enabled) {
+ mMultiSelectedCells = new LArray(sizeof(TableCellT));
+ }
+ }
}
/*virtual*/ void T2DlgItemTable::ClearSelectedCells() {
-}
+ if (IsValidCell(mSelectedCell))
+ InvalidateCell(mSelectedCell);
-int T2DlgItemTable::IsValidCell(const TableCellT&) const {
-}
+ mSelectedCell.col = 0;
+ mSelectedCell.row = 0;
-int T2DlgItemTable::EqualCell(const TableCellT&, const TableCellT&) const {
-}
+ if (IsMultiSelectable()) {
+ LArrayIterator iter(*mMultiSelectedCells);
+ TableCellT iterCell;
+ while (iter.Next(&iterCell))
+ InvalidateCell(iterCell);
-/*virtual*/ void T2DlgItemTable::InsertRows(int, unsigned int, void*) {
+ mMultiSelectedCells->RemoveItemsAt(mMultiSelectedCells->GetCount(), 1);
+ }
}
-/*virtual*/ void T2DlgItemTable::InsertCols(int, unsigned int, void*) {
+BOOL T2DlgItemTable::IsValidCell(const TableCellT& cell) const {
+ return (cell.row > 0) && (cell.row <= mRows) && (cell.col > 0) && (cell.col <= mCols);
}
-/*virtual*/ void T2DlgItemTable::RemoveRows(int, unsigned int) {
+BOOL T2DlgItemTable::EqualCell(const TableCellT& a, const TableCellT& b) const {
+ return (a.row == b.row) && (a.col == b.col);
}
-/*virtual*/ void T2DlgItemTable::RemoveCols(int, unsigned int) {
-}
+/*virtual*/ void T2DlgItemTable::InsertRows(int count, UINT where, void* data) {
+ if (mCellData)
+ mCellData->InsertItemsAt(count * mCols, where * mCols + 1, data);
-/*virtual*/ void T2DlgItemTable::SetRowHeight(int, unsigned int, unsigned int) {
+ mRows += count;
+ ClearSelectedCells();
+ Resized();
}
-/*virtual*/ void T2DlgItemTable::SetColWidth(int, unsigned int, unsigned int) {
-}
+/*virtual*/ void T2DlgItemTable::InsertCols(int count, UINT where, void* data) {
+ if (mCellData) {
+ UINT index = where + 1;
+ for (UINT i = 1; i <= mRows; i++) {
+ mCellData->InsertItemsAt(count, index, data);
+ index += (mCols + count);
+ }
+ }
-void T2DlgItemTable::SetCellDataSize(int) {
+ mCols += count;
+ ClearSelectedCells();
+ Resized();
}
-/*virtual*/ void T2DlgItemTable::SetCellData(const TableCellT&, void*) {
-}
+/*virtual*/ void T2DlgItemTable::RemoveRows(int count, UINT where) {
+ if (mCellData)
+ mCellData->RemoveItemsAt(count * mCols, (where - 1) * mCols + 1);
-/*virtual*/ void T2DlgItemTable::GetCellData(const TableCellT&, void*) {
+ mRows -= count;
+ ClearSelectedCells();
+ Resized();
}
-/*virtual*/ int T2DlgItemTable::FetchLocalCellFrame(const TableCellT&, RECT&) {
-}
+/*virtual*/ void T2DlgItemTable::RemoveCols(int count, UINT where) {
+ if (mCellData) {
+ UINT index = where;
+ for (UINT n = 1; n <= mRows; n++) {
+ mCellData->RemoveItemsAt(count, index);
+ index += (mCols - count);
+ }
+ }
-/*virtual*/ void T2DlgItemTable::FetchCellHitBy(const POINT&, TableCellT&) {
+ mCols -= count;
+ ClearSelectedCells();
+ Resized();
}
-int T2DlgItemTable::FetchCellDataIndex(const TableCellT&) {
+/*virtual*/ void T2DlgItemTable::SetRowHeight(int height, unsigned int, unsigned int) {
+ mRowHeight = height;
}
-/*virtual*/ void T2DlgItemTable::ClickSelf(const POINT&, unsigned int) {
+/*virtual*/ void T2DlgItemTable::SetColWidth(int width, unsigned int, unsigned int) {
+ mColWidth = width;
}
-/*virtual*/ int T2DlgItemTable::OnT2DlgItemEraseBkgnd(CDC*) {
+void T2DlgItemTable::SetCellDataSize(int size) {
+ if (!mCellData && size > 0) {
+ mCellData = new LArray(size);
+ mCellData->InsertItemsAt(mRows * mCols, 1, NULL);
+ }
}
-/*virtual*/ void T2DlgItemTable::HiliteCell(CDC*, const TableCellT&) {
+/*virtual*/ void T2DlgItemTable::SetCellData(const TableCellT& cell, void* data) {
+ if (mCellData)
+ mCellData->AssignItemsAt(1, FetchCellDataIndex(cell), data);
}
-/*virtual*/ void T2DlgItemTable::UnhiliteCell(CDC*, const TableCellT&) {
+/*virtual*/ void T2DlgItemTable::GetCellData(const TableCellT& cell, void* data) {
+ if (mCellData)
+ mCellData->FetchItemAt(FetchCellDataIndex(cell), data);
}
-/*virtual*/ void T2DlgItemTable::HiliteCells(CDC*, LArrayIterator&) {
+/*virtual*/ BOOL T2DlgItemTable::FetchLocalCellFrame(const TableCellT& cell, RECT& rect) {
+ rect.left = (cell.col - 1) * mColWidth;
+ rect.top = (cell.row - 1) * mRowHeight;
+ ViewToClient((POINT *) &rect.left, 1);
+ rect.right = rect.left + mColWidth;
+ rect.bottom = rect.top + mRowHeight;
+ return true;
}
-/*virtual*/ void T2DlgItemTable::UnhiliteCells(CDC*, LArrayIterator&) {
+/*virtual*/ void T2DlgItemTable::FetchCellHitBy(const POINT& pt, TableCellT& cell) {
+ cell.row = pt.y / mRowHeight + 1;
+ cell.col = pt.x / mColWidth + 1;
}
-/*virtual*/ void T2DlgItemTable::ClickCell(const TableCellT&, const POINT&) {
+int T2DlgItemTable::FetchCellDataIndex(const TableCellT& cell) {
+ return (cell.row - 1) * mCols + cell.col;
}
-/*virtual*/ void T2DlgItemTable::DrawCell(CDC*, const TableCellT&) {
-}
+TableCellIterator::TableCellIterator(const TableCellT& start, const TableCellT& end) {
+ mLastRow = (start.row > end.row) ? start.row : end.row;
+ mFirstCol = (start.col < end.col) ? start.col : end.col;
+ mLastCol = (start.col > end.col) ? start.col : end.col;
-/*virtual*/ void T2DlgItemTable::SelectCell(const TableCellT&) {
+ mCurrentRow = ((start.row < end.row) ? start.row : end.row) - 1;
+ mCurrentCol = mLastCol;
}
-/*virtual*/ void T2DlgItemTable::ToggleCell(const TableCellT&) {
-}
+BOOL TableCellIterator::Next(TableCellT& newCurrent) {
+ mCurrentCol++;
+ if (mCurrentCol > mLastCol) {
+ mCurrentRow++;
+ mCurrentCol = mFirstCol;
+ }
-int T2DlgItemTable::IsSelected(const TableCellT&) const {
+ BOOL isValid = (mCurrentRow <= mLastRow);
+ if (isValid) {
+ newCurrent.row = mCurrentRow;
+ newCurrent.col = mCurrentCol;
+ }
+ return isValid;
}
-void T2DlgItemTable::GetSelectedCell(TableCellT&) const {
-}
+/*virtual*/ void T2DlgItemTable::ClickSelf(const POINT& pt, UINT nFlags) {
+ UINT keyFlags = IsMultiSelectable() ? (nFlags & (MK_SHIFT | MK_CONTROL)) : 0;
+ POINT ptView = pt;
+ ClientToView(&ptView, 1);
-void T2DlgItemTable::InvalidateCell(const TableCellT&) {
-}
+ TableCellT cellClicked;
+ FetchCellHitBy(ptView, cellClicked);
-int T2DlgItemTable::Resized() {
+ if (IsValidCell(cellClicked)) {
+ switch (keyFlags) {
+ case MK_SHIFT:
+ ClearSelectedCells();
+ case (MK_SHIFT | MK_CONTROL):
+ {
+ TableCellIterator cellIterator(mClickedCell, cellClicked);
+ TableCellT cell;
+ while (cellIterator.Next(cell))
+ SelectCell(cell);
+ }
+ break;
+ case MK_CONTROL:
+ ToggleCell(cellClicked);
+ mClickedCell = cellClicked;
+ break;
+ default:
+ ClickCell(cellClicked, pt);
+ mClickedCell = cellClicked;
+ break;
+ }
+ }
}
-void T2DlgItemTable::ViewToClient(POINT*, int) {
-}
+/*virtual*/ BOOL T2DlgItemTable::OnT2DlgItemEraseBkgnd(CDC* dc) {
+ int save = dc->SaveDC();
-void T2DlgItemTable::ClientToView(POINT*, int) {
-}
+ dc->SelectPalette(mPalette, false);
+ dc->RealizePalette();
-/*virtual*/ void T2DlgItemTable::OnT2DlgItemLButtonDown(unsigned int, CPoint) {
-}
+ CPen pen;
+ pen.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255));
-/*virtual*/ void T2DlgItemTable::OnT2DlgItemLButtonUp(unsigned int, CPoint) {
-}
+ if (mShowHScroller && mShowVScroller) {
+ CRect insideRect;
+ GetClientRect(insideRect);
+ insideRect.right -= 16;
+ insideRect.bottom -= 16;
-/*virtual*/ void T2DlgItemTable::OnT2DlgItemMouseMove(unsigned int, CPoint) {
-}
+ dc->SelectObject(pen);
+ dc->MoveTo(insideRect.right - 1, insideRect.top);
+ dc->LineTo(insideRect.right - 1, insideRect.bottom - 1);
+ dc->LineTo(insideRect.left, insideRect.bottom - 1);
+ insideRect.right -= 1;
+ insideRect.bottom -= 1;
+ dc->FillSolidRect(&insideRect, PALETTERGB(204, 204, 204));
+ }
-/*virtual*/ int T2DlgItemTable::OnCommand(unsigned int, long) {
-}
+ CRect clipRect;
+ dc->GetClipBox(clipRect);
-/*virtual*/ void T2DlgItemTable::OnT2Size(unsigned int, int, int) {
-}
+ CRect clientRect;
+ GetClientRect(clientRect);
-void T2DlgItemTable::DoScroll() {
-}
+ clientRect.right -= mShowVScroller ? 16 : 0;
+ clientRect.bottom -= mShowHScroller ? 16 : 0;
+
+ clipRect.bottom = min(clipRect.bottom, clientRect.bottom);
+ clipRect.right = min(clipRect.right, clientRect.right);
+
+ dc->IntersectClipRect(&clientRect);
-/*virtual*/ void T2DlgItemTable::ListenToMessage(unsigned int, void*) {
+ CPoint topLeft;
+ topLeft = clipRect.TopLeft();
+ ClientToView(&topLeft, 1);
+
+ TableCellT topLeftCell;
+ FetchCellHitBy(topLeft, topLeftCell);
+
+ if (topLeftCell.row < 1)
+ topLeftCell.row = 1;
+ if (topLeftCell.col < 1)
+ topLeftCell.col = 1;
+
+ CPoint bottomRight = clipRect.BottomRight();
+ ClientToView(&bottomRight, 1);
+
+ TableCellT bottomRightCell;
+ FetchCellHitBy(bottomRight, bottomRightCell);
+
+ if (bottomRightCell.row > mRows)
+ bottomRightCell.row = mRows;
+ if (bottomRightCell.col > mCols)
+ bottomRightCell.col = mCols;
+
+ TableCellT i;
+ for (i.row = topLeftCell.row; i.row <= bottomRightCell.row; i.row++) {
+ for (i.col = topLeftCell.col; i.col <= bottomRightCell.col; i.col++) {
+ DrawCell(dc, i);
+ }
+ }
+
+ if (IsMultiSelectable()) {
+ LArrayIterator iter(*mMultiSelectedCells);
+ HiliteCells(dc, iter);
+ } else {
+ HiliteCell(dc, mSelectedCell);
+ }
+
+ dc->RestoreDC(save);
+ return true;
+}
+
+/*virtual*/ void T2DlgItemTable::HiliteCell(CDC* dc, const TableCellT& cell) {
+ RECT cellFrameRect;
+ if (IsValidCell(cell) && FetchLocalCellFrame(cell, cellFrameRect))
+ dc->InvertRect(&cellFrameRect);
}
-T2DlgItemHScr* T2DlgItemTable::GetHScroller() const {
+/*virtual*/ void T2DlgItemTable::UnhiliteCell(CDC* dc, const TableCellT& cell) {
+ RECT cellFrameRect;
+ if (IsValidCell(cell) && FetchLocalCellFrame(cell, cellFrameRect))
+ dc->InvertRect(&cellFrameRect);
}
-T2DlgItemVScr* T2DlgItemTable::GetVScroller() const {
+/*virtual*/ void T2DlgItemTable::HiliteCells(CDC* dc, LArrayIterator& iterator) {
+ TableCellT cell;
+
+ while (iterator.Next(&cell))
+ HiliteCell(dc, cell);
}
-void T2DlgItemTable::AttachHScroller(T2DlgItemHScr*, int) {
+/*virtual*/ void T2DlgItemTable::UnhiliteCells(CDC* dc, LArrayIterator& iterator) {
+ TableCellT cell;
+
+ while (iterator.Next(&cell))
+ UnhiliteCell(dc, cell);
}
-void T2DlgItemTable::AttachVScroller(T2DlgItemVScr*, int) {
+/*virtual*/ void T2DlgItemTable::ClickCell(const TableCellT& cell, const POINT&) {
+ ClearSelectedCells();
+ SelectCell(cell);
}
-void T2DlgItemTable::SetHScrollerStyle(T2DlgItemTable::ScrollerStyle) {
+/*virtual*/ void T2DlgItemTable::DrawCell(CDC* dc, const TableCellT& cell) {
+ CRect rect;
+ if (FetchLocalCellFrame(cell, rect)) {
+ int save = dc->SaveDC();
+
+ CBrush brush;
+ brush.CreateSolidBrush(PALETTEINDEX(0));
+
+ CPen pen0;
+ pen0.CreatePen(PS_SOLID, 0, PALETTEINDEX(255));
+
+ dc->SelectObject(&brush);
+ dc->SelectObject(&pen0);
+ dc->SetBkMode(TRANSPARENT);
+ dc->Rectangle(rect);
+
+ CString text;
+ text.Format("%d,%d", cell.row, cell.col);
+ dc->DrawText(text, rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
+
+ dc->RestoreDC(save);
+ }
+}
+
+/*virtual*/ void T2DlgItemTable::SelectCell(const TableCellT& cell) {
+ if (IsMultiSelectable()) {
+ if (!IsSelected(cell)) {
+ mSelectedCell = cell;
+ InvalidateCell(mSelectedCell);
+ mMultiSelectedCells->Add(&cell);
+ }
+ } else {
+ if (!EqualCell(cell, mSelectedCell)) {
+ InvalidateCell(mSelectedCell);
+ mSelectedCell = cell;
+ InvalidateCell(mSelectedCell);
+ Notify(0, &mSelectedCell);
+ }
+ }
+}
+
+/*virtual*/ void T2DlgItemTable::ToggleCell(const TableCellT& cell) {
+ if (IsSelected(cell)) {
+ mMultiSelectedCells->Remove(&cell);
+ if (EqualCell(cell, mSelectedCell)) {
+ mSelectedCell.col = 0;
+ mSelectedCell.row = 0;
+ mMultiSelectedCells->FetchItemAt(1, &mSelectedCell);
+ }
+ } else {
+ mMultiSelectedCells->Add(&cell);
+ }
+ InvalidateCell(cell);
+}
+
+BOOL T2DlgItemTable::IsSelected(const TableCellT& cell) const {
+ return IsMultiSelectable()
+ ? (mMultiSelectedCells->FetchIndexOf(&cell) != 0)
+ : EqualCell(mSelectedCell, cell);
+}
+
+void T2DlgItemTable::GetSelectedCell(TableCellT& cell) const {
+ cell = mSelectedCell;
+}
+
+void T2DlgItemTable::InvalidateCell(const TableCellT& cell) {
+ CRect rect;
+ if (FetchLocalCellFrame(cell, rect))
+ InvalidateRect(rect);
+}
+
+BOOL T2DlgItemTable::Resized() {
+ if (!m_hWnd)
+ return false;
+
+ BOOL changed = false;
+ mResizeCount++;
+
+ CRect clientRect;
+ GetClientRect(clientRect);
+ clientRect.right -= mShowVScroller ? 16 : 0;
+ clientRect.bottom -= mShowHScroller ? 16 : 0;
+
+ CRect tableRect;
+ tableRect.left = 0;
+ tableRect.top = 0;
+ tableRect.right = mColWidth * mCols;
+ tableRect.right = mRowHeight * mRows;
+
+ if (
+ (mHScrollerStyle == ShowIfNeeded && tableRect.Width() > clientRect.Width()) ||
+ mHScrollerStyle == AlwaysShow
+ )
+ {
+ if (!mShowHScroller && !changed) {
+ mShowHScroller = true;
+ changed = true;
+ }
+ }
+
+ if (
+ (mHScrollerStyle == ShowIfNeeded && tableRect.Width() <= clientRect.Width()) ||
+ (mHScrollerStyle != ShowIfNeeded && mHScrollerStyle != AlwaysShow)
+ )
+ {
+ if (mShowHScroller && !changed) {
+ mShowHScroller = false;
+ changed = true;
+ }
+ }
+
+ if (
+ (mVScrollerStyle == ShowIfNeeded && tableRect.Height() > clientRect.Height()) ||
+ mVScrollerStyle == AlwaysShow
+ )
+ {
+ if (!mShowVScroller && !changed) {
+ mShowVScroller = true;
+ changed = true;
+ }
+ }
+
+ if (
+ (mVScrollerStyle == ShowIfNeeded && tableRect.Height() <= clientRect.Height()) ||
+ (mVScrollerStyle != ShowIfNeeded && mVScrollerStyle != AlwaysShow)
+ )
+ {
+ if (mShowVScroller && !changed) {
+ mShowVScroller = false;
+ changed = true;
+ }
+ }
+
+ if (changed)
+ Resized();
+
+ mResizeCount--;
+
+ GetClientRect(clientRect);
+ clientRect.right -= mShowVScroller ? 16 : 0;
+ clientRect.bottom -= mShowHScroller ? 16 : 0;
+
+ if (mHScrollerStyle != AttachedNoUpdates) {
+ mHScroller->SetPage(clientRect.Width() / ((mColWidth > 0) ? mColWidth : 1));
+ mHScroller->SetRange(mCols);
+ }
+ if (mVScrollerStyle != AttachedNoUpdates) {
+ mVScroller->SetPage(clientRect.Height() / ((mRowHeight > 0) ? mRowHeight : 1));
+ mVScroller->SetRange(mRows);
+ }
+
+ if (IsOwnHScroller())
+ mHScroller->SetWindowPos(NULL, 0, 0, clientRect.Width(), 16, SWP_NOMOVE | SWP_NOZORDER);
+ if (IsOwnVScroller())
+ mVScroller->SetWindowPos(NULL, 0, 0, 16, clientRect.Height(), SWP_NOMOVE | SWP_NOZORDER);
+
+ if (mResizeCount == 0 && changed) {
+ if ((mHScrollerStyle == ShowIfNeeded && !mShowHScroller) || (mHScrollerStyle == AlwaysHide))
+ mHScroller->ShowWindow(SW_HIDE);
+ if ((mVScrollerStyle == ShowIfNeeded && !mShowVScroller) || (mVScrollerStyle == AlwaysHide))
+ mVScroller->ShowWindow(SW_HIDE);
+
+ if ((mHScrollerStyle == ShowIfNeeded && mShowHScroller) || (mHScrollerStyle == AlwaysShow))
+ mHScroller->ShowWindow(SW_SHOW);
+ if ((mVScrollerStyle == ShowIfNeeded && mShowVScroller) || (mVScrollerStyle == AlwaysShow))
+ mVScroller->ShowWindow(SW_SHOW);
+ }
+
+ return changed;
+}
+
+void T2DlgItemTable::ViewToClient(POINT* pt, int n) {
+ for (int i = 0; i < n; i++) {
+ pt->x -= mScrollOffset.x;
+ pt->y -= mScrollOffset.y;
+ pt++;
+ }
+}
+
+void T2DlgItemTable::ClientToView(POINT* pt, int n) {
+ for (int i = 0; i < n; i++) {
+ pt->x += mScrollOffset.x;
+ pt->y += mScrollOffset.y;
+ pt++;
+ }
+}
+
+/*virtual*/ void T2DlgItemTable::OnT2DlgItemLButtonDown(UINT nFlags, CPoint pt) {
+ ClickSelf(pt, nFlags);
+}
+
+/*virtual*/ void T2DlgItemTable::OnT2DlgItemLButtonUp(UINT, CPoint) {
+}
+
+/*virtual*/ void T2DlgItemTable::OnT2DlgItemMouseMove(UINT, CPoint) {
+}
+
+/*virtual*/ BOOL T2DlgItemTable::OnCommand(UINT, long) {
+ DoScroll();
+ return true;
}
-void T2DlgItemTable::SetVScrollerStyle(T2DlgItemTable::ScrollerStyle) {
+/*virtual*/ void T2DlgItemTable::OnT2Size(unsigned int, int, int) {
+ Resized();
}
-int T2DlgItemTable::IsOwnHScroller() const {
+void T2DlgItemTable::DoScroll() {
+ POINT prevOffset = mScrollOffset;
+ mScrollOffset.x = mHScroller->GetValue() * ((mColWidth > 0) ? mColWidth : 1);
+ mScrollOffset.y = mVScroller->GetValue() * ((mRowHeight > 0) ? mRowHeight : 1);
+
+ CRect clientRect;
+ GetClientRect(clientRect);
+ clientRect.right -= mShowVScroller ? 16 : 0;
+ clientRect.bottom -= mShowHScroller ? 16 : 0;
+ ScrollWindowEx(prevOffset.x - mScrollOffset.x, prevOffset.y - mScrollOffset.y, &clientRect, NULL, NULL, NULL, SW_INVALIDATE | SW_ERASE);
}
-int T2DlgItemTable::IsOwnVScroller() const {
+/*virtual*/ void T2DlgItemTable::ListenToMessage(unsigned int msg, void*) {
+ if (
+ (!IsOwnHScroller() && msg == mHScroller->GetDlgCtrlID()) ||
+ (!IsOwnVScroller() && msg == mVScroller->GetDlgCtrlID())
+ )
+ DoScroll();
}
-TableCellIterator::TableCellIterator(const TableCellT&, const TableCellT&) {
+T2DlgItemHScr* T2DlgItemTable::GetHScroller() const {
+ return mHScroller;
}
-int TableCellIterator::Next(TableCellT&) {
+T2DlgItemVScr* T2DlgItemTable::GetVScroller() const {
+ return mVScroller;
+}
+
+void T2DlgItemTable::AttachHScroller(T2DlgItemHScr* scroller, BOOL flag) {
+ if (scroller) {
+ if (IsOwnHScroller())
+ delete mHScroller;
+
+ mHScroller = scroller;
+ mHScrollerStyle = flag ? AttachedNoUpdates : Attached;
+ mHScroller->AddListener(this);
+ Resized();
+ }
+}
+
+void T2DlgItemTable::AttachVScroller(T2DlgItemVScr* scroller, BOOL flag) {
+ if (scroller) {
+ if (IsOwnVScroller())
+ delete mVScroller;
+
+ mVScroller = scroller;
+ mVScrollerStyle = flag ? AttachedNoUpdates : Attached;
+ mVScroller->AddListener(this);
+ Resized();
+ }
+}
+
+void T2DlgItemTable::SetHScrollerStyle(ScrollerStyle style) {
+ switch (style) {
+ case ShowIfNeeded:
+ case AlwaysHide:
+ case AlwaysShow:
+ if (IsOwnHScroller() && mHScrollerStyle != style) {
+ mHScrollerStyle = style;
+ Resized();
+ }
+ }
+}
+
+void T2DlgItemTable::SetVScrollerStyle(ScrollerStyle style) {
+ switch (style) {
+ case ShowIfNeeded:
+ case AlwaysHide:
+ case AlwaysShow:
+ if (IsOwnVScroller() && mVScrollerStyle != style) {
+ mVScrollerStyle = style;
+ Resized();
+ }
+ }
+}
+
+BOOL T2DlgItemTable::IsOwnHScroller() const {
+ BOOL result = false;
+ switch (mHScrollerStyle) {
+ case ShowIfNeeded:
+ case AlwaysHide:
+ case AlwaysShow:
+ result = true;
+ }
+ return result;
+}
+
+BOOL T2DlgItemTable::IsOwnVScroller() const {
+ BOOL result = false;
+ switch (mVScrollerStyle) {
+ case ShowIfNeeded:
+ case AlwaysHide:
+ case AlwaysShow:
+ result = true;
+ }
+ return result;
}