1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 
27 #include "TitleDialogData.hxx"
28 #include "TitleHelper.hxx"
29 #include "ChartModelHelper.hxx"
30 #include "AxisHelper.hxx"
31 
32 //.............................................................................
33 namespace chart
34 {
35 //.............................................................................
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::chart2;
38 
TitleDialogData(::std::auto_ptr<ReferenceSizeProvider> apRefSizeProvider)39 TitleDialogData::TitleDialogData( ::std::auto_ptr< ReferenceSizeProvider > apRefSizeProvider )
40         : aPossibilityList(7)
41         , aExistenceList(7)
42         , aTextList(7)
43         , apReferenceSizeProvider( apRefSizeProvider )
44 {
45     sal_Int32 nN = 0;
46     for(nN=7;nN--;)
47         aPossibilityList[nN]=sal_True;
48     for(nN=7;nN--;)
49         aExistenceList[nN]=sal_False;
50 }
51 
readFromModel(const uno::Reference<frame::XModel> & xChartModel)52 void TitleDialogData::readFromModel( const uno::Reference< frame::XModel>& xChartModel )
53 {
54     uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram(xChartModel);
55 
56     //get possibilities
57     uno::Sequence< sal_Bool > aAxisPossibilityList;
58     AxisHelper::getAxisOrGridPossibilities( aAxisPossibilityList, xDiagram );
59     this->aPossibilityList[2]=aAxisPossibilityList[0];//x axis title
60     this->aPossibilityList[3]=aAxisPossibilityList[1];//y axis title
61     this->aPossibilityList[4]=aAxisPossibilityList[2];//z axis title
62     this->aPossibilityList[5]=aAxisPossibilityList[3];//secondary x axis title
63     this->aPossibilityList[6]=aAxisPossibilityList[4];//secondary y axis title
64 
65     //find out which title exsist and get their text
66     //main title:
67     for( sal_Int32 nTitleIndex = static_cast< sal_Int32 >( TitleHelper::TITLE_BEGIN);
68          nTitleIndex < static_cast< sal_Int32 >( TitleHelper::NORMAL_TITLE_END );
69          nTitleIndex++)
70     {
71         uno::Reference< XTitle > xTitle =  TitleHelper::getTitle(
72             static_cast< TitleHelper::eTitleType >( nTitleIndex ), xChartModel );
73         this->aExistenceList[nTitleIndex] = xTitle.is();
74         this->aTextList[nTitleIndex]=TitleHelper::getCompleteString( xTitle );
75     }
76 }
77 
writeDifferenceToModel(const uno::Reference<frame::XModel> & xChartModel,const uno::Reference<uno::XComponentContext> & xContext,TitleDialogData * pOldState)78 bool TitleDialogData::writeDifferenceToModel(
79                           const uno::Reference< frame::XModel >& xChartModel
80                         , const uno::Reference< uno::XComponentContext >& xContext
81                         , TitleDialogData* pOldState )
82 {
83     bool bChanged = false;
84     for( sal_Int32 nN = static_cast< sal_Int32 >( TitleHelper::TITLE_BEGIN );
85          nN < static_cast< sal_Int32 >( TitleHelper::NORMAL_TITLE_END );
86          nN++)
87     {
88         if( !pOldState || ( pOldState->aExistenceList[nN] != this->aExistenceList[nN] ) )
89         {
90             if(this->aExistenceList[nN])
91             {
92                 TitleHelper::createTitle(
93                     static_cast< TitleHelper::eTitleType >( nN ), this->aTextList[nN], xChartModel, xContext,
94                     apReferenceSizeProvider.get() );
95                 bChanged = true;
96             }
97             else
98             {
99                 TitleHelper::removeTitle( static_cast< TitleHelper::eTitleType >( nN ), xChartModel );
100                 bChanged = true;
101             }
102         }
103         else if( !pOldState || ( pOldState->aTextList[nN] != this->aTextList[nN] ) )
104         {
105             //change content
106             uno::Reference< XTitle > xTitle(
107                 TitleHelper::getTitle( static_cast< TitleHelper::eTitleType >( nN ), xChartModel ) );
108             if(xTitle.is())
109             {
110                 TitleHelper::setCompleteString( this->aTextList[nN], xTitle, xContext );
111                 bChanged = true;
112             }
113         }
114     }
115     return bChanged;
116 }
117 
118 //.............................................................................
119 } //namespace chart
120 //.............................................................................
121