1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <sdattr.hrc>
21 #include <optsitem.hxx>
22 #include <prntopts.hxx>
23 #include <app.hrc>
24 #include <svl/intitem.hxx>
25 
26 /**
27  *  dialog to adjust print options
28  */
SdPrintOptions(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & rInAttrs)29 SdPrintOptions::SdPrintOptions(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
30     : SfxTabPage(pPage, pController, "modules/simpress/ui/prntopts.ui", "prntopts", &rInAttrs)
31     , m_xFrmContent(m_xBuilder->weld_frame("contentframe"))
32     , m_xCbxDraw(m_xBuilder->weld_check_button("drawingcb"))
33     , m_xCbxNotes(m_xBuilder->weld_check_button("notecb"))
34     , m_xCbxHandout(m_xBuilder->weld_check_button("handoutcb"))
35     , m_xCbxOutline(m_xBuilder->weld_check_button("outlinecb"))
36     , m_xRbtColor(m_xBuilder->weld_radio_button("defaultrb"))
37     , m_xRbtGrayscale(m_xBuilder->weld_radio_button("grayscalerb"))
38     , m_xRbtBlackWhite(m_xBuilder->weld_radio_button("blackwhiterb"))
39     , m_xCbxPagename(m_xBuilder->weld_check_button("pagenmcb"))
40     , m_xCbxDate(m_xBuilder->weld_check_button("datecb"))
41     , m_xCbxTime(m_xBuilder->weld_check_button("timecb"))
42     , m_xCbxHiddenPages(m_xBuilder->weld_check_button("hiddenpgcb"))
43     , m_xRbtDefault(m_xBuilder->weld_radio_button("pagedefaultrb"))
44     , m_xRbtPagesize(m_xBuilder->weld_radio_button("fittopgrb"))
45     , m_xRbtPagetile(m_xBuilder->weld_radio_button("tilepgrb"))
46     , m_xRbtBooklet(m_xBuilder->weld_radio_button("brouchrb"))
47     , m_xCbxFront(m_xBuilder->weld_check_button("frontcb"))
48     , m_xCbxBack(m_xBuilder->weld_check_button("backcb"))
49     , m_xCbxPaperbin(m_xBuilder->weld_check_button("papertryfrmprntrcb"))
50 {
51     Link<weld::ToggleButton&,void> aLink = LINK( this, SdPrintOptions, ClickBookletHdl );
52     m_xRbtDefault->connect_toggled( aLink );
53     m_xRbtPagesize->connect_toggled( aLink );
54     m_xRbtPagetile->connect_toggled( aLink );
55     m_xRbtBooklet->connect_toggled( aLink );
56 
57     aLink = LINK( this, SdPrintOptions, ClickCheckboxHdl );
58     m_xCbxDraw->connect_toggled( aLink );
59     m_xCbxNotes->connect_toggled( aLink );
60     m_xCbxHandout->connect_toggled( aLink );
61     m_xCbxOutline->connect_toggled( aLink );
62 
63 #ifndef MACOSX
64     SetDrawMode();
65 #endif
66 }
67 
~SdPrintOptions()68 SdPrintOptions::~SdPrintOptions()
69 {
70 }
71 
FillItemSet(SfxItemSet * rAttrs)72 bool SdPrintOptions::FillItemSet( SfxItemSet* rAttrs )
73 {
74     if( m_xCbxDraw->get_state_changed_from_saved() ||
75         m_xCbxNotes->get_state_changed_from_saved() ||
76         m_xCbxHandout->get_state_changed_from_saved() ||
77         m_xCbxOutline->get_state_changed_from_saved() ||
78         m_xCbxDate->get_state_changed_from_saved() ||
79         m_xCbxTime->get_state_changed_from_saved() ||
80         m_xCbxPagename->get_state_changed_from_saved() ||
81         m_xCbxHiddenPages->get_state_changed_from_saved() ||
82         m_xRbtPagesize->get_state_changed_from_saved() ||
83         m_xRbtPagetile->get_state_changed_from_saved() ||
84         m_xRbtBooklet->get_state_changed_from_saved() ||
85         m_xCbxFront->get_state_changed_from_saved() ||
86         m_xCbxBack->get_state_changed_from_saved() ||
87         m_xCbxPaperbin->get_state_changed_from_saved() ||
88         m_xRbtColor->get_state_changed_from_saved() ||
89         m_xRbtGrayscale->get_state_changed_from_saved()||
90         m_xRbtBlackWhite->get_state_changed_from_saved())
91     {
92         SdOptionsPrintItem aOptions;
93 
94         aOptions.GetOptionsPrint().SetDraw( m_xCbxDraw->get_active() );
95         aOptions.GetOptionsPrint().SetNotes( m_xCbxNotes->get_active() );
96         aOptions.GetOptionsPrint().SetHandout( m_xCbxHandout->get_active() );
97         aOptions.GetOptionsPrint().SetOutline( m_xCbxOutline->get_active() );
98         aOptions.GetOptionsPrint().SetDate( m_xCbxDate->get_active() );
99         aOptions.GetOptionsPrint().SetTime( m_xCbxTime->get_active() );
100         aOptions.GetOptionsPrint().SetPagename( m_xCbxPagename->get_active() );
101         aOptions.GetOptionsPrint().SetHiddenPages( m_xCbxHiddenPages->get_active() );
102         aOptions.GetOptionsPrint().SetPagesize( m_xRbtPagesize->get_active() );
103         aOptions.GetOptionsPrint().SetPagetile( m_xRbtPagetile->get_active() );
104         aOptions.GetOptionsPrint().SetBooklet( m_xRbtBooklet->get_active() );
105         aOptions.GetOptionsPrint().SetFrontPage( m_xCbxFront->get_active() );
106         aOptions.GetOptionsPrint().SetBackPage( m_xCbxBack->get_active() );
107         aOptions.GetOptionsPrint().SetPaperbin( m_xCbxPaperbin->get_active() );
108 
109         sal_uInt16 nQuality = 0; // Standard, also Color
110         if( m_xRbtGrayscale->get_active() )
111             nQuality = 1;
112         if( m_xRbtBlackWhite->get_active() )
113             nQuality = 2;
114         aOptions.GetOptionsPrint().SetOutputQuality( nQuality );
115 
116         rAttrs->Put( aOptions );
117 
118         return true;
119     }
120     return false;
121 }
122 
Reset(const SfxItemSet * rAttrs)123 void SdPrintOptions::Reset( const SfxItemSet* rAttrs )
124 {
125     const SdOptionsPrintItem* pPrintOpts = nullptr;
126     if( SfxItemState::SET == rAttrs->GetItemState( ATTR_OPTIONS_PRINT, false,
127                             reinterpret_cast<const SfxPoolItem**>(&pPrintOpts) ) )
128     {
129         m_xCbxDraw->set_active(              pPrintOpts->GetOptionsPrint().IsDraw() );
130         m_xCbxNotes->set_active(             pPrintOpts->GetOptionsPrint().IsNotes() );
131         m_xCbxHandout->set_active(           pPrintOpts->GetOptionsPrint().IsHandout() );
132         m_xCbxOutline->set_active(           pPrintOpts->GetOptionsPrint().IsOutline() );
133         m_xCbxDate->set_active(              pPrintOpts->GetOptionsPrint().IsDate() );
134         m_xCbxTime->set_active(              pPrintOpts->GetOptionsPrint().IsTime() );
135         m_xCbxPagename->set_active(          pPrintOpts->GetOptionsPrint().IsPagename() );
136         m_xCbxHiddenPages->set_active(       pPrintOpts->GetOptionsPrint().IsHiddenPages() );
137         m_xRbtPagesize->set_active(          pPrintOpts->GetOptionsPrint().IsPagesize() );
138         m_xRbtPagetile->set_active(          pPrintOpts->GetOptionsPrint().IsPagetile() );
139         m_xRbtBooklet->set_active(           pPrintOpts->GetOptionsPrint().IsBooklet() );
140         m_xCbxFront->set_active(             pPrintOpts->GetOptionsPrint().IsFrontPage() );
141         m_xCbxBack->set_active(              pPrintOpts->GetOptionsPrint().IsBackPage() );
142         m_xCbxPaperbin->set_active(          pPrintOpts->GetOptionsPrint().IsPaperbin() );
143 
144         if( !m_xRbtPagesize->get_active() &&
145             !m_xRbtPagetile->get_active() &&
146             !m_xRbtBooklet->get_active() )
147         {
148             m_xRbtDefault->set_active(true);
149         }
150 
151         sal_uInt16 nQuality = pPrintOpts->GetOptionsPrint().GetOutputQuality();
152         if( nQuality == 0 )
153             m_xRbtColor->set_active(true);
154         else if( nQuality == 1 )
155             m_xRbtGrayscale->set_active(true);
156         else
157             m_xRbtBlackWhite->set_active(true);
158     }
159     m_xCbxDraw->save_state();
160     m_xCbxNotes->save_state();
161     m_xCbxHandout->save_state();
162     m_xCbxOutline->save_state();
163     m_xCbxDate->save_state();
164     m_xCbxTime->save_state();
165     m_xCbxPagename->save_state();
166     m_xCbxHiddenPages->save_state();
167     m_xRbtPagesize->save_state();
168     m_xRbtPagetile->save_state();
169     m_xRbtBooklet->save_state();
170     m_xCbxPaperbin->save_state();
171     m_xRbtColor->save_state();
172     m_xRbtGrayscale->save_state();
173     m_xRbtBlackWhite->save_state();
174 
175     updateControls();
176 }
177 
Create(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * rOutAttrs)178 std::unique_ptr<SfxTabPage> SdPrintOptions::Create( weld::Container* pPage, weld::DialogController* pController,
179                                            const SfxItemSet* rOutAttrs )
180 {
181     return std::make_unique<SdPrintOptions>( pPage, pController, *rOutAttrs );
182 }
183 
IMPL_LINK(SdPrintOptions,ClickCheckboxHdl,weld::ToggleButton &,rCbx,void)184 IMPL_LINK(SdPrintOptions, ClickCheckboxHdl, weld::ToggleButton&, rCbx, void)
185 {
186     // there must be at least one of them checked
187     if( !m_xCbxDraw->get_active() && !m_xCbxNotes->get_active() && !m_xCbxOutline->get_active() && !m_xCbxHandout->get_active() )
188         rCbx.set_active(true);
189 
190     updateControls();
191 }
192 
IMPL_LINK_NOARG(SdPrintOptions,ClickBookletHdl,weld::ToggleButton &,void)193 IMPL_LINK_NOARG(SdPrintOptions, ClickBookletHdl, weld::ToggleButton&, void)
194 {
195     updateControls();
196 }
197 
updateControls()198 void SdPrintOptions::updateControls()
199 {
200     m_xCbxFront->set_sensitive(m_xRbtBooklet->get_active());
201     m_xCbxBack->set_sensitive(m_xRbtBooklet->get_active());
202 
203     m_xCbxDate->set_sensitive( !m_xRbtBooklet->get_active() );
204     m_xCbxTime->set_sensitive( !m_xRbtBooklet->get_active() );
205 
206     m_xCbxPagename->set_sensitive( !m_xRbtBooklet->get_active() && (m_xCbxDraw->get_active() || m_xCbxNotes->get_active() || m_xCbxOutline->get_active()) );
207 }
208 
SetDrawMode()209 void    SdPrintOptions::SetDrawMode()
210 {
211     if (m_xCbxNotes->get_visible())
212     {
213         m_xFrmContent->hide();
214     }
215 }
216 
PageCreated(const SfxAllItemSet & aSet)217 void SdPrintOptions::PageCreated (const SfxAllItemSet&
218 #ifdef MACOSX
219                                   aSet
220 #endif
221                                   )
222 {
223 #ifdef MACOSX
224     const SfxUInt32Item* pFlagItem = aSet.GetItem<SfxUInt32Item>(SID_SDMODE_FLAG, false);
225     if (pFlagItem)
226     {
227         sal_uInt32 nFlags=pFlagItem->GetValue();
228         if ( ( nFlags & SD_DRAW_MODE ) == SD_DRAW_MODE )
229             SetDrawMode();
230     }
231 #else
232     SetDrawMode();
233 #endif
234 }
235 
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
237