xref: /trunk/main/sd/source/ui/dlg/prntopts.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 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #ifdef SD_DLLIMPLEMENTATION
32 #undef SD_DLLIMPLEMENTATION
33 #endif
34 
35 
36 #include "sdattr.hxx"
37 #include "optsitem.hxx"
38 #include "prntopts.hrc"
39 #include "sdresid.hxx"
40 #include "prntopts.hxx"
41 #include "app.hrc"
42 #include <svl/intitem.hxx>
43 #include <sfx2/request.hxx>
44 
45 /*************************************************************************
46 |*
47 |*  Dialog zum Aendern der Print-Optionen
48 |*
49 \************************************************************************/
50 
51 SdPrintOptions::SdPrintOptions( Window* pParent, const SfxItemSet& rInAttrs ) :
52         SfxTabPage          ( pParent, SdResId( TP_PRINT_OPTIONS ), rInAttrs ),
53 
54         aGrpPrint               ( this, SdResId( GRP_PRINT ) ),
55         aCbxDraw                ( this, SdResId( CBX_DRAW ) ),
56         aCbxNotes               ( this, SdResId( CBX_NOTES ) ),
57         aCbxHandout             ( this, SdResId( CBX_HANDOUTS ) ),
58         aCbxOutline             ( this, SdResId( CBX_OUTLINE ) ),
59 
60         aSeparator1FL            ( this, SdResId( FL_SEPARATOR1 ) ),
61         aGrpOutput              ( this, SdResId( GRP_OUTPUT ) ),
62         aRbtColor               ( this, SdResId( RBT_COLOR ) ),
63         aRbtGrayscale           ( this, SdResId( RBT_GRAYSCALE ) ),
64         aRbtBlackWhite          ( this, SdResId( RBT_BLACKWHITE ) ),
65 
66         aGrpPrintExt            ( this, SdResId( GRP_PRINT_EXT ) ),
67         aCbxPagename            ( this, SdResId( CBX_PAGENAME ) ),
68         aCbxDate                ( this, SdResId( CBX_DATE ) ),
69         aCbxTime                ( this, SdResId( CBX_TIME ) ),
70         aCbxHiddenPages         ( this, SdResId( CBX_HIDDEN_PAGES ) ),
71 
72         aSeparator2FL            ( this, SdResId( FL_SEPARATOR2 ) ),
73         aGrpPageoptions         ( this, SdResId( GRP_PAGE ) ),
74         aRbtDefault             ( this, SdResId( RBT_DEFAULT ) ),
75         aRbtPagesize            ( this, SdResId( RBT_PAGESIZE ) ),
76         aRbtPagetile            ( this, SdResId( RBT_PAGETILE ) ),
77         aRbtBooklet             ( this, SdResId( RBT_BOOKLET ) ),
78         aCbxFront               ( this, SdResId( CBX_FRONT ) ),
79         aCbxBack                ( this, SdResId( CBX_BACK ) ),
80 
81         aCbxPaperbin            ( this, SdResId( CBX_PAPERBIN ) ),
82 
83         rOutAttrs               ( rInAttrs )
84 {
85     FreeResource();
86 
87     Link aLink = LINK( this, SdPrintOptions, ClickBookletHdl );
88     aRbtDefault.SetClickHdl( aLink );
89     aRbtPagesize.SetClickHdl( aLink );
90     aRbtPagetile.SetClickHdl( aLink );
91     aRbtBooklet.SetClickHdl( aLink );
92 
93     aLink = LINK( this, SdPrintOptions, ClickCheckboxHdl );
94     aCbxDraw.SetClickHdl( aLink );
95     aCbxNotes.SetClickHdl( aLink );
96     aCbxHandout.SetClickHdl( aLink );
97     aCbxOutline.SetClickHdl( aLink );
98 
99 #ifndef QUARTZ
100     SetDrawMode();
101 #endif
102 
103     aCbxFront.SetAccessibleRelationLabeledBy( &aRbtBooklet );
104     aCbxBack.SetAccessibleRelationLabeledBy( &aRbtBooklet );
105 }
106 
107 // -----------------------------------------------------------------------
108 
109 SdPrintOptions::~SdPrintOptions()
110 {
111 }
112 
113 // -----------------------------------------------------------------------
114 
115 sal_Bool SdPrintOptions::FillItemSet( SfxItemSet& rAttrs )
116 {
117     if( aCbxDraw.GetSavedValue() != aCbxDraw.IsChecked() ||
118         aCbxNotes.GetSavedValue() != aCbxNotes.IsChecked() ||
119         aCbxHandout.GetSavedValue() != aCbxHandout.IsChecked() ||
120         aCbxOutline.GetSavedValue() != aCbxOutline.IsChecked() ||
121         aCbxDate.GetSavedValue() != aCbxDate.IsChecked() ||
122         aCbxTime.GetSavedValue() != aCbxTime.IsChecked() ||
123         aCbxPagename.GetSavedValue() != aCbxPagename.IsChecked() ||
124         aCbxHiddenPages.GetSavedValue() != aCbxHiddenPages.IsChecked() ||
125         aRbtPagesize.GetSavedValue() != aRbtPagesize.IsChecked() ||
126         aRbtPagetile.GetSavedValue() != aRbtPagetile.IsChecked() ||
127         aRbtBooklet.GetSavedValue() != aRbtBooklet.IsChecked() ||
128         aCbxFront.GetSavedValue() != aCbxFront.IsChecked() ||
129         aCbxBack.GetSavedValue() != aCbxBack.IsChecked() ||
130         aCbxPaperbin.GetSavedValue() != aCbxPaperbin.IsChecked() ||
131         aRbtColor.GetSavedValue() != aRbtColor.IsChecked() ||
132         aRbtGrayscale.GetSavedValue() != aRbtGrayscale.IsChecked() ||
133         aRbtBlackWhite.GetSavedValue() != aRbtBlackWhite.IsChecked() )
134     {
135         SdOptionsPrintItem aOptions( ATTR_OPTIONS_PRINT );
136 
137         aOptions.GetOptionsPrint().SetDraw( aCbxDraw.IsChecked() );
138         aOptions.GetOptionsPrint().SetNotes( aCbxNotes.IsChecked() );
139         aOptions.GetOptionsPrint().SetHandout( aCbxHandout.IsChecked() );
140         aOptions.GetOptionsPrint().SetOutline( aCbxOutline.IsChecked() );
141         aOptions.GetOptionsPrint().SetDate( aCbxDate.IsChecked() );
142         aOptions.GetOptionsPrint().SetTime( aCbxTime.IsChecked() );
143         aOptions.GetOptionsPrint().SetPagename( aCbxPagename.IsChecked() );
144         aOptions.GetOptionsPrint().SetHiddenPages( aCbxHiddenPages.IsChecked() );
145         aOptions.GetOptionsPrint().SetPagesize( aRbtPagesize.IsChecked() );
146         aOptions.GetOptionsPrint().SetPagetile( aRbtPagetile.IsChecked() );
147         aOptions.GetOptionsPrint().SetBooklet( aRbtBooklet.IsChecked() );
148         aOptions.GetOptionsPrint().SetFrontPage( aCbxFront.IsChecked() );
149         aOptions.GetOptionsPrint().SetBackPage( aCbxBack.IsChecked() );
150         aOptions.GetOptionsPrint().SetPaperbin( aCbxPaperbin.IsChecked() );
151 
152         sal_uInt16 nQuality = 0; // Standard, also Color
153         if( aRbtGrayscale.IsChecked() )
154             nQuality = 1;
155         if( aRbtBlackWhite.IsChecked() )
156             nQuality = 2;
157         aOptions.GetOptionsPrint().SetOutputQuality( nQuality );
158 
159         rAttrs.Put( aOptions );
160 
161         return( sal_True );
162     }
163     return( sal_False );
164 }
165 
166 // -----------------------------------------------------------------------
167 
168 void SdPrintOptions::Reset( const SfxItemSet& rAttrs )
169 {
170     const SdOptionsPrintItem* pPrintOpts = NULL;
171     if( SFX_ITEM_SET == rAttrs.GetItemState( ATTR_OPTIONS_PRINT, sal_False,
172                             (const SfxPoolItem**) &pPrintOpts ) )
173     {
174         aCbxDraw.Check(              pPrintOpts->GetOptionsPrint().IsDraw() );
175         aCbxNotes.Check(             pPrintOpts->GetOptionsPrint().IsNotes() );
176         aCbxHandout.Check(           pPrintOpts->GetOptionsPrint().IsHandout() );
177         aCbxOutline.Check(           pPrintOpts->GetOptionsPrint().IsOutline() );
178         aCbxDate.Check(              pPrintOpts->GetOptionsPrint().IsDate() );
179         aCbxTime.Check(              pPrintOpts->GetOptionsPrint().IsTime() );
180         aCbxPagename.Check(          pPrintOpts->GetOptionsPrint().IsPagename() );
181         aCbxHiddenPages.Check(       pPrintOpts->GetOptionsPrint().IsHiddenPages() );
182         aRbtPagesize.Check(          pPrintOpts->GetOptionsPrint().IsPagesize() );
183         aRbtPagetile.Check(          pPrintOpts->GetOptionsPrint().IsPagetile() );
184         aRbtBooklet.Check(           pPrintOpts->GetOptionsPrint().IsBooklet() );
185         aCbxFront.Check(             pPrintOpts->GetOptionsPrint().IsFrontPage() );
186         aCbxBack.Check(              pPrintOpts->GetOptionsPrint().IsBackPage() );
187         aCbxPaperbin.Check(          pPrintOpts->GetOptionsPrint().IsPaperbin() );
188 
189         if( !aRbtPagesize.IsChecked() &&
190             !aRbtPagetile.IsChecked() &&
191             !aRbtBooklet.IsChecked() )
192         {
193             aRbtDefault.Check();
194         }
195 
196         sal_uInt16 nQuality = pPrintOpts->GetOptionsPrint().GetOutputQuality();
197         if( nQuality == 0 )
198             aRbtColor.Check();
199         else if( nQuality == 1 )
200             aRbtGrayscale.Check();
201         else
202             aRbtBlackWhite.Check();
203     }
204     aCbxDraw.SaveValue();
205     aCbxNotes.SaveValue();
206     aCbxHandout.SaveValue();
207     aCbxOutline.SaveValue();
208     aCbxDate.SaveValue();
209     aCbxTime.SaveValue();
210     aCbxPagename.SaveValue();
211     aCbxHiddenPages.SaveValue();
212     aRbtPagesize.SaveValue();
213     aRbtPagetile.SaveValue();
214     aRbtBooklet.SaveValue();
215     aCbxPaperbin.SaveValue();
216     aRbtColor.SaveValue();
217     aRbtGrayscale.SaveValue();
218     aRbtBlackWhite.SaveValue();
219 
220     ClickBookletHdl( NULL );
221 }
222 
223 // -----------------------------------------------------------------------
224 
225 SfxTabPage* SdPrintOptions::Create( Window* pWindow,
226                 const SfxItemSet& rOutAttrs )
227 {
228     return( new SdPrintOptions( pWindow, rOutAttrs ) );
229 }
230 
231 //-----------------------------------------------------------------------
232 
233 IMPL_LINK( SdPrintOptions, ClickCheckboxHdl, CheckBox *, pCbx )
234 {
235     // there must be at least one of them checked
236     if( !aCbxDraw.IsChecked() && !aCbxNotes.IsChecked() && !aCbxOutline.IsChecked() && !aCbxHandout.IsChecked() )
237         pCbx->Check();
238 
239     updateControls();
240     return 0;
241 }
242 
243 //-----------------------------------------------------------------------
244 
245 IMPL_LINK( SdPrintOptions, ClickBookletHdl, CheckBox *, EMPTYARG )
246 {
247     updateControls();
248     return 0;
249 }
250 
251 void SdPrintOptions::updateControls()
252 {
253     aCbxFront.Enable(aRbtBooklet.IsChecked());
254     aCbxBack.Enable(aRbtBooklet.IsChecked());
255 
256     aCbxDate.Enable( !aRbtBooklet.IsChecked() );
257     aCbxTime.Enable( !aRbtBooklet.IsChecked() );
258 
259     aCbxPagename.Enable( !aRbtBooklet.IsChecked() && (aCbxDraw.IsChecked() || aCbxNotes.IsChecked() || aCbxOutline.IsChecked()) );
260 }
261 
262 /* -----------------------------04.05.01 10:53--------------------------------
263 
264  ---------------------------------------------------------------------------*/
265 void lcl_MoveRB_Impl(Window& rBtn, long nXDiff)
266 {
267     Point aPos(rBtn.GetPosPixel());
268     aPos.X() -= nXDiff;
269     rBtn.SetPosPixel(aPos);
270 }
271 
272 void    SdPrintOptions::SetDrawMode()
273 {
274     if(aCbxNotes.IsVisible())
275     {
276         aCbxNotes.Hide();
277         aCbxHandout.Hide();
278         aCbxOutline.Hide();
279         aCbxDraw.Hide();
280         aGrpPrint.Hide();
281 
282         aSeparator1FL.Hide();
283         long nXDiff = aGrpOutput.GetPosPixel().X() - aGrpPrint.GetPosPixel().X();
284         lcl_MoveRB_Impl(aRbtColor, nXDiff);
285         lcl_MoveRB_Impl(aRbtGrayscale, nXDiff);
286         lcl_MoveRB_Impl(aRbtBlackWhite, nXDiff);
287         lcl_MoveRB_Impl(aGrpOutput, nXDiff);
288 
289         long nWidth =  aGrpOutput.GetSizePixel().Width() + nXDiff;
290         Size aSize(aGrpOutput.GetSizePixel());
291         aSize.Width() = nWidth;
292         aGrpOutput.SetSizePixel(aSize);
293     }
294 }
295 
296 void SdPrintOptions::PageCreated (SfxAllItemSet
297 #ifdef QUARTZ
298                                   aSet
299 #endif
300                                   )
301 {
302 #ifdef QUARTZ
303     SFX_ITEMSET_ARG (&aSet,pFlagItem,SfxUInt32Item,SID_SDMODE_FLAG,sal_False);
304     if (pFlagItem)
305     {
306         sal_uInt32 nFlags=pFlagItem->GetValue();
307         if ( ( nFlags & SD_DRAW_MODE ) == SD_DRAW_MODE )
308             SetDrawMode();
309     }
310 #else
311     SetDrawMode();
312 #endif
313 }
314 
315