update dev300-m57
[ooovba.git] / applied_patches / 0400-vba-zoom-per-sheet.diff
blob2cb61a85715b05b3182a8ce90ca399334225062c
1 diff --git sc/source/ui/inc/tabview.hxx sc/source/ui/inc/tabview.hxx
2 index 882c88b..95a5663 100644
3 --- sc/source/ui/inc/tabview.hxx
4 +++ sc/source/ui/inc/tabview.hxx
5 @@ -298,7 +298,7 @@ public:
7 void TabChanged();
8 void SetZoom( const Fraction& rNewX, const Fraction& rNewY, BOOL bAll );
9 - void RefreshZoom();
10 + SC_DLLPUBLIC void RefreshZoom();
11 void SetPagebreakMode( BOOL bSet );
13 void UpdateLayerLocks();
14 diff --git sc/source/ui/inc/viewdata.hxx sc/source/ui/inc/viewdata.hxx
15 index 27e6821..8557dc9 100644
16 --- sc/source/ui/inc/viewdata.hxx
17 +++ sc/source/ui/inc/viewdata.hxx
18 @@ -239,6 +239,7 @@ private:
20 SC_DLLPRIVATE void CalcPPT();
21 SC_DLLPRIVATE void CreateTabData( SCTAB nNewTab );
22 + SC_DLLPRIVATE void CreateTabData( std::vector< SCTAB >& rvTabs );
23 SC_DLLPRIVATE void CreateSelectedTabData();
25 public:
26 @@ -332,6 +333,8 @@ public:
27 void SetPasteMode ( ScPasteFlags nFlags ) { nPasteFlags = nFlags; }
29 void SetZoomType( SvxZoomType eNew, BOOL bAll );
30 + void SetZoomType( SvxZoomType eNew, std::vector< SCTAB >& tabs );
31 + void SetZoom( const Fraction& rNewX, const Fraction& rNewY, std::vector< SCTAB >& tabs );
32 void SetZoom( const Fraction& rNewX, const Fraction& rNewY, BOOL bAll );
33 void RefreshZoom();
35 diff --git sc/source/ui/vba/excelvbahelper.cxx sc/source/ui/vba/excelvbahelper.cxx
36 index 5f133d9..c98cab0 100644
37 --- sc/source/ui/vba/excelvbahelper.cxx
38 +++ sc/source/ui/vba/excelvbahelper.cxx
39 @@ -44,6 +44,13 @@ namespace vba
41 namespace excel
43 +void implSetZoom( const uno::Reference< frame::XModel >& xModel, sal_Int16 nZoom, std::vector< SCTAB >& nTabs )
45 + ScTabViewShell* pViewSh = excel::getBestViewShell( xModel );
46 + Fraction aFract( nZoom, 100 );
47 + pViewSh->GetViewData()->SetZoom( aFract, aFract, nTabs );
48 + pViewSh->RefreshZoom();
50 bool isInPrintPreview( SfxViewFrame* pView )
52 sal_uInt16 nViewNo = SID_VIEWSHELL1 - SID_VIEWSHELL0;
53 diff --git sc/source/ui/vba/excelvbahelper.hxx sc/source/ui/vba/excelvbahelper.hxx
54 index 3a3b7f8..af3e0bb 100644
55 --- sc/source/ui/vba/excelvbahelper.hxx
56 +++ sc/source/ui/vba/excelvbahelper.hxx
57 @@ -41,6 +41,8 @@ namespace ooo
59 namespace excel
61 + // nTabs empty means apply zoom to all sheets
62 + void implSetZoom( const css::uno::Reference< css::frame::XModel >& xModel, sal_Int16 nZoom, std::vector< SCTAB >& nTabs );
63 void implnCopy();
64 void implnPaste();
65 void implnCut();
66 diff --git sc/source/ui/vba/vbawindow.cxx sc/source/ui/vba/vbawindow.cxx
67 index c64e156..ea93022 100644
68 --- sc/source/ui/vba/vbawindow.cxx
69 +++ sc/source/ui/vba/vbawindow.cxx
70 @@ -58,6 +58,9 @@ using namespace ::com::sun::star;
71 using namespace ::ooo::vba;
72 using namespace ::ooo::vba::excel::XlWindowState;
74 +// nameExists defined in vbaworksheet.cxx
75 +bool nameExists( uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc, ::rtl::OUString & name, SCTAB& nTab ) throw ( lang::IllegalArgumentException );
77 typedef std::hash_map< rtl::OUString,
78 SCTAB, ::rtl::OUStringHash,
79 ::std::equal_to< ::rtl::OUString > > NameIndexHash;
80 @@ -735,24 +738,18 @@ ScVbaWindow::getZoom() throw (uno::RuntimeException)
81 void SAL_CALL
82 ScVbaWindow::setZoom( const uno::Any& _zoom ) throw (uno::RuntimeException)
84 - uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW );
85 - rtl::OUString sZoomType( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_ZOOMTYPE ) );
86 - sal_Int16 nZoomType = view::DocumentZoomType::PAGE_WIDTH;
87 - if( _zoom.getValueTypeClass() == uno::TypeClass_BOOLEAN )
88 - {
89 - //zoom type is PAGE_WIDTH_EXACT in helperapi, it seems that there is a issue for this zoom type in current OOo.
90 - // so PAGE_WIDTH is used.
91 - xProps->setPropertyValue(sZoomType, uno::makeAny( nZoomType ));
92 - }
93 - else
94 - {
95 - nZoomType = view::DocumentZoomType::BY_VALUE;
96 - rtl::OUString sZoomValue( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_ZOOMVALUE ));
97 - sal_Int16 nZoomValue = 100;
98 - _zoom >>= nZoomValue;
99 - xProps->setPropertyValue( sZoomType, uno::makeAny( nZoomType ));
100 - xProps->setPropertyValue( sZoomValue, uno::makeAny( nZoomValue ));
101 - }
102 + sal_Int16 nZoom = 100;
103 + _zoom >>= nZoom;
104 + uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( m_xModel, uno::UNO_QUERY_THROW );
105 + uno::Reference< excel::XWorksheet > xActiveSheet = ActiveSheet();
106 + SCTAB nTab = 0;
107 + rtl::OUString sName = xActiveSheet->getName();
108 + bool bSheetExists = nameExists (xSpreadDoc, sName, nTab);
109 + if ( !bSheetExists )
110 + throw uno::RuntimeException();
111 + std::vector< SCTAB > vTabs;
112 + vTabs.push_back( nTab );
113 + excel::implSetZoom( m_xModel, nZoom, vTabs );
116 uno::Reference< excel::XWorksheet > SAL_CALL
117 diff --git sc/source/ui/vba/vbaworksheet.cxx sc/source/ui/vba/vbaworksheet.cxx
118 index a416c8c..76c2f21 100644
119 --- sc/source/ui/vba/vbaworksheet.cxx
120 +++ sc/source/ui/vba/vbaworksheet.cxx
121 @@ -96,7 +96,7 @@
122 #define DOESNOTEXIST -1
123 using namespace com::sun::star;
124 using namespace ooo::vba;
125 -static bool
126 +bool
127 nameExists( uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc, ::rtl::OUString & name, SCTAB& nTab ) throw ( lang::IllegalArgumentException )
129 if (!xSpreadDoc.is())
130 diff --git sc/source/ui/view/viewdata.cxx sc/source/ui/view/viewdata.cxx
131 index ea04a47..1b2a7b8 100644
132 --- sc/source/ui/view/viewdata.cxx
133 +++ sc/source/ui/view/viewdata.cxx
134 @@ -650,66 +650,103 @@ void ScViewData::SetViewShell( ScTabViewShell* pViewSh )
135 pView = NULL;
138 +void ScViewData::CreateTabData( std::vector< SCTAB >& rvTabs )
140 + std::vector< SCTAB >::iterator it_end = rvTabs.end();
141 + for ( std::vector< SCTAB >::iterator it = rvTabs.begin(); it != it_end; ++it )
142 + if ( !pTabData[*it] )
143 + CreateTabData( *it );
146 -void ScViewData::SetZoomType( SvxZoomType eNew, BOOL bAll )
147 +void ScViewData::SetZoomType( SvxZoomType eNew, std::vector< SCTAB >& tabs )
149 - if ( !bAll )
150 - CreateSelectedTabData(); // if zoom is set for a table, it must be stored
151 + BOOL bAll = ( tabs.size() == 0 );
153 + if ( !bAll ) // create associated table data
154 + CreateTabData( tabs );
156 - for ( SCTAB i = 0; i <= MAXTAB; i++ )
157 - if ( pTabData[i] && ( bAll || aMarkData.GetTableSelect(i) ) )
158 + std::vector< SCTAB >::iterator it_end = tabs.end();
159 + std::vector< SCTAB >::iterator it = tabs.begin();
160 + for ( SCTAB i = ( bAll ? 0 : *it ); ( bAll ? i <= MAXTAB : it != it_end ); ++i , ++it )
162 + if ( pTabData[i] )
163 pTabData[i]->eZoomType = eNew;
164 + }
166 if ( bAll )
167 eDefZoomType = eNew;
170 -void ScViewData::SetZoom( const Fraction& rNewX, const Fraction& rNewY, BOOL bAll )
171 +void ScViewData::SetZoomType( SvxZoomType eNew, BOOL bAll )
173 + std::vector< SCTAB > vTabs; // Empty for all tabs
174 + if ( !bAll ) // get selected tabs
176 + SCTAB nTabCount = pDoc->GetTableCount();
177 + for (SCTAB i=0; i<nTabCount; i++)
179 + if ( aMarkData.GetTableSelect(i) )
180 + vTabs.push_back( i );
182 + }
183 + SetZoomType( eNew, vTabs );
186 +void ScViewData::SetZoom( const Fraction& rNewX, const Fraction& rNewY, std::vector< SCTAB >& tabs )
188 - if ( !bAll )
189 - CreateSelectedTabData(); // if zoom is set for a table, it must be stored
190 + BOOL bAll = ( tabs.size() == 0 );
191 + if ( !bAll ) // create associated table data
192 + CreateTabData( tabs );
193 + Fraction aFrac20( 1,5 );
194 + Fraction aFrac400( 4,1 );
196 - Fraction aFrac20( 1,5 );
197 - Fraction aFrac400( 4,1 );
198 + Fraction aValidX = rNewX;
199 + if (aValidX<aFrac20)
200 + aValidX = aFrac20;
201 + if (aValidX>aFrac400)
202 + aValidX = aFrac400;
204 - Fraction aValidX = rNewX;
205 - if (aValidX<aFrac20) aValidX = aFrac20;
206 - if (aValidX>aFrac400) aValidX = aFrac400;
207 + Fraction aValidY = rNewY;
208 + if (aValidY<aFrac20)
209 + aValidY = aFrac20;
210 + if (aValidY>aFrac400)
211 + aValidY = aFrac400;
213 - Fraction aValidY = rNewY;
214 - if (aValidY<aFrac20) aValidY = aFrac20;
215 - if (aValidY>aFrac400) aValidY = aFrac400;
216 + std::vector< SCTAB >::iterator it_end = tabs.end();
217 + std::vector< SCTAB >::iterator it = tabs.begin();
219 - if ( bPagebreak )
221 - for ( SCTAB i = 0; i <= MAXTAB; i++ )
222 - if ( pTabData[i] && ( bAll || aMarkData.GetTableSelect(i) ) )
223 + for ( SCTAB i = ( bAll ? 0 : *it ); ( bAll ? i <= MAXTAB : it != it_end ); ++i , ++it )
225 + if ( pTabData[i] )
227 + if ( bPagebreak )
229 pTabData[i]->aPageZoomX = aValidX;
230 pTabData[i]->aPageZoomY = aValidY;
232 - if ( bAll )
234 - aDefPageZoomX = aValidX;
235 - aDefPageZoomY = aValidY;
238 - else
240 - for ( SCTAB i = 0; i <= MAXTAB; i++ )
241 - if ( pTabData[i] && ( bAll || aMarkData.GetTableSelect(i) ) )
242 + else
244 pTabData[i]->aZoomX = aValidX;
245 pTabData[i]->aZoomY = aValidY;
247 - if ( bAll )
249 - aDefZoomX = aValidX;
250 - aDefZoomY = aValidY;
254 + RefreshZoom();
257 - RefreshZoom();
258 +void ScViewData::SetZoom( const Fraction& rNewX, const Fraction& rNewY, BOOL bAll )
260 + std::vector< SCTAB > vTabs;
261 + if ( !bAll ) // get selected tabs
263 + SCTAB nTabCount = pDoc->GetTableCount();
264 + for (SCTAB i=0; i<nTabCount; i++)
266 + if ( aMarkData.GetTableSelect(i) )
267 + vTabs.push_back( i );
269 + }
270 + SetZoom( rNewX, rNewY, vTabs );
273 void ScViewData::SetShowGrid( bool bShow )