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