Bump version to 6.4.7.2.M8
[LibreOffice.git] / cui / source / tabpages / tpbitmap.cxx
blobe7c32cb4198422306a8a87cf0e2d1242d33aa3f2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <memory>
21 #include <stdlib.h>
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;
51 enum BitmapStyle
53 CUSTOM,
54 TILED,
55 STRETCHED
58 enum TileOffset
60 ROW,
61 COLUMN
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)
75 , m_fObjectWidth(0.0)
76 , m_fObjectHeight(0.0)
77 , m_bLogicalSize(false)
78 , m_aXFillAttr(rInAttrs.GetPool())
79 , m_rXFSet(m_aXFillAttr.GetItemSet())
80 , mpView(nullptr)
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
122 Size aSize = getDrawPreviewOptimalSize(m_aCtlBitmapPreview.GetDrawingArea()->get_ref_device());
123 m_xBitmapLB->set_size_request(aSize.Width(), aSize.Height());
124 m_xCtlBitmapPreview->set_size_request(aSize.Width(), aSize.Height());
126 SfxItemPool* pPool = m_rXFSet.GetPool();
127 mePoolUnit = pPool->GetMetric( XATTR_FILLBMP_SIZEX );
128 meFieldUnit = GetModuleFieldUnit( rInAttrs );
129 SetFieldUnit( *m_xBitmapWidth, meFieldUnit, true );
130 SetFieldUnit( *m_xBitmapHeight, meFieldUnit, true );
132 SfxViewShell* pViewShell = SfxViewShell::Current();
133 if( pViewShell )
134 mpView = pViewShell->GetDrawView();
135 DBG_ASSERT( mpView, "no valid view (!)" );
138 SvxBitmapTabPage::~SvxBitmapTabPage()
140 m_xBitmapLBWin.reset();
141 m_xBitmapLB.reset();
142 m_xCtlBitmapPreview.reset();
145 void SvxBitmapTabPage::Construct()
147 m_xBitmapLB->FillPresetListBox( *m_pBitmapList );
150 void SvxBitmapTabPage::ActivatePage( const SfxItemSet& rSet )
152 XFillBitmapItem aItem( rSet.Get(XATTR_FILLBITMAP) );
154 sal_Int32 nPos( 0 );
155 if ( !aItem.isPattern() )
157 nPos = SearchBitmapList( aItem.GetGraphicObject() );
158 if ( nPos == LISTBOX_ENTRY_NOTFOUND )
159 return;
161 else
163 m_xBitmapWidth->set_value( 100, FieldUnit::NONE );
164 m_xBitmapHeight->set_value( 100, FieldUnit::NONE );
165 const_cast<SfxItemSet&>(rSet).Put( XFillBmpSizeXItem( GetCoreValue( *m_xBitmapWidth, mePoolUnit ) ) );
166 const_cast<SfxItemSet&>(rSet).Put( XFillBmpSizeYItem( GetCoreValue( *m_xBitmapHeight, mePoolUnit ) ) );
169 sal_uInt16 nId = m_xBitmapLB->GetItemId( static_cast<size_t>( nPos ) );
170 m_xBitmapLB->SelectItem( nId );
173 DeactivateRC SvxBitmapTabPage::DeactivatePage( SfxItemSet* _pSet )
175 if( _pSet )
176 FillItemSet( _pSet );
178 return DeactivateRC::LeavePage;
182 bool SvxBitmapTabPage::FillItemSet( SfxItemSet* rAttrs )
184 rAttrs->Put(XFillStyleItem(drawing::FillStyle_BITMAP));
185 size_t nPos = m_xBitmapLB->GetSelectItemPos();
186 if(VALUESET_ITEM_NOTFOUND != nPos)
188 const XBitmapEntry* pXBitmapEntry = m_pBitmapList->GetBitmap(nPos);
189 const OUString aString(m_xBitmapLB->GetItemText( m_xBitmapLB->GetSelectedItemId() ));
190 rAttrs->Put(XFillBitmapItem(aString, pXBitmapEntry->GetGraphicObject()));
193 BitmapStyle eStylePos = static_cast<BitmapStyle>(m_xBitmapStyleLB->get_active());
194 bool bIsStretched( eStylePos == STRETCHED );
195 bool bIsTiled( eStylePos == TILED );
197 rAttrs->Put( XFillBmpTileItem(bIsTiled) );
198 rAttrs->Put( XFillBmpStretchItem(bIsStretched) );
200 if(!bIsStretched)
202 Size aSetBitmapSize;
203 switch(eStylePos)
205 case CUSTOM:
206 case TILED:
208 sal_Int64 nWidthPercent = m_xBitmapWidth->get_value(FieldUnit::NONE);
209 sal_Int64 nHeightPercent = m_xBitmapHeight->get_value(FieldUnit::NONE);
210 if (m_xTsbScale->get_sensitive() && m_xTsbScale->get_state() == TRISTATE_TRUE)
212 aSetBitmapSize.setWidth( -nWidthPercent );
213 aSetBitmapSize.setHeight( -nHeightPercent );
215 else if (!m_bLogicalSize)
217 aSetBitmapSize.setWidth( GetCoreValue(*m_xBitmapWidth, mePoolUnit) );
218 aSetBitmapSize.setHeight( GetCoreValue(*m_xBitmapHeight, mePoolUnit) );
220 else
222 rAttrs->Put( XFillBmpSizeLogItem(true) );
223 aSetBitmapSize.setWidth( 0 );
224 aSetBitmapSize.setHeight( 0 );
227 break;
229 default:
230 break;
233 rAttrs->Put( XFillBmpSizeXItem( aSetBitmapSize.Width() ) );
234 rAttrs->Put( XFillBmpSizeYItem( aSetBitmapSize.Height() ) );
237 if (m_xPositionLB->get_sensitive())
238 rAttrs->Put( XFillBmpPosItem( static_cast<RectPoint>( m_xPositionLB->get_active() ) ) );
239 if (m_xPositionOffX->get_sensitive())
240 rAttrs->Put( XFillBmpPosOffsetXItem(m_xPositionOffX->get_value(FieldUnit::PERCENT)));
241 if (m_xPositionOffY->get_sensitive())
242 rAttrs->Put( XFillBmpPosOffsetYItem(m_xPositionOffY->get_value(FieldUnit::PERCENT)));
243 if (m_xTileOffBox->get_sensitive())
245 TileOffset eValue = static_cast<TileOffset>(m_xTileOffLB->get_active());
246 sal_uInt16 nOffsetValue = static_cast<sal_uInt16>(m_xTileOffset->get_value(FieldUnit::PERCENT));
247 sal_uInt16 nRowOff = (eValue == ROW) ? nOffsetValue : 0;
248 sal_uInt16 nColOff = (eValue == COLUMN) ? nOffsetValue : 0;
249 rAttrs->Put( XFillBmpTileOffsetXItem(nRowOff) );
250 rAttrs->Put( XFillBmpTileOffsetYItem(nColOff) );
252 return true;
256 void SvxBitmapTabPage::Reset( const SfxItemSet* rAttrs )
258 double transfWidth = 0.0;
259 double transfHeight = 0.0;
260 double fUIScale = 1.0;
261 if (mpView)
263 fUIScale = ( mpView->GetModel() ? double(mpView->GetModel()->GetUIScale()) : 1.0);
266 if (mpView->AreObjectsMarked())
268 SfxItemSet rGeoAttr(mpView->GetGeoAttrFromMarked());
269 transfWidth = static_cast<double>(GetItem( rGeoAttr, SID_ATTR_TRANSFORM_WIDTH )->GetValue());
270 transfHeight= static_cast<double>(GetItem( rGeoAttr, SID_ATTR_TRANSFORM_HEIGHT )->GetValue());
273 m_fObjectWidth = std::max( transfWidth, 1.0 );
274 m_fObjectHeight = std::max( transfHeight, 1.0 );
275 double fTmpWidth((OutputDevice::LogicToLogic(static_cast<sal_Int32>(m_fObjectWidth), mePoolUnit, MapUnit::Map100thMM )) / fUIScale);
276 m_fObjectWidth = fTmpWidth;
278 double fTmpHeight((OutputDevice::LogicToLogic(static_cast<sal_Int32>(m_fObjectHeight), mePoolUnit, MapUnit::Map100thMM )) / fUIScale);
279 m_fObjectHeight = fTmpHeight;
281 XFillBitmapItem aItem( rAttrs->Get(XATTR_FILLBITMAP) );
283 if(!aItem.isPattern())
285 m_rXFSet.Put( aItem );
286 m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
287 m_aCtlBitmapPreview.Invalidate();
289 else
290 m_xCtlBitmapPreview->set_sensitive(false);
292 std::unique_ptr<GraphicObject> pGraphicObject;
293 pGraphicObject.reset( new GraphicObject(aItem.GetGraphicObject()) );
295 BitmapEx aBmpEx(pGraphicObject->GetGraphic().GetBitmapEx());
296 Size aTempBitmapSize = aBmpEx.GetSizePixel();
297 rBitmapSize = Application::GetDefaultDevice()->PixelToLogic(aTempBitmapSize, MapMode(MapUnit::Map100thMM));
298 CalculateBitmapPresetSize();
300 bool bTiled = false; bool bStretched = false;
301 if(rAttrs->GetItemState( XATTR_FILLBMP_TILE ) != SfxItemState::DONTCARE)
302 bTiled = rAttrs->Get( XATTR_FILLBMP_TILE ).GetValue();
303 if(rAttrs->GetItemState( XATTR_FILLBMP_STRETCH ) != SfxItemState::DONTCARE)
304 bStretched = rAttrs->Get( XATTR_FILLBMP_STRETCH ).GetValue();
306 if (bTiled)
307 m_xBitmapStyleLB->set_active(static_cast<sal_Int32>(TILED));
308 else if (bStretched)
309 m_xBitmapStyleLB->set_active(static_cast<sal_Int32>(STRETCHED));
310 else
311 m_xBitmapStyleLB->set_active(static_cast<sal_Int32>(CUSTOM));
313 long nWidth = 0;
314 long nHeight = 0;
316 if(rAttrs->GetItemState(XATTR_FILLBMP_SIZELOG) != SfxItemState::DONTCARE)
318 if (rAttrs->Get( XATTR_FILLBMP_SIZELOG ).GetValue())
320 m_xTsbScale->set_state(TRISTATE_FALSE);
321 m_bLogicalSize = true;
323 else
325 m_xTsbScale->set_state(TRISTATE_TRUE);
326 m_bLogicalSize = false;
329 else
330 m_xTsbScale->set_state(TRISTATE_INDET);
332 TriState eRelative = TRISTATE_FALSE;
333 if(rAttrs->GetItemState(XATTR_FILLBMP_SIZEX) != SfxItemState::DONTCARE)
335 nWidth = static_cast<const XFillBmpSizeXItem&>( rAttrs->Get( XATTR_FILLBMP_SIZEX ) ).GetValue();
336 if(nWidth == 0)
337 nWidth = rBitmapSize.Width();
338 else if(nWidth < 0)
340 eRelative = TRISTATE_TRUE;
341 nWidth = std::abs(nWidth);
345 if(rAttrs->GetItemState( XATTR_FILLBMP_SIZEY ) != SfxItemState::DONTCARE)
347 nHeight = rAttrs->Get( XATTR_FILLBMP_SIZEY ).GetValue();
348 if(nHeight == 0)
349 nHeight = rBitmapSize.Height();
350 else if(nHeight < 0)
352 eRelative = TRISTATE_TRUE;
353 nHeight = std::abs(nHeight);
356 m_xTsbScale->set_state(eRelative);
357 ClickScaleHdl(*m_xTsbScale);
360 if(rBitmapSize.Width() > 0 && rBitmapSize.Height() > 0)
362 if (eRelative == TRISTATE_TRUE)
364 m_xBitmapWidth->set_value(nWidth, FieldUnit::NONE);
365 m_xBitmapHeight->set_value(nHeight, FieldUnit::NONE);
367 else
369 SetMetricValue(*m_xBitmapWidth, nWidth, mePoolUnit);
370 SetMetricValue(*m_xBitmapHeight, nHeight, mePoolUnit);
374 if( rAttrs->GetItemState( XATTR_FILLBMP_POS ) != SfxItemState::DONTCARE )
376 RectPoint eValue = rAttrs->Get( XATTR_FILLBMP_POS ).GetValue();
377 m_xPositionLB->set_active( static_cast< sal_Int32 >(eValue) );
380 if( rAttrs->GetItemState( XATTR_FILLBMP_POSOFFSETX ) != SfxItemState::DONTCARE )
382 sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_POSOFFSETX ).GetValue();
383 m_xPositionOffX->set_value(nValue, FieldUnit::PERCENT);
385 else
386 m_xPositionOffX->set_text("");
388 if( rAttrs->GetItemState( XATTR_FILLBMP_POSOFFSETY ) != SfxItemState::DONTCARE )
390 sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_POSOFFSETY ).GetValue();
391 m_xPositionOffY->set_value(nValue, FieldUnit::PERCENT);
393 else
394 m_xPositionOffY->set_text("");
396 if( rAttrs->GetItemState( XATTR_FILLBMP_TILEOFFSETX ) != SfxItemState::DONTCARE)
398 sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_TILEOFFSETX ).GetValue();
399 if(nValue > 0)
401 m_xTileOffLB->set_active(static_cast<sal_Int32>(ROW));
402 m_xTileOffset->set_value(nValue, FieldUnit::PERCENT);
406 if( rAttrs->GetItemState( XATTR_FILLBMP_TILEOFFSETY ) != SfxItemState::DONTCARE )
408 sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_TILEOFFSETY ).GetValue();
409 if(nValue > 0)
411 m_xTileOffLB->set_active(static_cast<sal_Int32>(COLUMN));
412 m_xTileOffset->set_value(nValue, FieldUnit::PERCENT);
416 ClickBitmapHdl_Impl();
419 std::unique_ptr<SfxTabPage> SvxBitmapTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrs)
421 return std::make_unique<SvxBitmapTabPage>(pPage, pController, *rAttrs);
424 void SvxBitmapTabPage::ClickBitmapHdl_Impl()
426 m_xBitmapLBWin->set_sensitive(true);
427 m_xCtlBitmapPreview->set_sensitive(true);
429 ModifyBitmapHdl(m_xBitmapLB.get());
432 void SvxBitmapTabPage::CalculateBitmapPresetSize()
434 if(rBitmapSize.Width() > 0 && rBitmapSize.Height() > 0)
436 long nObjectWidth = static_cast<long>(m_fObjectWidth);
437 long nObjectHeight = static_cast<long>(m_fObjectHeight);
439 if(std::abs(rBitmapSize.Width() - nObjectWidth) < std::abs(rBitmapSize.Height() - nObjectHeight))
441 rFilledSize.setWidth( nObjectWidth );
442 rFilledSize.setHeight( rBitmapSize.Height()*nObjectWidth/rBitmapSize.Width() );
443 rZoomedSize.setWidth( rBitmapSize.Width()*nObjectHeight/rBitmapSize.Height() );
444 rZoomedSize.setHeight( nObjectHeight );
446 else
448 rFilledSize.setWidth( rBitmapSize.Width()*nObjectHeight/rBitmapSize.Height() );
449 rFilledSize.setHeight( nObjectHeight );
450 rZoomedSize.setWidth( nObjectWidth );
451 rZoomedSize.setHeight( rBitmapSize.Height()*nObjectWidth/rBitmapSize.Width() );
456 IMPL_LINK_NOARG(SvxBitmapTabPage, ModifyBitmapHdl, SvtValueSet*, void)
458 std::unique_ptr<GraphicObject> pGraphicObject;
459 size_t nPos = m_xBitmapLB->GetSelectItemPos();
461 if( nPos != VALUESET_ITEM_NOTFOUND )
463 pGraphicObject.reset(new GraphicObject(m_pBitmapList->GetBitmap( static_cast<sal_uInt16>(nPos) )->GetGraphicObject()));
465 else
467 const SfxPoolItem* pPoolItem = nullptr;
469 if(SfxItemState::SET == m_rOutAttrs.GetItemState(GetWhich(XATTR_FILLSTYLE), true, &pPoolItem))
471 const drawing::FillStyle eXFS(static_cast<const XFillStyleItem*>(pPoolItem)->GetValue());
473 if((drawing::FillStyle_BITMAP == eXFS) && (SfxItemState::SET == m_rOutAttrs.GetItemState(GetWhich(XATTR_FILLBITMAP), true, &pPoolItem)))
475 pGraphicObject.reset(new GraphicObject(static_cast<const XFillBitmapItem*>(pPoolItem)->GetGraphicObject()));
479 if(!pGraphicObject)
481 sal_uInt16 nId = m_xBitmapLB->GetItemId(0);
482 m_xBitmapLB->SelectItem(nId);
484 if(0 != nId)
486 pGraphicObject.reset(new GraphicObject(m_pBitmapList->GetBitmap(0)->GetGraphicObject()));
491 if(pGraphicObject)
493 BitmapEx aBmpEx(pGraphicObject->GetGraphic().GetBitmapEx());
494 Size aTempBitmapSize = aBmpEx.GetSizePixel();
495 const double fUIScale = ( (mpView && mpView->GetModel()) ? double(mpView->GetModel()->GetUIScale()) : 1.0);
497 rBitmapSize.setWidth( (OutputDevice::LogicToLogic(static_cast<sal_Int32>(aTempBitmapSize.Width()),MapUnit::MapPixel, MapUnit::Map100thMM )) / fUIScale );
498 rBitmapSize.setHeight( (OutputDevice::LogicToLogic(static_cast<sal_Int32>(aTempBitmapSize.Height()),MapUnit::MapPixel, MapUnit::Map100thMM )) / fUIScale );
499 CalculateBitmapPresetSize();
500 ModifyBitmapStyleHdl( *m_xBitmapStyleLB );
501 ModifyBitmapPositionHdl( *m_xPositionLB );
503 m_rXFSet.ClearItem(XATTR_FILLBITMAP);
504 m_rXFSet.Put(XFillStyleItem(drawing::FillStyle_BITMAP));
505 m_rXFSet.Put(XFillBitmapItem(OUString(), *pGraphicObject));
507 m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
508 m_aCtlBitmapPreview.Invalidate();
510 else
512 SAL_WARN("cui.tabpages", "SvxBitmapTabPage::ModifyBitmapHdl(): null pGraphicObject");
517 IMPL_LINK_NOARG(SvxBitmapTabPage, ClickRenameHdl, SvxPresetListBox*, void)
519 sal_uInt16 nId = m_xBitmapLB->GetSelectedItemId();
520 size_t nPos = m_xBitmapLB->GetSelectItemPos();
522 if( nPos != VALUESET_ITEM_NOTFOUND )
524 OUString aDesc( CuiResId( RID_SVXSTR_DESC_NEW_BITMAP ) );
525 OUString aName( m_pBitmapList->GetBitmap( nPos )->GetName() );
527 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
528 ScopedVclPtr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog(GetFrameWeld(), aName, aDesc));
530 bool bLoop = true;
531 while( bLoop && pDlg->Execute() == RET_OK )
533 pDlg->GetName( aName );
534 sal_Int32 nBitmapPos = SearchBitmapList( aName );
535 bool bValidBitmapName = (nBitmapPos == static_cast<sal_Int32>(nPos) ) || (nBitmapPos == LISTBOX_ENTRY_NOTFOUND);
537 if(bValidBitmapName)
539 bLoop = false;
540 m_pBitmapList->GetBitmap(nPos)->SetName(aName);
542 m_xBitmapLB->SetItemText(nId, aName);
543 m_xBitmapLB->SelectItem( nId );
545 *m_pnBitmapListState |= ChangeType::MODIFIED;
547 else
549 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
550 std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
551 xBox->run();
557 IMPL_LINK_NOARG(SvxBitmapTabPage, ClickDeleteHdl, SvxPresetListBox*, void)
559 sal_uInt16 nId = m_xBitmapLB->GetSelectedItemId();
560 size_t nPos = m_xBitmapLB->GetSelectItemPos();
562 if( nPos != VALUESET_ITEM_NOTFOUND )
564 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/querydeletebitmapdialog.ui"));
565 std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog("AskDelBitmapDialog"));
567 if (xQueryBox->run() == RET_YES)
569 m_pBitmapList->Remove( static_cast<sal_uInt16>(nPos) );
570 m_xBitmapLB->RemoveItem( nId );
571 nId = m_xBitmapLB->GetItemId(0);
572 m_xBitmapLB->SelectItem( nId );
574 m_aCtlBitmapPreview.Invalidate();
575 ModifyBitmapHdl(m_xBitmapLB.get());
576 *m_pnBitmapListState |= ChangeType::MODIFIED;
581 IMPL_LINK_NOARG( SvxBitmapTabPage, ModifyBitmapSizeHdl, weld::MetricSpinButton&, void )
583 m_bLogicalSize = false;
584 if (m_xTsbScale->get_state() != TRISTATE_TRUE && static_cast<BitmapStyle>(m_xBitmapStyleLB->get_active()) != TILED)
586 sal_Int64 nWidthPercent = m_xBitmapWidth->denormalize(m_xBitmapWidth->get_value(FieldUnit::NONE));
587 sal_Int64 nHeightPercent = m_xBitmapHeight->denormalize(m_xBitmapHeight->get_value(FieldUnit::NONE));
588 if (nWidthPercent == 100 && nHeightPercent == 100)
589 m_xBitmapStyleLB->set_active(static_cast<sal_Int32>(CUSTOM));
591 ModifyBitmapStyleHdl(*m_xBitmapStyleLB);
593 m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
594 m_aCtlBitmapPreview.Invalidate();
597 IMPL_LINK_NOARG( SvxBitmapTabPage, ClickScaleHdl, weld::Button&, void )
599 if (m_xTsbScale->get_state() == TRISTATE_TRUE)
601 m_xBitmapWidth->set_digits( 0 );
602 m_xBitmapWidth->set_unit(FieldUnit::PERCENT);
603 m_xBitmapWidth->set_value(100, FieldUnit::NONE);
604 m_xBitmapWidth->set_range(0, 100, FieldUnit::NONE);
606 m_xBitmapHeight->set_digits( 0 );
607 m_xBitmapHeight->set_unit(FieldUnit::PERCENT);
608 m_xBitmapHeight->set_value(100, FieldUnit::NONE);
609 m_xBitmapHeight->set_range(0, 100, FieldUnit::NONE);
611 else
613 m_xBitmapWidth->set_digits( 2 );
614 m_xBitmapWidth->set_unit(meFieldUnit);
615 m_xBitmapWidth->set_value(100, FieldUnit::NONE);
616 m_xBitmapWidth->set_range(0, 999900, FieldUnit::NONE);
618 m_xBitmapHeight->set_digits( 2 );
619 m_xBitmapHeight->set_unit(meFieldUnit);
620 m_xBitmapHeight->set_value(100, FieldUnit::NONE);
621 m_xBitmapHeight->set_range(0, 999900, FieldUnit::NONE);
624 ModifyBitmapStyleHdl( *m_xBitmapStyleLB );
627 IMPL_LINK_NOARG( SvxBitmapTabPage, ModifyBitmapStyleHdl, weld::ComboBox&, void )
629 BitmapStyle eStylePos = static_cast<BitmapStyle>(m_xBitmapStyleLB->get_active());
630 bool bIsStretched( eStylePos == STRETCHED );
631 bool bIsTiled( eStylePos == TILED );
633 m_xSizeBox->set_sensitive( !bIsStretched );
634 m_xPositionBox->set_sensitive( !bIsStretched );
635 m_xPositionOffBox->set_sensitive( bIsTiled );
636 m_xTileOffBox->set_sensitive( bIsTiled );
638 m_rXFSet.Put( XFillBmpTileItem( bIsTiled ) );
639 m_rXFSet.Put( XFillBmpStretchItem( bIsStretched ) );
641 if(!bIsStretched)
643 Size aSetBitmapSize;
644 switch(eStylePos)
646 case CUSTOM:
647 case TILED:
649 if (m_xTsbScale->get_sensitive() && m_xTsbScale->get_state() == TRISTATE_TRUE)
651 aSetBitmapSize.setWidth(-m_xBitmapWidth->get_value(FieldUnit::NONE));
652 aSetBitmapSize.setHeight(-m_xBitmapHeight->get_value(FieldUnit::NONE));
654 else
656 aSetBitmapSize.setWidth( GetCoreValue( *m_xBitmapWidth, mePoolUnit ) );
657 aSetBitmapSize.setHeight( GetCoreValue( *m_xBitmapHeight, mePoolUnit ) );
660 break;
661 default:
662 break;
665 m_rXFSet.Put( XFillBmpSizeXItem( aSetBitmapSize.Width() ) );
666 m_rXFSet.Put( XFillBmpSizeYItem( aSetBitmapSize.Height() ) );
669 m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
670 m_aCtlBitmapPreview.Invalidate();
673 IMPL_LINK_NOARG(SvxBitmapTabPage, ModifyBitmapPositionHdl, weld::ComboBox&, void)
675 if (m_xPositionLB->get_sensitive())
676 m_rXFSet.Put( XFillBmpPosItem( static_cast< RectPoint >( m_xPositionLB->get_active() ) ) );
678 m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
679 m_aCtlBitmapPreview.Invalidate();
682 IMPL_LINK_NOARG(SvxBitmapTabPage, ModifyPositionOffsetHdl, weld::MetricSpinButton&, void)
684 if (m_xPositionOffX->get_sensitive())
685 m_rXFSet.Put( XFillBmpPosOffsetXItem( m_xPositionOffX->get_value(FieldUnit::PERCENT) ) );
687 if (m_xPositionOffY->get_sensitive())
688 m_rXFSet.Put( XFillBmpPosOffsetYItem( m_xPositionOffY->get_value(FieldUnit::PERCENT) ) );
690 m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
691 m_aCtlBitmapPreview.Invalidate();
694 IMPL_LINK_NOARG(SvxBitmapTabPage, ModifyTileOffsetHdl, weld::MetricSpinButton&, void)
696 sal_uInt16 nTileXOff = 0;
697 sal_uInt16 nTileYOff = 0;
699 if(m_xTileOffLB->get_active() == static_cast<sal_Int32>(ROW))
700 nTileXOff = m_xTileOffset->get_value(FieldUnit::PERCENT);
702 if(m_xTileOffLB->get_active() == static_cast<sal_Int32>(COLUMN))
703 nTileYOff = m_xTileOffset->get_value(FieldUnit::PERCENT);
705 m_rXFSet.Put( XFillBmpTileOffsetXItem(nTileXOff) );
706 m_rXFSet.Put( XFillBmpTileOffsetYItem(nTileYOff) );
708 m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
709 m_aCtlBitmapPreview.Invalidate();
712 IMPL_LINK_NOARG(SvxBitmapTabPage, ClickImportHdl, weld::Button&, void)
714 weld::Window* pDialogFrameWeld = GetFrameWeld();
716 SvxOpenGraphicDialog aDlg(CuiResId(RID_SVXSTR_ADD_IMAGE), pDialogFrameWeld);
717 aDlg.EnableLink(false);
718 long nCount = m_pBitmapList->Count();
720 if( !aDlg.Execute() )
722 Graphic aGraphic;
724 std::unique_ptr<weld::WaitObject> xWait(new weld::WaitObject(pDialogFrameWeld));
725 ErrCode nError = aDlg.GetGraphic( aGraphic );
726 xWait.reset();
728 if( !nError )
730 OUString aDesc(CuiResId(RID_SVXSTR_DESC_EXT_BITMAP));
732 // convert file URL to UI name
733 OUString aName;
734 INetURLObject aURL( aDlg.GetPath() );
735 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
736 ScopedVclPtr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog(
737 pDialogFrameWeld, aURL.GetLastName().getToken(0, '.'), aDesc));
738 nError = ErrCode(1);
740 while( pDlg->Execute() == RET_OK )
742 pDlg->GetName( aName );
744 bool bDifferent = true;
746 for( long i = 0; i < nCount && bDifferent; i++ )
747 if( aName == m_pBitmapList->GetBitmap( i )->GetName() )
748 bDifferent = false;
750 if( bDifferent ) {
751 nError = ERRCODE_NONE;
752 break;
755 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pDialogFrameWeld, "cui/ui/queryduplicatedialog.ui"));
756 std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
757 if (xBox->run() != RET_OK)
758 break;
761 pDlg.disposeAndClear();
763 if( !nError )
765 m_pBitmapList->Insert(std::make_unique<XBitmapEntry>(aGraphic, aName), nCount);
767 sal_Int32 nId = m_xBitmapLB->GetItemId( nCount - 1 );
768 BitmapEx aBitmap = m_pBitmapList->GetBitmapForPreview( nCount, m_xBitmapLB->GetIconSize() );
770 m_xBitmapLB->InsertItem( nId + 1, Image(aBitmap), aName );
771 m_xBitmapLB->SelectItem( nId + 1 );
772 *m_pnBitmapListState |= ChangeType::MODIFIED;
774 ModifyBitmapHdl(m_xBitmapLB.get());
777 else
779 // graphic couldn't be loaded
780 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pDialogFrameWeld, "cui/ui/querynoloadedfiledialog.ui"));
781 std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("NoLoadedFileDialog"));
782 xBox->run();
787 sal_Int32 SvxBitmapTabPage::SearchBitmapList(const GraphicObject& rGraphicObject)
789 long nCount = m_pBitmapList->Count();
790 sal_Int32 nPos = LISTBOX_ENTRY_NOTFOUND;
792 for(long i = 0;i < nCount;i++)
794 if(rGraphicObject.GetUniqueID() == m_pBitmapList->GetBitmap( i )->GetGraphicObject().GetUniqueID())
796 nPos = i;
797 break;
800 return nPos;
803 sal_Int32 SvxBitmapTabPage::SearchBitmapList(const OUString& rBitmapName)
805 long nCount = m_pBitmapList->Count();
806 bool bValidBitmapName = true;
807 sal_Int32 nPos = LISTBOX_ENTRY_NOTFOUND;
809 for(long i = 0;i < nCount && bValidBitmapName;i++)
811 if(rBitmapName == m_pBitmapList->GetBitmap( i )->GetName())
813 nPos = i;
814 bValidBitmapName = false;
817 return nPos;
820 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */