/*********************************************************************************
 JX2DPlotWidget.h

	Interface for the JX2DPlotWidget class.

	Copyright @ 1997 by Glenn W. Bach. All rights reserved.

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

#ifndef _H_JX2DPlotWidget
#define _H_JX2DPlotWidget

#include <JXWidget.h>
#include <J2DPlotWidget.h>

class JXPSPrinter;
class JXTextMenu;
class JXMenuBar;
class JXFontNameMenu;
class JXFontSizeMenu;
class JXPlotLabelDialog;
class JXPlotScaleDialog;
class JXPlotRangeDialog;
class JXCurveOptionsDialog;
class JXCursorMarkTableDir;

class JX2DPlotWidget : public JXWidget, public J2DPlotWidget
{
public:

	JX2DPlotWidget(JXMenuBar* menuBar, JXContainer* enclosure,
				   const HSizingOption hSizing, const VSizingOption vSizing,
				   const JCoordinate x, const JCoordinate y,
				   const JCoordinate w, const JCoordinate h);

	virtual ~JX2DPlotWidget();

	void			SetPSPrinter(JXPSPrinter* p);
	const JString&	GetPSPrintFileName() const;
	void			SetPSPrintFileName(const JCharacter* fileName);
	void			HandlePSPageSetup();
	void			PrintPS();

	virtual void 	HandleKeyPress(const int key, const JXKeyModifiers& modifiers);

	void	PWXReadSetup(istream& input);
	void	PWXWriteSetup(ostream& output) const;

protected:

	virtual void	Draw(JXWindowPainter& p, const JRect& rect);
	virtual void	DrawBorder(JXWindowPainter& p, const JRect& frame);
	virtual void	BoundsResized(const JCoordinate dw, const JCoordinate dh);

	virtual JBoolean	PrintMarks(JPagePrinter& p, const JBoolean putOnSamePage,
									const JRect& partialPageRect);

	virtual void	HandleMouseDown(const JPoint& pt, const JXMouseButton button,
									const JSize clickCount,
									const JXButtonStates& buttonStates,
									const JXKeyModifiers& modifiers);
	virtual void	HandleMouseDrag(const JPoint& pt, const JXButtonStates& buttonStates,
									const JXKeyModifiers& modifiers);
	virtual void	HandleMouseUp(const JPoint& pt, const JXMouseButton button,
								  const JXButtonStates& buttonStates,
								  const JXKeyModifiers& modifiers);
	virtual void	AdjustCursor(const JPoint& pt, const JXKeyModifiers& modifiers);

	virtual JSize	PWGetGUIWidth() const;
	virtual JSize	PWGetGUIHeight() const;

	virtual JPainter*	PWCreateDragInsidePainter();
	virtual JPainter*	PWGetDragPainter();
	virtual void		PWDeleteDragPainter();

	virtual void 	PWRefreshRect(const JRect& rect);
	virtual void	PWRedraw();
	virtual void 	PWRedrawRect(const JRect& rect);
	virtual void 	PWForceRefresh();
	virtual void	PWRefreshUpdate();
	virtual void	PWDisplayCursor(const MouseCursor cursor);

	virtual void	ProtectionChanged();
	virtual void	ChangeCurveOptions(const JIndex index);
	virtual void 	ChangeLabels(const LabelSelection selection);
	virtual void	ChangeScale(const JBoolean xAxis);

	virtual void	Receive(JBroadcaster* sender, const Message& message);

	JXTextMenu*		GetCursorMenu();

private:

	JXTextMenu* 			itsOptionsMenu;
	JXTextMenu*				itsRemoveCurveMenu;
	JXTextMenu*				itsCursorMenu;
	JXTextMenu*				itsMarkMenu;
	JXPlotLabelDialog* 		itsPlotLabelDialog;
	JXPlotScaleDialog*		itsPlotScaleDialog;
	JXPlotRangeDialog*		itsPlotRangeDialog;
	JXCurveOptionsDialog*	itsCurveOptionsDialog;
	JIndex					itsCurrentCurve;
	JPoint					itsStartPt;
	JPoint					itsPrevPt;
	JXCursorMarkTableDir*	itsMarkDir;
	JCursorIndex			itsDragXCursor;
	JCursorIndex			itsDragYCursor;

	JXPSPrinter*	itsPSPrinter;		// not owned; can be NULL
	JString			itsPSPrintName;		// file name when printing to a file

private:

	void HandleOptionsMenu(const JIndex index);
	void UpdateOptionsMenu();

	void HandleCurvesMenu(const JIndex index);
	void UpdateCurvesMenu();

	void HandleRemoveCurveMenu(const JIndex index);
	void UpdateRemoveCurveMenu();

	void UpdateCursorMenu();
	void HandleCursorMenu(const JIndex index);

	void UpdateMarkMenu();
	void HandleMarkMenu(const JIndex index);

	void GetNewLabels();

	void ChangeScale();
	void GetNewScale();

	void ChangeRange();
	void GetNewRange();

	void ChangeCurveOptions();
	void GetNewCurveOptions();

};

/******************************************************************************
 GetCursorMenu

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

inline JXTextMenu*
JX2DPlotWidget::GetCursorMenu()
{
	return itsCursorMenu;
}

/******************************************************************************
 GetPSPrintFileName

	Call this to get the file name used in the Print Setup dialog.

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

inline const JString&
JX2DPlotWidget::GetPSPrintFileName()
	const
{
	return itsPSPrintName;
}

/******************************************************************************
 SetPSPrintFileName

	Call this to set the file name used in the Print Setup dialog.

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

inline void
JX2DPlotWidget::SetPSPrintFileName
	(
	const JCharacter* fileName
	)
{
	itsPSPrintName = fileName;
}

#endif
