xref: /AOO41X/main/sw/source/ui/envelp/labprt.cxx (revision efeef26f81c84063fb0a91bde3856d4a51172d90)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #ifdef SW_DLLIMPLEMENTATION
28 #undef SW_DLLIMPLEMENTATION
29 #endif
30 
31 
32 #include <svtools/prnsetup.hxx>
33 #include <unotools/cmdoptions.hxx>
34 #include <vcl/print.hxx>
35 #include <wrtsh.hxx>
36 #include <label.hxx>
37 #include <labprt.hxx>
38 #include <labimg.hxx>
39 #ifndef _LABIMP_HXX
40 #include "swuilabimp.hxx"
41 #endif
42 
43 #ifndef _CMDID_H
44 #include <cmdid.h>
45 #endif
46 #ifndef _LABPRT_HRC
47 #include <labprt.hrc>
48 #endif
49 
50 
51 // --------------------------------------------------------------------------
52 
53 
54 
SwLabPrtPage(Window * pParent,const SfxItemSet & rSet)55 SwLabPrtPage::SwLabPrtPage(Window* pParent, const SfxItemSet& rSet) :
56 
57     SfxTabPage(pParent, SW_RES(TP_LAB_PRT), rSet),
58 
59     pPrinter( 0 ),
60     aFLDontKnow    (this, SW_RES(FL_DONTKNOW)),
61     aPageButton    (this, SW_RES(BTN_PAGE   )),
62     aSingleButton  (this, SW_RES(BTN_SINGLE )),
63     aColText       (this, SW_RES(TXT_COL    )),
64     aColField      (this, SW_RES(FLD_COL    )),
65     aRowText       (this, SW_RES(TXT_ROW    )),
66     aRowField      (this, SW_RES(FLD_ROW    )),
67     aSynchronCB    (this, SW_RES(CB_SYNCHRON)),
68     aFLPrinter     (this, SW_RES(FL_PRINTER )),
69     aPrinterInfo   (this, SW_RES(INF_PRINTER)),
70     aPrtSetup      (this, SW_RES(BTN_PRTSETUP))
71 
72 {
73     FreeResource();
74     SetExchangeSupport();
75 
76     // Handler installieren
77     Link aLk = LINK(this, SwLabPrtPage, CountHdl);
78     aPageButton  .SetClickHdl( aLk );
79     aSingleButton.SetClickHdl( aLk );
80 
81     aPrtSetup.SetClickHdl( aLk );
82 
83     SvtCommandOptions aCmdOpts;
84     if ( aCmdOpts.Lookup(
85              SvtCommandOptions::CMDOPTION_DISABLED,
86              rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Print"  ) ) ) )
87     {
88         aPrinterInfo.Hide();
89         aPrtSetup.Hide();
90         aFLPrinter.Hide();
91     }
92 }
93 
94 // --------------------------------------------------------------------------
95 
96 
97 
~SwLabPrtPage()98 SwLabPrtPage::~SwLabPrtPage()
99 {
100     if (pPrinter)
101         delete pPrinter;
102 }
103 
104 // --------------------------------------------------------------------------
105 
106 
107 
IMPL_LINK(SwLabPrtPage,CountHdl,Button *,pButton)108 IMPL_LINK( SwLabPrtPage, CountHdl, Button *, pButton )
109 {
110     if (pButton == &aPrtSetup)
111     {
112         // Druck-Setup aufrufen
113         if (!pPrinter)
114             pPrinter = new Printer;
115 
116         PrinterSetupDialog* pDlg = new PrinterSetupDialog(this );
117         pDlg->SetPrinter(pPrinter);
118         pDlg->Execute();
119         delete pDlg;
120         GrabFocus();
121         aPrinterInfo.SetText(pPrinter->GetName());
122         return 0;
123     }
124     const sal_Bool bEnable = pButton == &aSingleButton;
125     aColText .Enable(bEnable);
126     aColField.Enable(bEnable);
127     aRowText .Enable(bEnable);
128     aRowField.Enable(bEnable);
129     aSynchronCB.Enable(!bEnable);
130 
131     if ( bEnable )
132         aColField.GrabFocus();
133 #ifdef DBG_UTIL
134     else
135         ASSERT( pButton == &aPageButton, "NewButton?" );
136 #endif
137     return 0;
138 }
139 
140 // --------------------------------------------------------------------------
141 
142 
143 
Create(Window * pParent,const SfxItemSet & rSet)144 SfxTabPage* SwLabPrtPage::Create(Window* pParent, const SfxItemSet& rSet)
145 {
146     return new SwLabPrtPage( pParent, rSet );
147 }
148 
149 // --------------------------------------------------------------------------
150 
151 
152 
ActivatePage(const SfxItemSet & rSet)153 void SwLabPrtPage::ActivatePage( const SfxItemSet& rSet )
154 {
155     Reset(rSet);
156 }
157 
158 // --------------------------------------------------------------------------
159 
160 
161 
DeactivatePage(SfxItemSet * _pSet)162 int SwLabPrtPage::DeactivatePage(SfxItemSet* _pSet)
163 {
164     if ( _pSet )
165         FillItemSet(*_pSet);
166 
167     return sal_True;
168 }
169 
170 // --------------------------------------------------------------------------
171 
172 
173 
FillItem(SwLabItem & rItem)174 void SwLabPrtPage::FillItem(SwLabItem& rItem)
175 {
176     rItem.bPage = aPageButton.IsChecked();
177     rItem.nCol  = (sal_uInt16) aColField.GetValue();
178     rItem.nRow  = (sal_uInt16) aRowField.GetValue();
179     rItem.bSynchron = aSynchronCB.IsChecked() && aSynchronCB.IsEnabled();
180 }
181 
182 // --------------------------------------------------------------------------
183 
184 
185 
FillItemSet(SfxItemSet & rSet)186 sal_Bool SwLabPrtPage::FillItemSet(SfxItemSet& rSet)
187 {
188     SwLabItem aItem;
189     GetParent()->GetLabItem(aItem);
190     FillItem(aItem);
191     rSet.Put(aItem);
192 
193     return sal_True;
194 }
195 
196 // --------------------------------------------------------------------------
197 
198 
199 
Reset(const SfxItemSet &)200 void SwLabPrtPage::Reset(const SfxItemSet& )
201 {
202     SwLabItem aItem;
203     GetParent()->GetLabItem(aItem);
204 
205     aColField.SetValue   (aItem.nCol);
206     aRowField.SetValue   (aItem.nRow);
207 
208     if (aItem.bPage)
209     {
210         aPageButton.Check();
211         aPageButton.GetClickHdl().Call(&aPageButton);
212     }
213     else
214     {
215         aSingleButton.GetClickHdl().Call(&aSingleButton);
216         aSingleButton.Check();
217     }
218 
219     if (pPrinter)
220     {
221         // Drucker anzeigen
222         aPrinterInfo.SetText(pPrinter->GetName());
223     }
224     else
225         aPrinterInfo.SetText(Printer::GetDefaultPrinterName());
226 
227     aColField.SetMax(aItem.nCols);
228     aRowField.SetMax(aItem.nRows);
229 
230     aColField.SetLast(aColField.GetMax());
231     aRowField.SetLast(aRowField.GetMax());
232 
233     aSynchronCB.Check(aItem.bSynchron);
234 }
235 
236 
237 
238 
239