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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 
31 #include "TitleDialogData.hxx"
32 #include "TitleHelper.hxx"
33 #include "ChartModelHelper.hxx"
34 #include "AxisHelper.hxx"
35 
36 //.............................................................................
37 namespace chart
38 {
39 //.............................................................................
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::chart2;
42 
43 TitleDialogData::TitleDialogData( ::std::auto_ptr< ReferenceSizeProvider > apRefSizeProvider )
44         : aPossibilityList(7)
45         , aExistenceList(7)
46         , aTextList(7)
47         , apReferenceSizeProvider( apRefSizeProvider )
48 {
49     sal_Int32 nN = 0;
50     for(nN=7;nN--;)
51         aPossibilityList[nN]=sal_True;
52     for(nN=7;nN--;)
53         aExistenceList[nN]=sal_False;
54 }
55 
56 void TitleDialogData::readFromModel( const uno::Reference< frame::XModel>& xChartModel )
57 {
58     uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram(xChartModel);
59 
60     //get possibilities
61     uno::Sequence< sal_Bool > aAxisPossibilityList;
62     AxisHelper::getAxisOrGridPossibilities( aAxisPossibilityList, xDiagram );
63     this->aPossibilityList[2]=aAxisPossibilityList[0];//x axis title
64     this->aPossibilityList[3]=aAxisPossibilityList[1];//y axis title
65     this->aPossibilityList[4]=aAxisPossibilityList[2];//z axis title
66     this->aPossibilityList[5]=aAxisPossibilityList[3];//secondary x axis title
67     this->aPossibilityList[6]=aAxisPossibilityList[4];//secondary y axis title
68 
69     //find out which title exsist and get their text
70     //main title:
71     for( sal_Int32 nTitleIndex = static_cast< sal_Int32 >( TitleHelper::TITLE_BEGIN);
72          nTitleIndex < static_cast< sal_Int32 >( TitleHelper::NORMAL_TITLE_END );
73          nTitleIndex++)
74     {
75         uno::Reference< XTitle > xTitle =  TitleHelper::getTitle(
76             static_cast< TitleHelper::eTitleType >( nTitleIndex ), xChartModel );
77         this->aExistenceList[nTitleIndex] = xTitle.is();
78         this->aTextList[nTitleIndex]=TitleHelper::getCompleteString( xTitle );
79     }
80 }
81 
82 bool TitleDialogData::writeDifferenceToModel(
83                           const uno::Reference< frame::XModel >& xChartModel
84                         , const uno::Reference< uno::XComponentContext >& xContext
85                         , TitleDialogData* pOldState )
86 {
87     bool bChanged = false;
88     for( sal_Int32 nN = static_cast< sal_Int32 >( TitleHelper::TITLE_BEGIN );
89          nN < static_cast< sal_Int32 >( TitleHelper::NORMAL_TITLE_END );
90          nN++)
91     {
92         if( !pOldState || ( pOldState->aExistenceList[nN] != this->aExistenceList[nN] ) )
93         {
94             if(this->aExistenceList[nN])
95             {
96                 TitleHelper::createTitle(
97                     static_cast< TitleHelper::eTitleType >( nN ), this->aTextList[nN], xChartModel, xContext,
98                     apReferenceSizeProvider.get() );
99                 bChanged = true;
100             }
101             else
102             {
103                 TitleHelper::removeTitle( static_cast< TitleHelper::eTitleType >( nN ), xChartModel );
104                 bChanged = true;
105             }
106         }
107         else if( !pOldState || ( pOldState->aTextList[nN] != this->aTextList[nN] ) )
108         {
109             //change content
110             uno::Reference< XTitle > xTitle(
111                 TitleHelper::getTitle( static_cast< TitleHelper::eTitleType >( nN ), xChartModel ) );
112             if(xTitle.is())
113             {
114                 TitleHelper::setCompleteString( this->aTextList[nN], xTitle, xContext );
115                 bChanged = true;
116             }
117         }
118     }
119     return bChanged;
120 }
121 
122 //.............................................................................
123 } //namespace chart
124 //.............................................................................
125