1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <tools/urlobj.hxx>
23 #include <svx/xbtmpit.hxx>
24 #include <svx/svxids.hrc>
25 #include <strings.hrc>
26 #include <svx/xfillit0.hxx>
27 #include <svx/xtable.hxx>
28 #include <svx/xflbmsxy.hxx>
29 #include <svx/xflbmtit.hxx>
30 #include <svx/xflbstit.hxx>
31 #include <svx/xflbmsli.hxx>
32 #include <svx/xflbmpit.hxx>
33 #include <svx/xflboxy.hxx>
34 #include <svx/xflbtoxy.hxx>
35 #include <cuitabarea.hxx>
36 #include <dialmgr.hxx>
37 #include <svx/dlgutil.hxx>
38 #include <svl/intitem.hxx>
39 #include <sfx2/opengrf.hxx>
40 #include <vcl/svapp.hxx>
41 #include <vcl/weld.hxx>
42 #include <svx/svxdlg.hxx>
43 #include <sfx2/viewsh.hxx>
44 #include <sfx2/dialoghelper.hxx>
45 #include <sal/log.hxx>
46 #include <comphelper/lok.hxx>
47 #include <svtools/unitconv.hxx>
49 using namespace com::sun::star
;
64 const sal_uInt16
SvxBitmapTabPage::pBitmapRanges
[] =
66 SID_ATTR_TRANSFORM_WIDTH
,
67 SID_ATTR_TRANSFORM_HEIGHT
,
71 SvxBitmapTabPage::SvxBitmapTabPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rInAttrs
)
72 : SfxTabPage(pPage
, pController
, "cui/ui/bitmaptabpage.ui", "BitmapTabPage", &rInAttrs
)
73 , m_rOutAttrs(rInAttrs
)
74 , m_pnBitmapListState(nullptr)
76 , m_fObjectHeight(0.0)
77 , m_bLogicalSize(false)
78 , m_aXFillAttr(rInAttrs
.GetPool())
79 , m_rXFSet(m_aXFillAttr
.GetItemSet())
81 , m_xBitmapLB(new SvxPresetListBox(m_xBuilder
->weld_scrolled_window("bitmapwin")))
82 , m_xBitmapStyleLB(m_xBuilder
->weld_combo_box("bitmapstyle"))
83 , m_xSizeBox(m_xBuilder
->weld_container("sizebox"))
84 , m_xTsbScale(m_xBuilder
->weld_check_button("scaletsb"))
85 , m_xBitmapWidth(m_xBuilder
->weld_metric_spin_button("width", FieldUnit::PERCENT
))
86 , m_xBitmapHeight(m_xBuilder
->weld_metric_spin_button("height", FieldUnit::PERCENT
))
87 , m_xPositionBox(m_xBuilder
->weld_container("posbox"))
88 , m_xPositionLB(m_xBuilder
->weld_combo_box("positionlb"))
89 , m_xPositionOffBox(m_xBuilder
->weld_container("posoffbox"))
90 , m_xPositionOffX(m_xBuilder
->weld_metric_spin_button("posoffx", FieldUnit::PERCENT
))
91 , m_xPositionOffY(m_xBuilder
->weld_metric_spin_button("posoffy", FieldUnit::PERCENT
))
92 , m_xTileOffBox(m_xBuilder
->weld_container("tileoffbox"))
93 , m_xTileOffLB(m_xBuilder
->weld_combo_box("tileofflb"))
94 , m_xTileOffset(m_xBuilder
->weld_metric_spin_button("tileoffmtr", FieldUnit::PERCENT
))
95 , m_xBtnImport(m_xBuilder
->weld_button("BTN_IMPORT"))
96 , m_xCtlBitmapPreview(new weld::CustomWeld(*m_xBuilder
, "CTL_BITMAP_PREVIEW", m_aCtlBitmapPreview
))
97 , m_xBitmapLBWin(new weld::CustomWeld(*m_xBuilder
, "BITMAP", *m_xBitmapLB
))
99 // setting the output device
100 m_rXFSet
.Put( XFillStyleItem(drawing::FillStyle_BITMAP
) );
101 m_rXFSet
.Put( XFillBitmapItem(OUString(), Graphic()) );
102 m_aCtlBitmapPreview
.SetAttributes( m_aXFillAttr
.GetItemSet() );
104 m_xBitmapLB
->SetSelectHdl( LINK(this, SvxBitmapTabPage
, ModifyBitmapHdl
) );
105 m_xBitmapLB
->SetRenameHdl( LINK(this, SvxBitmapTabPage
, ClickRenameHdl
) );
106 m_xBitmapLB
->SetDeleteHdl( LINK(this, SvxBitmapTabPage
, ClickDeleteHdl
) );
107 m_xBitmapStyleLB
->connect_changed( LINK(this, SvxBitmapTabPage
, ModifyBitmapStyleHdl
) );
108 Link
<weld::MetricSpinButton
&, void> aLink1( LINK(this, SvxBitmapTabPage
, ModifyBitmapSizeHdl
) );
109 m_xBitmapWidth
->connect_value_changed( aLink1
);
110 m_xBitmapHeight
->connect_value_changed( aLink1
);
111 m_xTsbScale
->connect_clicked(LINK(this, SvxBitmapTabPage
, ClickScaleHdl
));
112 m_xPositionLB
->connect_changed( LINK( this, SvxBitmapTabPage
, ModifyBitmapPositionHdl
) );
113 Link
<weld::MetricSpinButton
&, void> aLink( LINK( this, SvxBitmapTabPage
, ModifyPositionOffsetHdl
) );
114 m_xPositionOffX
->connect_value_changed(aLink
);
115 m_xPositionOffY
->connect_value_changed(aLink
);
116 m_xTileOffset
->connect_value_changed( LINK( this, SvxBitmapTabPage
, ModifyTileOffsetHdl
) );
117 m_xBtnImport
->connect_clicked( LINK(this, SvxBitmapTabPage
, ClickImportHdl
) );
118 if (comphelper::LibreOfficeKit::isActive())
119 m_xBtnImport
->hide();
121 // Calculate size of display boxes
123 Size aBitmapLBSize
= getPagePropertiesOptimalSize(m_xBitmapLB
->GetDrawingArea()->get_ref_device());
124 m_xBitmapLB
->set_size_request(aBitmapLBSize
.Width(), aBitmapLBSize
.Height());
126 Size aSize
= getDrawPreviewOptimalSize(m_aCtlBitmapPreview
.GetDrawingArea()->get_ref_device());
127 m_xCtlBitmapPreview
->set_size_request(aSize
.Width(), aSize
.Height());
129 SfxItemPool
* pPool
= m_rXFSet
.GetPool();
130 mePoolUnit
= pPool
->GetMetric( XATTR_FILLBMP_SIZEX
);
131 meFieldUnit
= GetModuleFieldUnit( rInAttrs
);
132 SetFieldUnit( *m_xBitmapWidth
, meFieldUnit
, true );
133 SetFieldUnit( *m_xBitmapHeight
, meFieldUnit
, true );
135 SfxViewShell
* pViewShell
= SfxViewShell::Current();
137 mpView
= pViewShell
->GetDrawView();
138 DBG_ASSERT( mpView
, "no valid view (!)" );
141 SvxBitmapTabPage::~SvxBitmapTabPage()
143 m_xBitmapLBWin
.reset();
145 m_xCtlBitmapPreview
.reset();
148 void SvxBitmapTabPage::Construct()
150 m_xBitmapLB
->FillPresetListBox( *m_pBitmapList
);
153 void SvxBitmapTabPage::ActivatePage( const SfxItemSet
& rSet
)
155 XFillBitmapItem
aItem( rSet
.Get(XATTR_FILLBITMAP
) );
158 if ( !aItem
.isPattern() )
160 nPos
= SearchBitmapList( aItem
.GetGraphicObject() );
161 if ( nPos
== LISTBOX_ENTRY_NOTFOUND
)
166 m_xBitmapWidth
->set_value( 100, FieldUnit::NONE
);
167 m_xBitmapHeight
->set_value( 100, FieldUnit::NONE
);
168 const_cast<SfxItemSet
&>(rSet
).Put( XFillBmpSizeXItem( GetCoreValue( *m_xBitmapWidth
, mePoolUnit
) ) );
169 const_cast<SfxItemSet
&>(rSet
).Put( XFillBmpSizeYItem( GetCoreValue( *m_xBitmapHeight
, mePoolUnit
) ) );
172 sal_uInt16 nId
= m_xBitmapLB
->GetItemId( static_cast<size_t>( nPos
) );
173 m_xBitmapLB
->SelectItem( nId
);
176 DeactivateRC
SvxBitmapTabPage::DeactivatePage( SfxItemSet
* _pSet
)
179 FillItemSet( _pSet
);
181 return DeactivateRC::LeavePage
;
185 bool SvxBitmapTabPage::FillItemSet( SfxItemSet
* rAttrs
)
187 rAttrs
->Put(XFillStyleItem(drawing::FillStyle_BITMAP
));
188 size_t nPos
= m_xBitmapLB
->GetSelectItemPos();
189 if(VALUESET_ITEM_NOTFOUND
!= nPos
)
191 const XBitmapEntry
* pXBitmapEntry
= m_pBitmapList
->GetBitmap(nPos
);
192 const OUString
aString(m_xBitmapLB
->GetItemText( m_xBitmapLB
->GetSelectedItemId() ));
193 rAttrs
->Put(XFillBitmapItem(aString
, pXBitmapEntry
->GetGraphicObject()));
196 BitmapStyle eStylePos
= static_cast<BitmapStyle
>(m_xBitmapStyleLB
->get_active());
197 bool bIsStretched( eStylePos
== STRETCHED
);
198 bool bIsTiled( eStylePos
== TILED
);
200 rAttrs
->Put( XFillBmpTileItem(bIsTiled
) );
201 rAttrs
->Put( XFillBmpStretchItem(bIsStretched
) );
211 sal_Int64 nWidthPercent
= m_xBitmapWidth
->get_value(FieldUnit::NONE
);
212 sal_Int64 nHeightPercent
= m_xBitmapHeight
->get_value(FieldUnit::NONE
);
213 if (m_xTsbScale
->get_sensitive() && m_xTsbScale
->get_state() == TRISTATE_TRUE
)
215 aSetBitmapSize
.setWidth( -nWidthPercent
);
216 aSetBitmapSize
.setHeight( -nHeightPercent
);
218 else if (!m_bLogicalSize
)
220 aSetBitmapSize
.setWidth( GetCoreValue(*m_xBitmapWidth
, mePoolUnit
) );
221 aSetBitmapSize
.setHeight( GetCoreValue(*m_xBitmapHeight
, mePoolUnit
) );
225 rAttrs
->Put( XFillBmpSizeLogItem(true) );
226 aSetBitmapSize
.setWidth( 0 );
227 aSetBitmapSize
.setHeight( 0 );
236 rAttrs
->Put( XFillBmpSizeXItem( aSetBitmapSize
.Width() ) );
237 rAttrs
->Put( XFillBmpSizeYItem( aSetBitmapSize
.Height() ) );
240 if (m_xPositionLB
->get_sensitive())
241 rAttrs
->Put( XFillBmpPosItem( static_cast<RectPoint
>( m_xPositionLB
->get_active() ) ) );
242 if (m_xPositionOffX
->get_sensitive())
243 rAttrs
->Put( XFillBmpPosOffsetXItem(m_xPositionOffX
->get_value(FieldUnit::PERCENT
)));
244 if (m_xPositionOffY
->get_sensitive())
245 rAttrs
->Put( XFillBmpPosOffsetYItem(m_xPositionOffY
->get_value(FieldUnit::PERCENT
)));
246 if (m_xTileOffBox
->get_sensitive())
248 TileOffset eValue
= static_cast<TileOffset
>(m_xTileOffLB
->get_active());
249 sal_uInt16 nOffsetValue
= static_cast<sal_uInt16
>(m_xTileOffset
->get_value(FieldUnit::PERCENT
));
250 sal_uInt16 nRowOff
= (eValue
== ROW
) ? nOffsetValue
: 0;
251 sal_uInt16 nColOff
= (eValue
== COLUMN
) ? nOffsetValue
: 0;
252 rAttrs
->Put( XFillBmpTileOffsetXItem(nRowOff
) );
253 rAttrs
->Put( XFillBmpTileOffsetYItem(nColOff
) );
259 void SvxBitmapTabPage::Reset( const SfxItemSet
* rAttrs
)
261 const SfxPoolItem
* pItemTransfWidth
= nullptr;
262 const SfxPoolItem
* pItemTransfHeight
= nullptr;
263 double fUIScale
= 1.0;
266 fUIScale
= ( mpView
->GetModel() ? double(mpView
->GetModel()->GetUIScale()) : 1.0);
269 if (mpView
->AreObjectsMarked())
271 SfxItemSet
rGeoAttr(mpView
->GetGeoAttrFromMarked());
272 pItemTransfWidth
= GetItem( rGeoAttr
, SID_ATTR_TRANSFORM_WIDTH
);
273 pItemTransfHeight
= GetItem( rGeoAttr
, SID_ATTR_TRANSFORM_HEIGHT
);
276 m_fObjectWidth
= std::max( pItemTransfWidth
? static_cast<double>(static_cast<const SfxUInt32Item
*>(pItemTransfWidth
)->GetValue()) : 0.0, 1.0 );
277 m_fObjectHeight
= std::max( pItemTransfHeight
? static_cast<double>(static_cast<const SfxUInt32Item
*>(pItemTransfHeight
)->GetValue()) : 0.0, 1.0 );
278 double fTmpWidth((OutputDevice::LogicToLogic(static_cast<sal_Int32
>(m_fObjectWidth
), mePoolUnit
, MapUnit::Map100thMM
)) / fUIScale
);
279 m_fObjectWidth
= fTmpWidth
;
281 double fTmpHeight((OutputDevice::LogicToLogic(static_cast<sal_Int32
>(m_fObjectHeight
), mePoolUnit
, MapUnit::Map100thMM
)) / fUIScale
);
282 m_fObjectHeight
= fTmpHeight
;
284 XFillBitmapItem
aItem( rAttrs
->Get(XATTR_FILLBITMAP
) );
286 if(!aItem
.isPattern())
288 m_rXFSet
.Put( aItem
);
289 m_aCtlBitmapPreview
.SetAttributes( m_aXFillAttr
.GetItemSet() );
290 m_aCtlBitmapPreview
.Invalidate();
293 m_xCtlBitmapPreview
->set_sensitive(false);
295 std::unique_ptr
<GraphicObject
> pGraphicObject
;
296 pGraphicObject
.reset( new GraphicObject(aItem
.GetGraphicObject()) );
298 BitmapEx
aBmpEx(pGraphicObject
->GetGraphic().GetBitmapEx());
299 Size aTempBitmapSize
= aBmpEx
.GetSizePixel();
300 rBitmapSize
= Application::GetDefaultDevice()->PixelToLogic(aTempBitmapSize
, MapMode(MapUnit::Map100thMM
));
301 CalculateBitmapPresetSize();
303 bool bTiled
= false; bool bStretched
= false;
304 if(rAttrs
->GetItemState( XATTR_FILLBMP_TILE
) != SfxItemState::DONTCARE
)
305 bTiled
= rAttrs
->Get( XATTR_FILLBMP_TILE
).GetValue();
306 if(rAttrs
->GetItemState( XATTR_FILLBMP_STRETCH
) != SfxItemState::DONTCARE
)
307 bStretched
= rAttrs
->Get( XATTR_FILLBMP_STRETCH
).GetValue();
310 m_xBitmapStyleLB
->set_active(static_cast<sal_Int32
>(TILED
));
312 m_xBitmapStyleLB
->set_active(static_cast<sal_Int32
>(STRETCHED
));
314 m_xBitmapStyleLB
->set_active(static_cast<sal_Int32
>(CUSTOM
));
319 if(rAttrs
->GetItemState(XATTR_FILLBMP_SIZELOG
) != SfxItemState::DONTCARE
)
321 if (rAttrs
->Get( XATTR_FILLBMP_SIZELOG
).GetValue())
323 m_xTsbScale
->set_state(TRISTATE_FALSE
);
324 m_bLogicalSize
= true;
328 m_xTsbScale
->set_state(TRISTATE_TRUE
);
329 m_bLogicalSize
= false;
333 m_xTsbScale
->set_state(TRISTATE_INDET
);
335 TriState eRelative
= TRISTATE_FALSE
;
336 if(rAttrs
->GetItemState(XATTR_FILLBMP_SIZEX
) != SfxItemState::DONTCARE
)
338 nWidth
= static_cast<const XFillBmpSizeXItem
&>( rAttrs
->Get( XATTR_FILLBMP_SIZEX
) ).GetValue();
340 nWidth
= rBitmapSize
.Width();
343 eRelative
= TRISTATE_TRUE
;
344 nWidth
= std::abs(nWidth
);
348 if(rAttrs
->GetItemState( XATTR_FILLBMP_SIZEY
) != SfxItemState::DONTCARE
)
350 nHeight
= rAttrs
->Get( XATTR_FILLBMP_SIZEY
).GetValue();
352 nHeight
= rBitmapSize
.Height();
355 eRelative
= TRISTATE_TRUE
;
356 nHeight
= std::abs(nHeight
);
359 m_xTsbScale
->set_state(eRelative
);
360 ClickScaleHdl(*m_xTsbScale
);
363 if(rBitmapSize
.Width() > 0 && rBitmapSize
.Height() > 0)
365 if (eRelative
== TRISTATE_TRUE
)
367 m_xBitmapWidth
->set_value(nWidth
, FieldUnit::NONE
);
368 m_xBitmapHeight
->set_value(nHeight
, FieldUnit::NONE
);
372 SetMetricValue(*m_xBitmapWidth
, nWidth
, mePoolUnit
);
373 SetMetricValue(*m_xBitmapHeight
, nHeight
, mePoolUnit
);
377 if( rAttrs
->GetItemState( XATTR_FILLBMP_POS
) != SfxItemState::DONTCARE
)
379 RectPoint eValue
= rAttrs
->Get( XATTR_FILLBMP_POS
).GetValue();
380 m_xPositionLB
->set_active( static_cast< sal_Int32
>(eValue
) );
383 if( rAttrs
->GetItemState( XATTR_FILLBMP_POSOFFSETX
) != SfxItemState::DONTCARE
)
385 sal_Int32 nValue
= rAttrs
->Get( XATTR_FILLBMP_POSOFFSETX
).GetValue();
386 m_xPositionOffX
->set_value(nValue
, FieldUnit::PERCENT
);
389 m_xPositionOffX
->set_text("");
391 if( rAttrs
->GetItemState( XATTR_FILLBMP_POSOFFSETY
) != SfxItemState::DONTCARE
)
393 sal_Int32 nValue
= rAttrs
->Get( XATTR_FILLBMP_POSOFFSETY
).GetValue();
394 m_xPositionOffY
->set_value(nValue
, FieldUnit::PERCENT
);
397 m_xPositionOffY
->set_text("");
399 if( rAttrs
->GetItemState( XATTR_FILLBMP_TILEOFFSETX
) != SfxItemState::DONTCARE
)
401 sal_Int32 nValue
= rAttrs
->Get( XATTR_FILLBMP_TILEOFFSETX
).GetValue();
404 m_xTileOffLB
->set_active(static_cast<sal_Int32
>(ROW
));
405 m_xTileOffset
->set_value(nValue
, FieldUnit::PERCENT
);
409 if( rAttrs
->GetItemState( XATTR_FILLBMP_TILEOFFSETY
) != SfxItemState::DONTCARE
)
411 sal_Int32 nValue
= rAttrs
->Get( XATTR_FILLBMP_TILEOFFSETY
).GetValue();
414 m_xTileOffLB
->set_active(static_cast<sal_Int32
>(COLUMN
));
415 m_xTileOffset
->set_value(nValue
, FieldUnit::PERCENT
);
419 ClickBitmapHdl_Impl();
422 std::unique_ptr
<SfxTabPage
> SvxBitmapTabPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rAttrs
)
424 return std::make_unique
<SvxBitmapTabPage
>(pPage
, pController
, *rAttrs
);
427 void SvxBitmapTabPage::ClickBitmapHdl_Impl()
429 m_xBitmapLBWin
->set_sensitive(true);
430 m_xCtlBitmapPreview
->set_sensitive(true);
432 ModifyBitmapHdl(m_xBitmapLB
.get());
435 void SvxBitmapTabPage::CalculateBitmapPresetSize()
437 if(rBitmapSize
.Width() > 0 && rBitmapSize
.Height() > 0)
439 long nObjectWidth
= static_cast<long>(m_fObjectWidth
);
440 long nObjectHeight
= static_cast<long>(m_fObjectHeight
);
442 if(std::abs(rBitmapSize
.Width() - nObjectWidth
) < std::abs(rBitmapSize
.Height() - nObjectHeight
))
444 rFilledSize
.setWidth( nObjectWidth
);
445 rFilledSize
.setHeight( rBitmapSize
.Height()*nObjectWidth
/rBitmapSize
.Width() );
446 rZoomedSize
.setWidth( rBitmapSize
.Width()*nObjectHeight
/rBitmapSize
.Height() );
447 rZoomedSize
.setHeight( nObjectHeight
);
451 rFilledSize
.setWidth( rBitmapSize
.Width()*nObjectHeight
/rBitmapSize
.Height() );
452 rFilledSize
.setHeight( nObjectHeight
);
453 rZoomedSize
.setWidth( nObjectWidth
);
454 rZoomedSize
.setHeight( rBitmapSize
.Height()*nObjectWidth
/rBitmapSize
.Width() );
459 IMPL_LINK_NOARG(SvxBitmapTabPage
, ModifyBitmapHdl
, SvtValueSet
*, void)
461 std::unique_ptr
<GraphicObject
> pGraphicObject
;
462 size_t nPos
= m_xBitmapLB
->GetSelectItemPos();
464 if( nPos
!= VALUESET_ITEM_NOTFOUND
)
466 pGraphicObject
.reset(new GraphicObject(m_pBitmapList
->GetBitmap( static_cast<sal_uInt16
>(nPos
) )->GetGraphicObject()));
470 const SfxPoolItem
* pPoolItem
= nullptr;
472 if(SfxItemState::SET
== m_rOutAttrs
.GetItemState(GetWhich(XATTR_FILLSTYLE
), true, &pPoolItem
))
474 const drawing::FillStyle
eXFS(static_cast<const XFillStyleItem
*>(pPoolItem
)->GetValue());
476 if((drawing::FillStyle_BITMAP
== eXFS
) && (SfxItemState::SET
== m_rOutAttrs
.GetItemState(GetWhich(XATTR_FILLBITMAP
), true, &pPoolItem
)))
478 pGraphicObject
.reset(new GraphicObject(static_cast<const XFillBitmapItem
*>(pPoolItem
)->GetGraphicObject()));
484 sal_uInt16 nId
= m_xBitmapLB
->GetItemId(0);
485 m_xBitmapLB
->SelectItem(nId
);
489 pGraphicObject
.reset(new GraphicObject(m_pBitmapList
->GetBitmap(0)->GetGraphicObject()));
496 BitmapEx
aBmpEx(pGraphicObject
->GetGraphic().GetBitmapEx());
497 Size aTempBitmapSize
= aBmpEx
.GetSizePixel();
498 const double fUIScale
= ( (mpView
&& mpView
->GetModel()) ? double(mpView
->GetModel()->GetUIScale()) : 1.0);
500 rBitmapSize
.setWidth( (OutputDevice::LogicToLogic(static_cast<sal_Int32
>(aTempBitmapSize
.Width()),MapUnit::MapPixel
, MapUnit::Map100thMM
)) / fUIScale
);
501 rBitmapSize
.setHeight( (OutputDevice::LogicToLogic(static_cast<sal_Int32
>(aTempBitmapSize
.Height()),MapUnit::MapPixel
, MapUnit::Map100thMM
)) / fUIScale
);
502 CalculateBitmapPresetSize();
503 ModifyBitmapStyleHdl( *m_xBitmapStyleLB
);
504 ModifyBitmapPositionHdl( *m_xPositionLB
);
506 m_rXFSet
.ClearItem(XATTR_FILLBITMAP
);
507 m_rXFSet
.Put(XFillStyleItem(drawing::FillStyle_BITMAP
));
508 m_rXFSet
.Put(XFillBitmapItem(OUString(), *pGraphicObject
));
510 m_aCtlBitmapPreview
.SetAttributes( m_aXFillAttr
.GetItemSet() );
511 m_aCtlBitmapPreview
.Invalidate();
515 SAL_WARN("cui.tabpages", "SvxBitmapTabPage::ModifyBitmapHdl(): null pGraphicObject");
520 IMPL_LINK_NOARG(SvxBitmapTabPage
, ClickRenameHdl
, SvxPresetListBox
*, void)
522 sal_uInt16 nId
= m_xBitmapLB
->GetSelectedItemId();
523 size_t nPos
= m_xBitmapLB
->GetSelectItemPos();
525 if( nPos
!= VALUESET_ITEM_NOTFOUND
)
527 OUString
aDesc( CuiResId( RID_SVXSTR_DESC_NEW_BITMAP
) );
528 OUString
aName( m_pBitmapList
->GetBitmap( nPos
)->GetName() );
530 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
531 ScopedVclPtr
<AbstractSvxNameDialog
> pDlg(pFact
->CreateSvxNameDialog(GetFrameWeld(), aName
, aDesc
));
534 while( bLoop
&& pDlg
->Execute() == RET_OK
)
536 pDlg
->GetName( aName
);
537 sal_Int32 nBitmapPos
= SearchBitmapList( aName
);
538 bool bValidBitmapName
= (nBitmapPos
== static_cast<sal_Int32
>(nPos
) ) || (nBitmapPos
== LISTBOX_ENTRY_NOTFOUND
);
543 m_pBitmapList
->GetBitmap(nPos
)->SetName(aName
);
545 m_xBitmapLB
->SetItemText(nId
, aName
);
546 m_xBitmapLB
->SelectItem( nId
);
548 *m_pnBitmapListState
|= ChangeType::MODIFIED
;
552 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
553 std::unique_ptr
<weld::MessageDialog
> xBox(xBuilder
->weld_message_dialog("DuplicateNameDialog"));
560 IMPL_LINK_NOARG(SvxBitmapTabPage
, ClickDeleteHdl
, SvxPresetListBox
*, void)
562 sal_uInt16 nId
= m_xBitmapLB
->GetSelectedItemId();
563 size_t nPos
= m_xBitmapLB
->GetSelectItemPos();
565 if( nPos
!= VALUESET_ITEM_NOTFOUND
)
567 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/querydeletebitmapdialog.ui"));
568 std::unique_ptr
<weld::MessageDialog
> xQueryBox(xBuilder
->weld_message_dialog("AskDelBitmapDialog"));
570 if (xQueryBox
->run() == RET_YES
)
572 m_pBitmapList
->Remove( static_cast<sal_uInt16
>(nPos
) );
573 m_xBitmapLB
->RemoveItem( nId
);
574 nId
= m_xBitmapLB
->GetItemId(0);
575 m_xBitmapLB
->SelectItem( nId
);
577 m_aCtlBitmapPreview
.Invalidate();
578 ModifyBitmapHdl(m_xBitmapLB
.get());
579 *m_pnBitmapListState
|= ChangeType::MODIFIED
;
584 IMPL_LINK_NOARG( SvxBitmapTabPage
, ModifyBitmapSizeHdl
, weld::MetricSpinButton
&, void )
586 m_bLogicalSize
= false;
587 if (m_xTsbScale
->get_state() != TRISTATE_TRUE
&& static_cast<BitmapStyle
>(m_xBitmapStyleLB
->get_active()) != TILED
)
589 sal_Int64 nWidthPercent
= m_xBitmapWidth
->denormalize(m_xBitmapWidth
->get_value(FieldUnit::NONE
));
590 sal_Int64 nHeightPercent
= m_xBitmapHeight
->denormalize(m_xBitmapHeight
->get_value(FieldUnit::NONE
));
591 if (nWidthPercent
== 100 && nHeightPercent
== 100)
592 m_xBitmapStyleLB
->set_active(static_cast<sal_Int32
>(CUSTOM
));
594 ModifyBitmapStyleHdl(*m_xBitmapStyleLB
);
596 m_aCtlBitmapPreview
.SetAttributes( m_aXFillAttr
.GetItemSet() );
597 m_aCtlBitmapPreview
.Invalidate();
600 IMPL_LINK_NOARG( SvxBitmapTabPage
, ClickScaleHdl
, weld::Button
&, void )
602 if (m_xTsbScale
->get_state() == TRISTATE_TRUE
)
604 m_xBitmapWidth
->set_digits( 0 );
605 m_xBitmapWidth
->set_unit(FieldUnit::PERCENT
);
606 m_xBitmapWidth
->set_value(100, FieldUnit::NONE
);
607 m_xBitmapWidth
->set_range(0, 100, FieldUnit::NONE
);
609 m_xBitmapHeight
->set_digits( 0 );
610 m_xBitmapHeight
->set_unit(FieldUnit::PERCENT
);
611 m_xBitmapHeight
->set_value(100, FieldUnit::NONE
);
612 m_xBitmapHeight
->set_range(0, 100, FieldUnit::NONE
);
616 m_xBitmapWidth
->set_digits( 2 );
617 m_xBitmapWidth
->set_unit(meFieldUnit
);
618 m_xBitmapWidth
->set_value(100, FieldUnit::NONE
);
619 m_xBitmapWidth
->set_range(0, 999900, FieldUnit::NONE
);
621 m_xBitmapHeight
->set_digits( 2 );
622 m_xBitmapHeight
->set_unit(meFieldUnit
);
623 m_xBitmapHeight
->set_value(100, FieldUnit::NONE
);
624 m_xBitmapHeight
->set_range(0, 999900, FieldUnit::NONE
);
627 ModifyBitmapStyleHdl( *m_xBitmapStyleLB
);
630 IMPL_LINK_NOARG( SvxBitmapTabPage
, ModifyBitmapStyleHdl
, weld::ComboBox
&, void )
632 BitmapStyle eStylePos
= static_cast<BitmapStyle
>(m_xBitmapStyleLB
->get_active());
633 bool bIsStretched( eStylePos
== STRETCHED
);
634 bool bIsTiled( eStylePos
== TILED
);
636 m_xSizeBox
->set_sensitive( !bIsStretched
);
637 m_xPositionBox
->set_sensitive( !bIsStretched
);
638 m_xPositionOffBox
->set_sensitive( bIsTiled
);
639 m_xTileOffBox
->set_sensitive( bIsTiled
);
641 m_rXFSet
.Put( XFillBmpTileItem( bIsTiled
) );
642 m_rXFSet
.Put( XFillBmpStretchItem( bIsStretched
) );
652 if (m_xTsbScale
->get_sensitive() && m_xTsbScale
->get_state() == TRISTATE_TRUE
)
654 aSetBitmapSize
.setWidth(-m_xBitmapWidth
->get_value(FieldUnit::NONE
));
655 aSetBitmapSize
.setHeight(-m_xBitmapHeight
->get_value(FieldUnit::NONE
));
659 aSetBitmapSize
.setWidth( GetCoreValue( *m_xBitmapWidth
, mePoolUnit
) );
660 aSetBitmapSize
.setHeight( GetCoreValue( *m_xBitmapHeight
, mePoolUnit
) );
668 m_rXFSet
.Put( XFillBmpSizeXItem( aSetBitmapSize
.Width() ) );
669 m_rXFSet
.Put( XFillBmpSizeYItem( aSetBitmapSize
.Height() ) );
672 m_aCtlBitmapPreview
.SetAttributes( m_aXFillAttr
.GetItemSet() );
673 m_aCtlBitmapPreview
.Invalidate();
676 IMPL_LINK_NOARG(SvxBitmapTabPage
, ModifyBitmapPositionHdl
, weld::ComboBox
&, void)
678 if (m_xPositionLB
->get_sensitive())
679 m_rXFSet
.Put( XFillBmpPosItem( static_cast< RectPoint
>( m_xPositionLB
->get_active() ) ) );
681 m_aCtlBitmapPreview
.SetAttributes( m_aXFillAttr
.GetItemSet() );
682 m_aCtlBitmapPreview
.Invalidate();
685 IMPL_LINK_NOARG(SvxBitmapTabPage
, ModifyPositionOffsetHdl
, weld::MetricSpinButton
&, void)
687 if (m_xPositionOffX
->get_sensitive())
688 m_rXFSet
.Put( XFillBmpPosOffsetXItem( m_xPositionOffX
->get_value(FieldUnit::PERCENT
) ) );
690 if (m_xPositionOffY
->get_sensitive())
691 m_rXFSet
.Put( XFillBmpPosOffsetYItem( m_xPositionOffY
->get_value(FieldUnit::PERCENT
) ) );
693 m_aCtlBitmapPreview
.SetAttributes( m_aXFillAttr
.GetItemSet() );
694 m_aCtlBitmapPreview
.Invalidate();
697 IMPL_LINK_NOARG(SvxBitmapTabPage
, ModifyTileOffsetHdl
, weld::MetricSpinButton
&, void)
699 sal_uInt16 nTileXOff
= 0;
700 sal_uInt16 nTileYOff
= 0;
702 if(m_xTileOffLB
->get_active() == static_cast<sal_Int32
>(ROW
))
703 nTileXOff
= m_xTileOffset
->get_value(FieldUnit::PERCENT
);
705 if(m_xTileOffLB
->get_active() == static_cast<sal_Int32
>(COLUMN
))
706 nTileYOff
= m_xTileOffset
->get_value(FieldUnit::PERCENT
);
708 m_rXFSet
.Put( XFillBmpTileOffsetXItem(nTileXOff
) );
709 m_rXFSet
.Put( XFillBmpTileOffsetYItem(nTileYOff
) );
711 m_aCtlBitmapPreview
.SetAttributes( m_aXFillAttr
.GetItemSet() );
712 m_aCtlBitmapPreview
.Invalidate();
715 IMPL_LINK_NOARG(SvxBitmapTabPage
, ClickImportHdl
, weld::Button
&, void)
717 weld::Window
* pDialogFrameWeld
= GetFrameWeld();
719 SvxOpenGraphicDialog
aDlg(CuiResId(RID_SVXSTR_ADD_IMAGE
), pDialogFrameWeld
);
720 aDlg
.EnableLink(false);
721 long nCount
= m_pBitmapList
->Count();
723 if( !aDlg
.Execute() )
727 std::unique_ptr
<weld::WaitObject
> xWait(new weld::WaitObject(pDialogFrameWeld
));
728 ErrCode nError
= aDlg
.GetGraphic( aGraphic
);
733 OUString
aDesc(CuiResId(RID_SVXSTR_DESC_EXT_BITMAP
));
735 // convert file URL to UI name
737 INetURLObject
aURL( aDlg
.GetPath() );
738 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
739 ScopedVclPtr
<AbstractSvxNameDialog
> pDlg(pFact
->CreateSvxNameDialog(
740 pDialogFrameWeld
, aURL
.GetLastName().getToken(0, '.'), aDesc
));
743 while( pDlg
->Execute() == RET_OK
)
745 pDlg
->GetName( aName
);
747 bool bDifferent
= true;
749 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
750 if( aName
== m_pBitmapList
->GetBitmap( i
)->GetName() )
754 nError
= ERRCODE_NONE
;
758 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(pDialogFrameWeld
, "cui/ui/queryduplicatedialog.ui"));
759 std::unique_ptr
<weld::MessageDialog
> xBox(xBuilder
->weld_message_dialog("DuplicateNameDialog"));
760 if (xBox
->run() != RET_OK
)
764 pDlg
.disposeAndClear();
768 m_pBitmapList
->Insert(std::make_unique
<XBitmapEntry
>(aGraphic
, aName
), nCount
);
770 sal_Int32 nId
= m_xBitmapLB
->GetItemId( nCount
- 1 );
771 BitmapEx aBitmap
= m_pBitmapList
->GetBitmapForPreview( nCount
, m_xBitmapLB
->GetIconSize() );
773 m_xBitmapLB
->InsertItem( nId
+ 1, Image(aBitmap
), aName
);
774 m_xBitmapLB
->SelectItem( nId
+ 1 );
775 *m_pnBitmapListState
|= ChangeType::MODIFIED
;
777 ModifyBitmapHdl(m_xBitmapLB
.get());
782 // graphic couldn't be loaded
783 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(pDialogFrameWeld
, "cui/ui/querynoloadedfiledialog.ui"));
784 std::unique_ptr
<weld::MessageDialog
> xBox(xBuilder
->weld_message_dialog("NoLoadedFileDialog"));
790 sal_Int32
SvxBitmapTabPage::SearchBitmapList(const GraphicObject
& rGraphicObject
)
792 long nCount
= m_pBitmapList
->Count();
793 sal_Int32 nPos
= LISTBOX_ENTRY_NOTFOUND
;
795 for(long i
= 0;i
< nCount
;i
++)
797 if(rGraphicObject
.GetUniqueID() == m_pBitmapList
->GetBitmap( i
)->GetGraphicObject().GetUniqueID())
806 sal_Int32
SvxBitmapTabPage::SearchBitmapList(const OUString
& rBitmapName
)
808 long nCount
= m_pBitmapList
->Count();
809 bool bValidBitmapName
= true;
810 sal_Int32 nPos
= LISTBOX_ENTRY_NOTFOUND
;
812 for(long i
= 0;i
< nCount
&& bValidBitmapName
;i
++)
814 if(rBitmapName
== m_pBitmapList
->GetBitmap( i
)->GetName())
817 bValidBitmapName
= false;
823 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */