summaryrefslogtreecommitdiff
path: root/sw/source/ui/envelp/labprt.cxx
blob: 4bc9f9d88a038999e11a818c662f169bcf21b06f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <svtools/prnsetup.hxx>
#include <unotools/cmdoptions.hxx>
#include <vcl/print.hxx>
#include <wrtsh.hxx>
#include <label.hxx>
#include "labprt.hxx"
#include <labimg.hxx>

#include <cmdid.h>

SwLabPrtPage::SwLabPrtPage(vcl::Window* pParent, const SfxItemSet& rSet)
    : SfxTabPage(pParent, "LabelOptionsPage",
        "modules/swriter/ui/labeloptionspage.ui", &rSet)
    , pPrinter(nullptr)
{
    get(m_pPageButton, "entirepage");
    get(m_pSingleButton, "singlelabel");
    get(m_pSingleGrid, "singlegrid");
    get(m_pColField, "cols");
    get(m_pRowField, "rows");
    get(m_pSynchronCB, "synchronize");
    get(m_pPrinterFrame, "printerframe");
    get(m_pPrinterInfo, "printername");
    get(m_pPrtSetup, "setup");
    SetExchangeSupport();

    // Install handlers
    Link<Button*,void> aLk = LINK(this, SwLabPrtPage, CountHdl);
    m_pPageButton->SetClickHdl( aLk );
    m_pSingleButton->SetClickHdl( aLk );

    m_pPrtSetup->SetClickHdl( aLk );

    SvtCommandOptions aCmdOpts;
    if ( aCmdOpts.Lookup(
             SvtCommandOptions::CMDOPTION_DISABLED,
             "Print" ) )
    {
        m_pPrinterFrame->Hide();
    }
}

SwLabPrtPage::~SwLabPrtPage()
{
    disposeOnce();
}

void SwLabPrtPage::dispose()
{
    pPrinter.disposeAndClear();
    m_pPageButton.clear();
    m_pSingleButton.clear();
    m_pSingleGrid.clear();
    m_pPrinterFrame.clear();
    m_pColField.clear();
    m_pRowField.clear();
    m_pSynchronCB.clear();
    m_pPrinterInfo.clear();
    m_pPrtSetup.clear();
    SfxTabPage::dispose();
}

IMPL_LINK( SwLabPrtPage, CountHdl, Button *, pButton, void )
{
    if (pButton == m_pPrtSetup)
    {
        // Call printer setup
        if (!pPrinter)
            pPrinter = VclPtr<Printer>::Create();

        VclPtrInstance< PrinterSetupDialog > pDlg(this);
        pDlg->SetPrinter(pPrinter);
        pDlg->Execute();
        pDlg.disposeAndClear();
        GrabFocus();
        m_pPrinterInfo->SetText(pPrinter->GetName());
        return;
    }
    const bool bEnable = pButton == m_pSingleButton;
    m_pSingleGrid->Enable(bEnable);
    m_pSynchronCB->Enable(!bEnable);

    OSL_ENSURE(!bEnable || pButton == m_pPageButton, "NewButton?" );
    if ( bEnable )
    {
        m_pColField->GrabFocus();
    }
}

VclPtr<SfxTabPage> SwLabPrtPage::Create(vcl::Window* pParent, const SfxItemSet* rSet)
{
    return VclPtr<SwLabPrtPage>::Create( pParent, *rSet );
}

void SwLabPrtPage::ActivatePage( const SfxItemSet& rSet )
{
    Reset(&rSet);
}

DeactivateRC SwLabPrtPage::DeactivatePage(SfxItemSet* _pSet)
{
    if ( _pSet )
        FillItemSet(_pSet);

    return DeactivateRC::LeavePage;
}

void SwLabPrtPage::FillItem(SwLabItem& rItem)
{
    rItem.m_bPage = m_pPageButton->IsChecked();
    rItem.m_nCol = static_cast<sal_Int32>(m_pColField->GetValue());
    rItem.m_nRow = static_cast<sal_Int32>(m_pRowField->GetValue());
    rItem.m_bSynchron = m_pSynchronCB->IsChecked() && m_pSynchronCB->IsEnabled();
}

bool SwLabPrtPage::FillItemSet(SfxItemSet* rSet)
{
    SwLabItem aItem;
    GetParentSwLabDlg()->GetLabItem(aItem);
    FillItem(aItem);
    rSet->Put(aItem);

    return true;
}

void SwLabPrtPage::Reset(const SfxItemSet* )
{
    SwLabItem aItem;
    GetParentSwLabDlg()->GetLabItem(aItem);

    m_pColField->SetValue   (aItem.m_nCol);
    m_pRowField->SetValue   (aItem.m_nRow);

    if (aItem.m_bPage)
    {
        m_pPageButton->Check();
        m_pPageButton->GetClickHdl().Call(m_pPageButton);
    }
    else
    {
        m_pSingleButton->GetClickHdl().Call(m_pSingleButton);
        m_pSingleButton->Check();
    }

    if (pPrinter)
    {
        // show printer
        m_pPrinterInfo->SetText(pPrinter->GetName());
    }
    else
        m_pPrinterInfo->SetText(Printer::GetDefaultPrinterName());

    m_pColField->SetMax(aItem.m_nCols);
    m_pRowField->SetMax(aItem.m_nRows);

    m_pColField->SetLast(m_pColField->GetMax());
    m_pRowField->SetLast(m_pRowField->GetMax());

    m_pSynchronCB->Check(aItem.m_bSynchron);
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */