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

#include "m_plldn.hpp"

// ----- ZafPullDownMenu ----------------------------------------------------

#if defined(ZAF_DEFAULT_DRAW)
ZafEventType ZafPullDownMenu::Draw(const ZafEventStruct &, ZafEventType ccode)
{
	// Return the control code.
	return (ccode);
}

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

ZafEventType ZafPullDownMenu::Event(const ZafEventStruct &event)
{
	// Check for zinc events.
	ZafEventType ccode = event.type;
	switch (ccode)
	{
	// ----- Create messages -----
	case S_INITIALIZE:
		// This widget will be in the motif frame, not in the client area.
		ccode = ZafWindow::Event(event);
		break;

	case S_COMPUTE_SIZE:
		// Determine the default size.
		{
		ccode = ZafWindowObject::Event(event);

		// Let motif determine the actual size needed.
		((XmRowColumnRec *)screenID)->row_column.resize_width = true;
		XtWidgetGeometry intended, preferred;
		intended.request_mode = CWWidth;
		intended.width = (Dimension)zafRegion.Width();
		XtQueryGeometry(screenID, &intended, &preferred);
		((XmRowColumnRec *)screenID)->row_column.resize_width = false; // prevent multiple queries.

		// Adjust the size based on Motif's calculation.
		zafRegion.bottom = zafRegion.top + preferred.height - 1;
		}
		break;

	case S_DEINITIALIZE:
	case S_REGISTER_OBJECT:
		ccode = ZafWindow::Event(event);
		break;

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

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

ZafRegionStruct ZafPullDownMenu::MaxRegion(ZafWindowObject *object, ZafVtJustify vWeight, ZafHzJustify hWeight)
{
	// Defer to the base class.
	return (ZafWindow::MaxRegion(object, vWeight, hWeight));
}

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

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

OSWindowID ZafPullDownMenu::OSScreenID(ZafScreenIDType type) const
{
	// Return the client widget.
	if (type == ZAF_SHELLID && screenID)
		return (screenID->core.num_popups ? screenID->core.popup_list[0] : 0);
	return (ZafWindowObject::OSScreenID(type));
}

void ZafPullDownMenu::OSRegisterObject(void)
{
	// Create the Motif widget.
	char *name = zafCodeSet->ConvertToOSString(stringID, 0, false);
	screenID = XtVaCreateManagedWidget(name,
		xmRowColumnWidgetClass, parent->OSScreenID(ZAF_FRAMEID),
		// user information
		XmNuserData, this,
		// miscellaneous
		XmNrowColumnType, XmMENU_BAR,
		0);
}

void ZafPullDownMenu::OSSize(void)
{
	// Defer to the base class.
	ZafWindowObject::OSSize();
}

