/*	XGControl.cpp
 *
 *		The implementation of the abstract class 'XGControl'
 */

/**********************************************************************

  YAAF is Copyright 1997-1999 by William Woody.

  Redistribution and use in source and binary forms, with or without 
  modification, are permitted provided that the following conditions 
  are met:

  Redistributions of source code must retain the above copyright notice, 
  this list of conditions and the following disclaimer.

  Neither the name of the copyright holder or other contributors may
  be used to promote products derived from this software without
  specific written prior permission.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
  SOFTWARE.
  
  Contact:   woody@alumni.caltech.edu
  Web page:  http://www.pandawave.com/yaaf/

**********************************************************************/

#include <XConfig.h>			// must be first to optimize compile on MSVC++
#include <XControls.h>
#include <XWindow.h>

/************************************************************************/
/*																		*/
/*	Construction/Destruction											*/
/*																		*/
/************************************************************************/

/*$	XGControl::XGControl
 *
 *		Default constructor
 */

XGControl::XGControl(XGView *view, XGSViewInitRecord &s) : XGView(view,s)
{
}

/*$	XGControl::XGControl
 *
 *		Default constructor
 */

XGControl::XGControl(XGView *view, XGArgStream &s) : XGView(view,s)
{
}

/*$	XGControl::~XGControl
 *
 *		Delete me
 */

XGControl::~XGControl()
{
}

/************************************************************************/
/*																		*/
/*	Basic control support												*/
/*																		*/
/************************************************************************/

#if OPT_MACOS

/*$	XGControl::StripAmperstand
 *
 *		Macintosh controls do not show the amperstand. But for controls
 *	which defer to the built-in controls, I have to strip amperstands out
 */

char *XGControl::StripAmperstand(char *out, const char *in)
{
	char *a;
	const char *b;
	
	a = out;
	b = in;
	while (*b != 0) {
		if ((*b == '&') && (b[1] != 0)) b++;
		*a++ = *b++;
	}
	*a = 0;
	return out;
}

#endif

#if OPT_WINOS

/*$	XGControl::SetControlFocus
 *
 *		Set the focus of this control. This overrides the stuff inside
 *	of the view to 'do the right thing'. In particular, this does not
 *	set the focus in Microsoft Windows to the window containing this view,
 *	as I assume that if I'm calling this routine, I have a window I'm
 *	managing myself.
 */

void XGControl::SetControlFocus(HWND wptr)
{
	XGWindow *w;
	
	XGDispatch::SetFocus();
	
	w = GetWindow();
	if (w) w->fFocus = this;

	/*
	 *  Set the focus to either my control or the root, if the control
	 *	doesn't exist.
	 */
	 	
	if (XGWindow::GetFrontWindow() == GetWindow()) {
		if (wptr == NULL) ::SetFocus(GetRootWindow());
		else ::SetFocus(wptr);
	}
}

#endif
