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  const SfxPoolItem* pPoolItem = nullptr;
468 
469  if(SfxItemState::SET == m_rOutAttrs.GetItemState(GetWhich(XATTR_FILLSTYLE), true, &pPoolItem))
470  {
471  const drawing::FillStyle eXFS(static_cast<const XFillStyleItem*>(pPoolItem)->GetValue());
472 
473  if((drawing::FillStyle_BITMAP == eXFS) && (SfxItemState::SET == m_rOutAttrs.GetItemState(GetWhich(XATTR_FILLBITMAP), true, &pPoolItem)))
474  {
475  pGraphicObject.reset(new GraphicObject(static_cast<const XFillBitmapItem*>(pPoolItem)->GetGraphicObject()));
476  }
477  }
478 
479  if(!pGraphicObject)
480  {
481  sal_uInt16 nId = m_xBitmapLB->GetItemId(0);
482  m_xBitmapLB->SelectItem(nId);
483 
484  if(0 != nId)
485  {
486  pGraphicObject.reset(new GraphicObject(m_pBitmapList->GetBitmap(0)->GetGraphicObject()));
487  }
488  }
489  }
490 
491  if(pGraphicObject)
492  {
493  BitmapEx aBmpEx(pGraphicObject->GetGraphic().GetBitmapEx());
494  Size aTempBitmapSize = aBmpEx.GetSizePixel();
495  const double fUIScale = ( (mpView && mpView->GetModel()) ? double(mpView->GetModel()->GetUIScale()) : 1.0);
496  Size aBitmapSize100mm = o3tl::convert(aTempBitmapSize, o3tl::Length::pt, o3tl::Length::mm100);
497 
498  rBitmapSize.setWidth(aBitmapSize100mm.Width() / fUIScale);
499  rBitmapSize.setHeight(aBitmapSize100mm.Height() / fUIScale);
500  CalculateBitmapPresetSize();
501  ModifyBitmapStyleHdl( *m_xBitmapStyleLB );
502  ModifyBitmapPositionHdl( *m_xPositionLB );
503 
504  m_rXFSet.ClearItem(XATTR_FILLBITMAP);
505  m_rXFSet.Put(XFillStyleItem(drawing::FillStyle_BITMAP));
506  m_rXFSet.Put(XFillBitmapItem(OUString(), *pGraphicObject));
507 
508  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
509  m_aCtlBitmapPreview.Invalidate();
510  }
511  else
512  {
513  SAL_WARN("cui.tabpages", "SvxBitmapTabPage::ModifyBitmapHdl(): null pGraphicObject");
514  }
515 
516 }
517 
519 {
520  sal_uInt16 nId = m_xBitmapLB->GetSelectedItemId();
521  size_t nPos = m_xBitmapLB->GetSelectItemPos();
522 
523  if( nPos == VALUESET_ITEM_NOTFOUND )
524  return;
525 
526  OUString aDesc( CuiResId( RID_CUISTR_DESC_NEW_BITMAP ) );
527  OUString aName( m_pBitmapList->GetBitmap( nPos )->GetName() );
528 
530  ScopedVclPtr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog(GetFrameWeld(), aName, aDesc));
531 
532  bool bLoop = true;
533  while( bLoop && pDlg->Execute() == RET_OK )
534  {
535  pDlg->GetName( aName );
536  sal_Int32 nBitmapPos = SearchBitmapList( aName );
537  bool bValidBitmapName = (nBitmapPos == static_cast<sal_Int32>(nPos) ) || (nBitmapPos == -1);
538 
539  if(bValidBitmapName)
540  {
541  bLoop = false;
542  m_pBitmapList->GetBitmap(nPos)->SetName(aName);
543 
544  m_xBitmapLB->SetItemText(nId, aName);
545  m_xBitmapLB->SelectItem( nId );
546 
547  *m_pnBitmapListState |= ChangeType::MODIFIED;
548  }
549  else
550  {
551  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
552  std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
553  xBox->run();
554  }
555  }
556 }
557 
559 {
560  sal_uInt16 nId = m_xBitmapLB->GetSelectedItemId();
561  size_t nPos = m_xBitmapLB->GetSelectItemPos();
562 
563  if( nPos == VALUESET_ITEM_NOTFOUND )
564  return;
565 
566  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/querydeletebitmapdialog.ui"));
567  std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog("AskDelBitmapDialog"));
568 
569  if (xQueryBox->run() != RET_YES)
570  return;
571 
572  sal_uInt16 nNextId = m_xBitmapLB->GetItemId(nPos + 1);
573  if (!nNextId)
574  nNextId = m_xBitmapLB->GetItemId(nPos - 1);
575 
576  m_pBitmapList->Remove( static_cast<sal_uInt16>(nPos) );
577  m_xBitmapLB->RemoveItem( nId );
578 
579  m_xBitmapLB->SelectItem(nNextId);
580 
581  m_aCtlBitmapPreview.Invalidate();
582  ModifyBitmapHdl(m_xBitmapLB.get());
583  *m_pnBitmapListState |= ChangeType::MODIFIED;
584 }
585 
587 {
588  m_bLogicalSize = false;
589  if (m_xTsbScale->get_state() != TRISTATE_TRUE && static_cast<BitmapStyle>(m_xBitmapStyleLB->get_active()) != TILED)
590  {
591  sal_Int64 nWidthPercent = m_xBitmapWidth->denormalize(m_xBitmapWidth->get_value(FieldUnit::NONE));
592  sal_Int64 nHeightPercent = m_xBitmapHeight->denormalize(m_xBitmapHeight->get_value(FieldUnit::NONE));
593  if (nWidthPercent == 100 && nHeightPercent == 100)
594  m_xBitmapStyleLB->set_active(static_cast<sal_Int32>(CUSTOM));
595  }
596  ModifyBitmapStyleHdl(*m_xBitmapStyleLB);
597 
598  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
599  m_aCtlBitmapPreview.Invalidate();
600 }
601 
603 {
604  if (m_xTsbScale->get_state() == TRISTATE_TRUE)
605  {
606  m_xBitmapWidth->set_digits( 0 );
607  m_xBitmapWidth->set_unit(FieldUnit::PERCENT);
608  m_xBitmapWidth->set_value(100, FieldUnit::NONE);
609  m_xBitmapWidth->set_range(0, 100, FieldUnit::NONE);
610 
611  m_xBitmapHeight->set_digits( 0 );
612  m_xBitmapHeight->set_unit(FieldUnit::PERCENT);
613  m_xBitmapHeight->set_value(100, FieldUnit::NONE);
614  m_xBitmapHeight->set_range(0, 100, FieldUnit::NONE);
615  }
616  else
617  {
618  m_xBitmapWidth->set_digits( 2 );
619  m_xBitmapWidth->set_unit(meFieldUnit);
620  m_xBitmapWidth->set_value(100, FieldUnit::NONE);
621  m_xBitmapWidth->set_range(0, 999900, FieldUnit::NONE);
622 
623  m_xBitmapHeight->set_digits( 2 );
624  m_xBitmapHeight->set_unit(meFieldUnit);
625  m_xBitmapHeight->set_value(100, FieldUnit::NONE);
626  m_xBitmapHeight->set_range(0, 999900, FieldUnit::NONE);
627  }
628 
629  ModifyBitmapStyleHdl( *m_xBitmapStyleLB );
630 }
631 
632 IMPL_LINK_NOARG( SvxBitmapTabPage, ModifyBitmapStyleHdl, weld::ComboBox&, void )
633 {
634  BitmapStyle eStylePos = static_cast<BitmapStyle>(m_xBitmapStyleLB->get_active());
635  bool bIsStretched( eStylePos == STRETCHED );
636  bool bIsTiled( eStylePos == TILED );
637 
638  m_xSizeBox->set_sensitive( !bIsStretched );
639  m_xPositionBox->set_sensitive( !bIsStretched );
640  m_xPositionOffBox->set_sensitive( bIsTiled );
641  m_xTileOffBox->set_sensitive( bIsTiled );
642 
643  m_rXFSet.Put( XFillBmpTileItem( bIsTiled ) );
644  m_rXFSet.Put( XFillBmpStretchItem( bIsStretched ) );
645 
646  if(!bIsStretched)
647  {
648  Size aSetBitmapSize;
649  switch(eStylePos)
650  {
651  case CUSTOM:
652  case TILED:
653  {
654  if (m_xTsbScale->get_sensitive() && m_xTsbScale->get_state() == TRISTATE_TRUE)
655  {
656  aSetBitmapSize.setWidth(-m_xBitmapWidth->get_value(FieldUnit::NONE));
657  aSetBitmapSize.setHeight(-m_xBitmapHeight->get_value(FieldUnit::NONE));
658  }
659  else
660  {
661  aSetBitmapSize.setWidth( GetCoreValue( *m_xBitmapWidth, mePoolUnit ) );
662  aSetBitmapSize.setHeight( GetCoreValue( *m_xBitmapHeight, mePoolUnit ) );
663  }
664  }
665  break;
666  default:
667  break;
668  }
669 
670  m_rXFSet.Put( XFillBmpSizeXItem( aSetBitmapSize.Width() ) );
671  m_rXFSet.Put( XFillBmpSizeYItem( aSetBitmapSize.Height() ) );
672  }
673 
674  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
675  m_aCtlBitmapPreview.Invalidate();
676 }
677 
678 IMPL_LINK_NOARG(SvxBitmapTabPage, ModifyBitmapPositionHdl, weld::ComboBox&, void)
679 {
680  if (m_xPositionLB->get_sensitive())
681  m_rXFSet.Put( XFillBmpPosItem( static_cast< RectPoint >( m_xPositionLB->get_active() ) ) );
682 
683  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
684  m_aCtlBitmapPreview.Invalidate();
685 }
686 
687 IMPL_LINK_NOARG(SvxBitmapTabPage, ModifyPositionOffsetHdl, weld::MetricSpinButton&, void)
688 {
689  if (m_xPositionOffX->get_sensitive())
690  m_rXFSet.Put( XFillBmpPosOffsetXItem( m_xPositionOffX->get_value(FieldUnit::PERCENT) ) );
691 
692  if (m_xPositionOffY->get_sensitive())
693  m_rXFSet.Put( XFillBmpPosOffsetYItem( m_xPositionOffY->get_value(FieldUnit::PERCENT) ) );
694 
695  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
696  m_aCtlBitmapPreview.Invalidate();
697 }
698 
700 {
701  sal_uInt16 nTileXOff = 0;
702  sal_uInt16 nTileYOff = 0;
703 
704  if(m_xTileOffLB->get_active() == static_cast<sal_Int32>(ROW))
705  nTileXOff = m_xTileOffset->get_value(FieldUnit::PERCENT);
706 
707  if(m_xTileOffLB->get_active() == static_cast<sal_Int32>(COLUMN))
708  nTileYOff = m_xTileOffset->get_value(FieldUnit::PERCENT);
709 
710  m_rXFSet.Put( XFillBmpTileOffsetXItem(nTileXOff) );
711  m_rXFSet.Put( XFillBmpTileOffsetYItem(nTileYOff) );
712 
713  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
714  m_aCtlBitmapPreview.Invalidate();
715 }
716 
718 {
719  weld::Window* pDialogFrameWeld = GetFrameWeld();
720 
721  SvxOpenGraphicDialog aDlg(CuiResId(RID_CUISTR_ADD_IMAGE), pDialogFrameWeld);
722  aDlg.EnableLink(false);
723  tools::Long nCount = m_pBitmapList->Count();
724 
725  if( aDlg.Execute() )
726  return;
727 
728  Graphic aGraphic;
729 
730  std::unique_ptr<weld::WaitObject> xWait(new weld::WaitObject(pDialogFrameWeld));
731  ErrCode nError = aDlg.GetGraphic( aGraphic );
732  xWait.reset();
733 
734  if( !nError )
735  {
736  OUString aDesc(CuiResId(RID_CUISTR_DESC_EXT_BITMAP));
737 
738  // convert file URL to UI name
739  OUString aName;
740  INetURLObject aURL( aDlg.GetPath() );
742  ScopedVclPtr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog(
743  pDialogFrameWeld, aURL.GetLastName().getToken(0, '.'), aDesc));
744  nError = ErrCode(1);
745 
746  while( pDlg->Execute() == RET_OK )
747  {
748  pDlg->GetName( aName );
749 
750  bool bDifferent = true;
751 
752  for( tools::Long i = 0; i < nCount && bDifferent; i++ )
753  if( aName == m_pBitmapList->GetBitmap( i )->GetName() )
754  bDifferent = false;
755 
756  if( bDifferent ) {
757  nError = ERRCODE_NONE;
758  break;
759  }
760 
761  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pDialogFrameWeld, "cui/ui/queryduplicatedialog.ui"));
762  std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
763  if (xBox->run() != RET_OK)
764  break;
765  }
766 
767  pDlg.disposeAndClear();
768 
769  if( !nError )
770  {
771  m_pBitmapList->Insert(std::make_unique<XBitmapEntry>(aGraphic, aName), nCount);
772 
773  sal_Int32 nId = m_xBitmapLB->GetItemId( nCount - 1 );
774  BitmapEx aBitmap = m_pBitmapList->GetBitmapForPreview( nCount, m_xBitmapLB->GetIconSize() );
775 
776  m_xBitmapLB->InsertItem( nId + 1, Image(aBitmap), aName );
777  m_xBitmapLB->SelectItem( nId + 1 );
778  *m_pnBitmapListState |= ChangeType::MODIFIED;
779 
780  ModifyBitmapHdl(m_xBitmapLB.get());
781  }
782  }
783  else
784  {
785  // graphic couldn't be loaded
786  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pDialogFrameWeld, "cui/ui/querynoloadedfiledialog.ui"));
787  std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("NoLoadedFileDialog"));
788  xBox->run();
789  }
790 }
791 
792 sal_Int32 SvxBitmapTabPage::SearchBitmapList(const GraphicObject& rGraphicObject)
793 {
794  tools::Long nCount = m_pBitmapList->Count();
795  sal_Int32 nPos = -1;
796 
797  for(tools::Long i = 0;i < nCount;i++)
798  {
799  if(rGraphicObject.GetUniqueID() == m_pBitmapList->GetBitmap( i )->GetGraphicObject().GetUniqueID())
800  {
801  nPos = i;
802  break;
803  }
804  }
805  return nPos;
806 }
807 
808 sal_Int32 SvxBitmapTabPage::SearchBitmapList(std::u16string_view rBitmapName)
809 {
810  tools::Long nCount = m_pBitmapList->Count();
811  bool bValidBitmapName = true;
812  sal_Int32 nPos = -1;
813 
814  for(tools::Long i = 0;i < nCount && bValidBitmapName;i++)
815  {
816  if(rBitmapName == m_pBitmapList->GetBitmap( i )->GetName())
817  {
818  nPos = i;
819  bValidBitmapName = false;
820  }
821  }
822  return nPos;
823 }
824 
825 /* 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
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:808
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
int GetCoreValue(const weld::MetricSpinButton &rField, MapUnit eUnit)
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
void SetMetricValue(weld::MetricSpinButton &rField, int nCoreValue, MapUnit eUnit)
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
#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