/*
 * Copyright (c) 2002 Robert Collins.
 * Copyright (c) 2005-2006 Tom N Harris.
 *
 *     This program is free software; you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation; either version 2 of the License, or
 *     (at your option) any later version.
 *
 *     A copy of the GNU General Public License can be found at
 *     http://www.gnu.org/
 *
 * Written by Robert Collins <robertc@hotmail.com>
 * Written by Tom N Harris <telliamed@whoopdedo.org>
 *
 */

#ifndef SETUP_PICKVIEW_H
#define SETUP_PICKVIEW_H

#include <vector>

#include "win32.h"
#include "cString.h"
#include "Window.h"
#include "PickLine.h"

#define HMARGIN        10
#define ROW_MARGIN      5
#define ICON_MARGIN     4
#define RTARROW_WIDTH  11
#define SPIN_WIDTH     11
#define CHECK_SIZE     11
#define CATEGORY_INDENT 11

#define CATEGORY_EXPANDED  0
#define CATEGORY_COLLAPSED 1

#define VIEW_BITMAPCHECKYES 0
#define VIEW_BITMAPCHECKNO  1
#define VIEW_BITMAPCHECKNA  2
#define VIEW_NUMBITMAPS     3

#define VIEW_SELCHANGED 1

namespace Setup
{

class PickItemLine;
class PickCategoryLine;

class PickView : public Window
{
	static ATOM WindowClassAtom;
	virtual bool registerWindowClass();

public:
	PickView();
	virtual ~PickView();

	virtual LRESULT windowProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
	virtual bool create(Window * Parent = NULL, 
				        DWORD Style = WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN, 
				        RECT * r = NULL, LPCTSTR CtlId = NULL);
	virtual void init();

	void insertItem(String const & cat, const char* key, ...);
	void insertCategory(String const & name);
	void clearList(void);
	void refreshList();
	int clickRow(int row, int x);
	int getNumRows();
	PickLine * getRow(int row);

	int getNumColumns() const
		{ return m_headers.size(); }
	void insertColumn(String const &);
	void insertColumn(String const &, int);

protected:

	friend class PickItemLine;
	friend class PickCategoryLine;
	friend void PickLine::DrawCheck(PickView&, HDC, HRGN, int, int, CheckState);

	PickCategoryLine* m_contents;

	class Header
	{
	public:
		String text;
		int width;
		int x;
	};

	std::vector<Header> m_headers;
	int m_headerheight;
	int m_rowheight;

private:
	// Stuff needed to handle resizing
	bool m_hasClientRect;
	RECTWrapper m_lastClientRect;
  
	TEXTMETRIC m_textmetrics;
	HANDLE m_sysFont;
	HDC m_bitmapDC;
	HANDLE m_bitmaps[VIEW_NUMBITMAPS];

	int m_scrollX, m_scrollY;

	HWND m_listheader;

protected:
	void paint();
	void scroll(int which, int *var, int code);
	void click(int x, int y);

	void setScroll(int which);

	void setHeaders();
	void initHeaders(HDC dc);
	void noteWidth(String const &string, int addend, int column);

	HDC GetBitmapDC(int bitmap);

	HWND getListHeader(void)
		{ return m_listheader; }
};

};

#endif /* SETUP_PICKVIEW_H */
