1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "oox/xls/richstringcontext.hxx"
29 
30 #include "oox/xls/stylesfragment.hxx"
31 
32 namespace oox {
33 namespace xls {
34 
35 // ============================================================================
36 
37 using ::oox::core::ContextHandlerRef;
38 using ::rtl::OUString;
39 
40 // ============================================================================
41 
42 ContextHandlerRef RichStringContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
43 {
44     if( isRootElement() )
45     {
46         switch( nElement )
47         {
48             case XLS_TOKEN( t ):
49                 mxPortion = mxString->importText( rAttribs );
50                 return this;    // collect text in onCharacters()
51             case XLS_TOKEN( r ):
52                 mxPortion = mxString->importRun( rAttribs );
53                 return this;
54             case XLS_TOKEN( rPh ):
55                 mxPhonetic = mxString->importPhoneticRun( rAttribs );
56                 return this;
57             case XLS_TOKEN( phoneticPr ):
58                 mxString->importPhoneticPr( rAttribs );
59             break;
60         }
61     }
62     else switch( getCurrentElement() )
63     {
64         case XLS_TOKEN( r ):
65             switch( nElement )
66             {
67                 case XLS_TOKEN( rPr ):
68                     if( mxPortion.get() )
69                         return new FontContext( *this, mxPortion->createFont() );
70                 break;
71 
72                 case XLS_TOKEN( t ):
73                     return this;    // collect portion text in onCharacters()
74             }
75         break;
76 
77         case XLS_TOKEN( rPh ):
78             switch( nElement )
79             {
80                 case XLS_TOKEN( t ):
81                     return this;    // collect phonetic text in onCharacters()
82             }
83         break;
84     }
85     return 0;
86 }
87 
88 void RichStringContext::onCharacters( const OUString& rChars )
89 {
90     if( isCurrentElement( XLS_TOKEN( t ) ) ) switch( getParentElement() )
91     {
92         case XLS_TOKEN( rPh ):
93             if( mxPhonetic.get() )
94                 mxPhonetic->setText( rChars );
95         break;
96         default:
97             if( mxPortion.get() )
98                 mxPortion->setText( rChars );
99     }
100 }
101 
102 // ============================================================================
103 
104 } // namespace xls
105 } // namespace oox
106