mirror of https://github.com/buggins/dlangui.git
spreadsheet
This commit is contained in:
parent
2dbb69b5a6
commit
efeb1b94d4
|
@ -60,7 +60,7 @@ class SpreadSheetView : StringGridWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SpreadSheetWidget : WidgetGroupDefaultDrawing, OnScrollHandler {
|
class SpreadSheetWidget : WidgetGroupDefaultDrawing, OnScrollHandler, CellSelectedHandler, CellActivatedHandler, ViewScrolledHandler {
|
||||||
|
|
||||||
SheetEditControl _editControl;
|
SheetEditControl _editControl;
|
||||||
SheetTabs _tabs;
|
SheetTabs _tabs;
|
||||||
|
@ -106,10 +106,10 @@ class SpreadSheetWidget : WidgetGroupDefaultDrawing, OnScrollHandler {
|
||||||
_viewBottomLeft = new SpreadSheetView("sheetViewBottomLeft");
|
_viewBottomLeft = new SpreadSheetView("sheetViewBottomLeft");
|
||||||
_viewBottomRight = new SpreadSheetView("sheetViewBottomRight");
|
_viewBottomRight = new SpreadSheetView("sheetViewBottomRight");
|
||||||
|
|
||||||
_viewTopRight.headerCols = 0;
|
_viewTopRight.setColWidth(0, 0);
|
||||||
_viewBottomLeft.headerRows = 0;
|
_viewBottomLeft.setRowHeight(0, 0);
|
||||||
_viewBottomRight.headerCols = 0;
|
_viewBottomRight.setRowHeight(0, 0);
|
||||||
_viewBottomRight.headerRows = 0;
|
_viewBottomRight.setColWidth(0, 0);
|
||||||
|
|
||||||
_views[0] = _viewTopLeft;
|
_views[0] = _viewTopLeft;
|
||||||
_views[1] = _viewTopRight;
|
_views[1] = _viewTopRight;
|
||||||
|
@ -132,6 +132,11 @@ class SpreadSheetWidget : WidgetGroupDefaultDrawing, OnScrollHandler {
|
||||||
|
|
||||||
foreach(sb; _scrollbars)
|
foreach(sb; _scrollbars)
|
||||||
sb.onScrollEventListener = this;
|
sb.onScrollEventListener = this;
|
||||||
|
foreach(view; _views) {
|
||||||
|
view.cellSelected = this;
|
||||||
|
view.cellActivated = this;
|
||||||
|
view.viewScrolled = this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Measure widget according to desired width and height constraints. (Step 1 of two phase layout).
|
/// Measure widget according to desired width and height constraints. (Step 1 of two phase layout).
|
||||||
|
@ -198,4 +203,21 @@ class SpreadSheetWidget : WidgetGroupDefaultDrawing, OnScrollHandler {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Callback for handling of cell selection
|
||||||
|
void onCellSelected(GridWidgetBase source, int col, int row) {
|
||||||
|
foreach(view; _views) {
|
||||||
|
if (source != view)
|
||||||
|
view.selectCell(col + view.headerCols, row + view.headerRows, false, source, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Callback for handling of cell double click or Enter key press
|
||||||
|
void onCellActivated(GridWidgetBase source, int col, int row) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Callback for handling of view scroll (top left visible cell change)
|
||||||
|
void onViewScrolled(GridWidgetBase source, int col, int row) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,6 +225,11 @@ interface CellActivatedHandler {
|
||||||
void onCellActivated(GridWidgetBase source, int col, int row);
|
void onCellActivated(GridWidgetBase source, int col, int row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Callback for handling of view scroll (top left visible cell change)
|
||||||
|
interface ViewScrolledHandler {
|
||||||
|
void onViewScrolled(GridWidgetBase source, int col, int row);
|
||||||
|
}
|
||||||
|
|
||||||
/// Abstract grid widget
|
/// Abstract grid widget
|
||||||
class GridWidgetBase : ScrollWidgetBase {
|
class GridWidgetBase : ScrollWidgetBase {
|
||||||
/// Callback to handle selection change
|
/// Callback to handle selection change
|
||||||
|
@ -237,6 +242,9 @@ class GridWidgetBase : ScrollWidgetBase {
|
||||||
/// cellActivated signal alias for backward compatibility; will be deprecated in future
|
/// cellActivated signal alias for backward compatibility; will be deprecated in future
|
||||||
alias onCellActivated = cellActivated;
|
alias onCellActivated = cellActivated;
|
||||||
|
|
||||||
|
/// Callback for handling of view scroll (top left visible cell change)
|
||||||
|
Listener!ViewScrolledHandler viewScrolled;
|
||||||
|
|
||||||
protected CustomGridCellAdapter _customCellAdapter;
|
protected CustomGridCellAdapter _customCellAdapter;
|
||||||
|
|
||||||
/// Get adapter to override drawing of some particular cells
|
/// Get adapter to override drawing of some particular cells
|
||||||
|
@ -414,6 +422,10 @@ class GridWidgetBase : ScrollWidgetBase {
|
||||||
return _colWidths[x];
|
return _colWidths[x];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setColWidth(int x, int w) {
|
||||||
|
_colWidths[x] = w;
|
||||||
|
}
|
||||||
|
|
||||||
/// returns row height (index includes col/row headers, if any); returns 0 for riws hidden by scroll at the top
|
/// returns row height (index includes col/row headers, if any); returns 0 for riws hidden by scroll at the top
|
||||||
int rowHeight(int y) {
|
int rowHeight(int y) {
|
||||||
if (y >= _headerRows + _fixedRows && y < _headerRows + _fixedRows + _scrollRow)
|
if (y >= _headerRows + _fixedRows && y < _headerRows + _fixedRows + _scrollRow)
|
||||||
|
@ -421,6 +433,10 @@ class GridWidgetBase : ScrollWidgetBase {
|
||||||
return _rowHeights[y];
|
return _rowHeights[y];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setRowHeight(int y, int w) {
|
||||||
|
_rowHeights[y] = w;
|
||||||
|
}
|
||||||
|
|
||||||
/// returns cell rectangle relative to client area; row 0 is col headers row; col 0 is row headers column
|
/// returns cell rectangle relative to client area; row 0 is col headers row; col 0 is row headers column
|
||||||
Rect cellRect(int x, int y) {
|
Rect cellRect(int x, int y) {
|
||||||
Rect rc;
|
Rect rc;
|
||||||
|
@ -623,7 +639,9 @@ class GridWidgetBase : ScrollWidgetBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// move selection to specified cell
|
/// move selection to specified cell
|
||||||
bool selectCell(int col, int row, bool makeVisible = true) {
|
bool selectCell(int col, int row, bool makeVisible = true, GridWidgetBase source = null, bool needNotification = true) {
|
||||||
|
if (source is null)
|
||||||
|
source = this;
|
||||||
if (_col == col && _row == row)
|
if (_col == col && _row == row)
|
||||||
return false; // same position
|
return false; // same position
|
||||||
if (col < _headerCols || row < _headerRows || col >= _cols || row >= _rows)
|
if (col < _headerCols || row < _headerRows || col >= _cols || row >= _rows)
|
||||||
|
@ -634,8 +652,8 @@ class GridWidgetBase : ScrollWidgetBase {
|
||||||
calcScrollableAreaPos();
|
calcScrollableAreaPos();
|
||||||
if (makeVisible)
|
if (makeVisible)
|
||||||
makeCellVisible(_col, _row);
|
makeCellVisible(_col, _row);
|
||||||
if (onCellSelected.assigned)
|
if (needNotification && onCellSelected.assigned)
|
||||||
onCellSelected(this, _col - _headerCols, _row - _headerRows);
|
onCellSelected(source, _col - _headerCols, _row - _headerRows);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue