
/*	Copyright (C) G. Jespersen
	See Licence.txt.*/

// TopicListBox.cpp : implementation file
//

#include "stdafx.h"
#include "dslavsplit.h"
#include "TopicListBox.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTopicListBox

CTopicListBox::CTopicListBox()
{
	m_bDragging = FALSE;
}

CTopicListBox::~CTopicListBox()
{
}


BEGIN_MESSAGE_MAP(CTopicListBox, CDragListBox)
	//{{AFX_MSG_MAP(CTopicListBox)
	ON_WM_KEYDOWN()
	//}}AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTopicListBox message handlers

// Delete key.
void CTopicListBox::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	if(nChar == VK_DELETE)
	{
		int nItems = GetCount();
		int sel = GetCurSel();
		if(sel >= 0 && sel < nItems)
		{
			DeleteString(sel);

			// Owner resets list with indents and cur sel.
			nItems = GetCount();
			int newSel = sel - 1;
			if(newSel < 0)
				newSel = 0;
			else if(newSel >= nItems)
				newSel = nItems - 1;
			GetParent()->PostMessage(WM_USER_TOPIC_LIST_CHANGE, (WPARAM)newSel, (LPARAM)0);
		}
	}
	CListBox::OnKeyDown(nChar, nRepCnt, nFlags);
}

// User dragged an item to a new location - notify parent Dlg.
// Note this is called for every LButtonUp.
void CTopicListBox::Dropped(int nSrcIndex, CPoint pt)
{
	if(m_bDragging)
	{
		// Base to do the drop.
		CDragListBox::Dropped(nSrcIndex, pt);

		m_bDragging = FALSE;
		int iSel = GetCurSel();

		// Owner resets list with indents and cur sel.
		GetParent()->PostMessage(WM_USER_TOPIC_LIST_CHANGE, (WPARAM)iSel, (LPARAM)0);
	}
	// Clean list of drop target image remnants.
	else
		CancelDrag(pt);
}

// User dragging an item to a new location.
UINT CTopicListBox::Dragging(CPoint pt)
{
	m_bDragging = TRUE;
	// Base.
	return CDragListBox::Dragging(pt);
}

/*
// nada
void CTopicListBox::DeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CDragListBox::DeleteItem(lpDeleteItemStruct);
}

void CTopicListBox::OnDeleteItem(int nIDCtl, LPDELETEITEMSTRUCT lpDeleteItemStruct) 
{
	// TODO: Add your message handler code here and/or call default
	
	CDragListBox::OnDeleteItem(nIDCtl, lpDeleteItemStruct);
}*/
