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/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>
48 
49 using namespace com::sun::star;
50 
52 {
56 };
57 
59 {
60  ROW,
62 };
63 
64 const sal_uInt16 SvxBitmapTabPage::pBitmapRanges[] =
65 {
66  SID_ATTR_TRANSFORM_WIDTH,
67  SID_ATTR_TRANSFORM_HEIGHT,
68  0
69 };
70 
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))
98 {
99  // setting the output device
100  m_rXFSet.Put( XFillStyleItem(drawing::FillStyle_BITMAP) );
101  m_rXFSet.Put( XFillBitmapItem(OUString(), Graphic()) );
103 
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) );
119  m_xBtnImport->hide();
120 
121  // Calculate size of display boxes
122 
123  Size aBitmapLBSize = getPagePropertiesOptimalSize(m_xBitmapLB->GetDrawingArea()->get_ref_device());
124  m_xBitmapLB->set_size_request(aBitmapLBSize.Width(), aBitmapLBSize.Height());
125 
126  Size aSize = getDrawPreviewOptimalSize(m_aCtlBitmapPreview.GetDrawingArea()->get_ref_device());
127  m_xCtlBitmapPreview->set_size_request(aSize.Width(), aSize.Height());
128 
129  SfxItemPool* pPool = m_rXFSet.GetPool();
131  meFieldUnit = GetModuleFieldUnit( rInAttrs );
134 
135  SfxViewShell* pViewShell = SfxViewShell::Current();
136  if( pViewShell )
137  mpView = pViewShell->GetDrawView();
138  DBG_ASSERT( mpView, "no valid view (!)" );
139 }
140 
142 {
143  m_xBitmapLBWin.reset();
144  m_xBitmapLB.reset();
145  m_xCtlBitmapPreview.reset();
146 }
147 
149 {
150  m_xBitmapLB->FillPresetListBox( *m_pBitmapList );
151 }
152 
154 {
155  XFillBitmapItem aItem( rSet.Get(XATTR_FILLBITMAP) );
156 
157  sal_Int32 nPos( 0 );
158  if ( !aItem.isPattern() )
159  {
160  nPos = SearchBitmapList( aItem.GetGraphicObject() );
161  if ( nPos == LISTBOX_ENTRY_NOTFOUND )
162  return;
163  }
164  else
165  {
166  m_xBitmapWidth->set_value( 100, FieldUnit::NONE );
167  m_xBitmapHeight->set_value( 100, FieldUnit::NONE );
170  }
171 
172  sal_uInt16 nId = m_xBitmapLB->GetItemId( static_cast<size_t>( nPos ) );
173  m_xBitmapLB->SelectItem( nId );
174 }
175 
177 {
178  if( _pSet )
179  FillItemSet( _pSet );
180 
181  return DeactivateRC::LeavePage;
182 }
183 
184 
186 {
187  rAttrs->Put(XFillStyleItem(drawing::FillStyle_BITMAP));
188  size_t nPos = m_xBitmapLB->GetSelectItemPos();
189  if(VALUESET_ITEM_NOTFOUND != nPos)
190  {
191  const XBitmapEntry* pXBitmapEntry = m_pBitmapList->GetBitmap(nPos);
192  const OUString aString(m_xBitmapLB->GetItemText( m_xBitmapLB->GetSelectedItemId() ));
193  rAttrs->Put(XFillBitmapItem(aString, pXBitmapEntry->GetGraphicObject()));
194  }
195 
196  BitmapStyle eStylePos = static_cast<BitmapStyle>(m_xBitmapStyleLB->get_active());
197  bool bIsStretched( eStylePos == STRETCHED );
198  bool bIsTiled( eStylePos == TILED );
199 
200  rAttrs->Put( XFillBmpTileItem(bIsTiled) );
201  rAttrs->Put( XFillBmpStretchItem(bIsStretched) );
202 
203  if(!bIsStretched)
204  {
205  Size aSetBitmapSize;
206  switch(eStylePos)
207  {
208  case CUSTOM:
209  case TILED:
210  {
211  sal_Int64 nWidthPercent = m_xBitmapWidth->get_value(FieldUnit::NONE);
212  sal_Int64 nHeightPercent = m_xBitmapHeight->get_value(FieldUnit::NONE);
213  if (m_xTsbScale->get_sensitive() && m_xTsbScale->get_state() == TRISTATE_TRUE)
214  {
215  aSetBitmapSize.setWidth( -nWidthPercent );
216  aSetBitmapSize.setHeight( -nHeightPercent );
217  }
218  else if (!m_bLogicalSize)
219  {
220  aSetBitmapSize.setWidth( GetCoreValue(*m_xBitmapWidth, mePoolUnit) );
221  aSetBitmapSize.setHeight( GetCoreValue(*m_xBitmapHeight, mePoolUnit) );
222  }
223  else
224  {
225  rAttrs->Put( XFillBmpSizeLogItem(true) );
226  aSetBitmapSize.setWidth( 0 );
227  aSetBitmapSize.setHeight( 0 );
228  }
229 
230  break;
231  }
232  default:
233  break;
234  }
235 
236  rAttrs->Put( XFillBmpSizeXItem( aSetBitmapSize.Width() ) );
237  rAttrs->Put( XFillBmpSizeYItem( aSetBitmapSize.Height() ) );
238  }
239 
240  if (m_xPositionLB->get_sensitive())
241  rAttrs->Put( XFillBmpPosItem( static_cast<RectPoint>( m_xPositionLB->get_active() ) ) );
242  if (m_xPositionOffX->get_sensitive())
243  rAttrs->Put( XFillBmpPosOffsetXItem(m_xPositionOffX->get_value(FieldUnit::PERCENT)));
244  if (m_xPositionOffY->get_sensitive())
245  rAttrs->Put( XFillBmpPosOffsetYItem(m_xPositionOffY->get_value(FieldUnit::PERCENT)));
246  if (m_xTileOffBox->get_sensitive())
247  {
248  TileOffset eValue = static_cast<TileOffset>(m_xTileOffLB->get_active());
249  sal_uInt16 nOffsetValue = static_cast<sal_uInt16>(m_xTileOffset->get_value(FieldUnit::PERCENT));
250  sal_uInt16 nRowOff = (eValue == ROW) ? nOffsetValue : 0;
251  sal_uInt16 nColOff = (eValue == COLUMN) ? nOffsetValue : 0;
252  rAttrs->Put( XFillBmpTileOffsetXItem(nRowOff) );
253  rAttrs->Put( XFillBmpTileOffsetYItem(nColOff) );
254  }
255  return true;
256 }
257 
258 
259 void SvxBitmapTabPage::Reset( const SfxItemSet* rAttrs )
260 {
261  const SfxPoolItem* pItemTransfWidth = nullptr;
262  const SfxPoolItem* pItemTransfHeight = nullptr;
263  double fUIScale = 1.0;
264  if (mpView)
265  {
266  fUIScale = ( mpView->GetModel() ? double(mpView->GetModel()->GetUIScale()) : 1.0);
267 
268 
269  if (mpView->AreObjectsMarked())
270  {
272  pItemTransfWidth = GetItem( rGeoAttr, SID_ATTR_TRANSFORM_WIDTH );
273  pItemTransfHeight= GetItem( rGeoAttr, SID_ATTR_TRANSFORM_HEIGHT );
274  }
275  }
276  m_fObjectWidth = std::max( pItemTransfWidth ? static_cast<double>(static_cast<const SfxUInt32Item*>(pItemTransfWidth)->GetValue()) : 0.0, 1.0 );
277  m_fObjectHeight = std::max( pItemTransfHeight ? static_cast<double>(static_cast<const SfxUInt32Item*>(pItemTransfHeight)->GetValue()) : 0.0, 1.0 );
278  double fTmpWidth((OutputDevice::LogicToLogic(static_cast<sal_Int32>(m_fObjectWidth), mePoolUnit, MapUnit::Map100thMM )) / fUIScale);
279  m_fObjectWidth = fTmpWidth;
280 
281  double fTmpHeight((OutputDevice::LogicToLogic(static_cast<sal_Int32>(m_fObjectHeight), mePoolUnit, MapUnit::Map100thMM )) / fUIScale);
282  m_fObjectHeight = fTmpHeight;
283 
284  XFillBitmapItem aItem( rAttrs->Get(XATTR_FILLBITMAP) );
285 
286  if(!aItem.isPattern())
287  {
288  m_rXFSet.Put( aItem );
290  m_aCtlBitmapPreview.Invalidate();
291  }
292  else
293  m_xCtlBitmapPreview->set_sensitive(false);
294 
295  std::unique_ptr<GraphicObject> pGraphicObject;
296  pGraphicObject.reset( new GraphicObject(aItem.GetGraphicObject()) );
297 
298  BitmapEx aBmpEx(pGraphicObject->GetGraphic().GetBitmapEx());
299  Size aTempBitmapSize = aBmpEx.GetSizePixel();
300  rBitmapSize = Application::GetDefaultDevice()->PixelToLogic(aTempBitmapSize, MapMode(MapUnit::Map100thMM));
302 
303  bool bTiled = false; bool bStretched = false;
304  if(rAttrs->GetItemState( XATTR_FILLBMP_TILE ) != SfxItemState::DONTCARE)
305  bTiled = rAttrs->Get( XATTR_FILLBMP_TILE ).GetValue();
306  if(rAttrs->GetItemState( XATTR_FILLBMP_STRETCH ) != SfxItemState::DONTCARE)
307  bStretched = rAttrs->Get( XATTR_FILLBMP_STRETCH ).GetValue();
308 
309  if (bTiled)
310  m_xBitmapStyleLB->set_active(static_cast<sal_Int32>(TILED));
311  else if (bStretched)
312  m_xBitmapStyleLB->set_active(static_cast<sal_Int32>(STRETCHED));
313  else
314  m_xBitmapStyleLB->set_active(static_cast<sal_Int32>(CUSTOM));
315 
316  long nWidth = 0;
317  long nHeight = 0;
318 
319  if(rAttrs->GetItemState(XATTR_FILLBMP_SIZELOG) != SfxItemState::DONTCARE)
320  {
321  if (rAttrs->Get( XATTR_FILLBMP_SIZELOG ).GetValue())
322  {
323  m_xTsbScale->set_state(TRISTATE_FALSE);
324  m_bLogicalSize = true;
325  }
326  else
327  {
328  m_xTsbScale->set_state(TRISTATE_TRUE);
329  m_bLogicalSize = false;
330  }
331  }
332  else
333  m_xTsbScale->set_state(TRISTATE_INDET);
334 
335  TriState eRelative = TRISTATE_FALSE;
336  if(rAttrs->GetItemState(XATTR_FILLBMP_SIZEX) != SfxItemState::DONTCARE)
337  {
338  nWidth = static_cast<const XFillBmpSizeXItem&>( rAttrs->Get( XATTR_FILLBMP_SIZEX ) ).GetValue();
339  if(nWidth == 0)
340  nWidth = rBitmapSize.Width();
341  else if(nWidth < 0)
342  {
343  eRelative = TRISTATE_TRUE;
344  nWidth = std::abs(nWidth);
345  }
346  }
347 
348  if(rAttrs->GetItemState( XATTR_FILLBMP_SIZEY ) != SfxItemState::DONTCARE)
349  {
350  nHeight = rAttrs->Get( XATTR_FILLBMP_SIZEY ).GetValue();
351  if(nHeight == 0)
352  nHeight = rBitmapSize.Height();
353  else if(nHeight < 0)
354  {
355  eRelative = TRISTATE_TRUE;
356  nHeight = std::abs(nHeight);
357  }
358  }
359  m_xTsbScale->set_state(eRelative);
360  ClickScaleHdl(*m_xTsbScale);
361 
362 
363  if(rBitmapSize.Width() > 0 && rBitmapSize.Height() > 0)
364  {
365  if (eRelative == TRISTATE_TRUE)
366  {
367  m_xBitmapWidth->set_value(nWidth, FieldUnit::NONE);
368  m_xBitmapHeight->set_value(nHeight, FieldUnit::NONE);
369  }
370  else
371  {
374  }
375  }
376 
377  if( rAttrs->GetItemState( XATTR_FILLBMP_POS ) != SfxItemState::DONTCARE )
378  {
379  RectPoint eValue = rAttrs->Get( XATTR_FILLBMP_POS ).GetValue();
380  m_xPositionLB->set_active( static_cast< sal_Int32 >(eValue) );
381  }
382 
383  if( rAttrs->GetItemState( XATTR_FILLBMP_POSOFFSETX ) != SfxItemState::DONTCARE )
384  {
385  sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_POSOFFSETX ).GetValue();
386  m_xPositionOffX->set_value(nValue, FieldUnit::PERCENT);
387  }
388  else
389  m_xPositionOffX->set_text("");
390 
391  if( rAttrs->GetItemState( XATTR_FILLBMP_POSOFFSETY ) != SfxItemState::DONTCARE )
392  {
393  sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_POSOFFSETY ).GetValue();
394  m_xPositionOffY->set_value(nValue, FieldUnit::PERCENT);
395  }
396  else
397  m_xPositionOffY->set_text("");
398 
399  if( rAttrs->GetItemState( XATTR_FILLBMP_TILEOFFSETX ) != SfxItemState::DONTCARE)
400  {
401  sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_TILEOFFSETX ).GetValue();
402  if(nValue > 0)
403  {
404  m_xTileOffLB->set_active(static_cast<sal_Int32>(ROW));
405  m_xTileOffset->set_value(nValue, FieldUnit::PERCENT);
406  }
407  }
408 
409  if( rAttrs->GetItemState( XATTR_FILLBMP_TILEOFFSETY ) != SfxItemState::DONTCARE )
410  {
411  sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_TILEOFFSETY ).GetValue();
412  if(nValue > 0)
413  {
414  m_xTileOffLB->set_active(static_cast<sal_Int32>(COLUMN));
415  m_xTileOffset->set_value(nValue, FieldUnit::PERCENT);
416  }
417  }
418 
420 }
421 
422 std::unique_ptr<SfxTabPage> SvxBitmapTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrs)
423 {
424  return std::make_unique<SvxBitmapTabPage>(pPage, pController, *rAttrs);
425 }
426 
428 {
429  m_xBitmapLBWin->set_sensitive(true);
430  m_xCtlBitmapPreview->set_sensitive(true);
431 
432  ModifyBitmapHdl(m_xBitmapLB.get());
433 }
434 
436 {
437  if(rBitmapSize.Width() > 0 && rBitmapSize.Height() > 0)
438  {
439  long nObjectWidth = static_cast<long>(m_fObjectWidth);
440  long nObjectHeight = static_cast<long>(m_fObjectHeight);
441 
442  if(std::abs(rBitmapSize.Width() - nObjectWidth) < std::abs(rBitmapSize.Height() - nObjectHeight))
443  {
444  rFilledSize.setWidth( nObjectWidth );
447  rZoomedSize.setHeight( nObjectHeight );
448  }
449  else
450  {
452  rFilledSize.setHeight( nObjectHeight );
453  rZoomedSize.setWidth( nObjectWidth );
455  }
456  }
457 }
458 
460 {
461  std::unique_ptr<GraphicObject> pGraphicObject;
462  size_t nPos = m_xBitmapLB->GetSelectItemPos();
463 
464  if( nPos != VALUESET_ITEM_NOTFOUND )
465  {
466  pGraphicObject.reset(new GraphicObject(m_pBitmapList->GetBitmap( static_cast<sal_uInt16>(nPos) )->GetGraphicObject()));
467  }
468  else
469  {
470  const SfxPoolItem* pPoolItem = nullptr;
471 
472  if(SfxItemState::SET == m_rOutAttrs.GetItemState(GetWhich(XATTR_FILLSTYLE), true, &pPoolItem))
473  {
474  const drawing::FillStyle eXFS(static_cast<const XFillStyleItem*>(pPoolItem)->GetValue());
475 
476  if((drawing::FillStyle_BITMAP == eXFS) && (SfxItemState::SET == m_rOutAttrs.GetItemState(GetWhich(XATTR_FILLBITMAP), true, &pPoolItem)))
477  {
478  pGraphicObject.reset(new GraphicObject(static_cast<const XFillBitmapItem*>(pPoolItem)->GetGraphicObject()));
479  }
480  }
481 
482  if(!pGraphicObject)
483  {
484  sal_uInt16 nId = m_xBitmapLB->GetItemId(0);
485  m_xBitmapLB->SelectItem(nId);
486 
487  if(0 != nId)
488  {
489  pGraphicObject.reset(new GraphicObject(m_pBitmapList->GetBitmap(0)->GetGraphicObject()));
490  }
491  }
492  }
493 
494  if(pGraphicObject)
495  {
496  BitmapEx aBmpEx(pGraphicObject->GetGraphic().GetBitmapEx());
497  Size aTempBitmapSize = aBmpEx.GetSizePixel();
498  const double fUIScale = ( (mpView && mpView->GetModel()) ? double(mpView->GetModel()->GetUIScale()) : 1.0);
499 
500  rBitmapSize.setWidth( (OutputDevice::LogicToLogic(static_cast<sal_Int32>(aTempBitmapSize.Width()),MapUnit::MapPixel, MapUnit::Map100thMM )) / fUIScale );
501  rBitmapSize.setHeight( (OutputDevice::LogicToLogic(static_cast<sal_Int32>(aTempBitmapSize.Height()),MapUnit::MapPixel, MapUnit::Map100thMM )) / fUIScale );
502  CalculateBitmapPresetSize();
503  ModifyBitmapStyleHdl( *m_xBitmapStyleLB );
504  ModifyBitmapPositionHdl( *m_xPositionLB );
505 
506  m_rXFSet.ClearItem(XATTR_FILLBITMAP);
507  m_rXFSet.Put(XFillStyleItem(drawing::FillStyle_BITMAP));
508  m_rXFSet.Put(XFillBitmapItem(OUString(), *pGraphicObject));
509 
510  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
511  m_aCtlBitmapPreview.Invalidate();
512  }
513  else
514  {
515  SAL_WARN("cui.tabpages", "SvxBitmapTabPage::ModifyBitmapHdl(): null pGraphicObject");
516  }
517 
518 }
519 
521 {
522  sal_uInt16 nId = m_xBitmapLB->GetSelectedItemId();
523  size_t nPos = m_xBitmapLB->GetSelectItemPos();
524 
525  if( nPos != VALUESET_ITEM_NOTFOUND )
526  {
527  OUString aDesc( CuiResId( RID_SVXSTR_DESC_NEW_BITMAP ) );
528  OUString aName( m_pBitmapList->GetBitmap( nPos )->GetName() );
529 
531  ScopedVclPtr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog(GetFrameWeld(), aName, aDesc));
532 
533  bool bLoop = true;
534  while( bLoop && pDlg->Execute() == RET_OK )
535  {
536  pDlg->GetName( aName );
537  sal_Int32 nBitmapPos = SearchBitmapList( aName );
538  bool bValidBitmapName = (nBitmapPos == static_cast<sal_Int32>(nPos) ) || (nBitmapPos == LISTBOX_ENTRY_NOTFOUND);
539 
540  if(bValidBitmapName)
541  {
542  bLoop = false;
543  m_pBitmapList->GetBitmap(nPos)->SetName(aName);
544 
545  m_xBitmapLB->SetItemText(nId, aName);
546  m_xBitmapLB->SelectItem( nId );
547 
548  *m_pnBitmapListState |= ChangeType::MODIFIED;
549  }
550  else
551  {
552  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
553  std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
554  xBox->run();
555  }
556  }
557  }
558 }
559 
561 {
562  sal_uInt16 nId = m_xBitmapLB->GetSelectedItemId();
563  size_t nPos = m_xBitmapLB->GetSelectItemPos();
564 
565  if( nPos != VALUESET_ITEM_NOTFOUND )
566  {
567  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/querydeletebitmapdialog.ui"));
568  std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog("AskDelBitmapDialog"));
569 
570  if (xQueryBox->run() == RET_YES)
571  {
572  m_pBitmapList->Remove( static_cast<sal_uInt16>(nPos) );
573  m_xBitmapLB->RemoveItem( nId );
574  nId = m_xBitmapLB->GetItemId(0);
575  m_xBitmapLB->SelectItem( nId );
576 
577  m_aCtlBitmapPreview.Invalidate();
578  ModifyBitmapHdl(m_xBitmapLB.get());
579  *m_pnBitmapListState |= ChangeType::MODIFIED;
580  }
581  }
582 }
583 
585 {
586  m_bLogicalSize = false;
587  if (m_xTsbScale->get_state() != TRISTATE_TRUE && static_cast<BitmapStyle>(m_xBitmapStyleLB->get_active()) != TILED)
588  {
589  sal_Int64 nWidthPercent = m_xBitmapWidth->denormalize(m_xBitmapWidth->get_value(FieldUnit::NONE));
590  sal_Int64 nHeightPercent = m_xBitmapHeight->denormalize(m_xBitmapHeight->get_value(FieldUnit::NONE));
591  if (nWidthPercent == 100 && nHeightPercent == 100)
592  m_xBitmapStyleLB->set_active(static_cast<sal_Int32>(CUSTOM));
593  }
594  ModifyBitmapStyleHdl(*m_xBitmapStyleLB);
595 
596  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
597  m_aCtlBitmapPreview.Invalidate();
598 }
599 
601 {
602  if (m_xTsbScale->get_state() == TRISTATE_TRUE)
603  {
604  m_xBitmapWidth->set_digits( 0 );
605  m_xBitmapWidth->set_unit(FieldUnit::PERCENT);
606  m_xBitmapWidth->set_value(100, FieldUnit::NONE);
607  m_xBitmapWidth->set_range(0, 100, FieldUnit::NONE);
608 
609  m_xBitmapHeight->set_digits( 0 );
610  m_xBitmapHeight->set_unit(FieldUnit::PERCENT);
611  m_xBitmapHeight->set_value(100, FieldUnit::NONE);
612  m_xBitmapHeight->set_range(0, 100, FieldUnit::NONE);
613  }
614  else
615  {
616  m_xBitmapWidth->set_digits( 2 );
617  m_xBitmapWidth->set_unit(meFieldUnit);
618  m_xBitmapWidth->set_value(100, FieldUnit::NONE);
619  m_xBitmapWidth->set_range(0, 999900, FieldUnit::NONE);
620 
621  m_xBitmapHeight->set_digits( 2 );
622  m_xBitmapHeight->set_unit(meFieldUnit);
623  m_xBitmapHeight->set_value(100, FieldUnit::NONE);
624  m_xBitmapHeight->set_range(0, 999900, FieldUnit::NONE);
625  }
626 
627  ModifyBitmapStyleHdl( *m_xBitmapStyleLB );
628 }
629 
630 IMPL_LINK_NOARG( SvxBitmapTabPage, ModifyBitmapStyleHdl, weld::ComboBox&, void )
631 {
632  BitmapStyle eStylePos = static_cast<BitmapStyle>(m_xBitmapStyleLB->get_active());
633  bool bIsStretched( eStylePos == STRETCHED );
634  bool bIsTiled( eStylePos == TILED );
635 
636  m_xSizeBox->set_sensitive( !bIsStretched );
637  m_xPositionBox->set_sensitive( !bIsStretched );
638  m_xPositionOffBox->set_sensitive( bIsTiled );
639  m_xTileOffBox->set_sensitive( bIsTiled );
640 
641  m_rXFSet.Put( XFillBmpTileItem( bIsTiled ) );
642  m_rXFSet.Put( XFillBmpStretchItem( bIsStretched ) );
643 
644  if(!bIsStretched)
645  {
646  Size aSetBitmapSize;
647  switch(eStylePos)
648  {
649  case CUSTOM:
650  case TILED:
651  {
652  if (m_xTsbScale->get_sensitive() && m_xTsbScale->get_state() == TRISTATE_TRUE)
653  {
654  aSetBitmapSize.setWidth(-m_xBitmapWidth->get_value(FieldUnit::NONE));
655  aSetBitmapSize.setHeight(-m_xBitmapHeight->get_value(FieldUnit::NONE));
656  }
657  else
658  {
659  aSetBitmapSize.setWidth( GetCoreValue( *m_xBitmapWidth, mePoolUnit ) );
660  aSetBitmapSize.setHeight( GetCoreValue( *m_xBitmapHeight, mePoolUnit ) );
661  }
662  }
663  break;
664  default:
665  break;
666  }
667 
668  m_rXFSet.Put( XFillBmpSizeXItem( aSetBitmapSize.Width() ) );
669  m_rXFSet.Put( XFillBmpSizeYItem( aSetBitmapSize.Height() ) );
670  }
671 
672  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
673  m_aCtlBitmapPreview.Invalidate();
674 }
675 
676 IMPL_LINK_NOARG(SvxBitmapTabPage, ModifyBitmapPositionHdl, weld::ComboBox&, void)
677 {
678  if (m_xPositionLB->get_sensitive())
679  m_rXFSet.Put( XFillBmpPosItem( static_cast< RectPoint >( m_xPositionLB->get_active() ) ) );
680 
681  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
682  m_aCtlBitmapPreview.Invalidate();
683 }
684 
685 IMPL_LINK_NOARG(SvxBitmapTabPage, ModifyPositionOffsetHdl, weld::MetricSpinButton&, void)
686 {
687  if (m_xPositionOffX->get_sensitive())
688  m_rXFSet.Put( XFillBmpPosOffsetXItem( m_xPositionOffX->get_value(FieldUnit::PERCENT) ) );
689 
690  if (m_xPositionOffY->get_sensitive())
691  m_rXFSet.Put( XFillBmpPosOffsetYItem( m_xPositionOffY->get_value(FieldUnit::PERCENT) ) );
692 
693  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
694  m_aCtlBitmapPreview.Invalidate();
695 }
696 
698 {
699  sal_uInt16 nTileXOff = 0;
700  sal_uInt16 nTileYOff = 0;
701 
702  if(m_xTileOffLB->get_active() == static_cast<sal_Int32>(ROW))
703  nTileXOff = m_xTileOffset->get_value(FieldUnit::PERCENT);
704 
705  if(m_xTileOffLB->get_active() == static_cast<sal_Int32>(COLUMN))
706  nTileYOff = m_xTileOffset->get_value(FieldUnit::PERCENT);
707 
708  m_rXFSet.Put( XFillBmpTileOffsetXItem(nTileXOff) );
709  m_rXFSet.Put( XFillBmpTileOffsetYItem(nTileYOff) );
710 
711  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
712  m_aCtlBitmapPreview.Invalidate();
713 }
714 
716 {
717  weld::Window* pDialogFrameWeld = GetFrameWeld();
718 
719  SvxOpenGraphicDialog aDlg(CuiResId(RID_SVXSTR_ADD_IMAGE), pDialogFrameWeld);
720  aDlg.EnableLink(false);
721  long nCount = m_pBitmapList->Count();
722 
723  if( !aDlg.Execute() )
724  {
725  Graphic aGraphic;
726 
727  std::unique_ptr<weld::WaitObject> xWait(new weld::WaitObject(pDialogFrameWeld));
728  ErrCode nError = aDlg.GetGraphic( aGraphic );
729  xWait.reset();
730 
731  if( !nError )
732  {
733  OUString aDesc(CuiResId(RID_SVXSTR_DESC_EXT_BITMAP));
734 
735  // convert file URL to UI name
736  OUString aName;
737  INetURLObject aURL( aDlg.GetPath() );
739  ScopedVclPtr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog(
740  pDialogFrameWeld, aURL.GetLastName().getToken(0, '.'), aDesc));
741  nError = ErrCode(1);
742 
743  while( pDlg->Execute() == RET_OK )
744  {
745  pDlg->GetName( aName );
746 
747  bool bDifferent = true;
748 
749  for( long i = 0; i < nCount && bDifferent; i++ )
750  if( aName == m_pBitmapList->GetBitmap( i )->GetName() )
751  bDifferent = false;
752 
753  if( bDifferent ) {
754  nError = ERRCODE_NONE;
755  break;
756  }
757 
758  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pDialogFrameWeld, "cui/ui/queryduplicatedialog.ui"));
759  std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
760  if (xBox->run() != RET_OK)
761  break;
762  }
763 
764  pDlg.disposeAndClear();
765 
766  if( !nError )
767  {
768  m_pBitmapList->Insert(std::make_unique<XBitmapEntry>(aGraphic, aName), nCount);
769 
770  sal_Int32 nId = m_xBitmapLB->GetItemId( nCount - 1 );
771  BitmapEx aBitmap = m_pBitmapList->GetBitmapForPreview( nCount, m_xBitmapLB->GetIconSize() );
772 
773  m_xBitmapLB->InsertItem( nId + 1, Image(aBitmap), aName );
774  m_xBitmapLB->SelectItem( nId + 1 );
775  *m_pnBitmapListState |= ChangeType::MODIFIED;
776 
777  ModifyBitmapHdl(m_xBitmapLB.get());
778  }
779  }
780  else
781  {
782  // graphic couldn't be loaded
783  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pDialogFrameWeld, "cui/ui/querynoloadedfiledialog.ui"));
784  std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("NoLoadedFileDialog"));
785  xBox->run();
786  }
787  }
788 }
789 
790 sal_Int32 SvxBitmapTabPage::SearchBitmapList(const GraphicObject& rGraphicObject)
791 {
792  long nCount = m_pBitmapList->Count();
793  sal_Int32 nPos = LISTBOX_ENTRY_NOTFOUND;
794 
795  for(long i = 0;i < nCount;i++)
796  {
797  if(rGraphicObject.GetUniqueID() == m_pBitmapList->GetBitmap( i )->GetGraphicObject().GetUniqueID())
798  {
799  nPos = i;
800  break;
801  }
802  }
803  return nPos;
804 }
805 
806 sal_Int32 SvxBitmapTabPage::SearchBitmapList(const OUString& rBitmapName)
807 {
808  long nCount = m_pBitmapList->Count();
809  bool bValidBitmapName = true;
810  sal_Int32 nPos = LISTBOX_ENTRY_NOTFOUND;
811 
812  for(long i = 0;i < nCount && bValidBitmapName;i++)
813  {
814  if(rBitmapName == m_pBitmapList->GetBitmap( i )->GetName())
815  {
816  nPos = i;
817  bValidBitmapName = false;
818  }
819  }
820  return nPos;
821 }
822 
823 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
void SetFieldUnit(weld::MetricSpinButton &rField, FieldUnit eUnit, bool bAll)
std::unique_ptr< weld::CheckButton > m_xTsbScale
Definition: cuitabarea.hxx:516
FieldUnit
ErrCode GetGraphic(Graphic &) const
std::unique_ptr< weld::MetricSpinButton > m_xBitmapHeight
Definition: cuitabarea.hxx:518
Size getDrawPreviewOptimalSize(const OutputDevice &rReference)
std::unique_ptr< weld::ComboBox > m_xPositionLB
Definition: cuitabarea.hxx:520
TileOffset
Definition: tpbitmap.cxx:58
#define XATTR_FILLBMP_POSOFFSETX
std::string GetValue
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
BitmapStyle
Definition: tpbitmap.cxx:51
std::unique_ptr< weld::MetricSpinButton > m_xTileOffset
Definition: cuitabarea.hxx:526
long Height() const
#define VALUESET_ITEM_NOTFOUND
bool AreObjectsMarked() const
static SvxAbstractDialogFactory * Create()
void disposeAndClear()
sal_Int32 SearchBitmapList(const OUString &rBitmapName)
Definition: tpbitmap.cxx:806
sal_Int16 nId
OUString GetPath() const
TRISTATE_TRUE
XBitmapListRef m_pBitmapList
Definition: cuitabarea.hxx:496
static const SfxPoolItem * GetItem(const SfxItemSet &rSet, sal_uInt16 nSlot, bool bDeep=true)
#define LISTBOX_ENTRY_NOTFOUND
#define XATTR_FILLBMP_STRETCH
FieldUnit GetModuleFieldUnit(const SfxItemSet &rSet)
Put
SfxItemSet GetGeoAttrFromMarked() const
static OutputDevice * GetDefaultDevice()
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
RET_YES
OString GetUniqueID() const
SvxBitmapTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: tpbitmap.cxx:71
#define XATTR_FILLBMP_TILEOFFSETY
static SfxViewShell * Current()
std::unique_ptr< weld::Container > m_xTileOffBox
Definition: cuitabarea.hxx:524
TRISTATE_INDET
std::unique_ptr< weld::CustomWeld > m_xCtlBitmapPreview
Definition: cuitabarea.hxx:528
#define XATTR_FILLBMP_POSOFFSETY
#define XATTR_FILLBMP_SIZELOG
const GraphicObject & GetGraphicObject() const
#define XATTR_FILLBMP_POS
Size getPagePropertiesOptimalSize(const OutputDevice &rReference)
RectPoint
virtual ~SvxBitmapTabPage() override
Definition: tpbitmap.cxx:141
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define DBG_ASSERT(sCon, aError)
int i
TRISTATE_FALSE
int GetCoreValue(const weld::MetricSpinButton &rField, MapUnit eUnit)
#define XATTR_FILLBMP_SIZEX
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
std::unique_ptr< weld::ComboBox > m_xBitmapStyleLB
Definition: cuitabarea.hxx:514
void CalculateBitmapPresetSize()
Definition: tpbitmap.cxx:435
void SetAttributes(const SfxItemSet &rItemSet)
virtual bool FillItemSet(SfxItemSet *) override
Definition: tpbitmap.cxx:185
#define XATTR_FILLSTYLE
std::unique_ptr< SvxPresetListBox > m_xBitmapLB
Definition: cuitabarea.hxx:513
void SetMetricValue(weld::MetricSpinButton &rField, int nCoreValue, MapUnit eUnit)
IMPL_LINK_NOARG(SvxBitmapTabPage, ModifyBitmapHdl, SvtValueSet *, void)
Definition: tpbitmap.cxx:459
SfxItemPool * GetPool() const
virtual void Reset(const SfxItemSet *) override
Definition: tpbitmap.cxx:259
static const sal_uInt16 pBitmapRanges[]
Definition: cuitabarea.hxx:491
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
const SdrView * mpView
Definition: cuitabarea.hxx:505
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tpbitmap.cxx:153
std::unique_ptr< weld::CustomWeld > m_xBitmapLBWin
Definition: cuitabarea.hxx:529
std::unique_ptr< weld::ComboBox > m_xTileOffLB
Definition: cuitabarea.hxx:525
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tpbitmap.cxx:422
Point PixelToLogic(const Point &rDevicePt) const
SvxXRectPreview m_aCtlBitmapPreview
Definition: cuitabarea.hxx:512
#define XATTR_FILLBMP_SIZEY
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tpbitmap.cxx:176
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const Fraction & GetUIScale() const
std::unique_ptr< weld::MetricSpinButton > m_xPositionOffY
Definition: cuitabarea.hxx:523
#define XATTR_FILLBMP_TILE
virtual void GetName(OUString &rName)=0
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
#define ERRCODE_NONE
#define GetWhich(nSlot)
XFillAttrSetItem m_aXFillAttr
Definition: cuitabarea.hxx:503
RET_OK
std::unique_ptr< weld::MetricSpinButton > m_xPositionOffX
Definition: cuitabarea.hxx:522
const OUString PERCENT("Percent")
UnoViewSharedPtr mpView
virtual SdrView * GetDrawView() const
SfxItemSet & m_rXFSet
Definition: cuitabarea.hxx:504
DeactivateRC
OString const aName
#define XATTR_FILLBITMAP
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile)
#define XATTR_FILLBMP_TILEOFFSETX
#define SAL_WARN(area, stream)
std::unique_ptr< weld::MetricSpinButton > m_xBitmapWidth
Definition: cuitabarea.hxx:517
std::unique_ptr< weld::Button > m_xBtnImport
Definition: cuitabarea.hxx:527
TriState
double m_fObjectHeight
Definition: cuitabarea.hxx:500
sal_Int32 nPos
FieldUnit meFieldUnit
Definition: cuitabarea.hxx:507
void setWidth(long nWidth)
SdrModel * GetModel() const
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: tpbitmap.cxx:60
void ClickBitmapHdl_Impl()
Definition: tpbitmap.cxx:427
void setHeight(long nHeight)