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 
69 const sal_uInt16 SvxBitmapTabPage::pBitmapRanges[] =
70 {
71  SID_ATTR_TRANSFORM_WIDTH,
72  SID_ATTR_TRANSFORM_HEIGHT,
73  0
74 };
75 
77  : SfxTabPage(pPage, pController, "cui/ui/bitmaptabpage.ui", "BitmapTabPage", &rInAttrs)
78  , m_rOutAttrs(rInAttrs)
79  , m_pnBitmapListState(nullptr)
80  , m_fObjectWidth(0.0)
81  , m_fObjectHeight(0.0)
82  , m_bLogicalSize(false)
83  , m_aXFillAttr(rInAttrs.GetPool())
84  , m_rXFSet(m_aXFillAttr.GetItemSet())
85  , mpView(nullptr)
86  , m_xBitmapLB(new SvxPresetListBox(m_xBuilder->weld_scrolled_window("bitmapwin")))
87  , m_xBitmapStyleLB(m_xBuilder->weld_combo_box("bitmapstyle"))
88  , m_xSizeBox(m_xBuilder->weld_container("sizebox"))
89  , m_xTsbScale(m_xBuilder->weld_check_button("scaletsb"))
90  , m_xBitmapWidth(m_xBuilder->weld_metric_spin_button("width", FieldUnit::PERCENT))
91  , m_xBitmapHeight(m_xBuilder->weld_metric_spin_button("height", FieldUnit::PERCENT))
92  , m_xPositionBox(m_xBuilder->weld_container("posbox"))
93  , m_xPositionLB(m_xBuilder->weld_combo_box("positionlb"))
94  , m_xPositionOffBox(m_xBuilder->weld_container("posoffbox"))
95  , m_xPositionOffX(m_xBuilder->weld_metric_spin_button("posoffx", FieldUnit::PERCENT))
96  , m_xPositionOffY(m_xBuilder->weld_metric_spin_button("posoffy", FieldUnit::PERCENT))
97  , m_xTileOffBox(m_xBuilder->weld_container("tileoffbox"))
98  , m_xTileOffLB(m_xBuilder->weld_combo_box("tileofflb"))
99  , m_xTileOffset(m_xBuilder->weld_metric_spin_button("tileoffmtr", FieldUnit::PERCENT))
100  , m_xBtnImport(m_xBuilder->weld_button("BTN_IMPORT"))
101  , m_xCtlBitmapPreview(new weld::CustomWeld(*m_xBuilder, "CTL_BITMAP_PREVIEW", m_aCtlBitmapPreview))
102  , m_xBitmapLBWin(new weld::CustomWeld(*m_xBuilder, "BITMAP", *m_xBitmapLB))
103 {
104  // setting the output device
105  m_rXFSet.Put( XFillStyleItem(drawing::FillStyle_BITMAP) );
106  m_rXFSet.Put( XFillBitmapItem(OUString(), Graphic()) );
108 
109  m_xBitmapLB->SetSelectHdl( LINK(this, SvxBitmapTabPage, ModifyBitmapHdl) );
110  m_xBitmapLB->SetRenameHdl( LINK(this, SvxBitmapTabPage, ClickRenameHdl) );
111  m_xBitmapLB->SetDeleteHdl( LINK(this, SvxBitmapTabPage, ClickDeleteHdl) );
112  m_xBitmapStyleLB->connect_changed( LINK(this, SvxBitmapTabPage, ModifyBitmapStyleHdl) );
113  Link<weld::MetricSpinButton&, void> aLink1( LINK(this, SvxBitmapTabPage, ModifyBitmapSizeHdl) );
114  m_xBitmapWidth->connect_value_changed( aLink1 );
115  m_xBitmapHeight->connect_value_changed( aLink1 );
116  m_xTsbScale->connect_clicked(LINK(this, SvxBitmapTabPage, ClickScaleHdl));
117  m_xPositionLB->connect_changed( LINK( this, SvxBitmapTabPage, ModifyBitmapPositionHdl ) );
118  Link<weld::MetricSpinButton&, void> aLink( LINK( this, SvxBitmapTabPage, ModifyPositionOffsetHdl ) );
119  m_xPositionOffX->connect_value_changed(aLink);
120  m_xPositionOffY->connect_value_changed(aLink);
121  m_xTileOffset->connect_value_changed( LINK( this, SvxBitmapTabPage, ModifyTileOffsetHdl ) );
122  m_xBtnImport->connect_clicked( LINK(this, SvxBitmapTabPage, ClickImportHdl) );
124  m_xBtnImport->hide();
125 
126  // Calculate size of display boxes
127  Size aSize = getDrawPreviewOptimalSize(m_aCtlBitmapPreview.GetDrawingArea()->get_ref_device());
128  m_xBitmapLB->set_size_request(aSize.Width(), aSize.Height());
129  m_xCtlBitmapPreview->set_size_request(aSize.Width(), aSize.Height());
130 
131  SfxItemPool* pPool = m_rXFSet.GetPool();
133  meFieldUnit = GetModuleFieldUnit( rInAttrs );
136 
137  SfxViewShell* pViewShell = SfxViewShell::Current();
138  if( pViewShell )
139  mpView = pViewShell->GetDrawView();
140  DBG_ASSERT( mpView, "no valid view (!)" );
141 }
142 
144 {
145  m_xBitmapLBWin.reset();
146  m_xBitmapLB.reset();
147  m_xCtlBitmapPreview.reset();
148 }
149 
151 {
152  m_xBitmapLB->FillPresetListBox( *m_pBitmapList );
153 }
154 
156 {
157  XFillBitmapItem aItem( rSet.Get(XATTR_FILLBITMAP) );
158 
159  sal_Int32 nPos( 0 );
160  if ( !aItem.isPattern() )
161  {
162  nPos = SearchBitmapList( aItem.GetGraphicObject() );
163  if (nPos == -1)
164  return;
165  }
166  else
167  {
168  m_xBitmapWidth->set_value( 100, FieldUnit::NONE );
169  m_xBitmapHeight->set_value( 100, FieldUnit::NONE );
172  }
173 
174  sal_uInt16 nId = m_xBitmapLB->GetItemId( static_cast<size_t>( nPos ) );
175  m_xBitmapLB->SelectItem( nId );
176 }
177 
179 {
180  if( _pSet )
181  FillItemSet( _pSet );
182 
183  return DeactivateRC::LeavePage;
184 }
185 
186 
188 {
189  rAttrs->Put(XFillStyleItem(drawing::FillStyle_BITMAP));
190  size_t nPos = m_xBitmapLB->GetSelectItemPos();
191  if(VALUESET_ITEM_NOTFOUND != nPos)
192  {
193  const XBitmapEntry* pXBitmapEntry = m_pBitmapList->GetBitmap(nPos);
194  const OUString aString(m_xBitmapLB->GetItemText( m_xBitmapLB->GetSelectedItemId() ));
195  rAttrs->Put(XFillBitmapItem(aString, pXBitmapEntry->GetGraphicObject()));
196  }
197 
198  BitmapStyle eStylePos = static_cast<BitmapStyle>(m_xBitmapStyleLB->get_active());
199  bool bIsStretched( eStylePos == STRETCHED );
200  bool bIsTiled( eStylePos == TILED );
201 
202  rAttrs->Put( XFillBmpTileItem(bIsTiled) );
203  rAttrs->Put( XFillBmpStretchItem(bIsStretched) );
204 
205  if(!bIsStretched)
206  {
207  Size aSetBitmapSize;
208  switch(eStylePos)
209  {
210  case CUSTOM:
211  case TILED:
212  {
213  sal_Int64 nWidthPercent = m_xBitmapWidth->get_value(FieldUnit::NONE);
214  sal_Int64 nHeightPercent = m_xBitmapHeight->get_value(FieldUnit::NONE);
215  if (m_xTsbScale->get_sensitive() && m_xTsbScale->get_state() == TRISTATE_TRUE)
216  {
217  aSetBitmapSize.setWidth( -nWidthPercent );
218  aSetBitmapSize.setHeight( -nHeightPercent );
219  }
220  else if (!m_bLogicalSize)
221  {
222  aSetBitmapSize.setWidth( GetCoreValue(*m_xBitmapWidth, mePoolUnit) );
223  aSetBitmapSize.setHeight( GetCoreValue(*m_xBitmapHeight, mePoolUnit) );
224  }
225  else
226  {
227  rAttrs->Put( XFillBmpSizeLogItem(true) );
228  aSetBitmapSize.setWidth( 0 );
229  aSetBitmapSize.setHeight( 0 );
230  }
231 
232  break;
233  }
234  default:
235  break;
236  }
237 
238  rAttrs->Put( XFillBmpSizeXItem( aSetBitmapSize.Width() ) );
239  rAttrs->Put( XFillBmpSizeYItem( aSetBitmapSize.Height() ) );
240  }
241 
242  if (m_xPositionLB->get_sensitive())
243  rAttrs->Put( XFillBmpPosItem( static_cast<RectPoint>( m_xPositionLB->get_active() ) ) );
244  if (m_xPositionOffX->get_sensitive())
245  rAttrs->Put( XFillBmpPosOffsetXItem(m_xPositionOffX->get_value(FieldUnit::PERCENT)));
246  if (m_xPositionOffY->get_sensitive())
247  rAttrs->Put( XFillBmpPosOffsetYItem(m_xPositionOffY->get_value(FieldUnit::PERCENT)));
248  if (m_xTileOffBox->get_sensitive())
249  {
250  TileOffset eValue = static_cast<TileOffset>(m_xTileOffLB->get_active());
251  sal_uInt16 nOffsetValue = static_cast<sal_uInt16>(m_xTileOffset->get_value(FieldUnit::PERCENT));
252  sal_uInt16 nRowOff = (eValue == ROW) ? nOffsetValue : 0;
253  sal_uInt16 nColOff = (eValue == COLUMN) ? nOffsetValue : 0;
254  rAttrs->Put( XFillBmpTileOffsetXItem(nRowOff) );
255  rAttrs->Put( XFillBmpTileOffsetYItem(nColOff) );
256  }
257  return true;
258 }
259 
260 
261 void SvxBitmapTabPage::Reset( const SfxItemSet* rAttrs )
262 {
263  double transfWidth = 0.0;
264  double transfHeight = 0.0;
265  double fUIScale = 1.0;
266  if (mpView)
267  {
268  fUIScale = ( mpView->GetModel() ? double(mpView->GetModel()->GetUIScale()) : 1.0);
269 
270 
271  if (mpView->AreObjectsMarked())
272  {
274  transfWidth = static_cast<double>(GetItem( rGeoAttr, SID_ATTR_TRANSFORM_WIDTH )->GetValue());
275  transfHeight= static_cast<double>(GetItem( rGeoAttr, SID_ATTR_TRANSFORM_HEIGHT )->GetValue());
276  }
277  }
278  m_fObjectWidth = std::max( transfWidth, 1.0 );
279  m_fObjectHeight = std::max( transfHeight, 1.0 );
280  double fTmpWidth((OutputDevice::LogicToLogic(static_cast<sal_Int32>(m_fObjectWidth), mePoolUnit, MapUnit::Map100thMM )) / fUIScale);
281  m_fObjectWidth = fTmpWidth;
282 
283  double fTmpHeight((OutputDevice::LogicToLogic(static_cast<sal_Int32>(m_fObjectHeight), mePoolUnit, MapUnit::Map100thMM )) / fUIScale);
284  m_fObjectHeight = fTmpHeight;
285 
286  XFillBitmapItem aItem( rAttrs->Get(XATTR_FILLBITMAP) );
287 
288  if(!aItem.isPattern())
289  {
290  m_rXFSet.Put( aItem );
292  m_aCtlBitmapPreview.Invalidate();
293  }
294  else
295  m_xCtlBitmapPreview->set_sensitive(false);
296 
297  std::unique_ptr<GraphicObject> pGraphicObject;
298  pGraphicObject.reset( new GraphicObject(aItem.GetGraphicObject()) );
299 
300  BitmapEx aBmpEx(pGraphicObject->GetGraphic().GetBitmapEx());
301  Size aTempBitmapSize = aBmpEx.GetSizePixel();
302  rBitmapSize = Application::GetDefaultDevice()->PixelToLogic(aTempBitmapSize, MapMode(MapUnit::Map100thMM));
304 
305  bool bTiled = false; bool bStretched = false;
306  if(rAttrs->GetItemState( XATTR_FILLBMP_TILE ) != SfxItemState::DONTCARE)
307  bTiled = rAttrs->Get( XATTR_FILLBMP_TILE ).GetValue();
308  if(rAttrs->GetItemState( XATTR_FILLBMP_STRETCH ) != SfxItemState::DONTCARE)
309  bStretched = rAttrs->Get( XATTR_FILLBMP_STRETCH ).GetValue();
310 
311  if (bTiled)
312  m_xBitmapStyleLB->set_active(static_cast<sal_Int32>(TILED));
313  else if (bStretched)
314  m_xBitmapStyleLB->set_active(static_cast<sal_Int32>(STRETCHED));
315  else
316  m_xBitmapStyleLB->set_active(static_cast<sal_Int32>(CUSTOM));
317 
318  long nWidth = 0;
319  long nHeight = 0;
320 
321  if(rAttrs->GetItemState(XATTR_FILLBMP_SIZELOG) != SfxItemState::DONTCARE)
322  {
323  if (rAttrs->Get( XATTR_FILLBMP_SIZELOG ).GetValue())
324  {
325  m_xTsbScale->set_state(TRISTATE_FALSE);
326  m_bLogicalSize = true;
327  }
328  else
329  {
330  m_xTsbScale->set_state(TRISTATE_TRUE);
331  m_bLogicalSize = false;
332  }
333  }
334  else
335  m_xTsbScale->set_state(TRISTATE_INDET);
336 
337  TriState eRelative = TRISTATE_FALSE;
338  if(rAttrs->GetItemState(XATTR_FILLBMP_SIZEX) != SfxItemState::DONTCARE)
339  {
340  nWidth = static_cast<const XFillBmpSizeXItem&>( rAttrs->Get( XATTR_FILLBMP_SIZEX ) ).GetValue();
341  if(nWidth == 0)
342  nWidth = rBitmapSize.Width();
343  else if(nWidth < 0)
344  {
345  eRelative = TRISTATE_TRUE;
346  nWidth = std::abs(nWidth);
347  }
348  }
349 
350  if(rAttrs->GetItemState( XATTR_FILLBMP_SIZEY ) != SfxItemState::DONTCARE)
351  {
352  nHeight = rAttrs->Get( XATTR_FILLBMP_SIZEY ).GetValue();
353  if(nHeight == 0)
354  nHeight = rBitmapSize.Height();
355  else if(nHeight < 0)
356  {
357  eRelative = TRISTATE_TRUE;
358  nHeight = std::abs(nHeight);
359  }
360  }
361  m_xTsbScale->set_state(eRelative);
362  ClickScaleHdl(*m_xTsbScale);
363 
364 
365  if(!rBitmapSize.IsEmpty())
366  {
367  if (eRelative == TRISTATE_TRUE)
368  {
369  m_xBitmapWidth->set_value(nWidth, FieldUnit::NONE);
370  m_xBitmapHeight->set_value(nHeight, FieldUnit::NONE);
371  }
372  else
373  {
376  }
377  }
378 
379  if( rAttrs->GetItemState( XATTR_FILLBMP_POS ) != SfxItemState::DONTCARE )
380  {
381  RectPoint eValue = rAttrs->Get( XATTR_FILLBMP_POS ).GetValue();
382  m_xPositionLB->set_active( static_cast< sal_Int32 >(eValue) );
383  }
384 
385  if( rAttrs->GetItemState( XATTR_FILLBMP_POSOFFSETX ) != SfxItemState::DONTCARE )
386  {
387  sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_POSOFFSETX ).GetValue();
388  m_xPositionOffX->set_value(nValue, FieldUnit::PERCENT);
389  }
390  else
391  m_xPositionOffX->set_text("");
392 
393  if( rAttrs->GetItemState( XATTR_FILLBMP_POSOFFSETY ) != SfxItemState::DONTCARE )
394  {
395  sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_POSOFFSETY ).GetValue();
396  m_xPositionOffY->set_value(nValue, FieldUnit::PERCENT);
397  }
398  else
399  m_xPositionOffY->set_text("");
400 
401  if( rAttrs->GetItemState( XATTR_FILLBMP_TILEOFFSETX ) != SfxItemState::DONTCARE)
402  {
403  sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_TILEOFFSETX ).GetValue();
404  if(nValue > 0)
405  {
406  m_xTileOffLB->set_active(static_cast<sal_Int32>(ROW));
407  m_xTileOffset->set_value(nValue, FieldUnit::PERCENT);
408  }
409  }
410 
411  if( rAttrs->GetItemState( XATTR_FILLBMP_TILEOFFSETY ) != SfxItemState::DONTCARE )
412  {
413  sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_TILEOFFSETY ).GetValue();
414  if(nValue > 0)
415  {
416  m_xTileOffLB->set_active(static_cast<sal_Int32>(COLUMN));
417  m_xTileOffset->set_value(nValue, FieldUnit::PERCENT);
418  }
419  }
420 
422 }
423 
424 std::unique_ptr<SfxTabPage> SvxBitmapTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrs)
425 {
426  return std::make_unique<SvxBitmapTabPage>(pPage, pController, *rAttrs);
427 }
428 
430 {
431  m_xBitmapLBWin->set_sensitive(true);
432  m_xCtlBitmapPreview->set_sensitive(true);
433 
434  ModifyBitmapHdl(m_xBitmapLB.get());
435 }
436 
438 {
439  if(rBitmapSize.IsEmpty())
440  return;
441 
442  long nObjectWidth = static_cast<long>(m_fObjectWidth);
443  long nObjectHeight = static_cast<long>(m_fObjectHeight);
444 
445  if(std::abs(rBitmapSize.Width() - nObjectWidth) < std::abs(rBitmapSize.Height() - nObjectHeight))
446  {
447  rFilledSize.setWidth( nObjectWidth );
450  rZoomedSize.setHeight( nObjectHeight );
451  }
452  else
453  {
455  rFilledSize.setHeight( nObjectHeight );
456  rZoomedSize.setWidth( nObjectWidth );
458  }
459 }
460 
461 IMPL_LINK_NOARG(SvxBitmapTabPage, ModifyBitmapHdl, ValueSet*, void)
462 {
463  std::unique_ptr<GraphicObject> pGraphicObject;
464  size_t nPos = m_xBitmapLB->GetSelectItemPos();
465 
466  if( nPos != VALUESET_ITEM_NOTFOUND )
467  {
468  pGraphicObject.reset(new GraphicObject(m_pBitmapList->GetBitmap( static_cast<sal_uInt16>(nPos) )->GetGraphicObject()));
469  }
470  else
471  {
472  const SfxPoolItem* pPoolItem = nullptr;
473 
474  if(SfxItemState::SET == m_rOutAttrs.GetItemState(GetWhich(XATTR_FILLSTYLE), true, &pPoolItem))
475  {
476  const drawing::FillStyle eXFS(static_cast<const XFillStyleItem*>(pPoolItem)->GetValue());
477 
478  if((drawing::FillStyle_BITMAP == eXFS) && (SfxItemState::SET == m_rOutAttrs.GetItemState(GetWhich(XATTR_FILLBITMAP), true, &pPoolItem)))
479  {
480  pGraphicObject.reset(new GraphicObject(static_cast<const XFillBitmapItem*>(pPoolItem)->GetGraphicObject()));
481  }
482  }
483 
484  if(!pGraphicObject)
485  {
486  sal_uInt16 nId = m_xBitmapLB->GetItemId(0);
487  m_xBitmapLB->SelectItem(nId);
488 
489  if(0 != nId)
490  {
491  pGraphicObject.reset(new GraphicObject(m_pBitmapList->GetBitmap(0)->GetGraphicObject()));
492  }
493  }
494  }
495 
496  if(pGraphicObject)
497  {
498  BitmapEx aBmpEx(pGraphicObject->GetGraphic().GetBitmapEx());
499  Size aTempBitmapSize = aBmpEx.GetSizePixel();
500  const double fUIScale = ( (mpView && mpView->GetModel()) ? double(mpView->GetModel()->GetUIScale()) : 1.0);
501 
502  rBitmapSize.setWidth( (OutputDevice::LogicToLogic(static_cast<sal_Int32>(aTempBitmapSize.Width()),MapUnit::MapPixel, MapUnit::Map100thMM )) / fUIScale );
503  rBitmapSize.setHeight( (OutputDevice::LogicToLogic(static_cast<sal_Int32>(aTempBitmapSize.Height()),MapUnit::MapPixel, MapUnit::Map100thMM )) / fUIScale );
504  CalculateBitmapPresetSize();
505  ModifyBitmapStyleHdl( *m_xBitmapStyleLB );
506  ModifyBitmapPositionHdl( *m_xPositionLB );
507 
508  m_rXFSet.ClearItem(XATTR_FILLBITMAP);
509  m_rXFSet.Put(XFillStyleItem(drawing::FillStyle_BITMAP));
510  m_rXFSet.Put(XFillBitmapItem(OUString(), *pGraphicObject));
511 
512  m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
513  m_aCtlBitmapPreview.Invalidate();
514  }
515  else
516  {
517  SAL_WARN("cui.tabpages", "SvxBitmapTabPage::ModifyBitmapHdl(): null pGraphicObject");
518  }
519 
520 }
521 
523 {
524  sal_uInt16 nId = m_xBitmapLB->GetSelectedItemId();
525  size_t nPos = m_xBitmapLB->GetSelectItemPos();
526 
527  if( nPos == VALUESET_ITEM_NOTFOUND )
528  return;
529 
530  OUString aDesc( CuiResId( RID_SVXSTR_DESC_NEW_BITMAP ) );
531  OUString aName( m_pBitmapList->GetBitmap( nPos )->GetName() );
532 
534  ScopedVclPtr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog(GetFrameWeld(), aName, aDesc));
535 
536  bool bLoop = true;
537  while( bLoop && pDlg->Execute() == RET_OK )
538  {
539  pDlg->GetName( aName );
540  sal_Int32 nBitmapPos = SearchBitmapList( aName );
541  bool bValidBitmapName = (nBitmapPos == static_cast<sal_Int32>(nPos) ) || (nBitmapPos == -1);
542 
543  if(bValidBitmapName)
544  {
545  bLoop = false;
546  m_pBitmapList->GetBitmap(nPos)->SetName(aName);
547 
548  m_xBitmapLB->SetItemText(nId, aName);
549  m_xBitmapLB->SelectItem( nId );
550 
551  *m_pnBitmapListState |= ChangeType::MODIFIED;
552  }
553  else
554  {
555  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
556  std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
557  xBox->run();
558  }
559  }
560 }
561 
563 {
564  sal_uInt16 nId = m_xBitmapLB->GetSelectedItemId();
565  size_t nPos = m_xBitmapLB->GetSelectItemPos();
566 
567  if( nPos == VALUESET_ITEM_NOTFOUND )
568  return;
569 
570  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/querydeletebitmapdialog.ui"));
571  std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog("AskDelBitmapDialog"));
572 
573  if (xQueryBox->run() == RET_YES)
574  {
575  m_pBitmapList->Remove( static_cast<sal_uInt16>(nPos) );
576  m_xBitmapLB->RemoveItem( nId );
577  nId = m_xBitmapLB->GetItemId(0);
578  m_xBitmapLB->SelectItem( nId );
579 
580  m_aCtlBitmapPreview.Invalidate();
581  ModifyBitmapHdl(m_xBitmapLB.get());
582  *m_pnBitmapListState |= ChangeType::MODIFIED;
583  }
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_SVXSTR_ADD_IMAGE), pDialogFrameWeld);
722  aDlg.EnableLink(false);
723  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_SVXSTR_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( 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  long nCount = m_pBitmapList->Count();
795  sal_Int32 nPos = -1;
796 
797  for(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(const OUString& rBitmapName)
809 {
810  long nCount = m_pBitmapList->Count();
811  bool bValidBitmapName = true;
812  sal_Int32 nPos = -1;
813 
814  for(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: */
long Width() const
void SetFieldUnit(weld::MetricSpinButton &rField, FieldUnit eUnit, bool bAll)
std::unique_ptr< weld::CheckButton > m_xTsbScale
Definition: cuitabarea.hxx:515
URL aURL
FieldUnit
ErrCode GetGraphic(Graphic &) const
std::unique_ptr< weld::MetricSpinButton > m_xBitmapHeight
Definition: cuitabarea.hxx:517
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:519
TileOffset
Definition: tpbitmap.cxx:61
std::string GetValue
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:525
long Height() const
#define VALUESET_ITEM_NOTFOUND
constexpr TypedWhichId< SfxMetricItem > XATTR_FILLBMP_SIZEX(XATTR_FILL_FIRST+9)
bool AreObjectsMarked() const
static SvxAbstractDialogFactory * Create()
void disposeAndClear()
constexpr TypedWhichId< XFillStyleItem > XATTR_FILLSTYLE(XATTR_FILL_FIRST)
sal_Int32 SearchBitmapList(const OUString &rBitmapName)
Definition: tpbitmap.cxx:808
sal_Int16 nId
OUString GetPath() const
TRISTATE_TRUE
XBitmapListRef m_pBitmapList
Definition: cuitabarea.hxx:495
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()
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:76
int nCount
static SfxViewShell * Current()
IMPL_LINK_NOARG(SvxBitmapTabPage, ModifyBitmapHdl, ValueSet *, void)
Definition: tpbitmap.cxx:461
std::unique_ptr< weld::Container > m_xTileOffBox
Definition: cuitabarea.hxx:523
TRISTATE_INDET
std::unique_ptr< weld::CustomWeld > m_xCtlBitmapPreview
Definition: cuitabarea.hxx:527
const GraphicObject & GetGraphicObject() const
RectPoint
virtual ~SvxBitmapTabPage() override
Definition: tpbitmap.cxx:143
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:513
void CalculateBitmapPresetSize()
Definition: tpbitmap.cxx:437
void SetAttributes(const SfxItemSet &rItemSet)
virtual bool FillItemSet(SfxItemSet *) override
Definition: tpbitmap.cxx:187
std::unique_ptr< SvxPresetListBox > m_xBitmapLB
Definition: cuitabarea.hxx:512
void SetMetricValue(weld::MetricSpinButton &rField, int nCoreValue, MapUnit eUnit)
SfxItemPool * GetPool() const
virtual void Reset(const SfxItemSet *) override
Definition: tpbitmap.cxx:261
static const sal_uInt16 pBitmapRanges[]
Definition: cuitabarea.hxx:490
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
const SdrView * mpView
Definition: cuitabarea.hxx:504
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tpbitmap.cxx:155
std::unique_ptr< weld::CustomWeld > m_xBitmapLBWin
Definition: cuitabarea.hxx:528
std::unique_ptr< weld::ComboBox > m_xTileOffLB
Definition: cuitabarea.hxx:524
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tpbitmap.cxx:424
Point PixelToLogic(const Point &rDevicePt) const
SvxXRectPreview m_aCtlBitmapPreview
Definition: cuitabarea.hxx:511
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tpbitmap.cxx:178
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const Fraction & GetUIScale() const
std::unique_ptr< weld::MetricSpinButton > m_xPositionOffY
Definition: cuitabarea.hxx:522
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
#define GetWhich(nSlot)
XFillAttrSetItem m_aXFillAttr
Definition: cuitabarea.hxx:502
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:521
const OUString PERCENT("Percent")
constexpr TypedWhichId< XFillBmpSizeLogItem > XATTR_FILLBMP_SIZELOG(XATTR_FILL_FIRST+13)
UnoViewSharedPtr mpView
virtual SdrView * GetDrawView() const
SfxItemSet & m_rXFSet
Definition: cuitabarea.hxx:503
DeactivateRC
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile)
#define SAL_WARN(area, stream)
std::unique_ptr< weld::MetricSpinButton > m_xBitmapWidth
Definition: cuitabarea.hxx:516
std::unique_ptr< weld::Button > m_xBtnImport
Definition: cuitabarea.hxx:526
constexpr TypedWhichId< XFillBmpTileOffsetXItem > XATTR_FILLBMP_TILEOFFSETX(XATTR_FILL_FIRST+14)
TriState
double m_fObjectHeight
Definition: cuitabarea.hxx:499
constexpr TypedWhichId< XFillBmpSizeYItem > XATTR_FILLBMP_SIZEY(XATTR_FILL_FIRST+10)
FieldUnit meFieldUnit
Definition: cuitabarea.hxx:506
void setWidth(long nWidth)
SdrModel * GetModel() const
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
sal_uInt16 nPos
void ClickBitmapHdl_Impl()
Definition: tpbitmap.cxx:429
sal_Int16 nValue
void setHeight(long nHeight)