Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / pagedlg / tptable.cxx
blob21efc163b51b539245b9f71ad55a3eaf95a0ae91
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #undef SC_DLLIMPLEMENTATION
25 //------------------------------------------------------------------
27 #include "scitems.hxx"
29 #include "tptable.hxx"
30 #include "global.hxx"
31 #include "attrib.hxx"
32 #include "scresid.hxx"
33 #include "sc.hrc"
34 #include "pagedlg.hrc"
36 // =======================================================================
38 void EmptyNumericField::Modify()
40 if( !GetText().isEmpty() )
41 NumericField::Modify();
42 else
43 SetEmptyFieldValue();
46 void EmptyNumericField::SetValue( sal_Int64 nValue )
48 if( nValue == 0 )
49 SetEmptyFieldValue();
50 else
51 NumericField::SetValue( nValue );
54 sal_Int64 EmptyNumericField::GetValue() const
56 return IsEmptyFieldValue() ? 0 : NumericField::GetValue();
59 // =======================================================================
61 // STATIC DATA -----------------------------------------------------------
63 static sal_uInt16 pPageTableRanges[] =
65 ATTR_PAGE_NOTES, ATTR_PAGE_FIRSTPAGENO,
69 static sal_Bool lcl_PutVObjModeItem( sal_uInt16 nWhich,
70 SfxItemSet& rCoreSet,
71 const SfxItemSet& rOldSet,
72 const CheckBox& rBtn );
74 static sal_Bool lcl_PutScaleItem( sal_uInt16 nWhich,
75 SfxItemSet& rCoreSet,
76 const SfxItemSet& rOldSet,
77 const ListBox& rListBox,
78 sal_uInt16 nLBEntry,
79 const SpinField& rEd,
80 sal_uInt16 nValue );
82 static sal_Bool lcl_PutScaleItem2( sal_uInt16 nWhich,
83 SfxItemSet& rCoreSet,
84 const SfxItemSet& rOldSet,
85 const ListBox& rListBox,
86 sal_uInt16 nLBEntry,
87 const NumericField& rEd1,
88 const NumericField& rEd2 );
90 static sal_Bool lcl_PutBoolItem( sal_uInt16 nWhich,
91 SfxItemSet& rCoreSet,
92 const SfxItemSet& rOldSet,
93 sal_Bool bIsChecked,
94 sal_Bool bSavedValue );
96 //------------------------------------------------------------------------
98 #define PAGENO_HDL LINK(this,ScTablePage,PageNoHdl)
99 #define PAGEDIR_HDL LINK(this,ScTablePage,PageDirHdl)
100 #define SCALE_HDL LINK(this,ScTablePage,ScaleHdl)
102 #define WAS_DEFAULT(w,s) (SFX_ITEM_DEFAULT==(s).GetItemState((w),sal_True))
103 #define GET_BOOL(sid,set) ((const SfxBoolItem&)((set).Get(GetWhich((sid))))).GetValue()
104 #define GET_USHORT(sid,set) (sal_uInt16)((const SfxUInt16Item&)((set).Get(GetWhich((sid))))).GetValue()
105 #define GET_SHOW(sid,set) ( ScVObjMode( ((const ScViewObjectModeItem&)((set).Get(GetWhich((sid))))).GetValue() ) \
106 == VOBJ_MODE_SHOW )
107 // List box entries "Scaling mode"
108 #define SC_TPTABLE_SCALE_PERCENT 0
109 #define SC_TPTABLE_SCALE_TO 1
110 #define SC_TPTABLE_SCALE_TO_PAGES 2
112 //========================================================================
114 ScTablePage::ScTablePage( Window* pParent, const SfxItemSet& rCoreAttrs ) :
116 SfxTabPage( pParent, "SheetPrintPage","modules/scalc/ui/sheetprintpage.ui", rCoreAttrs )
118 get(m_pBtnTopDown,"radioBTN_TOPDOWN");
119 get(m_pBtnLeftRight,"radioBTN_LEFTRIGHT");
120 get(m_pBmpPageDir,"imageBMP_PAGEDIR");
121 get(m_pBtnPageNo,"checkBTN_PAGENO");
122 get(m_pEdPageNo,"spinED_PAGENO");
124 get(m_pBtnHeaders,"checkBTN_HEADER");
125 get(m_pBtnGrid,"checkBTN_GRID");
126 get(m_pBtnNotes,"checkBTN_NOTES");
127 get(m_pBtnObjects,"checkBTN_OBJECTS");
128 get(m_pBtnCharts,"checkBTN_CHARTS");
129 get(m_pBtnDrawings,"checkBTN_DRAWINGS");
130 get(m_pBtnFormulas,"checkBTN_FORMULAS");
131 get(m_pBtnNullVals,"checkBTN_NULLVALS");
133 get(m_pLbScaleMode,"comboLB_SCALEMODE");
134 get(m_pBxScaleAll,"boxSCALEALL");
135 get(m_pEdScaleAll,"spinED_SCALEALL");
136 get(m_pGrHeightWidth,"gridWH");
137 get(m_pEdScalePageWidth,"spinED_SCALEPAGEWIDTH");
138 get(m_pEdScalePageHeight,"spinED_SCALEPAGEHEIGHT");
139 get(m_pBxScalePageNum,"boxNP");
140 get(m_pEdScalePageNum,"spinED_SCALEPAGENUM");
142 SetExchangeSupport();
144 m_pBtnPageNo->SetClickHdl( PAGENO_HDL );
145 m_pBtnTopDown->SetClickHdl( PAGEDIR_HDL );
146 m_pBtnLeftRight->SetClickHdl( PAGEDIR_HDL );
147 m_pLbScaleMode->SetSelectHdl( SCALE_HDL );
151 // -----------------------------------------------------------------------
153 void ScTablePage::ShowImage()
155 Image aImg = Image( ScResId( (m_pBtnLeftRight->IsChecked()) ? IMG_LEFTRIGHT : IMG_TOPDOWN ) );
156 m_pBmpPageDir->SetImage( aImg );
157 m_pBmpPageDir->SetOutputSizePixel( aImg.GetSizePixel() );
160 // -----------------------------------------------------------------------
162 ScTablePage::~ScTablePage()
166 //------------------------------------------------------------------------
168 sal_uInt16* ScTablePage::GetRanges()
170 return pPageTableRanges;
173 // -----------------------------------------------------------------------
175 SfxTabPage* ScTablePage::Create( Window* pParent, const SfxItemSet& rCoreSet )
177 return ( new ScTablePage( pParent, rCoreSet ) );
180 // -----------------------------------------------------------------------
182 void ScTablePage::Reset( const SfxItemSet& rCoreSet )
184 sal_Bool bTopDown = GET_BOOL( SID_SCATTR_PAGE_TOPDOWN, rCoreSet );
185 sal_uInt16 nWhich = 0;
187 //-----------
188 // sal_Bool-Flags
189 //-----------
190 m_pBtnNotes->Check( GET_BOOL(SID_SCATTR_PAGE_NOTES,rCoreSet) );
191 m_pBtnGrid->Check( GET_BOOL(SID_SCATTR_PAGE_GRID,rCoreSet) );
192 m_pBtnHeaders->Check( GET_BOOL(SID_SCATTR_PAGE_HEADERS,rCoreSet) );
193 m_pBtnFormulas->Check( GET_BOOL(SID_SCATTR_PAGE_FORMULAS,rCoreSet) );
194 m_pBtnNullVals->Check( GET_BOOL(SID_SCATTR_PAGE_NULLVALS,rCoreSet) );
195 m_pBtnTopDown->Check( bTopDown );
196 m_pBtnLeftRight->Check( !bTopDown );
198 //------------------
199 // Erste Druckseite:
200 //------------------
201 sal_uInt16 nPage = GET_USHORT(SID_SCATTR_PAGE_FIRSTPAGENO,rCoreSet);
202 m_pBtnPageNo->Check( nPage != 0 );
203 m_pEdPageNo->SetValue( (nPage != 0) ? nPage : 1 );
204 PageNoHdl( NULL );
206 //-------------------
207 // Objektdarstellung:
208 //-------------------
209 m_pBtnCharts->Check( GET_SHOW( SID_SCATTR_PAGE_CHARTS, rCoreSet ) );
210 m_pBtnObjects->Check( GET_SHOW( SID_SCATTR_PAGE_OBJECTS, rCoreSet ) );
211 m_pBtnDrawings->Check( GET_SHOW( SID_SCATTR_PAGE_DRAWINGS, rCoreSet ) );
213 //------------
214 // Skalierung:
215 //------------
217 nWhich = GetWhich(SID_SCATTR_PAGE_SCALE);
218 if ( rCoreSet.GetItemState( nWhich, sal_True ) >= SFX_ITEM_AVAILABLE )
220 sal_uInt16 nScale = ((const SfxUInt16Item&)rCoreSet.Get(nWhich)).GetValue();
221 if( nScale > 0 )
222 m_pLbScaleMode->SelectEntryPos( SC_TPTABLE_SCALE_PERCENT );
223 m_pEdScaleAll->SetValue( (nScale > 0) ? nScale : 100 );
226 nWhich = GetWhich(SID_SCATTR_PAGE_SCALETO);
227 if ( rCoreSet.GetItemState( nWhich, sal_True ) >= SFX_ITEM_AVAILABLE )
229 const ScPageScaleToItem& rItem = static_cast< const ScPageScaleToItem& >( rCoreSet.Get( nWhich ) );
230 sal_uInt16 nWidth = rItem.GetWidth();
231 sal_uInt16 nHeight = rItem.GetHeight();
233 /* width==0 and height==0 is invalid state, used as "not selected".
234 Dialog shows width=height=1 then. */
235 bool bValid = nWidth || nHeight;
236 if( bValid )
237 m_pLbScaleMode->SelectEntryPos( SC_TPTABLE_SCALE_TO );
238 m_pEdScalePageWidth->SetValue( bValid ? nWidth : 1 );
239 m_pEdScalePageHeight->SetValue( bValid ? nHeight : 1 );
242 nWhich = GetWhich(SID_SCATTR_PAGE_SCALETOPAGES);
243 if ( rCoreSet.GetItemState( nWhich, sal_True ) >= SFX_ITEM_AVAILABLE )
245 sal_uInt16 nPages = ((const SfxUInt16Item&)rCoreSet.Get(nWhich)).GetValue();
246 if( nPages > 0 )
247 m_pLbScaleMode->SelectEntryPos( SC_TPTABLE_SCALE_TO_PAGES );
248 m_pEdScalePageNum->SetValue( (nPages > 0) ? nPages : 1 );
251 if( m_pLbScaleMode->GetSelectEntryCount() == 0 )
253 // fall back to 100%
254 OSL_FAIL( "ScTablePage::Reset - missing scaling item" );
255 m_pLbScaleMode->SelectEntryPos( SC_TPTABLE_SCALE_PERCENT );
256 m_pEdScaleAll->SetValue( 100 );
259 PageDirHdl( NULL );
260 ScaleHdl( NULL );
262 // merken fuer FillItemSet
263 m_pBtnFormulas->SaveValue();
264 m_pBtnNullVals->SaveValue();
265 m_pBtnNotes->SaveValue();
266 m_pBtnGrid->SaveValue();
267 m_pBtnHeaders->SaveValue();
268 m_pBtnTopDown->SaveValue();
269 m_pBtnLeftRight->SaveValue();
270 m_pLbScaleMode->SaveValue();
271 m_pBtnCharts->SaveValue();
272 m_pBtnObjects->SaveValue();
273 m_pBtnDrawings->SaveValue();
274 m_pBtnPageNo->SaveValue();
275 m_pEdPageNo->SaveValue();
276 m_pEdScaleAll->SaveValue();
277 m_pEdScalePageWidth->SaveValue();
278 m_pEdScalePageHeight->SaveValue();
279 m_pEdScalePageNum->SaveValue();
282 // -----------------------------------------------------------------------
284 sal_Bool ScTablePage::FillItemSet( SfxItemSet& rCoreSet )
286 const SfxItemSet& rOldSet = GetItemSet();
287 sal_uInt16 nWhichPageNo = GetWhich(SID_SCATTR_PAGE_FIRSTPAGENO);
288 sal_Bool bDataChanged = false;
290 //-----------
291 // sal_Bool-Flags
292 //-----------
294 bDataChanged |= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_NOTES),
295 rCoreSet, rOldSet,
296 m_pBtnNotes->IsChecked(),
297 m_pBtnNotes->GetSavedValue() != STATE_NOCHECK );
299 bDataChanged |= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_GRID),
300 rCoreSet, rOldSet,
301 m_pBtnGrid->IsChecked(),
302 m_pBtnGrid->GetSavedValue() != STATE_NOCHECK );
304 bDataChanged |= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_HEADERS),
305 rCoreSet, rOldSet,
306 m_pBtnHeaders->IsChecked(),
307 m_pBtnHeaders->GetSavedValue() != STATE_NOCHECK );
309 bDataChanged |= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_TOPDOWN),
310 rCoreSet, rOldSet,
311 m_pBtnTopDown->IsChecked(),
312 m_pBtnTopDown->GetSavedValue() );
314 bDataChanged |= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_FORMULAS),
315 rCoreSet, rOldSet,
316 m_pBtnFormulas->IsChecked(),
317 m_pBtnFormulas->GetSavedValue() != STATE_NOCHECK );
319 bDataChanged |= lcl_PutBoolItem( GetWhich(SID_SCATTR_PAGE_NULLVALS),
320 rCoreSet, rOldSet,
321 m_pBtnNullVals->IsChecked(),
322 m_pBtnNullVals->GetSavedValue() != STATE_NOCHECK );
324 //------------------
325 // Erste Druckseite:
326 //------------------
327 sal_Bool bUseValue = m_pBtnPageNo->IsChecked();
329 if ( WAS_DEFAULT(nWhichPageNo,rOldSet)
330 && ( (!bUseValue && bUseValue == m_pBtnPageNo->GetSavedValue())
331 || ( bUseValue && bUseValue == m_pBtnPageNo->GetSavedValue()
332 && m_pEdPageNo->GetText() == m_pEdPageNo->GetSavedValue() ) ) )
334 rCoreSet.ClearItem( nWhichPageNo );
336 else
338 sal_uInt16 nPage = (sal_uInt16)( m_pBtnPageNo->IsChecked()
339 ? m_pEdPageNo->GetValue()
340 : 0 );
342 rCoreSet.Put( SfxUInt16Item( nWhichPageNo, nPage ) );
343 bDataChanged = sal_True;
346 //-------------------
347 // Objektdarstellung:
348 //-------------------
350 bDataChanged |= lcl_PutVObjModeItem( GetWhich(SID_SCATTR_PAGE_CHARTS),
351 rCoreSet, rOldSet, *m_pBtnCharts );
353 bDataChanged |= lcl_PutVObjModeItem( GetWhich(SID_SCATTR_PAGE_OBJECTS),
354 rCoreSet, rOldSet, *m_pBtnObjects );
356 bDataChanged |= lcl_PutVObjModeItem( GetWhich(SID_SCATTR_PAGE_DRAWINGS),
357 rCoreSet, rOldSet, *m_pBtnDrawings );
359 //------------
360 // Skalierung:
361 //------------
363 if( !m_pEdScalePageWidth->GetValue() && !m_pEdScalePageHeight->GetValue() )
365 m_pLbScaleMode->SelectEntryPos( SC_TPTABLE_SCALE_PERCENT );
366 m_pEdScaleAll->SetValue( 100 );
369 bDataChanged |= lcl_PutScaleItem( GetWhich(SID_SCATTR_PAGE_SCALE),
370 rCoreSet, rOldSet,
371 *m_pLbScaleMode, SC_TPTABLE_SCALE_PERCENT,
372 *m_pEdScaleAll, (sal_uInt16)m_pEdScaleAll->GetValue() );
374 bDataChanged |= lcl_PutScaleItem2( GetWhich(SID_SCATTR_PAGE_SCALETO),
375 rCoreSet, rOldSet,
376 *m_pLbScaleMode, SC_TPTABLE_SCALE_TO,
377 *m_pEdScalePageWidth, *m_pEdScalePageHeight );
379 bDataChanged |= lcl_PutScaleItem( GetWhich(SID_SCATTR_PAGE_SCALETOPAGES),
380 rCoreSet, rOldSet,
381 *m_pLbScaleMode, SC_TPTABLE_SCALE_TO_PAGES,
382 *m_pEdScalePageNum, (sal_uInt16)m_pEdScalePageNum->GetValue() );
384 return bDataChanged;
387 //------------------------------------------------------------------------
389 int ScTablePage::DeactivatePage( SfxItemSet* pSetP )
391 if ( pSetP )
392 FillItemSet( *pSetP );
394 return LEAVE_PAGE;
397 //------------------------------------------------------------------------
399 void ScTablePage::DataChanged( const DataChangedEvent& rDCEvt )
401 if( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
402 ShowImage();
403 SfxTabPage::DataChanged( rDCEvt );
406 //------------------------------------------------------------------------
407 // Handler:
408 //------------------------------------------------------------------------
410 IMPL_LINK_NOARG(ScTablePage, PageDirHdl)
412 ShowImage();
413 return 0;
416 //------------------------------------------------------------------------
418 IMPL_LINK( ScTablePage, PageNoHdl, CheckBox*, pBtn )
420 if ( m_pBtnPageNo->IsChecked() )
422 m_pEdPageNo->Enable();
423 if ( pBtn )
424 m_pEdPageNo->GrabFocus();
426 else
427 m_pEdPageNo->Disable();
429 return 0;
432 //------------------------------------------------------------------------
434 IMPL_LINK_NOARG(ScTablePage, ScaleHdl)
436 // controls for Box "Reduce/enlarge"
437 m_pBxScaleAll->Show(m_pLbScaleMode->GetSelectEntryPos() == SC_TPTABLE_SCALE_PERCENT);
439 // controls for Grid "Scale to width/height"
440 m_pGrHeightWidth->Show(m_pLbScaleMode->GetSelectEntryPos() == SC_TPTABLE_SCALE_TO);
442 // controls for Box "Scale to pages"
443 m_pBxScalePageNum->Show(m_pLbScaleMode->GetSelectEntryPos() == SC_TPTABLE_SCALE_TO_PAGES);
445 return 0;
448 //========================================================================
449 // Hilfsfunktionen fuer FillItemSet:
450 //========================================================================
452 static sal_Bool lcl_PutBoolItem( sal_uInt16 nWhich,
453 SfxItemSet& rCoreSet,
454 const SfxItemSet& rOldSet,
455 sal_Bool bIsChecked,
456 sal_Bool bSavedValue )
458 sal_Bool bDataChanged = ( bSavedValue == bIsChecked
459 && WAS_DEFAULT(nWhich,rOldSet) );
461 if ( bDataChanged )
462 rCoreSet.ClearItem(nWhich);
463 else
464 rCoreSet.Put( SfxBoolItem( nWhich, bIsChecked ) );
466 return bDataChanged;
469 //------------------------------------------------------------------------
471 static sal_Bool lcl_PutVObjModeItem( sal_uInt16 nWhich,
472 SfxItemSet& rCoreSet,
473 const SfxItemSet& rOldSet,
474 const CheckBox& rBtn )
476 sal_Bool bIsChecked = rBtn.IsChecked();
477 sal_Bool bDataChanged = ( rBtn.GetSavedValue() == bIsChecked
478 && WAS_DEFAULT(nWhich,rOldSet) );
480 if ( bDataChanged )
481 rCoreSet.ClearItem( nWhich );
483 else
484 rCoreSet.Put( ScViewObjectModeItem( nWhich, bIsChecked
485 ? VOBJ_MODE_SHOW
486 : VOBJ_MODE_HIDE ) );
487 return bDataChanged;
490 //------------------------------------------------------------------------
492 static sal_Bool lcl_PutScaleItem( sal_uInt16 nWhich,
493 SfxItemSet& rCoreSet,
494 const SfxItemSet& rOldSet,
495 const ListBox& rListBox,
496 sal_uInt16 nLBEntry,
497 const SpinField& rEd,
498 sal_uInt16 nValue )
500 sal_Bool bIsSel = (rListBox.GetSelectEntryPos() == nLBEntry);
501 sal_Bool bDataChanged = (rListBox.GetSavedValue() != nLBEntry) ||
502 (rEd.GetSavedValue() != rEd.GetText()) ||
503 !WAS_DEFAULT( nWhich, rOldSet );
505 if( bDataChanged )
506 rCoreSet.Put( SfxUInt16Item( nWhich, bIsSel ? nValue : 0 ) );
507 else
508 rCoreSet.ClearItem( nWhich );
510 return bDataChanged;
514 static sal_Bool lcl_PutScaleItem2( sal_uInt16 nWhich,
515 SfxItemSet& rCoreSet,
516 const SfxItemSet& rOldSet,
517 const ListBox& rListBox,
518 sal_uInt16 nLBEntry,
519 const NumericField& rEd1,
520 const NumericField& rEd2 )
522 sal_uInt16 nValue1 = (sal_uInt16)rEd1.GetValue();
523 sal_uInt16 nValue2 = (sal_uInt16)rEd2.GetValue();
524 sal_Bool bIsSel = (rListBox.GetSelectEntryPos() == nLBEntry);
525 sal_Bool bDataChanged = (rListBox.GetSavedValue() != nLBEntry) ||
526 (rEd1.GetSavedValue() != rEd1.GetText()) ||
527 (rEd2.GetSavedValue() != rEd2.GetText()) ||
528 !WAS_DEFAULT( nWhich, rOldSet );
530 if( bDataChanged )
532 ScPageScaleToItem aItem;
533 if( bIsSel )
534 aItem.Set( nValue1, nValue2 );
535 rCoreSet.Put( aItem );
537 else
538 rCoreSet.ClearItem( nWhich );
540 return bDataChanged;
545 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */