Line data Source code
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 <svtools/prnsetup.hxx>
21 : #include <unotools/cmdoptions.hxx>
22 : #include <vcl/print.hxx>
23 : #include <wrtsh.hxx>
24 : #include <label.hxx>
25 : #include <labprt.hxx>
26 : #include <labimg.hxx>
27 : #include "swuilabimp.hxx"
28 :
29 : #include <cmdid.h>
30 :
31 0 : SwLabPrtPage::SwLabPrtPage(Window* pParent, const SfxItemSet& rSet)
32 : : SfxTabPage(pParent, "LabelOptionsPage",
33 : "modules/swriter/ui/labeloptionspage.ui", rSet)
34 0 : , pPrinter(0)
35 : {
36 0 : get(m_pPageButton, "entirepage");
37 0 : get(m_pSingleButton, "singlelabel");
38 0 : get(m_pSingleGrid, "singlegrid");
39 0 : get(m_pColField, "cols");
40 0 : get(m_pRowField, "rows");
41 0 : get(m_pSynchronCB, "synchronize");
42 0 : get(m_pPrinterFrame, "printerframe");
43 0 : get(m_pPrinterInfo, "printername");
44 0 : get(m_pPrtSetup, "setup");
45 0 : SetExchangeSupport();
46 :
47 : // Install handlers
48 0 : Link aLk = LINK(this, SwLabPrtPage, CountHdl);
49 0 : m_pPageButton->SetClickHdl( aLk );
50 0 : m_pSingleButton->SetClickHdl( aLk );
51 :
52 0 : m_pPrtSetup->SetClickHdl( aLk );
53 :
54 0 : SvtCommandOptions aCmdOpts;
55 0 : if ( aCmdOpts.Lookup(
56 : SvtCommandOptions::CMDOPTION_DISABLED,
57 0 : OUString( "Print" ) ) )
58 : {
59 0 : m_pPrinterFrame->Hide();
60 0 : }
61 0 : }
62 :
63 0 : SwLabPrtPage::~SwLabPrtPage()
64 : {
65 0 : delete pPrinter;
66 0 : }
67 :
68 0 : IMPL_LINK( SwLabPrtPage, CountHdl, Button *, pButton )
69 : {
70 0 : if (pButton == m_pPrtSetup)
71 : {
72 : // Call printer setup
73 0 : if (!pPrinter)
74 0 : pPrinter = new Printer;
75 :
76 0 : PrinterSetupDialog* pDlg = new PrinterSetupDialog(this );
77 0 : pDlg->SetPrinter(pPrinter);
78 0 : pDlg->Execute();
79 0 : delete pDlg;
80 0 : GrabFocus();
81 0 : m_pPrinterInfo->SetText(pPrinter->GetName());
82 0 : return 0;
83 : }
84 0 : const bool bEnable = pButton == m_pSingleButton;
85 0 : m_pSingleGrid->Enable(bEnable);
86 0 : m_pSynchronCB->Enable(!bEnable);
87 :
88 : OSL_ENSURE(!bEnable || pButton == m_pPageButton, "NewButton?" );
89 0 : if ( bEnable )
90 : {
91 0 : m_pColField->GrabFocus();
92 : }
93 0 : return 0;
94 : }
95 :
96 0 : SfxTabPage* SwLabPrtPage::Create(Window* pParent, const SfxItemSet& rSet)
97 : {
98 0 : return new SwLabPrtPage( pParent, rSet );
99 : }
100 :
101 0 : void SwLabPrtPage::ActivatePage( const SfxItemSet& rSet )
102 : {
103 0 : Reset(rSet);
104 0 : }
105 :
106 0 : int SwLabPrtPage::DeactivatePage(SfxItemSet* _pSet)
107 : {
108 0 : if ( _pSet )
109 0 : FillItemSet(*_pSet);
110 :
111 0 : return sal_True;
112 : }
113 :
114 0 : void SwLabPrtPage::FillItem(SwLabItem& rItem)
115 : {
116 0 : rItem.bPage = m_pPageButton->IsChecked();
117 0 : rItem.nCol = static_cast<sal_Int32>(m_pColField->GetValue());
118 0 : rItem.nRow = static_cast<sal_Int32>(m_pRowField->GetValue());
119 0 : rItem.bSynchron = m_pSynchronCB->IsChecked() && m_pSynchronCB->IsEnabled();
120 0 : }
121 :
122 0 : bool SwLabPrtPage::FillItemSet(SfxItemSet& rSet)
123 : {
124 0 : SwLabItem aItem;
125 0 : GetParentSwLabDlg()->GetLabItem(aItem);
126 0 : FillItem(aItem);
127 0 : rSet.Put(aItem);
128 :
129 0 : return true;
130 : }
131 :
132 0 : void SwLabPrtPage::Reset(const SfxItemSet& )
133 : {
134 0 : SwLabItem aItem;
135 0 : GetParentSwLabDlg()->GetLabItem(aItem);
136 :
137 0 : m_pColField->SetValue (aItem.nCol);
138 0 : m_pRowField->SetValue (aItem.nRow);
139 :
140 0 : if (aItem.bPage)
141 : {
142 0 : m_pPageButton->Check();
143 0 : m_pPageButton->GetClickHdl().Call(m_pPageButton);
144 : }
145 : else
146 : {
147 0 : m_pSingleButton->GetClickHdl().Call(m_pSingleButton);
148 0 : m_pSingleButton->Check();
149 : }
150 :
151 0 : if (pPrinter)
152 : {
153 : // show printer
154 0 : m_pPrinterInfo->SetText(pPrinter->GetName());
155 : }
156 : else
157 0 : m_pPrinterInfo->SetText(Printer::GetDefaultPrinterName());
158 :
159 0 : m_pColField->SetMax(aItem.nCols);
160 0 : m_pRowField->SetMax(aItem.nRows);
161 :
162 0 : m_pColField->SetLast(m_pColField->GetMax());
163 0 : m_pRowField->SetLast(m_pRowField->GetMax());
164 :
165 0 : m_pSynchronCB->Check(aItem.bSynchron);
166 0 : }
167 :
168 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|