LibreOffice Module cui (master) 1
grfpage.cxx
Go to the documentation of this file.
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 <memory>
21#include <svl/eitem.hxx>
22#include <svl/stritem.hxx>
23#include <dialmgr.hxx>
24#include <svx/dlgutil.hxx>
25#include <editeng/sizeitem.hxx>
26#include <editeng/brushitem.hxx>
27#include <grfpage.hxx>
28#include <svx/grfcrop.hxx>
29#include <rtl/ustring.hxx>
30#include <tools/debug.hxx>
31#include <tools/fract.hxx>
32#include <svx/svxids.hrc>
33#include <strings.hrc>
34#include <vcl/fieldvalues.hxx>
35#include <vcl/outdev.hxx>
36#include <vcl/settings.hxx>
37#include <vcl/svapp.hxx>
38#include <svtools/unitconv.hxx>
43
45
46
47static int lcl_GetValue(const weld::MetricSpinButton& rMetric, FieldUnit eUnit)
48{
49 return rMetric.denormalize(rMetric.get_value(eUnit));
50}
51
52/*--------------------------------------------------------------------
53 description: crop graphic
54 --------------------------------------------------------------------*/
55
57 : SfxTabPage(pPage, pController, "cui/ui/croppage.ui", "CropPage", &rSet)
58 , m_nOldWidth(0)
59 , m_nOldHeight(0)
60 , m_bSetOrigSize(false)
61 , m_aPreferredDPI(0)
62 , m_xCropFrame(m_xBuilder->weld_widget("cropframe"))
63 , m_xZoomConstRB(m_xBuilder->weld_radio_button("keepscale"))
64 , m_xSizeConstRB(m_xBuilder->weld_radio_button("keepsize"))
65 , m_xLeftMF(m_xBuilder->weld_metric_spin_button("left", FieldUnit::CM))
66 , m_xRightMF(m_xBuilder->weld_metric_spin_button("right", FieldUnit::CM))
67 , m_xTopMF(m_xBuilder->weld_metric_spin_button("top", FieldUnit::CM))
68 , m_xBottomMF(m_xBuilder->weld_metric_spin_button("bottom", FieldUnit::CM))
69 , m_xScaleFrame(m_xBuilder->weld_widget("scaleframe"))
70 , m_xWidthZoomMF(m_xBuilder->weld_metric_spin_button("widthzoom", FieldUnit::PERCENT))
71 , m_xHeightZoomMF(m_xBuilder->weld_metric_spin_button("heightzoom", FieldUnit::PERCENT))
72 , m_xSizeFrame(m_xBuilder->weld_widget("sizeframe"))
73 , m_xWidthMF(m_xBuilder->weld_metric_spin_button("width", FieldUnit::CM))
74 , m_xHeightMF(m_xBuilder->weld_metric_spin_button("height", FieldUnit::CM))
75 , m_xOrigSizeGrid(m_xBuilder->weld_widget("origsizegrid"))
76 , m_xOrigSizeFT(m_xBuilder->weld_label("origsizeft"))
77 , m_xOrigSizePB(m_xBuilder->weld_button("origsize"))
78 , m_xExampleWN(new weld::CustomWeld(*m_xBuilder, "preview", m_aExampleWN))
79{
81
82 // set the correct metric
83 const FieldUnit eMetric = GetModuleFieldUnit( rSet );
84
85 SetFieldUnit( *m_xWidthMF, eMetric );
86 SetFieldUnit( *m_xHeightMF, eMetric );
87 SetFieldUnit( *m_xLeftMF, eMetric );
88 SetFieldUnit( *m_xRightMF, eMetric );
89 SetFieldUnit( *m_xTopMF , eMetric );
90 SetFieldUnit( *m_xBottomMF, eMetric );
91
93 m_xWidthMF->connect_value_changed( aLk );
94 m_xHeightMF->connect_value_changed( aLk );
95
96 aLk = LINK(this, SvxGrfCropPage, ZoomHdl);
97 m_xWidthZoomMF->connect_value_changed( aLk );
98 m_xHeightZoomMF->connect_value_changed( aLk );
99
100 aLk = LINK(this, SvxGrfCropPage, CropModifyHdl);
101 m_xLeftMF->connect_value_changed( aLk );
102 m_xRightMF->connect_value_changed( aLk );
103 m_xTopMF->connect_value_changed( aLk );
104 m_xBottomMF->connect_value_changed( aLk );
105
106 m_xOrigSizePB->connect_clicked(LINK(this, SvxGrfCropPage, OrigSizeHdl));
107}
108
110{
111 m_xExampleWN.reset();
112}
113
114std::unique_ptr<SfxTabPage> SvxGrfCropPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet)
115{
116 return std::make_unique<SvxGrfCropPage>(pPage, pController, *rSet);
117}
118
120{
121 const SfxPoolItem* pItem;
122 const SfxItemPool& rPool = *rSet->GetPool();
123
124 if(SfxItemState::SET == rSet->GetItemState( rPool.GetWhich(
125 SID_ATTR_GRAF_KEEP_ZOOM ), true, &pItem ))
126 {
127 if( static_cast<const SfxBoolItem*>(pItem)->GetValue() )
128 m_xZoomConstRB->set_active(true);
129 else
130 m_xSizeConstRB->set_active(true);
131 m_xZoomConstRB->save_state();
132 }
133
134 sal_uInt16 nW = rPool.GetWhich( SID_ATTR_GRAF_CROP );
135 if( SfxItemState::SET == rSet->GetItemState( nW, true, &pItem))
136 {
137 FieldUnit eUnit = MapToFieldUnit( rSet->GetPool()->GetMetric( nW ));
138
139 const SvxGrfCrop* pCrop = static_cast<const SvxGrfCrop*>(pItem);
140
141 m_aExampleWN.SetLeft(pCrop->GetLeft());
143 m_aExampleWN.SetTop(pCrop->GetTop());
145
146 m_xLeftMF->set_value( m_xLeftMF->normalize( pCrop->GetLeft()), eUnit );
147 m_xRightMF->set_value( m_xRightMF->normalize( pCrop->GetRight()), eUnit );
148 m_xTopMF->set_value( m_xTopMF->normalize( pCrop->GetTop()), eUnit );
149 m_xBottomMF->set_value( m_xBottomMF->normalize( pCrop->GetBottom()), eUnit );
150 }
151 else
152 {
153 m_xLeftMF->set_value(0, FieldUnit::NONE);
154 m_xRightMF->set_value(0, FieldUnit::NONE);
155 m_xTopMF->set_value(0, FieldUnit::NONE);
156 m_xBottomMF->set_value(0, FieldUnit::NONE);
157 }
158
159 m_xLeftMF->save_value();
160 m_xRightMF->save_value();
161 m_xTopMF->save_value();
162 m_xBottomMF->save_value();
163
164 nW = rPool.GetWhich( SID_ATTR_PAGE_SIZE );
165 if ( SfxItemState::SET == rSet->GetItemState( nW, false, &pItem ) )
166 {
167 // orientation and size from the PageItem
168 FieldUnit eUnit = MapToFieldUnit( rSet->GetPool()->GetMetric( nW ));
169
170 m_aPageSize = static_cast<const SvxSizeItem*>(pItem)->GetSize();
171
172 auto nMin = m_xWidthMF->normalize( 23 );
173 auto nMax = m_xHeightMF->normalize(m_aPageSize.Height());
174 m_xHeightMF->set_range(nMin, nMax, eUnit);
175 nMax = m_xWidthMF->normalize(m_aPageSize.Width());
176 m_xWidthMF->set_range(nMin, nMax, eUnit);
177 }
178 else
179 {
182 MapMode( MapUnit::MapTwip ),
183 MapMode( rSet->GetPool()->GetMetric( nW ) ) );
184 }
185
186 bool bFound = false;
187 if( const SvxBrushItem* pGraphicItem = rSet->GetItemIfSet( SID_ATTR_GRAF_GRAPHIC, false ) )
188 {
189 OUString referer;
190 SfxStringItem const * it = rSet->GetItem(SID_REFERER);
191 if (it != nullptr) {
192 referer = it->GetValue();
193 }
194 const Graphic* pGrf = pGraphicItem->GetGraphic(referer);
195 if( pGrf )
196 {
197 m_aOrigSize = GetGrfOrigSize( *pGrf );
198 if (pGrf->GetType() == GraphicType::Bitmap && m_aOrigSize.Width() && m_aOrigSize.Height())
199 {
201 }
202
204 {
206 m_aExampleWN.SetGraphic( *pGrf );
208
209 bFound = true;
210 if( !pGraphicItem->GetGraphicLink().isEmpty() )
211 m_aGraphicName = pGraphicItem->GetGraphicLink();
212 }
213 }
214 }
215
216 GraphicHasChanged( bFound );
217 ActivatePage( *rSet );
218}
219
221{
222 const SfxItemPool& rPool = *rSet->GetPool();
223 bool bModified = false;
224 if( m_xWidthMF->get_value_changed_from_saved() ||
225 m_xHeightMF->get_value_changed_from_saved() )
226 {
227 constexpr TypedWhichId<SvxSizeItem> nW = SID_ATTR_GRAF_FRMSIZE;
228 FieldUnit eUnit = MapToFieldUnit( rSet->GetPool()->GetMetric( nW ));
229
230 std::shared_ptr<SvxSizeItem> aSz(std::make_shared<SvxSizeItem>(nW));
231
232 // size could already have been set from another page
233 const SfxItemSet* pExSet = GetDialogExampleSet();
234 const SvxSizeItem* pSizeItem = nullptr;
235 if( pExSet && (pSizeItem = pExSet->GetItemIfSet( nW, false )) )
236 {
237 aSz.reset(pSizeItem->Clone());
238 }
239 else
240 {
241 aSz.reset(GetItemSet().Get(nW).Clone());
242 }
243
244 Size aTmpSz( aSz->GetSize() );
245 if( m_xWidthMF->get_value_changed_from_saved() )
246 aTmpSz.setWidth( lcl_GetValue( *m_xWidthMF, eUnit ) );
247 if( m_xHeightMF->get_value_changed_from_saved() )
248 aTmpSz.setHeight( lcl_GetValue( *m_xHeightMF, eUnit ) );
249 aSz->SetSize( aTmpSz );
250 m_xWidthMF->save_value();
251 m_xHeightMF->save_value();
252
253 bModified |= nullptr != rSet->Put( *aSz );
254
255 if (m_bSetOrigSize)
256 {
257 bModified |= nullptr != rSet->Put( SvxSizeItem( rPool.GetWhich(
258 SID_ATTR_GRAF_FRMSIZE_PERCENT ), Size( 0, 0 )) );
259 }
260 }
261 if( m_xLeftMF->get_value_changed_from_saved() || m_xRightMF->get_value_changed_from_saved() ||
262 m_xTopMF->get_value_changed_from_saved() || m_xBottomMF->get_value_changed_from_saved() )
263 {
264 sal_uInt16 nW = rPool.GetWhich( SID_ATTR_GRAF_CROP );
265 FieldUnit eUnit = MapToFieldUnit( rSet->GetPool()->GetMetric( nW ));
266 std::unique_ptr<SvxGrfCrop> pNew(static_cast<SvxGrfCrop*>(rSet->Get( nW ).Clone()));
267
268 pNew->SetLeft( lcl_GetValue( *m_xLeftMF, eUnit ) );
269 pNew->SetRight( lcl_GetValue( *m_xRightMF, eUnit ) );
270 pNew->SetTop( lcl_GetValue( *m_xTopMF, eUnit ) );
271 pNew->SetBottom( lcl_GetValue( *m_xBottomMF, eUnit ) );
272 bModified |= nullptr != rSet->Put( std::move(pNew) );
273 }
274
275 if( m_xZoomConstRB->get_state_changed_from_saved() )
276 {
277 bModified |= nullptr != rSet->Put( SfxBoolItem( rPool.GetWhich(
278 SID_ATTR_GRAF_KEEP_ZOOM), m_xZoomConstRB->get_active() ) );
279 }
280
281 return bModified;
282}
283
285{
286#ifdef DBG_UTIL
287 SfxItemPool* pPool = GetItemSet().GetPool();
288 DBG_ASSERT( pPool, "Where is the pool?" );
289#endif
290
292 auto aIterator = aProperties.find("PreferredDPI");
293 if (aIterator != aProperties.end())
294 m_aPreferredDPI = aIterator->second.get<sal_Int32>();
295
296 m_bSetOrigSize = false;
297
298 // Size
299 Size aSize;
300 if( const SvxSizeItem* pFrmSizeItem = rSet.GetItemIfSet( SID_ATTR_GRAF_FRMSIZE, false ) )
301 aSize = pFrmSizeItem->GetSize();
302
303 m_nOldWidth = aSize.Width();
304 m_nOldHeight = aSize.Height();
305
306 auto nWidth = m_xWidthMF->normalize(m_nOldWidth);
307 auto nHeight = m_xHeightMF->normalize(m_nOldHeight);
308
309 if (nWidth != m_xWidthMF->get_value(FieldUnit::TWIP))
310 m_xWidthMF->set_value(nWidth, FieldUnit::TWIP);
311 m_xWidthMF->save_value();
312
313 if (nHeight != m_xHeightMF->get_value(FieldUnit::TWIP))
314 m_xHeightMF->set_value(nHeight, FieldUnit::TWIP);
315 m_xHeightMF->save_value();
316
317 if( const SvxBrushItem* pBrushItem = rSet.GetItemIfSet( SID_ATTR_GRAF_GRAPHIC, false ) )
318 {
319 if( !pBrushItem->GetGraphicLink().isEmpty() &&
320 m_aGraphicName != pBrushItem->GetGraphicLink() )
321 m_aGraphicName = pBrushItem->GetGraphicLink();
322
323 OUString referer;
324 SfxStringItem const * it = rSet.GetItem(SID_REFERER);
325 if (it != nullptr) {
326 referer = it->GetValue();
327 }
328 const Graphic* pGrf = pBrushItem->GetGraphic(referer);
329 if( pGrf )
330 {
331 m_aExampleWN.SetGraphic( *pGrf );
332 m_aOrigSize = GetGrfOrigSize( *pGrf );
333 if (pGrf->GetType() == GraphicType::Bitmap && m_aOrigSize.Width() > 1 && m_aOrigSize.Height() > 1) {
335 }
339 }
340 else
341 GraphicHasChanged( false );
342 }
343
344 CalcZoom();
345}
346
348{
349 if ( _pSet )
350 FillItemSet( _pSet );
351 return DeactivateRC::LeavePage;
352}
353
354/*--------------------------------------------------------------------
355 description: scale changed, adjust size
356 --------------------------------------------------------------------*/
357
359{
360 SfxItemPool* pPool = GetItemSet().GetPool();
361 DBG_ASSERT( pPool, "Where is the pool?" );
362 FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
363 SID_ATTR_GRAF_CROP ) ) );
364
365 if (&rField == m_xWidthZoomMF.get())
366 {
367 tools::Long nLRBorders = lcl_GetValue(*m_xLeftMF, eUnit)
368 +lcl_GetValue(*m_xRightMF, eUnit);
369 m_xWidthMF->set_value( m_xWidthMF->normalize(
370 ((m_aOrigSize.Width() - nLRBorders) * rField.get_value(FieldUnit::NONE))/100),
371 eUnit);
372 }
373 else
374 {
375 tools::Long nULBorders = lcl_GetValue(*m_xTopMF, eUnit)
376 +lcl_GetValue(*m_xBottomMF, eUnit);
377 m_xHeightMF->set_value( m_xHeightMF->normalize(
378 ((m_aOrigSize.Height() - nULBorders ) * rField.get_value(FieldUnit::NONE))/100) ,
379 eUnit );
380 }
381}
382
383/*--------------------------------------------------------------------
384 description: change size, adjust scale
385 --------------------------------------------------------------------*/
386
388{
389 SfxItemPool* pPool = GetItemSet().GetPool();
390 DBG_ASSERT( pPool, "Where is the pool?" );
391 FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
392 SID_ATTR_GRAF_CROP ) ) );
393
394 Size aSize( lcl_GetValue(*m_xWidthMF, eUnit),
395 lcl_GetValue(*m_xHeightMF, eUnit) );
396
397 if(&rField == m_xWidthMF.get())
398 {
399 tools::Long nWidth = m_aOrigSize.Width() -
400 ( lcl_GetValue(*m_xLeftMF, eUnit) +
401 lcl_GetValue(*m_xRightMF, eUnit) );
402 if(!nWidth)
403 nWidth++;
404 sal_uInt16 nZoom = static_cast<sal_uInt16>( aSize.Width() * 100 / nWidth);
405 m_xWidthZoomMF->set_value(nZoom, FieldUnit::NONE);
406 }
407 else
408 {
409 tools::Long nHeight = m_aOrigSize.Height() -
410 ( lcl_GetValue(*m_xTopMF, eUnit) +
411 lcl_GetValue(*m_xBottomMF, eUnit));
412 if(!nHeight)
413 nHeight++;
414 sal_uInt16 nZoom = static_cast<sal_uInt16>( aSize.Height() * 100 / nHeight);
415 m_xHeightZoomMF->set_value(nZoom, FieldUnit::NONE);
416 }
417}
418
419/*--------------------------------------------------------------------
420 description: evaluate border
421 --------------------------------------------------------------------*/
422
423IMPL_LINK( SvxGrfCropPage, CropModifyHdl, weld::MetricSpinButton&, rField, void )
424{
425 SfxItemPool* pPool = GetItemSet().GetPool();
426 DBG_ASSERT( pPool, "Where is the pool?" );
427 FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
428 SID_ATTR_GRAF_CROP ) ) );
429
430 bool bZoom = m_xZoomConstRB->get_active();
431 if (&rField == m_xLeftMF.get() || &rField == m_xRightMF.get())
432 {
433 tools::Long nLeft = lcl_GetValue( *m_xLeftMF, eUnit );
434 tools::Long nRight = lcl_GetValue( *m_xRightMF, eUnit );
435 tools::Long nWidthZoom = static_cast<tools::Long>(m_xWidthZoomMF->get_value(FieldUnit::NONE));
436 if (bZoom && nWidthZoom != 0 && ( ( ( m_aOrigSize.Width() - (nLeft + nRight )) * nWidthZoom )
437 / 100 >= m_aPageSize.Width() ) )
438 {
439 if (&rField == m_xLeftMF.get())
440 {
441 nLeft = m_aOrigSize.Width() -
442 ( m_aPageSize.Width() * 100 / nWidthZoom + nRight );
443 m_xLeftMF->set_value( m_xLeftMF->normalize( nLeft ), eUnit );
444 }
445 else
446 {
447 nRight = m_aOrigSize.Width() -
448 ( m_aPageSize.Width() * 100 / nWidthZoom + nLeft );
449 m_xRightMF->set_value( m_xRightMF->normalize( nRight ), eUnit );
450 }
451 }
453 {
454 m_aExampleWN.SetLeft(nRight);
455 m_aExampleWN.SetRight(nLeft);
456 }
457 else
458 {
459 m_aExampleWN.SetLeft(nLeft);
460 m_aExampleWN.SetRight(nRight);
461 }
462 if(bZoom)
463 {
464 // scale stays, recompute width
465 ZoomHdl(*m_xWidthZoomMF);
466 }
467 }
468 else
469 {
470 tools::Long nTop = lcl_GetValue( *m_xTopMF, eUnit );
471 tools::Long nBottom = lcl_GetValue( *m_xBottomMF, eUnit );
472 tools::Long nHeightZoom = static_cast<tools::Long>(m_xHeightZoomMF->get_value(FieldUnit::NONE));
473 if(bZoom && ( ( ( m_aOrigSize.Height() - (nTop + nBottom )) * nHeightZoom)
474 / 100 >= m_aPageSize.Height()))
475 {
476 assert(nHeightZoom && "div-by-zero");
477 if(&rField == m_xTopMF.get())
478 {
479 nTop = m_aOrigSize.Height() -
480 ( m_aPageSize.Height() * 100 / nHeightZoom + nBottom);
481 m_xTopMF->set_value( m_xWidthMF->normalize( nTop ), eUnit );
482 }
483 else
484 {
485 nBottom = m_aOrigSize.Height() -
486 ( m_aPageSize.Height() * 100 / nHeightZoom + nTop);
487 m_xBottomMF->set_value( m_xWidthMF->normalize( nBottom ), eUnit );
488 }
489 }
490 m_aExampleWN.SetTop( nTop );
491 m_aExampleWN.SetBottom( nBottom );
492 if(bZoom)
493 {
494 // scale stays, recompute height
495 ZoomHdl(*m_xHeightZoomMF);
496 }
497 }
498 m_aExampleWN.Invalidate();
499 // size and border changed -> recompute scale
500 if(!bZoom)
501 CalcZoom();
502 CalcMinMaxBorder();
503}
504/*--------------------------------------------------------------------
505 description: set original size
506 --------------------------------------------------------------------*/
507
509{
510 SfxItemPool* pPool = GetItemSet().GetPool();
511 DBG_ASSERT( pPool, "Where is the pool?" );
512 FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
513 SID_ATTR_GRAF_CROP ) ) );
514
515 tools::Long nWidth = m_aOrigSize.Width() -
516 lcl_GetValue( *m_xLeftMF, eUnit ) -
517 lcl_GetValue( *m_xRightMF, eUnit );
518 m_xWidthMF->set_value( m_xWidthMF->normalize( nWidth ), eUnit );
519 tools::Long nHeight = m_aOrigSize.Height() -
520 lcl_GetValue( *m_xTopMF, eUnit ) -
521 lcl_GetValue( *m_xBottomMF, eUnit );
522 m_xHeightMF->set_value( m_xHeightMF->normalize( nHeight ), eUnit );
523 m_xWidthZoomMF->set_value(100, FieldUnit::NONE);
524 m_xHeightZoomMF->set_value(100, FieldUnit::NONE);
525 m_bSetOrigSize = true;
526}
527/*--------------------------------------------------------------------
528 description: compute scale
529 --------------------------------------------------------------------*/
530
532{
533 SfxItemPool* pPool = GetItemSet().GetPool();
534 DBG_ASSERT( pPool, "Where is the pool?" );
535 FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
536 SID_ATTR_GRAF_CROP ) ) );
537
538 tools::Long nWidth = lcl_GetValue( *m_xWidthMF, eUnit );
539 tools::Long nHeight = lcl_GetValue( *m_xHeightMF, eUnit );
540 tools::Long nLRBorders = lcl_GetValue( *m_xLeftMF, eUnit ) +
541 lcl_GetValue( *m_xRightMF, eUnit );
542 tools::Long nULBorders = lcl_GetValue( *m_xTopMF, eUnit ) +
543 lcl_GetValue( *m_xBottomMF, eUnit );
544 sal_uInt16 nZoom = 0;
545 tools::Long nDen;
546 if( (nDen = m_aOrigSize.Width() - nLRBorders) > 0)
547 nZoom = static_cast<sal_uInt16>((( nWidth * 1000 / nDen )+5)/10);
548 m_xWidthZoomMF->set_value(nZoom, FieldUnit::NONE);
549 if( (nDen = m_aOrigSize.Height() - nULBorders) > 0)
550 nZoom = static_cast<sal_uInt16>((( nHeight * 1000 / nDen )+5)/10);
551 else
552 nZoom = 0;
553 m_xHeightZoomMF->set_value(nZoom, FieldUnit::NONE);
554}
555
556/*--------------------------------------------------------------------
557 description: set minimum/maximum values for the margins
558 --------------------------------------------------------------------*/
559
561{
562 SfxItemPool* pPool = GetItemSet().GetPool();
563 DBG_ASSERT( pPool, "Where is the pool?" );
564 FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
565 SID_ATTR_GRAF_CROP ) ) );
566 tools::Long nR = lcl_GetValue(*m_xRightMF, eUnit );
567 tools::Long nMinWidth = (m_aOrigSize.Width() * 10) /11;
568 tools::Long nMin = nMinWidth - (nR >= 0 ? nR : 0);
569 m_xLeftMF->set_max( m_xLeftMF->normalize(nMin), eUnit );
570
571 tools::Long nL = lcl_GetValue(*m_xLeftMF, eUnit );
572 nMin = nMinWidth - (nL >= 0 ? nL : 0);
573 m_xRightMF->set_max( m_xRightMF->normalize(nMin), eUnit );
574
575 tools::Long nUp = lcl_GetValue( *m_xTopMF, eUnit );
576 tools::Long nMinHeight = (m_aOrigSize.Height() * 10) /11;
577 nMin = nMinHeight - (nUp >= 0 ? nUp : 0);
578 m_xBottomMF->set_max( m_xBottomMF->normalize(nMin), eUnit );
579
580 tools::Long nLow = lcl_GetValue(*m_xBottomMF, eUnit );
581 nMin = nMinHeight - (nLow >= 0 ? nLow : 0);
582 m_xTopMF->set_max( m_xTopMF->normalize(nMin), eUnit );
583}
584/*--------------------------------------------------------------------
585 description: set spinsize to 1/20 of the original size,
586 fill FixedText with the original size
587 --------------------------------------------------------------------*/
588
590{
591 if( bFound )
592 {
593 SfxItemPool* pPool = GetItemSet().GetPool();
594 DBG_ASSERT( pPool, "Where is the pool?" );
595 FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
596 SID_ATTR_GRAF_CROP ) ));
597
598 sal_Int64 nSpin = m_xLeftMF->normalize(m_aOrigSize.Width()) / 20;
599 nSpin = vcl::ConvertValue( nSpin, m_aOrigSize.Width(), 0,
600 eUnit, m_xLeftMF->get_unit());
601
602 // if the margin is too big, it is set to 1/3 on both pages
603 tools::Long nR = lcl_GetValue( *m_xRightMF, eUnit );
604 tools::Long nL = lcl_GetValue( *m_xLeftMF, eUnit );
605 if((nL + nR) < - m_aOrigSize.Width())
606 {
607 tools::Long nVal = m_aOrigSize.Width() / -3;
608 m_xRightMF->set_value( m_xRightMF->normalize( nVal ), eUnit );
609 m_xLeftMF->set_value( m_xLeftMF->normalize( nVal ), eUnit );
610 m_aExampleWN.SetLeft(nVal);
612 }
613 tools::Long nUp = lcl_GetValue(*m_xTopMF, eUnit );
614 tools::Long nLow = lcl_GetValue(*m_xBottomMF, eUnit );
615 if((nUp + nLow) < - m_aOrigSize.Height())
616 {
617 tools::Long nVal = m_aOrigSize.Height() / -3;
618 m_xTopMF->set_value( m_xTopMF->normalize( nVal ), eUnit );
619 m_xBottomMF->set_value( m_xBottomMF->normalize( nVal ), eUnit );
620 m_aExampleWN.SetTop(nVal);
622 }
623
624 m_xLeftMF->set_increments(nSpin, nSpin * 10, FieldUnit::NONE);
625 m_xRightMF->set_increments(nSpin, nSpin * 10, FieldUnit::NONE);
626 nSpin = m_xTopMF->normalize(m_aOrigSize.Height()) / 20;
627 nSpin = vcl::ConvertValue( nSpin, m_aOrigSize.Width(), 0,
628 eUnit, m_xLeftMF->get_unit() );
629 m_xTopMF->set_increments(nSpin, nSpin * 10, FieldUnit::NONE);
630 m_xBottomMF->set_increments(nSpin, nSpin * 10, FieldUnit::NONE);
631
632 // display original size
633 const FieldUnit eMetric = GetModuleFieldUnit( GetItemSet() );
634
635 OUString sTemp;
636 {
637 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/spinbox.ui"));
638 std::unique_ptr<weld::Dialog> xTopLevel(xBuilder->weld_dialog("SpinDialog"));
639 std::unique_ptr<weld::MetricSpinButton> xFld(xBuilder->weld_metric_spin_button("spin", FieldUnit::CM));
640 SetFieldUnit( *xFld, eMetric );
641 xFld->set_digits(m_xWidthMF->get_digits());
642 xFld->set_max(INT_MAX - 1, FieldUnit::NONE);
643
644 xFld->set_value(xFld->normalize(m_aOrigSize.Width()), eUnit);
645 sTemp = xFld->get_text();
646 xFld->set_value(xFld->normalize(m_aOrigSize.Height()), eUnit);
647 // multiplication sign (U+00D7)
648 sTemp += u"\u00D7" + xFld->get_text();
649 }
650
652 sal_Int32 ax = 0.5 + m_aOrigPixelSize.Width() /
653 o3tl::convert<double>(m_aOrigSize.Width(), o3tl::Length::twip,
655 sal_Int32 ay = 0.5 + m_aOrigPixelSize.Height() /
656 o3tl::convert<double>(m_aOrigSize.Height(), o3tl::Length::twip,
658 OUString sPPI = OUString::number(ax);
659 if (abs(ax - ay) > 1) {
660 sPPI += u"\u00D7" + OUString::number(ay);
661 }
662 sTemp += " " + CuiResId(RID_CUISTR_PPI).replaceAll("%1", sPPI);
663 }
664 sTemp += "\n" + OUString::number(m_aOrigPixelSize.Width()) + u"\u00D7" + OUString::number(m_aOrigPixelSize.Height()) + " px";
665 m_xOrigSizeFT->set_label(sTemp);
666 }
667
668 m_xCropFrame->set_sensitive(bFound);
669 m_xScaleFrame->set_sensitive(bFound);
670 m_xSizeFrame->set_sensitive(bFound);
671 m_xOrigSizeGrid->set_sensitive(bFound);
672 m_xZoomConstRB->set_sensitive(bFound);
673}
674
676{
677 Size aSize;
678
679 if (m_aPreferredDPI > 0)
680 {
681 Size aPixelSize = rGrf.GetSizePixel();
682 double fWidth = aPixelSize.Width() / double(m_aPreferredDPI);
683 double fHeight = aPixelSize.Height() / double(m_aPreferredDPI);
686 aSize = Size(fWidth, fHeight);
687 }
688 else
689 {
690 const MapMode aMapTwip( MapUnit::MapTwip );
691 aSize = rGrf.GetPrefSize();
692 if( MapUnit::MapPixel == rGrf.GetPrefMapMode().GetMapUnit() )
693 aSize = Application::GetDefaultDevice()->PixelToLogic(aSize, aMapTwip);
694 else
695 aSize = OutputDevice::LogicToLogic( aSize,
696 rGrf.GetPrefMapMode(), aMapTwip );
697 }
698 return aSize;
699}
700
701/*****************************************************************/
702
704 : m_aTopLeft(0, 0)
705 , m_aBottomRight(0, 0)
706{
707}
708
710{
711 CustomWidgetController::SetDrawingArea(pDrawingArea);
712 OutputDevice& rDevice = pDrawingArea->get_ref_device();
713 Size aSize(rDevice.LogicToPixel(Size(78, 78), MapMode(MapUnit::MapAppFont)));
714 pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
715
716 m_aMapMode = rDevice.GetMapMode();
719 MapMode(MapUnit::MapTwip), m_aMapMode);
720}
721
722void SvxCropExample::Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle&)
723{
724 rRenderContext.Push(vcl::PushFlags::MAPMODE);
725 rRenderContext.SetMapMode(m_aMapMode);
726
727 // Win BG
728 const Size aWinSize(rRenderContext.PixelToLogic(GetOutputSizePixel()));
729 rRenderContext.SetLineColor();
730 rRenderContext.SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetWindowColor());
731 rRenderContext.DrawRect(::tools::Rectangle(Point(), aWinSize));
732
733 // use AA, the Graphic may be a metafile/svg and would then look ugly
734 rRenderContext.SetAntialiasing(AntialiasingFlags::Enable);
735
736 // draw Graphic
737 ::tools::Rectangle aRect(
738 Point((aWinSize.Width() - m_aFrameSize.Width())/2, (aWinSize.Height() - m_aFrameSize.Height())/2),
740 m_aGrf.Draw(rRenderContext, aRect.TopLeft(), aRect.GetSize());
741
742 // Remove one more case that uses XOR paint (RasterOp::Invert).
743 // Get colors and logic DashLength from settings, use equal to
744 // PolygonMarkerPrimitive2D, may be changed to that primitive later.
745 // Use this to guarantee good visibility - that was the purpose of
746 // the former used XOR paint.
747 const Color aColA(SvtOptionsDrawinglayer::GetStripeColorA().getBColor());
748 const Color aColB(SvtOptionsDrawinglayer::GetStripeColorB().getBColor());
749 const double fStripeLength(SvtOptionsDrawinglayer::GetStripeLength());
750 const basegfx::B2DVector aDashVector(rRenderContext.GetInverseViewTransformation() * basegfx::B2DVector(fStripeLength, 0.0));
751 const double fLogicDashLength(aDashVector.getX());
752
753 // apply current crop settings
754 aRect.AdjustLeft(m_aTopLeft.Y());
755 aRect.AdjustTop(m_aTopLeft.X());
756 aRect.AdjustRight(-m_aBottomRight.Y());
757 aRect.AdjustBottom(-m_aBottomRight.X());
758
759 // apply dash with direct paint callbacks
762 basegfx::B2DRange(aRect.Left(), aRect.Top(), aRect.Right(), aRect.Bottom())),
763 std::vector< double >(2, fLogicDashLength),
764 [&aColA,&rRenderContext](const basegfx::B2DPolygon& rSnippet)
765 {
766 rRenderContext.SetLineColor(aColA);
767 rRenderContext.DrawPolyLine(rSnippet);
768 },
769 [&aColB,&rRenderContext](const basegfx::B2DPolygon& rSnippet)
770 {
771 rRenderContext.SetLineColor(aColB);
772 rRenderContext.DrawPolyLine(rSnippet);
773 },
774 2.0 * fLogicDashLength);
775
776 rRenderContext.Pop();
777}
778
780{
782}
783
785{
786 m_aFrameSize = rSz;
787 if (!m_aFrameSize.Width())
789 if (!m_aFrameSize.Height())
791 Size aWinSize( GetOutputSizePixel() );
792 Fraction aXScale( aWinSize.Width() * 4, m_aFrameSize.Width() * 5 );
793 Fraction aYScale( aWinSize.Height() * 4, m_aFrameSize.Height() * 5 );
794
795 if( aYScale < aXScale )
796 aXScale = aYScale;
797
798 m_aMapMode.SetScaleX(aXScale);
799 m_aMapMode.SetScaleY(aXScale);
800
801 Invalidate();
802}
803
804/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertiesInfo aProperties
const StyleSettings & GetStyleSettings() const
static bool GetLayoutRTL()
static OutputDevice * GetDefaultDevice()
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
const OUString & GetValue() const
Size GetPrefSize() const
GraphicType GetType() const
MapMode GetPrefMapMode() const
Size GetSizePixel(const OutputDevice *pRefDevice=nullptr) const
void Draw(OutputDevice &rOutDev, const Point &rDestPt) const
void SetScaleY(const Fraction &rScaleY)
MapUnit GetMapUnit() const
void SetScaleX(const Fraction &rScaleX)
void SetAntialiasing(AntialiasingFlags nMode)
basegfx::B2DHomMatrix GetInverseViewTransformation() const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
void DrawRect(const tools::Rectangle &rRect)
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
void SetLineColor()
void SetMapMode()
void SetFillColor()
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
const MapMode & GetMapMode() const
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
const AllSettings & GetSettings() const
constexpr tools::Long Y() const
constexpr tools::Long X() const
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
SfxItemPool * GetPool() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const=0
const SfxItemSet & GetItemSet() const
void SetExchangeSupport()
const SfxItemSet * GetDialogExampleSet() const
std::unordered_map< OUString, css::uno::Any > & getAdditionalProperties()
weld::Window * GetFrameWeld() const
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
const Color & GetWindowColor() const
Size m_aFrameSize
Definition: grfpage.hxx:29
void SetBottom(tools::Long nVal)
Definition: grfpage.hxx:41
Point m_aBottomRight
Definition: grfpage.hxx:30
void SetLeft(tools::Long nVal)
Definition: grfpage.hxx:42
void SetTop(tools::Long nVal)
Definition: grfpage.hxx:40
void SetFrameSize(const Size &rSz)
Definition: grfpage.cxx:784
virtual void Resize() override
Definition: grfpage.cxx:779
virtual void Paint(vcl::RenderContext &rRenderContext, const ::tools::Rectangle &rRect) override
Definition: grfpage.cxx:722
Point m_aTopLeft
Definition: grfpage.hxx:30
void SetGraphic(const Graphic &rGrf)
Definition: grfpage.hxx:45
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: grfpage.cxx:709
void SetRight(tools::Long nVal)
Definition: grfpage.hxx:43
Graphic m_aGrf
Definition: grfpage.hxx:31
MapMode m_aMapMode
Definition: grfpage.hxx:28
std::unique_ptr< weld::Widget > m_xCropFrame
Definition: grfpage.hxx:63
std::unique_ptr< weld::MetricSpinButton > m_xWidthMF
Definition: grfpage.hxx:76
tools::Long m_nOldHeight
Definition: grfpage.hxx:57
Size m_aPageSize
Definition: grfpage.hxx:55
std::unique_ptr< weld::Widget > m_xSizeFrame
Definition: grfpage.hxx:75
std::unique_ptr< weld::MetricSpinButton > m_xRightMF
Definition: grfpage.hxx:67
void CalcMinMaxBorder()
Definition: grfpage.cxx:560
std::unique_ptr< weld::RadioButton > m_xSizeConstRB
Definition: grfpage.hxx:65
virtual void Reset(const SfxItemSet *rSet) override
Definition: grfpage.cxx:119
std::unique_ptr< weld::MetricSpinButton > m_xWidthZoomMF
Definition: grfpage.hxx:72
std::unique_ptr< weld::CustomWeld > m_xExampleWN
Definition: grfpage.hxx:84
std::unique_ptr< weld::RadioButton > m_xZoomConstRB
Definition: grfpage.hxx:64
std::unique_ptr< weld::Widget > m_xScaleFrame
Definition: grfpage.hxx:71
Size m_aOrigSize
Definition: grfpage.hxx:53
std::unique_ptr< weld::Widget > m_xOrigSizeGrid
Definition: grfpage.hxx:79
sal_Int32 m_aPreferredDPI
Definition: grfpage.hxx:59
bool m_bSetOrigSize
Definition: grfpage.hxx:58
std::unique_ptr< weld::MetricSpinButton > m_xTopMF
Definition: grfpage.hxx:68
std::unique_ptr< weld::Label > m_xOrigSizeFT
Definition: grfpage.hxx:80
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: grfpage.cxx:220
std::unique_ptr< weld::MetricSpinButton > m_xHeightMF
Definition: grfpage.hxx:77
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: grfpage.cxx:347
OUString m_aGraphicName
Definition: grfpage.hxx:52
std::unique_ptr< weld::MetricSpinButton > m_xHeightZoomMF
Definition: grfpage.hxx:73
std::unique_ptr< weld::MetricSpinButton > m_xLeftMF
Definition: grfpage.hxx:66
void CalcZoom()
Definition: grfpage.cxx:531
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: grfpage.cxx:114
Size m_aOrigPixelSize
Definition: grfpage.hxx:54
std::unique_ptr< weld::Button > m_xOrigSizePB
Definition: grfpage.hxx:81
SvxCropExample m_aExampleWN
Definition: grfpage.hxx:61
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: grfpage.cxx:284
std::unique_ptr< weld::MetricSpinButton > m_xBottomMF
Definition: grfpage.hxx:69
void GraphicHasChanged(bool bFound)
Definition: grfpage.cxx:589
virtual ~SvxGrfCropPage() override
Definition: grfpage.cxx:109
Size GetGrfOrigSize(const Graphic &rGraphic)
Definition: grfpage.cxx:675
tools::Long m_nOldWidth
Definition: grfpage.hxx:56
SvxGrfCropPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: grfpage.cxx:56
sal_Int32 GetTop() const
sal_Int32 GetRight() const
sal_Int32 GetLeft() const
sal_Int32 GetBottom() const
virtual SvxSizeItem * Clone(SfxItemPool *pPool=nullptr) const override
TYPE getX() const
constexpr tools::Long Top() const
constexpr Point TopLeft() const
constexpr Size GetSize() const
constexpr tools::Long Right() const
tools::Long AdjustTop(tools::Long nVertMoveDelta)
tools::Long AdjustRight(tools::Long nHorzMoveDelta)
tools::Long AdjustBottom(tools::Long nVertMoveDelta)
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
Size const & GetOutputSizePixel() const
virtual OutputDevice & get_ref_device()=0
sal_Int64 denormalize(sal_Int64 nValue) const
sal_Int64 get_value(FieldUnit eDestUnit) const
virtual void set_size_request(int nWidth, int nHeight)=0
OUString CuiResId(TranslateId aKey)
Definition: cuiresmgr.cxx:23
#define DBG_ASSERT(sCon, aError)
virtual tools::Long GetValue() const override
SVXCORE_DLLPUBLIC FieldUnit GetModuleFieldUnit(const SfxItemSet &)
float u
FieldUnit
IMPL_LINK(SvxGrfCropPage, ZoomHdl, weld::MetricSpinButton &, rField, void)
Definition: grfpage.cxx:358
static int lcl_GetValue(const weld::MetricSpinButton &rMetric, FieldUnit eUnit)
Definition: grfpage.cxx:47
IMPL_LINK_NOARG(SvxGrfCropPage, OrigSizeHdl, weld::Button &, void)
Definition: grfpage.cxx:508
constexpr auto CM_1_TO_TWIP
Definition: grfpage.cxx:44
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
SVXCORE_DLLPUBLIC MSO_SPT Get(const OUString &)
sal_uInt16 GetStripeLength()
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
void applyLineDashing(const B2DPolygon &rCandidate, const std::vector< double > &rDotDashArray, B2DPolyPolygon *pLineTarget, B2DPolyPolygon *pGapTarget, double fDotDashLength)
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
css::uno::Reference< css::animations::XAnimationNode > Clone(const css::uno::Reference< css::animations::XAnimationNode > &xSourceNode, const SdPage *pSource=nullptr, const SdPage *pTarget=nullptr)
long Long
sal_Int64 ConvertValue(sal_Int64 nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits, FieldUnit eInUnit, FieldUnit eOutUnit)
SwNodeOffset abs(const SwNodeOffset &a)
static SfxItemSet & rSet
DeactivateRC
SVT_DLLPUBLIC void SetFieldUnit(weld::MetricSpinButton &rCtrl, FieldUnit eUnit, bool bAll=false)
SVT_DLLPUBLIC FieldUnit MapToFieldUnit(const MapUnit eUnit)
constexpr OUStringLiteral PERCENT(u"Percent")