/***************************************************************************
                          SIMPLY POWERFUL TOOLKIT (SPTK)
                          CExcelView.cpp  -  description
                             -------------------
    begin                : August 19 2004
    copyright            : (C) 2004 by Alexey Parshin
    email                : alexeyp@tts-sf.com
 ***************************************************************************/

/***************************************************************************
   This library is free software; you can redistribute it and/or modify it 
   under the terms of the GNU Library General Public License as published by
   the Free Software Foundation; either version 2 of the License, or (at 
   your option) any later version.

   This library is distributed in the hope that it will be useful, but 
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
   General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; if not, write to the Free Software Foundation, 
   Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

   Please report all bugs and problems to "alexeyp@tts-sf.com"
 ***************************************************************************/

#include <sptk/excel/CExcelView.h>

CExcelSheetView::CExcelSheetView(int x,int y,int w,int h,const char *label) 
: Fl_Box(x,y,w,h,label) {
	m_excelSheet = 0L;	
}

int CExcelSheetView::handle(int event) {
	return Fl_Box::handle(event);
}

void CExcelSheetView::draw() {
	Fl_Box::draw();
}

void CExcelSheetView::attach(CExcelSheet *sheet) {
	m_excelSheet = sheet;
	autoSize();
}

void CExcelSheetView::autoSize() {
	CExcelRows& rows = m_excelSheet->rows;
	unsigned cnt = rows.count();
	unsigned totalHeight = 20;
	if (cnt) {
		CExcelRow& row = rows[cnt-1];
		totalHeight = row.m_position + row.m_height;
	}
	unsigned totalWidth = 0;
	unsigned colCount = m_excelSheet->colCount();
	for (unsigned i = 0; i < colCount; i++) {
		totalWidth += m_excelSheet->colWidth(i);
	}
	if (totalWidth < 20) totalWidth = 20;
	size(totalWidth,totalHeight);
}
