Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "tabcol.hxx"
21 :
22 : #include <limits.h>
23 : #include <osl/diagnose.h>
24 :
25 204 : SwTabCols::SwTabCols( sal_uInt16 nSize ) :
26 : nLeftMin( 0 ),
27 : nLeft( 0 ),
28 : nRight( 0 ),
29 : nRightMax( 0 ),
30 204 : bLastRowAllowedToChange( true )
31 : {
32 204 : if ( nSize )
33 0 : aData.reserve( nSize );
34 204 : }
35 :
36 156 : SwTabCols::SwTabCols( const SwTabCols& rCpy ) :
37 156 : nLeftMin( rCpy.GetLeftMin() ),
38 156 : nLeft( rCpy.GetLeft() ),
39 156 : nRight( rCpy.GetRight() ),
40 156 : nRightMax( rCpy.GetRightMax() ),
41 156 : bLastRowAllowedToChange( rCpy.IsLastRowAllowedToChange() ),
42 780 : aData( rCpy.GetData() )
43 : {
44 : #if OSL_DEBUG_LEVEL > 0
45 : for ( sal_uInt16 i = 0; i < Count(); ++i )
46 : {
47 : SwTabColsEntry aEntry1 = aData[i];
48 : SwTabColsEntry aEntry2 = rCpy.GetData()[i];
49 : (void) aEntry1;
50 : (void) aEntry2;
51 : OSL_ENSURE( aEntry1.nPos == aEntry2.nPos &&
52 : aEntry1.nMin == aEntry2.nMin &&
53 : aEntry1.nMax == aEntry2.nMax &&
54 : aEntry1.bHidden == aEntry2.bHidden,
55 : "CopyContructor of SwTabColsEntries did not succeed!" );
56 : }
57 : #endif
58 156 : }
59 :
60 22 : SwTabCols &SwTabCols::operator=( const SwTabCols& rCpy )
61 : {
62 22 : nLeftMin = rCpy.GetLeftMin();
63 22 : nLeft = rCpy.GetLeft();
64 22 : nRight = rCpy.GetRight();
65 22 : nRightMax= rCpy.GetRightMax();
66 22 : bLastRowAllowedToChange = rCpy.IsLastRowAllowedToChange();
67 :
68 22 : Remove( 0, Count() );
69 22 : aData = rCpy.GetData();
70 :
71 22 : return *this;
72 : }
73 :
74 0 : bool SwTabCols::operator==( const SwTabCols& rCmp ) const
75 : {
76 : sal_uInt16 i;
77 :
78 0 : if ( !(nLeftMin == rCmp.GetLeftMin() &&
79 0 : nLeft == rCmp.GetLeft() &&
80 0 : nRight == rCmp.GetRight() &&
81 0 : nRightMax== rCmp.GetRightMax()&&
82 0 : bLastRowAllowedToChange== rCmp.IsLastRowAllowedToChange() &&
83 0 : Count()== rCmp.Count()) )
84 0 : return false;
85 :
86 0 : for ( i = 0; i < Count(); ++i )
87 : {
88 0 : SwTabColsEntry aEntry1 = aData[i];
89 0 : SwTabColsEntry aEntry2 = rCmp.GetData()[i];
90 0 : if ( aEntry1.nPos != aEntry2.nPos || aEntry1.bHidden != aEntry2.bHidden )
91 0 : return sal_False;
92 : }
93 :
94 0 : return true;
95 : }
96 :
97 38 : void SwTabCols::Insert( long nValue, long nMin, long nMax,
98 : sal_Bool bValue, sal_uInt16 nPos )
99 : {
100 : SwTabColsEntry aEntry;
101 38 : aEntry.nPos = nValue;
102 38 : aEntry.nMin = nMin;
103 38 : aEntry.nMax = nMax;
104 38 : aEntry.bHidden = bValue;
105 38 : aData.insert( aData.begin() + nPos, aEntry );
106 38 : }
107 :
108 604 : void SwTabCols::Insert( long nValue, sal_Bool bValue, sal_uInt16 nPos )
109 : {
110 : SwTabColsEntry aEntry;
111 604 : aEntry.nPos = nValue;
112 604 : aEntry.nMin = 0;
113 604 : aEntry.nMax = LONG_MAX;
114 604 : aEntry.bHidden = bValue;
115 604 : aData.insert( aData.begin() + nPos, aEntry );
116 :
117 : #if OSL_DEBUG_LEVEL > 1
118 : SwTabColsEntries::iterator aPos = aData.begin();
119 : for ( ; aPos != aData.end(); ++aPos )
120 : {
121 : aEntry =(*aPos);
122 : }
123 : #endif
124 604 : }
125 :
126 386 : void SwTabCols::Remove( sal_uInt16 nPos, sal_uInt16 nAnz )
127 : {
128 386 : SwTabColsEntries::iterator aStart = aData.begin() + nPos;
129 386 : aData.erase( aStart, aStart + nAnz );
130 386 : }
131 :
132 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|