1*9e0e4191SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9e0e4191SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9e0e4191SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9e0e4191SAndrew Rist  * distributed with this work for additional information
6*9e0e4191SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9e0e4191SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9e0e4191SAndrew Rist  * "License"); you may not use this file except in compliance
9*9e0e4191SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9e0e4191SAndrew Rist  *
11*9e0e4191SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9e0e4191SAndrew Rist  *
13*9e0e4191SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9e0e4191SAndrew Rist  * software distributed under the License is distributed on an
15*9e0e4191SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9e0e4191SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9e0e4191SAndrew Rist  * specific language governing permissions and limitations
18*9e0e4191SAndrew Rist  * under the License.
19*9e0e4191SAndrew Rist  *
20*9e0e4191SAndrew Rist  *************************************************************/
21*9e0e4191SAndrew Rist 
22*9e0e4191SAndrew Rist 
23cdf0e10cSrcweir #include "precompiled_reportdesign.hxx"
24cdf0e10cSrcweir #include "PageNumber.hxx"
25cdf0e10cSrcweir #ifndef RPTUI_PAGENUMBER_HRC
26cdf0e10cSrcweir #include "PageNumber.hrc"
27cdf0e10cSrcweir #endif
28cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
29cdf0e10cSrcweir #include <tools/debug.hxx>
30cdf0e10cSrcweir #ifndef _RPTUI_DLGRESID_HRC
31cdf0e10cSrcweir #include "RptResId.hrc"
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #ifndef _RPTUI_SLOTID_HRC_
34cdf0e10cSrcweir #include "rptui_slotid.hrc"
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #ifndef _RPTUI_MODULE_HELPER_DBU_HXX_
37cdf0e10cSrcweir #include "ModuleHelper.hxx"
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #include "RptDef.hxx"
40cdf0e10cSrcweir #ifndef RTPUI_REPORTDESIGN_HELPID_HRC
41cdf0e10cSrcweir #include "helpids.hrc"
42cdf0e10cSrcweir #endif
43cdf0e10cSrcweir #include <vcl/msgbox.hxx>
44cdf0e10cSrcweir #ifndef _GLOBLMN_HRC
45cdf0e10cSrcweir #include <svx/globlmn.hrc>
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir #ifndef _SBASLTID_HRC
48cdf0e10cSrcweir #include <svx/svxids.hrc>
49cdf0e10cSrcweir #endif
50cdf0e10cSrcweir #ifndef RPTUI_TOOLS_HXX
51cdf0e10cSrcweir #include "UITools.hxx"
52cdf0e10cSrcweir #endif
53cdf0e10cSrcweir #ifndef REPORTDESIGN_SHARED_UISTRINGS_HRC
54cdf0e10cSrcweir #include "uistrings.hrc"
55cdf0e10cSrcweir #endif
56cdf0e10cSrcweir #include "ReportController.hxx"
57cdf0e10cSrcweir #include <com/sun/star/report/XFixedText.hpp>
58cdf0e10cSrcweir #include <algorithm>
59cdf0e10cSrcweir 
60cdf0e10cSrcweir namespace rptui
61cdf0e10cSrcweir {
62cdf0e10cSrcweir using namespace ::com::sun::star;
63cdf0e10cSrcweir using namespace ::comphelper;
64cdf0e10cSrcweir 
DBG_NAME(rpt_OPageNumberDialog)65cdf0e10cSrcweir DBG_NAME( rpt_OPageNumberDialog )
66cdf0e10cSrcweir //========================================================================
67cdf0e10cSrcweir // class OPageNumberDialog
68cdf0e10cSrcweir //========================================================================
69cdf0e10cSrcweir OPageNumberDialog::OPageNumberDialog( Window* _pParent
70cdf0e10cSrcweir 										   ,const uno::Reference< report::XReportDefinition >& _xHoldAlive
71cdf0e10cSrcweir 										   ,OReportController* _pController)
72cdf0e10cSrcweir 	: ModalDialog( _pParent, ModuleRes(RID_PAGENUMBERS) )
73cdf0e10cSrcweir 	,m_aFormat(this, ModuleRes(FL_FORMAT) )
74cdf0e10cSrcweir 	,m_aPageN(this, ModuleRes(RB_PAGE_N) )
75cdf0e10cSrcweir 	,m_aPageNofM(this, ModuleRes(RB_PAGE_N_OF_M) )
76cdf0e10cSrcweir 	,m_aPosition(this, ModuleRes(FL_POSITION) )
77cdf0e10cSrcweir 	,m_aTopPage(this, ModuleRes(RB_PAGE_TOPPAGE) )
78cdf0e10cSrcweir 	,m_aBottomPage(this, ModuleRes(RB_PAGE_BOTTOMPAGE) )
79cdf0e10cSrcweir 	,m_aMisc(this, ModuleRes(FL_MISC) )
80cdf0e10cSrcweir 	,m_aAlignment(this, ModuleRes(FL_ALIGNMENT) )
81cdf0e10cSrcweir 	,m_aAlignmentLst(this, ModuleRes(LST_ALIGNMENT) )
82cdf0e10cSrcweir 	,m_aShowNumberOnFirstPage(this, ModuleRes(CB_SHOWNUMBERONFIRSTPAGE) )
83cdf0e10cSrcweir 	,m_aFl1(this,		ModuleRes(FL_SEPARATOR1))
84cdf0e10cSrcweir 	,m_aPB_OK(this,		ModuleRes(PB_OK))
85cdf0e10cSrcweir 	,m_aPB_CANCEL(this,	ModuleRes(PB_CANCEL))
86cdf0e10cSrcweir 	,m_aPB_Help(this,	ModuleRes(PB_HELP))
87cdf0e10cSrcweir 	,m_pController(_pController)
88cdf0e10cSrcweir 	,m_xHoldAlive(_xHoldAlive)
89cdf0e10cSrcweir {
90cdf0e10cSrcweir 	DBG_CTOR( rpt_OPageNumberDialog,NULL);
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     m_aShowNumberOnFirstPage.Hide();
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	FreeResource();
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir //------------------------------------------------------------------------
~OPageNumberDialog()98cdf0e10cSrcweir OPageNumberDialog::~OPageNumberDialog()
99cdf0e10cSrcweir {
100cdf0e10cSrcweir 	DBG_DTOR( rpt_OPageNumberDialog,NULL);
101cdf0e10cSrcweir }
102cdf0e10cSrcweir // -----------------------------------------------------------------------------
Execute()103cdf0e10cSrcweir short OPageNumberDialog::Execute()
104cdf0e10cSrcweir {
105cdf0e10cSrcweir 	short nRet = ModalDialog::Execute();
106cdf0e10cSrcweir 	if ( nRet == RET_OK )
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir 		try
109cdf0e10cSrcweir 		{
110cdf0e10cSrcweir 			sal_Int32 nControlMaxSize = 3000;
111cdf0e10cSrcweir 			sal_Int32 nPosX = 0;
112cdf0e10cSrcweir 			sal_Int32 nPos2X = 0;
113cdf0e10cSrcweir 			awt::Size aRptSize = getStyleProperty<awt::Size>(m_xHoldAlive,PROPERTY_PAPERSIZE);
114cdf0e10cSrcweir 			switch ( m_aAlignmentLst.GetSelectEntryPos() )
115cdf0e10cSrcweir 			{
116cdf0e10cSrcweir 				case 0: // left
117cdf0e10cSrcweir 					nPosX = getStyleProperty<sal_Int32>(m_xHoldAlive,PROPERTY_LEFTMARGIN);
118cdf0e10cSrcweir 					break;
119cdf0e10cSrcweir 				case 1: // middle
120cdf0e10cSrcweir 					nPosX = getStyleProperty<sal_Int32>(m_xHoldAlive,PROPERTY_LEFTMARGIN) + (aRptSize.Width - getStyleProperty<sal_Int32>(m_xHoldAlive,PROPERTY_LEFTMARGIN) - getStyleProperty<sal_Int32>(m_xHoldAlive,PROPERTY_RIGHTMARGIN) - nControlMaxSize) / 2;
121cdf0e10cSrcweir 					break;
122cdf0e10cSrcweir 				case 2: // right
123cdf0e10cSrcweir 					nPosX = (aRptSize.Width - getStyleProperty<sal_Int32>(m_xHoldAlive,PROPERTY_RIGHTMARGIN) - nControlMaxSize);
124cdf0e10cSrcweir 					break;
125cdf0e10cSrcweir 				case 3: // inner
126cdf0e10cSrcweir 				case 4: // outer
127cdf0e10cSrcweir 					nPosX = getStyleProperty<sal_Int32>(m_xHoldAlive,PROPERTY_LEFTMARGIN);
128cdf0e10cSrcweir 					nPos2X = (aRptSize.Width - getStyleProperty<sal_Int32>(m_xHoldAlive,PROPERTY_RIGHTMARGIN) - nControlMaxSize);
129cdf0e10cSrcweir 					break;
130cdf0e10cSrcweir                 default:
131cdf0e10cSrcweir                     break;
132cdf0e10cSrcweir 			}
133cdf0e10cSrcweir             if ( m_aAlignmentLst.GetSelectEntryPos() > 2 )
134cdf0e10cSrcweir                 nPosX = nPos2X;
135cdf0e10cSrcweir 
136cdf0e10cSrcweir             sal_Int32 nLength = 0;
137cdf0e10cSrcweir             uno::Sequence<beans::PropertyValue> aValues( 3 );
138cdf0e10cSrcweir             aValues[nLength].Name = PROPERTY_POSITION;
139cdf0e10cSrcweir             aValues[nLength++].Value <<= awt::Point(nPosX,0);
140cdf0e10cSrcweir 
141cdf0e10cSrcweir             aValues[nLength].Name = PROPERTY_PAGEHEADERON;
142cdf0e10cSrcweir             aValues[nLength++].Value <<= m_aTopPage.IsChecked();
143cdf0e10cSrcweir 
144cdf0e10cSrcweir             aValues[nLength].Name = PROPERTY_STATE;
145cdf0e10cSrcweir             aValues[nLength++].Value <<= m_aPageNofM.IsChecked();
146cdf0e10cSrcweir 
147cdf0e10cSrcweir             m_pController->executeChecked(SID_INSERT_FLD_PGNUMBER,aValues);
148cdf0e10cSrcweir 		}
149cdf0e10cSrcweir 		catch(uno::Exception&)
150cdf0e10cSrcweir 		{
151cdf0e10cSrcweir 			nRet = RET_NO;
152cdf0e10cSrcweir 		}
153cdf0e10cSrcweir 	}
154cdf0e10cSrcweir 	return nRet;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir // =============================================================================
157cdf0e10cSrcweir } // rptui
158cdf0e10cSrcweir // =============================================================================
159