//	Zinc Application Framework - W_VLIST.CPP
//	COPYRIGHT (C) 1990-1999.  All Rights Reserved.
//	Zinc Software Incorporated.  Pleasant Grove, Utah  USA

#include <w_app.hpp>
#include <z_keymap.hpp>
#include <z_str1.hpp>
#include <z_vlist.hpp>

// ----- ZafVtList --------------------------------------------------------

ZafWindowObject *ZafVtList::Add(ZafWindowObject *object, ZafWindowObject *position)
{
	if (!object || object->parent)
		return (object);

	object->SetSystemObject(false);
	object->SetParentDrawBorder(true);
	object->SetParentDrawFocus(true);
	object->SetParentPalette(true);

	// Add the object to the list.
	if (object->SupportObject())
		return (ZafWindow::Add(object, position));

	// Bypass ZafWindow::Add() since we need to add the Windows object before
	// selecting the object.  Using ZafWindow::Add() would set the object as
	// selected before the Windows item existed which results in the wrong
	// list item getting selected.
	if (position)
		ZafList::Add(object, position);	// position insert.
	else
		ZafList::Add(object);			// compareFunction insert.

	// See if object should be the "current" object (and selected).
	bool setSelected = object->Selected();
	bool setCurrent = (object->Focus() || (selectionType == ZAF_SINGLE_SELECTION &&
		setSelected))? true : false;

	// Clear the focus flag. (The object can't really have focus until it
	// is displayed in the window.)
	object->SetFocus(false);
	object->SetSelected(false);

	// Set parent after SetSelected(false) in case ZAF_SINGLE_SELECTION.
	object->parent = this;

	// Insert the list item (if the list is already on the screen).
	if (screenID)
	{
		// Create the object (make it appear in the window).
		object->Event(S_CREATE);

		if (ZafMSWindowsApp::convertText)
		{
			char *osText = zafCodeSet->ConvertToOSString(object->Text());
			SendMessage(screenID, LB_INSERTSTRING, (WPARAM)Index(object), OSDraw() ? (LPARAM)osText : (LPARAM)object);
			delete []osText;
		}
		else
			SendMessage(screenID, LB_INSERTSTRING, (WPARAM)Index(object), OSDraw() ? (LPARAM)object->Text() : (LPARAM)object);
	}

	// Update the focus.
	if (setCurrent)
	{
		if (Focus())
			object->SetFocus(true);
		else
			ZafList::SetCurrent(object);
	}

	// Update selection.
	if (setSelected)
		object->SetSelected(true);

	return (object);
}

#if defined(ZAF_DEFAULT_DRAW)
ZafEventType ZafVtList::Draw(const ZafEventStruct &, ZafEventType ccode)
{
	// List is always drawn by windows.
	// (Ownerdraw means children draw themselves insetead of being drawn by
	// the list.)
	return (ccode);
}

ZafEventType ZafVtList::DrawBorder(ZafRegionStruct &, ZafEventType ccode)
{
	return (ccode);
}
#endif

ZafEventType ZafVtList::DragDropEvent(const ZafEventStruct &event)
{
	ZafEventType ccode = event.type;

	switch (ccode)
	{
	case S_DROP_DEFAULT:
		if (windowManager->dragObject->MoveDraggable())
			ccode = S_DROP_MOVE;
		else if (windowManager->dragObject->CopyDraggable())
			ccode = S_DROP_COPY;
		else
		{
			ccode = S_ERROR;
			break;
		}
		//Continue.
	case S_DROP_COPY:
	case S_DROP_MOVE:
		if (Disabled())
			return (S_ERROR);
		else if (AcceptDrop() && this != windowManager->dragObject)
		{
			// Clear all selections if extended selection list.
			if (selectionType == ZAF_EXTENDED_SELECTION)
			{
				for (ZafWindowObject *item = First(); item; item = item->Next())
					item->SetSelected(false);
			}

			if (windowManager->dragObject->IsA(ID_ZAF_LIST))
			{
				ZafWindow *dragList = DynamicPtrCast(windowManager->dragObject, ZafWindow);

				bool saveAutoUpdateSource = dragList->AutomaticUpdate();
				bool saveAutoUpdateTarget = automaticUpdate;

				if (ccode == S_DROP_MOVE)
					dragList->SetAutomaticUpdate(false);
				SetAutomaticUpdate(false);

				// Move the selected objects.
				ZafWindowObject *object = dragList->First();
				while (object)
				{
					ZafWindowObject *nextObject = object->Next();
					if (object->Selected())
					{
						if (ccode == S_DROP_COPY)
							Add(object->Duplicate());
						else
						{
							dragList->Subtract(object);
							Add(object);
						}
					}
					object = nextObject;
				}
				if (ccode == S_DROP_MOVE)
					dragList->SetAutomaticUpdate(saveAutoUpdateSource);
				SetAutomaticUpdate(saveAutoUpdateTarget);
			}
			else
			{
				const ZafIChar *dropText = windowManager->dragObject->Text();
				if (dropText && *dropText)
				{
					ZafString *newString = new ZafString(0, 0, 0, new ZafStringData(dropText));
					newString->SetBordered(false);
					Add(newString);
					if (ccode != S_DROP_COPY)
						windowManager->dragObject->SetText(ZafLanguageManager::blankString);
				}
				else
					ccode = S_ERROR;
			}
		}
		else
			ccode = S_ERROR;
		break;

	default:
		ccode = ZafWindowObject::DragDropEvent(event);
		break;
	}

	return (ccode);
}

ZafEventType ZafVtList::Event(const ZafEventStruct &event)
{
	ZafEventType ccode = event.type;

	if (ccode == E_OSEVENT)
		return (ZafVtList::OSEvent(event));

	// Switch on the event type.
	switch (ccode)
	{
	case S_HOT_KEY:
		ccode = S_UNKNOWN;
		break;

	case S_REDISPLAY_DATA:
		ZafWindowObject::Event(ZafEventStruct(S_REDISPLAY));
		break;

	case S_REGISTER_OBJECT:
		{
		ccode = ZafWindow::Event(event);

		// Add the items to the list.
		int index = 0;
		for (ZafWindowObject *object = First(); object; object = object->Next())
		{
			if (ZafMSWindowsApp::convertText)
			{
				char *osText = zafCodeSet->ConvertToOSString(object->Text());
				SendMessage(screenID, LB_INSERTSTRING, (WPARAM)-1, OSDraw() ? (LPARAM)osText : (LPARAM)object);
				delete []osText;
			}
			else
				SendMessage(screenID, LB_INSERTSTRING, (WPARAM)-1, OSDraw() ? (LPARAM)object->Text() : (LPARAM)object);
			if (object->Selected())
			{
				if (SelectionType() != ZAF_SINGLE_SELECTION)
					SendMessage(screenID, LB_SETSEL, (WPARAM)TRUE, (LPARAM)index);
				else
				{
					ZafList::SetCurrent(object);
					SendMessage(screenID, LB_SETCURSEL, (WPARAM)index, (LPARAM)0);
				}
			}
			index++;
		}

		// Set the current item in the list.
		if (SelectionType() != ZAF_SINGLE_SELECTION)
		{
			if (!current && first)
				ZafList::SetCurrent(first);
			if (current)
				SendMessage(screenID, LB_SETCARETINDEX, (WPARAM)Index(current), (LPARAM)0);
		}
		}
		break;

	case N_SIZE:
		break;

	default:
		ccode = ZafWindow::Event(event);
		break;
	}

	// Return the control code.
	return (ccode);
}

ZafWindowObject *ZafVtList::NotifyFocus(ZafWindowObject *object, bool setFocus)
{
	if (systemObject)
	{
		ZafWindowObject *invalidObject = ZafWindow::NotifyFocus(object, setFocus);
		if (object != this && setFocus && !invalidObject)
		{
			int index = Index(object);
			if (SendMessage(screenID, LB_GETCARETINDEX, (WPARAM)0, (LPARAM)0) != index)
				if (SelectionType() == ZAF_MULTIPLE_SELECTION)
					SendMessage(screenID, LB_SETCARETINDEX, (WPARAM)index, (LPARAM)0);
				else
					SendMessage(screenID, LB_SETCURSEL, (WPARAM)index, (LPARAM)0);
		}

		return (invalidObject);
	}
	else
		// Let the combo box process the focus.
		return (parent->NotifyFocus(object, setFocus));
}

ZafWindowObject *ZafVtList::NotifySelection(ZafWindowObject *object, bool setSelected)
{
	ZafWindow::NotifySelection(object, setSelected);
	if (object->Selected() == setSelected)
	{
		if (screenID && SystemObject())
		{
			int index = Index(object);
			if ((SendMessage(screenID, LB_GETSEL, (WPARAM)index, (LPARAM)0) ? true : false) != setSelected)
			{
				if (SelectionType() != ZAF_SINGLE_SELECTION)
				{
					SendMessage(screenID, LB_SETSEL, (WPARAM)setSelected, (LPARAM)index);
					SendMessage(screenID, LB_SETCARETINDEX, (WPARAM)Index(current), (LPARAM)0);
				}
				else if (setSelected)
				{
					SendMessage(screenID, LB_SETCURSEL, (WPARAM)index, (LPARAM)0);
					// Single select lists are also auto select.
					if (Focus())
						object->SetFocus(true);
					else
						ZafList::SetCurrent(object);
				}
			}
		}
		else if (temporary)
			// This is a combo box's list.
			parent->NotifySelection(object, setSelected);
	}

	return (object);
}

ZafWindowObject *ZafVtList::Subtract(ZafWindowObject *object)
{
	if (screenID && systemObject && !object->SupportObject())
		SendMessage(screenID, LB_DELETESTRING, (WPARAM)Index(object), (LPARAM)0);
	return (ZafWindow::Subtract(object));
}

// ----- OS Specific Functions ----------------------------------------------

void ZafVtList::OSDestroy(void)
{
	if (screenID)
	{
		SendMessage(screenID, LB_RESETCONTENT, 0, 0);
		for (ZafWindowObject *object = First(); object; object = object->Next())
			object->Event(S_DEINITIALIZE);
	}
}

ZafEventType ZafVtList::OSEvent(const ZafEventStruct &event)
{
	if (editMode && event.InputType() == E_MOUSE)
		return (ZafWindowObject::Event(event));

	ZafEventType ccode = event.type;

	switch (event.osEvent.message)
	{
	case WM_COMMAND:
		{
#if defined(ZAF_WIN32)
		HWND hwndCtrl = (HWND)event.osEvent.lParam;
#else
		HWND hwndCtrl = (HWND)LOWORD(event.osEvent.lParam);
#endif

		// Sometimes the WM_COMMAND goes to the child first and it needs to
		// both process it and pass it to the DefWindProc. Passing it to
		// DefWindProc usually results in it going to the parent window,
		// which sends it back, resulting in the child processing the
		// message twice, or worse, an infinite loop. Thus, on messages the
		// parent sends back, we zero out the hwnd in lParam so the child
		// knows it can process the message.
		if (hwndCtrl)
			ccode = ZafWindowObject::OSEvent(event);
		else
		{
#if defined(ZAF_WIN32)
			WORD wNotifyCode = HIWORD(event.osEvent.wParam);
#else
			WORD wNotifyCode = HIWORD(event.osEvent.lParam);
#endif
			if (wNotifyCode == LBN_SELCHANGE || wNotifyCode == LBN_SELCANCEL)
			{
				// Get index of the current item.
				int currentIndex = (int)SendMessage(screenID, LB_GETCARETINDEX, 0, 0);

				// Update the selected and current items.
				if (SelectionType() != ZAF_SINGLE_SELECTION)
				{
					// Build an array of selected item indexes.
					int selectedItems = (int)SendMessage(screenID, LB_GETSELCOUNT, 0, 0);
					int *selectionArray = new int[selectedItems];
					SendMessage(screenID, LB_GETSELITEMS, (WPARAM)selectedItems, (LPARAM)selectionArray);

					int index = 0;
					int selectionIndex = 0;
					for (ZafWindowObject *object = First(); object; object = object->Next())
					{
						// Update current list item.
						if (index == currentIndex && object != current)
							object->NotifyFocus(object, true);

						// Update list items selections.
						if (!object->Disabled())
						{
							if (selectionIndex < selectedItems && index == selectionArray[selectionIndex])
							{
								if (!object->Selected())
								{
									// Select the item.
									object->SetSelected(true);
									(object->*(object->memberUserFunction))(event, L_SELECT);
								}
							}
							else
							{
								if (object->Selected())
								{
									// Un-select the item.
									object->SetSelected(false);
									(object->*(object->memberUserFunction))(event, L_SELECT);
								}
							}
						}

						// Increment the indexes.
						if (selectionIndex < selectedItems && selectionArray[selectionIndex] <= index)
							selectionIndex++;
						index++;

						// Stop if finished.
						if (index > currentIndex && selectionIndex > selectedItems)
							break;
					}

					// Clean up.
					delete []selectionArray;
				}
				else
				{
					// Get the new current/selected object.
					ZafWindowObject *object = DynamicPtrCast(ZafList::Get(currentIndex), ZafWindowObject);

					// Set the focus and selection.
					if (object && !object->Disabled())
					{
						object->NotifyFocus(object, true);
						object->SetSelected(true);
						(object->*(object->memberUserFunction))(event, L_SELECT);
					}
				}
			}
			else if (wNotifyCode == LBN_DBLCLK)
			{
				ZafWindowObject *object = Current();
				if (object && !object->Disabled())
					(object->*(object->memberUserFunction))(event, L_DOUBLE_CLICK);
			}
		}
		}
		break;

#if defined(ZAF_WIN32)
	case WM_CTLCOLORLISTBOX:
#else
	case WM_CTLCOLOR:
#endif
		{
		// Get the palettes.
		ZafPaletteState state = PaletteState();
		ZafPaletteStruct textPalette = LogicalPalette(ZAF_PM_TEXT, state);
		ZafPaletteStruct backgroundPalette = LogicalPalette(ZAF_PM_BACKGROUND, state);

		// Get the OS colors from the text palette.
		COLORREF colorForeground = (textPalette.colorForeground == ZAF_CLR_DEFAULT) ?
			textPalette.osPalette.colorForeground :
			((ZafScreenDisplay *)display)->colorTable[textPalette.colorForeground];
		COLORREF colorBackground = (backgroundPalette.colorBackground == ZAF_CLR_DEFAULT) ?
			backgroundPalette.osPalette.colorBackground :
			((ZafScreenDisplay *)display)->colorTable[backgroundPalette.colorBackground];

		// Set the OS colors.
		SelectPalette((HDC)event.osEvent.wParam, ((ZafScreenDisplay *)display)->logicalPalette, FALSE);
		::SetTextColor((HDC)event.osEvent.wParam, colorForeground);
		SetBkColor((HDC)event.osEvent.wParam, colorBackground);

		// Get a background brush.
		HBRUSH backgroundBrush = ((ZafScreenDisplay *)display)->GetGdiCacheBrush(backgroundPalette);
		((ZafScreenDisplay *)display)->ReleaseGdiCacheObject(backgroundBrush);
		ccode = (ZafEventType)backgroundBrush;
		}
		break;

	case WM_DRAWITEM:
		{
		DRAWITEMSTRUCT *drawItemStruct = (DRAWITEMSTRUCT *)event.osEvent.lParam;

		// Begin drawing operation.
		display->BeginDraw(drawItemStruct->hDC, 0, zafRegion, zafRegion);

		if (drawItemStruct->itemID == (UINT)-1)
		{
			ZafRegionStruct focusRegion;
			focusRegion.ImportPoint(drawItemStruct->rcItem);

			if (drawItemStruct->itemState & ODS_FOCUS)
				DrawFocus(focusRegion, S_CURRENT);
			else
				DrawFocus(focusRegion, S_NON_CURRENT);
		}
		else
		{
			ZafWindowObject *object = (ZafWindowObject *)drawItemStruct->itemData;
			object->zafRegion.ImportPoint(drawItemStruct->rcItem);
			object->Event(event);
		}

		// End drawing operation.
		display->EndDraw();

		ccode = TRUE;
		}
		break;

	case WM_KEYDOWN:
		switch ((int)event.osEvent.wParam)
		{
		case VK_UP:
		case VK_DOWN:
		case VK_LEFT:
		case VK_RIGHT:
		case VK_PRIOR:
		case VK_NEXT:
		case VK_SPACE:
			// Allow arrowing.
			ccode = DefaultCallback(event);
			break;

		default:
			ccode = ZafWindowObject::OSEvent(event);
			break;
		}
		break;

	case WM_LBUTTONUP:
	case WM_RBUTTONUP:
		// Perform default operation.
		if (Noncurrent())
		{
#if defined(ZAF_WIN32)
			POINTS mousePos = MAKEPOINTS(event.osEvent.lParam);
#else
			POINT mousePos = MAKEPOINT(event.osEvent.lParam);
#endif
			int index = (int)SendMessage(screenID, LB_GETTOPINDEX, 0, 0);
			int pos = 0;

			while (mousePos.y > pos)
				pos += SendMessage(screenID, LB_GETITEMHEIGHT, (WPARAM)index++, 0);
			index--; // One more than needed for 0-based Get.

			ZafWindowObject *item = Get(index);
			if (item)
			{
				if (!item->Selected())
				{
					item->SetSelected(true);
					(item->*(item->memberUserFunction))(event, L_SELECT);
				}
				else if (selectionType != ZAF_SINGLE_SELECTION)
					item->SetSelected(false);
			}
		}
		else
			ccode = ZafWindowObject::OSEvent(event);
		break;

	case WM_MEASUREITEM:
		if (OSDraw())
			ccode = ZafWindowObject::OSEvent(event);
		else
		{
			MEASUREITEMSTRUCT *measureItemStruct = (MEASUREITEMSTRUCT *)event.osEvent.lParam;
			ZafWindowObject *object = (ZafWindowObject *)measureItemStruct->itemData;
			object->Event(ZafEventStruct(S_COMPUTE_SIZE));
			measureItemStruct->itemWidth = object->zafRegion.Width();
			measureItemStruct->itemHeight = object->zafRegion.Height();
			ccode = TRUE;
		}
		break;

	case WM_PAINT:
	case WM_ERASEBKGND:
		// Don't call Draw().
		ccode = DefaultCallback(event);
		break;

	case WM_WINDOWPOSCHANGED:
		// Set the client region.
		RECT clientRect;
		GetClientRect(screenID, &clientRect);
		clientRegion.ImportPoint(clientRect);
		ccode = ZafWindowObject::Event(event);
		break;

	default:
		ccode = ZafWindowObject::OSEvent(event);
	}

	return (ccode);
}

void ZafVtList::OSMapPalette(ZafPaletteStruct &palette, ZafPaletteType type, ZafPaletteState state)
{
	// Get default colors from the operating system.
	if (type == ZAF_PM_TEXT || type == ZAF_PM_FOREGROUND)
	{
		if (palette.colorForeground == ZAF_CLR_DEFAULT && palette.osPalette.colorForeground == 0xFFFFFFFFL)
		{
			if (state & ZAF_PM_DISABLED)
				palette.osPalette.colorForeground = GetSysColor(COLOR_GRAYTEXT);
			else if (state & ZAF_PM_SELECTED)
				palette.osPalette.colorForeground = GetSysColor(COLOR_HIGHLIGHTTEXT);
			else
				palette.osPalette.colorForeground = GetSysColor(COLOR_WINDOWTEXT);
		}
		if (palette.colorBackground == ZAF_CLR_DEFAULT && palette.osPalette.colorBackground == 0xFFFFFFFFL)
		{
			if (state & ZAF_PM_SELECTED)
				palette.osPalette.colorBackground = GetSysColor(COLOR_HIGHLIGHT);
			else
				palette.osPalette.colorBackground = GetSysColor(COLOR_WINDOW);
		}
	}
	else if (type == ZAF_PM_BACKGROUND)
	{
		if (palette.colorForeground == ZAF_CLR_DEFAULT && palette.osPalette.colorForeground == 0xFFFFFFFFL)
		{
			if (state & ZAF_PM_SELECTED)
				palette.osPalette.colorForeground = GetSysColor(COLOR_HIGHLIGHT);
			else
				palette.osPalette.colorForeground = GetSysColor(COLOR_WINDOW);
		}
		if (palette.colorBackground == ZAF_CLR_DEFAULT && palette.osPalette.colorBackground == 0xFFFFFFFFL)
		{
			if (state & ZAF_PM_SELECTED)
				palette.osPalette.colorBackground = GetSysColor(COLOR_HIGHLIGHT);
			else
				palette.osPalette.colorBackground = GetSysColor(COLOR_WINDOW);
		}
	}
	else
		ZafWindow::OSMapPalette(palette, type, state);
}

void ZafVtList::OSRegisterObject(void)
{
	DWORD dwStyle = LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_CLIPSIBLINGS;
	DWORD dwExStyle = 0;

	if (SelectionType() == ZAF_MULTIPLE_SELECTION)
		dwStyle |= LBS_MULTIPLESEL;
	else if (SelectionType() == ZAF_EXTENDED_SELECTION)
		dwStyle |= (LBS_MULTIPLESEL | LBS_EXTENDEDSEL);

	if (visible)
		dwStyle |= WS_VISIBLE;

	if (bordered)
	{
#if defined(ZAF_MSWINDOWS_3D)
		if (ZafMSWindowsApp::native3D)
			dwExStyle |= WS_EX_CLIENTEDGE;
		else
			dwStyle |= WS_BORDER;
#else
		dwStyle |= WS_BORDER;
#endif
	}

	if (Disabled() && !editMode)
		dwStyle |= WS_DISABLED;

	if (!osDraw)
		dwStyle |= LBS_OWNERDRAWVARIABLE;

	if (VerticalScrollBar())
		dwStyle |= WS_VSCROLL;

	// Create the list.
	screenID = ZafMSWindowsApp::CreateSubclassedWindow(this, ZAF_ITEXT("LISTBOX"), dwStyle, ZAF_NULLP(ZafIChar), 0, dwExStyle);

	// Set the font.
	ZafPaletteStruct fontPalette = LogicalPalette(ZAF_PM_TEXT, ZAF_PM_ACTIVE | ZAF_PM_ENABLED);
	SendMessage(screenID, WM_SETFONT, (WPARAM)((ZafScreenDisplay *)display)->fontTable[fontPalette.font], (LPARAM)FALSE);
}

ZafError ZafVtList::OSUpdatePalettes(ZafPaletteType, ZafPaletteType)
{
	if (screenID)
	{
		ZafPaletteStruct fontPalette = LogicalPalette(ZAF_PM_TEXT, ZAF_PM_ACTIVE | ZAF_PM_ENABLED);
		SendMessage(screenID, WM_SETREDRAW, (WPARAM)FALSE, 0);
		SendMessage(screenID, WM_SETFONT, (WPARAM)((ZafScreenDisplay *)display)->fontTable[fontPalette.font], (LPARAM)FALSE);
		if (automaticUpdate && visible)
			SendMessage(screenID, WM_SETREDRAW, (WPARAM)TRUE, 0);
		Redisplay();
	}

	return (ZAF_ERROR_NONE);
}

// ----- Stubs --------------------------------------------------------------

ZafRegionStruct ZafVtList::ConvertToDrawRegion(const ZafWindowObject *object,
	const ZafRegionStruct *region) const
{
	return (ZafWindowObject::ConvertToDrawRegion(object, region));
}

#if defined(ZAF_DEFAULT_DRAW)
ZafEventType ZafVtList::DrawFocus(ZafRegionStruct &region, ZafEventType ccode)
{
	return (ZafWindowObject::DrawFocus(region, ccode));
}
#endif

void ZafVtList::GetClip(ZafWindowObject *, ZafRegionStruct &, ZafRegionStruct &)
{
	// Handled automatically by Windows.
}

ZafEventType ZafVtList::MoveEvent(const ZafEventStruct &event)
{
	// Handled automatically by Windows.
	return (event.type);
}

OSWindowID ZafVtList::OSScreenID(ZafScreenIDType) const
{
	return (screenID);
}

void ZafVtList::OSSize(void)
{
	ZafWindowObject::OSSize();
}


void ZafVtList::OSSort(void)
{
	if (screenID)
	{
		SendMessage(screenID, LB_RESETCONTENT, (WPARAM)0, (LPARAM)0);

		//??? Duplicate code.
		//??? Optimize Refresh.
		int index = 0;
		for (ZafWindowObject *object = First(); object; object = object->Next())
		{
			if (ZafMSWindowsApp::convertText)
			{
				char *osText = zafCodeSet->ConvertToOSString(object->Text());
				SendMessage(screenID, LB_INSERTSTRING, (WPARAM)-1, OSDraw() ? (LPARAM)osText : (LPARAM)object);
				delete []osText;
			}
			else
				SendMessage(screenID, LB_INSERTSTRING, (WPARAM)-1, OSDraw() ? (LPARAM)object->Text() : (LPARAM)object);
			if (object->Selected())
			{
				if (SelectionType() != ZAF_SINGLE_SELECTION)
					SendMessage(screenID, LB_SETSEL, (WPARAM)TRUE, (LPARAM)index);
				else
				{
					ZafList::SetCurrent(object);
					SendMessage(screenID, LB_SETCURSEL, (WPARAM)index, (LPARAM)0);
				}
			}
			index++;
		}
	}
}

ZafEventType ZafVtList::ScrollEvent(const ZafEventStruct &event)
{
	ZafEventType ccode = event.type;

	switch (ccode)
	{
	case S_VSCROLL:
		{
		int topIndex = (int)SendMessage(screenID, LB_GETTOPINDEX, (WPARAM)0, (LPARAM)0);
		topIndex += (int)event.scroll.delta;
		SendMessage(screenID, LB_SETTOPINDEX, (WPARAM)topIndex, (LPARAM)0);
		}
		break;
	}

	return (ccode);
}

bool ZafVtList::SetAutomaticUpdate(bool setAutomaticUpdate)
{
	// Defer to the base class.
	return (ZafWindow::SetAutomaticUpdate(setAutomaticUpdate));
}

bool ZafVtList::SetVisible(bool setVisible)
{
	return (ZafWindowObject::SetVisible(setVisible));
}


