1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gen.cxx,v $
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_tools.hxx"
33 #include <tools/debug.hxx>
34 #include <tools/gen.hxx>
35 #include <tools/stream.hxx>
37 // =======================================================================
39 SvStream
& operator>>( SvStream
& rIStream
, Pair
& rPair
)
41 DBG_ASSERTWARNING( rIStream
.GetVersion(), "Pair::>> - Solar-Version not set on rIStream" );
43 if ( rIStream
.GetCompressMode() == COMPRESSMODE_FULL
)
46 unsigned char cAry
[8];
53 i1
= (cId
& 0x70) >> 4;
55 rIStream
.Read( cAry
, i1
+i2
);
67 rPair
.nA
= (INT32
)nNum
;
79 rPair
.nB
= (INT32
)nNum
;
83 rIStream
>> rPair
.nA
>> rPair
.nB
;
89 // -----------------------------------------------------------------------
91 SvStream
& operator<<( SvStream
& rOStream
, const Pair
& rPair
)
93 DBG_ASSERTWARNING( rOStream
.GetVersion(), "Pair::<< - Solar-Version not set on rOStream" );
95 if ( rOStream
.GetCompressMode() == COMPRESSMODE_FULL
)
97 unsigned char cAry
[9];
103 nNum
= (UINT32
)(INT32
)rPair
.nA
;
111 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
117 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
123 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
129 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
144 nNum
= (UINT32
)(INT32
)rPair
.nB
;
152 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
158 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
164 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
170 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
185 rOStream
.Write( cAry
, i
);
189 rOStream
<< rPair
.nA
<< rPair
.nB
;
195 /*************************************************************************
197 |* Rectangle::SetSize()
199 |* Beschreibung GEN.SDW
200 |* Ersterstellung DV 29.10.91
201 |* Letzte Aenderung MM 21.04.94
203 *************************************************************************/
205 void Rectangle::SetSize( const Size
& rSize
)
207 if ( rSize
.Width() < 0 )
208 nRight
= nLeft
+ rSize
.Width() +1;
209 else if ( rSize
.Width() > 0 )
210 nRight
= nLeft
+ rSize
.Width() -1;
214 if ( rSize
.Height() < 0 )
215 nBottom
= nTop
+ rSize
.Height() +1;
216 else if ( rSize
.Height() > 0 )
217 nBottom
= nTop
+ rSize
.Height() -1;
219 nBottom
= RECT_EMPTY
;
222 /*************************************************************************
224 |* Rectangle::Union()
226 |* Beschreibung GEN.SDW
227 |* Ersterstellung TH 20.10.92
228 |* Letzte Aenderung MM 21.04.94
230 *************************************************************************/
232 Rectangle
& Rectangle::Union( const Rectangle
& rRect
)
234 if ( rRect
.IsEmpty() )
241 nLeft
= Min( Min( nLeft
, rRect
.nLeft
), Min( nRight
, rRect
.nRight
) );
242 nRight
= Max( Max( nLeft
, rRect
.nLeft
), Max( nRight
, rRect
.nRight
) );
243 nTop
= Min( Min( nTop
, rRect
.nTop
), Min( nBottom
, rRect
.nBottom
) );
244 nBottom
= Max( Max( nTop
, rRect
.nTop
), Max( nBottom
, rRect
.nBottom
) );
250 /*************************************************************************
252 |* Rectangle::Intersection()
254 |* Beschreibung GEN.SDW
255 |* Ersterstellung TH 20.10.92
256 |* Letzte Aenderung MM 21.04.94
258 *************************************************************************/
260 Rectangle
& Rectangle::Intersection( const Rectangle
& rRect
)
264 if ( rRect
.IsEmpty() )
270 // nicht mit umgedrehten Rechtecken arbeiten
271 Rectangle
aTmpRect( rRect
);
276 nLeft
= Max( nLeft
, aTmpRect
.nLeft
);
277 nRight
= Min( nRight
, aTmpRect
.nRight
);
278 nTop
= Max( nTop
, aTmpRect
.nTop
);
279 nBottom
= Min( nBottom
, aTmpRect
.nBottom
);
281 // Feststellen ob Schnitt leer
282 if ( nRight
< nLeft
|| nBottom
< nTop
)
288 /*************************************************************************
290 |* Rectangle::Justify()
292 |* Beschreibung GEN.SDW
293 |* Ersterstellung DV 07.03.91
294 |* Letzte Aenderung DV 07.03.91
296 *************************************************************************/
298 void Rectangle::Justify()
302 // Abfrage, ob Right kleiner Left
303 if ( (nRight
< nLeft
) && (nRight
!= RECT_EMPTY
) )
310 // Abfrage, ob Bottom kleiner Top
311 if ( (nBottom
< nTop
) && (nBottom
!= RECT_EMPTY
) )
319 /*************************************************************************
321 |* Rectangle::IsInside()
323 |* Beschreibung GEN.SDW
324 |* Ersterstellung TH 19.03.90
325 |* Letzte Aenderung MM 21.04.94
327 *************************************************************************/
329 BOOL
Rectangle::IsInside( const Point
& rPoint
) const
335 if ( nLeft
<= nRight
)
337 if ( (rPoint
.X() < nLeft
) || (rPoint
.X() > nRight
) )
342 if ( (rPoint
.X() > nLeft
) || (rPoint
.X() < nRight
) )
345 if ( nTop
<= nBottom
)
347 if ( (rPoint
.Y() < nTop
) || (rPoint
.Y() > nBottom
) )
352 if ( (rPoint
.Y() > nTop
) || (rPoint
.Y() < nBottom
) )
358 /*************************************************************************
360 |* Rectangle::IsInside()
362 |* Beschreibung GEN.SDW
363 |* Ersterstellung TH 19.03.90
364 |* Letzte Aenderung MM 21.04.94
366 *************************************************************************/
368 BOOL
Rectangle::IsInside( const Rectangle
& rRect
) const
370 if ( IsInside( rRect
.TopLeft() ) && IsInside( rRect
.BottomRight() ) )
376 /*************************************************************************
378 |* Rectangle::IsOver()
380 |* Beschreibung GEN.SDW
381 |* Ersterstellung TH 19.03.90
382 |* Letzte Aenderung MM 21.04.94
384 *************************************************************************/
386 BOOL
Rectangle::IsOver( const Rectangle
& rRect
) const
388 // Wenn sie sich nicht schneiden, ueberlappen sie auch nicht
389 return !GetIntersection( rRect
).IsEmpty();
392 // =======================================================================
394 SvStream
& operator>>( SvStream
& rIStream
, Rectangle
& rRect
)
396 DBG_ASSERTWARNING( rIStream
.GetVersion(), "Rectangle::>> - Solar-Version not set on rIStream" );
398 if ( rIStream
.GetCompressMode() == COMPRESSMODE_FULL
)
400 unsigned char cIdAry
[2];
401 unsigned char cAry
[16];
410 rIStream
.Read( cIdAry
, 2 );
411 i1
= (cIdAry
[0] & 0x70) >> 4;
412 i2
= cIdAry
[0] & 0x07;
413 i3
= (cIdAry
[1] & 0x70) >> 4;
414 i4
= cIdAry
[1] & 0x07;
415 rIStream
.Read( cAry
, i1
+i2
+i3
+i4
);
427 if ( cIdAry
[0] & 0x80 )
429 rRect
.nLeft
= (INT32
)nNum
;
440 if ( cIdAry
[0] & 0x08 )
442 rRect
.nTop
= (INT32
)nNum
;
453 if ( cIdAry
[1] & 0x80 )
455 rRect
.nRight
= (INT32
)nNum
;
465 if ( cIdAry
[1] & 0x08 )
467 rRect
.nBottom
= (INT32
)nNum
;
471 rIStream
>> rRect
.nLeft
>> rRect
.nTop
>> rRect
.nRight
>> rRect
.nBottom
;
477 // -----------------------------------------------------------------------
479 SvStream
& operator<<( SvStream
& rOStream
, const Rectangle
& rRect
)
481 DBG_ASSERTWARNING( rOStream
.GetVersion(), "Rectangle::<< - Solar-Version not set on rOStream" );
483 if ( rOStream
.GetCompressMode() == COMPRESSMODE_FULL
)
485 unsigned char cAry
[18];
492 nNum
= (UINT32
)(INT32
)rRect
.nLeft
;
493 if ( rRect
.nLeft
< 0 )
500 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
506 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
512 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
518 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
533 nNum
= (UINT32
)(INT32
)rRect
.nTop
;
534 if ( rRect
.nTop
< 0 )
541 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
547 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
553 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
559 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
574 nNum
= (UINT32
)(INT32
)rRect
.nRight
;
575 if ( rRect
.nRight
< 0 )
582 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
588 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
594 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
600 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
615 nNum
= (UINT32
)(INT32
)rRect
.nBottom
;
616 if ( rRect
.nBottom
< 0 )
623 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
629 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
635 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
641 cAry
[i
] = (unsigned char)(nNum
& 0xFF);
656 rOStream
.Write( cAry
, i
);
660 rOStream
<< rRect
.nLeft
<< rRect
.nTop
<< rRect
.nRight
<< rRect
.nBottom
;