xref: /AOO41X/main/reportdesign/source/ui/dlg/PageNumber.cxx (revision 9e0e41911c53968aad5ad356e2b2126da667034f)
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 #include "precompiled_reportdesign.hxx"
24 #include "PageNumber.hxx"
25 #ifndef RPTUI_PAGENUMBER_HRC
26 #include "PageNumber.hrc"
27 #endif
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <tools/debug.hxx>
30 #ifndef _RPTUI_DLGRESID_HRC
31 #include "RptResId.hrc"
32 #endif
33 #ifndef _RPTUI_SLOTID_HRC_
34 #include "rptui_slotid.hrc"
35 #endif
36 #ifndef _RPTUI_MODULE_HELPER_DBU_HXX_
37 #include "ModuleHelper.hxx"
38 #endif
39 #include "RptDef.hxx"
40 #ifndef RTPUI_REPORTDESIGN_HELPID_HRC
41 #include "helpids.hrc"
42 #endif
43 #include <vcl/msgbox.hxx>
44 #ifndef _GLOBLMN_HRC
45 #include <svx/globlmn.hrc>
46 #endif
47 #ifndef _SBASLTID_HRC
48 #include <svx/svxids.hrc>
49 #endif
50 #ifndef RPTUI_TOOLS_HXX
51 #include "UITools.hxx"
52 #endif
53 #ifndef REPORTDESIGN_SHARED_UISTRINGS_HRC
54 #include "uistrings.hrc"
55 #endif
56 #include "ReportController.hxx"
57 #include <com/sun/star/report/XFixedText.hpp>
58 #include <algorithm>
59 
60 namespace rptui
61 {
62 using namespace ::com::sun::star;
63 using namespace ::comphelper;
64 
DBG_NAME(rpt_OPageNumberDialog)65 DBG_NAME( rpt_OPageNumberDialog )
66 //========================================================================
67 // class OPageNumberDialog
68 //========================================================================
69 OPageNumberDialog::OPageNumberDialog( Window* _pParent
70                                            ,const uno::Reference< report::XReportDefinition >& _xHoldAlive
71                                            ,OReportController* _pController)
72     : ModalDialog( _pParent, ModuleRes(RID_PAGENUMBERS) )
73     ,m_aFormat(this, ModuleRes(FL_FORMAT) )
74     ,m_aPageN(this, ModuleRes(RB_PAGE_N) )
75     ,m_aPageNofM(this, ModuleRes(RB_PAGE_N_OF_M) )
76     ,m_aPosition(this, ModuleRes(FL_POSITION) )
77     ,m_aTopPage(this, ModuleRes(RB_PAGE_TOPPAGE) )
78     ,m_aBottomPage(this, ModuleRes(RB_PAGE_BOTTOMPAGE) )
79     ,m_aMisc(this, ModuleRes(FL_MISC) )
80     ,m_aAlignment(this, ModuleRes(FL_ALIGNMENT) )
81     ,m_aAlignmentLst(this, ModuleRes(LST_ALIGNMENT) )
82     ,m_aShowNumberOnFirstPage(this, ModuleRes(CB_SHOWNUMBERONFIRSTPAGE) )
83     ,m_aFl1(this,       ModuleRes(FL_SEPARATOR1))
84     ,m_aPB_OK(this,     ModuleRes(PB_OK))
85     ,m_aPB_CANCEL(this, ModuleRes(PB_CANCEL))
86     ,m_aPB_Help(this,   ModuleRes(PB_HELP))
87     ,m_pController(_pController)
88     ,m_xHoldAlive(_xHoldAlive)
89 {
90     DBG_CTOR( rpt_OPageNumberDialog,NULL);
91 
92     m_aShowNumberOnFirstPage.Hide();
93 
94     FreeResource();
95 }
96 
97 //------------------------------------------------------------------------
~OPageNumberDialog()98 OPageNumberDialog::~OPageNumberDialog()
99 {
100     DBG_DTOR( rpt_OPageNumberDialog,NULL);
101 }
102 // -----------------------------------------------------------------------------
Execute()103 short OPageNumberDialog::Execute()
104 {
105     short nRet = ModalDialog::Execute();
106     if ( nRet == RET_OK )
107     {
108         try
109         {
110             sal_Int32 nControlMaxSize = 3000;
111             sal_Int32 nPosX = 0;
112             sal_Int32 nPos2X = 0;
113             awt::Size aRptSize = getStyleProperty<awt::Size>(m_xHoldAlive,PROPERTY_PAPERSIZE);
114             switch ( m_aAlignmentLst.GetSelectEntryPos() )
115             {
116                 case 0: // left
117                     nPosX = getStyleProperty<sal_Int32>(m_xHoldAlive,PROPERTY_LEFTMARGIN);
118                     break;
119                 case 1: // middle
120                     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;
121                     break;
122                 case 2: // right
123                     nPosX = (aRptSize.Width - getStyleProperty<sal_Int32>(m_xHoldAlive,PROPERTY_RIGHTMARGIN) - nControlMaxSize);
124                     break;
125                 case 3: // inner
126                 case 4: // outer
127                     nPosX = getStyleProperty<sal_Int32>(m_xHoldAlive,PROPERTY_LEFTMARGIN);
128                     nPos2X = (aRptSize.Width - getStyleProperty<sal_Int32>(m_xHoldAlive,PROPERTY_RIGHTMARGIN) - nControlMaxSize);
129                     break;
130                 default:
131                     break;
132             }
133             if ( m_aAlignmentLst.GetSelectEntryPos() > 2 )
134                 nPosX = nPos2X;
135 
136             sal_Int32 nLength = 0;
137             uno::Sequence<beans::PropertyValue> aValues( 3 );
138             aValues[nLength].Name = PROPERTY_POSITION;
139             aValues[nLength++].Value <<= awt::Point(nPosX,0);
140 
141             aValues[nLength].Name = PROPERTY_PAGEHEADERON;
142             aValues[nLength++].Value <<= m_aTopPage.IsChecked();
143 
144             aValues[nLength].Name = PROPERTY_STATE;
145             aValues[nLength++].Value <<= m_aPageNofM.IsChecked();
146 
147             m_pController->executeChecked(SID_INSERT_FLD_PGNUMBER,aValues);
148         }
149         catch(uno::Exception&)
150         {
151             nRet = RET_NO;
152         }
153     }
154     return nRet;
155 }
156 // =============================================================================
157 } // rptui
158 // =============================================================================
159