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
50using namespace com::sun::star;
51
52namespace {
53
54enum BitmapStyle
55{
56 CUSTOM,
57 TILED,
58 STRETCHED
59};
60
61enum TileOffset
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{
153
154 sal_Int32 nPos( 0 );
155 if ( !aItem.isPattern() )
156 {
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();
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) );
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
257{
258 double transfWidth = 0.0;
259 double transfHeight = 0.0;
260 double fUIScale = 1.0;
261 if (mpView)
262 {
263 fUIScale = double(mpView->GetModel().GetUIScale());
264
265
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 m_xTsbScale->set_state(TRISTATE_FALSE);
320 else
321 m_xTsbScale->set_state(TRISTATE_TRUE);
322 }
323 else
324 m_xTsbScale->set_state(TRISTATE_INDET);
325
326 TriState eRelative = TRISTATE_FALSE;
327 if(rAttrs->GetItemState(XATTR_FILLBMP_SIZEX) != SfxItemState::DONTCARE)
328 {
329 nWidth = static_cast<const XFillBmpSizeXItem&>( rAttrs->Get( XATTR_FILLBMP_SIZEX ) ).GetValue();
330 if(nWidth == 0)
331 nWidth = rBitmapSize.Width();
332 else if(nWidth < 0)
333 {
334 m_bLogicalSize = true;
335 eRelative = TRISTATE_TRUE;
336 nWidth = std::abs(nWidth);
337 }
338 }
339
340 if(rAttrs->GetItemState( XATTR_FILLBMP_SIZEY ) != SfxItemState::DONTCARE)
341 {
342 nHeight = rAttrs->Get( XATTR_FILLBMP_SIZEY ).GetValue();
343 if(nHeight == 0)
344 nHeight = rBitmapSize.Height();
345 else if(nHeight < 0)
346 {
347 m_bLogicalSize = true;
348 eRelative = TRISTATE_TRUE;
349 nHeight = std::abs(nHeight);
350 }
351 }
352 m_xTsbScale->set_state(eRelative);
353 ClickScaleHdl(*m_xTsbScale);
354
355
356 if(!rBitmapSize.IsEmpty())
357 {
358 if (eRelative == TRISTATE_TRUE)
359 {
360 m_xBitmapWidth->set_value(nWidth, FieldUnit::NONE);
361 m_xBitmapHeight->set_value(nHeight, FieldUnit::NONE);
362 }
363 else
364 {
367 }
368 }
369
370 if( rAttrs->GetItemState( XATTR_FILLBMP_POS ) != SfxItemState::DONTCARE )
371 {
372 RectPoint eValue = rAttrs->Get( XATTR_FILLBMP_POS ).GetValue();
373 m_xPositionLB->set_active( static_cast< sal_Int32 >(eValue) );
374 }
375
376 if( rAttrs->GetItemState( XATTR_FILLBMP_POSOFFSETX ) != SfxItemState::DONTCARE )
377 {
378 sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_POSOFFSETX ).GetValue();
379 m_xPositionOffX->set_value(nValue, FieldUnit::PERCENT);
380 }
381 else
382 m_xPositionOffX->set_text("");
383
384 if( rAttrs->GetItemState( XATTR_FILLBMP_POSOFFSETY ) != SfxItemState::DONTCARE )
385 {
386 sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_POSOFFSETY ).GetValue();
387 m_xPositionOffY->set_value(nValue, FieldUnit::PERCENT);
388 }
389 else
390 m_xPositionOffY->set_text("");
391
392 if( rAttrs->GetItemState( XATTR_FILLBMP_TILEOFFSETX ) != SfxItemState::DONTCARE)
393 {
394 sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_TILEOFFSETX ).GetValue();
395 if(nValue > 0)
396 {
397 m_xTileOffLB->set_active(static_cast<sal_Int32>(ROW));
398 m_xTileOffset->set_value(nValue, FieldUnit::PERCENT);
399 }
400 }
401
402 if( rAttrs->GetItemState( XATTR_FILLBMP_TILEOFFSETY ) != SfxItemState::DONTCARE )
403 {
404 sal_Int32 nValue = rAttrs->Get( XATTR_FILLBMP_TILEOFFSETY ).GetValue();
405 if(nValue > 0)
406 {
407 m_xTileOffLB->set_active(static_cast<sal_Int32>(COLUMN));
408 m_xTileOffset->set_value(nValue, FieldUnit::PERCENT);
409 }
410 }
411
413}
414
415std::unique_ptr<SfxTabPage> SvxBitmapTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrs)
416{
417 return std::make_unique<SvxBitmapTabPage>(pPage, pController, *rAttrs);
418}
419
421{
422 m_xBitmapLBWin->set_sensitive(true);
423 m_xCtlBitmapPreview->set_sensitive(true);
424
425 ModifyBitmapHdl(m_xBitmapLB.get());
426}
427
429{
430 if(rBitmapSize.IsEmpty())
431 return;
432
433 tools::Long nObjectWidth = static_cast<tools::Long>(m_fObjectWidth);
434 tools::Long nObjectHeight = static_cast<tools::Long>(m_fObjectHeight);
435
436 if(std::abs(rBitmapSize.Width() - nObjectWidth) < std::abs(rBitmapSize.Height() - nObjectHeight))
437 {
438 rFilledSize.setWidth( nObjectWidth );
441 rZoomedSize.setHeight( nObjectHeight );
442 }
443 else
444 {
446 rFilledSize.setHeight( nObjectHeight );
447 rZoomedSize.setWidth( nObjectWidth );
449 }
450}
451
453{
454 std::unique_ptr<GraphicObject> pGraphicObject;
455 size_t nPos = m_xBitmapLB->GetSelectItemPos();
456
458 {
459 pGraphicObject.reset(new GraphicObject(m_pBitmapList->GetBitmap( static_cast<sal_uInt16>(nPos) )->GetGraphicObject()));
460 }
461 else
462 {
463 if(const XFillStyleItem* pFillStyleItem = m_rOutAttrs.GetItemIfSet(GetWhich(XATTR_FILLSTYLE)))
464 {
465 const drawing::FillStyle eXFS(pFillStyleItem->GetValue());
466
467 const XFillBitmapItem* pBitmapItem;
468 if((drawing::FillStyle_BITMAP == eXFS) && (pBitmapItem = m_rOutAttrs.GetItemIfSet(GetWhich(XATTR_FILLBITMAP))))
469 {
470 pGraphicObject.reset(new GraphicObject(pBitmapItem->GetGraphicObject()));
471 }
472 }
473
474 if(!pGraphicObject)
475 {
476 sal_uInt16 nId = m_xBitmapLB->GetItemId(0);
477 m_xBitmapLB->SelectItem(nId);
478
479 if(0 != nId)
480 {
481 pGraphicObject.reset(new GraphicObject(m_pBitmapList->GetBitmap(0)->GetGraphicObject()));
482 }
483 }
484 }
485
486 if(pGraphicObject)
487 {
488 BitmapEx aBmpEx(pGraphicObject->GetGraphic().GetBitmapEx());
489 Size aTempBitmapSize = aBmpEx.GetSizePixel();
490 const double fUIScale = mpView ? double(mpView->GetModel().GetUIScale()) : 1.0;
491 Size aBitmapSize100mm = o3tl::convert(aTempBitmapSize, o3tl::Length::pt, o3tl::Length::mm100);
492
493 rBitmapSize.setWidth(aBitmapSize100mm.Width() / fUIScale);
494 rBitmapSize.setHeight(aBitmapSize100mm.Height() / fUIScale);
495 CalculateBitmapPresetSize();
496 ModifyBitmapStyleHdl( *m_xBitmapStyleLB );
497 ModifyBitmapPositionHdl( *m_xPositionLB );
498
499 m_rXFSet.ClearItem(XATTR_FILLBITMAP);
500 m_rXFSet.Put(XFillStyleItem(drawing::FillStyle_BITMAP));
501 m_rXFSet.Put(XFillBitmapItem(OUString(), *pGraphicObject));
502
503 m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
504 m_aCtlBitmapPreview.Invalidate();
505 }
506 else
507 {
508 SAL_WARN("cui.tabpages", "SvxBitmapTabPage::ModifyBitmapHdl(): null pGraphicObject");
509 }
510
511}
512
514{
515 sal_uInt16 nId = m_xBitmapLB->GetSelectedItemId();
516 size_t nPos = m_xBitmapLB->GetSelectItemPos();
517
519 return;
520
521 OUString aDesc( CuiResId( RID_CUISTR_DESC_NEW_BITMAP ) );
522 OUString aName( m_pBitmapList->GetBitmap( nPos )->GetName() );
523
526
527 bool bLoop = true;
528 while( bLoop && pDlg->Execute() == RET_OK )
529 {
530 pDlg->GetName( aName );
531 sal_Int32 nBitmapPos = SearchBitmapList( aName );
532 bool bValidBitmapName = (nBitmapPos == static_cast<sal_Int32>(nPos) ) || (nBitmapPos == -1);
533
534 if(bValidBitmapName)
535 {
536 bLoop = false;
537 m_pBitmapList->GetBitmap(nPos)->SetName(aName);
538
539 m_xBitmapLB->SetItemText(nId, aName);
540 m_xBitmapLB->SelectItem( nId );
541
542 *m_pnBitmapListState |= ChangeType::MODIFIED;
543 }
544 else
545 {
546 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
547 std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
548 xBox->run();
549 }
550 }
551}
552
554{
555 sal_uInt16 nId = m_xBitmapLB->GetSelectedItemId();
556 size_t nPos = m_xBitmapLB->GetSelectItemPos();
557
559 return;
560
561 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/querydeletebitmapdialog.ui"));
562 std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog("AskDelBitmapDialog"));
563
564 if (xQueryBox->run() != RET_YES)
565 return;
566
567 sal_uInt16 nNextId = m_xBitmapLB->GetItemId(nPos + 1);
568 if (!nNextId)
569 nNextId = m_xBitmapLB->GetItemId(nPos - 1);
570
571 m_pBitmapList->Remove( static_cast<sal_uInt16>(nPos) );
572 m_xBitmapLB->RemoveItem( nId );
573
574 m_xBitmapLB->SelectItem(nNextId);
575
576 m_aCtlBitmapPreview.Invalidate();
577 ModifyBitmapHdl(m_xBitmapLB.get());
578 *m_pnBitmapListState |= ChangeType::MODIFIED;
579}
580
582{
583 m_bLogicalSize = false;
584 if (m_xTsbScale->get_state() != TRISTATE_TRUE && static_cast<BitmapStyle>(m_xBitmapStyleLB->get_active()) != TILED)
585 {
586 sal_Int64 nWidthPercent = m_xBitmapWidth->denormalize(m_xBitmapWidth->get_value(FieldUnit::NONE));
587 sal_Int64 nHeightPercent = m_xBitmapHeight->denormalize(m_xBitmapHeight->get_value(FieldUnit::NONE));
588 if (nWidthPercent == 100 && nHeightPercent == 100)
589 m_xBitmapStyleLB->set_active(static_cast<sal_Int32>(CUSTOM));
590 }
591 ModifyBitmapStyleHdl(*m_xBitmapStyleLB);
592
593 m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
594 m_aCtlBitmapPreview.Invalidate();
595}
596
598{
599 if (m_xTsbScale->get_state() == TRISTATE_TRUE)
600 {
601 m_xBitmapWidth->set_digits( 0 );
602 m_xBitmapWidth->set_unit(FieldUnit::PERCENT);
603 m_xBitmapWidth->set_value(100, FieldUnit::NONE);
604 m_xBitmapWidth->set_range(0, 100, FieldUnit::NONE);
605
606 m_xBitmapHeight->set_digits( 0 );
607 m_xBitmapHeight->set_unit(FieldUnit::PERCENT);
608 m_xBitmapHeight->set_value(100, FieldUnit::NONE);
609 m_xBitmapHeight->set_range(0, 100, FieldUnit::NONE);
610 }
611 else
612 {
613 m_xBitmapWidth->set_digits( 2 );
614 m_xBitmapWidth->set_unit(meFieldUnit);
615 m_xBitmapWidth->set_value(100, FieldUnit::NONE);
616 m_xBitmapWidth->set_range(0, 999900, FieldUnit::NONE);
617
618 m_xBitmapHeight->set_digits( 2 );
619 m_xBitmapHeight->set_unit(meFieldUnit);
620 m_xBitmapHeight->set_value(100, FieldUnit::NONE);
621 m_xBitmapHeight->set_range(0, 999900, FieldUnit::NONE);
622 }
623
624 ModifyBitmapStyleHdl( *m_xBitmapStyleLB );
625}
626
627IMPL_LINK_NOARG( SvxBitmapTabPage, ModifyBitmapStyleHdl, weld::ComboBox&, void )
628{
629 BitmapStyle eStylePos = static_cast<BitmapStyle>(m_xBitmapStyleLB->get_active());
630 bool bIsStretched( eStylePos == STRETCHED );
631 bool bIsTiled( eStylePos == TILED );
632
633 m_xSizeBox->set_sensitive( !bIsStretched );
634 m_xPositionBox->set_sensitive( !bIsStretched );
635 m_xPositionOffBox->set_sensitive( bIsTiled );
636 m_xTileOffBox->set_sensitive( bIsTiled );
637
638 m_rXFSet.Put( XFillBmpTileItem( bIsTiled ) );
639 m_rXFSet.Put( XFillBmpStretchItem( bIsStretched ) );
640
641 if(!bIsStretched)
642 {
643 Size aSetBitmapSize;
644 switch(eStylePos)
645 {
646 case CUSTOM:
647 case TILED:
648 {
649 if (m_xTsbScale->get_sensitive() && m_xTsbScale->get_state() == TRISTATE_TRUE)
650 {
651 aSetBitmapSize.setWidth(-m_xBitmapWidth->get_value(FieldUnit::NONE));
652 aSetBitmapSize.setHeight(-m_xBitmapHeight->get_value(FieldUnit::NONE));
653 }
654 else
655 {
656 aSetBitmapSize.setWidth( GetCoreValue( *m_xBitmapWidth, mePoolUnit ) );
657 aSetBitmapSize.setHeight( GetCoreValue( *m_xBitmapHeight, mePoolUnit ) );
658 }
659 }
660 break;
661 default:
662 break;
663 }
664
665 m_rXFSet.Put( XFillBmpSizeXItem( aSetBitmapSize.Width() ) );
666 m_rXFSet.Put( XFillBmpSizeYItem( aSetBitmapSize.Height() ) );
667 }
668
669 m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
670 m_aCtlBitmapPreview.Invalidate();
671}
672
673IMPL_LINK_NOARG(SvxBitmapTabPage, ModifyBitmapPositionHdl, weld::ComboBox&, void)
674{
675 if (m_xPositionLB->get_sensitive())
676 m_rXFSet.Put( XFillBmpPosItem( static_cast< RectPoint >( m_xPositionLB->get_active() ) ) );
677
678 m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
679 m_aCtlBitmapPreview.Invalidate();
680}
681
683{
684 if (m_xPositionOffX->get_sensitive())
685 m_rXFSet.Put( XFillBmpPosOffsetXItem( m_xPositionOffX->get_value(FieldUnit::PERCENT) ) );
686
687 if (m_xPositionOffY->get_sensitive())
688 m_rXFSet.Put( XFillBmpPosOffsetYItem( m_xPositionOffY->get_value(FieldUnit::PERCENT) ) );
689
690 m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
691 m_aCtlBitmapPreview.Invalidate();
692}
693
695{
696 sal_uInt16 nTileXOff = 0;
697 sal_uInt16 nTileYOff = 0;
698
699 if(m_xTileOffLB->get_active() == static_cast<sal_Int32>(ROW))
700 nTileXOff = m_xTileOffset->get_value(FieldUnit::PERCENT);
701
702 if(m_xTileOffLB->get_active() == static_cast<sal_Int32>(COLUMN))
703 nTileYOff = m_xTileOffset->get_value(FieldUnit::PERCENT);
704
705 m_rXFSet.Put( XFillBmpTileOffsetXItem(nTileXOff) );
706 m_rXFSet.Put( XFillBmpTileOffsetYItem(nTileYOff) );
707
708 m_aCtlBitmapPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
709 m_aCtlBitmapPreview.Invalidate();
710}
711
713{
714 weld::Window* pDialogFrameWeld = GetFrameWeld();
715
716 SvxOpenGraphicDialog aDlg(CuiResId(RID_CUISTR_ADD_IMAGE), pDialogFrameWeld);
717 aDlg.EnableLink(false);
718 tools::Long nCount = m_pBitmapList->Count();
719
720 if( aDlg.Execute() )
721 return;
722
723 Graphic aGraphic;
724
725 std::unique_ptr<weld::WaitObject> xWait(new weld::WaitObject(pDialogFrameWeld));
726 ErrCode nError = aDlg.GetGraphic( aGraphic );
727 xWait.reset();
728
729 if( !nError )
730 {
731 OUString aDesc(CuiResId(RID_CUISTR_DESC_EXT_BITMAP));
732
733 // convert file URL to UI name
734 OUString aName;
735 INetURLObject aURL( aDlg.GetPath() );
738 pDialogFrameWeld, aURL.GetLastName().getToken(0, '.'), aDesc));
739 nError = ErrCode(1);
740
741 while( pDlg->Execute() == RET_OK )
742 {
743 pDlg->GetName( aName );
744
745 bool bDifferent = true;
746
747 for( tools::Long i = 0; i < nCount && bDifferent; i++ )
748 if( aName == m_pBitmapList->GetBitmap( i )->GetName() )
749 bDifferent = false;
750
751 if( bDifferent ) {
752 nError = ERRCODE_NONE;
753 break;
754 }
755
756 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pDialogFrameWeld, "cui/ui/queryduplicatedialog.ui"));
757 std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
758 if (xBox->run() != RET_OK)
759 break;
760 }
761
762 pDlg.disposeAndClear();
763
764 if( !nError )
765 {
766 m_pBitmapList->Insert(std::make_unique<XBitmapEntry>(aGraphic, aName), nCount);
767
768 sal_Int32 nId = m_xBitmapLB->GetItemId( nCount - 1 );
769 BitmapEx aBitmap = m_pBitmapList->GetBitmapForPreview( nCount, m_xBitmapLB->GetIconSize() );
770
771 m_xBitmapLB->InsertItem( nId + 1, Image(aBitmap), aName );
772 m_xBitmapLB->SelectItem( nId + 1 );
773 *m_pnBitmapListState |= ChangeType::MODIFIED;
774
775 ModifyBitmapHdl(m_xBitmapLB.get());
776 }
777 }
778 else
779 {
780 // graphic couldn't be loaded
781 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pDialogFrameWeld, "cui/ui/querynoloadedfiledialog.ui"));
782 std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("NoLoadedFileDialog"));
783 xBox->run();
784 }
785}
786
787sal_Int32 SvxBitmapTabPage::SearchBitmapList(const GraphicObject& rGraphicObject)
788{
790 sal_Int32 nPos = -1;
791
792 for(tools::Long i = 0;i < nCount;i++)
793 {
794 if(rGraphicObject.GetUniqueID() == m_pBitmapList->GetBitmap( i )->GetGraphicObject().GetUniqueID())
795 {
796 nPos = i;
797 break;
798 }
799 }
800 return nPos;
801}
802
803sal_Int32 SvxBitmapTabPage::SearchBitmapList(std::u16string_view rBitmapName)
804{
806 bool bValidBitmapName = true;
807 sal_Int32 nPos = -1;
808
809 for(tools::Long i = 0;i < nCount && bValidBitmapName;i++)
810 {
811 if(rBitmapName == m_pBitmapList->GetBitmap( i )->GetName())
812 {
813 nPos = i;
814 bValidBitmapName = false;
815 }
816 }
817 return nPos;
818}
819
820/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define GetWhich(nSlot)
static OutputDevice * GetDefaultDevice()
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
const Size & GetSizePixel() const
OString GetUniqueID() const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
SfxItemSet GetGeoAttrFromMarked() const
bool AreObjectsMarked() const
const Fraction & GetUIScale() const
SdrModel & GetModel() const
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
SfxItemPool * GetPool() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
static const SfxPoolItem * GetItem(const SfxItemSet &rSet, sal_uInt16 nSlot, bool bDeep=true)
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
virtual SdrView * GetDrawView() const
bool IsEmpty() const
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
virtual VclPtr< AbstractSvxNameDialog > CreateSvxNameDialog(weld::Window *pParent, const OUString &rName, const OUString &rDesc)=0
static SvxAbstractDialogFactory * Create()
FieldUnit meFieldUnit
Definition: cuitabarea.hxx:523
std::unique_ptr< weld::Button > m_xBtnImport
Definition: cuitabarea.hxx:543
std::unique_ptr< SvxPresetListBox > m_xBitmapLB
Definition: cuitabarea.hxx:529
std::unique_ptr< weld::MetricSpinButton > m_xBitmapWidth
Definition: cuitabarea.hxx:533
std::unique_ptr< weld::MetricSpinButton > m_xPositionOffY
Definition: cuitabarea.hxx:539
const SdrView * mpView
Definition: cuitabarea.hxx:521
std::unique_ptr< weld::CheckButton > m_xTsbScale
Definition: cuitabarea.hxx:532
XBitmapListRef m_pBitmapList
Definition: cuitabarea.hxx:512
SvxXRectPreview m_aCtlBitmapPreview
Definition: cuitabarea.hxx:528
std::unique_ptr< weld::MetricSpinButton > m_xPositionOffX
Definition: cuitabarea.hxx:538
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tpbitmap.cxx:173
sal_Int32 SearchBitmapList(std::u16string_view rBitmapName)
Definition: tpbitmap.cxx:803
virtual bool FillItemSet(SfxItemSet *) override
Definition: tpbitmap.cxx:182
SvxBitmapTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: tpbitmap.cxx:69
double m_fObjectHeight
Definition: cuitabarea.hxx:516
std::unique_ptr< weld::ComboBox > m_xTileOffLB
Definition: cuitabarea.hxx:541
std::unique_ptr< weld::MetricSpinButton > m_xTileOffset
Definition: cuitabarea.hxx:542
std::unique_ptr< weld::ComboBox > m_xBitmapStyleLB
Definition: cuitabarea.hxx:530
std::unique_ptr< weld::CustomWeld > m_xBitmapLBWin
Definition: cuitabarea.hxx:545
std::unique_ptr< weld::MetricSpinButton > m_xBitmapHeight
Definition: cuitabarea.hxx:534
XFillAttrSetItem m_aXFillAttr
Definition: cuitabarea.hxx:519
SfxItemSet & m_rXFSet
Definition: cuitabarea.hxx:520
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tpbitmap.cxx:415
std::unique_ptr< weld::ComboBox > m_xPositionLB
Definition: cuitabarea.hxx:536
std::unique_ptr< weld::Container > m_xTileOffBox
Definition: cuitabarea.hxx:540
virtual ~SvxBitmapTabPage() override
Definition: tpbitmap.cxx:138
void ClickBitmapHdl_Impl()
Definition: tpbitmap.cxx:420
virtual void Reset(const SfxItemSet *) override
Definition: tpbitmap.cxx:256
void CalculateBitmapPresetSize()
Definition: tpbitmap.cxx:428
std::unique_ptr< weld::CustomWeld > m_xCtlBitmapPreview
Definition: cuitabarea.hxx:544
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tpbitmap.cxx:150
OUString GetPath() const
ErrCode GetGraphic(Graphic &) const
void SetAttributes(const SfxItemSet &rItemSet)
void disposeAndClear()
const GraphicObject & GetGraphicObject() const
bool isPattern() const
const GraphicObject & GetGraphicObject() const
OUString CuiResId(TranslateId aKey)
Definition: cuiresmgr.cxx:23
int nCount
#define DBG_ASSERT(sCon, aError)
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Size SFX2_DLLPUBLIC getDrawPreviewOptimalSize(const OutputDevice &rReference)
URL aURL
virtual tools::Long GetValue() const override
SVXCORE_DLLPUBLIC FieldUnit GetModuleFieldUnit(const SfxItemSet &)
#define ERRCODE_NONE
FieldUnit
sal_Int16 nValue
TriState
TRISTATE_FALSE
TRISTATE_INDET
TRISTATE_TRUE
OUString aName
sal_uInt16 nPos
#define SAL_WARN(area, stream)
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
int i
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
Put
long Long
sal_Int16 nId
RectPoint
static SfxItemSet & rSet
UnoViewSharedPtr mpView
DeactivateRC
IMPL_LINK_NOARG(SvxBitmapTabPage, ModifyBitmapHdl, ValueSet *, void)
Definition: tpbitmap.cxx:452
SVT_DLLPUBLIC sal_Int64 GetCoreValue(const weld::MetricSpinButton &rField, MapUnit eUnit)
SVT_DLLPUBLIC void SetMetricValue(weld::MetricSpinButton &rField, sal_Int64 nCoreValue, MapUnit eUnit)
SVT_DLLPUBLIC void SetFieldUnit(weld::MetricSpinButton &rCtrl, FieldUnit eUnit, bool bAll=false)
#define WB_FLATVALUESET
#define VALUESET_ITEM_NOTFOUND
#define WB_NO_DIRECTSELECT
constexpr OUStringLiteral PERCENT(u"Percent")
RET_OK
RET_YES
WinBits const WB_TABSTOP
constexpr TypedWhichId< XFillBmpPosOffsetYItem > XATTR_FILLBMP_POSOFFSETY(XATTR_FILL_FIRST+18)
constexpr TypedWhichId< XFillBmpPosItem > XATTR_FILLBMP_POS(XATTR_FILL_FIRST+8)
constexpr TypedWhichId< XFillBmpTileOffsetXItem > XATTR_FILLBMP_TILEOFFSETX(XATTR_FILL_FIRST+14)
constexpr TypedWhichId< SfxMetricItem > XATTR_FILLBMP_SIZEX(XATTR_FILL_FIRST+9)
constexpr TypedWhichId< XFillBmpPosOffsetXItem > XATTR_FILLBMP_POSOFFSETX(XATTR_FILL_FIRST+17)
constexpr TypedWhichId< XFillBmpTileOffsetYItem > XATTR_FILLBMP_TILEOFFSETY(XATTR_FILL_FIRST+15)
constexpr TypedWhichId< XFillBmpSizeYItem > XATTR_FILLBMP_SIZEY(XATTR_FILL_FIRST+10)
constexpr TypedWhichId< XFillBmpStretchItem > XATTR_FILLBMP_STRETCH(XATTR_FILL_FIRST+16)
constexpr TypedWhichId< XFillBmpSizeLogItem > XATTR_FILLBMP_SIZELOG(XATTR_FILL_FIRST+13)
constexpr TypedWhichId< XFillBmpTileItem > XATTR_FILLBMP_TILE(XATTR_FILL_FIRST+7)
constexpr TypedWhichId< XFillBitmapItem > XATTR_FILLBITMAP(XATTR_FILL_FIRST+4)
constexpr TypedWhichId< XFillStyleItem > XATTR_FILLSTYLE(XATTR_FILL_FIRST)