// 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 "base.h"
#include "CellRange.h"
//#include "ASelection.h"
#include "msg.h"
#include "Selections.h"
namespace mycell{
class Worksheet;
class SelectionsHandler : public Selections
//public ActiveCell<SelectionsHandler>
{
typedef Selections baseClass;
//typedef ActiveCell<SelectionsHandler> baseActiveCell;
//Worksheet* pSheet_;
//Selections* pCurSelections_;
//CCellRange activeSelection_;
//vector<CCellRange> vecSel_;
//CCell activeCell_;
enum eAutoScroll
{
AS_UP =1<<0,
AS_LEFT =1<<1,
AS_DOWN =1<<2,
AS_RIGHT =1<<3,
};
//int autoScrollType_;
enum {ID_TIMER_SCROLL=WM_USER+100};
enum {TIME_INTERVAL=100};
public:
SelectionsHandler(Worksheet* p);
//BEGIN_MSG_MAP(SelectionsHandler)
// //MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
// MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
// MESSAGE_HANDLER(WM_KEYDOWN,OnKeyDown)
// MESSAGE_HANDLER(WM_RBUTTONDOWN, OnRButtonDown)
// //MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUP)
// //MESSAGE_HANDLER(WM_TIMER,OnTimer)
//END_MSG_MAP()
//BOOL get_ListMode()const
//{
// return FALSE;
//}
//void SetupRowHeaderDE(int row,DrawEnvironment& de,BOOL& bFullInselection);
//void SetupColHeaderDE(int col,DrawEnvironment& de,BOOL& bFullInselection);
//void SetupHeaderCornerDE(DrawEnvironment& de);
//void SetupCellDE(int row,int col,DrawEnvironment& de);
//bool InSelection(int row,int col)const;
MoveToConstants get_EnterKeyMoveTo()const
{
return cellNextRow;
}
void OnLButtonDown(const CELLHITTESTINFO& chi,WPARAM wParam);
void OnRButtonDown(const CELLHITTESTINFO& chi,WPARAM wParam);
LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
/*
void get_Range(vector<CCellRange>& vec)const
{
if(!IsMultiSelectionMode()){
CCellRange cr;
get_Range(cr.first.col,cr.first.row,cr.second.col,cr.second.row);
vec.push_back(cr);
}else{
#ifdef _DEBUG
size_t cnt=vecSel_.size();
for(size_t i=0;i<cnt;++i){
const CCellRange cr=vecSel_[i];
vec.push_back(cr);
}
#else
vec.insert(vec.begin(),vecSel_.begin(),vecSel_.end());
#endif
}
}
bool IsMultiSelectionMode()const
{
return false;//!vecSel_.empty();
}
*/
//BOOL CellInSelection(int row,int col)
//{
// return activeSelection_.Inside/*<false>*/(row,col);
//}
//CCell GetActiveCell()const
//{
// return baseActiveCell::GetActiveCell();
//}
////void GetActiveCell(int& row,int& col)const
////{
//// CCell cell=baseActiveCell::GetActiveCell();
//// //Cell
//// row=cell.row;
//// col=cell.col;
////}
//void SetActiveCell(int row,int col)
//{
// baseActiveCell::SetActiveCell(row,col);//activeCell_.set(row,col);
//}
//void SetActiveCell(CCell cell)
//{
// SetActiveCell(cell.row,cell.col);
//}
//void InvalidateWindow(CCell const& oldActiveCell,const Selections& oldSelections);//CCellRange const& oldActiveCellRange);
//BOOL IsSelectAll(CCellRange const& cr)const;
//BOOL IsSelectAll()const
//{
// return IsSelectAll(activeSelection_);
//}
//template<int iNULL>
//LRESULT SendMessageToListener(int nRow, int nCol, int nNotifyCode,LPARAM lParam) const
//{
// return pSheet_->SendNotifyMessageToListener(nRow,nCol,nNotifyCode,lParam);
//}
//CCellRange GetActiveSelection()const
//{
// if(IsMultiSelectionMode()){
// CCellRange cr;
// cr.SetNull();
// return cr;
// }
// return activeSelection_;
//}
void InvalidateContent(CCell const& oldActiveCell,const Selections& oldSelections,BOOL bUpdateWindow=FALSE)const;
//void OnMergeCells(int minR,int minC,int maxR,int maxC)
//{
// const Selections oss=this;
// baseClass::OnMergeCells(minR,minC,maxR,maxC);
// InvalidateContent(pSheet_->GetActiveCell(),oss);
//}
private:
//void get_Range(int& leftCol,int& topRow,int& rightCol,int& bottomRow) const
//{
// leftCol=activeSelection_.LeftCol();
// topRow=activeSelection_.TopRow();
// rightCol=activeSelection_.RightCol();
// bottomRow=activeSelection_.BottomRow();
// //MinMax<int>(activeSelection_.first.row,activeSelection_.second.row,topRow,bottomRow);
// //MinMax<int>(activeSelection_.first.col,activeSelection_.second.col,leftCol,rightCol);
//}
/*
void OnHeaderCornerClick()
{
//SelectAllCells();
}
//void SelectRow(int row);
//void SelectCol(int col);
void OnRowHeaderClick(int row)
{
if (get_ListMode()){
}else{
//SelectRow(row);
//BeginSelect(row,IGNOR_COL);
}
}
void OnColHeaderClick(int col)
{
//SelectCol(col);
//BeginSelect(IGNOR_ROW,col);
}
*/
//EMouseMode BeginSelect(int row,int col);
void Selecting(int row,int col);
//void InvalidateRect(LPCRECT lprc1,LPCRECT lprc2,BOOL bUnion=FALSE);
//void InvalidateHeader(CCell const& oldActiveCell,const Selections& oldSelections);//CCellRange const& oldActiveCellRange);
//void InvalidateColHeader(CCell const& oldActiveCell,const Selections& oldSelections);//,CCellRange const& oldActiveCellRange/*,BOOL bUnion*/);
//void InvalidateSelectionBorder(const Selections& ss,CCellRange& crClip);
//void InvalidateHeaderCorner(const Selections& oldSelections);//CCellRange const& oldActiveCellRange);
//void InvalidateActiveAdjoinEdges(const CCellRange& oldActiveSelection,const CCellRange& newActiveSelection)const;
//void InvalidateDirtyBorderOnFreezeLine(const CCellRange& oldActiveSelection,const CCellRange& newActiveSelection);
//���ѡ���������ʹ���border������Ч
void InvalidateActiveSelectionExpandBorder(const Selections& oss)const;
//void InvalidateDragBounds(const CCellRange& activeSelection);
//ȡScrollRowHeader������[firstRow,lastRow]�ཻ�ķ�Χ��������ཻ�ط�Χ{0,0,0,0}
//RECT GetScrollRowHeaderRect(int firstRow,int lastRow/*CCellRange const& cr*/)const;
//ȡFreezeRowHeader������[firstRow,lastRow]�ཻ�ķ�Χ��������ཻ�ط�Χ{0,0,0,0}
//RECT GetFreezeRowHeaderRect(int firstRow,int lastRow)const;
//ȡScrollColHeader������[firstCol,lastCol]�ཻ�ķ�Χ��������ཻ�ط�Χ{0,0,0,0}
//RECT GetScrollColHeaderRect(int firstCol,int lastCol/*CCellRange const& cr*/)const;
//ȡFreezeColHeader������[firstCol,lastCol]�ཻ�ķ�Χ��������ཻ�ط�Χ{0,0,0,0}
//RECT GetFreezeColHeaderRect(int firstCol,int lastCol)const;
//RECT GetRect(CCellRange const& cr);
//BOOL IsFullRowSelected(CCellRange const& cr);
//BOOL IsFullColSelected(CCellRange const& cr);
//
//void _DestroyInplaceWindow(){}
BOOL MoveLeft();
BOOL MoveRight();
BOOL MoveUp();
BOOL MoveDown();
void MoveNextPage();
void MovePriorPage();
void MoveHome();
void MoveLineHome();
void MoveEnd();
void MoveLineEnd();
void OnEditCopy();
public:
//void AddSelection(const CCellRange& newActiveSelection,bool bIsActiveSelection=true)
//{
// const CCellRange oldActiveSelection=GetActiveSelection();
// baseClass::AddSelection(newActiveSelection,bIsActiveSelection);
// InvalidateActiveAdjoinEdges(oldActiveSelection,newActiveSelection);
//}
////����newActiveSelection Ӧ���Ѿ������ཻ��
////�ϲ���Ԫ����н������˵ġ�
//void SetActiveSelection(const CCellRange& newActiveSelection);
private:
void SelectCells(CCell cell,const CCellRange& oldCR);
void TrackSingleCellSelection(CCell cell);
void TrackMultiCellSelection(CCell cell,BOOL bAppendSelection,EMouseMode mouseMode);
////�Ļѡ�������ԭʼѡ��
//template<class TGrid>
//void ChangeActiveSelection(TGrid* pSheet,const CCellRange& newActiveSelection)
//{
// const CCellRange oldActiveSelection=GetActiveSelection();
// baseClass::ChangeActiveSelection(newActiveSelection);
// //InvalidateActiveAdjoinEdges(oldActiveSelection,newActiveSelection);
//}
//template<class TGrid>
//CCellRange& AdjustSelection(TGrid* pSheet,/*[in,out]*/CCellRange& cr)const
//{
// return pSheet->AdjustSelection(cr);
//}
//int GetPreRow(int row);
//int GetNextRow(int row);
//int GetPreCol(int col);
//int GetNextCol(int col);
//void ExpandDirtyActiveSelection(CCellRange cr);`
private:
//LRESULT OnMouseMove(UINT nFlags,WPARAM,LPARAM lParam,BOOL&);
//LRESULT OnLButtonDown(UINT,WPARAM,LPARAM,BOOL&);
//LRESULT OnLButtonUP(UINT,WPARAM,LPARAM,BOOL&);
//LRESULT OnRButtonDown(UINT,WPARAM,LPARAM lParam,BOOL&);
//LRESULT OnLButtonUP(UINT,WPARAM,LPARAM lParam,BOOL& bHandled);
//LRESULT OnTimer(UINT,WPARAM,LPARAM lParam,BOOL&);
};
}//namespace mycell