/*
 * $Source: $
 * $Revision: $
 * $Date: $
 * $State: $
 * $Author: $
 *
 *
 * $Log: $
 * Revision 3.1  3/10/92 wade
 *
 * Revision 4.2a3 6/9/94 - edward
 * Removed sysequ.h because it's not one of the universal headers
 */
 
 /*  
 *	Copyright (c) 1991 by the Massachusetts Institute of Technology,
 *	For copying and distribution information, see the file
 *	"mit-copyright.h".
 *
 *  cdef.c  - WADE 7/15/92
 *		This file is a CDEF resource - see Makefile the the resource id.
 *              This custom control resource displays text with no frameRect, 
 *              e.g. a button with no outline.
 *
 *
 */

#ifndef __MWERKS__

#include <Types.h>
#include <QuickDraw.h>
#include <Fonts.h>
#include <Events.h>
#include <Controls.h>
#include <Windows.h>
#include <Menus.h>
#include <TextEdit.h>
#include <Dialogs.h>
#include <Desk.h>
#include <ToolUtils.h>
#include <Memory.h>
#include <SegLoad.h>
#include <Files.h>
#include <OSUtils.h>
#include <Traps.h>
#include <Lists.h>
#include <resources.h>
#include <stdio.h>
#include <String.h>
#include "pips.h"
#include <Utilities.h>

#endif

#include "mit-copyright.h"

pascal long main(short, ControlHandle theControl, short message, long param) 
{ 
	Rect	*cRect;
	long	rc;
	Point	thePoint;
	StringPtr titlestr;
	short	titlewidth;
	
	rc = 0;
	switch(message) {
		case drawCntl:
			HLock((Handle)theControl);
			
			if ((**theControl).contrlVis > 0 ) {
				/* draw control title */
				cRect = &(**theControl).contrlRect;
				titlestr = (**theControl).contrlTitle;
				/* let's cheat to get the length of the string */
				TextBox(titlestr+1, titlestr[0], cRect, teJustLeft);
				
				/* if the control is hilighted, then draw an underline */
				if ((**theControl).contrlValue > 0) {
					titlewidth = StringWidth((**theControl).contrlTitle);
					MoveTo(cRect->left,cRect->bottom - 3);
					PenNormal();
					ForeColor(blueColor);
					LineTo(cRect->left+titlewidth, cRect->bottom - 3);
					ForeColor(blackColor);
				}
			}

			HUnlock((Handle)theControl);
			break;
		case testCntl:
			HLock((Handle)theControl);
			cRect = &(**theControl).contrlRect;
			thePoint.v = HiWord(param);
			thePoint.h = LoWord(param);
			if (PtInRect(thePoint,(Rect*)cRect))
				rc = (**theControl).contrlRfCon;
			HUnlock((Handle)theControl);
			break;
		case calcCRgns:	/* support for pre 7.0 */
			/* we don't expect the control to move or re-size, so this */
			/* message will not be called */
			HLock((Handle)theControl);
			cRect = &(**theControl).contrlRect;
			RectRgn((RgnHandle)param, (Rect*)cRect);
			HUnlock((Handle)theControl);
			break;
		case initCntl:
			/* bad error message, but I hope we don't get this */
			break;
		case dispCntl:
			break;
		case autoTrack:
			break;
		case calcCntlRgn:	/* new in System 7.0 */
			/* we don't expect the control to move or re-size, so this */
			/* message will not be called */
			break;
		case calcThumbRgn:  /* new in System 7.0 */
			break;
	}
	
	return((long)rc);
}

