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