1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "privsplt.hxx"
22 /*************************************************************************
23 #* Member: ScPrivatSplit
24 #*------------------------------------------------------------------------
28 #* Funktion: Konstruktor der Klasse ScPrivatSplit
34 #************************************************************************/
36 ScPrivatSplit::ScPrivatSplit( Window
* pParent
, const ResId
& rResId
,
37 SC_SPLIT_DIRECTION eSplit
):
38 Control( pParent
, rResId
)
40 Point aPos
=GetPosPixel();
41 nOldX
=(short)aPos
.X();
42 nOldY
=(short)aPos
.Y();
43 nNewX
=(short)aPos
.X();
44 nNewY
=(short)aPos
.Y();
46 aXMovingRange
.Min()=nNewX
;
47 aXMovingRange
.Max()=nNewX
;
48 aYMovingRange
.Min()=nNewY
;
49 aYMovingRange
.Max()=nNewY
;
51 aWinPointer
=GetPointer();
54 if(eScSplit
==SC_SPLIT_HORZ
)
56 aWinPointer
=Pointer(POINTER_HSPLIT
);
60 aWinPointer
=Pointer(POINTER_VSPLIT
);
62 SetPointer(aWinPointer
);
66 /*************************************************************************
67 #* Member: MouseButtonDown
68 #*------------------------------------------------------------------------
70 #* Klasse: ScPrivatSplit
72 #* Funktion: Reagiert auf einen einzelnen Mouse-Event. Nach Aufruf
73 #* werden alle Mauseingaben an dieses Control weitergeleitet.
79 #************************************************************************/
81 void ScPrivatSplit::MouseButtonDown( const MouseEvent
& rMEvt
)
83 Point aPos
=LogicToPixel(rMEvt
.GetPosPixel());
85 nOldX
=(short)aPos
.X();
86 nOldY
=(short)aPos
.Y();
91 /*************************************************************************
92 #* Member: MouseButtonUp
93 #*------------------------------------------------------------------------
95 #* Klasse: ScPrivatSplit
97 #* Funktion: Ende einer Benutzeraktion mit der Maus. Es werden
98 #* die aktuelle Maus- Koordinaten ermittelt und fuer
99 #* die Verschiebung des Fensters verwendet.
105 #************************************************************************/
107 void ScPrivatSplit::MouseButtonUp( const MouseEvent
& rMEvt
)
111 Point aPos
=LogicToPixel(rMEvt
.GetPosPixel());
112 Point a2Pos
=GetPosPixel();
115 if(eScSplit
==SC_SPLIT_HORZ
)
117 nNewX
=(short)aPos
.X();
120 if(a2Pos
.X()<aXMovingRange
.Min())
122 nDeltaX
=(short)(aXMovingRange
.Min()-a3Pos
.X());
123 a2Pos
.X()=aXMovingRange
.Min();
125 else if(a2Pos
.X()>aXMovingRange
.Max())
127 nDeltaX
=(short)(aXMovingRange
.Max()-a3Pos
.X());
128 a2Pos
.X()=aXMovingRange
.Max();
133 nNewY
=(short)aPos
.Y();
136 if(a2Pos
.Y()<aYMovingRange
.Min())
138 nDeltaY
=(short)(aYMovingRange
.Min()-a3Pos
.Y());
139 a2Pos
.Y()=aYMovingRange
.Min();
141 else if(a2Pos
.Y()>aYMovingRange
.Max())
143 nDeltaY
=(short)(aYMovingRange
.Max()-a3Pos
.Y());
144 a2Pos
.Y()=aYMovingRange
.Max();
153 /*************************************************************************
155 #*------------------------------------------------------------------------
157 #* Klasse: ScPrivatSplit
159 #* Funktion: Reagiert kontinuierlich auf Mausbewegungen. Es werden
160 #* die aktuelle Maus- Koordinaten ermittelt und fuer
161 #* die Verschiebung des Fensters verwendet.
167 #************************************************************************/
169 void ScPrivatSplit::MouseMove( const MouseEvent
& rMEvt
)
171 Point aPos
=LogicToPixel(rMEvt
.GetPosPixel());
172 Point a2Pos
=GetPosPixel();
176 if(eScSplit
==SC_SPLIT_HORZ
)
178 nNewX
=(short)aPos
.X();
182 if(a2Pos
.X()<aXMovingRange
.Min())
184 nDeltaX
=(short)(aXMovingRange
.Min()-a3Pos
.X());
185 a2Pos
.X()=aXMovingRange
.Min();
187 else if(a2Pos
.X()>aXMovingRange
.Max())
189 nDeltaX
=(short)(aXMovingRange
.Max()-a3Pos
.X());
190 a2Pos
.X()=aXMovingRange
.Max();
195 nNewY
=(short)aPos
.Y();
198 if(a2Pos
.Y()<aYMovingRange
.Min())
200 nDeltaY
=(short)(aYMovingRange
.Min()-a3Pos
.Y());
201 a2Pos
.Y()=aYMovingRange
.Min();
203 else if(a2Pos
.Y()>aYMovingRange
.Max())
205 nDeltaY
=(short)(aYMovingRange
.Max()-a3Pos
.Y());
206 a2Pos
.Y()=aYMovingRange
.Max();
218 /*************************************************************************
220 #*------------------------------------------------------------------------
222 #* Klasse: ScPrivatSplit
224 #* Funktion: Setzt den Range fuer die Y- Verschiebung
226 #* Input: neuer Bereich
230 #************************************************************************/
231 void ScPrivatSplit::SetYRange(Range cRgeY
)
238 /*************************************************************************
240 #*------------------------------------------------------------------------
242 #* Klasse: ScPrivatSplit
244 #* Funktion: Liefert die relative x-Verschiebung zurueck
250 #************************************************************************/
251 short ScPrivatSplit::GetDeltaX()
256 /*************************************************************************
258 #*------------------------------------------------------------------------
260 #* Klasse: ScPrivatSplit
262 #* Funktion: Liefert die relative y-Verschiebung zurueck
268 #************************************************************************/
269 short ScPrivatSplit::GetDeltaY()
274 /*************************************************************************
275 #* Member: CtrModified
276 #*------------------------------------------------------------------------
278 #* Klasse: ScPrivatSplit
280 #* Funktion: Teilt einem installierten Handler mit, dass
281 #* eine Veraenderung eingetreten ist.
287 #************************************************************************/
288 void ScPrivatSplit::CtrModified()
290 aCtrModifiedLink
.Call( this );
293 void ScPrivatSplit::MoveSplitTo(Point aPos
)
295 Point a2Pos
=GetPosPixel();
296 nOldX
=(short)a2Pos
.X();
297 nOldY
=(short)a2Pos
.Y();
300 if(eScSplit
==SC_SPLIT_HORZ
)
302 nNewX
=(short)aPos
.X();
305 if(a2Pos
.X()<aXMovingRange
.Min())
307 nDeltaX
=(short)(aXMovingRange
.Min()-a3Pos
.X());
308 a2Pos
.X()=aXMovingRange
.Min();
310 else if(a2Pos
.X()>aXMovingRange
.Max())
312 nDeltaX
=(short)(aXMovingRange
.Max()-a3Pos
.X());
313 a2Pos
.X()=aXMovingRange
.Max();
318 nNewY
=(short)aPos
.Y();
321 if(a2Pos
.Y()<aYMovingRange
.Min())
323 nDeltaY
=(short)(aYMovingRange
.Min()-a3Pos
.Y());
324 a2Pos
.Y()=aYMovingRange
.Min();
326 else if(a2Pos
.Y()>aYMovingRange
.Max())
328 nDeltaY
=(short)(aYMovingRange
.Max()-a3Pos
.Y());
329 a2Pos
.Y()=aYMovingRange
.Max();
339 void ScPrivatSplit::ImplInitSettings( sal_Bool bFont
, sal_Bool bForeground
, sal_Bool bBackground
)
341 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
345 Font aFont
= rStyleSettings
.GetAppFont();
346 if ( IsControlFont() )
347 aFont
.Merge( GetControlFont() );
351 if ( bFont
|| bForeground
)
353 Color aTextColor
= rStyleSettings
.GetButtonTextColor();
354 if ( IsControlForeground() )
355 aTextColor
= GetControlForeground();
356 SetTextColor( aTextColor
);
361 SetBackground( rStyleSettings
.GetFaceColor());
363 if ( IsBackground() )
365 SetFillColor( GetBackground().GetColor() );
371 // -----------------------------------------------------------------------
373 void ScPrivatSplit::StateChanged( StateChangedType nType
)
375 if ( (nType
== STATE_CHANGE_ZOOM
) ||
376 (nType
== STATE_CHANGE_CONTROLFONT
) )
378 ImplInitSettings( sal_True
, false, false );
381 if ( nType
== STATE_CHANGE_CONTROLFOREGROUND
)
383 ImplInitSettings( false, sal_True
, false );
386 else if ( nType
== STATE_CHANGE_CONTROLBACKGROUND
)
388 ImplInitSettings( false, false, sal_True
);
392 Control::StateChanged( nType
);
395 // -----------------------------------------------------------------------
397 void ScPrivatSplit::DataChanged( const DataChangedEvent
& rDCEvt
)
399 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
400 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
402 ImplInitSettings( sal_True
, sal_True
, sal_True
);
406 Window::DataChanged( rDCEvt
);
410 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */