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
This commit is contained in:
unodgs 2010-07-18 22:00:06 +00:00
parent 92ae6d7d67
commit 658e53da02
2 changed files with 39 additions and 3 deletions

View file

@ -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<Value> GridCtrl::ReadRow(int n) const
Vector<Value> GridCtrl::ReadCol(int n, int start_row, int end_row) const
{
Vector<Value> 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<Value> GridCtrl::ReadRow(int n, int start_col, int end_col) const
{
Vector<Value> 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;

View file

@ -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<Value> ReadRow(int n = -1) const;
Vector<Value> ReadCol(int n = -1, int start_row = -1, int end_row = -1) const;
Vector<Value> ReadRow(int n = -1, int start_col = -1, int end_col = -1) const;
GridCtrl& Add(const Vector<Value> &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);