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