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 : * Frame whose anchor is not page.
59 : ************************************************************************/
60 : #include "xfframe.hxx"
61 : #include "xfparagraph.hxx"
62 : #define ZINDEX_MIN 0
63 0 : XFFrame::XFFrame()
64 : {
65 0 : m_isTextBox = sal_False;
66 0 : m_eAnchor = enumXFAnchorPara;
67 0 : m_nAnchorPage = 0;
68 0 : m_nZIndex = ZINDEX_MIN;
69 : //give it a default name:
70 0 : m_strName = XFGlobal::GenFrameName();
71 0 : m_fMinHeight = 0;
72 0 : m_fMaxHeight = 0;
73 0 : m_nFlag = 0;
74 0 : m_eType = enumXFFrameTextbox;
75 0 : }
76 0 : XFFrame::XFFrame(sal_Bool isTextBox):m_isTextBox(isTextBox)
77 : {
78 0 : m_eAnchor = enumXFAnchorPara;
79 0 : m_nAnchorPage = 0;
80 0 : m_nZIndex = ZINDEX_MIN;
81 : //give it a default name:
82 0 : m_strName = XFGlobal::GenFrameName();
83 0 : m_fMinHeight = 0;
84 0 : m_fMaxHeight = 0;
85 0 : m_nFlag = 0;
86 0 : m_eType = enumXFFrameTextbox;
87 0 : }
88 :
89 0 : XFFrame::~XFFrame()
90 : {
91 0 : }
92 :
93 0 : void XFFrame::Add(IXFContent *pContent)
94 : {
95 0 : if (!pContent)
96 0 : return;
97 0 : XFContentContainer::Add(pContent);
98 0 : if( pContent->GetContentType() == enumXFContentFrame )
99 : {
100 0 : XFFrame *pFrame = (XFFrame*)pContent;
101 0 : if( pFrame )
102 : {
103 0 : pFrame->SetZIndex(pFrame->m_nZIndex + 1);
104 : }
105 : }
106 :
107 : }
108 :
109 0 : void XFFrame::SetZIndex(sal_uInt32 zIndex)
110 : {
111 0 : if( zIndex == m_nZIndex )
112 0 : return;
113 0 : m_nZIndex = zIndex;
114 0 : AdjustZIndex();
115 : }
116 :
117 0 : enumXFFrameType XFFrame::GetFrameType()
118 : {
119 0 : return m_eType;
120 : }
121 :
122 0 : enumXFContent XFFrame::GetContentType()
123 : {
124 0 : return enumXFContentFrame;
125 : }
126 :
127 0 : void XFFrame::ToXml(IXFStream *pStrm)
128 : {
129 0 : StartFrame(pStrm);
130 :
131 0 : XFContentContainer::ToXml(pStrm);
132 :
133 0 : EndFrame(pStrm);
134 0 : }
135 :
136 0 : void XFFrame::StartFrame(IXFStream *pStrm)
137 : {
138 0 : IXFAttrList *pAttrList = pStrm->GetAttrList();
139 :
140 0 : if( !GetStyleName().isEmpty() )
141 0 : pAttrList->AddAttribute( "draw:style-name", GetStyleName() );
142 :
143 : assert(!m_strName.isEmpty()); //name should not be null.
144 0 : if( !m_strName.isEmpty() && m_isTextBox == sal_False)
145 0 : pAttrList->AddAttribute( "draw:name", m_strName );
146 : //anchor type:
147 0 : switch( m_eAnchor )
148 : {
149 : case enumXFAnchorPara:
150 0 : pAttrList->AddAttribute( "text:anchor-type", "paragraph" );
151 0 : break;
152 : case enumXFAnchorPage:
153 0 : pAttrList->AddAttribute( "text:anchor-type", "page" );
154 0 : pAttrList->AddAttribute( "text:anchor-page-number", OUString::number(m_nAnchorPage) );
155 0 : break;
156 : case enumXFAnchorChar:
157 0 : pAttrList->AddAttribute( "text:anchor-type", "char" );
158 0 : break;
159 : case enumXFAnchorAsChar:
160 0 : pAttrList->AddAttribute( "text:anchor-type", "as-char" );
161 0 : break;
162 : case enumXFAnchorFrame:
163 0 : pAttrList->AddAttribute( "text:anchor-type", "frame" );
164 0 : break;
165 : default:
166 0 : break;
167 : }
168 0 : pAttrList->AddAttribute( "svg:x", OUString::number(m_aRect.GetX()) + "cm" );
169 0 : pAttrList->AddAttribute( "svg:y", OUString::number(m_aRect.GetY()) + "cm" );
170 0 : pAttrList->AddAttribute( "svg:width", OUString::number(m_aRect.GetWidth()) + "cm" );
171 0 : if( m_nFlag& XFFRAME_FLAG_MINHEIGHT )
172 : {
173 0 : pAttrList->AddAttribute( "fo:min-height", OUString::number(m_fMinHeight) + "cm" );
174 0 : if( m_nFlag&XFFRAME_FLAG_MAXHEIGHT )
175 0 : pAttrList->AddAttribute( "fo:max-height", OUString::number(m_fMaxHeight) + "cm" );
176 : }
177 : else
178 0 : pAttrList->AddAttribute( "svg:height", OUString::number(m_aRect.GetHeight()) + "cm" );
179 :
180 0 : pAttrList->AddAttribute( "draw:z-index", OUString::number(m_nZIndex) );
181 :
182 0 : if( !m_strNextLink.isEmpty() )
183 0 : pAttrList->AddAttribute( "draw:chain-next-name", m_strNextLink );
184 :
185 0 : pStrm->StartElement( "draw:text-box" );
186 0 : }
187 :
188 0 : void XFFrame::EndFrame(IXFStream *pStrm)
189 : {
190 0 : pStrm->EndElement( "draw:text-box" );
191 0 : }
192 :
193 0 : void XFFrame::AdjustZIndex()
194 : {
195 0 : for( int i=0; i<GetCount(); i++ )
196 : {
197 0 : IXFContent *pContent = GetContent(i);
198 0 : if( pContent )
199 : {
200 0 : if( pContent->GetContentType() == enumXFContentFrame )
201 : {
202 0 : XFFrame *pFrame = (XFFrame*)pContent;
203 0 : pFrame->m_nZIndex = m_nZIndex + 1;
204 0 : pFrame->AdjustZIndex();
205 : }
206 : }
207 : }
208 0 : }
209 :
210 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|