merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / formdlg / privsplt.cxx
blobc419c211491281fbbeaac96ccabe58884cd4fcca
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: privsplt.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 #include "privsplt.hxx"
38 /*************************************************************************
39 #* Member: ScPrivatSplit Datum:13.10.97
40 #*------------------------------------------------------------------------
42 #* Klasse: MD_Test
44 #* Funktion: Konstruktor der Klasse ScPrivatSplit
46 #* Input: ---
48 #* Output: ---
50 #************************************************************************/
52 ScPrivatSplit::ScPrivatSplit( Window* pParent, const ResId& rResId,
53 SC_SPLIT_DIRECTION eSplit):
54 Control( pParent, rResId )
56 Point aPos=GetPosPixel();
57 nOldX=(short)aPos.X();
58 nOldY=(short)aPos.Y();
59 nNewX=(short)aPos.X();
60 nNewY=(short)aPos.Y();
61 eScSplit=eSplit;
62 aXMovingRange.Min()=nNewX;
63 aXMovingRange.Max()=nNewX;
64 aYMovingRange.Min()=nNewY;
65 aYMovingRange.Max()=nNewY;
67 aWinPointer=GetPointer();
69 aMovingFlag=FALSE;
70 if(eScSplit==SC_SPLIT_HORZ)
72 aWinPointer=Pointer(POINTER_HSPLIT);
74 else
76 aWinPointer=Pointer(POINTER_VSPLIT);
78 SetPointer(aWinPointer);
82 /*************************************************************************
83 #* Member: MouseButtonDown Datum:13.10.97
84 #*------------------------------------------------------------------------
86 #* Klasse: ScPrivatSplit
88 #* Funktion: Reagiert auf einen einzelnen Mouse-Event. Nach Aufruf
89 #* werden alle Mauseingaben an dieses Control weitergeleitet.
91 #* Input: ---
93 #* Output: ---
95 #************************************************************************/
97 void ScPrivatSplit::MouseButtonDown( const MouseEvent& rMEvt )
99 Point aPos=LogicToPixel(rMEvt.GetPosPixel());
101 nOldX=(short)aPos.X();
102 nOldY=(short)aPos.Y();
104 CaptureMouse();
107 /*************************************************************************
108 #* Member: MouseButtonUp Datum:13.10.97
109 #*------------------------------------------------------------------------
111 #* Klasse: ScPrivatSplit
113 #* Funktion: Ende einer Benutzeraktion mit der Maus. Es werden
114 #* die aktuelle Maus- Koordinaten ermittelt und fuer
115 #* die Verschiebung des Fensters verwendet.
117 #* Input: ---
119 #* Output: ---
121 #************************************************************************/
123 void ScPrivatSplit::MouseButtonUp( const MouseEvent& rMEvt )
125 ReleaseMouse();
127 Point aPos=LogicToPixel(rMEvt.GetPosPixel());
128 Point a2Pos=GetPosPixel();
129 Point a3Pos=a2Pos;
131 if(eScSplit==SC_SPLIT_HORZ)
133 nNewX=(short)aPos.X();
134 nDeltaX=nNewX-nOldX;
135 a2Pos.X()+=nDeltaX;
136 if(a2Pos.X()<aXMovingRange.Min())
138 nDeltaX=(short)(aXMovingRange.Min()-a3Pos.X());
139 a2Pos.X()=aXMovingRange.Min();
141 else if(a2Pos.X()>aXMovingRange.Max())
143 nDeltaX=(short)(aXMovingRange.Max()-a3Pos.X());
144 a2Pos.X()=aXMovingRange.Max();
147 else
149 nNewY=(short)aPos.Y();
150 nDeltaY=nNewY-nOldY;
151 a2Pos.Y()+=nDeltaY;
152 if(a2Pos.Y()<aYMovingRange.Min())
154 nDeltaY=(short)(aYMovingRange.Min()-a3Pos.Y());
155 a2Pos.Y()=aYMovingRange.Min();
157 else if(a2Pos.Y()>aYMovingRange.Max())
159 nDeltaY=(short)(aYMovingRange.Max()-a3Pos.Y());
160 a2Pos.Y()=aYMovingRange.Max();
163 SetPosPixel(a2Pos);
164 Invalidate();
165 Update();
166 CtrModified();
169 /*************************************************************************
170 #* Member: MouseMove Datum:13.10.97
171 #*------------------------------------------------------------------------
173 #* Klasse: ScPrivatSplit
175 #* Funktion: Reagiert kontinuierlich auf Mausbewegungen. Es werden
176 #* die aktuelle Maus- Koordinaten ermittelt und fuer
177 #* die Verschiebung des Fensters verwendet.
179 #* Input: ---
181 #* Output: ---
183 #************************************************************************/
185 void ScPrivatSplit::MouseMove( const MouseEvent& rMEvt )
187 Point aPos=LogicToPixel(rMEvt.GetPosPixel());
188 Point a2Pos=GetPosPixel();
189 Point a3Pos=a2Pos;
190 if(rMEvt.IsLeft())
192 if(eScSplit==SC_SPLIT_HORZ)
194 nNewX=(short)aPos.X();
195 nDeltaX=nNewX-nOldX;
196 a2Pos.X()+=nDeltaX;
198 if(a2Pos.X()<aXMovingRange.Min())
200 nDeltaX=(short)(aXMovingRange.Min()-a3Pos.X());
201 a2Pos.X()=aXMovingRange.Min();
203 else if(a2Pos.X()>aXMovingRange.Max())
205 nDeltaX=(short)(aXMovingRange.Max()-a3Pos.X());
206 a2Pos.X()=aXMovingRange.Max();
209 else
211 nNewY=(short)aPos.Y();
212 nDeltaY=nNewY-nOldY;
213 a2Pos.Y()+=nDeltaY;
214 if(a2Pos.Y()<aYMovingRange.Min())
216 nDeltaY=(short)(aYMovingRange.Min()-a3Pos.Y());
217 a2Pos.Y()=aYMovingRange.Min();
219 else if(a2Pos.Y()>aYMovingRange.Max())
221 nDeltaY=(short)(aYMovingRange.Max()-a3Pos.Y());
222 a2Pos.Y()=aYMovingRange.Max();
226 SetPosPixel(a2Pos);
228 CtrModified();
229 Invalidate();
230 Update();
234 /*************************************************************************
235 #* Member: SetYRange Datum:14.10.97
236 #*------------------------------------------------------------------------
238 #* Klasse: ScPrivatSplit
240 #* Funktion: Setzt den Range fuer die Y- Verschiebung
242 #* Input: neuer Bereich
244 #* Output: ---
246 #************************************************************************/
247 void ScPrivatSplit::SetYRange(Range cRgeY)
249 aYMovingRange=cRgeY;
254 /*************************************************************************
255 #* Member: GetDeltaY Datum:13.10.97
256 #*------------------------------------------------------------------------
258 #* Klasse: ScPrivatSplit
260 #* Funktion: Liefert die relative x-Verschiebung zurueck
262 #* Input: ---
264 #* Output: ---
266 #************************************************************************/
267 short ScPrivatSplit::GetDeltaX()
269 return nDeltaX;
272 /*************************************************************************
273 #* Member: GetDeltaY Datum:13.10.97
274 #*------------------------------------------------------------------------
276 #* Klasse: ScPrivatSplit
278 #* Funktion: Liefert die relative y-Verschiebung zurueck
280 #* Input: ---
282 #* Output: ---
284 #************************************************************************/
285 short ScPrivatSplit::GetDeltaY()
287 return nDeltaY;
290 /*************************************************************************
291 #* Member: CtrModified Datum:13.10.97
292 #*------------------------------------------------------------------------
294 #* Klasse: ScPrivatSplit
296 #* Funktion: Teilt einem installierten Handler mit, dass
297 #* eine Veraenderung eingetreten ist.
299 #* Input: ---
301 #* Output: ---
303 #************************************************************************/
304 void ScPrivatSplit::CtrModified()
306 aCtrModifiedLink.Call( this );
309 void ScPrivatSplit::MoveSplitTo(Point aPos)
311 Point a2Pos=GetPosPixel();
312 nOldX=(short)a2Pos.X();
313 nOldY=(short)a2Pos.Y();
314 Point a3Pos=a2Pos;
316 if(eScSplit==SC_SPLIT_HORZ)
318 nNewX=(short)aPos.X();
319 nDeltaX=nNewX-nOldX;
320 a2Pos.X()+=nDeltaX;
321 if(a2Pos.X()<aXMovingRange.Min())
323 nDeltaX=(short)(aXMovingRange.Min()-a3Pos.X());
324 a2Pos.X()=aXMovingRange.Min();
326 else if(a2Pos.X()>aXMovingRange.Max())
328 nDeltaX=(short)(aXMovingRange.Max()-a3Pos.X());
329 a2Pos.X()=aXMovingRange.Max();
332 else
334 nNewY=(short)aPos.Y();
335 nDeltaY=nNewY-nOldY;
336 a2Pos.Y()+=nDeltaY;
337 if(a2Pos.Y()<aYMovingRange.Min())
339 nDeltaY=(short)(aYMovingRange.Min()-a3Pos.Y());
340 a2Pos.Y()=aYMovingRange.Min();
342 else if(a2Pos.Y()>aYMovingRange.Max())
344 nDeltaY=(short)(aYMovingRange.Max()-a3Pos.Y());
345 a2Pos.Y()=aYMovingRange.Max();
348 SetPosPixel(a2Pos);
349 Invalidate();
350 Update();
351 CtrModified();
355 void ScPrivatSplit::ImplInitSettings( BOOL bFont, BOOL bForeground, BOOL bBackground )
357 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
359 if ( bFont )
361 Font aFont = rStyleSettings.GetAppFont();
362 if ( IsControlFont() )
363 aFont.Merge( GetControlFont() );
364 SetFont( aFont );
367 if ( bFont || bForeground )
369 Color aTextColor = rStyleSettings.GetButtonTextColor();
370 if ( IsControlForeground() )
371 aTextColor = GetControlForeground();
372 SetTextColor( aTextColor );
375 if ( bBackground )
377 SetBackground( rStyleSettings.GetFaceColor());
379 if ( IsBackground() )
381 SetFillColor( GetBackground().GetColor() );
382 SetBackground();
384 Invalidate();
387 // -----------------------------------------------------------------------
389 void ScPrivatSplit::StateChanged( StateChangedType nType )
391 if ( (nType == STATE_CHANGE_ZOOM) ||
392 (nType == STATE_CHANGE_CONTROLFONT) )
394 ImplInitSettings( TRUE, FALSE, FALSE );
395 Invalidate();
397 if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
399 ImplInitSettings( FALSE, TRUE, FALSE );
400 Invalidate();
402 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
404 ImplInitSettings( FALSE, FALSE, TRUE );
405 Invalidate();
408 Control::StateChanged( nType );
411 // -----------------------------------------------------------------------
413 void ScPrivatSplit::DataChanged( const DataChangedEvent& rDCEvt )
415 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
416 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
418 ImplInitSettings( TRUE, TRUE, TRUE );
419 Invalidate();
421 else
422 Window::DataChanged( rDCEvt );