#ifndef __WListCore__H
#define __WListCore__H

#include "WimpLib:std.h"
#include <stdbool.h>
#include "WimpLib:Coords.h"
#include "WimpLib:Event.h"
#include "WimpLib:Array.h"
#include "WimpLib:Window.h"
#include "WimpLib:WItem.h"
#include "WimpLib:WSelector.h"

#ifdef __cplusplus
extern "C" {
#endif

#define EWList_SelModeMulti     0x00000001
#define EWList_SelModeSingle    0x00000002
#define EWList_SelModePopup     0x00000003
#define EWList_SelModeMask      0x0000000f
#define EWList_MultiColumn      0x00000010
#define EWList_GrowHorz         0x00000020
#define EWList_RightToLeft      0x00000040
#define EWList_BottomToTop      0x00000080
#define EWList_Transparent      0x00000100
#define EWList_FitVisibleArea   0x00000200
#define EWList_FilerExtent      0x00000400
#define EWList_HoverSensitive   0x00000800
#define EWList_ShowMarks        0x00001000
#define EWList_MultiMark        0x00002000
#define EWList_FlagsMask        0x00003fff

#define EWListCore_Init         0x00000001
#define EWListCore_HasFocus     0x00000002
#define EWListCore_DragMouse    0x00000004
#define EWListCore_DragKey      0x00000008
#define EWListCore_DragAdjust   0x00000010
#define EWListCore_ShrinkSize   0x00000020
#define EWListCore_MoveOnlyMode 0x00000040
#define EWListCore_OpenAsMenu   0x00000080

typedef struct
{
	WItem_VTable           item;
	FWOwner_PlotBackGround FPlotBackGround;
} WListCore_FWList;

struct WListCore
{
	HWind              m_wnd;
	HWind              m_parentwnd;
	Array*             m_pList;
	void*              m_pHandle;
	WListCore_FWList*  m_pFWList;
	WSelector*         m_pSelector;

	HWind              m_OwnerWnd;
	CRect              m_RectToFit;

	int                m_NrSizes;
	int*               m_pItemMaxs;
	int*               m_pItemSizes;
	CSize              m_Size;
	CSize              m_MinSize;
	CSize              m_RowCols;
	CSize              m_Offset;

	unsigned int       m_flags;
	unsigned int       m_coreflags;
	int                m_FocusPos;
	int                m_HoverPos;

	struct
	{
		bool    m_bShowHourglass;
		int     m_DisableCount;
		int     m_Min;
		int     m_OldMax;
		CSize   m_OldSize;
	} m_refresh;

	CPoint             m_GhostCaret;
};

void throw_WListCore_WListCore( WListCore*
		, unsigned int flags
		, CTemplate* t
		, void* pHandle
		, int NrSizes
		, WListCore_FWList* pFWList
		);
void WListCore_NotWListCore(WListCore*);

int   WListCore_Count(const WListCore*);
void  throw_WListCore_Insert(WListCore*, int index, void* pobj);
void* WListCore_Get(const WListCore*, int index);
void  WListCore_Set(WListCore*, int index, void* pobj);
int   WListCore_Find(const WListCore*, int start, const void* pobj);
bool  WListCore_Del(WListCore*, int index);
bool  WListCore_DelRange(WListCore*, int start, int end /* Exclusive */);
void  WListCore_Clear(WListCore*);

HWind WListCore_GetWindow(const WListCore*);
void  WListCore_SubMenu(WListCore*);
void  WListCore_Popup(WListCore*, HWind w, HIcon i);
void  WListCore_SetExtent(WListCore*);
void  WListCore_SetOffset(WListCore*, CSize s);

CRect WListCore_RowColsToPixels(const WListCore*, const CRect* pbox);
CRect WListCore_PixelsToRowCols(const WListCore*, const CRect* pbox);
CRect WListCore_ItemRect(const WListCore*, int index);
CPoint WListCore_IndexToRowCol(const WListCore*, int index);
int WListCore_RowColToIndex(const WListCore*, CPoint pos);

void WListCore_ForceRedraw(const WListCore*, int min, int max);
void WListCore_AllowRefresh(WListCore*, bool bAllow);
bool WListCore_IsRefreshAllowed(const WListCore*);
void WListCore_Refresh(WListCore*, int min, int max);
void WListCore_RecalcSize(WListCore*);
void WListCore_ShowItem(WListCore*, int index);

int  WListCore_GetFocus(const WListCore*);
void WListCore_SetFocus(WListCore*, int focus, bool show);
bool WListCore_MoveFocus(WListCore*, int focus);

void WListCore_PlotGhostCaret(WListCore*, bool bShow);
void WListCore_ShowGhostCaret(WListCore*, const CPoint* ppt);
void WListCore_HideGhostCaret(WListCore*);
int  WListCore_GetGhostCaretIndex(const WListCore*);

unsigned int WListCore_GetFlags(const WListCore*);
void WListCore_SetFlags(WListCore*, unsigned int flags);
void WListCore_SetParent(WListCore*, HWind parentwnd);
void throw_WListCore_SetPane(WListCore*, HWind parentwnd, const CRect* box);

unsigned int WListCore_GetItemState(const WListCore*, int index);
bool WListCore_SetItemState(WListCore*, int index, unsigned int val, unsigned int mask);
bool WListCore_InvertItemState(WListCore*, int index, unsigned int mask);
bool WListCore_SetItemsState(WListCore*, unsigned int val, unsigned int mask, unsigned int selval, unsigned int selmask);
bool WListCore_InvertItemsState(WListCore*, unsigned int mask, unsigned int selval, unsigned int selmask);
int  WListCore_FindItemState(const WListCore*, int start, unsigned int val, unsigned int mask);

void WListCore_NotifySelChange(WListCore*, int item);
void WListCore_StartSelection(WListCore*, unsigned int mode, WSelector* pSel);
void WListCore_EndSelection(WListCore*, bool bSuccess);

void WListCore_BoxActivation(WListCore*, const CRect* obox, const CRect* nbox);

#define EWListPtrMode_Hover   0x00
#define EWListPtrMode_Insert  0x01
#define EWListPtrMode_InRange 0x02

int WListCore_ItemFromScreenPt(const WListCore*, const CPoint* ppt, unsigned int flags);
int WListCore_ItemAreaFromScreenPt(const WListCore*, const Mouse* pMouse, unsigned int flags, WItemArea* pArea);
void WListCore_ItemArea(const WListCore*, int item, WItemArea* pArea);

const int* WListCore_ItemGetSizes(const WListCore*, int item);
const int* WListCore_GetSizes(const WListCore*);

EListenerAction WListCore_EventHandler(void* handle, const Event* pevent);
EListenerAction WListCore_ListEventHandler(void* handle, const Event* pevent);

#ifdef __cplusplus
}
#endif

#endif
