From 658e53da022cca5bd2bc1467f59cb8944e12e35b Mon Sep 17 00:00:00 2001 From: unodgs Date: Sun, 18 Jul 2010 22:00:06 +0000 Subject: [PATCH] GridCtrl: Added FindCol by string, ReadCol, CopyColumnNames, some additions to ReadRow git-svn-id: svn://ultimatepp.org/upp/trunk@2544 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/GridCtrl/GridCtrl.cpp | 36 ++++++++++++++++++++++++++++++++++-- uppsrc/GridCtrl/GridCtrl.h | 6 +++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/uppsrc/GridCtrl/GridCtrl.cpp b/uppsrc/GridCtrl/GridCtrl.cpp index 5100bc701..f67862928 100644 --- a/uppsrc/GridCtrl/GridCtrl.cpp +++ b/uppsrc/GridCtrl/GridCtrl.cpp @@ -129,6 +129,7 @@ GridCtrl::GridCtrl() : holder(*this) clipboard = false; extra_paste = true; fixed_paste = false; + copy_column_names = false; draw_focus = false; cancel_all = false; ask_remove = false; @@ -662,6 +663,16 @@ void GridCtrl::SetClipboard(bool all, bool silent) for(int i = fixed_rows; i < total_rows; i++) { bool row_selected = select_row && IsSelected(i, false); + + if(i == fixed_rows && copy_column_names) + { + for(int j = fixed_cols; j < total_cols; j++) + if(all || IsSelected(i, j, false)) + tc += hitems[j].GetName() + '\t'; + + tc += "\r\n"; + } + for(int j = fixed_cols; j < total_cols; j++) if(all || row_selected || IsSelected(i, j, false)) { @@ -2849,11 +2860,24 @@ bool GridCtrl::IsModified(Id id) return items[vitems[rowidx].id][aliases.Get(id)].modified; } -Vector GridCtrl::ReadRow(int n) const +Vector GridCtrl::ReadCol(int n, int start_row, int end_row) const +{ + Vector v; + int idx = hitems[n < 0 ? colidx : n].id; + if(start_row < 0) start_row = fixed_rows; + if(end_row < 0) end_row = total_rows - 1; + for(int i = start_row; i <= end_row; i++) + v.Add(items[i][idx].val); + return v; +} + +Vector GridCtrl::ReadRow(int n, int start_col, int end_col) const { Vector v; int idy = vitems[n < 0 ? rowidx : n].id; - for(int i = fixed_cols; i < total_cols; i++) + if(start_col < 0) start_col = fixed_cols; + if(end_col < 0) end_col = total_cols - 1; + for(int i = start_col; i <= end_col; i++) v.Add(items[idy][i].val); return v; } @@ -5754,6 +5778,14 @@ int GridCtrl::FindCol(int id) const return -1; } +int GridCtrl::FindCol(const String& s) const +{ + for(int i = fixed_cols; i < total_cols; i++) + if(hitems[i].GetName() == s) + return i - fixed_cols; + return -1; +} + int GridCtrl::FindRow(int id) const { id += fixed_rows; diff --git a/uppsrc/GridCtrl/GridCtrl.h b/uppsrc/GridCtrl/GridCtrl.h index f963e45c7..9329534a3 100644 --- a/uppsrc/GridCtrl/GridCtrl.h +++ b/uppsrc/GridCtrl/GridCtrl.h @@ -839,6 +839,7 @@ class GridCtrl : public Ctrl bool clipboard:1; bool extra_paste:1; bool fixed_paste:1; + bool copy_column_names:1; bool draw_focus:1; bool cancel_all:1; bool ask_remove:1; @@ -1091,6 +1092,7 @@ class GridCtrl : public Ctrl GridCtrl& Clipboard(bool b = true) { clipboard = b; return *this; } GridCtrl& ExtraPaste(bool b = true) { extra_paste = b; return *this; } GridCtrl& FixedPaste(bool b = true) { fixed_paste = b; return *this; } + GridCtrl& CopyColumnNames(bool b = true) { copy_column_names = b; return *this; } GridCtrl& AskRemove(bool b = true) { ask_remove = b; return *this; } GridCtrl& RowChanging(bool b = true) { row_changing = b; return *this; } @@ -1277,7 +1279,8 @@ class GridCtrl : public Ctrl bool IsVersionedRow() { return vitems[rowidx].operation.GetVersion() > 0; } int GetRowOperation() { return vitems[rowidx].operation; } - Vector ReadRow(int n = -1) const; + Vector ReadCol(int n = -1, int start_row = -1, int end_row = -1) const; + Vector ReadRow(int n = -1, int start_col = -1, int end_col = -1) const; GridCtrl& Add(const Vector &v, int offset = 0, int count = -1, bool hidden = false); void SetFixedRows(int n = 1); @@ -1383,6 +1386,7 @@ class GridCtrl : public Ctrl int GetColUId() const; int GetRowUId() const; int FindCol(int id) const; + int FindCol(const String& s) const; int FindRow(int id) const; int GetNextRow(int n);