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"
21 #include <vcl/settings.hxx>
23 /*************************************************************************
24 #* Member: ScPrivatSplit
25 #*------------------------------------------------------------------------
29 #* Funktion: Konstruktor der Klasse ScPrivatSplit
35 #************************************************************************/
37 ScPrivatSplit::ScPrivatSplit(vcl::Window
* pParent
, const ResId
& rResId
,
38 SC_SPLIT_DIRECTION eSplit
)
39 : Control(pParent
, rResId
)
43 Point aPos
=GetPosPixel();
44 nOldX
=(short)aPos
.X();
45 nOldY
=(short)aPos
.Y();
46 nNewX
=(short)aPos
.X();
47 nNewY
=(short)aPos
.Y();
49 aXMovingRange
.Min()=nNewX
;
50 aXMovingRange
.Max()=nNewX
;
51 aYMovingRange
.Min()=nNewY
;
52 aYMovingRange
.Max()=nNewY
;
54 aWinPointer
=GetPointer();
57 if(eScSplit
==SC_SPLIT_HORZ
)
59 aWinPointer
=Pointer(PointerStyle::HSplit
);
63 aWinPointer
=Pointer(PointerStyle::VSplit
);
65 SetPointer(aWinPointer
);
68 /*************************************************************************
69 #* Member: MouseButtonDown
70 #*------------------------------------------------------------------------
72 #* Klasse: ScPrivatSplit
74 #* Funktion: Reagiert auf einen einzelnen Mouse-Event. Nach Aufruf
75 #* werden alle Mauseingaben an dieses Control weitergeleitet.
81 #************************************************************************/
83 void ScPrivatSplit::MouseButtonDown( const MouseEvent
& rMEvt
)
85 Point aPos
=LogicToPixel(rMEvt
.GetPosPixel());
87 nOldX
=(short)aPos
.X();
88 nOldY
=(short)aPos
.Y();
93 /*************************************************************************
94 #* Member: MouseButtonUp
95 #*------------------------------------------------------------------------
97 #* Klasse: ScPrivatSplit
99 #* Funktion: Ende einer Benutzeraktion mit der Maus. Es werden
100 #* die aktuelle Maus- Koordinaten ermittelt und fuer
101 #* die Verschiebung des Fensters verwendet.
107 #************************************************************************/
109 void ScPrivatSplit::MouseButtonUp( const MouseEvent
& rMEvt
)
113 Point aPos
=LogicToPixel(rMEvt
.GetPosPixel());
114 Point a2Pos
=GetPosPixel();
117 if(eScSplit
==SC_SPLIT_HORZ
)
119 nNewX
=(short)aPos
.X();
122 if(a2Pos
.X()<aXMovingRange
.Min())
124 nDeltaX
=(short)(aXMovingRange
.Min()-a3Pos
.X());
125 a2Pos
.X()=aXMovingRange
.Min();
127 else if(a2Pos
.X()>aXMovingRange
.Max())
129 nDeltaX
=(short)(aXMovingRange
.Max()-a3Pos
.X());
130 a2Pos
.X()=aXMovingRange
.Max();
135 nNewY
=(short)aPos
.Y();
138 if(a2Pos
.Y()<aYMovingRange
.Min())
140 nDeltaY
=(short)(aYMovingRange
.Min()-a3Pos
.Y());
141 a2Pos
.Y()=aYMovingRange
.Min();
143 else if(a2Pos
.Y()>aYMovingRange
.Max())
145 nDeltaY
=(short)(aYMovingRange
.Max()-a3Pos
.Y());
146 a2Pos
.Y()=aYMovingRange
.Max();
155 /*************************************************************************
157 #*------------------------------------------------------------------------
159 #* Klasse: ScPrivatSplit
161 #* Funktion: Reagiert kontinuierlich auf Mausbewegungen. Es werden
162 #* die aktuelle Maus- Koordinaten ermittelt und fuer
163 #* die Verschiebung des Fensters verwendet.
169 #************************************************************************/
171 void ScPrivatSplit::MouseMove( const MouseEvent
& rMEvt
)
173 Point aPos
=LogicToPixel(rMEvt
.GetPosPixel());
174 Point a2Pos
=GetPosPixel();
178 if(eScSplit
==SC_SPLIT_HORZ
)
180 nNewX
=(short)aPos
.X();
184 if(a2Pos
.X()<aXMovingRange
.Min())
186 nDeltaX
=(short)(aXMovingRange
.Min()-a3Pos
.X());
187 a2Pos
.X()=aXMovingRange
.Min();
189 else if(a2Pos
.X()>aXMovingRange
.Max())
191 nDeltaX
=(short)(aXMovingRange
.Max()-a3Pos
.X());
192 a2Pos
.X()=aXMovingRange
.Max();
197 nNewY
=(short)aPos
.Y();
200 if(a2Pos
.Y()<aYMovingRange
.Min())
202 nDeltaY
=(short)(aYMovingRange
.Min()-a3Pos
.Y());
203 a2Pos
.Y()=aYMovingRange
.Min();
205 else if(a2Pos
.Y()>aYMovingRange
.Max())
207 nDeltaY
=(short)(aYMovingRange
.Max()-a3Pos
.Y());
208 a2Pos
.Y()=aYMovingRange
.Max();
220 /*************************************************************************
222 #*------------------------------------------------------------------------
224 #* Klasse: ScPrivatSplit
226 #* Funktion: Setzt den Range fuer die Y- Verschiebung
228 #* Input: neuer Bereich
232 #************************************************************************/
233 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();
338 void ScPrivatSplit::ImplInitSettings( bool bFont
, bool bForeground
, bool bBackground
)
340 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
344 vcl::Font aFont
= rStyleSettings
.GetAppFont();
345 if ( IsControlFont() )
346 aFont
.Merge( GetControlFont() );
350 if ( bFont
|| bForeground
)
352 Color aTextColor
= rStyleSettings
.GetButtonTextColor();
353 if ( IsControlForeground() )
354 aTextColor
= GetControlForeground();
355 SetTextColor( aTextColor
);
360 SetBackground( rStyleSettings
.GetFaceColor());
362 if ( IsBackground() )
364 SetFillColor( GetBackground().GetColor() );
370 void ScPrivatSplit::StateChanged( StateChangedType nType
)
372 if ( (nType
== StateChangedType::Zoom
) ||
373 (nType
== StateChangedType::ControlFont
) )
375 ImplInitSettings( true, false, false );
378 if ( nType
== StateChangedType::ControlForeground
)
380 ImplInitSettings( false, true, false );
383 else if ( nType
== StateChangedType::ControlBackground
)
385 ImplInitSettings( false, false, true );
389 Control::StateChanged( nType
);
392 void ScPrivatSplit::DataChanged( const DataChangedEvent
& rDCEvt
)
394 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
395 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
397 ImplInitSettings( true, true, true );
401 Window::DataChanged( rDCEvt
);
404 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */