added wxGrid::{Set,Get}{Row,Col}Sizes() methods allowing to save/restore all grid rows/columns sizes at once

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59144 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2009-02-25 23:41:29 +00:00
parent 0330301cb3
commit 574e1c5a03
5 changed files with 1021 additions and 826 deletions

View File

@ -481,6 +481,7 @@ All (GUI):
a selective wxEventLoopBase::YieldFor() function.
Added also wxEventLoopBase::IsYielding to help cure re-entrancy problems with Yield().
- Render <th> element contents in bold in wxHTML.
- Added wxGrid::{Set,Get}{Row,Col}Sizes() methods (Andrey Putrin).
wxGTK:

View File

@ -761,6 +761,39 @@ private:
// Grid view classes
// ============================================================================
// ----------------------------------------------------------------------------
// wxGridSizesInfo stores information about sizes of the rows or columns.
//
// It assumes that most of the columns or rows have default size and so stores
// the default size separately and uses a hash to map column or row numbers to
// their non default size for those which don't have the default size.
// ----------------------------------------------------------------------------
// Hashmap to store postions as the keys and sizes as the values
WX_DECLARE_HASH_MAP_WITH_DECL( unsigned, int, wxIntegerHash, wxIntegerEqual,
wxUnsignedToIntHashMap, class WXDLLIMPEXP_ADV );
struct WXDLLIMPEXP_ADV wxGridSizesInfo
{
// default ctor, initialize m_sizeDefault and m_customSizes later
wxGridSizesInfo() { }
// ctor used by wxGrid::Get{Col,Row}Sizes()
wxGridSizesInfo(int defSize, const wxArrayInt& allSizes);
// default copy ctor, assignment operator and dtor are ok
// Get the size of the element with the given index
int GetSize(unsigned pos) const;
// default size
int m_sizeDefault;
// position -> size map containing all elements with non-default size
wxUnsignedToIntHashMap m_customSizes;
};
// ----------------------------------------------------------------------------
// wxGrid
// ----------------------------------------------------------------------------
@ -1170,6 +1203,17 @@ public:
void HideCol(int col) { SetColSize(col, 0); }
void ShowCol(int col) { SetColSize(col, -1); }
// the row and column sizes can be also set all at once using
// wxGridSizesInfo which holds all of them at once
wxGridSizesInfo GetColSizes() const
{ return wxGridSizesInfo(GetDefaultColSize(), m_colWidths); }
wxGridSizesInfo GetRowSizes() const
{ return wxGridSizesInfo(GetDefaultRowSize(), m_rowHeights); }
void SetColSizes(const wxGridSizesInfo& sizeInfo);
void SetRowSizes(const wxGridSizesInfo& sizeInfo);
// ------- columns (only, for now) reordering
@ -2037,6 +2081,10 @@ private:
bool DoAppendLines(bool (wxGridTableBase::*funcAppend)(size_t),
int num, bool updateLabels);
// Common part of Set{Col,Row}Sizes
void DoSetSizes(const wxGridSizesInfo& sizeInfo,
const wxGridOperations& oper);
DECLARE_DYNAMIC_CLASS( wxGrid )
DECLARE_EVENT_TABLE()
wxDECLARE_NO_COPY_CLASS(wxGrid);

File diff suppressed because it is too large Load Diff

View File

@ -1028,6 +1028,68 @@ public:
virtual bool CanHaveAttributes();
};
/**
@class wxGridSizesInfo
wxGridSizesInfo stores information about sizes of all wxGrid rows or
columns.
It assumes that most of the rows or columns (which are both called elements
here as the difference between them doesn't matter at this class level)
have the default size and so stores it separately. And it uses a wxHashMap
to store the sizes of all elements which have the non-default size.
This structure is particularly useful for serializing the sizes of all
wxGrid elements at once.
@library{wxadv}
@category{grid}
*/
struct wxGridSizesInfo
{
/**
Default constructor.
m_sizeDefault and m_customSizes must be initialized later.
*/
wxGridSizesInfo();
/**
Constructor.
This constructor is used by wxGrid::GetRowSizes() and GetColSizes()
methods. User code will usually use the default constructor instead.
@param defSize
The default element size.
@param
Array containing the sizes of @em all elements, including those
which have the default size.
*/
wxGridSizesInfo(int defSize, const wxArrayInt& allSizes);
/**
Get the element size.
@param pos
The index of the element.
@return
The size for this element, using m_customSizes if @a pos is in it
or m_sizeDefault otherwise.
*/
int GetSize(unsigned pos) const;
/// Default size
int m_sizeDefault;
/**
Map with element indices as keys and their sizes as values.
This map only contains the elements with non-default size.
*/
wxUnsignedToIntHashMap m_customSizes;
};
/**
@ -2213,6 +2275,41 @@ public:
*/
void ShowRow(int col);
/**
Get size information for all columns at once.
This method is useful when the information about all column widths
needs to be saved. The widths can be later restored using
SetColSizes().
@sa wxGridSizesInfo, GetRowSizes()
*/
wxGridSizesInfo GetColSizes() const;
/**
Get size information for all row at once.
@sa wxGridSizesInfo, GetColSizes()
*/
wxGridSizesInfo GetRowSizes() const;
/**
Restore all columns sizes.
This is usually called with wxGridSizesInfo object previously returned
by GetColSizes().
@sa SetRowSizes()
*/
void SetColSizes(const wxGridSizesInfo& sizeInfo);
/**
Restore all rows sizes.
@sa SetColSizes()
*/
void SetRowSizes(const wxGridSizesInfo& sizeInfo);
//@}

View File

@ -8336,6 +8336,48 @@ wxRect wxGrid::BlockToDeviceRect( const wxGridCellCoords& topLeft,
return resultRect;
}
void wxGrid::DoSetSizes(const wxGridSizesInfo& sizeInfo,
const wxGridOperations& oper)
{
BeginBatch();
oper.SetDefaultLineSize(this, sizeInfo.m_sizeDefault, true);
const int numLines = oper.GetNumberOfLines(this);
for ( int i = 0; i < numLines; i++ )
{
int size = sizeInfo.GetSize(i);
if ( size != sizeInfo.m_sizeDefault)
oper.SetLineSize(this, i, size);
}
EndBatch();
}
void wxGrid::SetColSizes(const wxGridSizesInfo& sizeInfo)
{
DoSetSizes(sizeInfo, wxGridColumnOperations());
}
void wxGrid::SetRowSizes(const wxGridSizesInfo& sizeInfo)
{
DoSetSizes(sizeInfo, wxGridRowOperations());
}
wxGridSizesInfo::wxGridSizesInfo(int defSize, const wxArrayInt& allSizes)
{
m_sizeDefault = defSize;
for ( size_t i = 0; i < allSizes.size(); i++ )
{
if ( allSizes[i] != defSize )
m_customSizes[i] = allSizes[i];
}
}
int wxGridSizesInfo::GetSize(unsigned pos) const
{
wxUnsignedToIntHashMap::const_iterator it = m_customSizes.find(pos);
return it == m_customSizes.end() ? m_sizeDefault : it->second;
}
// ----------------------------------------------------------------------------
// drop target
// ----------------------------------------------------------------------------