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 = static_cast<SfxStringItem const *>(
191 rSet->GetItem(SID_REFERER));
192 if (it != nullptr) {
193 referer = it->GetValue();
194 }
195 const Graphic* pGrf = pGraphicItem->GetGraphic(referer);
196 if( pGrf )
197 {
198 m_aOrigSize = GetGrfOrigSize( *pGrf );
199 if (pGrf->GetType() == GraphicType::Bitmap && m_aOrigSize.Width() && m_aOrigSize.Height())
200 {
202 }
203
205 {
207 m_aExampleWN.SetGraphic( *pGrf );
209
210 bFound = true;
211 if( !pGraphicItem->GetGraphicLink().isEmpty() )
212 m_aGraphicName = pGraphicItem->GetGraphicLink();
213 }
214 }
215 }
216
217 GraphicHasChanged( bFound );
218 ActivatePage( *rSet );
219}
220
222{
223 const SfxItemPool& rPool = *rSet->GetPool();
224 bool bModified = false;
225 if( m_xWidthMF->get_value_changed_from_saved() ||
226 m_xHeightMF->get_value_changed_from_saved() )
227 {
228 constexpr TypedWhichId<SvxSizeItem> nW = SID_ATTR_GRAF_FRMSIZE;
229 FieldUnit eUnit = MapToFieldUnit( rSet->GetPool()->GetMetric( nW ));
230
231 std::shared_ptr<SvxSizeItem> aSz(std::make_shared<SvxSizeItem>(nW));
232
233 // size could already have been set from another page
234 const SfxItemSet* pExSet = GetDialogExampleSet();
235 const SvxSizeItem* pSizeItem = nullptr;
236 if( pExSet && (pSizeItem = pExSet->GetItemIfSet( nW, false )) )
237 {
238 aSz.reset(pSizeItem->Clone());
239 }
240 else
241 {
242 aSz.reset(GetItemSet().Get(nW).Clone());
243 }
244
245 Size aTmpSz( aSz->GetSize() );
246 if( m_xWidthMF->get_value_changed_from_saved() )
247 aTmpSz.setWidth( lcl_GetValue( *m_xWidthMF, eUnit ) );
248 if( m_xHeightMF->get_value_changed_from_saved() )
249 aTmpSz.setHeight( lcl_GetValue( *m_xHeightMF, eUnit ) );
250 aSz->SetSize( aTmpSz );
251 m_xWidthMF->save_value();
252 m_xHeightMF->save_value();
253
254 bModified |= nullptr != rSet->Put( *aSz );
255
256 if (m_bSetOrigSize)
257 {
258 bModified |= nullptr != rSet->Put( SvxSizeItem( rPool.GetWhich(
259 SID_ATTR_GRAF_FRMSIZE_PERCENT ), Size( 0, 0 )) );
260 }
261 }
262 if( m_xLeftMF->get_value_changed_from_saved() || m_xRightMF->get_value_changed_from_saved() ||
263 m_xTopMF->get_value_changed_from_saved() || m_xBottomMF->get_value_changed_from_saved() )
264 {
265 sal_uInt16 nW = rPool.GetWhich( SID_ATTR_GRAF_CROP );
266 FieldUnit eUnit = MapToFieldUnit( rSet->GetPool()->GetMetric( nW ));
267 std::unique_ptr<SvxGrfCrop> pNew(static_cast<SvxGrfCrop*>(rSet->Get( nW ).Clone()));
268
269 pNew->SetLeft( lcl_GetValue( *m_xLeftMF, eUnit ) );
270 pNew->SetRight( lcl_GetValue( *m_xRightMF, eUnit ) );
271 pNew->SetTop( lcl_GetValue( *m_xTopMF, eUnit ) );
272 pNew->SetBottom( lcl_GetValue( *m_xBottomMF, eUnit ) );
273 bModified |= nullptr != rSet->Put( std::move(pNew) );
274 }
275
276 if( m_xZoomConstRB->get_state_changed_from_saved() )
277 {
278 bModified |= nullptr != rSet->Put( SfxBoolItem( rPool.GetWhich(
279 SID_ATTR_GRAF_KEEP_ZOOM), m_xZoomConstRB->get_active() ) );
280 }
281
282 return bModified;
283}
284
286{
287#ifdef DBG_UTIL
288 SfxItemPool* pPool = GetItemSet().GetPool();
289 DBG_ASSERT( pPool, "Where is the pool?" );
290#endif
291
293 auto aIterator = aProperties.find("PreferredDPI");
294 if (aIterator != aProperties.end())
295 m_aPreferredDPI = aIterator->second.get<sal_Int32>();
296
297 m_bSetOrigSize = false;
298
299 // Size
300 Size aSize;
301 if( const SvxSizeItem* pFrmSizeItem = rSet.GetItemIfSet( SID_ATTR_GRAF_FRMSIZE, false ) )
302 aSize = pFrmSizeItem->GetSize();
303
304 m_nOldWidth = aSize.Width();
305 m_nOldHeight = aSize.Height();
306
307 auto nWidth = m_xWidthMF->normalize(m_nOldWidth);
308 auto nHeight = m_xHeightMF->normalize(m_nOldHeight);
309
310 if (nWidth != m_xWidthMF->get_value(FieldUnit::TWIP))
311 m_xWidthMF->set_value(nWidth, FieldUnit::TWIP);
312 m_xWidthMF->save_value();
313
314 if (nHeight != m_xHeightMF->get_value(FieldUnit::TWIP))
315 m_xHeightMF->set_value(nHeight, FieldUnit::TWIP);
316 m_xHeightMF->save_value();
317
318 if( const SvxBrushItem* pBrushItem = rSet.GetItemIfSet( SID_ATTR_GRAF_GRAPHIC, false ) )
319 {
320 if( !pBrushItem->GetGraphicLink().isEmpty() &&
321 m_aGraphicName != pBrushItem->GetGraphicLink() )
322 m_aGraphicName = pBrushItem->GetGraphicLink();
323
324 OUString referer;
325 SfxStringItem const * it = static_cast<SfxStringItem const *>(
326 rSet.GetItem(SID_REFERER));
327 if (it != nullptr) {
328 referer = it->GetValue();
329 }
330 const Graphic* pGrf = pBrushItem->GetGraphic(referer);
331 if( pGrf )
332 {
333 m_aExampleWN.SetGraphic( *pGrf );
334 m_aOrigSize = GetGrfOrigSize( *pGrf );
335 if (pGrf->GetType() == GraphicType::Bitmap && m_aOrigSize.Width() > 1 && m_aOrigSize.Height() > 1) {
337 }
341 }
342 else
343 GraphicHasChanged( false );
344 }
345
346 CalcZoom();
347}
348
350{
351 if ( _pSet )
352 FillItemSet( _pSet );
353 return DeactivateRC::LeavePage;
354}
355
356/*--------------------------------------------------------------------
357 description: scale changed, adjust size
358 --------------------------------------------------------------------*/
359
361{
362 SfxItemPool* pPool = GetItemSet().GetPool();
363 DBG_ASSERT( pPool, "Where is the pool?" );
364 FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
365 SID_ATTR_GRAF_CROP ) ) );
366
367 if (&rField == m_xWidthZoomMF.get())
368 {
369 tools::Long nLRBorders = lcl_GetValue(*m_xLeftMF, eUnit)
370 +lcl_GetValue(*m_xRightMF, eUnit);
371 m_xWidthMF->set_value( m_xWidthMF->normalize(
372 ((m_aOrigSize.Width() - nLRBorders) * rField.get_value(FieldUnit::NONE))/100),
373 eUnit);
374 }
375 else
376 {
377 tools::Long nULBorders = lcl_GetValue(*m_xTopMF, eUnit)
378 +lcl_GetValue(*m_xBottomMF, eUnit);
379 m_xHeightMF->set_value( m_xHeightMF->normalize(
380 ((m_aOrigSize.Height() - nULBorders ) * rField.get_value(FieldUnit::NONE))/100) ,
381 eUnit );
382 }
383}
384
385/*--------------------------------------------------------------------
386 description: change size, adjust scale
387 --------------------------------------------------------------------*/
388
390{
391 SfxItemPool* pPool = GetItemSet().GetPool();
392 DBG_ASSERT( pPool, "Where is the pool?" );
393 FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
394 SID_ATTR_GRAF_CROP ) ) );
395
396 Size aSize( lcl_GetValue(*m_xWidthMF, eUnit),
397 lcl_GetValue(*m_xHeightMF, eUnit) );
398
399 if(&rField == m_xWidthMF.get())
400 {
401 tools::Long nWidth = m_aOrigSize.Width() -
402 ( lcl_GetValue(*m_xLeftMF, eUnit) +
403 lcl_GetValue(*m_xRightMF, eUnit) );
404 if(!nWidth)
405 nWidth++;
406 sal_uInt16 nZoom = static_cast<sal_uInt16>( aSize.Width() * 100 / nWidth);
407 m_xWidthZoomMF->set_value(nZoom, FieldUnit::NONE);
408 }
409 else
410 {
411 tools::Long nHeight = m_aOrigSize.Height() -
412 ( lcl_GetValue(*m_xTopMF, eUnit) +
413 lcl_GetValue(*m_xBottomMF, eUnit));
414 if(!nHeight)
415 nHeight++;
416 sal_uInt16 nZoom = static_cast<sal_uInt16>( aSize.Height() * 100 / nHeight);
417 m_xHeightZoomMF->set_value(nZoom, FieldUnit::NONE);
418 }
419}
420
421/*--------------------------------------------------------------------
422 description: evaluate border
423 --------------------------------------------------------------------*/
424
425IMPL_LINK( SvxGrfCropPage, CropModifyHdl, weld::MetricSpinButton&, rField, void )
426{
427 SfxItemPool* pPool = GetItemSet().GetPool();
428 DBG_ASSERT( pPool, "Where is the pool?" );
429 FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
430 SID_ATTR_GRAF_CROP ) ) );
431
432 bool bZoom = m_xZoomConstRB->get_active();
433 if (&rField == m_xLeftMF.get() || &rField == m_xRightMF.get())
434 {
435 tools::Long nLeft = lcl_GetValue( *m_xLeftMF, eUnit );
436 tools::Long nRight = lcl_GetValue( *m_xRightMF, eUnit );
437 tools::Long nWidthZoom = static_cast<tools::Long>(m_xWidthZoomMF->get_value(FieldUnit::NONE));
438 if (bZoom && nWidthZoom != 0 && ( ( ( m_aOrigSize.Width() - (nLeft + nRight )) * nWidthZoom )
439 / 100 >= m_aPageSize.Width() ) )
440 {
441 if (&rField == m_xLeftMF.get())
442 {
443 nLeft = m_aOrigSize.Width() -
444 ( m_aPageSize.Width() * 100 / nWidthZoom + nRight );
445 m_xLeftMF->set_value( m_xLeftMF->normalize( nLeft ), eUnit );
446 }
447 else
448 {
449 nRight = m_aOrigSize.Width() -
450 ( m_aPageSize.Width() * 100 / nWidthZoom + nLeft );
451 m_xRightMF->set_value( m_xRightMF->normalize( nRight ), eUnit );
452 }
453 }
455 {
456 m_aExampleWN.SetLeft(nRight);
457 m_aExampleWN.SetRight(nLeft);
458 }
459 else
460 {
461 m_aExampleWN.SetLeft(nLeft);
462 m_aExampleWN.SetRight(nRight);
463 }
464 if(bZoom)
465 {
466 // scale stays, recompute width
467 ZoomHdl(*m_xWidthZoomMF);
468 }
469 }
470 else
471 {
472 tools::Long nTop = lcl_GetValue( *m_xTopMF, eUnit );
473 tools::Long nBottom = lcl_GetValue( *m_xBottomMF, eUnit );
474 tools::Long nHeightZoom = static_cast<tools::Long>(m_xHeightZoomMF->get_value(FieldUnit::NONE));
475 if(bZoom && ( ( ( m_aOrigSize.Height() - (nTop + nBottom )) * nHeightZoom)
476 / 100 >= m_aPageSize.Height()))
477 {
478 assert(nHeightZoom && "div-by-zero");
479 if(&rField == m_xTopMF.get())
480 {
481 nTop = m_aOrigSize.Height() -
482 ( m_aPageSize.Height() * 100 / nHeightZoom + nBottom);
483 m_xTopMF->set_value( m_xWidthMF->normalize( nTop ), eUnit );
484 }
485 else
486 {
487 nBottom = m_aOrigSize.Height() -
488 ( m_aPageSize.Height() * 100 / nHeightZoom + nTop);
489 m_xBottomMF->set_value( m_xWidthMF->normalize( nBottom ), eUnit );
490 }
491 }
492 m_aExampleWN.SetTop( nTop );
493 m_aExampleWN.SetBottom( nBottom );
494 if(bZoom)
495 {
496 // scale stays, recompute height
497 ZoomHdl(*m_xHeightZoomMF);
498 }
499 }
500 m_aExampleWN.Invalidate();
501 // size and border changed -> recompute scale
502 if(!bZoom)
503 CalcZoom();
504 CalcMinMaxBorder();
505}
506/*--------------------------------------------------------------------
507 description: set original size
508 --------------------------------------------------------------------*/
509
511{
512 SfxItemPool* pPool = GetItemSet().GetPool();
513 DBG_ASSERT( pPool, "Where is the pool?" );
514 FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
515 SID_ATTR_GRAF_CROP ) ) );
516
517 tools::Long nWidth = m_aOrigSize.Width() -
518 lcl_GetValue( *m_xLeftMF, eUnit ) -
519 lcl_GetValue( *m_xRightMF, eUnit );
520 m_xWidthMF->set_value( m_xWidthMF->normalize( nWidth ), eUnit );
521 tools::Long nHeight = m_aOrigSize.Height() -
522 lcl_GetValue( *m_xTopMF, eUnit ) -
523 lcl_GetValue( *m_xBottomMF, eUnit );
524 m_xHeightMF->set_value( m_xHeightMF->normalize( nHeight ), eUnit );
525 m_xWidthZoomMF->set_value(100, FieldUnit::NONE);
526 m_xHeightZoomMF->set_value(100, FieldUnit::NONE);
527 m_bSetOrigSize = true;
528}
529/*--------------------------------------------------------------------
530 description: compute scale
531 --------------------------------------------------------------------*/
532
534{
535 SfxItemPool* pPool = GetItemSet().GetPool();
536 DBG_ASSERT( pPool, "Where is the pool?" );
537 FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
538 SID_ATTR_GRAF_CROP ) ) );
539
540 tools::Long nWidth = lcl_GetValue( *m_xWidthMF, eUnit );
541 tools::Long nHeight = lcl_GetValue( *m_xHeightMF, eUnit );
542 tools::Long nLRBorders = lcl_GetValue( *m_xLeftMF, eUnit ) +
543 lcl_GetValue( *m_xRightMF, eUnit );
544 tools::Long nULBorders = lcl_GetValue( *m_xTopMF, eUnit ) +
545 lcl_GetValue( *m_xBottomMF, eUnit );
546 sal_uInt16 nZoom = 0;
547 tools::Long nDen;
548 if( (nDen = m_aOrigSize.Width() - nLRBorders) > 0)
549 nZoom = static_cast<sal_uInt16>((( nWidth * 1000 / nDen )+5)/10);
550 m_xWidthZoomMF->set_value(nZoom, FieldUnit::NONE);
551 if( (nDen = m_aOrigSize.Height() - nULBorders) > 0)
552 nZoom = static_cast<sal_uInt16>((( nHeight * 1000 / nDen )+5)/10);
553 else
554 nZoom = 0;
555 m_xHeightZoomMF->set_value(nZoom, FieldUnit::NONE);
556}
557
558/*--------------------------------------------------------------------
559 description: set minimum/maximum values for the margins
560 --------------------------------------------------------------------*/
561
563{
564 SfxItemPool* pPool = GetItemSet().GetPool();
565 DBG_ASSERT( pPool, "Where is the pool?" );
566 FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
567 SID_ATTR_GRAF_CROP ) ) );
568 tools::Long nR = lcl_GetValue(*m_xRightMF, eUnit );
569 tools::Long nMinWidth = (m_aOrigSize.Width() * 10) /11;
570 tools::Long nMin = nMinWidth - (nR >= 0 ? nR : 0);
571 m_xLeftMF->set_max( m_xLeftMF->normalize(nMin), eUnit );
572
573 tools::Long nL = lcl_GetValue(*m_xLeftMF, eUnit );
574 nMin = nMinWidth - (nL >= 0 ? nL : 0);
575 m_xRightMF->set_max( m_xRightMF->normalize(nMin), eUnit );
576
577 tools::Long nUp = lcl_GetValue( *m_xTopMF, eUnit );
578 tools::Long nMinHeight = (m_aOrigSize.Height() * 10) /11;
579 nMin = nMinHeight - (nUp >= 0 ? nUp : 0);
580 m_xBottomMF->set_max( m_xBottomMF->normalize(nMin), eUnit );
581
582 tools::Long nLow = lcl_GetValue(*m_xBottomMF, eUnit );
583 nMin = nMinHeight - (nLow >= 0 ? nLow : 0);
584 m_xTopMF->set_max( m_xTopMF->normalize(nMin), eUnit );
585}
586/*--------------------------------------------------------------------
587 description: set spinsize to 1/20 of the original size,
588 fill FixedText with the original size
589 --------------------------------------------------------------------*/
590
592{
593 if( bFound )
594 {
595 SfxItemPool* pPool = GetItemSet().GetPool();
596 DBG_ASSERT( pPool, "Where is the pool?" );
597 FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
598 SID_ATTR_GRAF_CROP ) ));
599
600 sal_Int64 nSpin = m_xLeftMF->normalize(m_aOrigSize.Width()) / 20;
601 nSpin = vcl::ConvertValue( nSpin, m_aOrigSize.Width(), 0,
602 eUnit, m_xLeftMF->get_unit());
603
604 // if the margin is too big, it is set to 1/3 on both pages
605 tools::Long nR = lcl_GetValue( *m_xRightMF, eUnit );
606 tools::Long nL = lcl_GetValue( *m_xLeftMF, eUnit );
607 if((nL + nR) < - m_aOrigSize.Width())
608 {
609 tools::Long nVal = m_aOrigSize.Width() / -3;
610 m_xRightMF->set_value( m_xRightMF->normalize( nVal ), eUnit );
611 m_xLeftMF->set_value( m_xLeftMF->normalize( nVal ), eUnit );
612 m_aExampleWN.SetLeft(nVal);
614 }
615 tools::Long nUp = lcl_GetValue(*m_xTopMF, eUnit );
616 tools::Long nLow = lcl_GetValue(*m_xBottomMF, eUnit );
617 if((nUp + nLow) < - m_aOrigSize.Height())
618 {
619 tools::Long nVal = m_aOrigSize.Height() / -3;
620 m_xTopMF->set_value( m_xTopMF->normalize( nVal ), eUnit );
621 m_xBottomMF->set_value( m_xBottomMF->normalize( nVal ), eUnit );
622 m_aExampleWN.SetTop(nVal);
624 }
625
626 m_xLeftMF->set_increments(nSpin, nSpin * 10, FieldUnit::NONE);
627 m_xRightMF->set_increments(nSpin, nSpin * 10, FieldUnit::NONE);
628 nSpin = m_xTopMF->normalize(m_aOrigSize.Height()) / 20;
629 nSpin = vcl::ConvertValue( nSpin, m_aOrigSize.Width(), 0,
630 eUnit, m_xLeftMF->get_unit() );
631 m_xTopMF->set_increments(nSpin, nSpin * 10, FieldUnit::NONE);
632 m_xBottomMF->set_increments(nSpin, nSpin * 10, FieldUnit::NONE);
633
634 // display original size
635 const FieldUnit eMetric = GetModuleFieldUnit( GetItemSet() );
636
637 OUString sTemp;
638 {
639 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/spinbox.ui"));
640 std::unique_ptr<weld::Dialog> xTopLevel(xBuilder->weld_dialog("SpinDialog"));
641 std::unique_ptr<weld::MetricSpinButton> xFld(xBuilder->weld_metric_spin_button("spin", FieldUnit::CM));
642 SetFieldUnit( *xFld, eMetric );
643 xFld->set_digits(m_xWidthMF->get_digits());
644 xFld->set_max(INT_MAX - 1, FieldUnit::NONE);
645
646 xFld->set_value(xFld->normalize(m_aOrigSize.Width()), eUnit);
647 sTemp = xFld->get_text();
648 xFld->set_value(xFld->normalize(m_aOrigSize.Height()), eUnit);
649 // multiplication sign (U+00D7)
650 sTemp += u"\u00D7" + xFld->get_text();
651 }
652
654 sal_Int32 ax = 0.5 + m_aOrigPixelSize.Width() /
655 o3tl::convert<double>(m_aOrigSize.Width(), o3tl::Length::twip,
657 sal_Int32 ay = 0.5 + m_aOrigPixelSize.Height() /
658 o3tl::convert<double>(m_aOrigSize.Height(), o3tl::Length::twip,
660 OUString sPPI = OUString::number(ax);
661 if (abs(ax - ay) > 1) {
662 sPPI += u"\u00D7" + OUString::number(ay);
663 }
664 sTemp += " " + CuiResId(RID_CUISTR_PPI).replaceAll("%1", sPPI);
665 }
666 sTemp += "\n" + OUString::number(m_aOrigPixelSize.Width()) + u"\u00D7" + OUString::number(m_aOrigPixelSize.Height()) + " px";
667 m_xOrigSizeFT->set_label(sTemp);
668 }
669
670 m_xCropFrame->set_sensitive(bFound);
671 m_xScaleFrame->set_sensitive(bFound);
672 m_xSizeFrame->set_sensitive(bFound);
673 m_xOrigSizeGrid->set_sensitive(bFound);
674 m_xZoomConstRB->set_sensitive(bFound);
675}
676
678{
679 Size aSize;
680
681 if (m_aPreferredDPI > 0)
682 {
683 Size aPixelSize = rGrf.GetSizePixel();
684 double fWidth = aPixelSize.Width() / double(m_aPreferredDPI);
685 double fHeight = aPixelSize.Height() / double(m_aPreferredDPI);
688 aSize = Size(fWidth, fHeight);
689 }
690 else
691 {
692 const MapMode aMapTwip( MapUnit::MapTwip );
693 aSize = rGrf.GetPrefSize();
694 if( MapUnit::MapPixel == rGrf.GetPrefMapMode().GetMapUnit() )
695 aSize = Application::GetDefaultDevice()->PixelToLogic(aSize, aMapTwip);
696 else
697 aSize = OutputDevice::LogicToLogic( aSize,
698 rGrf.GetPrefMapMode(), aMapTwip );
699 }
700 return aSize;
701}
702
703/*****************************************************************/
704
706 : m_aTopLeft(0, 0)
707 , m_aBottomRight(0, 0)
708{
709}
710
712{
713 CustomWidgetController::SetDrawingArea(pDrawingArea);
714 OutputDevice& rDevice = pDrawingArea->get_ref_device();
715 Size aSize(rDevice.LogicToPixel(Size(78, 78), MapMode(MapUnit::MapAppFont)));
716 pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
717
718 m_aMapMode = rDevice.GetMapMode();
721 MapMode(MapUnit::MapTwip), m_aMapMode);
722}
723
724void SvxCropExample::Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle&)
725{
726 rRenderContext.Push(vcl::PushFlags::MAPMODE);
727 rRenderContext.SetMapMode(m_aMapMode);
728
729 // Win BG
730 const Size aWinSize(rRenderContext.PixelToLogic(GetOutputSizePixel()));
731 rRenderContext.SetLineColor();
732 rRenderContext.SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetWindowColor());
733 rRenderContext.DrawRect(::tools::Rectangle(Point(), aWinSize));
734
735 // use AA, the Graphic may be a metafile/svg and would then look ugly
736 rRenderContext.SetAntialiasing(AntialiasingFlags::Enable);
737
738 // draw Graphic
739 ::tools::Rectangle aRect(
740 Point((aWinSize.Width() - m_aFrameSize.Width())/2, (aWinSize.Height() - m_aFrameSize.Height())/2),
742 m_aGrf.Draw(rRenderContext, aRect.TopLeft(), aRect.GetSize());
743
744 // Remove one more case that uses XOR paint (RasterOp::Invert).
745 // Get colors and logic DashLength from settings, use equal to
746 // PolygonMarkerPrimitive2D, may be changed to that primitive later.
747 // Use this to guarantee good visibility - that was the purpose of
748 // the former used XOR paint.
749 const Color aColA(SvtOptionsDrawinglayer::GetStripeColorA().getBColor());
750 const Color aColB(SvtOptionsDrawinglayer::GetStripeColorB().getBColor());
751 const double fStripeLength(SvtOptionsDrawinglayer::GetStripeLength());
752 const basegfx::B2DVector aDashVector(rRenderContext.GetInverseViewTransformation() * basegfx::B2DVector(fStripeLength, 0.0));
753 const double fLogicDashLength(aDashVector.getX());
754
755 // apply current crop settings
756 aRect.AdjustLeft(m_aTopLeft.Y());
757 aRect.AdjustTop(m_aTopLeft.X());
758 aRect.AdjustRight(-m_aBottomRight.Y());
759 aRect.AdjustBottom(-m_aBottomRight.X());
760
761 // apply dash with direct paint callbacks
764 basegfx::B2DRange(aRect.Left(), aRect.Top(), aRect.Right(), aRect.Bottom())),
765 std::vector< double >(2, fLogicDashLength),
766 [&aColA,&rRenderContext](const basegfx::B2DPolygon& rSnippet)
767 {
768 rRenderContext.SetLineColor(aColA);
769 rRenderContext.DrawPolyLine(rSnippet);
770 },
771 [&aColB,&rRenderContext](const basegfx::B2DPolygon& rSnippet)
772 {
773 rRenderContext.SetLineColor(aColB);
774 rRenderContext.DrawPolyLine(rSnippet);
775 },
776 2.0 * fLogicDashLength);
777
778 rRenderContext.Pop();
779}
780
782{
784}
785
787{
788 m_aFrameSize = rSz;
789 if (!m_aFrameSize.Width())
791 if (!m_aFrameSize.Height())
793 Size aWinSize( GetOutputSizePixel() );
794 Fraction aXScale( aWinSize.Width() * 4, m_aFrameSize.Width() * 5 );
795 Fraction aYScale( aWinSize.Height() * 4, m_aFrameSize.Height() * 5 );
796
797 if( aYScale < aXScale )
798 aXScale = aYScale;
799
800 m_aMapMode.SetScaleX(aXScale);
801 m_aMapMode.SetScaleY(aXScale);
802
803 Invalidate();
804}
805
806/* 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
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()
std::unordered_map< OString, css::uno::Any > & getAdditionalProperties()
const SfxItemSet * GetDialogExampleSet() const
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:786
virtual void Resize() override
Definition: grfpage.cxx:781
virtual void Paint(vcl::RenderContext &rRenderContext, const ::tools::Rectangle &rRect) override
Definition: grfpage.cxx:724
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:711
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:562
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:221
std::unique_ptr< weld::MetricSpinButton > m_xHeightMF
Definition: grfpage.hxx:77
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: grfpage.cxx:349
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:533
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:285
std::unique_ptr< weld::MetricSpinButton > m_xBottomMF
Definition: grfpage.hxx:69
void GraphicHasChanged(bool bFound)
Definition: grfpage.cxx:591
virtual ~SvxGrfCropPage() override
Definition: grfpage.cxx:109
Size GetGrfOrigSize(const Graphic &rGraphic)
Definition: grfpage.cxx:677
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:360
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:510
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")