xref: /aoo42x/main/extensions/source/scanner/grid.hxx (revision 46dbacee)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _EXTENSIONS_SCANNER_GRID_HXX
24 #define _EXTENSIONS_SCANNER_GRID_HXX
25 
26 #include <vcl/window.hxx>
27 #ifndef _SV_BUTTON_HXX
28 #include <vcl/button.hxx>
29 #endif
30 #include <vcl/lstbox.hxx>
31 #include <vcl/dialog.hxx>
32 
33 class GridWindow : public ModalDialog
34 {
35 	// helper class for handles
36 	struct impHandle
37 	{
38 		Point			maPos;
39 		sal_uInt16		mnOffX;
40 		sal_uInt16		mnOffY;
41 
impHandleGridWindow::impHandle42 		impHandle(const Point& rPos, sal_uInt16 nX, sal_uInt16 nY)
43 		:	maPos(rPos), mnOffX(nX), mnOffY(nY)
44 		{
45 		}
46 
operator <GridWindow::impHandle47 		bool operator<(const impHandle& rComp) const
48 		{
49 			return (maPos.X() < rComp.maPos.X());
50 		}
51 
drawGridWindow::impHandle52 		void draw(Window& rWin, const BitmapEx& rBitmapEx)
53 		{
54 			const Point aOffset(rWin.PixelToLogic(Point(mnOffX, mnOffY)));
55 			rWin.DrawBitmapEx(maPos - aOffset, rBitmapEx);
56 		}
57 
isHitGridWindow::impHandle58 		bool isHit(Window& rWin, const Point& rPos)
59 		{
60 			const Point aOffset(rWin.PixelToLogic(Point(mnOffX, mnOffY)));
61 			const Rectangle aTarget(maPos - aOffset, maPos + aOffset);
62 			return aTarget.IsInside(rPos);
63 		}
64 	};
65 
66 	Rectangle		m_aGridArea;
67 
68 	double 			m_fMinX;
69 	double			m_fMinY;
70 	double			m_fMaxX;
71 	double			m_fMaxY;
72 
73 	double			m_fChunkX;
74 	double			m_fMinChunkX;
75 	double			m_fChunkY;
76 	double			m_fMinChunkY;
77 
78 	double*			m_pXValues;
79 	double*			m_pOrigYValues;
80 	int				m_nValues;
81 	double*			m_pNewYValues;
82 
83 	sal_uInt16		m_BmOffX;
84 	sal_uInt16		m_BmOffY;
85 
86 	sal_Bool			m_bCutValues;
87 
88 	// stuff for handles
89 	std::vector< impHandle >	m_aHandles;
90 	sal_uInt32					m_nDragIndex;
91 
92 	BitmapEx 		m_aMarkerBitmap;
93 
94 	OKButton		m_aOKButton;
95 	CancelButton	m_aCancelButton;
96 
97 	ListBox			m_aResetTypeBox;
98 	PushButton		m_aResetButton;
99 
100 
101 	Point transform( double x, double y );
102 	void transform( const Point& rOriginal, double& x, double& y );
103 
104 	double findMinX();
105 	double findMinY();
106 	double findMaxX();
107 	double findMaxY();
108 
109 	void drawGrid();
110 	void drawOriginal();
111 	void drawNew();
112 	void drawHandles();
113 
114 	void computeExtremes();
115 	void computeChunk( double fMin, double fMax, double& fChunkOut, double& fMinChunkOut );
116 	void computeNew();
117 	double interpolate( double x, double* pNodeX, double* pNodeY, int nNodes );
118 
119 	DECL_LINK( ClickButtonHdl, Button* );
120 
121 	virtual void MouseMove( const MouseEvent& );
122 	virtual void MouseButtonDown( const MouseEvent& );
123 	virtual void MouseButtonUp( const MouseEvent& );
124 public:
125 	GridWindow( double* pXValues, double* pYValues, int nValues,
126 				Window* pParent, sal_Bool bCutValues = sal_True );
127 	~GridWindow();
128 
129 	void setBoundings( double fMinX, double fMinY, double fMaxX, double fMaxY );
getMinX()130 	double getMinX() { return m_fMinX; }
getMinY()131 	double getMinY() { return m_fMinY; }
getMaxX()132 	double getMaxX() { return m_fMaxX; }
getMaxY()133 	double getMaxY() { return m_fMaxY; }
134 
countValues()135 	int countValues() { return m_nValues; }
getXValues()136 	double* getXValues() { return m_pXValues; }
getOrigYValues()137 	double* getOrigYValues() { return m_pOrigYValues; }
getNewYValues()138 	double* getNewYValues() { return m_pNewYValues; }
139 
140 	void drawLine( double x1, double y1, double x2, double y2 );
141 
142 	virtual void Paint( const Rectangle& rRect );
143 };
144 
145 #endif // _EXTENSIONS_SCANNER_GRID_HXX
146