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

#include "i_combo.hpp"
#include <z_app.hpp>
#include <z_ctype.hpp>
#define USE_RAW_KEYS
#include <z_keymap.hpp>
#include <z_lang.hpp>
#include <z_mouse2.hpp>
#include <z_string.hpp>
#include <z_utils.hpp>

// ----- ZafComboBox ------------------------------------------------------

ZafWindowObject *ZafComboBox::Add(ZafWindowObject *object, ZafWindowObject *position)
{
	// Add the item to the list.
	return (list->Add(object, position));
}

void ZafComboBox::ConvertCoordinates(ZafCoordinateType newType)
{
	if (zafRegion.coordinateType != newType)
	{
		if (maxListHeight != -1)
		{
			maxListHeight = (int)display->ConvertYValue(maxListHeight,
				zafRegion.coordinateType, newType);
			listHeight = maxListHeight;
		}
		else
			listHeight = (int)display->ConvertYValue(listHeight,
				zafRegion.coordinateType, newType);
		if (listWidth != -1)
			listWidth = (int)display->ConvertXValue(listWidth,
				zafRegion.coordinateType, newType);
		ZafWindow::ConvertCoordinates(newType);
	}
}

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

ZafEventType ZafComboBox::DispatchMouseEvent(const ZafEventStruct &event)
{
	// This object behaves as an atom.
	return (ZafWindowObject::DispatchMouseEvent(event));
}

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

	switch (ccode)
	{
	case S_BEGIN_DRAG:
		if (list->Current())
			list->Current()->SetSelected(true);
		ZafWindowObject::DragDropEvent(event);
		break;

	case S_DROP_DEFAULT:
		ccode = S_DROP_MOVE;
		// Fall through to S_DROP_MOVE.
	case S_DROP_COPY:
	case S_DROP_MOVE:
		if (Disabled() || !AcceptDrop() || windowManager->dragObject == this)
			return (S_ERROR);
		else if (windowManager->dragObject->IsA(ID_ZAF_LIST))
		{
			// Move the selected objects.
			ZafWindow *dragList = DynamicPtrCast(windowManager->dragObject, ZafWindow);
			ZafWindowObject *object;
			if (dragList->IsA(ID_ZAF_COMBO_BOX))
				object = DynamicPtrCast(dragList, ZafComboBox)->First();
			else
				object = dragList->First();
			while (object)
			{
				ZafWindowObject *temp = object->Next();
				if (object->Selected())
				{
					if (ccode == S_DROP_COPY)
					{
						ZafWindowObject *newObject = object->Duplicate();
						newObject->SetSelected(false);
						Add(newObject);
					}
					else
					{
						dragList->Subtract(object);
						object->SetSelected(false);
						Add(object);
					}
				}
				object = temp;
			}
		}
		else if (OSDraw() && !ViewOnly())
			ccode = ZafWindowObject::DragDropEvent(event);
		else
			ccode = S_ERROR;
		break;

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

	return (ccode);
}

#if defined(ZAF_DEFAULT_DRAW)
ZafEventType ZafComboBox::Draw(const ZafEventStruct &event, ZafEventType ccode)
{
	ZafWindow::Draw(event, ccode);

	if (OSDraw() && !viewOnly)
		return (ccode);

	ZafWindowObject *object = list->Current();
	if (object)
	{
		ZafRegionStruct _zafRegion = object->zafRegion;
		OSWindowID _screenID = object->screenID;
		ZafWindowObject *_parent = object->parent;

		object->zafRegion = clientRegion;
		object->zafRegion.HzShift(-clientRegion.left);
		object->zafRegion.VtShift(-clientRegion.top);
		object->screenID = 0;
		object->SetSystemObject(true);
		object->screenID = screenID;

		automaticUpdate = false;
		bool _focus = object->Focus();
		bool _selected = object->Selected();
		object->SetFocus(focus);
		object->SetSelected(false);
		automaticUpdate = true;

		object->parent = this;
		ZafEventStruct childEvent = event;
		childEvent.region.Assign(0, 0, clientRegion.Width(),
			clientRegion.Height(), clientRegion.coordinateType);
		object->Draw(childEvent, ccode);

		automaticUpdate = false;
		object->SetFocus(_focus);
		object->SetSelected(_selected);

		object->screenID = 0;
		object->SetSystemObject(false);
		object->zafRegion = _zafRegion;
		object->screenID = _screenID;
		object->parent = _parent;
//		comboString->SetFocus(focus);

		automaticUpdate = true;
	}

	return (ccode);
}

ZafEventType ZafComboBox::DrawBorder(ZafRegionStruct &region, ZafEventType ccode)
{
	return (ZafWindowObject::DrawBorder(region, ccode));
}

ZafEventType ZafComboBox::DrawFocus(ZafRegionStruct &, ZafEventType ccode)
{
	return (ccode);
}
#endif

ZafEventType ZafComboBox::Event(const ZafEventStruct &event)
{
	ZafEventType ccode = LogicalEvent(event);

	// Check for zinc events.
	switch (ccode)
	{
	// ----- Create messages -----
	case S_INITIALIZE:
		if (!comboButton)
		{
			comboButton = new ZafComboButton;
			ZafWindow::Add(comboButton);
		}
		comboButton->SetSystemObject(SystemObject());
		if (!comboString && (OSDraw() && !viewOnly))
		{
			comboString = new ZafComboString;
#if defined(ZAF_GRAPHICS_MODE)
			if (ViewOnly())
				comboString->SetParentPalette(true);
#endif
			ZafWindow::Add(comboString);
		}
		if (viewOnly || !OSDraw() && comboString)
		{
			ZafWindow::Subtract(comboString);
			delete comboString;
			comboString = ZAF_NULLP(ZafWindowObject);
		}
		if (comboString && list->current)
			comboString->SetText(list->Current()->Text());
		list->Event(event);
		ccode = ZafWindow::Event(event);
		break;

	case L_VIEW:
	case L_CONTINUE_SELECT:
	case L_END_SELECT:
		if (Draggable() && ccode != L_VIEW && !windowManager->dragObject)
			ZafWindowObject::Event(event);
		if (editMode || windowManager->dragObject)
			ZafWindowObject::Event(event);
		else
		{
			ZafPositionStruct mousePosition = event.position;
			ZafRegionStruct windowClient = ClientRegion();
			if (windowClient.Overlap(mousePosition))
			{
				// If the mouse is over the client region, convert to the client
				// region's coordinates.
				mousePosition.column -= windowClient.left;
				mousePosition.line -= windowClient.top;
				// Cast away the constness so we can have event.position relative
				// to the client region.
				((ZafEventStruct &)event).position = mousePosition;

				// The combo string is the only possible client object.
				ZafWindowObject *object = ComboFirst();
				if (object && object->Visible() && object->zafRegion.Overlap(mousePosition))
				{
					// If the string is being overlapped for the first time
					// let it set the mouse cursor without making it the
					// window manager's mouseObject (that would mess up
					// help tips if the combo box had one).
					if (ccode == L_VIEW && mouseObject != object)
					{
						ZafEventStruct mouseEvent = event;
						mouseEvent.type = N_MOUSE_ENTER;
						object->Event(mouseEvent);
						mouseObject = object;
					}
					else
						ccode = object->Event(event);
				}
			}
			else if (comboButton->zafRegion.Overlap(mousePosition))
			{
				// If the button is being overlapped for the first time
				// let it set the mouse cursor without making it the
				// window manager's mouseObject (that would mess up
				// help tips if the combo box had one).
		 		if (ccode == L_VIEW && mouseObject != comboButton)
				{
					ZafEventStruct mouseEvent = event;
					mouseEvent.type = N_MOUSE_ENTER;
					comboButton->Event(mouseEvent);
					mouseObject = comboButton;
				}
				else
					ccode = comboButton->Event(event);
			}
			else
			{
				// If nothing is overlapped, reset the mouse cursor.
				if (ccode == L_VIEW)
				{
					mouseObject = ZAF_NULLP(ZafWindowObject);
					eventManager->SetDeviceState(E_MOUSE, DM_VIEW);
				}
				else
					ccode = ZafWindow::Event(event);
			}
		}
		break;

	case L_BEGIN_SELECT:
		if (Draggable())
			ZafWindow::Event(event);

		// Open the drop-down list if a click occurs anywhere on the combo-box.
		if (!viewOnly && OSDraw())
		{
			ZafPositionStruct mousePosition = event.position;
			ZafRegionStruct windowClient = ClientRegion();
			if (windowClient.Overlap(mousePosition))
			{
				// If the mouse is over the client region, convert to the client
				// region's coordinates.
				mousePosition.column -= windowClient.left;
				mousePosition.line -= windowClient.top;
				// Cast away the constness so we can have event.position relative
				// to the client region.
				((ZafEventStruct &)event).position = mousePosition;

				// The combo string is the only possible client object.
				ZafWindowObject *object = ComboFirst();
				if (object && object->Visible() && object->zafRegion.Overlap(mousePosition))
					return (object->Event(event));
			}
			else if (comboButton->zafRegion.Overlap(mousePosition))
				return (comboButton->Event(event));
			else
				return (ZafWindow::Event(event));
		}

		// Continue to L_SELECT.

	case L_SELECT:
		{
			if (ccode == L_SELECT && event.type == E_KEY)
			{
				if (windowManager->First() != list && event.rawCode != F4)
				{
					(this->*memberUserFunction)(event, L_SELECT);
					break;
				}
			}

			if (windowManager->First() == list)
			{
				Event(N_CLOSE_COMBO_LIST);
				windowManager->Event(S_CLOSE_TEMPORARY);
				break;
			}

			// Put up drop-down list.
//			int height = list->zafRegion.Height();
			int height;
			if (!list->First())
				height = listHeight;
			else
			{
				// Make sure the item has a valid height.
				list->Event(N_SIZE);
				height = ZafMin(list->Count() * (list->First()->zafRegion.Height()
					+ 2*display->preSpace), listHeight);
			}
			int width;
			if (listWidth == -1)
				width = zafRegion.Width();
			else
				width = listWidth;
			ZafPositionStruct origin;
			origin.column = zafRegion.left;
			origin.line = zafRegion.bottom;
			origin.coordinateType = zafRegion.coordinateType;
			origin = parent->ConvertToOSPosition(this, &origin);
			list->zafRegion.left = origin.column;
#if defined(ZAF_TEXT_MODE)
			list->zafRegion.top = origin.line + 1;
#else
			list->zafRegion.top = origin.line;
#endif
			list->zafRegion.right = origin.column + width - 1;
			list->zafRegion.bottom = list->zafRegion.top + height - 1;
			if (list->zafRegion.bottom > Display()->lines - 1)
				list->zafRegion.VtShift(-(list->zafRegion.Height() +
					zafRegion.Height()));
			list->SetModal(false);
			ZafWindow *scrollBar = DynamicPtrCast(list->SupportFirst(), ZafWindow);
			if (scrollBar)
				scrollBar->SetTemporary(false);
			list->overlapped = false;
			windowManager->Add(list);
			list->Event(S_VSCROLL_CHECK);
			Event(N_OPEN_COMBO_LIST);
		}
		break;

	case N_MOUSE_ENTER:
		ZafWindow::Event(event);
		mouseObject = ZAF_NULLP(ZafWindowObject);
		break;

	case S_NON_CURRENT:
	case S_CURRENT:
		{
			bool _focus = focus;
			current = comboString;
			ZafWindow::Event(event);
			if (_focus != focus)
				Redisplay();
		}
		break;

	case L_UP:
	case L_DOWN:
		list->Event(event);
		break;

	case L_NEXT:
	case L_PREVIOUS:
		ccode = S_UNKNOWN;
		break;

	case E_KEY:
		if (comboString)
			comboString->Event(event);
		MatchInput(event.key.value);
		break;

	// ----- Unknown or error messages -----
	default:
		ccode = ZafWindow::Event(event);
		break;
	}

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

ZafWindowObject *ZafComboBox::FindMouseObject(const ZafEventStruct &event)
{
	return (ZafWindowObject::FindMouseObject(event));
}

void ZafComboBox::GetClip(ZafWindowObject *object, ZafRegionStruct &clip,
	ZafRegionStruct &viewPort)
{
	ZafWindow::GetClip(object, clip, viewPort);
}

ZafWindowObject *ZafComboBox::MatchInput(ZafIChar matchValue)
{
	if (!list->first)
		return (ZAF_NULLP(ZafWindowObject));

	ZafWindowObject *object = ZAF_NULLP(ZafWindowObject);
	if (!viewOnly && OSDraw() && comboString)
	{
		const ZafIChar *comboText = comboString->Text();
		if (!comboText || !First())
			return (ZAF_NULLP(ZafWindowObject));

		if (!*comboText && !First()->Selected())
			object = First();
		else
			for (object = First(); object; object = object->Next())
				if (*comboText && !strnicmp(comboText, object->Text(), strlen(comboText)))
					break;

		if (!object)
			return (ZAF_NULLP(ZafWindowObject));
		else
		{
			// Select the object if the list is open.  Otherwise, only make the
			// matching item current so it will be selected (and the comboString
			// updated) when the list is opened.
			object->SetFocus(true);
			if (windowManager->First() == list)
				list->Event(S_VSCROLL_CHECK);
		}
	}
	// Try to do first character recognition.
	else if (IsPrint(matchValue) && list->current)
	{
		ZafIChar buffer[2];
		buffer[0] = matchValue;
		buffer[1] = 0;
		object = list->Current()->Next() ? list->Current()->Next() : list->First();
		while (object != list->current)
		{
			const ZafIChar *text = object->Text();
			if (text && !strnicmp(buffer, text, 1))
				break;
			object = object->Next() ? object->Next() : list->First();
		}
		if (object != list->current)
		{
			// Give the object focus and select it.
			object->SetFocus(true);
			NotifySelection(object, true);
			list->Event(S_VSCROLL_CHECK);
		}
	}

	return (object);
}

ZafWindowObject *ZafComboBox::NotifyFocus(ZafWindowObject *focusObject, bool setFocus)
{
	if (focusObject && list->Index(focusObject) != -1)
		return (list->NotifyFocus(focusObject, setFocus));
	else
		return (ZafWindow::NotifyFocus(focusObject, setFocus));
}

ZafWindowObject *ZafComboBox::NotifySelection(ZafWindowObject *newObject,
	bool)
{
	if (!newObject)
		return (ZAF_NULLP(ZafWindowObject));

	if (!newObject->Selected())
		newObject->SetSelected(true);

	// Place new data in combo-box.
	if (screenID)
	{
		if (OSDraw() && !viewOnly)
		{
			comboString->SetText(newObject->Text());
			comboString->Redisplay();
		}
		else
		{
//			bool _selected = newObject->selected;
//			newObject->selected = false;

			ZafRegionStruct _zafRegion = newObject->zafRegion;
			OSWindowID _screenID = newObject->screenID;
			ZafWindowObject *_parent = newObject->parent;
			newObject->zafRegion = clientRegion;
			newObject->zafRegion.HzShift(-clientRegion.left);
			newObject->zafRegion.VtShift(-clientRegion.top);
			newObject->screenID = screenID;
			newObject->parent = this;
			newObject->Event(S_REDISPLAY);
			newObject->zafRegion = _zafRegion;
			newObject->screenID = _screenID;
			newObject->parent = _parent;

//			newObject->selected = _selected;
		}
	}
	return (newObject);
}

void ZafComboBox::SetListRegion(const ZafRegionStruct &region)
{
	if (!screenID)
	{
		list->zafRegion = region;
		maxListHeight = region.Height();
		listWidth = region.Width();
		if (maxListHeight != -1)
			listHeight = maxListHeight;
	}
}

int ZafComboBox::SetMaximumListHeight(int tMaxListHeight)
{
	if (!screenID)
	{
		maxListHeight = tMaxListHeight;
		if (maxListHeight != -1)
			listHeight = maxListHeight;
	}

	return (maxListHeight);
}

void ZafComboBox::SetRegion(const ZafRegionStruct &region)
{
	if (region != zafRegion && zafRegion.coordinateType != region.coordinateType)
	{
		if (maxListHeight != -1)
		{
			maxListHeight = (int)display->ConvertYValue(maxListHeight,
				zafRegion.coordinateType, region.coordinateType);
			listHeight = maxListHeight;
		}
		else
			listHeight = (int)display->ConvertYValue(listHeight,
				zafRegion.coordinateType, region.coordinateType);
	}
	if (listWidth == -1)
		list->SetRegion(region);
	ZafWindow::SetRegion(region);
}

ZafWindowObject *ZafComboBox::Subtract(ZafWindowObject *object)
{
	ZafWindowObject *retValue = list->Subtract(object);
	if (object->Selected())
	{
		if (ComboFirst())
			SetText(ZafLanguageManager::blankString);
		if (!list->Current())
			list->SetCurrent(list->First());
	}
	return (retValue);
}

const ZafIChar *ZafComboBox::Text(void)
{
	// Return the current object contents.
	ZafWindowObject *object;
	if (comboString)
		object = comboString;
	else
		object = list->Current();
	return (object ? object->Text() : ZAF_NULLP(ZafIChar));
}

bool ZafComboBox::SetAcceptDrop(bool acceptDrop)
{
	return (ZafWindowObject::SetAcceptDrop(acceptDrop));
}

bool ZafComboBox::SetAutoSortData(bool autoSortData)
{
	// Set the list attribute.
	return (list->SetAutoSortData(autoSortData));
}

bool ZafComboBox::SetDisabled(bool setDisabled)
{
	// Defer to the base class.
	return (ZafWindow::SetDisabled(setDisabled));
}

bool ZafComboBox::SetFocus(bool tFocus)
{
	return (ZafWindow::SetFocus(tFocus));
}

ZafError ZafComboBox::SetText(const ZafIChar *text)
{
	// Return the current object contents.
	if (ViewOnly() || !OSDraw())
		return (ZAF_ERROR_INVALID);
	return (comboString ? comboString->SetText(text) : ZAF_ERROR_INVALID);
}

bool ZafComboBox::SetVisible(bool tVisible)
{
	return (ZafWindow::SetVisible(tVisible));
}

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

void ZafComboBox::OSDestroy(void)
{
	if (comboString)
	{
		bool tAuto = automaticUpdate;
		automaticUpdate = false;
		comboString->SetText(ZafLanguageManager::blankString);
		automaticUpdate = tAuto;
		OSInvalidateRegion(&comboString->zafRegion, false, false);
	}
}

ZafEventType ZafComboBox::OSEvent(const ZafEventStruct &)
{
	return (S_ERROR);
}

ZafError ZafComboBox::OSGetText(void)
{
	return (ZAF_ERROR_NONE);
}

void ZafComboBox::OSMapPalette(ZafPaletteStruct &palette, ZafPaletteType type, ZafPaletteState state)
{
	ZafWindowObject::OSMapPalette(palette, type, state);
}

void ZafComboBox::OSRegisterObject(void)
{
	ZafWindowObject::OSRegisterObject();
}

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

ZafError ZafComboBox::OSSetText(void)
{
	return (ZAF_ERROR_NONE);
}

void ZafComboBox::OSSize(void)
{
	ZafWindow::OSSize();
}

void ZafComboBox::OSSort(void)
{
}

ZafError ZafComboBox::OSUpdatePalettes(ZafPaletteType zafTypes, ZafPaletteType osTypes)
{
	return (ZafWindow::OSUpdatePalettes(zafTypes, osTypes));
}

// ----- ZafComboButton ---------------------------------------------------

#define ZAF_COMBO_BUTTON_INFO
#include "img_def.cpp"

char ZAF_FARDATA ZafComboButton::comboDownArrowName[] = "comboDownArrow";

ZafBitmapData *ZafComboButton::comboDownArrowBitmap = ZAF_NULLP(ZafBitmapData);

#if defined(ZAF_TEXT_MODE)
ZafComboButton::ZafComboButton(void) :
	ZafButton(0, 0, 0, 0, new ZafStringData("[\x19]", 3))
#else
ZafComboButton::ZafComboButton(void) :
	ZafButton(0, 0, 0, 0, ZAF_NULLP(ZafIChar))
#endif
{
	SetBordered(false);
	SetHzJustify(ZAF_HZ_CENTER);
	SetSupportObject(true);
	SetAllowToggling(false);
	SetAutoSize(false);
	SetRegionType(ZAF_AVAILABLE_REGION);
	SetNoncurrent(true);

	// Check the image information.
	ImageAllocate();

	bitmapData = comboDownArrowBitmap;
}

ZafComboButton::~ZafComboButton(void)
{
	// Check the image information.
	ImageFree();
}

#if defined(ZAF_DEFAULT_DRAW)
ZafEventType ZafComboButton::DrawShadow(ZafRegionStruct &region,
	int, ZafEventType ccode)
{
	ZafPaletteStruct lightShadow = LogicalPalette(ZAF_PM_LIGHT_SHADOW, 0);
	ZafPaletteStruct darkShadow = LogicalPalette(ZAF_PM_DARK_SHADOW, 0);
	ZafPaletteStruct whiteShadow = lightShadow;
	ZafPaletteStruct blackShadow = darkShadow;

	// Copy the background colors to the foreground since display->Line() uses 
	// the foreground color.  The "shadow" palettes have different colors in 
	// the foreground and background entries so they can generate two shades
	// of shadow.
	whiteShadow.colorForeground = whiteShadow.colorBackground;
	blackShadow.colorForeground = blackShadow.colorBackground;

	// Draw the shadow pattern.
	display->SetPalette(lightShadow);
	display->Line(region.left, region.top, region.right - 1, region.top);
	display->Line(region.left, region.top, region.left, region.bottom - 1);

	display->SetPalette(whiteShadow);
	display->Line(region.left + 1, region.top + 1, region.right - 1, region.top + 1);
	display->Line(region.left + 1, region.top + 1, region.left + 1, region.bottom - 1);

	display->SetPalette(blackShadow);
	display->Line(region.left, region.bottom, region.right, region.bottom);
	display->Line(region.right, region.top, region.right, region.bottom);

	display->SetPalette(darkShadow);
	display->Line(region.left + 1, region.bottom - 1, region.right - 1, region.bottom - 1);
	display->Line(region.right - 1, region.top + 1, region.right - 1, region.bottom - 1);

	region -= ZAF_BORDER_SIZE;
	return (ccode);
}
#endif

ZafWindowObject *ZafComboButton::Duplicate(void)
{
	return (ZAF_NULLP(ZafWindowObject));
}

ZafEventType ZafComboButton::Event(const ZafEventStruct &event)
{
 	// Switch on the event type.
	ZafEventType ccode = LogicalEvent(event);
	switch (ccode)
	{
	case S_COMPUTE_SIZE:
		ZafWindowObject::Event(event);
#if defined(ZAF_TEXT_MODE)
		zafRegion.left = zafRegion.right - 2;
#else
		zafRegion.left = zafRegion.right - (3 * display->cellHeight) / 4;
#endif
		break;

	case L_BEGIN_SELECT:
		if (DynamicPtrCast(windowManager->First(), ZafWindow)->Temporary() &&
			windowManager->First()->parent == parent)
			windowManager->Event(S_CLOSE_TEMPORARY);
		else
			parent->Event(L_SELECT);
		break;

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

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

void ZafComboButton::ImageAllocate(void)
{
#if !defined(ZAF_TEXT_MODE)
	// comboUpArrowBitmap
	if (!comboDownArrowBitmap)
	{
		ZafI18nData::AddStaticModule(ImageFree);
		comboDownArrowBitmap = new ZafBitmapData(_comboDownArrow_ZafBitmap);
		comboDownArrowBitmap->staticHandle = true;
		comboDownArrowBitmap->SetDestroyable(false);
	}
#endif
}

void ZafComboButton::ImageFree(bool globalRequest)
{
#if !defined(ZAF_TEXT_MODE)
	// Destroy the static images.
	if (globalRequest && comboDownArrowBitmap)
	{
		comboDownArrowBitmap->staticHandle = false;
		delete comboDownArrowBitmap;
		comboDownArrowBitmap = ZAF_NULLP(ZafBitmapData);
	}
#endif
}

bool ZafComboButton::SetSupportObject(bool setSupportObject)
{
	// Make sure the attribute has changed.
	if (supportObject != setSupportObject)
		supportObject = setSupportObject;

	// Return the current attribute.
	return (supportObject);
}

// ----- ZafComboString ---------------------------------------------------

ZafComboString::ZafComboString(void) :
	ZafString(0, 0, 0, new ZafStringData(ZafLanguageManager::blankString, 128))
{
	SetAutoClear(true);
	SetBordered(false);
	SetRegionType(ZAF_AVAILABLE_REGION);
}

ZafEventType ZafComboString::Event(const ZafEventStruct &event)
{
 	// Switch on the event type.
	ZafEventType ccode = LogicalEvent(event);
	switch (ccode)
	{
	default:
		ccode = ZafString::Event(event);
		break;
	}

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


bool ZafComboString::CopyDraggable(void) const
{
	return (parent ? parent->CopyDraggable() : false);
}

bool ZafComboString::Draggable(void) const
{
	return (parent ? parent->Draggable() : false);
}

bool ZafComboString::LinkDraggable(void) const
{
	return (parent ? parent->LinkDraggable() : false);
}

bool ZafComboString::MoveDraggable(void) const
{
	return (parent ? parent->MoveDraggable() : false);
}

ZafEventType ZafComboString::DragDropEvent(const ZafEventStruct &event)
{
	ZafEventType ccode = S_UNKNOWN;
	if (parent)
		ccode = parent->Event(event);

	return (ccode);
}
