/*====START_GENERATED_PROLOG======================================
 */
/*
 *   COMPONENT_NAME: odpubutils
 *
 *   CLASSES:   CFocus
 *		CFocusWindow
 *
 *   ORIGINS: 82,27,94
 *
 *
 *   (C) COPYRIGHT International Business Machines Corp. 1995,1996
 *   All Rights Reserved
 *   Licensed Materials - Property of IBM
 *   US Government Users Restricted Rights - Use, duplication or
 *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 *   	
 *   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 *   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 *   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
 *   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
 *   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
 *   OR PERFORMANCE OF THIS SOFTWARE.
 */
/*====END_GENERATED_PROLOG========================================
 */
// @(#) 1.7 nt/src/pubutils/include/FocusLib.h, odpubutils, od96nt, odnt9712d 3/14/97 17:04:21 [ 3/21/97 17:20:02 ]
#ifdef _PLATFORM_WIN32_
// We have a new implementation of CFocus for Win32
/*
	File:		FocusLib.h

	Contains:	Library routines for focusing (setting up for drawing into a facet)

	Owned by:	Jens Alfke

	Copyright:	(C) 1993 - 1995 by Apple Computer, Inc., all rights reserved.
		 
		 
	THEORY OF OPERATION:
	
		FocusLib sets up the drawing environment for a QuickDraw-based part so that
		it can start drawing into a facet. It provides both a one-time change of
		focus (via the Focus call) and a way to set the focus but restore it later
		when the current scope exits (via the CFocus object.)
		
		Focus() and FocusWindow() are slightly different for offscreen facets. If the
		facet is in an offscreen canvas, Focus will set up to draw into that canvas;
		this is what one usually wants to do. On the other hand, FocusWindow will
		always focus onto an on-screen canvas, even for an off-screen facet. Use
		FocusWindow for things like rubber-banding where your drawing needs to show
		up immediately, even if the facet is offscreen.

		The CFocus object deserves an example:
		
		void DrawSomething( ODFacet *facet )
		{
			CFocus f(facet);		// Creates a CFocus object on the stack, which
									// changes the focus but stores the old state
			....drawing code...
		}
		
		Declaring the CFocus object calls its constructor, which sets the focus and
		stores the old state in the CFocus object itself (on the stack.) When its
		scope exists, the CFocus object's destructor is called, which restores the
		old focus.
		
		CFocus inherits from Destructo (see Except.h) so it will now be destructed
		properly if an exception is thrown while it's active. You no longer need to
		catch the exception and manually destruct the CFocus.
*/


#ifndef _FOCUSLIB_
#define _FOCUSLIB_

#ifndef _ODTYPES_
#include <ODTypes.h>
#endif

#ifdef __cplusplus
	class ODCanvas;
	class ODShape;
	class ODFacet;
	struct Environment;
#else
	#ifndef som_h
	#include <som.h>
	#endif
	#ifndef SOM_ODCanvas_h
	#include <Canvas.h>
	#endif
	#ifndef SOM_ODShape_h
	#include <Shape.h>
	#endif
	#ifndef SOM_ODFacet_h
	#include <Facet.h>
	#endif
#endif

#ifndef _ODMVCLNK_
#include <ODMvcLnk.h>
#endif

/*	FocusState stores the state data for QD focusing.
	C users should allocate one on the stack and call BeginFocus and
	EndFocus (q.v.) to do the focusing.
	C++ users should ignore FocusState and simply allocate a CFocus object
	(see below).
*/



#define kCFocusID "appl:cfocus$class"

struct FocusState
{
// Flag indicating whether we're drawing to a window or a canvas
   ODBoolean       fToWindow;
// The facet we're working on
   ODFacet        *fFacet;
// The HDC
   HDC             fHDC;
// If we're toWindow, the HWND
   HWND            fHWnd;
// For restoring DC state
   int             fOldMapMode;
   POINT           fOldWinOrg;
   SIZE            fOldVPExtent;
   SIZE            fOldWinExtent;
   int             fSaveDC;
   HRGN            fOldClip;
   ODShape        *fclipShape;

#ifdef __cplusplus
  _DLLIMPORTEXPORT_ void BeginFocus( ODFacet *facet, ODShape* invalShape, ODBoolean toWindow );
  _DLLIMPORTEXPORT_ void EndFocus( );
#endif
};

/*	CFocus is a class for C++ users. Just allocate one as a local variable:
	the constructor will focus, and the destructor (called when it goes out
	of scope or an exception is thrown) will unfocus.
	CFocusWindow is just like CFocus, but focuses to the window instead of
	the facet's canvas (if they're different.)
*/
class CFocus {
  public:
    _DLLIMPORTEXPORT_ CFocus( ODFacet *facet, ODShape* invalShape, HDC *theHDC );
    _DLLIMPORTEXPORT_ virtual ~CFocus( );


  protected:
    CFocus( )	{ }
        
    FocusState f;
};

class CFocusWindow :public CFocus {
  public:
    _DLLIMPORTEXPORT_ CFocusWindow( ODFacet *facet, ODShape* invalShape, HDC *theHDC, HWND *theHWnd );
};



#ifdef __cplusplus
extern "C" {
#endif

// For C only:
  _DLLIMPORTEXPORT_ void BeginFocus( FocusState *foc, ODFacet *facet, ODShape* invalShape, HDC *theHDC);

_DLLIMPORTEXPORT_ void EndFocus( FocusState* );

#ifdef __cplusplus
}
#endif

#endif //_FOCUSLIB_

#endif // WIN32/OS2
