Added wxRichTextTableBlock class to help with table UI operations

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74872 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2013-09-29 13:35:58 +00:00
parent 787de84048
commit af4168e2cf
3 changed files with 182 additions and 0 deletions

View File

@@ -5797,6 +5797,55 @@ protected:
wxRichTextObjectPtrArrayArray m_cells;
};
/** @class wxRichTextTableBlock
Stores the coordinates for a block of cells.
*/
class WXDLLIMPEXP_RICHTEXT wxRichTextTableBlock
{
public:
wxRichTextTableBlock() { Init(); }
wxRichTextTableBlock(int colStart, int colEnd, int rowStart, int rowEnd)
{ Init(); m_colStart = colStart; m_colEnd = colEnd; m_rowStart = rowStart; m_rowEnd = rowEnd; }
wxRichTextTableBlock(const wxRichTextTableBlock& block) { Copy(block); }
void Init() { m_colStart = 0; m_colEnd = 0; m_rowStart = 0; m_rowEnd = 0; }
void Copy(const wxRichTextTableBlock& block)
{
m_colStart = block.m_colStart; m_colEnd = block.m_colEnd; m_rowStart = block.m_rowStart; m_rowEnd = block.m_rowEnd;
}
void operator=(const wxRichTextTableBlock& block) { Copy(block); }
bool operator==(const wxRichTextTableBlock& block)
{ return m_colStart == block.m_colStart && m_colEnd == block.m_colEnd && m_rowStart == block.m_rowStart && m_rowEnd == block.m_rowEnd; }
/// Computes the block given a table (perhaps about to be edited) and a rich text control
/// that may have a selection. If no selection, the whole table is used. If just the whole content
/// of one cell is selected, this cell only is used. If the cell contents is not selected and
/// requireCellSelection is @false, the focused cell will count as a selected cell.
bool ComputeBlockForSelection(wxRichTextTable* table, wxRichTextCtrl* ctrl, bool requireCellSelection = true);
/// Does this block represent the whole table?
bool IsWholeTable(wxRichTextTable* table) const;
/// Returns the cell focused in the table, if any
static wxRichTextCell* GetFocusedCell(wxRichTextCtrl* ctrl);
int& ColStart() { return m_colStart; }
int ColStart() const { return m_colStart; }
int& ColEnd() { return m_colEnd; }
int ColEnd() const { return m_colEnd; }
int& RowStart() { return m_rowStart; }
int RowStart() const { return m_rowStart; }
int& RowEnd() { return m_rowEnd; }
int RowEnd() const { return m_rowEnd; }
int m_colStart, m_colEnd, m_rowStart, m_rowEnd;
};
/**
The command identifiers for Do/Undo.

View File

@@ -5654,6 +5654,55 @@ protected:
wxRichTextObjectPtrArrayArray m_cells;
};
/** @class wxRichTextTableBlock
Stores the coordinates for a block of cells.
*/
class wxRichTextTableBlock
{
public:
wxRichTextTableBlock() { Init(); }
wxRichTextTableBlock(int colStart, int colEnd, int rowStart, int rowEnd)
{ Init(); m_colStart = colStart; m_colEnd = colEnd; m_rowStart = rowStart; m_rowEnd = rowEnd; }
wxRichTextTableBlock(const wxRichTextTableBlock& block) { Copy(block); }
void Init() { m_colStart = 0; m_colEnd = 0; m_rowStart = 0; m_rowEnd = 0; }
void Copy(const wxRichTextTableBlock& block)
{
m_colStart = block.m_colStart; m_colEnd = block.m_colEnd; m_rowStart = block.m_rowStart; m_rowEnd = block.m_rowEnd;
}
void operator=(const wxRichTextTableBlock& block) { Copy(block); }
bool operator==(const wxRichTextTableBlock& block)
{ return m_colStart == block.m_colStart && m_colEnd == block.m_colEnd && m_rowStart == block.m_rowStart && m_rowEnd == block.m_rowEnd; }
/// Computes the block given a table (perhaps about to be edited) and a rich text control
/// that may have a selection. If no selection, the whole table is used. If just the whole content
/// of one cell is selected, this cell only is used. If the cell contents is not selected and
/// requireCellSelection is @false, the focused cell will count as a selected cell.
bool ComputeBlockForSelection(wxRichTextTable* table, wxRichTextCtrl* ctrl, bool requireCellSelection = true);
/// Does this block represent the whole table?
bool IsWholeTable(wxRichTextTable* table) const;
/// Returns the cell focused in the table, if any
static wxRichTextCell* GetFocusedCell(wxRichTextCtrl* ctrl);
int& ColStart() { return m_colStart; }
int ColStart() const { return m_colStart; }
int& ColEnd() { return m_colEnd; }
int ColEnd() const { return m_colEnd; }
int& RowStart() { return m_rowStart; }
int RowStart() const { return m_rowStart; }
int& RowEnd() { return m_rowEnd; }
int RowEnd() const { return m_rowEnd; }
int m_colStart, m_colEnd, m_rowStart, m_rowEnd;
};
/**
The command identifiers for Do/Undo.

View File

@@ -10762,6 +10762,90 @@ bool wxRichTextTable::EditProperties(wxWindow* parent, wxRichTextBuffer* buffer)
return false;
}
bool wxRichTextTableBlock::ComputeBlockForSelection(wxRichTextTable* table, wxRichTextCtrl* ctrl, bool requireCellSelection)
{
if (!ctrl)
return false;
ColStart() = 0;
ColEnd() = table->GetColumnCount()-1;
RowStart() = 0;
RowEnd() = table->GetRowCount()-1;
wxRichTextSelection selection = ctrl->GetSelection();
if (selection.IsValid() && selection.GetContainer() == table)
{
// Start with an invalid block and increase.
wxRichTextTableBlock selBlock(-1, -1, -1, -1);
wxRichTextRangeArray ranges = selection.GetRanges();
int row, col;
for (row = 0; row < table->GetRowCount(); row++)
{
for (col = 0; col < table->GetColumnCount(); col++)
{
if (selection.WithinSelection(table->GetCell(row, col)->GetRange().GetStart()))
{
if (selBlock.ColStart() == -1)
selBlock.ColStart() = col;
if (selBlock.ColEnd() == -1)
selBlock.ColEnd() = col;
if (col < selBlock.ColStart())
selBlock.ColStart() = col;
if (col > selBlock.ColEnd())
selBlock.ColEnd() = col;
if (selBlock.RowStart() == -1)
selBlock.RowStart() = row;
if (selBlock.RowEnd() == -1)
selBlock.RowEnd() = row;
if (row < selBlock.RowStart())
selBlock.RowStart() = row;
if (row > selBlock.RowEnd())
selBlock.RowEnd() = row;
}
}
}
if (selBlock.RowStart() != -1 && selBlock.RowEnd() != -1 && selBlock.ColStart() != -1 && selBlock.ColEnd() != -1)
(*this) = selBlock;
}
else
{
// See if a whole cell's contents is selected, in which case we can treat the cell as selected.
// wxRTC lacks the ability to select a single cell.
wxRichTextCell* cell = wxDynamicCast(ctrl->GetFocusObject(), wxRichTextCell);
if (cell && (!requireCellSelection || (ctrl->HasSelection() && ctrl->GetSelectionRange() == cell->GetOwnRange())))
{
int row, col;
if (table->GetCellRowColumnPosition(cell->GetRange().GetStart(), row, col))
{
RowStart() = row;
RowEnd() = row;
ColStart() = col;
ColEnd() = col;
}
}
}
return true;
}
// Does this block represent the whole table?
bool wxRichTextTableBlock::IsWholeTable(wxRichTextTable* table) const
{
return (ColStart() == 0 && RowStart() == 0 && ColEnd() == (table->GetColumnCount()-1) && RowEnd() == (table->GetRowCount()-1));
}
// Returns the cell focused in the table, if any
wxRichTextCell* wxRichTextTableBlock::GetFocusedCell(wxRichTextCtrl* ctrl)
{
if (!ctrl)
return NULL;
wxRichTextCell* cell = wxDynamicCast(ctrl->GetFocusObject(), wxRichTextCell);
return cell;
}
/*
* Module to initialise and clean up handlers
*/