1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: printdialog.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include <boost/scoped_ptr.hpp>
36 #include "sdresid.hxx"
37 #include "printdialog.hxx"
38 #include "printdialog.hrc"
39 #include "optsitem.hxx"
40 #include "res_bmp.hrc"
42 class SdPrintDialogImpl
: public ModalDialog
46 : ModalDialog( 0, SdResId( DLG_PRINTDIALOG
) )
50 virtual ~SdPrintDialogImpl()
57 aOptions.GetOptionsPrint().SetDraw( aCbxDraw.IsChecked() );
58 aOptions.GetOptionsPrint().SetNotes( aCbxNotes.IsChecked() );
59 aOptions.GetOptionsPrint().SetHandout( aCbxHandout.IsChecked() );
60 aOptions.GetOptionsPrint().SetOutline( aCbxOutline.IsChecked() );
62 aCbxDraw.Check( pPrintOpts->GetOptionsPrint().IsDraw() );
63 aCbxNotes.Check( pPrintOpts->GetOptionsPrint().IsNotes() );
64 aCbxHandout.Check( pPrintOpts->GetOptionsPrint().IsHandout() );
65 aCbxOutline.Check( pPrintOpts->GetOptionsPrint().IsOutline() );
70 SdPrintDialog
* SdPrintDialog::Create( Window
* pWindow
, bool bImpress
)
72 return new SdPrintDialog( pWindow
, bImpress
);
75 SdPrintDialog::SdPrintDialog( Window
* pWindow
, bool bImpress
)
76 : PrintDialog( pWindow
, false )
77 , mbImpress( bImpress
)
81 mpControls
.resize( PRINTDLG_CONTROLCOUNT
);
83 boost::scoped_ptr
< SdPrintDialogImpl
> aImplDlg( new SdPrintDialogImpl() );
85 USHORT nChildCount
= GetChildCount();
87 mpControls
[FL_PRINTCONTENT
-1].reset( new FixedLine( this, SdResId( FL_PRINTCONTENT
) ) );
88 mpControls
[FT_CONTENT
-1].reset( new FixedText( this, SdResId( FT_CONTENT
) ) );
89 mpControls
[CB_CONTENT
-1].reset( new ListBox( this, SdResId( CB_CONTENT
) ) );
90 mpControls
[FT_SLIDESPERPAGE
-1].reset( new FixedText( this, SdResId( FT_SLIDESPERPAGE
) ) );
91 mpControls
[CB_SLIDESPERPAGE
-1].reset( new ListBox( this, SdResId( CB_SLIDESPERPAGE
) ) );
92 mpControls
[FT_ORDER
-1].reset( new FixedText( this, SdResId( FT_ORDER
) ) );
93 mpControls
[RBT_HORIZONTAL
-1].reset( new RadioButton( this, SdResId( RBT_HORIZONTAL
) ) );
94 mpControls
[RBT_VERTICAL
-1].reset( new RadioButton( this, SdResId( RBT_VERTICAL
) ) );
95 mpControls
[IMG_PREVIEW
-1].reset( new FixedImage( this, SdResId( IMG_PREVIEW
) ) );
97 sal_Int32 nHeight
= LogicToPixel( Size( 0, 71 ), MAP_APPFONT
).Height();
99 sal_Int32 nInsertY
= nHeight
;
101 Window
* pNextControl
= 0;
103 // find second fixed line
105 USHORT nFixedLine
= 2;
106 while( nChildCount
-- )
108 pNextControl
= GetChild( nChild
++ );
109 if( dynamic_cast< FixedLine
* >( pNextControl
) )
111 if( --nFixedLine
== 0 )
113 nInsertY
= pNextControl
->GetPosPixel().Y();
121 // move lower controls down
122 std::vector
< Window
* > aLowerControls
;
123 while( nChildCount
-- )
125 Window
* pControl
= GetChild( nChild
++ );
128 Point
aPos( pControl
->GetPosPixel() );
130 pControl
->SetPosPixel(aPos
);
131 aLowerControls
.push_back(pControl
);
135 // positionate new controls
136 for( int i
= 0; i
< PRINTDLG_CONTROLCOUNT
; i
++ )
138 Control
* pControl
= mpControls
[i
].get();
141 Point
aPos( pControl
->GetPosPixel() );
142 aPos
.Y() += nInsertY
;
143 pControl
->SetPosPixel(aPos
);
144 pControl
->SetZOrder( pNextControl
, WINDOW_ZORDER_BEFOR
);
148 Size
aDialogSize( GetSizePixel() );
149 aDialogSize
.Height() += nHeight
;
150 SetSizePixel( aDialogSize
);
154 SdPrintDialog::~SdPrintDialog()
158 void SdPrintDialog::Init( const SdOptionsPrintItem
* pPrintOpts
)
162 bool bDraw
= true, bHandout
= false, bNotes
= false, bOutline
= false;
163 sal_uInt16 nPagesPerHandout
= 6;
164 bool bHandoutHorizontal
= true;
168 const SdOptionsPrint
& rOpts
= pPrintOpts
->GetOptionsPrint();
169 bDraw
= rOpts
.IsDraw();
170 bHandout
= rOpts
.IsHandout();
171 bNotes
= rOpts
.IsNotes();
172 bOutline
= rOpts
.IsOutline();
173 nPagesPerHandout
= rOpts
.GetHandoutPages();
174 bHandoutHorizontal
= rOpts
.IsHandoutHorizontal();
187 static_cast<ListBox
*>( mpControls
[CB_CONTENT
-1].get() )->SelectEntryPos( nPos
);
189 switch( nPagesPerHandout
)
191 case 1: nPos
= 0; break;
192 case 2: nPos
= 1; break;
193 case 3: nPos
= 2; break;
194 case 4: nPos
= 3; break;
196 case 6: nPos
= 4; break;
197 default:nPos
= 5; break;
199 static_cast<ListBox
*>( mpControls
[CB_SLIDESPERPAGE
-1].get() )->SelectEntryPos( nPos
);
202 static_cast<RadioButton
*>( mpControls
[RBT_HORIZONTAL
-1].get() )->Check( bHandoutHorizontal
== true ) ;
203 static_cast<RadioButton
*>( mpControls
[RBT_VERTICAL
-1].get() )->Check( bHandoutHorizontal
== false ) ;
207 Image
* pImage
= mpPreviews
[0].get();
210 FixedImage
* pPreviewImage
= static_cast<FixedImage
*>( mpControls
[IMG_PREVIEW
-1].get() );
212 Point
aPos( pPreviewImage
->GetPosPixel() );
213 pPreviewImage
->SetSizePixel( pImage
->GetSizePixel() );
214 aPos
.X() -= pImage
->GetSizePixel().Width();
216 pPreviewImage
->SetPosPixel( aPos
);
221 Link
aLink( LINK(this,SdPrintDialog
,UpdateStatesHdl
) );
222 static_cast<ListBox
*>( mpControls
[CB_CONTENT
-1].get() )->SetSelectHdl( aLink
);
223 static_cast<ListBox
*>( mpControls
[CB_SLIDESPERPAGE
-1].get() )->SetSelectHdl( aLink
);
227 bool SdPrintDialog::Fill( SdOptionsPrintItem
* pPrintOpts
)
229 bool bChanges
= false;
230 if( mbImpress
&& pPrintOpts
)
232 SdOptionsPrint
& rOpts
= pPrintOpts
->GetOptionsPrint();
234 BOOL bDraw
= FALSE
, bHandout
= FALSE
, bNotes
= FALSE
, bOutline
= FALSE
;
235 switch( static_cast<ListBox
*>( mpControls
[CB_CONTENT
-1].get() )->GetSelectEntryPos() )
237 case 1: bHandout
= TRUE
; break;
238 case 2: bNotes
= TRUE
; break;
239 case 3: bOutline
= TRUE
; break;
240 default: bDraw
= TRUE
; break;
242 if( rOpts
.IsDraw() != bDraw
)
245 rOpts
.SetDraw( bDraw
);
248 if( rOpts
.IsNotes() != bNotes
)
251 rOpts
.SetNotes( bNotes
);
254 if( rOpts
.IsHandout() != bHandout
)
257 rOpts
.SetHandout( bHandout
);
260 if( rOpts
.IsOutline() != bOutline
)
263 rOpts
.SetOutline( bOutline
);
266 sal_uInt16 nSlidePerHandout
= 6;
267 switch( static_cast<ListBox
*>( mpControls
[CB_SLIDESPERPAGE
-1].get() )->GetSelectEntryPos() )
269 case 0: nSlidePerHandout
= 1; break;
270 case 1: nSlidePerHandout
= 2; break;
271 case 2: nSlidePerHandout
= 3; break;
272 case 3: nSlidePerHandout
= 4; break;
273 case 5: nSlidePerHandout
= 9; break;
276 if( rOpts
.GetHandoutPages() != nSlidePerHandout
)
279 rOpts
.SetHandoutPages( nSlidePerHandout
);
282 const BOOL bHorizontal
= static_cast<RadioButton
*>( mpControls
[RBT_HORIZONTAL
-1].get() )->IsChecked();
283 if( rOpts
.IsHandoutHorizontal() != bHorizontal
)
286 rOpts
.SetHandoutHorizontal( bHorizontal
);
292 static const sal_uInt16 PREVIEW_COUNT
= 6;
294 void SdPrintDialog::UpdateStates()
296 const sal_uInt16 nSlidesPerPagePos
= static_cast<ListBox
*>( mpControls
[CB_SLIDESPERPAGE
-1].get() )->GetSelectEntryPos();
297 bool bHandout
= static_cast<ListBox
*>( mpControls
[CB_CONTENT
-1].get() )->GetSelectEntryPos() == 1;
298 bool bOrder
= bHandout
&& ( nSlidesPerPagePos
>= 3);
300 static_cast<Control
*>( mpControls
[FT_SLIDESPERPAGE
-1].get() )->Enable( bHandout
);
301 static_cast<Control
*>( mpControls
[CB_SLIDESPERPAGE
-1].get() )->Enable( bHandout
);
302 static_cast<Control
*>( mpControls
[FT_ORDER
-1].get() )->Enable( bHandout
&& bOrder
);
303 static_cast<Control
*>( mpControls
[RBT_HORIZONTAL
-1].get() )->Enable( bHandout
&& bOrder
);
304 static_cast<Control
*>( mpControls
[RBT_VERTICAL
-1].get() )->Enable( bHandout
&& bOrder
);
306 FixedImage
* pPreviewImage
= static_cast<FixedImage
*>( mpControls
[IMG_PREVIEW
-1].get() );
310 pPreviewImage
->Show( bHandout
);
313 if( nSlidesPerPagePos
< PREVIEW_COUNT
)
315 if( mpPreviews
[nSlidesPerPagePos
].get() )
316 pPreviewImage
->SetModeImage( *mpPreviews
[nSlidesPerPagePos
].get(), BMP_COLOR_NORMAL
);
318 if( mpPreviewsHC
[nSlidesPerPagePos
].get() )
319 pPreviewImage
->SetModeImage( *mpPreviewsHC
[nSlidesPerPagePos
].get(), BMP_COLOR_HIGHCONTRAST
);
325 IMPL_LINK( SdPrintDialog
, UpdateStatesHdl
, void*, EMPTYARG
)
331 void SdPrintDialog::LoadPreviewImages()
333 static const sal_uInt16 aResId
[2*PREVIEW_COUNT
] = { BMP_FOILH_01
, BMP_FOILH_01_H
, BMP_FOILH_02
, BMP_FOILH_02_H
, BMP_FOILH_03
, BMP_FOILH_03_H
, BMP_FOILH_04
, BMP_FOILH_04_H
, BMP_FOILH_06
, BMP_FOILH_06_H
, BMP_FOILH_09
, BMP_FOILH_09_H
};
335 mpPreviews
.resize( PREVIEW_COUNT
);
336 mpPreviewsHC
.resize( PREVIEW_COUNT
);
338 const sal_uInt16
* pResId( aResId
);
339 for( sal_uInt16 i
= 0; i
< PREVIEW_COUNT
; i
++ )
341 mpPreviews
[i
].reset( new Image( Bitmap( SdResId( *pResId
++ ) ) ) );
342 mpPreviewsHC
[i
].reset( new Image( Bitmap( SdResId( *pResId
++ ) ) ) );