Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * The Contents of this file are made available subject to the terms of
5 : * either of the following licenses
6 : *
7 : * - GNU Lesser General Public License Version 2.1
8 : * - Sun Industry Standards Source License Version 1.1
9 : *
10 : * Sun Microsystems Inc., October, 2000
11 : *
12 : * GNU Lesser General Public License Version 2.1
13 : * =============================================
14 : * Copyright 2000 by Sun Microsystems, Inc.
15 : * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 : *
17 : * This library is free software; you can redistribute it and/or
18 : * modify it under the terms of the GNU Lesser General Public
19 : * License version 2.1, as published by the Free Software Foundation.
20 : *
21 : * This library is distributed in the hope that it will be useful,
22 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 : * Lesser General Public License for more details.
25 : *
26 : * You should have received a copy of the GNU Lesser General Public
27 : * License along with this library; if not, write to the Free Software
28 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 : * MA 02111-1307 USA
30 : *
31 : *
32 : * Sun Industry Standards Source License Version 1.1
33 : * =================================================
34 : * The contents of this file are subject to the Sun Industry Standards
35 : * Source License Version 1.1 (the "License"); You may not use this file
36 : * except in compliance with the License. You may obtain a copy of the
37 : * License at http://www.openoffice.org/license.html.
38 : *
39 : * Software provided under this License is provided on an "AS IS" basis,
40 : * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 : * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 : * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 : * See the License for the specific provisions governing your rights and
44 : * obligations concerning the Software.
45 : *
46 : * The Initial Developer of the Original Code is: IBM Corporation
47 : *
48 : * Copyright: 2008 by IBM Corporation
49 : *
50 : * All Rights Reserved.
51 : *
52 : * Contributor(s): _______________________________________
53 : *
54 : *
55 : ************************************************************************/
56 : /*************************************************************************
57 : * @file
58 : * Container for content.It will destroy all children when destroy.
59 : ************************************************************************/
60 : #include "xfcontentcontainer.hxx"
61 : #include "xftextcontent.hxx"
62 :
63 263 : XFContentContainer::XFContentContainer()
64 : {
65 263 : }
66 :
67 0 : XFContentContainer::XFContentContainer(const XFContentContainer& other):XFContent(other)
68 : {
69 0 : std::vector<IXFContent*>::const_iterator it;
70 :
71 0 : for( it = other.m_aContents.begin(); it != other.m_aContents.end(); ++it )
72 : {
73 0 : IXFContent *pContent = *it;
74 0 : if( pContent )
75 : {
76 0 : IXFContent *pClone = pContent->Clone();
77 0 : if( pClone )
78 0 : Add(pClone);
79 : }
80 : }
81 0 : }
82 :
83 0 : XFContentContainer& XFContentContainer::operator=(const XFContentContainer& other)
84 : {
85 0 : std::vector<IXFContent*>::const_iterator it;
86 :
87 0 : for( it = other.m_aContents.begin(); it != other.m_aContents.end(); ++it )
88 : {
89 0 : IXFContent *pContent = *it;
90 0 : if( pContent )
91 : {
92 0 : IXFContent *pClone = pContent->Clone();
93 0 : if( pClone )
94 0 : Add(pClone);
95 : }
96 : }
97 0 : return *this;
98 : }
99 :
100 526 : XFContentContainer::~XFContentContainer()
101 : {
102 260 : std::vector<IXFContent*>::iterator it;
103 :
104 688 : for( it = m_aContents.begin(); it != m_aContents.end(); ++it )
105 : {
106 428 : IXFContent *pContent = *it;
107 428 : delete pContent;
108 : }
109 266 : }
110 :
111 429 : void XFContentContainer::Add(IXFContent *pContent)
112 : {
113 429 : m_aContents.push_back(pContent);
114 429 : }
115 :
116 0 : void XFContentContainer::InsertAtBegin(IXFContent * pContent)
117 : {
118 0 : m_aContents.insert(m_aContents.begin(), pContent);
119 0 : }
120 0 : void XFContentContainer::RemoveAt(sal_uInt32 nPos)
121 : {
122 0 : m_aContents.erase(m_aContents.begin()+nPos);
123 0 : }
124 0 : void XFContentContainer::Add(const OUString& text)
125 : {
126 0 : XFTextContent *pTC = new XFTextContent();
127 0 : pTC->SetText(text);
128 0 : Add(pTC);
129 0 : }
130 :
131 18 : int XFContentContainer::GetCount() const
132 : {
133 18 : return m_aContents.size();
134 : }
135 :
136 0 : void XFContentContainer::Reset()
137 : {
138 0 : std::vector<IXFContent*>::iterator it;
139 :
140 0 : for( it = m_aContents.begin(); it != m_aContents.end(); ++it )
141 : {
142 0 : IXFContent *pContent = *it;
143 0 : if( pContent )
144 0 : delete pContent;
145 : }
146 0 : m_aContents.clear();
147 0 : }
148 :
149 0 : IXFContent* XFContentContainer::FindFirstContent(enumXFContent type)
150 : {
151 0 : IXFContent *pRet = NULL;
152 0 : IXFContent *pContent = NULL;
153 :
154 0 : for( int i=0; i<GetCount(); i++ )
155 : {
156 0 : pContent = GetContent(i);
157 0 : if( !pContent )
158 0 : continue;
159 :
160 0 : enumXFContent eType = pContent->GetContentType();
161 0 : if( eType == type )
162 0 : return pContent;
163 : else
164 : {
165 0 : XFContentContainer *pChildCont = static_cast<XFContentContainer*>(pContent);
166 0 : if( pChildCont )
167 : {
168 0 : pRet = pChildCont->FindFirstContent(type);
169 0 : if( pRet )
170 0 : return pRet;
171 : }
172 : }
173 : }
174 0 : return pRet;
175 : }
176 :
177 0 : enumXFContent XFContentContainer::GetContentType()
178 : {
179 0 : return enumXFContentContainer;
180 : }
181 :
182 223 : void XFContentContainer::ToXml(IXFStream *pStrm)
183 : {
184 223 : std::vector<IXFContent*>::iterator it;
185 :
186 631 : for( it = m_aContents.begin(); it != m_aContents.end(); ++it )
187 : {
188 408 : IXFContent *pContent = *it;
189 408 : if( pContent )
190 408 : pContent->ToXml(pStrm);
191 : }
192 223 : }
193 :
194 1 : IXFContent* XFContentContainer::GetLastContent()
195 : {
196 1 : sal_uInt32 index = m_aContents.size()-1;
197 1 : if(index >0)
198 : {
199 1 : return m_aContents[index];
200 : }
201 :
202 0 : return NULL;
203 : }
204 :
205 1 : void XFContentContainer::RemoveLastContent()
206 : {
207 1 : sal_uInt32 index = m_aContents.size()-1;
208 1 : if(index >0)
209 : {
210 1 : m_aContents.erase(m_aContents.begin() + index);
211 : }
212 1 : }
213 :
214 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|