LibreOffice Module cui (master)  1
tpbitmap.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 <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/image.hxx>
41 #include <vcl/svapp.hxx>
42 #include <vcl/weld.hxx>
43 #include <svx/svxdlg.hxx>
44 #include <sfx2/viewsh.hxx>
45 #include <sfx2/dialoghelper.hxx>
46 #include <sal/log.hxx>
47 #include <comphelper/lok.hxx>
48 #include <svtools/unitconv.hxx>
49 
50 using namespace com::sun::star;
51 
52 namespace {
53 
55 {
56  CUSTOM,
57  TILED,
58  STRETCHED
59 };
60 
62 {
63  ROW,
64  COLUMN
65 };
66 
67 }
68 
70  : SfxTabPage(pPage, pController, "cui/ui/imagetabpage.ui", "ImageTabPage", &rInAttrs)
71  , m_rOutAttrs(rInAttrs)
72  , m_pnBitmapListState(nullptr)
73  , m_fObjectWidth(0.0)
74  , m_fObjectHeight(0.0)
75  , m_bLogicalSize(false)
76  , m_aXFillAttr(rInAttrs.GetPool())
77  , m_rXFSet(m_aXFillAttr.GetItemSet())
78  , mpView(nullptr)
79  , m_xBitmapLB(new SvxPresetListBox(m_xBuilder->weld_scrolled_window("imagewin", true)))
80  , m_xBitmapStyleLB(m_xBuilder->weld_combo_box("imagestyle"))
81  , m_xSizeBox(m_xBuilder->weld_container("sizebox"))
82  , m_xTsbScale(m_xBuilder->weld_check_button("scaletsb"))
83  , m_xBitmapWidth(m_xBuilder->weld_metric_spin_button("width", FieldUnit::PERCENT))
84  , m_xBitmapHeight(m_xBuilder->weld_metric_spin_button("height", FieldUnit::PERCENT))
85  , m_xPositionBox(m_xBuilder->weld_container("posbox"))
86  , m_xPositionLB(m_xBuilder->weld_combo_box("positionlb"))
87  , m_xPositionOffBox(m_xBuilder->weld_container("posoffbox"))
88  , m_xPositionOffX(m_xBuilder->weld_metric_spin_button("posoffx", FieldUnit::PERCENT))
89  , m_xPositionOffY(m_xBuilder->weld_metric_spin_button("posoffy", FieldUnit::PERCENT))
90  , m_xTileOffBox(m_xBuilder->weld_container("tileoffbox"))
91  , m_xTileOffLB(m_xBuilder->weld_combo_box("tileofflb"))
92  , m_xTileOffset(m_xBuilder->weld_metric_spin_button("tileoffmtr", FieldUnit::PERCENT))
93  , m_xBtnImport(m_xBuilder->weld_button("BTN_IMPORT"))
94  , m_xCtlBitmapPreview(new weld::CustomWeld(*m_xBuilder, "CTL_IMAGE_PREVIEW", m_aCtlBitmapPreview))
95  , m_xBitmapLBWin(new weld::CustomWeld(*m_xBuilder, "IMAGE", *m_xBitmapLB))
96 {
97  // setting the output device
98  m_rXFSet.Put( XFillStyleItem(drawing::FillStyle_BITMAP) );
99  m_rXFSet.Put( XFillBitmapItem(OUString(), Graphic()) );
101 
102  m_xBitmapLB->SetSelectHdl( LINK(this, SvxBitmapTabPage, ModifyBitmapHdl) );
103  m_xBitmapLB->SetRenameHdl( LINK(this, SvxBitmapTabPage, ClickRenameHdl) );
104  m_xBitmapLB->SetDeleteHdl( LINK(this, SvxBitmapTabPage, ClickDeleteHdl) );
105  m_xBitmapStyleLB->connect_changed( LINK(this, SvxBitmapTabPage, ModifyBitmapStyleHdl) );
106  Link<weld::MetricSpinButton&, void> aLink1( LINK(this, SvxBitmapTabPage, ModifyBitmapSizeHdl) );
107  m_xBitmapWidth->connect_value_changed( aLink1 );
108  m_xBitmapHeight->connect_value_changed( aLink1 );
109  m_xTsbScale->connect_toggled(LINK(this, SvxBitmapTabPage, ClickScaleHdl));
110  m_xPositionLB->connect_changed( LINK( this, SvxBitmapTabPage, ModifyBitmapPositionHdl ) );
111  Link<weld::MetricSpinButton&, void> aLink( LINK( this, SvxBitmapTabPage, ModifyPositionOffsetHdl ) );
112  m_xPositionOffX->connect_value_changed(aLink);
113  m_xPositionOffY->connect_value_changed(aLink);
114  m_xTileOffset->connect_value_changed( LINK( this, SvxBitmapTabPage, ModifyTileOffsetHdl ) );
115  m_xBtnImport->connect_clicked( LINK(this, SvxBitmapTabPage, ClickImportHdl) );
117  m_xBtnImport->hide();
118 
119  // Calculate size of display boxes
120  Size aSize = getDrawPreviewOptimalSize(m_aCtlBitmapPreview.GetDrawingArea()->get_ref_device());
121  m_xBitmapLB->set_size_request(aSize.Width(), aSize.Height());
122  m_xCtlBitmapPreview->set_size_request(aSize.Width(), aSize.Height());
123 
124  SfxItemPool* pPool = m_rXFSet.GetPool();
126  meFieldUnit = GetModuleFieldUnit( rInAttrs );
129 
131 
132  SfxViewShell* pViewShell = SfxViewShell::Current();
133  if( pViewShell )
134  mpView = pViewShell->GetDrawView();
135  DBG_ASSERT( mpView, "no valid view (!)" );
136 }
137 
139 {
140  m_xBitmapLBWin.reset();
141  m_xBitmapLB.reset();
142  m_xCtlBitmapPreview.reset();
143 }
144 
146 {
147  m_xBitmapLB->FillPresetListBox( *m_pBitmapList );
148 }
149 
151 {
152  XFillBitmapItem aItem( rSet.Get(XATTR_FILLBITMAP) );
153 
154  sal_Int32 nPos( 0 );
155  if ( !aItem.isPattern() )
156  {
157  nPos = SearchBitmapList( aItem.GetGraphicObject() );
158  if (nPos == -1)
159  return;
160  }
161  else
162  {
163  m_xBitmapWidth->set_value( 100, FieldUnit::NONE );
164  m_xBitmapHeight->set_value( 100, FieldUnit::NONE );
167  }
168 
169  sal_uInt16 nId = m_xBitmapLB->GetItemId( static_cast<size_t>( nPos ) );
170  m_xBitmapLB->SelectItem( nId );
171 }
172 
174 {
175  if( _pSet )
176  FillItemSet( _pSet );
177 
178  return DeactivateRC::LeavePage;
179 }
180 
181 
183 {
184  rAttrs->Put(XFillStyleItem(drawing::FillStyle_BITMAP));
185  size_t nPos = m_xBitmapLB->GetSelectItemPos();
186  if(VALUESET_ITEM_NOTFOUND != nPos)
187  {
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()));
191  }
192 
193  BitmapStyle eStylePos = static_cast<BitmapStyle>(m_xBitmapStyleLB->get_active());
194  bool bIsStretched( eStylePos == STRETCHED );
195  bool bIsTiled( eStylePos == TILED );
196 
197  rAttrs->Put( XFillBmpTileItem(bIsTiled) );
198  rAttrs->Put( XFillBmpStretchItem(bIsStretched) );
199 
200  if(!bIsStretched)
201  {
202  Size aSetBitmapSize;
203  switch(eStylePos)
204  {
205  case CUSTOM:
206  case TILED:
207  {
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)
211  {
212  aSetBitmapSize.setWidth( -nWidthPercent );
213  aSetBitmapSize.setHeight( -nHeightPercent );
214  }
215  else if (!m_bLogicalSize)
216  {
217  aSetBitmapSize.setWidth( GetCoreValue(*m_xBitmapWidth, mePoolUnit) );
218  aSetBitmapSize.setHeight( GetCoreValue(*m_xBitmapHeight, mePoolUnit) );
219  }
220  else
221  {
222  rAttrs->Put( XFillBmpSizeLogItem(true) );
223  aSetBitmapSize.setWidth( 0 );
224  aSetBitmapSize.setHeight( 0 );
225  }
226 
227  break;
228  }
229  default:
230  break;
231  }
232 
233  rAttrs->Put( XFillBmpSizeXItem( aSetBitmapSize.Width() ) );
234  rAttrs->Put( XFillBmpSizeYItem( aSetBitmapSize.Height() ) );
235  }
236 
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())
244  {
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) );
251  }
252  return true;
253 }
254 
255 
256 void SvxBitmapTabPage::Reset( const SfxItemSet* rAttrs )
257 {
258  double transfWidth = 0.0;
259  double transfHeight = 0.0;
260  double fUIScale = 1.0;
261  if (mpView)
262  {
263  fUIScale = ( mpView->GetModel() ? double(mpView->GetModel()->GetUIScale()) : 1.0);
264 
265 
266  if (mpView->AreObjectsMarked())
267  {
269  transfWidth = static_cast<double>(GetItem( rGeoAttr, SID_ATTR_TRANSFORM_WIDTH )->GetValue());
270  transfHeight= static_cast<double>(GetItem( rGeoAttr, SID_ATTR_TRANSFORM_HEIGHT )->GetValue());
271  }
272  }
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;
277 
278  double fTmpHeight((OutputDevice::LogicToLogic(static_cast<sal_Int32>(m_fObjectHeight), mePoolUnit, MapUnit::Map100thMM )) / fUIScale);
279  m_fObjectHeight = fTmpHeight;
280 
281  XFillBitmapItem aItem( rAttrs->Get(XATTR_FILLBITMAP) );
282 
283  if(!aItem.isPattern())
284  {
285  m_rXFSet.Put( aItem );
287  m_aCtlBitmapPreview.Invalidate();
288  }
289  else
290  m_xCtlBitmapPreview->set_sensitive(false);
291 
292  std::unique_ptr<GraphicObject> pGraphicObject;
293  pGraphicObject.reset( new GraphicObject(aItem.GetGraphicObject()) );
294 
295  BitmapEx aBmpEx(pGraphicObject->GetGraphic().GetBitmapEx());
296  Size aTempBitmapSize = aBmpEx.GetSizePixel();
297  rBitmapSize = Application::GetDefaultDevice()->PixelToLogic(aTempBitmapSize, MapMode(MapUnit::Map100thMM));
299 
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();
305 
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));
312 
313  tools::Long nWidth = 0;
314  tools::Long nHeight = 0;
315 
316  if(rAttrs->GetItemState(XATTR_FILLBMP_SIZELOG) != SfxItemState::DONTCARE)
317  {
318  if (rAttrs->Get( XATTR_FILLBMP_SIZELOG ).GetValue())
319  {
320  m_xTsbScale->set_state(TRISTATE_FALSE);
321  m_bLogicalSize = true;
322  }
323  else
324  {
325  m_xTsbScale->set_state(TRISTATE_TRUE);
326  m_bLogicalSize = false;
327  }
328  }
329  else
330  m_xTsbScale->set_state(TRISTATE_INDET);
331 
332  TriState eRelative = TRISTATE_FALSE;
333  if(rAttrs->GetItemState(XATTR_FILLBMP_SIZEX) != SfxItemState::DONTCARE)
334  {
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)
339  {
340  eRelative = TRISTATE_TRUE;
341  nWidth = std::abs(nWidth);
342  }
343  }
344 
345  if(rAttrs->GetItemState( XATTR_FILLBMP_SIZEY ) != SfxItemState::DONTCARE)
346  {
347  nHeight = rAttrs->Get( XATTR_FILLBMP_SIZEY ).GetValue();
348  if(nHeight == 0)
349  nHeight = rBitmapSize.Height();
350  else if(nHeight < 0)
351  {
352  eRelative = TRISTATE_TRUE;
353  nHeight = std::abs(nHeight);
354  }
355  }
356  m_xTsbScale->set_state(eRelative);
357  ClickScaleHdl(*m_xTsbScale);
358 
359 
360  if(!rBitmapSize.IsEmpty())
361  {
362  if (eRelative == TRISTATE_TRUE)
363  {
364  m_xBitmapWidth->set_value(nWidth, FieldUnit::NONE);
365  m_xBitmapHeight->set_value(nHeight, FieldUnit::NONE);
366  }
367  else
368  {
371  }
372  }
373 
374  if( rAttrs->GetItemState( XATTR_FILLBMP_POS ) != SfxItemState::DONTCARE )
375  {
376  RectPoint eValue = rAttrs->Get( XATTR_FILLBMP_POS ).GetValue();
377  m_xPositionLB->set_active( static_cast< sal_Int32 >(eValue) );
378  }
379 
380  if( rAttrs->GetItemState( XATTR_FILLBMP_POSOFFSETX ) != SfxItemState::DONTCARE )
381  {
382  sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_POSOFFSETX ).GetValue();
383  m_xPositionOffX->set_value(nValue, FieldUnit::PERCENT);
384  }
385  else
386  m_xPositionOffX->set_text("");
387 
388  if( rAttrs->GetItemState( XATTR_FILLBMP_POSOFFSETY ) != SfxItemState::DONTCARE )
389  {
390  sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_POSOFFSETY ).GetValue();
391  m_xPositionOffY->set_value(nValue, FieldUnit::PERCENT);
392  }
393  else
394  m_xPositionOffY->set_text("");
395 
396  if( rAttrs->GetItemState( XATTR_FILLBMP_TILEOFFSETX ) != SfxItemState::DONTCARE)
397  {
398  sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_TILEOFFSETX ).GetValue();
399  if(nValue > 0)
400  {
401  m_xTileOffLB->set_active(static_cast<sal_Int32>(ROW));
402  m_xTileOffset->set_value(nValue, FieldUnit::PERCENT);
403  }
404  }
405 
406  if( rAttrs->GetItemState( XATTR_FILLBMP_TILEOFFSETY ) != SfxItemState::DONTCARE )
407  {
408  sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_TILEOFFSETY ).GetValue();
409  if(nValue > 0)
410  {
411  m_xTileOffLB->set_active(static_cast<sal_Int32>(COLUMN));
412  m_xTileOffset->set_value(nValue, FieldUnit::PERCENT);
413  }
414  }
415 
417 }
418 
419 std::unique_ptr<SfxTabPage> SvxBitmapTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrs)
420 {
421  return std::make_unique<SvxBitmapTabPage>(pPage, pController, *rAttrs);
422 }
423 
425 {
426  m_xBitmapLBWin->set_sensitive(true);
427  m_xCtlBitmapPreview->set_sensitive(true);
428 
429  ModifyBitmapHdl(m_xBitmapLB.get());
430 }
431 
433 {
434  if(rBitmapSize.IsEmpty())
435  return;
436 
437  tools::Long nObjectWidth = static_cast<tools::Long>(m_fObjectWidth);
438  tools::Long nObjectHeight = static_cast<tools::Long>(m_fObjectHeight);
439 
440  if(std::abs(rBitmapSize.Width() - nObjectWidth) < std::abs(rBitmapSize.Height() - nObjectHeight))
441  {
442  rFilledSize.setWidth( nObjectWidth );
445  rZoomedSize.setHeight( nObjectHeight );
446  }
447  else
448  {
450  rFilledSize.setHeight( nObjectHeight );
451  rZoomedSize.setWidth( nObjectWidth );
453  }
454 }
455 
456 IMPL_LINK_NOARG(SvxBitmapTabPage, ModifyBitmapHdl, ValueSet*, void)
457 {
458  std::unique_ptr<GraphicObject> pGraphicObject;
459  size_t nPos = m_xBitmapLB->GetSelectItemPos();
460 
461  if( nPos != VALUESET_ITEM_NOTFOUND )
462  {
463  pGraphicObject.reset(new GraphicObject(m_pBitmapList->GetBitmap( static_cast<sal_uInt16>(nPos) )->GetGraphicObject()));
464  }
465  else
466  {
467  if(const XFillStyleItem* pFillStyleItem = m_rOutAttrs.GetItemIfSet(GetWhich(XATTR_FILLSTYLE)))
468  {
469  const drawing::FillStyle eXFS(pFillStyleItem->GetValue());
470 
471  const XFillBitmapItem* pBitmapItem;
472  if((drawing::FillStyle_BITMAP == eXFS) && (pBitmapItem = m_rOutAttrs.GetItemIfSet(GetWhich(XATTR_FILLBITMAP))))
473  {
474  pGraphicObject.reset(new GraphicObject(pBitmapItem->GetGraphicObject()));
475  }
476  }
477 
478  if(!pGraphicObject)
479  {
480  sal_uInt16 nId = m_xBitmapLB->GetItemId(0);
481  m_xBitmapLB->SelectItem(nId);
482 
483  if(0 != nId)
484  {
485  pGraphicObject.reset(new GraphicObject(m_pBitmapList->GetBitmap(0)->GetGraphicObject()));
486  }
487  }
488  }
489 
490  if(pGraphicObject)
491  {
492  BitmapEx aBmpEx(pGraphicObject->GetGraphic().GetBitmapEx());
493  Size aTempBitmapSize = aBmpEx.GetSizePixel();
494  const double fUIScale = ( (mpView && mpView->GetModel()) ? double(mpView->GetModel()->GetUIScale()) : 1.0);
495  Size aBitmapSize100mm = o3tl::convert(aTempBitmapSize, o3tl::Length::pt, o3tl::Length::mm100);
496 
497  rBitmapSize.setWidth(aBitmapSize100mm.Width() / fUIScale);
498  rBitmapSize.setHeight(aBitmapSize100mm.Height() / fUIScale);
499  CalculateBitmapPresetSize();
500  ModifyBitmapStyleHdl( *m_xBitmapStyleLB );
501  ModifyBitmapPositionHdl( *m_xPositionLB );
502 
503  m_rXFSet.ClearItem(XATTR_FILLBITMAP);
504  m_rXFSet.Put(XFillStyleItem(drawing::FillStyle_BITMAP));
505  m_rXFSet.Put(XFillBitmapItem(OUString(), *pGraphicObject));
506 
507  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
508  m_aCtlBitmapPreview.Invalidate();
509  }
510  else
511  {
512  SAL_WARN("cui.tabpages", "SvxBitmapTabPage::ModifyBitmapHdl(): null pGraphicObject");
513  }
514 
515 }
516 
518 {
519  sal_uInt16 nId = m_xBitmapLB->GetSelectedItemId();
520  size_t nPos = m_xBitmapLB->GetSelectItemPos();
521 
522  if( nPos == VALUESET_ITEM_NOTFOUND )
523  return;
524 
525  OUString aDesc( CuiResId( RID_CUISTR_DESC_NEW_BITMAP ) );
526  OUString aName( m_pBitmapList->GetBitmap( nPos )->GetName() );
527 
529  ScopedVclPtr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog(GetFrameWeld(), aName, aDesc));
530 
531  bool bLoop = true;
532  while( bLoop && pDlg->Execute() == RET_OK )
533  {
534  pDlg->GetName( aName );
535  sal_Int32 nBitmapPos = SearchBitmapList( aName );
536  bool bValidBitmapName = (nBitmapPos == static_cast<sal_Int32>(nPos) ) || (nBitmapPos == -1);
537 
538  if(bValidBitmapName)
539  {
540  bLoop = false;
541  m_pBitmapList->GetBitmap(nPos)->SetName(aName);
542 
543  m_xBitmapLB->SetItemText(nId, aName);
544  m_xBitmapLB->SelectItem( nId );
545 
546  *m_pnBitmapListState |= ChangeType::MODIFIED;
547  }
548  else
549  {
550  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
551  std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
552  xBox->run();
553  }
554  }
555 }
556 
558 {
559  sal_uInt16 nId = m_xBitmapLB->GetSelectedItemId();
560  size_t nPos = m_xBitmapLB->GetSelectItemPos();
561 
562  if( nPos == VALUESET_ITEM_NOTFOUND )
563  return;
564 
565  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/querydeletebitmapdialog.ui"));
566  std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog("AskDelBitmapDialog"));
567 
568  if (xQueryBox->run() != RET_YES)
569  return;
570 
571  sal_uInt16 nNextId = m_xBitmapLB->GetItemId(nPos + 1);
572  if (!nNextId)
573  nNextId = m_xBitmapLB->GetItemId(nPos - 1);
574 
575  m_pBitmapList->Remove( static_cast<sal_uInt16>(nPos) );
576  m_xBitmapLB->RemoveItem( nId );
577 
578  m_xBitmapLB->SelectItem(nNextId);
579 
580  m_aCtlBitmapPreview.Invalidate();
581  ModifyBitmapHdl(m_xBitmapLB.get());
582  *m_pnBitmapListState |= ChangeType::MODIFIED;
583 }
584 
586 {
587  m_bLogicalSize = false;
588  if (m_xTsbScale->get_state() != TRISTATE_TRUE && static_cast<BitmapStyle>(m_xBitmapStyleLB->get_active()) != TILED)
589  {
590  sal_Int64 nWidthPercent = m_xBitmapWidth->denormalize(m_xBitmapWidth->get_value(FieldUnit::NONE));
591  sal_Int64 nHeightPercent = m_xBitmapHeight->denormalize(m_xBitmapHeight->get_value(FieldUnit::NONE));
592  if (nWidthPercent == 100 && nHeightPercent == 100)
593  m_xBitmapStyleLB->set_active(static_cast<sal_Int32>(CUSTOM));
594  }
595  ModifyBitmapStyleHdl(*m_xBitmapStyleLB);
596 
597  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
598  m_aCtlBitmapPreview.Invalidate();
599 }
600 
602 {
603  if (m_xTsbScale->get_state() == TRISTATE_TRUE)
604  {
605  m_xBitmapWidth->set_digits( 0 );
606  m_xBitmapWidth->set_unit(FieldUnit::PERCENT);
607  m_xBitmapWidth->set_value(100, FieldUnit::NONE);
608  m_xBitmapWidth->set_range(0, 100, FieldUnit::NONE);
609 
610  m_xBitmapHeight->set_digits( 0 );
611  m_xBitmapHeight->set_unit(FieldUnit::PERCENT);
612  m_xBitmapHeight->set_value(100, FieldUnit::NONE);
613  m_xBitmapHeight->set_range(0, 100, FieldUnit::NONE);
614  }
615  else
616  {
617  m_xBitmapWidth->set_digits( 2 );
618  m_xBitmapWidth->set_unit(meFieldUnit);
619  m_xBitmapWidth->set_value(100, FieldUnit::NONE);
620  m_xBitmapWidth->set_range(0, 999900, FieldUnit::NONE);
621 
622  m_xBitmapHeight->set_digits( 2 );
623  m_xBitmapHeight->set_unit(meFieldUnit);
624  m_xBitmapHeight->set_value(100, FieldUnit::NONE);
625  m_xBitmapHeight->set_range(0, 999900, FieldUnit::NONE);
626  }
627 
628  ModifyBitmapStyleHdl( *m_xBitmapStyleLB );
629 }
630 
631 IMPL_LINK_NOARG( SvxBitmapTabPage, ModifyBitmapStyleHdl, weld::ComboBox&, void )
632 {
633  BitmapStyle eStylePos = static_cast<BitmapStyle>(m_xBitmapStyleLB->get_active());
634  bool bIsStretched( eStylePos == STRETCHED );
635  bool bIsTiled( eStylePos == TILED );
636 
637  m_xSizeBox->set_sensitive( !bIsStretched );
638  m_xPositionBox->set_sensitive( !bIsStretched );
639  m_xPositionOffBox->set_sensitive( bIsTiled );
640  m_xTileOffBox->set_sensitive( bIsTiled );
641 
642  m_rXFSet.Put( XFillBmpTileItem( bIsTiled ) );
643  m_rXFSet.Put( XFillBmpStretchItem( bIsStretched ) );
644 
645  if(!bIsStretched)
646  {
647  Size aSetBitmapSize;
648  switch(eStylePos)
649  {
650  case CUSTOM:
651  case TILED:
652  {
653  if (m_xTsbScale->get_sensitive() && m_xTsbScale->get_state() == TRISTATE_TRUE)
654  {
655  aSetBitmapSize.setWidth(-m_xBitmapWidth->get_value(FieldUnit::NONE));
656  aSetBitmapSize.setHeight(-m_xBitmapHeight->get_value(FieldUnit::NONE));
657  }
658  else
659  {
660  aSetBitmapSize.setWidth( GetCoreValue( *m_xBitmapWidth, mePoolUnit ) );
661  aSetBitmapSize.setHeight( GetCoreValue( *m_xBitmapHeight, mePoolUnit ) );
662  }
663  }
664  break;
665  default:
666  break;
667  }
668 
669  m_rXFSet.Put( XFillBmpSizeXItem( aSetBitmapSize.Width() ) );
670  m_rXFSet.Put( XFillBmpSizeYItem( aSetBitmapSize.Height() ) );
671  }
672 
673  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
674  m_aCtlBitmapPreview.Invalidate();
675 }
676 
677 IMPL_LINK_NOARG(SvxBitmapTabPage, ModifyBitmapPositionHdl, weld::ComboBox&, void)
678 {
679  if (m_xPositionLB->get_sensitive())
680  m_rXFSet.Put( XFillBmpPosItem( static_cast< RectPoint >( m_xPositionLB->get_active() ) ) );
681 
682  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
683  m_aCtlBitmapPreview.Invalidate();
684 }
685 
686 IMPL_LINK_NOARG(SvxBitmapTabPage, ModifyPositionOffsetHdl, weld::MetricSpinButton&, void)
687 {
688  if (m_xPositionOffX->get_sensitive())
689  m_rXFSet.Put( XFillBmpPosOffsetXItem( m_xPositionOffX->get_value(FieldUnit::PERCENT) ) );
690 
691  if (m_xPositionOffY->get_sensitive())
692  m_rXFSet.Put( XFillBmpPosOffsetYItem( m_xPositionOffY->get_value(FieldUnit::PERCENT) ) );
693 
694  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
695  m_aCtlBitmapPreview.Invalidate();
696 }
697 
699 {
700  sal_uInt16 nTileXOff = 0;
701  sal_uInt16 nTileYOff = 0;
702 
703  if(m_xTileOffLB->get_active() == static_cast<sal_Int32>(ROW))
704  nTileXOff = m_xTileOffset->get_value(FieldUnit::PERCENT);
705 
706  if(m_xTileOffLB->get_active() == static_cast<sal_Int32>(COLUMN))
707  nTileYOff = m_xTileOffset->get_value(FieldUnit::PERCENT);
708 
709  m_rXFSet.Put( XFillBmpTileOffsetXItem(nTileXOff) );
710  m_rXFSet.Put( XFillBmpTileOffsetYItem(nTileYOff) );
711 
712  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
713  m_aCtlBitmapPreview.Invalidate();
714 }
715 
717 {
718  weld::Window* pDialogFrameWeld = GetFrameWeld();
719 
720  SvxOpenGraphicDialog aDlg(CuiResId(RID_CUISTR_ADD_IMAGE), pDialogFrameWeld);
721  aDlg.EnableLink(false);
722  tools::Long nCount = m_pBitmapList->Count();
723 
724  if( aDlg.Execute() )
725  return;
726 
727  Graphic aGraphic;
728 
729  std::unique_ptr<weld::WaitObject> xWait(new weld::WaitObject(pDialogFrameWeld));
730  ErrCode nError = aDlg.GetGraphic( aGraphic );
731  xWait.reset();
732 
733  if( !nError )
734  {
735  OUString aDesc(CuiResId(RID_CUISTR_DESC_EXT_BITMAP));
736 
737  // convert file URL to UI name
738  OUString aName;
739  INetURLObject aURL( aDlg.GetPath() );
741  ScopedVclPtr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog(
742  pDialogFrameWeld, aURL.GetLastName().getToken(0, '.'), aDesc));
743  nError = ErrCode(1);
744 
745  while( pDlg->Execute() == RET_OK )
746  {
747  pDlg->GetName( aName );
748 
749  bool bDifferent = true;
750 
751  for( tools::Long i = 0; i < nCount && bDifferent; i++ )
752  if( aName == m_pBitmapList->GetBitmap( i )->GetName() )
753  bDifferent = false;
754 
755  if( bDifferent ) {
756  nError = ERRCODE_NONE;
757  break;
758  }
759 
760  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pDialogFrameWeld, "cui/ui/queryduplicatedialog.ui"));
761  std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
762  if (xBox->run() != RET_OK)
763  break;
764  }
765 
766  pDlg.disposeAndClear();
767 
768  if( !nError )
769  {
770  m_pBitmapList->Insert(std::make_unique<XBitmapEntry>(aGraphic, aName), nCount);
771 
772  sal_Int32 nId = m_xBitmapLB->GetItemId( nCount - 1 );
773  BitmapEx aBitmap = m_pBitmapList->GetBitmapForPreview( nCount, m_xBitmapLB->GetIconSize() );
774 
775  m_xBitmapLB->InsertItem( nId + 1, Image(aBitmap), aName );
776  m_xBitmapLB->SelectItem( nId + 1 );
777  *m_pnBitmapListState |= ChangeType::MODIFIED;
778 
779  ModifyBitmapHdl(m_xBitmapLB.get());
780  }
781  }
782  else
783  {
784  // graphic couldn't be loaded
785  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pDialogFrameWeld, "cui/ui/querynoloadedfiledialog.ui"));
786  std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("NoLoadedFileDialog"));
787  xBox->run();
788  }
789 }
790 
791 sal_Int32 SvxBitmapTabPage::SearchBitmapList(const GraphicObject& rGraphicObject)
792 {
793  tools::Long nCount = m_pBitmapList->Count();
794  sal_Int32 nPos = -1;
795 
796  for(tools::Long i = 0;i < nCount;i++)
797  {
798  if(rGraphicObject.GetUniqueID() == m_pBitmapList->GetBitmap( i )->GetGraphicObject().GetUniqueID())
799  {
800  nPos = i;
801  break;
802  }
803  }
804  return nPos;
805 }
806 
807 sal_Int32 SvxBitmapTabPage::SearchBitmapList(std::u16string_view rBitmapName)
808 {
809  tools::Long nCount = m_pBitmapList->Count();
810  bool bValidBitmapName = true;
811  sal_Int32 nPos = -1;
812 
813  for(tools::Long i = 0;i < nCount && bValidBitmapName;i++)
814  {
815  if(rBitmapName == m_pBitmapList->GetBitmap( i )->GetName())
816  {
817  nPos = i;
818  bValidBitmapName = false;
819  }
820  }
821  return nPos;
822 }
823 
824 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetFieldUnit(weld::MetricSpinButton &rField, FieldUnit eUnit, bool bAll)
std::unique_ptr< weld::CheckButton > m_xTsbScale
Definition: cuitabarea.hxx:514
URL aURL
FieldUnit
void SetMetricValue(weld::MetricSpinButton &rField, sal_Int64 nCoreValue, MapUnit eUnit)
ErrCode GetGraphic(Graphic &) const
std::unique_ptr< weld::MetricSpinButton > m_xBitmapHeight
Definition: cuitabarea.hxx:516
constexpr TypedWhichId< XFillBmpTileOffsetYItem > XATTR_FILLBMP_TILEOFFSETY(XATTR_FILL_FIRST+15)
Size getDrawPreviewOptimalSize(const OutputDevice &rReference)
std::unique_ptr< weld::ComboBox > m_xPositionLB
Definition: cuitabarea.hxx:518
TileOffset
Definition: tpbitmap.cxx:61
void setWidth(tools::Long nWidth)
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
BitmapStyle
Definition: tpbitmap.cxx:54
std::unique_ptr< weld::MetricSpinButton > m_xTileOffset
Definition: cuitabarea.hxx:524
#define VALUESET_ITEM_NOTFOUND
constexpr TypedWhichId< SfxMetricItem > XATTR_FILLBMP_SIZEX(XATTR_FILL_FIRST+9)
bool AreObjectsMarked() const
static SvxAbstractDialogFactory * Create()
long Long
void disposeAndClear()
constexpr TypedWhichId< XFillStyleItem > XATTR_FILLSTYLE(XATTR_FILL_FIRST)
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
constexpr OUStringLiteral PERCENT(u"Percent")
sal_Int16 nId
OUString GetPath() const
TRISTATE_TRUE
XBitmapListRef m_pBitmapList
Definition: cuitabarea.hxx:494
static const SfxPoolItem * GetItem(const SfxItemSet &rSet, sal_uInt16 nSlot, bool bDeep=true)
FieldUnit GetModuleFieldUnit(const SfxItemSet &rSet)
Put
SfxItemSet GetGeoAttrFromMarked() const
static OutputDevice * GetDefaultDevice()
constexpr tools::Long Width() const
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
RET_YES
sal_Int32 SearchBitmapList(std::u16string_view rBitmapName)
Definition: tpbitmap.cxx:807
OString GetUniqueID() const
SvxBitmapTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: tpbitmap.cxx:69
int nCount
static SfxViewShell * Current()
IMPL_LINK_NOARG(SvxBitmapTabPage, ModifyBitmapHdl, ValueSet *, void)
Definition: tpbitmap.cxx:456
std::unique_ptr< weld::Container > m_xTileOffBox
Definition: cuitabarea.hxx:522
TRISTATE_INDET
std::unique_ptr< weld::CustomWeld > m_xCtlBitmapPreview
Definition: cuitabarea.hxx:526
const GraphicObject & GetGraphicObject() const
virtual tools::Long GetValue() const override
OUString CuiResId(TranslateId aKey)
Definition: cuiresmgr.cxx:23
RectPoint
virtual ~SvxBitmapTabPage() override
Definition: tpbitmap.cxx:138
bool IsEmpty() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define DBG_ASSERT(sCon, aError)
int i
constexpr TypedWhichId< XFillBitmapItem > XATTR_FILLBITMAP(XATTR_FILL_FIRST+4)
TRISTATE_FALSE
constexpr TypedWhichId< XFillBmpPosItem > XATTR_FILLBMP_POS(XATTR_FILL_FIRST+8)
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
std::unique_ptr< weld::ComboBox > m_xBitmapStyleLB
Definition: cuitabarea.hxx:512
void CalculateBitmapPresetSize()
Definition: tpbitmap.cxx:432
void SetAttributes(const SfxItemSet &rItemSet)
virtual bool FillItemSet(SfxItemSet *) override
Definition: tpbitmap.cxx:182
std::unique_ptr< SvxPresetListBox > m_xBitmapLB
Definition: cuitabarea.hxx:511
SfxItemPool * GetPool() const
virtual void Reset(const SfxItemSet *) override
Definition: tpbitmap.cxx:256
const SdrView * mpView
Definition: cuitabarea.hxx:503
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tpbitmap.cxx:150
std::unique_ptr< weld::CustomWeld > m_xBitmapLBWin
Definition: cuitabarea.hxx:527
std::unique_ptr< weld::ComboBox > m_xTileOffLB
Definition: cuitabarea.hxx:523
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tpbitmap.cxx:419
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
SvxXRectPreview m_aCtlBitmapPreview
Definition: cuitabarea.hxx:510
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tpbitmap.cxx:173
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const Fraction & GetUIScale() const
std::unique_ptr< weld::MetricSpinButton > m_xPositionOffY
Definition: cuitabarea.hxx:521
#define WB_NO_DIRECTSELECT
virtual void GetName(OUString &rName)=0
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
constexpr TypedWhichId< XFillBmpPosOffsetYItem > XATTR_FILLBMP_POSOFFSETY(XATTR_FILL_FIRST+18)
#define ERRCODE_NONE
constexpr tools::Long Height() const
sal_Int64 GetCoreValue(const weld::MetricSpinButton &rField, MapUnit eUnit)
#define GetWhich(nSlot)
XFillAttrSetItem m_aXFillAttr
Definition: cuitabarea.hxx:501
constexpr TypedWhichId< XFillBmpStretchItem > XATTR_FILLBMP_STRETCH(XATTR_FILL_FIRST+16)
OUString aName
RET_OK
constexpr TypedWhichId< XFillBmpPosOffsetXItem > XATTR_FILLBMP_POSOFFSETX(XATTR_FILL_FIRST+17)
constexpr TypedWhichId< XFillBmpTileItem > XATTR_FILLBMP_TILE(XATTR_FILL_FIRST+7)
std::unique_ptr< weld::MetricSpinButton > m_xPositionOffX
Definition: cuitabarea.hxx:520
constexpr TypedWhichId< XFillBmpSizeLogItem > XATTR_FILLBMP_SIZELOG(XATTR_FILL_FIRST+13)
UnoViewSharedPtr mpView
virtual SdrView * GetDrawView() const
WinBits const WB_TABSTOP
SfxItemSet & m_rXFSet
Definition: cuitabarea.hxx:502
DeactivateRC
void setHeight(tools::Long nHeight)
#define SAL_WARN(area, stream)
std::unique_ptr< weld::MetricSpinButton > m_xBitmapWidth
Definition: cuitabarea.hxx:515
std::unique_ptr< weld::Button > m_xBtnImport
Definition: cuitabarea.hxx:525
constexpr TypedWhichId< XFillBmpTileOffsetXItem > XATTR_FILLBMP_TILEOFFSETX(XATTR_FILL_FIRST+14)
#define WB_FLATVALUESET
TriState
double m_fObjectHeight
Definition: cuitabarea.hxx:498
constexpr TypedWhichId< XFillBmpSizeYItem > XATTR_FILLBMP_SIZEY(XATTR_FILL_FIRST+10)
FieldUnit meFieldUnit
Definition: cuitabarea.hxx:505
SdrModel * GetModel() const
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
sal_uInt16 nPos
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
void ClickBitmapHdl_Impl()
Definition: tpbitmap.cxx:424
sal_Int16 nValue
bool m_bDetectedRangeSegmentation false