//
// Copyright (c) 2000 by Tech Soft 3D, LLC.
// The information contained herein is confidential and proprietary to
// Tech Soft 3D, LLC., and considered a trade secret as defined under
// civil and criminal statutes.  Tech Soft 3D shall pursue its civil
// and criminal remedies in the event of unauthorized use or misappropriation
// of its trade secrets.  Use of this information by anyone other than
// authorized employees of Tech Soft 3D, LLC. is granted only under a
// written non-disclosure agreement, expressly prescribing the scope and
// manner of such use.
//
// $Header: /files/homes/master/cvs/hoops_master/shared/qt4_common/HQWidget.h,v 1.30 2007-11-08 00:48:18 david Exp $
//


#ifndef HQWIDGET_H
#define HQWIDGET_H


#if defined(IS_OSX) && defined(USE_MDI)
#include <QGLWidget>
#else
#include <QWidget>
#endif

#if defined(ACIS) || defined(PARASOLID)
#include "HSolidModel.h"
#include "HSolidView.h"
#else
#include "HBaseModel.h"
#include "HBaseView.h"
#endif


class HNetClient;

/*!
	The HQWidget class provides a HOOPS-specific implementation of the QWidget object. 	It serves as a base HOOPS/Qt widget 
	class and should be sub-classed to create an application specific derivation.

	HQWidget creates and manages the connection of a HOOPS/3dGS driver instance to a QWidget object.  The custom widget:

	- optimally configures associated windowing system resources, such as X11 Visuals & colormaps or 
	  MS Windows color palettes

	- ensures correct handling of "Paint/Expose" and "Resize" events

	- overrides the QWidget's Mouse and Key events and pass the events to the appropriate HOOPS/MVO View's current Operator methods 
*/
#if defined(IS_OSX) && defined(USE_MDI)
class HQWidget: public QGLWidget
#else
class HQWidget: public QWidget
#endif
{
	Q_OBJECT
public:
	HQWidget( QWidget* parent=0, const char* name=0, Qt::WFlags f=0, HNetClient * net_client=0);
	~HQWidget();

	/*! \return A pointer to the HOOPS/MVO HBaseView object associated with the widget */
	HBaseView* GetHoopsView() { return (HBaseView*) m_pHView; }

	/*! \return A pointer to the HOOPS/MVO HBaseModel object associated with the widget */
	HBaseModel* GetHoopsModel() { return (HBaseModel*) m_pHBaseModel; }

	/*! \return A pointer to the HOOPS/Net HNetClient object associated with the widget */
	HNetClient* GetHNetClient() { return m_pHNetClient; }

	static bool GetKeyState(unsigned int key, int &flags);
    
/*! EMSS function */
    void setViewKey(HC_KEY viewKey);    

protected:

	/*! \return A pointer to the colormap associated with the widget */
	void * GetColorMap();

	/*! \return A pointer to the window id associated with the widget */
	void * GetWindowId();

#if defined(IS_OSX) && defined(USE_MDI)
	/*! \return A pointer to the QGLContext if derived from a QGLWidget (OSX MDI only) */
	void * GetQGLContext();
#endif

	/*! \return A pointer to the clip override structure; currently only applies to OS/X */
	void * GetClipOverride();

	/*! Performs HOOPS/QT specific initialization */
    virtual void Init();	

	/*! return null */
	virtual QPaintEngine* paintEngine() const;

	/*! 
		Overloaded to automatically perform a HOOPS/3dGS update
	*/
	virtual void paintEvent( QPaintEvent* e);

	/*! 
		Overloaded to automatically perform a HOOPS/3dGS update
	*/
	virtual void resizeEvent( QResizeEvent* e);

	virtual void focusInEvent(QFocusEvent* e);

	virtual void focusOutEvent(QFocusEvent* e);

	/*! Adjusts the relative size of the Axis window so that it always has the same size if the outer window is resized */
	void AdjustAxisWindow();

	/*!
		Used to stop events from getting passed to the object
	*/
	bool eventFilter(QObject *obj, QEvent *ev);

#ifdef PARASOLID

	/*! Pointer to the HSolidView object associated with this widget */
	HSolidView * m_pHView;

	/*! Pointer to the HSolidModel object associated with this widget */
	HSolidModel * m_pHBaseModel;
#else
	/*! Pointer to the HBaseView object associated with this widget */
	HBaseView * m_pHView;

	/*! Pointer to the HBaseModel object associated with this widget */
	HBaseModel * m_pHBaseModel;
#endif

	/*! Pointer to the HNetClient object associated with this widget */
	HNetClient * m_pHNetClient;

	bool ignore_update;

private:

	bool initDone;

	void setup_window(bool use_gl);

	unsigned long MapFlags(unsigned long state);

	void * my_colormap;	
	void * my_windowid;
	void * my_clip_override;
	bool my_have_gl_visual;

#if IS_OSX
	int use_clip_override[8];
#if USE_MDI
	void * my_qgl_context;
#endif
#endif

    HC_KEY m_viewKey;

};


#endif 

