// MyCell - version 1.0
// Written by Yanxueming <yanxm2003@hotmail.com>
// Copyright (C) 2006-2006
// All rights reserved.
//
// The code and information is provided "as-is" without
// warranty of any kind, either expressed or implied.
#pragma once
#include "StyleDesc.h"
namespace mycell{
template<class T>
class CellTypeMgr
{
public:
CellTypeMgr()
{}
ECellType get_CellType(int row,int col,StyleDesc const& styleDesc)const
{
T const* pT=static_cast<T const*>(this);
//StyleDesc styleDesc;
//if(pT->GetCellStyle(row,col,styleDesc)){
// if(cellTypeNone!=styleDesc.cellType)
// return styleDesc.cellType;
//}
//map<int,map<int,ECellType> >::const_iterator i1=cellType_.find(row);
//if(i1!=cellType_.end()){
// map<int,ECellType>::const_iterator i2=i1->second.find(col);
// if(i2!=i1->second.end())
// return i2->second;
//}
if(cellTypeNone==styleDesc.cellType){
ColHeader const& ch=pT->get_ColHeader();
return ch.get_ColType(col);
}else
return styleDesc.cellType;
}
void put_CellType(int row,int col,ECellType cellType)
{
T* pT=static_cast<T*>(this);
_ASSERT(cellType<ECT_MAX);
ColHeader& ch=pT->get_ColHeader();
if(ch.get_ColType(col)!=cellType){
StyleDesc styleDesc;
pT->GetCellStyle(row,col,styleDesc);
styleDesc.cellType=cellType;
pT->SetCellStyle(row,col,styleDesc);
}
}
//protected:
// void OnRowDelete(int beg,int end);
// void OnColDelete(int beg,int end);
// void OnColInsertFront(int col,int nCount);
// void OnRowInsertFront(int row,int nCount);
//private:
// map<int,map<int,ECellType> > cellType_;
};
/*
//---------------------------impl---------------------------
template<class T>
void CellTypeMgr<T>::OnRowInsertFront(int row,int nCount)
{
typedef map<int,ECellType> second_t;
vector<pair<int,second_t> > vec;
for(map<int,second_t>::iterator it=cellType_.begin();it!=cellType_.end();)
{
if(it->first>=row){
vec.push_back(make_pair(it->first+nCount,it->second));
it=cellType_.erase(it);
continue;
}
++it;
}
for(vector<pair<int,second_t> >::const_iterator _i=vec.begin();_i!=vec.end();++_i)
{
cellType_.insert(*_i);
}
}
template<class T>
void CellTypeMgr<T>::OnColInsertFront(int col,int nCount)
{
typedef map<int,ECellType> second_t;
vector<pair<int,ECellType> > vec;
for(map<int,map<int,ECellType> >::iterator it=cellType_.begin();it!=cellType_.end();++it)
{
for(second_t::iterator i=it->second.begin();i!=it->second.end();)
{
int const _col=i->first;
if(_col>=col){
vec.push_back(make_pair(_col+nCount,i->second));
i=it->second.erase(i);
continue;
}
++i;
}
for(vector<pair<int,ECellType> >::const_iterator _i=vec.begin();_i!=vec.end();++_i)
{
it->second.insert(*_i);
}
vec.clear();
}
}
template<class T>
void CellTypeMgr<T>::OnRowDelete(int beg,int end)
{
_ASSERT(end>=beg);
int const cnt=end-beg+1;
vector<pair<int,map<int,ECellType> > > vec;
for(map<int,map<int,ECellType> >::iterator it=cellType_.begin();it!=cellType_.end();)
{
if(it->first>=beg && it->first<=end){
cellType_.erase(it);
it=cellType_.begin();
continue;
}else if(it->first>end){
vec.push_back(make_pair(it->first-cnt,it->second));
cellType_.erase(it);
it=cellType_.begin();
continue;
}
++it;
}
for(vector<pair<int,map<int,ECellType> > >::const_iterator it=vec.begin();it!=vec.end();++it)
{
cellType_.insert(*it);
}
}
template<class T>
void CellTypeMgr<T>::OnColDelete(int beg,int end)
{
_ASSERT(end>=beg);
int const cnt=end-beg+1;
vector<pair<int,ECellType> > vec;
for(map<int,map<int,ECellType> >::iterator it=cellType_.begin();it!=cellType_.end();++it)
{
for(map<int,ECellType>::iterator i=it->second.begin();i!=it->second.end();)
{
if(i->first>=beg && i->first<=end){
i=it->second.erase(i);
continue;
}else if(i->first>end){
vec.push_back(make_pair(i->first-cnt,i->second));
i=it->second.erase(i);
continue;
}
++i;
}
for(vector<pair<int,ECellType> >::const_iterator _i=vec.begin();_i!=vec.end();++_i)
{
it->second.insert(*_i);
}
vec.clear();
}
}
*/
}//namespace mycell