1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "tp_Wizard_TitlesAndObjects.hxx"
21 #include <res_Titles.hxx>
22 #include <res_LegendPosition.hxx>
23 #include <ChartModel.hxx>
24 #include <Diagram.hxx>
25 #include <AxisHelper.hxx>
26 #include <ControllerLockGuard.hxx>
31 using namespace ::com::sun::star
;
32 using namespace ::com::sun::star::chart2
;
34 TitlesAndObjectsTabPage::TitlesAndObjectsTabPage(weld::Container
* pPage
, weld::DialogController
* pController
,
35 rtl::Reference
<::chart::ChartModel
> xChartModel
,
36 const uno::Reference
< uno::XComponentContext
>& xContext
)
37 : OWizardPage(pPage
, pController
, u
"modules/schart/ui/wizelementspage.ui"_ustr
, u
"WizElementsPage"_ustr
)
38 , m_xTitleResources(new TitleResources(*m_xBuilder
, false))
39 , m_xLegendPositionResources(new LegendPositionResources(*m_xBuilder
, xContext
))
40 , m_xChartModel(std::move(xChartModel
))
42 , m_bCommitToModel(true)
43 , m_aTimerTriggeredControllerLock( m_xChartModel
)
44 , m_xCB_Grid_X(m_xBuilder
->weld_check_button(u
"x"_ustr
))
45 , m_xCB_Grid_Y(m_xBuilder
->weld_check_button(u
"y"_ustr
))
46 , m_xCB_Grid_Z(m_xBuilder
->weld_check_button(u
"z"_ustr
))
48 m_xTitleResources
->connect_changed( LINK( this, TitlesAndObjectsTabPage
, ChangeEditHdl
));
49 m_xLegendPositionResources
->SetChangeHdl( LINK( this, TitlesAndObjectsTabPage
, ChangeHdl
));
51 m_xCB_Grid_X
->connect_toggled( LINK( this, TitlesAndObjectsTabPage
, ChangeCheckBoxHdl
));
52 m_xCB_Grid_Y
->connect_toggled( LINK( this, TitlesAndObjectsTabPage
, ChangeCheckBoxHdl
));
53 m_xCB_Grid_Z
->connect_toggled( LINK( this, TitlesAndObjectsTabPage
, ChangeCheckBoxHdl
));
56 TitlesAndObjectsTabPage::~TitlesAndObjectsTabPage()
60 void TitlesAndObjectsTabPage::initializePage()
62 m_bCommitToModel
= false;
66 TitleDialogData aTitleInput
;
67 aTitleInput
.readFromModel( m_xChartModel
);
68 m_xTitleResources
->writeToResources( aTitleInput
);
73 m_xLegendPositionResources
->writeToResources( m_xChartModel
);
76 //init grid checkboxes
78 rtl::Reference
< Diagram
> xDiagram
= m_xChartModel
->getFirstChartDiagram();
79 uno::Sequence
< sal_Bool
> aPossibilityList
;
80 uno::Sequence
< sal_Bool
> aExistenceList
;
81 AxisHelper::getAxisOrGridPossibilities( aPossibilityList
, xDiagram
, false );
82 AxisHelper::getAxisOrGridExistence( aExistenceList
, xDiagram
, false );
83 m_xCB_Grid_X
->set_sensitive( aPossibilityList
[0] );
84 m_xCB_Grid_Y
->set_sensitive( aPossibilityList
[1] );
85 m_xCB_Grid_Z
->set_sensitive( aPossibilityList
[2] );
86 m_xCB_Grid_X
->set_active( aExistenceList
[0] );
87 m_xCB_Grid_Y
->set_active( aExistenceList
[1] );
88 m_xCB_Grid_Z
->set_active( aExistenceList
[2] );
91 m_bCommitToModel
= true;
94 bool TitlesAndObjectsTabPage::commitPage( ::vcl::WizardTypes::CommitPageReason
/*eReason*/ )
96 if( m_xTitleResources
->get_value_changed_from_saved() ) //titles may have changed in the meanwhile
98 return true;//return false if this page should not be left
101 void TitlesAndObjectsTabPage::commitToModel()
103 m_aTimerTriggeredControllerLock
.startTimer();
104 rtl::Reference
<::chart::ChartModel
> xModel
= m_xChartModel
;
106 ControllerLockGuardUNO
aLockedControllers( xModel
);
108 //commit title changes to model
110 TitleDialogData aTitleOutput
;
111 m_xTitleResources
->readFromResources( aTitleOutput
);
112 aTitleOutput
.writeDifferenceToModel( xModel
, m_xCC
);
113 m_xTitleResources
->save_value();
116 //commit legend changes to model
118 m_xLegendPositionResources
->writeToModel( xModel
);
121 //commit grid changes to model
123 rtl::Reference
< Diagram
> xDiagram
= xModel
->getFirstChartDiagram();
124 uno::Sequence
< sal_Bool
> aOldExistenceList
;
125 AxisHelper::getAxisOrGridExistence( aOldExistenceList
, xDiagram
, false );
126 uno::Sequence
< sal_Bool
> aNewExistenceList(aOldExistenceList
);
127 sal_Bool
* pNewExistenceList
= aNewExistenceList
.getArray();
128 pNewExistenceList
[0] = m_xCB_Grid_X
->get_active();
129 pNewExistenceList
[1] = m_xCB_Grid_Y
->get_active();
130 pNewExistenceList
[2] = m_xCB_Grid_Z
->get_active();
131 AxisHelper::changeVisibilityOfGrids( xDiagram
132 , aOldExistenceList
, aNewExistenceList
);
136 IMPL_LINK_NOARG(TitlesAndObjectsTabPage
, ChangeCheckBoxHdl
, weld::Toggleable
&, void)
141 IMPL_LINK_NOARG(TitlesAndObjectsTabPage
, ChangeEditHdl
, weld::Entry
&, void)
146 IMPL_LINK_NOARG(TitlesAndObjectsTabPage
, ChangeHdl
, LinkParamNone
*, void)
148 if( m_bCommitToModel
)
152 bool TitlesAndObjectsTabPage::canAdvance() const
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */