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 : #include <limits.h>
22 : #include <osl/diagnose.h>
23 :
24 2204 : SwTabCols::SwTabCols( sal_uInt16 nSize ) :
25 : nLeftMin( 0 ),
26 : nLeft( 0 ),
27 : nRight( 0 ),
28 : nRightMax( 0 ),
29 2204 : bLastRowAllowedToChange( true )
30 : {
31 2204 : if ( nSize )
32 0 : aData.reserve( nSize );
33 2204 : }
34 :
35 1867 : SwTabCols::SwTabCols( const SwTabCols& rCpy ) :
36 1867 : nLeftMin( rCpy.GetLeftMin() ),
37 1867 : nLeft( rCpy.GetLeft() ),
38 1867 : nRight( rCpy.GetRight() ),
39 1867 : nRightMax( rCpy.GetRightMax() ),
40 1867 : bLastRowAllowedToChange( rCpy.IsLastRowAllowedToChange() ),
41 9335 : aData( rCpy.GetData() )
42 : {
43 : #if OSL_DEBUG_LEVEL > 0
44 : for ( size_t i = 0; i < Count(); ++i )
45 : {
46 : SwTabColsEntry aEntry1 = aData[i];
47 : SwTabColsEntry aEntry2 = rCpy.GetData()[i];
48 : (void) aEntry1;
49 : (void) aEntry2;
50 : OSL_ENSURE( aEntry1.nPos == aEntry2.nPos &&
51 : aEntry1.nMin == aEntry2.nMin &&
52 : aEntry1.nMax == aEntry2.nMax &&
53 : aEntry1.bHidden == aEntry2.bHidden,
54 : "CopyContructor of SwTabColsEntries did not succeed!" );
55 : }
56 : #endif
57 1867 : }
58 :
59 7 : SwTabCols &SwTabCols::operator=( const SwTabCols& rCpy )
60 : {
61 7 : nLeftMin = rCpy.GetLeftMin();
62 7 : nLeft = rCpy.GetLeft();
63 7 : nRight = rCpy.GetRight();
64 7 : nRightMax= rCpy.GetRightMax();
65 7 : bLastRowAllowedToChange = rCpy.IsLastRowAllowedToChange();
66 :
67 7 : Remove( 0, Count() );
68 7 : aData = rCpy.GetData();
69 :
70 7 : return *this;
71 : }
72 :
73 0 : bool SwTabCols::operator==( const SwTabCols& rCmp ) const
74 : {
75 0 : if ( !(nLeftMin == rCmp.GetLeftMin() &&
76 0 : nLeft == rCmp.GetLeft() &&
77 0 : nRight == rCmp.GetRight() &&
78 0 : nRightMax== rCmp.GetRightMax()&&
79 0 : bLastRowAllowedToChange== rCmp.IsLastRowAllowedToChange() &&
80 0 : Count()== rCmp.Count()) )
81 0 : return false;
82 :
83 0 : for ( size_t i = 0; i < Count(); ++i )
84 : {
85 0 : SwTabColsEntry aEntry1 = aData[i];
86 0 : SwTabColsEntry aEntry2 = rCmp.GetData()[i];
87 0 : if ( aEntry1.nPos != aEntry2.nPos || aEntry1.bHidden != aEntry2.bHidden )
88 0 : return false;
89 : }
90 :
91 0 : return true;
92 : }
93 :
94 3 : void SwTabCols::Insert( long nValue, long nMin, long nMax,
95 : sal_Bool bValue, size_t nPos )
96 : {
97 : SwTabColsEntry aEntry;
98 3 : aEntry.nPos = nValue;
99 3 : aEntry.nMin = nMin;
100 3 : aEntry.nMax = nMax;
101 3 : aEntry.bHidden = bValue;
102 3 : aData.insert( aData.begin() + nPos, aEntry );
103 3 : }
104 :
105 6771 : void SwTabCols::Insert( long nValue, sal_Bool bValue, size_t nPos )
106 : {
107 : SwTabColsEntry aEntry;
108 6771 : aEntry.nPos = nValue;
109 6771 : aEntry.nMin = 0;
110 6771 : aEntry.nMax = LONG_MAX;
111 6771 : aEntry.bHidden = bValue;
112 6771 : aData.insert( aData.begin() + nPos, aEntry );
113 :
114 : #if OSL_DEBUG_LEVEL > 1
115 : SwTabColsEntries::iterator aPos = aData.begin();
116 : for ( ; aPos != aData.end(); ++aPos )
117 : {
118 : aEntry =(*aPos);
119 : }
120 : #endif
121 6771 : }
122 :
123 4401 : void SwTabCols::Remove( size_t nPos, size_t nAnz )
124 : {
125 4401 : SwTabColsEntries::iterator aStart = aData.begin() + nPos;
126 4401 : aData.erase( aStart, aStart + nAnz );
127 4401 : }
128 :
129 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|