lok: Don't attempt to select the exact text after a failed search.
[LibreOffice.git] / cui / source / tabpages / backgrnd.cxx
blob8c5703cd6241ddd004bab4672ad73ec5afcd0fbb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/drawing/FillStyle.hpp>
21 #include <unotools/pathoptions.hxx>
22 #include <vcl/builderfactory.hxx>
23 #include <vcl/msgbox.hxx>
24 #include <vcl/settings.hxx>
25 #include <vcl/idle.hxx>
26 #include <tools/urlobj.hxx>
27 #include <sfx2/dialoghelper.hxx>
28 #include <sfx2/objsh.hxx>
29 #include <sfx2/docfile.hxx>
30 #include <svl/cntwall.hxx>
31 #include <sfx2/cntids.hrc>
32 #include <svx/dialogs.hrc>
34 #include <cuires.hrc>
35 #include <svx/dialmgr.hxx>
36 #include <editeng/memberids.hrc>
37 #include <editeng/editrids.hrc>
38 #include <editeng/eerdll.hxx>
40 #include <editeng/brushitem.hxx>
41 #include "backgrnd.hxx"
43 #include <svx/xtable.hxx>
44 #include <sfx2/opengrf.hxx>
45 #include <svx/svxerr.hxx>
46 #include <svx/drawitem.hxx>
47 #include <dialmgr.hxx>
48 #include <sfx2/htmlmode.hxx>
49 #include <svtools/controldims.hrc>
50 #include <svx/flagsdef.hxx>
51 #include <svl/intitem.hxx>
52 #include <sfx2/request.hxx>
53 #include <svtools/grfmgr.hxx>
54 #include <boost/scoped_ptr.hpp>
56 using namespace css;
58 // table background
59 #define TBL_DEST_CELL 0
60 #define TBL_DEST_ROW 1
61 #define TBL_DEST_TBL 2
63 const sal_uInt16 SvxBackgroundTabPage::pPageRanges[] =
65 SID_VIEW_FLD_PIC, SID_VIEW_FLD_PIC,
66 SID_ATTR_BRUSH, SID_ATTR_BRUSH,
67 SID_ATTR_BRUSH_CHAR, SID_ATTR_BRUSH_CHAR,
71 struct SvxBackgroundTable_Impl
73 SvxBrushItem* pCellBrush;
74 SvxBrushItem* pRowBrush;
75 SvxBrushItem* pTableBrush;
76 sal_uInt16 nCellWhich;
77 sal_uInt16 nRowWhich;
78 sal_uInt16 nTableWhich;
79 sal_Int32 nActPos;
81 SvxBackgroundTable_Impl()
82 : pCellBrush(NULL)
83 , pRowBrush(NULL)
84 , pTableBrush(NULL)
85 , nCellWhich(0)
86 , nRowWhich(0)
87 , nTableWhich(0)
88 , nActPos(0)
92 struct SvxBackgroundPara_Impl
94 SvxBrushItem* pParaBrush;
95 SvxBrushItem* pCharBrush;
97 sal_Int32 nActPos;
99 SvxBackgroundPara_Impl()
100 : pParaBrush(NULL)
101 , pCharBrush(NULL)
102 , nActPos(LISTBOX_ENTRY_NOTFOUND)
107 struct SvxBackgroundPage_Impl
109 Idle* pLoadIdle;
110 bool bIsImportDlgInExecute;
112 SvxBackgroundPage_Impl()
113 : pLoadIdle(NULL)
114 , bIsImportDlgInExecute(false)
118 static inline sal_uInt8 lcl_PercentToTransparency(long nPercent)
120 //0xff must not be returned!
121 return sal_uInt8(nPercent ? (50 + 0xfe * nPercent) / 100 : 0);
123 static inline sal_uInt8 lcl_TransparencyToPercent(sal_uInt8 nTrans)
125 return (nTrans * 100 + 127) / 254;
127 static void lcl_SetTransparency(SvxBrushItem& rBrush, long nTransparency)
129 uno::Any aTransparency;
130 aTransparency <<= (sal_Int8)nTransparency;
131 rBrush.PutValue(aTransparency, MID_GRAPHIC_TRANSPARENCY);
134 /// Returns the fill style of the currently selected entry.
135 static drawing::FillStyle lcl_getFillStyle(ListBox* pLbSelect)
137 return (drawing::FillStyle)reinterpret_cast<sal_uLong>(pLbSelect->GetSelectEntryData());
140 // Selects the entry matching the specified fill style.
141 static void lcl_setFillStyle(ListBox* pLbSelect, drawing::FillStyle eStyle)
143 for (int i = 0; i < pLbSelect->GetEntryCount(); ++i)
145 if ((drawing::FillStyle)reinterpret_cast<sal_uLong>(pLbSelect->GetEntryData(i)) == eStyle)
147 pLbSelect->SelectEntryPos(i);
148 return;
153 sal_uInt16 GetItemId_Impl( ValueSet& rValueSet, const Color& rCol )
155 bool bFound = false;
156 sal_uInt16 nCount = rValueSet.GetItemCount();
157 sal_uInt16 n = 1;
159 while ( !bFound && n <= nCount )
161 Color aValCol = rValueSet.GetItemColor(n);
163 bFound = ( aValCol.GetRed() == rCol.GetRed()
164 && aValCol.GetGreen() == rCol.GetGreen()
165 && aValCol.GetBlue() == rCol.GetBlue() );
167 if ( !bFound )
168 n++;
170 return bFound ? n : 0;
174 /** Preview window for brush or bitmap */
175 class BackgroundPreviewImpl : public vcl::Window
177 public:
178 BackgroundPreviewImpl(vcl::Window* pParent);
179 void setBmp(bool bBmp);
180 virtual ~BackgroundPreviewImpl();
181 virtual void dispose() SAL_OVERRIDE;
183 void NotifyChange( const Color& rColor );
184 void NotifyChange( const Bitmap* pBitmap );
186 protected:
187 virtual void Paint( vcl::RenderContext& /*rRenderContext*/, const Rectangle& rRect ) SAL_OVERRIDE;
188 virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
189 virtual void Resize() SAL_OVERRIDE;
191 private:
193 void recalcDrawPos();
195 bool bIsBmp;
196 Bitmap* pBitmap;
197 Point aDrawPos;
198 Size aDrawSize;
199 Rectangle aDrawRect;
200 sal_uInt8 nTransparency;
203 BackgroundPreviewImpl::BackgroundPreviewImpl(vcl::Window* pParent)
204 : Window(pParent, WB_BORDER)
205 , bIsBmp(false)
206 , pBitmap(NULL)
207 , aDrawRect(Point(0,0), GetOutputSizePixel())
208 , nTransparency(0)
210 SetBorderStyle(WindowBorderStyle::MONO);
211 Invalidate(aDrawRect);
214 VCL_BUILDER_DECL_FACTORY(BackgroundPreview)
216 (void)rMap;
217 rRet = VclPtr<BackgroundPreviewImpl>::Create(pParent);
220 void BackgroundPreviewImpl::setBmp(bool bBmp)
222 bIsBmp = bBmp;
223 Invalidate();
226 BackgroundPreviewImpl::~BackgroundPreviewImpl()
228 disposeOnce();
231 void BackgroundPreviewImpl::dispose()
233 delete pBitmap;
234 pBitmap = NULL;
235 vcl::Window::dispose();
238 void BackgroundPreviewImpl::NotifyChange( const Color& rColor )
240 if ( !bIsBmp )
242 const static Color aTranspCol( COL_TRANSPARENT );
244 nTransparency = lcl_TransparencyToPercent( rColor.GetTransparency() );
246 SetFillColor( rColor == aTranspCol ? GetSettings().GetStyleSettings().GetFieldColor() : Color(rColor.GetRGBColor()) );
247 Invalidate(aDrawRect);
251 void BackgroundPreviewImpl::NotifyChange( const Bitmap* pNewBitmap )
253 if (bIsBmp && (pNewBitmap || pBitmap))
255 if (pNewBitmap && pBitmap)
256 *pBitmap = *pNewBitmap;
257 else if (pNewBitmap && !pBitmap)
258 pBitmap = new Bitmap(*pNewBitmap);
259 else if (!pNewBitmap)
260 DELETEZ(pBitmap);
262 recalcDrawPos();
264 Invalidate(aDrawRect);
265 Update();
269 void BackgroundPreviewImpl::recalcDrawPos()
271 if (pBitmap)
273 Size aSize = GetOutputSizePixel();
274 // InnerSize == Size without one pixel border
275 Size aInnerSize = aSize;
276 aInnerSize.Width() -= 2;
277 aInnerSize.Height() -= 2;
278 aDrawSize = pBitmap->GetSizePixel();
280 // bitmap bigger than preview window?
281 if (aDrawSize.Width() > aInnerSize.Width())
283 aDrawSize.Height() = aDrawSize.Height() * aInnerSize.Width() / aDrawSize.Width();
284 if (aDrawSize.Height() > aInnerSize.Height())
286 aDrawSize.Width() = aDrawSize.Height();
287 aDrawSize.Height() = aInnerSize.Height();
289 else
290 aDrawSize.Width() = aInnerSize.Width();
292 else if (aDrawSize.Height() > aInnerSize.Height())
294 aDrawSize.Width() = aDrawSize.Width() * aInnerSize.Height() / aDrawSize.Height();
295 if (aDrawSize.Width() > aInnerSize.Width())
297 aDrawSize.Height() = aDrawSize.Width();
298 aDrawSize.Width() = aInnerSize.Width();
300 else
301 aDrawSize.Height() = aInnerSize.Height();
304 aDrawPos.X() = (aSize.Width() - aDrawSize.Width()) / 2;
305 aDrawPos.Y() = (aSize.Height() - aDrawSize.Height()) / 2;
309 void BackgroundPreviewImpl::Resize()
311 Window::Resize();
312 aDrawRect = Rectangle(Point(0,0), GetOutputSizePixel());
313 recalcDrawPos();
316 void BackgroundPreviewImpl::Paint(vcl::RenderContext& rRenderContext, const Rectangle&)
318 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
319 rRenderContext.SetBackground(Wallpaper(rStyleSettings.GetWindowColor()));
320 rRenderContext.SetLineColor();
322 if (bIsBmp)
324 rRenderContext.SetFillColor(Color(COL_TRANSPARENT));
326 rRenderContext.DrawRect(aDrawRect);
328 if (bIsBmp)
330 if (pBitmap)
331 rRenderContext.DrawBitmap(aDrawPos, aDrawSize, *pBitmap);
332 else
334 Size aSize = rRenderContext.GetOutputSizePixel();
335 rRenderContext.DrawLine(Point(0, 0), Point(aSize.Width(), aSize.Height()));
336 rRenderContext.DrawLine(Point(0, aSize.Height()), Point(aSize.Width(), 0));
341 void BackgroundPreviewImpl::DataChanged( const DataChangedEvent& rDCEvt )
343 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
344 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
346 Invalidate();
348 Window::DataChanged( rDCEvt );
351 #define HDL(hdl) LINK(this,SvxBackgroundTabPage,hdl)
353 SvxBackgroundTabPage::SvxBackgroundTabPage(vcl::Window* pParent, const SfxItemSet& rCoreSet)
354 : SvxTabPage(pParent, "BackgroundPage", "cui/ui/backgroundpage.ui", rCoreSet)
355 , nHtmlMode(0)
356 , bAllowShowSelector(true)
357 , bIsGraphicValid(false)
358 , bLinkOnly(false)
359 , bColTransparency(false)
360 , bGraphTransparency(false)
361 , pPageImpl(new SvxBackgroundPage_Impl)
362 , pImportDlg(NULL)
363 , pTableBck_Impl(NULL)
364 , pParaBck_Impl(NULL)
366 get(m_pAsGrid, "asgrid");
367 get(m_pSelectTxt, "asft");
368 get(m_pLbSelect, "selectlb");
369 get(m_pTblDesc, "forft");
370 get(m_pTblLBox, "tablelb");
371 get(m_pParaLBox, "paralb");
373 get(m_pBackGroundColorFrame, "backgroundcolorframe");
374 get(m_pBackgroundColorSet, "backgroundcolorset");
375 get(m_pPreviewWin1, "preview1");
377 get(m_pColTransFT, "transparencyft");
378 get(m_pColTransMF, "transparencymf");
379 get(m_pBtnPreview, "showpreview");
381 get(m_pBitmapContainer, "graphicgrid");
382 get(m_pFileFrame, "fileframe");
383 get(m_pBtnBrowse, "browse");
384 get(m_pBtnLink, "link");
385 get(m_pFtUnlinked, "unlinkedft");
386 get(m_pFtFile, "fileft");
388 get(m_pTypeFrame, "typeframe");
389 get(m_pBtnPosition, "positionrb");
390 get(m_pBtnArea, "arearb");
391 get(m_pBtnTile, "tilerb");
392 get(m_pWndPosition, "windowpos");
394 get(m_pGraphTransFrame, "graphtransframe");
395 get(m_pGraphTransMF, "graphtransmf");
397 get(m_pPreviewWin2, "preview2");
398 m_pPreviewWin2->setBmp(true);
400 // this page needs ExchangeSupport
401 SetExchangeSupport();
403 const SfxPoolItem* pItem;
404 SfxObjectShell* pShell;
406 if ( SfxItemState::SET == rCoreSet.GetItemState( SID_HTML_MODE, false, &pItem )
407 || ( 0 != ( pShell = SfxObjectShell::Current()) &&
408 0 != ( pItem = pShell->GetItem( SID_HTML_MODE ) ) ) )
410 nHtmlMode = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
413 FillColorValueSets_Impl();
415 m_pBackgroundColorSet->SetSelectHdl( HDL(BackgroundColorHdl_Impl) );
416 m_pBackgroundColorSet->SetStyle(m_pBackgroundColorSet->GetStyle() | WB_ITEMBORDER | WB_NAMEFIELD | WB_NONEFIELD);
417 m_pBackgroundColorSet->SetText(SVX_RESSTR(RID_SVXSTR_TRANSPARENT));
420 SvxBackgroundTabPage::~SvxBackgroundTabPage()
422 disposeOnce();
425 void SvxBackgroundTabPage::dispose()
427 if (pPageImpl)
429 delete pPageImpl->pLoadIdle;
430 delete pPageImpl;
431 pPageImpl = NULL;
434 delete pImportDlg;
435 pImportDlg = NULL;
437 if( pTableBck_Impl)
439 delete pTableBck_Impl->pCellBrush;
440 delete pTableBck_Impl->pRowBrush;
441 delete pTableBck_Impl->pTableBrush;
442 delete pTableBck_Impl;
443 pTableBck_Impl = NULL;
446 if(pParaBck_Impl)
448 delete pParaBck_Impl->pParaBrush;
449 delete pParaBck_Impl->pCharBrush;
450 delete pParaBck_Impl;
451 pParaBck_Impl = NULL;
454 m_pAsGrid.clear();
455 m_pSelectTxt.clear();
456 m_pLbSelect.clear();
457 m_pTblDesc.clear();
458 m_pTblLBox.clear();
459 m_pParaLBox.clear();
460 m_pBackGroundColorFrame.clear();
461 m_pBackgroundColorSet.clear();
462 m_pPreviewWin1.clear();
463 m_pColTransFT.clear();
464 m_pColTransMF.clear();
465 m_pBtnPreview.clear();
466 m_pBitmapContainer.clear();
467 m_pFileFrame.clear();
468 m_pBtnBrowse.clear();
469 m_pBtnLink.clear();
470 m_pFtUnlinked.clear();
471 m_pFtFile.clear();
472 m_pTypeFrame.clear();
473 m_pBtnPosition.clear();
474 m_pBtnArea.clear();
475 m_pBtnTile.clear();
476 m_pWndPosition.clear();
477 m_pGraphTransFrame.clear();
478 m_pGraphTransMF.clear();
479 m_pPreviewWin2.clear();
480 SvxTabPage::dispose();
483 VclPtr<SfxTabPage> SvxBackgroundTabPage::Create( vcl::Window* pParent, const SfxItemSet* rAttrSet )
485 return VclPtr<SfxTabPage>( new SvxBackgroundTabPage( pParent, *rAttrSet ), SAL_NO_ACQUIRE );
488 void SvxBackgroundTabPage::Reset( const SfxItemSet* rSet )
490 // os: Such a nonsense! One will always find such an item somewhere,
491 // but it must be existing in the rSet!
492 // const SfxPoolItem* pX = GetOldItem( rSet, SID_VIEW_FLD_PIC );
493 // if( pX && pX->ISA(SfxWallpaperItem))
494 if(SfxItemState::DEFAULT <= rSet->GetItemState(GetWhich(SID_VIEW_FLD_PIC), false))
496 ResetFromWallpaperItem( *rSet );
497 return;
500 // condition of the preview button is persistent due to UserData
501 OUString aUserData = GetUserData();
502 m_pBtnPreview->Check( !aUserData.isEmpty() && '1' == aUserData[0] );
504 // don't be allowed to call ShowSelector() after reset anymore
505 bAllowShowSelector = false;
508 // get and evaluate Input-BrushItem
509 const SvxBrushItem* pBgdAttr = NULL;
510 sal_uInt16 nSlot = SID_ATTR_BRUSH;
511 const SfxPoolItem* pItem;
512 sal_uInt16 nDestValue = USHRT_MAX;
514 if ( SfxItemState::SET == rSet->GetItemState( SID_BACKGRND_DESTINATION,
515 false, &pItem ) )
517 nDestValue = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
518 m_pTblLBox->SelectEntryPos(nDestValue);
520 switch ( nDestValue )
522 case TBL_DEST_CELL:
523 nSlot = SID_ATTR_BRUSH;
524 break;
525 case TBL_DEST_ROW:
526 nSlot = SID_ATTR_BRUSH_ROW;
527 break;
528 case TBL_DEST_TBL:
529 nSlot = SID_ATTR_BRUSH_TABLE;
530 break;
533 else if( SfxItemState::SET == rSet->GetItemState(
534 SID_PARA_BACKGRND_DESTINATION, false, &pItem ) )
536 nDestValue = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
537 // character activated?
538 sal_Int32 nParaSel = m_pParaLBox->GetSelectEntryPos();
539 if(1 == nParaSel)
541 // then it was a "standard"-call
542 nDestValue = nParaSel;
544 m_pParaLBox->SelectEntryPos(nDestValue);
546 switch ( nDestValue )
548 case PARA_DEST_PARA:
549 nSlot = SID_ATTR_BRUSH;
550 break;
551 case PARA_DEST_CHAR:
552 nSlot = SID_ATTR_BRUSH_CHAR;
553 break;
556 //#111173# the destination item is missing when the parent style has been changed
557 if(USHRT_MAX == nDestValue && (m_pParaLBox->IsVisible()||m_pTblLBox->IsVisible()))
558 nDestValue = 0;
559 sal_uInt16 nWhich = GetWhich( nSlot );
561 if ( rSet->GetItemState( nWhich, false ) >= SfxItemState::DEFAULT )
562 pBgdAttr = static_cast<const SvxBrushItem*>(&( rSet->Get( nWhich ) ));
564 m_pBtnTile->Check();
566 if ( pBgdAttr )
568 FillControls_Impl(*pBgdAttr, aUserData);
569 aBgdColor = const_cast<SvxBrushItem*>(pBgdAttr)->GetColor();
571 else
573 m_pSelectTxt->Hide();
574 m_pLbSelect->Hide();
575 lcl_setFillStyle(m_pLbSelect, drawing::FillStyle_SOLID);
576 ShowColorUI_Impl();
578 const SfxPoolItem* pOld = GetOldItem( *rSet, SID_ATTR_BRUSH );
580 if ( pOld )
581 aBgdColor = static_cast<const SvxBrushItem*>(pOld)->GetColor();
584 if ( nDestValue != USHRT_MAX )
586 if(m_pTblLBox->IsVisible())
588 sal_Int32 nValue = m_pTblLBox->GetSelectEntryPos();
590 if ( pTableBck_Impl )
592 DELETEZ( pTableBck_Impl->pCellBrush);
593 DELETEZ( pTableBck_Impl->pRowBrush);
594 DELETEZ( pTableBck_Impl->pTableBrush);
596 else
597 pTableBck_Impl = new SvxBackgroundTable_Impl();
599 pTableBck_Impl->nActPos = nValue;
601 nWhich = GetWhich( SID_ATTR_BRUSH );
602 if ( rSet->GetItemState( nWhich, false ) >= SfxItemState::DEFAULT )
604 pBgdAttr = static_cast<const SvxBrushItem*>(&( rSet->Get( nWhich ) ));
605 pTableBck_Impl->pCellBrush = new SvxBrushItem(*pBgdAttr);
607 pTableBck_Impl->nCellWhich = nWhich;
609 if ( rSet->GetItemState( SID_ATTR_BRUSH_ROW, false ) >= SfxItemState::DEFAULT )
611 pBgdAttr = static_cast<const SvxBrushItem*>(&( rSet->Get( SID_ATTR_BRUSH_ROW ) ));
612 pTableBck_Impl->pRowBrush = new SvxBrushItem(*pBgdAttr);
614 pTableBck_Impl->nRowWhich = SID_ATTR_BRUSH_ROW;
616 if ( rSet->GetItemState( SID_ATTR_BRUSH_TABLE, false ) >= SfxItemState::DEFAULT )
618 pBgdAttr = static_cast<const SvxBrushItem*>(&( rSet->Get( SID_ATTR_BRUSH_TABLE ) ));
619 pTableBck_Impl->pTableBrush = new SvxBrushItem(*pBgdAttr);
621 pTableBck_Impl->nTableWhich = SID_ATTR_BRUSH_TABLE;
623 TblDestinationHdl_Impl(m_pTblLBox);
624 m_pTblLBox->SaveValue();
626 else
628 sal_Int32 nValue = m_pParaLBox->GetSelectEntryPos();
630 if ( pParaBck_Impl )
632 delete pParaBck_Impl->pParaBrush;
633 delete pParaBck_Impl->pCharBrush;
635 else
636 pParaBck_Impl = new SvxBackgroundPara_Impl();
638 pParaBck_Impl->nActPos = nValue;
640 nWhich = GetWhich( SID_ATTR_BRUSH );
641 if ( rSet->GetItemState( nWhich, false ) >= SfxItemState::DEFAULT )
643 pBgdAttr = static_cast<const SvxBrushItem*>(&( rSet->Get( nWhich ) ));
644 pParaBck_Impl->pParaBrush = new SvxBrushItem(*pBgdAttr);
647 nWhich = GetWhich( SID_ATTR_BRUSH_CHAR );
648 rSet->GetItemState( nWhich, true );
649 rSet->GetItemState( nWhich, false );
650 if ( rSet->GetItemState( nWhich, true ) > SfxItemState::DEFAULT )
652 pBgdAttr = static_cast<const SvxBrushItem*>(&( rSet->Get( nWhich ) ));
653 pParaBck_Impl->pCharBrush = new SvxBrushItem(*pBgdAttr);
655 else
656 pParaBck_Impl->pCharBrush = new SvxBrushItem(SID_ATTR_BRUSH_CHAR);
658 ParaDestinationHdl_Impl(m_pParaLBox);
659 m_pParaLBox->SaveValue();
664 void SvxBackgroundTabPage::ResetFromWallpaperItem( const SfxItemSet& rSet )
666 ShowSelector();
668 // condition of the preview button is persistent due to UserData
669 OUString aUserData = GetUserData();
670 m_pBtnPreview->Check( !aUserData.isEmpty() && '1' == aUserData[0] );
672 // get and evaluate Input-BrushItem
673 const SvxBrushItem* pBgdAttr = NULL;
674 sal_uInt16 nSlot = SID_VIEW_FLD_PIC;
675 sal_uInt16 nWhich = GetWhich( nSlot );
676 boost::scoped_ptr<SvxBrushItem> pTemp;
678 if ( rSet.GetItemState( nWhich, false ) >= SfxItemState::DEFAULT )
680 const CntWallpaperItem* pItem = static_cast<const CntWallpaperItem*>(&rSet.Get( nWhich ));
681 pTemp.reset(new SvxBrushItem( *pItem, nWhich ));
682 pBgdAttr = pTemp.get();
685 m_pBtnTile->Check();
687 if ( pBgdAttr )
689 FillControls_Impl(*pBgdAttr, aUserData);
690 // brush shall be kept when showing the graphic, too
691 if( aBgdColor != pBgdAttr->GetColor() )
693 aBgdColor = pBgdAttr->GetColor();
694 sal_uInt16 nCol = GetItemId_Impl(*m_pBackgroundColorSet, aBgdColor);
695 m_pBackgroundColorSet->SelectItem( nCol );
696 m_pPreviewWin1->NotifyChange( aBgdColor );
699 else
701 lcl_setFillStyle(m_pLbSelect, drawing::FillStyle_SOLID);
702 ShowColorUI_Impl();
704 const SfxPoolItem* pOld = GetOldItem( rSet, SID_VIEW_FLD_PIC );
705 if ( pOld )
706 aBgdColor = Color( static_cast<const CntWallpaperItem*>(pOld)->GetColor() );
709 // We now have always a link to the background
710 bLinkOnly = true;
711 m_pBtnLink->Check( true );
712 m_pBtnLink->Show( false );
715 /** When destroying a SfxTabPage this virtual method is called,
716 so that the TabPage can save internal information.
718 In this case the condition of the preview button is saved.
720 void SvxBackgroundTabPage::FillUserData()
724 SetUserData( m_pBtnPreview->IsChecked() ? OUString('1') : OUString('0') );
727 bool SvxBackgroundTabPage::FillItemSet( SfxItemSet* rCoreSet )
729 if ( pPageImpl->pLoadIdle && pPageImpl->pLoadIdle->IsActive() )
731 pPageImpl->pLoadIdle->Stop();
732 LoadIdleHdl_Impl( pPageImpl->pLoadIdle );
734 // os: Such a nonsense! One will always find such an item somewhere,
735 // but it must be existing in the rSet!
737 // const SfxPoolItem* pX = GetOldItem( rCoreSet, SID_VIEW_FLD_PIC );
738 // if( pX && pX->ISA(SfxWallpaperItem))
739 if(SfxItemState::DEFAULT <= rCoreSet->GetItemState(GetWhich(SID_VIEW_FLD_PIC), false))
740 return FillItemSetWithWallpaperItem( *rCoreSet, SID_VIEW_FLD_PIC );
742 bool bModified = false;
743 sal_uInt16 nSlot = SID_ATTR_BRUSH;
745 if ( m_pTblLBox->IsVisible() )
747 switch( m_pTblLBox->GetSelectEntryPos() )
749 case TBL_DEST_CELL:
750 nSlot = SID_ATTR_BRUSH;
751 break;
752 case TBL_DEST_ROW:
753 nSlot = SID_ATTR_BRUSH_ROW;
754 break;
755 case TBL_DEST_TBL:
756 nSlot = SID_ATTR_BRUSH_TABLE;
757 break;
760 else if (m_pParaLBox->GetData() == m_pParaLBox)
762 switch(m_pParaLBox->GetSelectEntryPos())
764 case PARA_DEST_PARA:
765 nSlot = SID_ATTR_BRUSH;
766 break;
767 case PARA_DEST_CHAR:
768 nSlot = SID_ATTR_BRUSH_CHAR;
769 break;
772 sal_uInt16 nWhich = GetWhich( nSlot );
774 const SfxPoolItem* pOld = GetOldItem( *rCoreSet, nSlot );
775 SfxItemState eOldItemState = rCoreSet->GetItemState(nSlot, false);
776 const SfxItemSet& rOldSet = GetItemSet();
778 bool bGraphTransparencyChanged = bGraphTransparency && m_pGraphTransMF->IsValueChangedFromSaved();
779 if ( pOld )
781 const SvxBrushItem& rOldItem = static_cast<const SvxBrushItem&>(*pOld);
782 SvxGraphicPosition eOldPos = rOldItem.GetGraphicPos();
783 const bool bIsBrush = ( drawing::FillStyle_SOLID == lcl_getFillStyle(m_pLbSelect) );
785 // transparency has to be set if enabled, the color not already set to "No fill" and
786 if( bColTransparency &&
787 aBgdColor.GetTransparency() < 0xff)
789 aBgdColor.SetTransparency(lcl_PercentToTransparency(static_cast<long>(m_pColTransMF->GetValue())));
791 if ( ( (GPOS_NONE == eOldPos) && bIsBrush )
792 || ( (GPOS_NONE != eOldPos) && !bIsBrush ) ) // Brush <-> Bitmap changed?
794 // background art hasn't been changed:
796 if ( (GPOS_NONE == eOldPos) || !m_pLbSelect->IsVisible() )
798 // Brush-treatment:
799 if ( rOldItem.GetColor() != aBgdColor ||
800 (SfxItemState::DEFAULT >= eOldItemState && !m_pBackgroundColorSet->IsNoSelection()))
802 bModified = true;
803 rCoreSet->Put( SvxBrushItem( aBgdColor, nWhich ) );
805 else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) )
806 rCoreSet->ClearItem( nWhich );
808 else
810 // Bitmap-treatment:
812 SvxGraphicPosition eNewPos = GetGraphicPosition_Impl();
813 const bool bIsLink = m_pBtnLink->IsChecked();
814 const bool bWasLink = (NULL != rOldItem.GetGraphicLink() );
817 if ( !bIsLink && !bIsGraphicValid )
818 bIsGraphicValid = LoadLinkedGraphic_Impl();
820 if ( bGraphTransparencyChanged ||
821 eNewPos != eOldPos
822 || bIsLink != bWasLink
823 || ( bWasLink && rOldItem.GetGraphicLink()
824 != aBgdGraphicPath )
825 || ( !bWasLink && rOldItem.GetGraphic()->GetBitmap()
826 != aBgdGraphic.GetBitmap() )
829 bModified = true;
831 SvxBrushItem aTmpBrush(nWhich);
832 if ( bIsLink )
834 aTmpBrush = SvxBrushItem( aBgdGraphicPath,
835 aBgdGraphicFilter,
836 eNewPos,
837 nWhich );
839 else
840 aTmpBrush = SvxBrushItem( aBgdGraphic,
841 eNewPos,
842 nWhich );
843 lcl_SetTransparency(aTmpBrush, static_cast<long>(m_pGraphTransMF->GetValue()));
845 rCoreSet->Put(aTmpBrush);
847 else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) )
848 rCoreSet->ClearItem( nWhich );
851 else // Brush <-> Bitmap changed!
853 if ( bIsBrush )
855 rCoreSet->Put( SvxBrushItem( aBgdColor, nWhich ) );
857 else
859 boost::scoped_ptr<SvxBrushItem> pTmpBrush;
860 if ( m_pBtnLink->IsChecked() )
862 pTmpBrush.reset(new SvxBrushItem( aBgdGraphicPath,
863 aBgdGraphicFilter,
864 GetGraphicPosition_Impl(),
865 nWhich ));
867 else
869 if ( !bIsGraphicValid )
870 bIsGraphicValid = LoadLinkedGraphic_Impl();
872 if ( bIsGraphicValid )
873 pTmpBrush.reset(new SvxBrushItem( aBgdGraphic,
874 GetGraphicPosition_Impl(),
875 nWhich ));
877 if(pTmpBrush)
879 lcl_SetTransparency(*pTmpBrush, static_cast<long>(m_pGraphTransMF->GetValue()));
880 rCoreSet->Put(*pTmpBrush);
883 bModified = ( bIsBrush || m_pBtnLink->IsChecked() || bIsGraphicValid );
886 else if ( SID_ATTR_BRUSH_CHAR == nSlot && aBgdColor != Color( COL_WHITE ) )
888 rCoreSet->Put( SvxBrushItem( aBgdColor, nWhich ) );
889 bModified = true;
892 if( m_pTblLBox->IsVisible() )
894 // the current condition has already been put
895 if( nSlot != SID_ATTR_BRUSH && pTableBck_Impl->pCellBrush)
897 const SfxPoolItem* pOldCell =
898 GetOldItem( *rCoreSet, SID_ATTR_BRUSH );
900 if ( *pTableBck_Impl->pCellBrush != *pOldCell )
902 rCoreSet->Put( *pTableBck_Impl->pCellBrush );
903 bModified |= true;
907 if( nSlot != SID_ATTR_BRUSH_ROW && pTableBck_Impl->pRowBrush)
909 const SfxPoolItem* pOldRow =
910 GetOldItem( *rCoreSet, SID_ATTR_BRUSH_ROW );
912 if ( *pTableBck_Impl->pRowBrush != *pOldRow )
914 rCoreSet->Put( *pTableBck_Impl->pRowBrush );
915 bModified |= true;
919 if( nSlot != SID_ATTR_BRUSH_TABLE && pTableBck_Impl->pTableBrush)
921 const SfxPoolItem* pOldTable =
922 GetOldItem( *rCoreSet, SID_ATTR_BRUSH_TABLE );
924 if ( *pTableBck_Impl->pTableBrush != *pOldTable )
926 rCoreSet->Put( *pTableBck_Impl->pTableBrush );
927 bModified |= true;
931 if( m_pTblLBox->IsValueChangedFromSaved() )
933 rCoreSet->Put( SfxUInt16Item( SID_BACKGRND_DESTINATION,
934 m_pTblLBox->GetSelectEntryPos() ) );
935 bModified |= true;
938 else if (m_pParaLBox->GetData() == m_pParaLBox)
940 // the current condition has already been put
941 if( nSlot != SID_ATTR_BRUSH && m_pParaLBox->IsVisible()) // not in search format dialog
943 const SfxPoolItem* pOldPara =
944 GetOldItem( *rCoreSet, SID_ATTR_BRUSH );
946 if ( *pParaBck_Impl->pParaBrush != *pOldPara )
948 rCoreSet->Put( *pParaBck_Impl->pParaBrush );
949 bModified |= true;
953 if( nSlot != SID_ATTR_BRUSH_CHAR )
955 const SfxPoolItem* pOldChar =
956 GetOldItem( *rCoreSet, SID_ATTR_BRUSH_CHAR );
957 DBG_ASSERT(pParaBck_Impl, "pParaBck_Impl == NULL ?");
958 if ( pOldChar &&
959 //#111173# crash report shows that pParaBck_Impl can be NULL, the cause is unknown
960 pParaBck_Impl &&
961 (*pParaBck_Impl->pCharBrush != *pOldChar ||
962 *pParaBck_Impl->pCharBrush != SvxBrushItem(SID_ATTR_BRUSH_CHAR)))
964 rCoreSet->Put( *pParaBck_Impl->pCharBrush );
965 bModified |= true;
969 if( m_pParaLBox->IsValueChangedFromSaved() )
971 rCoreSet->Put( SfxUInt16Item( SID_BACKGRND_DESTINATION,
972 m_pParaLBox->GetSelectEntryPos() ) );
973 bModified |= true;
976 return bModified;
979 bool SvxBackgroundTabPage::FillItemSetWithWallpaperItem( SfxItemSet& rCoreSet, sal_uInt16 nSlot)
981 sal_uInt16 nWhich = GetWhich( nSlot );
982 const SfxPoolItem* pOld = GetOldItem( rCoreSet, nSlot );
983 DBG_ASSERT(pOld,"FillItemSetWithWallpaperItem: Item not found");
984 if (!pOld)
985 return false;
986 const SfxItemSet& rOldSet = GetItemSet();
988 SvxBrushItem rOldItem( static_cast<const CntWallpaperItem&>(*pOld), nWhich );
989 SvxGraphicPosition eOldPos = rOldItem.GetGraphicPos();
990 const bool bIsBrush = ( drawing::FillStyle_SOLID == lcl_getFillStyle(m_pLbSelect) );
991 bool bModified = false;
993 if ( ( (GPOS_NONE == eOldPos) && bIsBrush )
994 || ( (GPOS_NONE != eOldPos) && !bIsBrush ) ) // Brush <-> Bitmap changed?
996 // background art hasn't been changed
998 if ( (GPOS_NONE == eOldPos) || !m_pLbSelect->IsVisible() )
1000 // Brush-treatment:
1001 if ( rOldItem.GetColor() != aBgdColor )
1003 bModified = true;
1004 CntWallpaperItem aItem( nWhich );
1005 aItem.SetColor( aBgdColor );
1006 rCoreSet.Put( aItem );
1008 else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) )
1009 rCoreSet.ClearItem( nWhich );
1011 else
1013 // Bitmap-treatment:
1014 SvxGraphicPosition eNewPos = GetGraphicPosition_Impl();
1016 bool bBitmapChanged = ( ( eNewPos != eOldPos ) ||
1017 ( rOldItem.GetGraphicLink() != aBgdGraphicPath ) );
1018 bool bBrushChanged = ( rOldItem.GetColor() != aBgdColor );
1019 if( bBitmapChanged || bBrushChanged )
1021 bModified = true;
1023 CntWallpaperItem aItem( nWhich );
1024 WallpaperStyle eWallStyle = SvxBrushItem::GraphicPos2WallpaperStyle(eNewPos);
1025 aItem.SetStyle( sal::static_int_cast< sal_uInt16 >( eWallStyle ) );
1026 aItem.SetColor( aBgdColor );
1027 aItem.SetBitmapURL( aBgdGraphicPath );
1028 rCoreSet.Put( aItem );
1030 else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) )
1031 rCoreSet.ClearItem( nWhich );
1034 else // Brush <-> Bitmap changed!
1036 CntWallpaperItem aItem( nWhich );
1037 if ( bIsBrush )
1039 aItem.SetColor( aBgdColor );
1040 rCoreSet.Put( aItem );
1042 else
1044 WallpaperStyle eWallStyle =
1045 SvxBrushItem::GraphicPos2WallpaperStyle( GetGraphicPosition_Impl() );
1046 aItem.SetStyle( sal::static_int_cast< sal_uInt16 >( eWallStyle ) );
1047 aItem.SetColor( aBgdColor );
1048 aItem.SetBitmapURL( aBgdGraphicPath );
1049 rCoreSet.Put( aItem );
1052 bModified = true;
1054 return bModified;
1057 /** virtual method; is called on deactivation */
1058 SfxTabPage::sfxpg SvxBackgroundTabPage::DeactivatePage( SfxItemSet* _pSet )
1060 if ( pPageImpl->bIsImportDlgInExecute )
1061 return KEEP_PAGE;
1063 if ( _pSet )
1064 FillItemSet( _pSet );
1066 return LEAVE_PAGE;
1069 void SvxBackgroundTabPage::PointChanged( vcl::Window* , RECT_POINT )
1071 // has to be implemented so that position control can work
1074 void SvxBackgroundTabPage::ShowSelector()
1076 if( bAllowShowSelector)
1078 m_pAsGrid->Show();
1079 m_pSelectTxt->Show();
1080 m_pLbSelect->Show();
1081 m_pLbSelect->SetSelectHdl( HDL(SelectHdl_Impl) );
1082 m_pBtnLink->SetClickHdl( HDL(FileClickHdl_Impl) );
1083 m_pBtnPreview->SetClickHdl( HDL(FileClickHdl_Impl) );
1084 m_pBtnBrowse->SetClickHdl( HDL(BrowseHdl_Impl) );
1085 m_pBtnArea->SetClickHdl( HDL(RadioClickHdl_Impl) );
1086 m_pBtnTile->SetClickHdl( HDL(RadioClickHdl_Impl) );
1087 m_pBtnPosition->SetClickHdl( HDL(RadioClickHdl_Impl) );
1089 // delayed loading via timer (because of UI-Update)
1090 pPageImpl->pLoadIdle = new Idle;
1091 pPageImpl->pLoadIdle->SetPriority( SchedulerPriority::LOWEST );
1092 pPageImpl->pLoadIdle->SetIdleHdl(
1093 LINK( this, SvxBackgroundTabPage, LoadIdleHdl_Impl ) );
1095 bAllowShowSelector = false;
1097 if(nHtmlMode & HTMLMODE_ON)
1099 m_pBtnArea->Enable(false);
1104 void SvxBackgroundTabPage::RaiseLoadError_Impl()
1106 SfxErrorContext aContext( ERRCTX_SVX_BACKGROUND,
1107 OUString(),
1108 this,
1109 RID_SVXERRCTX,
1110 &CUI_MGR() );
1112 ErrorHandler::HandleError(
1113 *new StringErrorInfo( ERRCODE_SVX_GRAPHIC_NOTREADABLE,
1114 aBgdGraphicPath ) );
1117 bool SvxBackgroundTabPage::LoadLinkedGraphic_Impl()
1119 bool bResult = ( !aBgdGraphicPath.isEmpty() ) &&
1120 ( GRFILTER_OK == GraphicFilter::LoadGraphic( aBgdGraphicPath,
1121 aBgdGraphicFilter,
1122 aBgdGraphic ) );
1123 return bResult;
1126 void SvxBackgroundTabPage::FillColorValueSets_Impl()
1128 SfxObjectShell* pDocSh = SfxObjectShell::Current();
1129 const SfxPoolItem* pItem = NULL;
1130 XColorListRef pColorTable = NULL;
1131 if ( pDocSh && ( 0 != ( pItem = pDocSh->GetItem( SID_COLOR_TABLE ) ) ) )
1133 pColorTable = static_cast<const SvxColorListItem*>(pItem)->GetColorList();
1136 if ( !pColorTable.is() )
1137 pColorTable = XColorList::CreateStdColorList();
1139 if ( pColorTable.is() )
1141 m_pBackgroundColorSet->Clear();
1142 m_pBackgroundColorSet->addEntriesForXColorList(*pColorTable);
1145 const WinBits nBits(m_pBackgroundColorSet->GetStyle() | WB_ITEMBORDER | WB_NAMEFIELD | WB_NONEFIELD);
1146 m_pBackgroundColorSet->SetStyle(nBits);
1147 m_pBackgroundColorSet->SetColCount(SvxColorValueSet::getColumnCount());
1150 /** Hide the controls for editing the bitmap
1151 and show the controls for color settings instead.
1153 void SvxBackgroundTabPage::ShowColorUI_Impl()
1155 if (!m_pBackGroundColorFrame->IsVisible())
1157 HideBitmapUI_Impl();
1158 m_pBackGroundColorFrame->Show();
1160 if(bColTransparency)
1162 m_pColTransFT->Show();
1163 m_pColTransMF->Show();
1168 void SvxBackgroundTabPage::HideColorUI_Impl()
1170 m_pBackGroundColorFrame->Hide();
1173 /** Hide the controls for color settings
1174 and show controls for editing the bitmap instead.
1176 void SvxBackgroundTabPage::ShowBitmapUI_Impl()
1178 if (m_pLbSelect->IsVisible() &&
1179 (m_pBackGroundColorFrame->IsVisible() || !m_pFileFrame->IsVisible()))
1181 HideColorUI_Impl();
1184 m_pBitmapContainer->Show();
1186 m_pFileFrame->Show();
1187 m_pBtnLink->Show(!bLinkOnly && !(nHtmlMode & HTMLMODE_ON));
1189 m_pTypeFrame->Show();
1191 m_pPreviewWin2->Show();
1192 m_pBtnPreview->Show();
1194 m_pGraphTransFrame->Show(bGraphTransparency);
1195 m_pColTransFT->Show(false);
1196 m_pColTransMF->Show(false);
1200 void SvxBackgroundTabPage::HideBitmapUI_Impl()
1202 m_pBitmapContainer->Hide();
1203 m_pFileFrame->Hide();
1204 m_pTypeFrame->Hide();
1205 m_pPreviewWin2->Hide();
1206 m_pBtnPreview->Hide();
1207 m_pGraphTransFrame->Hide();
1210 void SvxBackgroundTabPage::SetGraphicPosition_Impl( SvxGraphicPosition ePos )
1212 switch ( ePos )
1214 case GPOS_AREA:
1216 m_pBtnArea->Check();
1217 m_pWndPosition->Disable();
1219 break;
1221 case GPOS_TILED:
1223 m_pBtnTile->Check();
1224 m_pWndPosition->Disable();
1226 break;
1228 default:
1230 m_pBtnPosition->Check();
1231 m_pWndPosition->Enable();
1232 RECT_POINT eNewPos = RP_MM;
1234 switch ( ePos )
1236 case GPOS_MM: break;
1237 case GPOS_LT: eNewPos = RP_LT; break;
1238 case GPOS_MT: eNewPos = RP_MT; break;
1239 case GPOS_RT: eNewPos = RP_RT; break;
1240 case GPOS_LM: eNewPos = RP_LM; break;
1241 case GPOS_RM: eNewPos = RP_RM; break;
1242 case GPOS_LB: eNewPos = RP_LB; break;
1243 case GPOS_MB: eNewPos = RP_MB; break;
1244 case GPOS_RB: eNewPos = RP_RB; break;
1245 default: ;//prevent warning
1247 m_pWndPosition->SetActualRP( eNewPos );
1249 break;
1251 m_pWndPosition->Invalidate();
1254 SvxGraphicPosition SvxBackgroundTabPage::GetGraphicPosition_Impl()
1256 if ( m_pBtnTile->IsChecked() )
1257 return GPOS_TILED;
1258 else if ( m_pBtnArea->IsChecked() )
1259 return GPOS_AREA;
1260 else
1262 switch ( m_pWndPosition->GetActualRP() )
1264 case RP_LT: return GPOS_LT;
1265 case RP_MT: return GPOS_MT;
1266 case RP_RT: return GPOS_RT;
1267 case RP_LM: return GPOS_LM;
1268 case RP_MM: return GPOS_MM;
1269 case RP_RM: return GPOS_RM;
1270 case RP_LB: return GPOS_LB;
1271 case RP_MB: return GPOS_MB;
1272 case RP_RB: return GPOS_RB;
1275 return GPOS_MM;
1279 // Handler
1281 /** Handler, called when color selection is changed */
1282 IMPL_LINK_NOARG(SvxBackgroundTabPage, BackgroundColorHdl_Impl)
1284 sal_uInt16 nItemId = m_pBackgroundColorSet->GetSelectItemId();
1285 Color aColor = nItemId ? ( m_pBackgroundColorSet->GetItemColor( nItemId ) ) : Color( COL_TRANSPARENT );
1286 aBgdColor = aColor;
1287 m_pPreviewWin1->NotifyChange( aBgdColor );
1288 bool bEnableTransp = aBgdColor.GetTransparency() < 0xff;
1289 m_pColTransFT->Enable(bEnableTransp);
1290 m_pColTransMF->Enable(bEnableTransp);
1291 return 0;
1294 IMPL_LINK_NOARG(SvxBackgroundTabPage, SelectHdl_Impl)
1296 if ( drawing::FillStyle_SOLID == lcl_getFillStyle(m_pLbSelect) )
1298 ShowColorUI_Impl();
1299 m_pParaLBox->Enable(); // drawing background can't be a bitmap
1301 else
1303 ShowBitmapUI_Impl();
1304 m_pParaLBox->Enable(false); // drawing background can't be a bitmap
1306 return 0;
1309 IMPL_LINK( SvxBackgroundTabPage, FileClickHdl_Impl, CheckBox*, pBox )
1311 if (m_pBtnLink == pBox)
1313 if ( m_pBtnLink->IsChecked() )
1315 m_pFtUnlinked->Hide();
1316 INetURLObject aObj( aBgdGraphicPath );
1317 OUString aFilePath;
1318 if ( aObj.GetProtocol() == INetProtocol::File )
1319 aFilePath = aObj.getFSysPath( INetURLObject::FSYS_DETECT );
1320 else
1321 aFilePath = aBgdGraphicPath;
1322 m_pFtFile->SetText( aFilePath );
1323 m_pFtFile->Show();
1325 else
1327 m_pFtUnlinked->Show();
1328 m_pFtFile->Hide();
1331 else if (m_pBtnPreview == pBox)
1333 if ( m_pBtnPreview->IsChecked() )
1335 if ( !bIsGraphicValid )
1336 bIsGraphicValid = LoadLinkedGraphic_Impl();
1338 if ( bIsGraphicValid )
1340 Bitmap aBmp = aBgdGraphic.GetBitmap();
1341 m_pPreviewWin2->NotifyChange( &aBmp );
1343 else
1345 if ( !aBgdGraphicPath.isEmpty() ) // only for linked bitmap
1346 RaiseLoadError_Impl();
1347 m_pPreviewWin2->NotifyChange( NULL );
1350 else
1351 m_pPreviewWin2->NotifyChange( NULL );
1353 return 0;
1356 IMPL_LINK( SvxBackgroundTabPage, RadioClickHdl_Impl, RadioButton*, pBtn )
1358 if (pBtn == m_pBtnPosition)
1360 if ( !m_pWndPosition->IsEnabled() )
1362 m_pWndPosition->Enable();
1363 m_pWndPosition->Invalidate();
1366 else if ( m_pWndPosition->IsEnabled() )
1368 m_pWndPosition->Disable();
1369 m_pWndPosition->Invalidate();
1371 return 0;
1374 /** Handler, called by pressing the browse button.
1375 Create graphic/insert dialog, set path and start.
1377 IMPL_LINK_NOARG(SvxBackgroundTabPage, BrowseHdl_Impl)
1379 if ( pPageImpl->pLoadIdle->IsActive() )
1380 return 0;
1381 bool bHtml = 0 != ( nHtmlMode & HTMLMODE_ON );
1383 OUString aStrBrowse(get<vcl::Window>("findgraphicsft")->GetText());
1384 pImportDlg = new SvxOpenGraphicDialog( aStrBrowse );
1385 if ( bHtml || bLinkOnly )
1386 pImportDlg->EnableLink(false);
1387 pImportDlg->SetPath( aBgdGraphicPath, m_pBtnLink->IsChecked() );
1389 pPageImpl->bIsImportDlgInExecute = true;
1390 short nErr = pImportDlg->Execute();
1391 pPageImpl->bIsImportDlgInExecute = false;
1393 if( !nErr )
1395 if ( bHtml )
1396 m_pBtnLink->Check();
1397 // if link isn't checked and preview isn't, either,
1398 // activate preview, so that the user sees which
1399 // graphic he has chosen
1400 if ( !m_pBtnLink->IsChecked() && !m_pBtnPreview->IsChecked() )
1401 m_pBtnPreview->Check( true );
1402 // timer-delayed loading of the graphic
1403 pPageImpl->pLoadIdle->Start();
1405 else
1406 DELETEZ( pImportDlg );
1407 return 0;
1410 /** Delayed loading of the graphic.
1411 Graphic is only loaded, if it's
1412 different to the current graphic.
1414 IMPL_LINK_TYPED( SvxBackgroundTabPage, LoadIdleHdl_Impl, Idle* , pIdle, void )
1416 if ( pIdle == pPageImpl->pLoadIdle )
1418 pPageImpl->pLoadIdle->Stop();
1420 if ( pImportDlg )
1422 INetURLObject aOld( aBgdGraphicPath );
1423 INetURLObject aNew( pImportDlg->GetPath() );
1424 if ( aBgdGraphicPath.isEmpty() || aNew != aOld )
1426 // new file chosen
1427 aBgdGraphicPath = pImportDlg->GetPath();
1428 aBgdGraphicFilter = pImportDlg->GetCurrentFilter();
1429 bool bLink = ( nHtmlMode & HTMLMODE_ON ) || bLinkOnly || pImportDlg->IsAsLink();
1430 m_pBtnLink->Check( bLink );
1431 m_pBtnLink->Enable();
1433 if ( m_pBtnPreview->IsChecked() )
1435 if( !pImportDlg->GetGraphic(aBgdGraphic) )
1437 bIsGraphicValid = true;
1439 else
1441 aBgdGraphicFilter.clear();
1442 aBgdGraphicPath.clear();
1443 bIsGraphicValid = false;
1446 else
1447 bIsGraphicValid = false; // load graphic not until preview click
1449 if ( m_pBtnPreview->IsChecked() && bIsGraphicValid )
1451 Bitmap aBmp = aBgdGraphic.GetBitmap();
1452 m_pPreviewWin2->NotifyChange( &aBmp );
1454 else
1455 m_pPreviewWin2->NotifyChange( NULL );
1458 FileClickHdl_Impl(m_pBtnLink);
1459 DELETEZ( pImportDlg );
1464 void SvxBackgroundTabPage::ShowTblControl()
1466 m_pTblLBox->SetSelectHdl( HDL(TblDestinationHdl_Impl) );
1467 m_pTblLBox->SelectEntryPos(0);
1468 m_pTblDesc->Show();
1469 m_pTblLBox->Show();
1470 m_pAsGrid->Show();
1473 void SvxBackgroundTabPage::ShowParaControl(bool bCharOnly)
1475 m_pParaLBox->SetSelectHdl(HDL(ParaDestinationHdl_Impl));
1476 m_pParaLBox->SelectEntryPos(0);
1477 if (!bCharOnly)
1479 m_pTblDesc->Show();
1480 m_pParaLBox->Show();
1481 m_pAsGrid->Show();
1483 m_pParaLBox->SetData(m_pParaLBox); // here it can be recognized that this mode is turned on
1486 IMPL_LINK( SvxBackgroundTabPage, TblDestinationHdl_Impl, ListBox*, pBox )
1488 sal_Int32 nSelPos = pBox->GetSelectEntryPos();
1489 if( pTableBck_Impl && pTableBck_Impl->nActPos != nSelPos)
1491 boost::scoped_ptr<SvxBrushItem> xItemHolder;
1492 SvxBrushItem* pActItem = NULL;
1493 sal_uInt16 nWhich = 0;
1494 switch(pTableBck_Impl->nActPos)
1496 case TBL_DEST_CELL:
1497 pActItem = pTableBck_Impl->pCellBrush;
1498 nWhich = pTableBck_Impl->nCellWhich;
1499 break;
1500 case TBL_DEST_ROW:
1501 pActItem = pTableBck_Impl->pRowBrush;
1502 nWhich = pTableBck_Impl->nRowWhich;
1503 break;
1504 case TBL_DEST_TBL:
1505 pActItem = pTableBck_Impl->pTableBrush;
1506 nWhich = pTableBck_Impl->nTableWhich;
1507 break;
1508 default:
1509 pActItem = NULL;
1510 break;
1512 pTableBck_Impl->nActPos = nSelPos;
1513 if(!pActItem)
1515 xItemHolder.reset(new SvxBrushItem(nWhich));
1516 pActItem = xItemHolder.get();
1518 if(drawing::FillStyle_SOLID == lcl_getFillStyle(m_pLbSelect)) // brush selected
1520 *pActItem = SvxBrushItem( aBgdColor, nWhich );
1522 else
1524 SvxGraphicPosition eNewPos = GetGraphicPosition_Impl();
1525 const bool bIsLink = m_pBtnLink->IsChecked();
1527 if ( !bIsLink && !bIsGraphicValid )
1528 bIsGraphicValid = LoadLinkedGraphic_Impl();
1530 if ( bIsLink )
1531 *pActItem = SvxBrushItem( aBgdGraphicPath,
1532 aBgdGraphicFilter,
1533 eNewPos,
1534 pActItem->Which() );
1535 else
1536 *pActItem = SvxBrushItem( aBgdGraphic,
1537 eNewPos,
1538 pActItem->Which() );
1540 switch(nSelPos)
1542 case TBL_DEST_CELL:
1543 pActItem = pTableBck_Impl->pCellBrush;
1544 m_pLbSelect->Enable();
1545 nWhich = pTableBck_Impl->nCellWhich;
1546 break;
1547 case TBL_DEST_ROW:
1548 pActItem = pTableBck_Impl->pRowBrush;
1549 nWhich = pTableBck_Impl->nRowWhich;
1550 break;
1551 case TBL_DEST_TBL:
1552 pActItem = pTableBck_Impl->pTableBrush;
1553 m_pLbSelect->Enable();
1554 nWhich = pTableBck_Impl->nTableWhich;
1555 break;
1556 default:
1557 // The item will be new'ed again below, but that will be the
1558 // default item then, not an existing modified one.
1559 xItemHolder.reset();
1560 pActItem = NULL;
1561 break;
1563 OUString aUserData = GetUserData();
1564 if (!pActItem)
1566 xItemHolder.reset(new SvxBrushItem(nWhich));
1567 pActItem = xItemHolder.get();
1569 FillControls_Impl(*pActItem, aUserData);
1571 return 0;
1574 IMPL_LINK( SvxBackgroundTabPage, ParaDestinationHdl_Impl, ListBox*, pBox )
1576 sal_Int32 nSelPos = pBox->GetSelectEntryPos();
1577 if( pParaBck_Impl && pParaBck_Impl->nActPos != nSelPos)
1579 SvxBrushItem* pActItem = NULL;
1580 switch(pParaBck_Impl->nActPos)
1582 case PARA_DEST_PARA:
1583 pActItem = pParaBck_Impl->pParaBrush;
1584 break;
1585 case PARA_DEST_CHAR:
1586 pActItem = pParaBck_Impl->pCharBrush;
1587 break;
1588 default:
1589 /* we assert here because the rest of the code expect pActItem to be non NULL */
1590 assert(false);
1591 return 0;
1593 pParaBck_Impl->nActPos = nSelPos;
1594 if(drawing::FillStyle_SOLID == lcl_getFillStyle(m_pLbSelect)) // brush selected
1596 sal_uInt16 nWhich = pActItem->Which();
1597 *pActItem = SvxBrushItem( aBgdColor, nWhich );
1599 else
1601 SvxGraphicPosition eNewPos = GetGraphicPosition_Impl();
1602 const bool bIsLink = m_pBtnLink->IsChecked();
1604 if ( !bIsLink && !bIsGraphicValid )
1605 bIsGraphicValid = LoadLinkedGraphic_Impl();
1607 if ( bIsLink )
1608 *pActItem = SvxBrushItem( aBgdGraphicPath,
1609 aBgdGraphicFilter,
1610 eNewPos,
1611 pActItem->Which() );
1612 else
1613 *pActItem = SvxBrushItem( aBgdGraphic,
1614 eNewPos,
1615 pActItem->Which() );
1617 switch(nSelPos)
1619 case PARA_DEST_PARA:
1620 pActItem = pParaBck_Impl->pParaBrush;
1621 m_pLbSelect->Enable();
1622 break;
1623 case PARA_DEST_CHAR:
1625 pActItem = pParaBck_Impl->pCharBrush;
1626 m_pLbSelect->Enable(false);
1628 break;
1630 OUString aUserData = GetUserData();
1631 FillControls_Impl(*pActItem, aUserData);
1633 return 0;
1636 void SvxBackgroundTabPage::FillControls_Impl( const SvxBrushItem& rBgdAttr,
1637 const OUString& rUserData )
1639 SvxGraphicPosition ePos = rBgdAttr.GetGraphicPos();
1640 const Color& rColor = rBgdAttr.GetColor();
1641 if(bColTransparency)
1643 m_pColTransMF->SetValue(lcl_TransparencyToPercent(rColor.GetTransparency()));
1644 m_pColTransMF->SaveValue();
1645 bool bEnableTransp = rColor.GetTransparency() < 0xff;
1646 m_pColTransFT->Enable(bEnableTransp);
1647 m_pColTransMF->Enable(bEnableTransp);
1648 //the default setting should be "no transparency"
1649 if(!bEnableTransp)
1650 m_pColTransMF->SetValue(0);
1653 if ( GPOS_NONE == ePos || !m_pLbSelect->IsVisible() )
1655 lcl_setFillStyle(m_pLbSelect, drawing::FillStyle_SOLID);
1656 ShowColorUI_Impl();
1657 Color aTrColor( COL_TRANSPARENT );
1658 aBgdColor = rColor;
1660 sal_uInt16 nCol = ( aTrColor != aBgdColor ) ?
1661 GetItemId_Impl(*m_pBackgroundColorSet, aBgdColor) : 0;
1663 if( aTrColor != aBgdColor && nCol == 0)
1665 m_pBackgroundColorSet->SetNoSelection();
1667 else
1669 m_pBackgroundColorSet->SelectItem( nCol );
1672 m_pPreviewWin1->NotifyChange( aBgdColor );
1674 if ( m_pLbSelect->IsVisible() ) // initialize graphic part
1676 aBgdGraphicFilter.clear();
1677 aBgdGraphicPath.clear();
1679 if ( rUserData.isEmpty() )
1680 m_pBtnPreview->Check( false );
1681 m_pBtnLink->Check( false );
1682 m_pBtnLink->Disable();
1683 m_pPreviewWin2->NotifyChange( NULL );
1684 SetGraphicPosition_Impl( GPOS_TILED ); // tiles as default
1687 else
1689 const OUString aStrLink = rBgdAttr.GetGraphicLink();
1690 const OUString aStrFilter = rBgdAttr.GetGraphicFilter();
1692 lcl_setFillStyle(m_pLbSelect, drawing::FillStyle_BITMAP);
1693 ShowBitmapUI_Impl();
1695 if ( !aStrLink.isEmpty() )
1697 #ifdef DBG_UTIL
1698 INetURLObject aObj( aStrLink );
1699 DBG_ASSERT( aObj.GetProtocol() != INetProtocol::NotValid, "Invalid URL!" );
1700 #endif
1701 aBgdGraphicPath = aStrLink;
1702 m_pBtnLink->Check( true );
1703 m_pBtnLink->Enable();
1705 else
1707 aBgdGraphicPath.clear();
1708 m_pBtnLink->Check( false );
1709 m_pBtnLink->Disable();
1712 if (bGraphTransparency)
1714 const GraphicObject* pObject = rBgdAttr.GetGraphicObject();
1715 if(pObject)
1716 m_pGraphTransMF->SetValue(lcl_TransparencyToPercent(pObject->GetAttr().GetTransparency()));
1717 else
1718 m_pGraphTransMF->SetValue(0);
1719 m_pGraphTransMF->SaveValue();
1722 FileClickHdl_Impl(m_pBtnLink);
1724 aBgdGraphicFilter = aStrFilter;
1726 if ( aStrLink.isEmpty() || m_pBtnPreview->IsChecked() )
1728 // Graphic exists in the item and doesn't have
1729 // to be loaded:
1731 const Graphic* pGraphic = rBgdAttr.GetGraphic();
1733 if ( !pGraphic && m_pBtnPreview->IsChecked() )
1734 bIsGraphicValid = LoadLinkedGraphic_Impl();
1735 else if ( pGraphic )
1737 aBgdGraphic = *pGraphic;
1738 bIsGraphicValid = true;
1740 if ( rUserData.isEmpty() )
1741 m_pBtnPreview->Check();
1743 else
1745 RaiseLoadError_Impl();
1746 bIsGraphicValid = false;
1748 if ( rUserData.isEmpty() )
1749 m_pBtnPreview->Check( false );
1753 if ( m_pBtnPreview->IsChecked() && bIsGraphicValid )
1755 Bitmap aBmp = aBgdGraphic.GetBitmap();
1756 m_pPreviewWin2->NotifyChange( &aBmp );
1758 else
1759 m_pPreviewWin2->NotifyChange( NULL );
1761 SetGraphicPosition_Impl( ePos );
1765 void SvxBackgroundTabPage::EnableTransparency(bool bColor, bool bGraphic)
1767 bColTransparency = bColor;
1768 bGraphTransparency = bGraphic;
1769 m_pColTransFT->Show(bColor);
1770 m_pColTransMF->Show(bColor);
1773 void SvxBackgroundTabPage::PageCreated(const SfxAllItemSet& aSet)
1775 SFX_ITEMSET_ARG (&aSet,pFlagItem,SfxUInt32Item,SID_FLAG_TYPE,false);
1777 if (pFlagItem)
1779 SvxBackgroundTabFlags nFlags = static_cast<SvxBackgroundTabFlags>(pFlagItem->GetValue());
1780 if (nFlags & SvxBackgroundTabFlags::SHOW_TBLCTL )
1781 ShowTblControl();
1782 if ( nFlags & SvxBackgroundTabFlags::SHOW_PARACTL )
1783 ShowParaControl();
1784 if ( nFlags & SvxBackgroundTabFlags::SHOW_SELECTOR )
1785 ShowSelector();
1786 if ( nFlags & SvxBackgroundTabFlags::ENABLE_TRANSPARENCY )
1787 EnableTransparency(true, true);
1791 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */