summaryrefslogtreecommitdiff
path: root/sd/source/ui/dlg/copydlg.cxx
blob: 5cd238bba6059bcbefe4e820e70b2e99d3ea8b0a (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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/* -*- 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 <copydlg.hxx>
#include <comphelper/string.hxx>
#include <svx/colorbox.hxx>
#include <svx/dlgutil.hxx>
#include <sfx2/module.hxx>
#include <svx/xcolit.hxx>
#include <svx/xflclit.hxx>
#include <svx/xdef.hxx>
#include <svx/xfillit0.hxx>
#include <svx/xenum.hxx>

#include <sfx2/app.hxx>

#include <sdattr.hxx>

#include <View.hxx>
#include <drawdoc.hxx>


namespace sd {

#define TOKEN ';'

CopyDlg::CopyDlg(vcl::Window* pWindow, const SfxItemSet& rInAttrs, ::sd::View* pInView)
    : SfxModalDialog(pWindow, "DuplicateDialog", "modules/sdraw/ui/copydlg.ui")
    , mrOutAttrs(rInAttrs)
    , maUIScale(pInView->GetDoc().GetUIScale())
    , mpView(pInView)
{
    get(m_pNumFldCopies, "copies");
    get(m_pBtnSetViewData, "viewdata");
    get(m_pMtrFldMoveX, "x");
    get(m_pMtrFldMoveY, "y");
    get(m_pMtrFldAngle, "angle");
    get(m_pMtrFldWidth, "width");
    get(m_pMtrFldHeight, "height");
    get(m_pLbStartColor, "start");
    get(m_pFtEndColor, "endlabel");
    get(m_pLbEndColor, "end");
    get(m_pBtnSetDefault, "default");

    m_pLbStartColor->SetSelectHdl( LINK( this, CopyDlg, SelectColorHdl ) );
    m_pBtnSetViewData->SetClickHdl( LINK( this, CopyDlg, SetViewData ) );
    m_pBtnSetDefault->SetClickHdl( LINK( this, CopyDlg, SetDefault ) );

    FieldUnit eFUnit( SfxModule::GetCurrentFieldUnit() );

    SetFieldUnit( *m_pMtrFldMoveX, eFUnit, true );
    SetFieldUnit( *m_pMtrFldMoveY, eFUnit, true );
    SetFieldUnit( *m_pMtrFldWidth, eFUnit, true );
    SetFieldUnit( *m_pMtrFldHeight, eFUnit, true );

    Reset();
}

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

void CopyDlg::dispose()
{
    OUString& rStr = GetExtraData();

    rStr = OUString::number(m_pNumFldCopies->GetValue());
    rStr += OUString(TOKEN);

    rStr += OUString::number(m_pMtrFldMoveX->GetValue());
    rStr += OUString( TOKEN );

    rStr += OUString::number(m_pMtrFldMoveY->GetValue());
    rStr += OUString( TOKEN );

    rStr += OUString::number(m_pMtrFldAngle->GetValue());
    rStr += OUString( TOKEN );

    rStr += OUString::number(m_pMtrFldWidth->GetValue());
    rStr += OUString( TOKEN );

    rStr += OUString::number(m_pMtrFldHeight->GetValue());
    rStr += OUString( TOKEN );

    rStr += OUString::number( sal_uInt32(m_pLbStartColor->GetSelectEntryColor()) );
    rStr += OUString( TOKEN );

    rStr += OUString::number( sal_uInt32(m_pLbEndColor->GetSelectEntryColor()) );

    m_pNumFldCopies.clear();
    m_pBtnSetViewData.clear();
    m_pMtrFldMoveX.clear();
    m_pMtrFldMoveY.clear();
    m_pMtrFldAngle.clear();
    m_pMtrFldWidth.clear();
    m_pMtrFldHeight.clear();
    m_pLbStartColor.clear();
    m_pFtEndColor.clear();
    m_pLbEndColor.clear();
    m_pBtnSetDefault.clear();
    SfxModalDialog::dispose();
}

/**
 * reads provided item set or evaluate ini string
 */
void CopyDlg::Reset()
{
    // Set Min/Max values
    ::tools::Rectangle aRect = mpView->GetAllMarkedRect();
    Size aPageSize = mpView->GetSdrPageView()->GetPage()->GetSize();
    SetMetricValue( *m_pMtrFldMoveX, long(1000000 / maUIScale), MapUnit::Map100thMM);
    double fScaleFactor = m_pMtrFldMoveX->GetValue()/1000000.0;

    long nPageWidth  = aPageSize.Width()  * fScaleFactor;
    long nPageHeight = aPageSize.Height() * fScaleFactor;
    long nRectWidth  = aRect.GetWidth()   * fScaleFactor;
    long nRectHeight = aRect.GetHeight()  * fScaleFactor;
    m_pMtrFldMoveX->SetMin( -nPageWidth );
    m_pMtrFldMoveX->SetMax(  nPageWidth );
    m_pMtrFldMoveY->SetMin( -nPageHeight );
    m_pMtrFldMoveY->SetMax(  nPageHeight );
    m_pMtrFldWidth->SetMin( -nRectWidth );
    m_pMtrFldWidth->SetMax(  nPageWidth );
    m_pMtrFldHeight->SetMin( -nRectHeight );
    m_pMtrFldHeight->SetMax(  nPageHeight );

    const SfxPoolItem* pPoolItem = nullptr;
    OUString aStr( GetExtraData() );

    if (comphelper::string::getTokenCount(aStr, TOKEN) < 8)
    {
        if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_NUMBER, true, &pPoolItem ) )
            m_pNumFldCopies->SetValue( static_cast<const SfxUInt16Item*>( pPoolItem )->GetValue() );
        else
            m_pNumFldCopies->SetValue( 1 );

        long nMoveX = 500;
        if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_MOVE_X, true, &pPoolItem ) )
            nMoveX = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
        SetMetricValue( *m_pMtrFldMoveX, long(nMoveX / maUIScale), MapUnit::Map100thMM);

        long nMoveY = 500;
        if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_MOVE_Y, true, &pPoolItem ) )
            nMoveY = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
        SetMetricValue( *m_pMtrFldMoveY, long(nMoveY / maUIScale), MapUnit::Map100thMM);

        if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_ANGLE, true, &pPoolItem ) )
            m_pMtrFldAngle->SetValue( static_cast<const SfxInt32Item*>( pPoolItem )->GetValue() );
        else
            m_pMtrFldAngle->SetValue( 0 );

        long nWidth = 0;
        if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_WIDTH, true, &pPoolItem ) )
            nWidth = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
        SetMetricValue( *m_pMtrFldWidth, long(nWidth / maUIScale), MapUnit::Map100thMM);

        long nHeight = 0;
        if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_HEIGHT, true, &pPoolItem ) )
            nHeight = static_cast<const SfxInt32Item*>( pPoolItem )->GetValue();
        SetMetricValue( *m_pMtrFldHeight, long(nHeight / maUIScale), MapUnit::Map100thMM);

        if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, true, &pPoolItem ) )
        {
            Color aColor = static_cast<const XColorItem*>( pPoolItem )->GetColorValue();
            m_pLbStartColor->SelectEntry( aColor );
            m_pLbEndColor->SelectEntry( aColor );
        }
        else
        {
            m_pLbStartColor->SetNoSelection();
            m_pLbEndColor->SetNoSelection();
            m_pLbEndColor->Disable();
            m_pFtEndColor->Disable();
        }
    }
    else
    {
        sal_Int32 nTmp;
        nTmp = static_cast<long>(aStr.getToken( 0, TOKEN ).toInt32());
        m_pNumFldCopies->SetValue( nTmp );

        nTmp = static_cast<long>(aStr.getToken( 1, TOKEN ).toInt32());
        m_pMtrFldMoveX->SetValue( nTmp );

        nTmp = static_cast<long>(aStr.getToken( 2, TOKEN ).toInt32());
        m_pMtrFldMoveY->SetValue( nTmp );

        nTmp = static_cast<long>(aStr.getToken( 3, TOKEN ).toInt32());
        m_pMtrFldAngle->SetValue( nTmp );

        nTmp = static_cast<long>(aStr.getToken( 4, TOKEN ).toInt32());
        m_pMtrFldWidth->SetValue( nTmp );

        nTmp = static_cast<long>(aStr.getToken( 5, TOKEN ).toInt32());
        m_pMtrFldHeight->SetValue( nTmp );

        nTmp = static_cast<long>(aStr.getToken( 6, TOKEN ).toInt32());
        m_pLbStartColor->SelectEntry( Color( nTmp ) );

        nTmp = static_cast<long>(aStr.getToken( 7, TOKEN ).toInt32());
        m_pLbEndColor->SelectEntry( Color( nTmp ) );
    }

}

/**
 * fills provided item set with dialog box attributes
 */
void CopyDlg::GetAttr( SfxItemSet& rOutAttrs )
{
    long nMoveX = long( GetCoreValue( *m_pMtrFldMoveX, MapUnit::Map100thMM) * maUIScale);
    long nMoveY = long( GetCoreValue( *m_pMtrFldMoveY, MapUnit::Map100thMM) * maUIScale);
    long nHeight = long( GetCoreValue( *m_pMtrFldHeight, MapUnit::Map100thMM) * maUIScale);
    long nWidth  = long( GetCoreValue( *m_pMtrFldWidth, MapUnit::Map100thMM) * maUIScale);

    rOutAttrs.Put( SfxUInt16Item( ATTR_COPY_NUMBER, static_cast<sal_uInt16>(m_pNumFldCopies->GetValue()) ) );
    rOutAttrs.Put( SfxInt32Item( ATTR_COPY_MOVE_X, nMoveX ) );
    rOutAttrs.Put( SfxInt32Item( ATTR_COPY_MOVE_Y, nMoveY ) );
    rOutAttrs.Put( SfxInt32Item( ATTR_COPY_ANGLE, static_cast<sal_Int32>(m_pMtrFldAngle->GetValue()) ) );
    rOutAttrs.Put( SfxInt32Item( ATTR_COPY_WIDTH, nWidth ) );
    rOutAttrs.Put( SfxInt32Item( ATTR_COPY_HEIGHT, nHeight ) );

    NamedColor aColor = m_pLbStartColor->GetSelectedEntry();
    rOutAttrs.Put(XColorItem(ATTR_COPY_START_COLOR, aColor.second, aColor.first));
    aColor = m_pLbEndColor->GetSelectedEntry();
    rOutAttrs.Put(XColorItem(ATTR_COPY_END_COLOR, aColor.second, aColor.first));
}

/**
 * enables and selects end color LB
 */
IMPL_LINK_NOARG(CopyDlg, SelectColorHdl, SvxColorListBox&, void)
{
    const Color aColor = m_pLbStartColor->GetSelectEntryColor();

    if (!m_pLbEndColor->IsEnabled())
    {
        m_pLbEndColor->SelectEntry(aColor);
        m_pLbEndColor->Enable();
        m_pFtEndColor->Enable();
    }
}

/**
 * sets values of selection
 */
IMPL_LINK_NOARG(CopyDlg, SetViewData, Button*, void)
{
    ::tools::Rectangle aRect = mpView->GetAllMarkedRect();

    SetMetricValue( *m_pMtrFldMoveX, long( aRect.GetWidth() /
                                    maUIScale ), MapUnit::Map100thMM);
    SetMetricValue( *m_pMtrFldMoveY, long( aRect.GetHeight() /
                                    maUIScale ), MapUnit::Map100thMM);

    // sets color attribute
    const SfxPoolItem*  pPoolItem = nullptr;
    if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, true, &pPoolItem ) )
    {
        Color aColor = static_cast<const XColorItem*>( pPoolItem )->GetColorValue();
        m_pLbStartColor->SelectEntry( aColor );
    }
}

/**
 * resets values to default
 */
IMPL_LINK_NOARG(CopyDlg, SetDefault, Button*, void)
{
    m_pNumFldCopies->SetValue( 1 );

    long nValue = 500;
    SetMetricValue( *m_pMtrFldMoveX, long(nValue / maUIScale), MapUnit::Map100thMM);
    SetMetricValue( *m_pMtrFldMoveY, long(nValue / maUIScale), MapUnit::Map100thMM);

    nValue = 0;
    m_pMtrFldAngle->SetValue( nValue );
    SetMetricValue( *m_pMtrFldWidth, long(nValue / maUIScale), MapUnit::Map100thMM);
    SetMetricValue( *m_pMtrFldHeight, long(nValue / maUIScale), MapUnit::Map100thMM);

    // set color attribute
    const SfxPoolItem*  pPoolItem = nullptr;
    if( SfxItemState::SET == mrOutAttrs.GetItemState( ATTR_COPY_START_COLOR, true, &pPoolItem ) )
    {
        Color aColor = static_cast<const XColorItem*>( pPoolItem )->GetColorValue();
        m_pLbStartColor->SelectEntry( aColor );
        m_pLbEndColor->SelectEntry( aColor );
    }
}

} // end of namespace sd

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