xref: /aoo41x/main/sc/source/ui/formdlg/privsplt.cxx (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 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 
32 
33 #include "privsplt.hxx"
34 
35 /*************************************************************************
36 #*	Member:		ScPrivatSplit								Datum:13.10.97
37 #*------------------------------------------------------------------------
38 #*
39 #*  Klasse:		MD_Test
40 #*
41 #*  Funktion:	Konstruktor der Klasse ScPrivatSplit
42 #*
43 #*  Input:		---
44 #*
45 #*	Output:		---
46 #*
47 #************************************************************************/
48 
49 ScPrivatSplit::ScPrivatSplit( Window* pParent, const ResId& rResId,
50 							 SC_SPLIT_DIRECTION eSplit):
51 						Control( pParent, rResId )
52 {
53 	Point aPos=GetPosPixel();
54 	nOldX=(short)aPos.X();
55 	nOldY=(short)aPos.Y();
56 	nNewX=(short)aPos.X();
57 	nNewY=(short)aPos.Y();
58 	eScSplit=eSplit;
59 	aXMovingRange.Min()=nNewX;
60 	aXMovingRange.Max()=nNewX;
61 	aYMovingRange.Min()=nNewY;
62 	aYMovingRange.Max()=nNewY;
63 
64 	aWinPointer=GetPointer();
65 
66 	aMovingFlag=sal_False;
67 	if(eScSplit==SC_SPLIT_HORZ)
68 	{
69 		aWinPointer=Pointer(POINTER_HSPLIT);
70 	}
71 	else
72 	{
73 		aWinPointer=Pointer(POINTER_VSPLIT);
74 	}
75 	SetPointer(aWinPointer);
76 }
77 
78 
79 /*************************************************************************
80 #*	Member:		MouseButtonDown							Datum:13.10.97
81 #*------------------------------------------------------------------------
82 #*
83 #*  Klasse:		ScPrivatSplit
84 #*
85 #*  Funktion:	Reagiert auf einen einzelnen Mouse-Event. Nach Aufruf
86 #*				werden alle Mauseingaben an dieses Control weitergeleitet.
87 #*
88 #*  Input:		---
89 #*
90 #*	Output:		---
91 #*
92 #************************************************************************/
93 
94 void ScPrivatSplit::MouseButtonDown( const MouseEvent& rMEvt )
95 {
96 	Point aPos=LogicToPixel(rMEvt.GetPosPixel());
97 
98 	nOldX=(short)aPos.X();
99 	nOldY=(short)aPos.Y();
100 
101 	CaptureMouse();
102 }
103 
104 /*************************************************************************
105 #*	Member:		MouseButtonUp							Datum:13.10.97
106 #*------------------------------------------------------------------------
107 #*
108 #*  Klasse:		ScPrivatSplit
109 #*
110 #*  Funktion:	Ende einer Benutzeraktion mit der Maus. Es werden
111 #*				die aktuelle Maus- Koordinaten ermittelt und fuer
112 #*				die Verschiebung des Fensters verwendet.
113 #*
114 #*  Input:		---
115 #*
116 #*	Output:		---
117 #*
118 #************************************************************************/
119 
120 void ScPrivatSplit::MouseButtonUp( const MouseEvent& rMEvt )
121 {
122 	ReleaseMouse();
123 
124 	Point aPos=LogicToPixel(rMEvt.GetPosPixel());
125 	Point a2Pos=GetPosPixel();
126 	Point a3Pos=a2Pos;
127 
128 	if(eScSplit==SC_SPLIT_HORZ)
129 	{
130 		nNewX=(short)aPos.X();
131 		nDeltaX=nNewX-nOldX;
132 		a2Pos.X()+=nDeltaX;
133 		if(a2Pos.X()<aXMovingRange.Min())
134 		{
135 			nDeltaX=(short)(aXMovingRange.Min()-a3Pos.X());
136 			a2Pos.X()=aXMovingRange.Min();
137 		}
138 		else if(a2Pos.X()>aXMovingRange.Max())
139 		{
140 			nDeltaX=(short)(aXMovingRange.Max()-a3Pos.X());
141 			a2Pos.X()=aXMovingRange.Max();
142 		}
143 	}
144 	else
145 	{
146 		nNewY=(short)aPos.Y();
147 		nDeltaY=nNewY-nOldY;
148 		a2Pos.Y()+=nDeltaY;
149 		if(a2Pos.Y()<aYMovingRange.Min())
150 		{
151 			nDeltaY=(short)(aYMovingRange.Min()-a3Pos.Y());
152 			a2Pos.Y()=aYMovingRange.Min();
153 		}
154 		else if(a2Pos.Y()>aYMovingRange.Max())
155 		{
156 			nDeltaY=(short)(aYMovingRange.Max()-a3Pos.Y());
157 			a2Pos.Y()=aYMovingRange.Max();
158 		}
159 	}
160 	SetPosPixel(a2Pos);
161 	Invalidate();
162 	Update();
163 	CtrModified();
164 }
165 
166 /*************************************************************************
167 #*	Member:		MouseMove									Datum:13.10.97
168 #*------------------------------------------------------------------------
169 #*
170 #*  Klasse:		ScPrivatSplit
171 #*
172 #*  Funktion:	Reagiert kontinuierlich auf Mausbewegungen. Es werden
173 #*				die aktuelle Maus- Koordinaten ermittelt und fuer
174 #*				die Verschiebung des Fensters verwendet.
175 #*
176 #*  Input:		---
177 #*
178 #*	Output:		---
179 #*
180 #************************************************************************/
181 
182 void ScPrivatSplit::MouseMove( const MouseEvent& rMEvt )
183 {
184 	Point aPos=LogicToPixel(rMEvt.GetPosPixel());
185 	Point a2Pos=GetPosPixel();
186 	Point a3Pos=a2Pos;
187 	if(rMEvt.IsLeft())
188 	{
189 		if(eScSplit==SC_SPLIT_HORZ)
190 		{
191 			nNewX=(short)aPos.X();
192 			nDeltaX=nNewX-nOldX;
193 			a2Pos.X()+=nDeltaX;
194 
195 			if(a2Pos.X()<aXMovingRange.Min())
196 			{
197 				nDeltaX=(short)(aXMovingRange.Min()-a3Pos.X());
198 				a2Pos.X()=aXMovingRange.Min();
199 			}
200 			else if(a2Pos.X()>aXMovingRange.Max())
201 			{
202 				nDeltaX=(short)(aXMovingRange.Max()-a3Pos.X());
203 				a2Pos.X()=aXMovingRange.Max();
204 			}
205 		}
206 		else
207 		{
208 			nNewY=(short)aPos.Y();
209 			nDeltaY=nNewY-nOldY;
210 			a2Pos.Y()+=nDeltaY;
211 			if(a2Pos.Y()<aYMovingRange.Min())
212 			{
213 				nDeltaY=(short)(aYMovingRange.Min()-a3Pos.Y());
214 				a2Pos.Y()=aYMovingRange.Min();
215 			}
216 			else if(a2Pos.Y()>aYMovingRange.Max())
217 			{
218 				nDeltaY=(short)(aYMovingRange.Max()-a3Pos.Y());
219 				a2Pos.Y()=aYMovingRange.Max();
220 			}
221 		}
222 
223 		SetPosPixel(a2Pos);
224 
225 		CtrModified();
226 		Invalidate();
227 		Update();
228 	}
229 }
230 
231 /*************************************************************************
232 #*	Member:		SetYRange									Datum:14.10.97
233 #*------------------------------------------------------------------------
234 #*
235 #*  Klasse:		ScPrivatSplit
236 #*
237 #*  Funktion:	Setzt den Range fuer die Y- Verschiebung
238 #*
239 #*  Input:		neuer Bereich
240 #*
241 #*	Output:		---
242 #*
243 #************************************************************************/
244 void ScPrivatSplit::SetYRange(Range cRgeY)
245 {
246 	aYMovingRange=cRgeY;
247 }
248 
249 
250 
251 /*************************************************************************
252 #*	Member:		GetDeltaY									Datum:13.10.97
253 #*------------------------------------------------------------------------
254 #*
255 #*  Klasse:		ScPrivatSplit
256 #*
257 #*  Funktion:	Liefert die relative x-Verschiebung zurueck
258 #*
259 #*  Input:		---
260 #*
261 #*	Output:		---
262 #*
263 #************************************************************************/
264 short ScPrivatSplit::GetDeltaX()
265 {
266 	return nDeltaX;
267 }
268 
269 /*************************************************************************
270 #*	Member:		GetDeltaY									Datum:13.10.97
271 #*------------------------------------------------------------------------
272 #*
273 #*  Klasse:		ScPrivatSplit
274 #*
275 #*  Funktion:	Liefert die relative y-Verschiebung zurueck
276 #*
277 #*  Input:		---
278 #*
279 #*	Output:		---
280 #*
281 #************************************************************************/
282 short ScPrivatSplit::GetDeltaY()
283 {
284 	return nDeltaY;
285 }
286 
287 /*************************************************************************
288 #*	Member:		CtrModified									Datum:13.10.97
289 #*------------------------------------------------------------------------
290 #*
291 #*  Klasse:		ScPrivatSplit
292 #*
293 #*  Funktion:	Teilt einem installierten Handler mit, dass
294 #*				eine Veraenderung eingetreten ist.
295 #*
296 #*  Input:		---
297 #*
298 #*	Output:		---
299 #*
300 #************************************************************************/
301 void ScPrivatSplit::CtrModified()
302 {
303 	aCtrModifiedLink.Call( this );
304 }
305 
306 void ScPrivatSplit::MoveSplitTo(Point aPos)
307 {
308 	Point a2Pos=GetPosPixel();
309 	nOldX=(short)a2Pos.X();
310 	nOldY=(short)a2Pos.Y();
311 	Point a3Pos=a2Pos;
312 
313 	if(eScSplit==SC_SPLIT_HORZ)
314 	{
315 		nNewX=(short)aPos.X();
316 		nDeltaX=nNewX-nOldX;
317 		a2Pos.X()+=nDeltaX;
318 		if(a2Pos.X()<aXMovingRange.Min())
319 		{
320 			nDeltaX=(short)(aXMovingRange.Min()-a3Pos.X());
321 			a2Pos.X()=aXMovingRange.Min();
322 		}
323 		else if(a2Pos.X()>aXMovingRange.Max())
324 		{
325 			nDeltaX=(short)(aXMovingRange.Max()-a3Pos.X());
326 			a2Pos.X()=aXMovingRange.Max();
327 		}
328 	}
329 	else
330 	{
331 		nNewY=(short)aPos.Y();
332 		nDeltaY=nNewY-nOldY;
333 		a2Pos.Y()+=nDeltaY;
334 		if(a2Pos.Y()<aYMovingRange.Min())
335 		{
336 			nDeltaY=(short)(aYMovingRange.Min()-a3Pos.Y());
337 			a2Pos.Y()=aYMovingRange.Min();
338 		}
339 		else if(a2Pos.Y()>aYMovingRange.Max())
340 		{
341 			nDeltaY=(short)(aYMovingRange.Max()-a3Pos.Y());
342 			a2Pos.Y()=aYMovingRange.Max();
343 		}
344 	}
345 	SetPosPixel(a2Pos);
346 	Invalidate();
347 	Update();
348 	CtrModified();
349 }
350 
351 
352 void ScPrivatSplit::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
353 {
354 	const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
355 
356 	if ( bFont )
357 	{
358 		Font aFont = rStyleSettings.GetAppFont();
359 		if ( IsControlFont() )
360 			aFont.Merge( GetControlFont() );
361 		SetFont( aFont );
362 	}
363 
364 	if ( bFont || bForeground )
365 	{
366 		Color aTextColor = rStyleSettings.GetButtonTextColor();
367 		if ( IsControlForeground() )
368 			aTextColor = GetControlForeground();
369 		SetTextColor( aTextColor );
370 	}
371 
372 	if ( bBackground )
373 	{
374 		SetBackground( rStyleSettings.GetFaceColor());
375 	}
376 	if ( IsBackground() )
377 	{
378 		SetFillColor( GetBackground().GetColor() );
379 		SetBackground();
380 	}
381 	Invalidate();
382 }
383 
384 // -----------------------------------------------------------------------
385 
386 void ScPrivatSplit::StateChanged( StateChangedType nType )
387 {
388 	if ( (nType == STATE_CHANGE_ZOOM) ||
389 		 (nType == STATE_CHANGE_CONTROLFONT) )
390 	{
391 		ImplInitSettings( sal_True, sal_False, sal_False );
392 		Invalidate();
393 	}
394 	if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
395 	{
396 		ImplInitSettings( sal_False, sal_True, sal_False );
397 		Invalidate();
398 	}
399 	else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
400 	{
401 		ImplInitSettings( sal_False, sal_False, sal_True );
402 		Invalidate();
403 	}
404 
405 	Control::StateChanged( nType );
406 }
407 
408 // -----------------------------------------------------------------------
409 
410 void ScPrivatSplit::DataChanged( const DataChangedEvent& rDCEvt )
411 {
412 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
413 		 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
414 	{
415 		ImplInitSettings( sal_True, sal_True, sal_True );
416 		Invalidate();
417 	}
418 	else
419 		Window::DataChanged( rDCEvt );
420 }
421 
422 
423