xref: /AOO41X/main/tools/source/generic/gen.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_tools.hxx"
30*cdf0e10cSrcweir #include <tools/debug.hxx>
31*cdf0e10cSrcweir #include <tools/gen.hxx>
32*cdf0e10cSrcweir #include <tools/stream.hxx>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir // =======================================================================
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStream, Pair& rPair )
37*cdf0e10cSrcweir {
38*cdf0e10cSrcweir 	DBG_ASSERTWARNING( rIStream.GetVersion(), "Pair::>> - Solar-Version not set on rIStream" );
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir 	if ( rIStream.GetCompressMode() == COMPRESSMODE_FULL )
41*cdf0e10cSrcweir 	{
42*cdf0e10cSrcweir 		unsigned char	cId;
43*cdf0e10cSrcweir 		unsigned char	cAry[8];
44*cdf0e10cSrcweir 		int 			i;
45*cdf0e10cSrcweir 		int 			i1;
46*cdf0e10cSrcweir 		int 			i2;
47*cdf0e10cSrcweir 		sal_uInt32			nNum;
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir 		rIStream >> cId;
50*cdf0e10cSrcweir 		i1 = (cId & 0x70) >> 4;
51*cdf0e10cSrcweir 		i2 = cId & 0x07;
52*cdf0e10cSrcweir 		rIStream.Read( cAry, i1+i2 );
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir 		nNum = 0;
55*cdf0e10cSrcweir 		i = i1;
56*cdf0e10cSrcweir 		while ( i )
57*cdf0e10cSrcweir 		{
58*cdf0e10cSrcweir 			i--;
59*cdf0e10cSrcweir 			nNum <<= 8;
60*cdf0e10cSrcweir 			nNum |= cAry[i];
61*cdf0e10cSrcweir 		}
62*cdf0e10cSrcweir 		if ( cId & 0x80 )
63*cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
64*cdf0e10cSrcweir 		rPair.nA = (sal_Int32)nNum;
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir 		nNum = 0;
67*cdf0e10cSrcweir 		i = i1+i2;
68*cdf0e10cSrcweir 		while ( i > i1 )
69*cdf0e10cSrcweir 		{
70*cdf0e10cSrcweir 			i--;
71*cdf0e10cSrcweir 			nNum <<= 8;
72*cdf0e10cSrcweir 			nNum |= cAry[i];
73*cdf0e10cSrcweir 		}
74*cdf0e10cSrcweir 		if ( cId & 0x08 )
75*cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
76*cdf0e10cSrcweir 		rPair.nB = (sal_Int32)nNum;
77*cdf0e10cSrcweir 	}
78*cdf0e10cSrcweir 	else
79*cdf0e10cSrcweir 	{
80*cdf0e10cSrcweir 		rIStream >> rPair.nA >> rPair.nB;
81*cdf0e10cSrcweir 	}
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 	return rIStream;
84*cdf0e10cSrcweir }
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir // -----------------------------------------------------------------------
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStream, const Pair& rPair )
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir 	DBG_ASSERTWARNING( rOStream.GetVersion(), "Pair::<< - Solar-Version not set on rOStream" );
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 	if ( rOStream.GetCompressMode() == COMPRESSMODE_FULL )
93*cdf0e10cSrcweir 	{
94*cdf0e10cSrcweir 		unsigned char	cAry[9];
95*cdf0e10cSrcweir 		int 			i = 1;
96*cdf0e10cSrcweir 		sal_uInt32			nNum;
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 		cAry[0] = 0;
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 		nNum = (sal_uInt32)(sal_Int32)rPair.nA;
101*cdf0e10cSrcweir 		if ( rPair.nA < 0 )
102*cdf0e10cSrcweir 		{
103*cdf0e10cSrcweir 			cAry[0] |= 0x80;
104*cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
105*cdf0e10cSrcweir 		}
106*cdf0e10cSrcweir 		if ( nNum )
107*cdf0e10cSrcweir 		{
108*cdf0e10cSrcweir 			cAry[i] = (unsigned char)(nNum & 0xFF);
109*cdf0e10cSrcweir 			nNum >>= 8;
110*cdf0e10cSrcweir 			i++;
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 			if ( nNum )
113*cdf0e10cSrcweir 			{
114*cdf0e10cSrcweir 				cAry[i] = (unsigned char)(nNum & 0xFF);
115*cdf0e10cSrcweir 				nNum >>= 8;
116*cdf0e10cSrcweir 				i++;
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 				if ( nNum )
119*cdf0e10cSrcweir 				{
120*cdf0e10cSrcweir 					cAry[i] = (unsigned char)(nNum & 0xFF);
121*cdf0e10cSrcweir 					nNum >>= 8;
122*cdf0e10cSrcweir 					i++;
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 					if ( nNum )
125*cdf0e10cSrcweir 					{
126*cdf0e10cSrcweir 						cAry[i] = (unsigned char)(nNum & 0xFF);
127*cdf0e10cSrcweir 						nNum >>= 8;
128*cdf0e10cSrcweir 						i++;
129*cdf0e10cSrcweir 						cAry[0] |= 0x40;
130*cdf0e10cSrcweir 					}
131*cdf0e10cSrcweir 					else
132*cdf0e10cSrcweir 						cAry[0] |= 0x30;
133*cdf0e10cSrcweir 				}
134*cdf0e10cSrcweir 				else
135*cdf0e10cSrcweir 					cAry[0] |= 0x20;
136*cdf0e10cSrcweir 			}
137*cdf0e10cSrcweir 			else
138*cdf0e10cSrcweir 				cAry[0] |= 0x10;
139*cdf0e10cSrcweir 		}
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 		nNum = (sal_uInt32)(sal_Int32)rPair.nB;
142*cdf0e10cSrcweir 		if ( rPair.nB < 0 )
143*cdf0e10cSrcweir 		{
144*cdf0e10cSrcweir 			cAry[0] |= 0x08;
145*cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
146*cdf0e10cSrcweir 		}
147*cdf0e10cSrcweir 		if ( nNum )
148*cdf0e10cSrcweir 		{
149*cdf0e10cSrcweir 			cAry[i] = (unsigned char)(nNum & 0xFF);
150*cdf0e10cSrcweir 			nNum >>= 8;
151*cdf0e10cSrcweir 			i++;
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 			if ( nNum )
154*cdf0e10cSrcweir 			{
155*cdf0e10cSrcweir 				cAry[i] = (unsigned char)(nNum & 0xFF);
156*cdf0e10cSrcweir 				nNum >>= 8;
157*cdf0e10cSrcweir 				i++;
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 				if ( nNum )
160*cdf0e10cSrcweir 				{
161*cdf0e10cSrcweir 					cAry[i] = (unsigned char)(nNum & 0xFF);
162*cdf0e10cSrcweir 					nNum >>= 8;
163*cdf0e10cSrcweir 					i++;
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 					if ( nNum )
166*cdf0e10cSrcweir 					{
167*cdf0e10cSrcweir 						cAry[i] = (unsigned char)(nNum & 0xFF);
168*cdf0e10cSrcweir 						nNum >>= 8;
169*cdf0e10cSrcweir 						i++;
170*cdf0e10cSrcweir 						cAry[0] |= 0x04;
171*cdf0e10cSrcweir 					}
172*cdf0e10cSrcweir 					else
173*cdf0e10cSrcweir 						cAry[0] |= 0x03;
174*cdf0e10cSrcweir 				}
175*cdf0e10cSrcweir 				else
176*cdf0e10cSrcweir 					cAry[0] |= 0x02;
177*cdf0e10cSrcweir 			}
178*cdf0e10cSrcweir 			else
179*cdf0e10cSrcweir 				cAry[0] |= 0x01;
180*cdf0e10cSrcweir 		}
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 		rOStream.Write( cAry, i );
183*cdf0e10cSrcweir 	}
184*cdf0e10cSrcweir 	else
185*cdf0e10cSrcweir 	{
186*cdf0e10cSrcweir 		rOStream << rPair.nA << rPair.nB;
187*cdf0e10cSrcweir 	}
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 	return rOStream;
190*cdf0e10cSrcweir }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir /*************************************************************************
193*cdf0e10cSrcweir |*
194*cdf0e10cSrcweir |*    Rectangle::SetSize()
195*cdf0e10cSrcweir |*
196*cdf0e10cSrcweir |*    Beschreibung      GEN.SDW
197*cdf0e10cSrcweir |*    Ersterstellung    DV 29.10.91
198*cdf0e10cSrcweir |*    Letzte Aenderung  MM 21.04.94
199*cdf0e10cSrcweir |*
200*cdf0e10cSrcweir *************************************************************************/
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir void Rectangle::SetSize( const Size& rSize )
203*cdf0e10cSrcweir {
204*cdf0e10cSrcweir     if ( rSize.Width() < 0 )
205*cdf0e10cSrcweir         nRight  = nLeft + rSize.Width() +1;
206*cdf0e10cSrcweir     else if ( rSize.Width() > 0 )
207*cdf0e10cSrcweir         nRight  = nLeft + rSize.Width() -1;
208*cdf0e10cSrcweir     else
209*cdf0e10cSrcweir         nRight = RECT_EMPTY;
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir     if ( rSize.Height() < 0 )
212*cdf0e10cSrcweir         nBottom  = nTop + rSize.Height() +1;
213*cdf0e10cSrcweir     else if ( rSize.Height() > 0 )
214*cdf0e10cSrcweir         nBottom  = nTop + rSize.Height() -1;
215*cdf0e10cSrcweir     else
216*cdf0e10cSrcweir         nBottom = RECT_EMPTY;
217*cdf0e10cSrcweir }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir /*************************************************************************
220*cdf0e10cSrcweir |*
221*cdf0e10cSrcweir |*    Rectangle::Union()
222*cdf0e10cSrcweir |*
223*cdf0e10cSrcweir |*    Beschreibung      GEN.SDW
224*cdf0e10cSrcweir |*    Ersterstellung    TH 20.10.92
225*cdf0e10cSrcweir |*    Letzte Aenderung  MM 21.04.94
226*cdf0e10cSrcweir |*
227*cdf0e10cSrcweir *************************************************************************/
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir Rectangle& Rectangle::Union( const Rectangle& rRect )
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir     if ( rRect.IsEmpty() )
232*cdf0e10cSrcweir         return *this;
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir     if ( IsEmpty() )
235*cdf0e10cSrcweir         *this = rRect;
236*cdf0e10cSrcweir     else
237*cdf0e10cSrcweir     {
238*cdf0e10cSrcweir         nLeft  =  Min( Min( nLeft, rRect.nLeft ), Min( nRight, rRect.nRight )   );
239*cdf0e10cSrcweir         nRight  = Max( Max( nLeft, rRect.nLeft ), Max( nRight, rRect.nRight )   );
240*cdf0e10cSrcweir         nTop    = Min( Min( nTop, rRect.nTop ),   Min( nBottom, rRect.nBottom ) );
241*cdf0e10cSrcweir         nBottom = Max( Max( nTop, rRect.nTop ),   Max( nBottom, rRect.nBottom ) );
242*cdf0e10cSrcweir     }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir     return *this;
245*cdf0e10cSrcweir }
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir /*************************************************************************
248*cdf0e10cSrcweir |*
249*cdf0e10cSrcweir |*    Rectangle::Intersection()
250*cdf0e10cSrcweir |*
251*cdf0e10cSrcweir |*    Beschreibung      GEN.SDW
252*cdf0e10cSrcweir |*    Ersterstellung    TH 20.10.92
253*cdf0e10cSrcweir |*    Letzte Aenderung  MM 21.04.94
254*cdf0e10cSrcweir |*
255*cdf0e10cSrcweir *************************************************************************/
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir Rectangle& Rectangle::Intersection( const Rectangle& rRect )
258*cdf0e10cSrcweir {
259*cdf0e10cSrcweir     if ( IsEmpty() )
260*cdf0e10cSrcweir         return *this;
261*cdf0e10cSrcweir     if ( rRect.IsEmpty() )
262*cdf0e10cSrcweir     {
263*cdf0e10cSrcweir         *this = Rectangle();
264*cdf0e10cSrcweir         return *this;
265*cdf0e10cSrcweir     }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir     // nicht mit umgedrehten Rechtecken arbeiten
268*cdf0e10cSrcweir     Rectangle aTmpRect( rRect );
269*cdf0e10cSrcweir     Justify();
270*cdf0e10cSrcweir     aTmpRect.Justify();
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir     // Schnitt bilden
273*cdf0e10cSrcweir     nLeft  = Max( nLeft, aTmpRect.nLeft );
274*cdf0e10cSrcweir     nRight = Min( nRight, aTmpRect.nRight );
275*cdf0e10cSrcweir     nTop   = Max( nTop, aTmpRect.nTop );
276*cdf0e10cSrcweir     nBottom= Min( nBottom, aTmpRect.nBottom );
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir     // Feststellen ob Schnitt leer
279*cdf0e10cSrcweir     if ( nRight < nLeft || nBottom < nTop )
280*cdf0e10cSrcweir         *this = Rectangle();
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir     return *this;
283*cdf0e10cSrcweir }
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir /*************************************************************************
286*cdf0e10cSrcweir |*
287*cdf0e10cSrcweir |*    Rectangle::Justify()
288*cdf0e10cSrcweir |*
289*cdf0e10cSrcweir |*    Beschreibung      GEN.SDW
290*cdf0e10cSrcweir |*    Ersterstellung    DV 07.03.91
291*cdf0e10cSrcweir |*    Letzte Aenderung  DV 07.03.91
292*cdf0e10cSrcweir |*
293*cdf0e10cSrcweir *************************************************************************/
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir void Rectangle::Justify()
296*cdf0e10cSrcweir {
297*cdf0e10cSrcweir     long nHelp;
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir     // Abfrage, ob Right kleiner Left
300*cdf0e10cSrcweir     if ( (nRight < nLeft) && (nRight != RECT_EMPTY) )
301*cdf0e10cSrcweir     {
302*cdf0e10cSrcweir         nHelp = nLeft;
303*cdf0e10cSrcweir         nLeft = nRight;
304*cdf0e10cSrcweir         nRight = nHelp;
305*cdf0e10cSrcweir     }
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir     // Abfrage, ob Bottom kleiner Top
308*cdf0e10cSrcweir     if ( (nBottom < nTop) && (nBottom != RECT_EMPTY) )
309*cdf0e10cSrcweir     {
310*cdf0e10cSrcweir         nHelp = nBottom;
311*cdf0e10cSrcweir         nBottom = nTop;
312*cdf0e10cSrcweir         nTop = nHelp;
313*cdf0e10cSrcweir     }
314*cdf0e10cSrcweir }
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir /*************************************************************************
317*cdf0e10cSrcweir |*
318*cdf0e10cSrcweir |*    Rectangle::IsInside()
319*cdf0e10cSrcweir |*
320*cdf0e10cSrcweir |*    Beschreibung      GEN.SDW
321*cdf0e10cSrcweir |*    Ersterstellung    TH 19.03.90
322*cdf0e10cSrcweir |*    Letzte Aenderung  MM 21.04.94
323*cdf0e10cSrcweir |*
324*cdf0e10cSrcweir *************************************************************************/
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir sal_Bool Rectangle::IsInside( const Point& rPoint ) const
327*cdf0e10cSrcweir {
328*cdf0e10cSrcweir     if ( IsEmpty() )
329*cdf0e10cSrcweir         return sal_False;
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir     sal_Bool bRet = sal_True;
332*cdf0e10cSrcweir     if ( nLeft <= nRight )
333*cdf0e10cSrcweir     {
334*cdf0e10cSrcweir         if ( (rPoint.X() < nLeft) || (rPoint.X() > nRight) )
335*cdf0e10cSrcweir             bRet = sal_False;
336*cdf0e10cSrcweir     }
337*cdf0e10cSrcweir     else
338*cdf0e10cSrcweir     {
339*cdf0e10cSrcweir         if ( (rPoint.X() > nLeft) || (rPoint.X() < nRight) )
340*cdf0e10cSrcweir             bRet = sal_False;
341*cdf0e10cSrcweir     }
342*cdf0e10cSrcweir     if ( nTop <= nBottom )
343*cdf0e10cSrcweir     {
344*cdf0e10cSrcweir         if ( (rPoint.Y() < nTop) || (rPoint.Y() > nBottom) )
345*cdf0e10cSrcweir             bRet = sal_False;
346*cdf0e10cSrcweir     }
347*cdf0e10cSrcweir     else
348*cdf0e10cSrcweir     {
349*cdf0e10cSrcweir         if ( (rPoint.Y() > nTop) || (rPoint.Y() < nBottom) )
350*cdf0e10cSrcweir             bRet = sal_False;
351*cdf0e10cSrcweir     }
352*cdf0e10cSrcweir     return bRet;
353*cdf0e10cSrcweir }
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir /*************************************************************************
356*cdf0e10cSrcweir |*
357*cdf0e10cSrcweir |*    Rectangle::IsInside()
358*cdf0e10cSrcweir |*
359*cdf0e10cSrcweir |*    Beschreibung      GEN.SDW
360*cdf0e10cSrcweir |*    Ersterstellung    TH 19.03.90
361*cdf0e10cSrcweir |*    Letzte Aenderung  MM 21.04.94
362*cdf0e10cSrcweir |*
363*cdf0e10cSrcweir *************************************************************************/
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir sal_Bool Rectangle::IsInside( const Rectangle& rRect ) const
366*cdf0e10cSrcweir {
367*cdf0e10cSrcweir     if ( IsInside( rRect.TopLeft() ) && IsInside( rRect.BottomRight() ) )
368*cdf0e10cSrcweir         return sal_True;
369*cdf0e10cSrcweir     else
370*cdf0e10cSrcweir         return sal_False;
371*cdf0e10cSrcweir }
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir /*************************************************************************
374*cdf0e10cSrcweir |*
375*cdf0e10cSrcweir |*    Rectangle::IsOver()
376*cdf0e10cSrcweir |*
377*cdf0e10cSrcweir |*    Beschreibung      GEN.SDW
378*cdf0e10cSrcweir |*    Ersterstellung    TH 19.03.90
379*cdf0e10cSrcweir |*    Letzte Aenderung  MM 21.04.94
380*cdf0e10cSrcweir |*
381*cdf0e10cSrcweir *************************************************************************/
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir sal_Bool Rectangle::IsOver( const Rectangle& rRect ) const
384*cdf0e10cSrcweir {
385*cdf0e10cSrcweir     // Wenn sie sich nicht schneiden, ueberlappen sie auch nicht
386*cdf0e10cSrcweir     return !GetIntersection( rRect ).IsEmpty();
387*cdf0e10cSrcweir }
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir // =======================================================================
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStream, Rectangle& rRect )
392*cdf0e10cSrcweir {
393*cdf0e10cSrcweir 	DBG_ASSERTWARNING( rIStream.GetVersion(), "Rectangle::>> - Solar-Version not set on rIStream" );
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir 	if ( rIStream.GetCompressMode() == COMPRESSMODE_FULL )
396*cdf0e10cSrcweir 	{
397*cdf0e10cSrcweir 		unsigned char	cIdAry[2];
398*cdf0e10cSrcweir 		unsigned char	cAry[16];
399*cdf0e10cSrcweir 		int 			i;
400*cdf0e10cSrcweir 		int 			iLast;
401*cdf0e10cSrcweir 		int 			i1;
402*cdf0e10cSrcweir 		int 			i2;
403*cdf0e10cSrcweir 		int 			i3;
404*cdf0e10cSrcweir 		int 			i4;
405*cdf0e10cSrcweir 		sal_uInt32			nNum;
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 		rIStream.Read( cIdAry, 2 );
408*cdf0e10cSrcweir 		i1 = (cIdAry[0] & 0x70) >> 4;
409*cdf0e10cSrcweir 		i2 = cIdAry[0] & 0x07;
410*cdf0e10cSrcweir 		i3 = (cIdAry[1] & 0x70) >> 4;
411*cdf0e10cSrcweir 		i4 = cIdAry[1] & 0x07;
412*cdf0e10cSrcweir 		rIStream.Read( cAry, i1+i2+i3+i4 );
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir 		nNum = 0;
415*cdf0e10cSrcweir 		i = i1;
416*cdf0e10cSrcweir 		iLast = i;
417*cdf0e10cSrcweir 		while ( i )
418*cdf0e10cSrcweir 		{
419*cdf0e10cSrcweir 			i--;
420*cdf0e10cSrcweir 			nNum <<= 8;
421*cdf0e10cSrcweir 			nNum |= cAry[i];
422*cdf0e10cSrcweir 		}
423*cdf0e10cSrcweir 		iLast = i1;
424*cdf0e10cSrcweir 		if ( cIdAry[0] & 0x80 )
425*cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
426*cdf0e10cSrcweir 		rRect.nLeft = (sal_Int32)nNum;
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir 		nNum = 0;
429*cdf0e10cSrcweir 		i = iLast+i2;
430*cdf0e10cSrcweir 		while ( i > iLast )
431*cdf0e10cSrcweir 		{
432*cdf0e10cSrcweir 			i--;
433*cdf0e10cSrcweir 			nNum <<= 8;
434*cdf0e10cSrcweir 			nNum |= cAry[i];
435*cdf0e10cSrcweir 		}
436*cdf0e10cSrcweir 		iLast += i2;
437*cdf0e10cSrcweir 		if ( cIdAry[0] & 0x08 )
438*cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
439*cdf0e10cSrcweir 		rRect.nTop = (sal_Int32)nNum;
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir 		nNum = 0;
442*cdf0e10cSrcweir 		i = iLast+i3;
443*cdf0e10cSrcweir 		while ( i > iLast )
444*cdf0e10cSrcweir 		{
445*cdf0e10cSrcweir 			i--;
446*cdf0e10cSrcweir 			nNum <<= 8;
447*cdf0e10cSrcweir 			nNum |= cAry[i];
448*cdf0e10cSrcweir 		}
449*cdf0e10cSrcweir 		iLast += i3;
450*cdf0e10cSrcweir 		if ( cIdAry[1] & 0x80 )
451*cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
452*cdf0e10cSrcweir 		rRect.nRight = (sal_Int32)nNum;
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir 		nNum = 0;
455*cdf0e10cSrcweir 		i = iLast+i4;
456*cdf0e10cSrcweir 		while ( i > iLast )
457*cdf0e10cSrcweir 		{
458*cdf0e10cSrcweir 			i--;
459*cdf0e10cSrcweir 			nNum <<= 8;
460*cdf0e10cSrcweir 			nNum |= cAry[i];
461*cdf0e10cSrcweir 		}
462*cdf0e10cSrcweir 		if ( cIdAry[1] & 0x08 )
463*cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
464*cdf0e10cSrcweir 		rRect.nBottom = (sal_Int32)nNum;
465*cdf0e10cSrcweir 	}
466*cdf0e10cSrcweir 	else
467*cdf0e10cSrcweir 	{
468*cdf0e10cSrcweir 		rIStream >> rRect.nLeft >> rRect.nTop >> rRect.nRight >> rRect.nBottom;
469*cdf0e10cSrcweir 	}
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir 	return rIStream;
472*cdf0e10cSrcweir }
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir // -----------------------------------------------------------------------
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStream, const Rectangle& rRect )
477*cdf0e10cSrcweir {
478*cdf0e10cSrcweir 	DBG_ASSERTWARNING( rOStream.GetVersion(), "Rectangle::<< - Solar-Version not set on rOStream" );
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir 	if ( rOStream.GetCompressMode() == COMPRESSMODE_FULL )
481*cdf0e10cSrcweir 	{
482*cdf0e10cSrcweir 		unsigned char	cAry[18];
483*cdf0e10cSrcweir 		int 			i = 2;
484*cdf0e10cSrcweir 		sal_uInt32			nNum;
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir 		cAry[0] = 0;
487*cdf0e10cSrcweir 		cAry[1] = 0;
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir 		nNum = (sal_uInt32)(sal_Int32)rRect.nLeft;
490*cdf0e10cSrcweir 		if ( rRect.nLeft < 0 )
491*cdf0e10cSrcweir 		{
492*cdf0e10cSrcweir 			cAry[0] |= 0x80;
493*cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
494*cdf0e10cSrcweir 		}
495*cdf0e10cSrcweir 		if ( nNum )
496*cdf0e10cSrcweir 		{
497*cdf0e10cSrcweir 			cAry[i] = (unsigned char)(nNum & 0xFF);
498*cdf0e10cSrcweir 			nNum >>= 8;
499*cdf0e10cSrcweir 			i++;
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir 			if ( nNum )
502*cdf0e10cSrcweir 			{
503*cdf0e10cSrcweir 				cAry[i] = (unsigned char)(nNum & 0xFF);
504*cdf0e10cSrcweir 				nNum >>= 8;
505*cdf0e10cSrcweir 				i++;
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir 				if ( nNum )
508*cdf0e10cSrcweir 				{
509*cdf0e10cSrcweir 					cAry[i] = (unsigned char)(nNum & 0xFF);
510*cdf0e10cSrcweir 					nNum >>= 8;
511*cdf0e10cSrcweir 					i++;
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir 					if ( nNum )
514*cdf0e10cSrcweir 					{
515*cdf0e10cSrcweir 						cAry[i] = (unsigned char)(nNum & 0xFF);
516*cdf0e10cSrcweir 						nNum >>= 8;
517*cdf0e10cSrcweir 						i++;
518*cdf0e10cSrcweir 						cAry[0] |= 0x40;
519*cdf0e10cSrcweir 					}
520*cdf0e10cSrcweir 					else
521*cdf0e10cSrcweir 						cAry[0] |= 0x30;
522*cdf0e10cSrcweir 				}
523*cdf0e10cSrcweir 				else
524*cdf0e10cSrcweir 					cAry[0] |= 0x20;
525*cdf0e10cSrcweir 			}
526*cdf0e10cSrcweir 			else
527*cdf0e10cSrcweir 				cAry[0] |= 0x10;
528*cdf0e10cSrcweir 		}
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir 		nNum = (sal_uInt32)(sal_Int32)rRect.nTop;
531*cdf0e10cSrcweir 		if ( rRect.nTop < 0 )
532*cdf0e10cSrcweir 		{
533*cdf0e10cSrcweir 			cAry[0] |= 0x08;
534*cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
535*cdf0e10cSrcweir 		}
536*cdf0e10cSrcweir 		if ( nNum )
537*cdf0e10cSrcweir 		{
538*cdf0e10cSrcweir 			cAry[i] = (unsigned char)(nNum & 0xFF);
539*cdf0e10cSrcweir 			nNum >>= 8;
540*cdf0e10cSrcweir 			i++;
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir 			if ( nNum )
543*cdf0e10cSrcweir 			{
544*cdf0e10cSrcweir 				cAry[i] = (unsigned char)(nNum & 0xFF);
545*cdf0e10cSrcweir 				nNum >>= 8;
546*cdf0e10cSrcweir 				i++;
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir 				if ( nNum )
549*cdf0e10cSrcweir 				{
550*cdf0e10cSrcweir 					cAry[i] = (unsigned char)(nNum & 0xFF);
551*cdf0e10cSrcweir 					nNum >>= 8;
552*cdf0e10cSrcweir 					i++;
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir 					if ( nNum )
555*cdf0e10cSrcweir 					{
556*cdf0e10cSrcweir 						cAry[i] = (unsigned char)(nNum & 0xFF);
557*cdf0e10cSrcweir 						nNum >>= 8;
558*cdf0e10cSrcweir 						i++;
559*cdf0e10cSrcweir 						cAry[0] |= 0x04;
560*cdf0e10cSrcweir 					}
561*cdf0e10cSrcweir 					else
562*cdf0e10cSrcweir 						cAry[0] |= 0x03;
563*cdf0e10cSrcweir 				}
564*cdf0e10cSrcweir 				else
565*cdf0e10cSrcweir 					cAry[0] |= 0x02;
566*cdf0e10cSrcweir 			}
567*cdf0e10cSrcweir 			else
568*cdf0e10cSrcweir 				cAry[0] |= 0x01;
569*cdf0e10cSrcweir 		}
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir 		nNum = (sal_uInt32)(sal_Int32)rRect.nRight;
572*cdf0e10cSrcweir 		if ( rRect.nRight < 0 )
573*cdf0e10cSrcweir 		{
574*cdf0e10cSrcweir 			cAry[1] |= 0x80;
575*cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
576*cdf0e10cSrcweir 		}
577*cdf0e10cSrcweir 		if ( nNum )
578*cdf0e10cSrcweir 		{
579*cdf0e10cSrcweir 			cAry[i] = (unsigned char)(nNum & 0xFF);
580*cdf0e10cSrcweir 			nNum >>= 8;
581*cdf0e10cSrcweir 			i++;
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir 			if ( nNum )
584*cdf0e10cSrcweir 			{
585*cdf0e10cSrcweir 				cAry[i] = (unsigned char)(nNum & 0xFF);
586*cdf0e10cSrcweir 				nNum >>= 8;
587*cdf0e10cSrcweir 				i++;
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir 				if ( nNum )
590*cdf0e10cSrcweir 				{
591*cdf0e10cSrcweir 					cAry[i] = (unsigned char)(nNum & 0xFF);
592*cdf0e10cSrcweir 					nNum >>= 8;
593*cdf0e10cSrcweir 					i++;
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir 					if ( nNum )
596*cdf0e10cSrcweir 					{
597*cdf0e10cSrcweir 						cAry[i] = (unsigned char)(nNum & 0xFF);
598*cdf0e10cSrcweir 						nNum >>= 8;
599*cdf0e10cSrcweir 						i++;
600*cdf0e10cSrcweir 						cAry[1] |= 0x40;
601*cdf0e10cSrcweir 					}
602*cdf0e10cSrcweir 					else
603*cdf0e10cSrcweir 						cAry[1] |= 0x30;
604*cdf0e10cSrcweir 				}
605*cdf0e10cSrcweir 				else
606*cdf0e10cSrcweir 					cAry[1] |= 0x20;
607*cdf0e10cSrcweir 			}
608*cdf0e10cSrcweir 			else
609*cdf0e10cSrcweir 				cAry[1] |= 0x10;
610*cdf0e10cSrcweir 		}
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir 		nNum = (sal_uInt32)(sal_Int32)rRect.nBottom;
613*cdf0e10cSrcweir 		if ( rRect.nBottom < 0 )
614*cdf0e10cSrcweir 		{
615*cdf0e10cSrcweir 			cAry[1] |= 0x08;
616*cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
617*cdf0e10cSrcweir 		}
618*cdf0e10cSrcweir 		if ( nNum )
619*cdf0e10cSrcweir 		{
620*cdf0e10cSrcweir 			cAry[i] = (unsigned char)(nNum & 0xFF);
621*cdf0e10cSrcweir 			nNum >>= 8;
622*cdf0e10cSrcweir 			i++;
623*cdf0e10cSrcweir 
624*cdf0e10cSrcweir 			if ( nNum )
625*cdf0e10cSrcweir 			{
626*cdf0e10cSrcweir 				cAry[i] = (unsigned char)(nNum & 0xFF);
627*cdf0e10cSrcweir 				nNum >>= 8;
628*cdf0e10cSrcweir 				i++;
629*cdf0e10cSrcweir 
630*cdf0e10cSrcweir 				if ( nNum )
631*cdf0e10cSrcweir 				{
632*cdf0e10cSrcweir 					cAry[i] = (unsigned char)(nNum & 0xFF);
633*cdf0e10cSrcweir 					nNum >>= 8;
634*cdf0e10cSrcweir 					i++;
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir 					if ( nNum )
637*cdf0e10cSrcweir 					{
638*cdf0e10cSrcweir 						cAry[i] = (unsigned char)(nNum & 0xFF);
639*cdf0e10cSrcweir 						nNum >>= 8;
640*cdf0e10cSrcweir 						i++;
641*cdf0e10cSrcweir 						cAry[1] |= 0x04;
642*cdf0e10cSrcweir 					}
643*cdf0e10cSrcweir 					else
644*cdf0e10cSrcweir 						cAry[1] |= 0x03;
645*cdf0e10cSrcweir 				}
646*cdf0e10cSrcweir 				else
647*cdf0e10cSrcweir 					cAry[1] |= 0x02;
648*cdf0e10cSrcweir 			}
649*cdf0e10cSrcweir 			else
650*cdf0e10cSrcweir 				cAry[1] |= 0x01;
651*cdf0e10cSrcweir 		}
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir 		rOStream.Write( cAry, i );
654*cdf0e10cSrcweir 	}
655*cdf0e10cSrcweir 	else
656*cdf0e10cSrcweir 	{
657*cdf0e10cSrcweir 		rOStream << rRect.nLeft << rRect.nTop << rRect.nRight << rRect.nBottom;
658*cdf0e10cSrcweir 	}
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir 	return rOStream;
661*cdf0e10cSrcweir }
662