xref: /trunk/main/extensions/source/scanner/grid.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _EXTENSIONS_SCANNER_GRID_HXX
28 #define _EXTENSIONS_SCANNER_GRID_HXX
29 
30 #include <vcl/window.hxx>
31 #ifndef _SV_BUTTON_HXX
32 #include <vcl/button.hxx>
33 #endif
34 #include <vcl/lstbox.hxx>
35 #include <vcl/dialog.hxx>
36 
37 class GridWindow : public ModalDialog
38 {
39 	// helper class for handles
40 	struct impHandle
41 	{
42 		Point			maPos;
43 		sal_uInt16		mnOffX;
44 		sal_uInt16		mnOffY;
45 
46 		impHandle(const Point& rPos, sal_uInt16 nX, sal_uInt16 nY)
47 		:	maPos(rPos), mnOffX(nX), mnOffY(nY)
48 		{
49 		}
50 
51 		bool operator<(const impHandle& rComp) const
52 		{
53 			return (maPos.X() < rComp.maPos.X());
54 		}
55 
56 		void draw(Window& rWin, const BitmapEx& rBitmapEx)
57 		{
58 			const Point aOffset(rWin.PixelToLogic(Point(mnOffX, mnOffY)));
59 			rWin.DrawBitmapEx(maPos - aOffset, rBitmapEx);
60 		}
61 
62 		bool isHit(Window& rWin, const Point& rPos)
63 		{
64 			const Point aOffset(rWin.PixelToLogic(Point(mnOffX, mnOffY)));
65 			const Rectangle aTarget(maPos - aOffset, maPos + aOffset);
66 			return aTarget.IsInside(rPos);
67 		}
68 	};
69 
70 	Rectangle		m_aGridArea;
71 
72 	double 			m_fMinX;
73 	double			m_fMinY;
74 	double			m_fMaxX;
75 	double			m_fMaxY;
76 
77 	double			m_fChunkX;
78 	double			m_fMinChunkX;
79 	double			m_fChunkY;
80 	double			m_fMinChunkY;
81 
82 	double*			m_pXValues;
83 	double*			m_pOrigYValues;
84 	int				m_nValues;
85 	double*			m_pNewYValues;
86 
87 	sal_uInt16		m_BmOffX;
88 	sal_uInt16		m_BmOffY;
89 
90 	sal_Bool			m_bCutValues;
91 
92 	// stuff for handles
93 	std::vector< impHandle >	m_aHandles;
94 	sal_uInt32					m_nDragIndex;
95 
96 	BitmapEx 		m_aMarkerBitmap;
97 
98 	OKButton		m_aOKButton;
99 	CancelButton	m_aCancelButton;
100 
101 	ListBox			m_aResetTypeBox;
102 	PushButton		m_aResetButton;
103 
104 
105 	Point transform( double x, double y );
106 	void transform( const Point& rOriginal, double& x, double& y );
107 
108 	double findMinX();
109 	double findMinY();
110 	double findMaxX();
111 	double findMaxY();
112 
113 	void drawGrid();
114 	void drawOriginal();
115 	void drawNew();
116 	void drawHandles();
117 
118 	void computeExtremes();
119 	void computeChunk( double fMin, double fMax, double& fChunkOut, double& fMinChunkOut );
120 	void computeNew();
121 	double interpolate( double x, double* pNodeX, double* pNodeY, int nNodes );
122 
123 	DECL_LINK( ClickButtonHdl, Button* );
124 
125 	virtual void MouseMove( const MouseEvent& );
126 	virtual void MouseButtonDown( const MouseEvent& );
127 	virtual void MouseButtonUp( const MouseEvent& );
128 public:
129 	GridWindow( double* pXValues, double* pYValues, int nValues,
130 				Window* pParent, sal_Bool bCutValues = sal_True );
131 	~GridWindow();
132 
133 	void setBoundings( double fMinX, double fMinY, double fMaxX, double fMaxY );
134 	double getMinX() { return m_fMinX; }
135 	double getMinY() { return m_fMinY; }
136 	double getMaxX() { return m_fMaxX; }
137 	double getMaxY() { return m_fMaxY; }
138 
139 	int countValues() { return m_nValues; }
140 	double* getXValues() { return m_pXValues; }
141 	double* getOrigYValues() { return m_pOrigYValues; }
142 	double* getNewYValues() { return m_pNewYValues; }
143 
144 	void drawLine( double x1, double y1, double x2, double y2 );
145 
146 	virtual void Paint( const Rectangle& rRect );
147 };
148 
149 #endif // _EXTENSIONS_SCANNER_GRID_HXX
150