bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / tabpages / backgrnd.cxx
blobdde5853986f6070738c142a84b1b932895eca1e2
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(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 , bHighlighting(false)
362 , pPageImpl(new SvxBackgroundPage_Impl)
363 , pImportDlg(NULL)
364 , pTableBck_Impl(NULL)
365 , pParaBck_Impl(NULL)
366 , pHighlighting(nullptr)
368 get(m_pAsGrid, "asgrid");
369 get(m_pSelectTxt, "asft");
370 get(m_pLbSelect, "selectlb");
371 get(m_pTblDesc, "forft");
372 get(m_pTblLBox, "tablelb");
373 get(m_pParaLBox, "paralb");
375 get(m_pBackGroundColorLabelFT, "background_label");
376 get(m_pBackGroundColorFrame, "backgroundcolorframe");
377 get(m_pBackgroundColorSet, "backgroundcolorset");
378 get(m_pPreviewWin1, "preview1");
380 get(m_pColTransFT, "transparencyft");
381 get(m_pColTransMF, "transparencymf");
382 get(m_pBtnPreview, "showpreview");
384 get(m_pBitmapContainer, "graphicgrid");
385 get(m_pFileFrame, "fileframe");
386 get(m_pBtnBrowse, "browse");
387 get(m_pBtnLink, "link");
388 get(m_pFtUnlinked, "unlinkedft");
389 get(m_pFtFile, "fileft");
391 get(m_pTypeFrame, "typeframe");
392 get(m_pBtnPosition, "positionrb");
393 get(m_pBtnArea, "arearb");
394 get(m_pBtnTile, "tilerb");
395 get(m_pWndPosition, "windowpos");
397 get(m_pGraphTransFrame, "graphtransframe");
398 get(m_pGraphTransMF, "graphtransmf");
400 get(m_pPreviewWin2, "preview2");
401 m_pPreviewWin2->setBmp(true);
403 // this page needs ExchangeSupport
404 SetExchangeSupport();
406 const SfxPoolItem* pItem;
407 SfxObjectShell* pShell;
409 if ( SfxItemState::SET == rCoreSet.GetItemState( SID_HTML_MODE, false, &pItem )
410 || ( 0 != ( pShell = SfxObjectShell::Current()) &&
411 0 != ( pItem = pShell->GetItem( SID_HTML_MODE ) ) ) )
413 nHtmlMode = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
416 FillColorValueSets_Impl();
418 m_pBackgroundColorSet->SetSelectHdl( HDL(BackgroundColorHdl_Impl) );
419 m_pBackgroundColorSet->SetStyle(m_pBackgroundColorSet->GetStyle() | WB_ITEMBORDER | WB_NAMEFIELD | WB_NONEFIELD);
420 m_pBackgroundColorSet->SetText(SVX_RESSTR(RID_SVXSTR_TRANSPARENT));
423 SvxBackgroundTabPage::~SvxBackgroundTabPage()
425 disposeOnce();
428 void SvxBackgroundTabPage::dispose()
430 if (pPageImpl)
432 delete pPageImpl->pLoadIdle;
433 delete pPageImpl;
434 pPageImpl = NULL;
437 delete pImportDlg;
438 pImportDlg = NULL;
440 if( pTableBck_Impl)
442 delete pTableBck_Impl->pCellBrush;
443 delete pTableBck_Impl->pRowBrush;
444 delete pTableBck_Impl->pTableBrush;
445 delete pTableBck_Impl;
446 pTableBck_Impl = NULL;
449 if(pParaBck_Impl)
451 delete pParaBck_Impl->pParaBrush;
452 delete pParaBck_Impl->pCharBrush;
453 delete pParaBck_Impl;
454 pParaBck_Impl = NULL;
457 m_pAsGrid.clear();
458 m_pSelectTxt.clear();
459 m_pLbSelect.clear();
460 m_pTblDesc.clear();
461 m_pTblLBox.clear();
462 m_pParaLBox.clear();
463 m_pBackGroundColorFrame.clear();
464 m_pBackgroundColorSet.clear();
465 m_pPreviewWin1.clear();
466 m_pColTransFT.clear();
467 m_pColTransMF.clear();
468 m_pBtnPreview.clear();
469 m_pBitmapContainer.clear();
470 m_pFileFrame.clear();
471 m_pBtnBrowse.clear();
472 m_pBtnLink.clear();
473 m_pFtUnlinked.clear();
474 m_pFtFile.clear();
475 m_pTypeFrame.clear();
476 m_pBtnPosition.clear();
477 m_pBtnArea.clear();
478 m_pBtnTile.clear();
479 m_pWndPosition.clear();
480 m_pGraphTransFrame.clear();
481 m_pGraphTransMF.clear();
482 m_pPreviewWin2.clear();
483 SvxTabPage::dispose();
486 VclPtr<SfxTabPage> SvxBackgroundTabPage::Create( vcl::Window* pParent, const SfxItemSet* rAttrSet )
488 return VclPtr<SvxBackgroundTabPage>::Create( pParent, *rAttrSet );
491 void SvxBackgroundTabPage::Reset( const SfxItemSet* rSet )
493 // os: Such a nonsense! One will always find such an item somewhere,
494 // but it must be existing in the rSet!
495 // const SfxPoolItem* pX = GetOldItem( rSet, SID_VIEW_FLD_PIC );
496 // if( pX && pX->ISA(SfxWallpaperItem))
497 if(SfxItemState::DEFAULT <= rSet->GetItemState(GetWhich(SID_VIEW_FLD_PIC), false))
499 ResetFromWallpaperItem( *rSet );
500 return;
503 // condition of the preview button is persistent due to UserData
504 OUString aUserData = GetUserData();
505 m_pBtnPreview->Check( !aUserData.isEmpty() && '1' == aUserData[0] );
507 // don't be allowed to call ShowSelector() after reset anymore
508 bAllowShowSelector = false;
511 // get and evaluate Input-BrushItem
512 const SvxBrushItem* pBgdAttr = NULL;
513 sal_uInt16 nSlot = SID_ATTR_BRUSH;
514 const SfxPoolItem* pItem;
515 sal_uInt16 nDestValue = USHRT_MAX;
517 if ( SfxItemState::SET == rSet->GetItemState( SID_BACKGRND_DESTINATION,
518 false, &pItem ) )
520 nDestValue = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
521 m_pTblLBox->SelectEntryPos(nDestValue);
523 switch ( nDestValue )
525 case TBL_DEST_CELL:
526 nSlot = SID_ATTR_BRUSH;
527 break;
528 case TBL_DEST_ROW:
529 nSlot = SID_ATTR_BRUSH_ROW;
530 break;
531 case TBL_DEST_TBL:
532 nSlot = SID_ATTR_BRUSH_TABLE;
533 break;
536 else if( SfxItemState::SET == rSet->GetItemState(
537 SID_PARA_BACKGRND_DESTINATION, false, &pItem ) )
539 nDestValue = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
540 // character activated?
541 sal_Int32 nParaSel = m_pParaLBox->GetSelectEntryPos();
542 if(1 == nParaSel)
544 // then it was a "standard"-call
545 nDestValue = nParaSel;
547 m_pParaLBox->SelectEntryPos(nDestValue);
549 switch ( nDestValue )
551 case PARA_DEST_PARA:
552 nSlot = SID_ATTR_BRUSH;
553 break;
554 case PARA_DEST_CHAR:
555 nSlot = SID_ATTR_BRUSH_CHAR;
556 break;
559 else if( bHighlighting )
561 nSlot = SID_ATTR_BRUSH_CHAR;
563 //#111173# the destination item is missing when the parent style has been changed
564 if(USHRT_MAX == nDestValue && (m_pParaLBox->IsVisible()||m_pTblLBox->IsVisible()))
565 nDestValue = 0;
566 sal_uInt16 nWhich = GetWhich( nSlot );
568 if ( rSet->GetItemState( nWhich, false ) >= SfxItemState::DEFAULT )
569 pBgdAttr = static_cast<const SvxBrushItem*>(&( rSet->Get( nWhich ) ));
571 m_pBtnTile->Check();
573 if ( pBgdAttr )
575 FillControls_Impl(*pBgdAttr, aUserData);
576 aBgdColor = const_cast<SvxBrushItem*>(pBgdAttr)->GetColor();
578 else
580 m_pSelectTxt->Hide();
581 m_pLbSelect->Hide();
582 lcl_setFillStyle(m_pLbSelect, drawing::FillStyle_SOLID);
583 ShowColorUI_Impl();
585 const SfxPoolItem* pOld = GetOldItem( *rSet, SID_ATTR_BRUSH );
587 if ( pOld )
588 aBgdColor = static_cast<const SvxBrushItem*>(pOld)->GetColor();
591 if ( nDestValue != USHRT_MAX )
593 if(m_pTblLBox->IsVisible())
595 sal_Int32 nValue = m_pTblLBox->GetSelectEntryPos();
597 if ( pTableBck_Impl )
599 DELETEZ( pTableBck_Impl->pCellBrush);
600 DELETEZ( pTableBck_Impl->pRowBrush);
601 DELETEZ( pTableBck_Impl->pTableBrush);
603 else
604 pTableBck_Impl = new SvxBackgroundTable_Impl();
606 pTableBck_Impl->nActPos = nValue;
608 nWhich = GetWhich( SID_ATTR_BRUSH );
609 if ( rSet->GetItemState( nWhich, false ) >= SfxItemState::DEFAULT )
611 pBgdAttr = static_cast<const SvxBrushItem*>(&( rSet->Get( nWhich ) ));
612 pTableBck_Impl->pCellBrush = new SvxBrushItem(*pBgdAttr);
614 pTableBck_Impl->nCellWhich = nWhich;
616 if ( rSet->GetItemState( SID_ATTR_BRUSH_ROW, false ) >= SfxItemState::DEFAULT )
618 pBgdAttr = static_cast<const SvxBrushItem*>(&( rSet->Get( SID_ATTR_BRUSH_ROW ) ));
619 pTableBck_Impl->pRowBrush = new SvxBrushItem(*pBgdAttr);
621 pTableBck_Impl->nRowWhich = SID_ATTR_BRUSH_ROW;
623 if ( rSet->GetItemState( SID_ATTR_BRUSH_TABLE, false ) >= SfxItemState::DEFAULT )
625 pBgdAttr = static_cast<const SvxBrushItem*>(&( rSet->Get( SID_ATTR_BRUSH_TABLE ) ));
626 pTableBck_Impl->pTableBrush = new SvxBrushItem(*pBgdAttr);
628 pTableBck_Impl->nTableWhich = SID_ATTR_BRUSH_TABLE;
630 TblDestinationHdl_Impl(m_pTblLBox);
631 m_pTblLBox->SaveValue();
633 else if (m_pParaLBox->GetData() == m_pParaLBox)
635 sal_Int32 nValue = m_pParaLBox->GetSelectEntryPos();
637 if ( pParaBck_Impl )
639 delete pParaBck_Impl->pParaBrush;
640 delete pParaBck_Impl->pCharBrush;
642 else
643 pParaBck_Impl = new SvxBackgroundPara_Impl();
645 pParaBck_Impl->nActPos = nValue;
647 nWhich = GetWhich( SID_ATTR_BRUSH );
648 if ( rSet->GetItemState( nWhich, false ) >= SfxItemState::DEFAULT )
650 pBgdAttr = static_cast<const SvxBrushItem*>(&( rSet->Get( nWhich ) ));
651 pParaBck_Impl->pParaBrush = new SvxBrushItem(*pBgdAttr);
654 nWhich = GetWhich( SID_ATTR_BRUSH_CHAR );
655 rSet->GetItemState( nWhich, true );
656 rSet->GetItemState( nWhich, false );
657 if ( rSet->GetItemState( nWhich, true ) > SfxItemState::DEFAULT )
659 pBgdAttr = static_cast<const SvxBrushItem*>(&( rSet->Get( nWhich ) ));
660 pParaBck_Impl->pCharBrush = new SvxBrushItem(*pBgdAttr);
662 else
663 pParaBck_Impl->pCharBrush = new SvxBrushItem(SID_ATTR_BRUSH_CHAR);
665 ParaDestinationHdl_Impl(m_pParaLBox);
666 m_pParaLBox->SaveValue();
668 else if( bHighlighting )
670 nWhich = GetWhich( SID_ATTR_BRUSH_CHAR );
671 if ( rSet->GetItemState( nWhich, false ) >= SfxItemState::DEFAULT )
673 pBgdAttr = static_cast<const SvxBrushItem*>(&( rSet->Get( nWhich ) ));
674 pHighlighting.reset(new SvxBrushItem(*pBgdAttr));
680 void SvxBackgroundTabPage::ResetFromWallpaperItem( const SfxItemSet& rSet )
682 ShowSelector();
684 // condition of the preview button is persistent due to UserData
685 OUString aUserData = GetUserData();
686 m_pBtnPreview->Check( !aUserData.isEmpty() && '1' == aUserData[0] );
688 // get and evaluate Input-BrushItem
689 const SvxBrushItem* pBgdAttr = NULL;
690 sal_uInt16 nSlot = SID_VIEW_FLD_PIC;
691 sal_uInt16 nWhich = GetWhich( nSlot );
692 boost::scoped_ptr<SvxBrushItem> pTemp;
694 if ( rSet.GetItemState( nWhich, false ) >= SfxItemState::DEFAULT )
696 const CntWallpaperItem* pItem = static_cast<const CntWallpaperItem*>(&rSet.Get( nWhich ));
697 pTemp.reset(new SvxBrushItem( *pItem, nWhich ));
698 pBgdAttr = pTemp.get();
701 m_pBtnTile->Check();
703 if ( pBgdAttr )
705 FillControls_Impl(*pBgdAttr, aUserData);
706 // brush shall be kept when showing the graphic, too
707 if( aBgdColor != pBgdAttr->GetColor() )
709 aBgdColor = pBgdAttr->GetColor();
710 sal_uInt16 nCol = GetItemId_Impl(*m_pBackgroundColorSet, aBgdColor);
711 m_pBackgroundColorSet->SelectItem( nCol );
712 m_pPreviewWin1->NotifyChange( aBgdColor );
715 else
717 lcl_setFillStyle(m_pLbSelect, drawing::FillStyle_SOLID);
718 ShowColorUI_Impl();
720 const SfxPoolItem* pOld = GetOldItem( rSet, SID_VIEW_FLD_PIC );
721 if ( pOld )
722 aBgdColor = Color( static_cast<const CntWallpaperItem*>(pOld)->GetColor() );
725 // We now have always a link to the background
726 bLinkOnly = true;
727 m_pBtnLink->Check( true );
728 m_pBtnLink->Show( false );
731 /** When destroying a SfxTabPage this virtual method is called,
732 so that the TabPage can save internal information.
734 In this case the condition of the preview button is saved.
736 void SvxBackgroundTabPage::FillUserData()
740 SetUserData( m_pBtnPreview->IsChecked() ? OUString('1') : OUString('0') );
743 bool SvxBackgroundTabPage::FillItemSet( SfxItemSet* rCoreSet )
745 if ( pPageImpl->pLoadIdle && pPageImpl->pLoadIdle->IsActive() )
747 pPageImpl->pLoadIdle->Stop();
748 LoadIdleHdl_Impl( pPageImpl->pLoadIdle );
750 // os: Such a nonsense! One will always find such an item somewhere,
751 // but it must be existing in the rSet!
753 // const SfxPoolItem* pX = GetOldItem( rCoreSet, SID_VIEW_FLD_PIC );
754 // if( pX && pX->ISA(SfxWallpaperItem))
755 if(SfxItemState::DEFAULT <= rCoreSet->GetItemState(GetWhich(SID_VIEW_FLD_PIC), false))
756 return FillItemSetWithWallpaperItem( *rCoreSet, SID_VIEW_FLD_PIC );
758 bool bModified = false;
759 sal_uInt16 nSlot = SID_ATTR_BRUSH;
761 if ( m_pTblLBox->IsVisible() )
763 switch( m_pTblLBox->GetSelectEntryPos() )
765 case TBL_DEST_CELL:
766 nSlot = SID_ATTR_BRUSH;
767 break;
768 case TBL_DEST_ROW:
769 nSlot = SID_ATTR_BRUSH_ROW;
770 break;
771 case TBL_DEST_TBL:
772 nSlot = SID_ATTR_BRUSH_TABLE;
773 break;
776 else if (m_pParaLBox->GetData() == m_pParaLBox)
778 switch(m_pParaLBox->GetSelectEntryPos())
780 case PARA_DEST_PARA:
781 nSlot = SID_ATTR_BRUSH;
782 break;
783 case PARA_DEST_CHAR:
784 nSlot = SID_ATTR_BRUSH_CHAR;
785 break;
788 else if( bHighlighting )
790 nSlot = SID_ATTR_BRUSH_CHAR;
792 sal_uInt16 nWhich = GetWhich( nSlot );
794 const SfxPoolItem* pOld = GetOldItem( *rCoreSet, nSlot );
795 SfxItemState eOldItemState = rCoreSet->GetItemState(nSlot, false);
796 const SfxItemSet& rOldSet = GetItemSet();
798 bool bGraphTransparencyChanged = bGraphTransparency && m_pGraphTransMF->IsValueChangedFromSaved();
799 if ( pOld )
801 const SvxBrushItem& rOldItem = static_cast<const SvxBrushItem&>(*pOld);
802 SvxGraphicPosition eOldPos = rOldItem.GetGraphicPos();
803 const bool bIsBrush = ( drawing::FillStyle_SOLID == lcl_getFillStyle(m_pLbSelect) );
805 // transparency has to be set if enabled, the color not already set to "No fill" and
806 if( bColTransparency &&
807 aBgdColor.GetTransparency() < 0xff)
809 aBgdColor.SetTransparency(lcl_PercentToTransparency(static_cast<long>(m_pColTransMF->GetValue())));
811 if ( ( (GPOS_NONE == eOldPos) && bIsBrush )
812 || ( (GPOS_NONE != eOldPos) && !bIsBrush ) ) // Brush <-> Bitmap changed?
814 // background art hasn't been changed:
816 if ( (GPOS_NONE == eOldPos) || !m_pLbSelect->IsVisible() )
818 // Brush-treatment:
819 if ( rOldItem.GetColor() != aBgdColor ||
820 (SfxItemState::DEFAULT >= eOldItemState && !m_pBackgroundColorSet->IsNoSelection()))
822 bModified = true;
823 rCoreSet->Put( SvxBrushItem( aBgdColor, nWhich ) );
825 else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) )
826 rCoreSet->ClearItem( nWhich );
828 else
830 // Bitmap-treatment:
832 SvxGraphicPosition eNewPos = GetGraphicPosition_Impl();
833 const bool bIsLink = m_pBtnLink->IsChecked();
834 const bool bWasLink = (NULL != rOldItem.GetGraphicLink() );
837 if ( !bIsLink && !bIsGraphicValid )
838 bIsGraphicValid = LoadLinkedGraphic_Impl();
840 bool bModifyBrush = false;
841 if (bGraphTransparencyChanged || eNewPos != eOldPos || bIsLink != bWasLink)
842 bModifyBrush = true;
843 else if (bWasLink && rOldItem.GetGraphicLink() != aBgdGraphicPath)
844 bModifyBrush = true;
845 else if (!bWasLink)
847 const Graphic* pGraphic = rOldItem.GetGraphic();
848 if (pGraphic)
849 bModifyBrush = pGraphic->GetBitmap() != aBgdGraphic.GetBitmap();
851 if (bModifyBrush)
853 bModified = true;
855 SvxBrushItem aTmpBrush(nWhich);
856 if ( bIsLink )
858 aTmpBrush = SvxBrushItem( aBgdGraphicPath,
859 aBgdGraphicFilter,
860 eNewPos,
861 nWhich );
863 else
864 aTmpBrush = SvxBrushItem( aBgdGraphic,
865 eNewPos,
866 nWhich );
867 lcl_SetTransparency(aTmpBrush, static_cast<long>(m_pGraphTransMF->GetValue()));
869 rCoreSet->Put(aTmpBrush);
871 else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) )
872 rCoreSet->ClearItem( nWhich );
875 else // Brush <-> Bitmap changed!
877 if ( bIsBrush )
879 rCoreSet->Put( SvxBrushItem( aBgdColor, nWhich ) );
881 else
883 boost::scoped_ptr<SvxBrushItem> pTmpBrush;
884 if ( m_pBtnLink->IsChecked() )
886 pTmpBrush.reset(new SvxBrushItem( aBgdGraphicPath,
887 aBgdGraphicFilter,
888 GetGraphicPosition_Impl(),
889 nWhich ));
891 else
893 if ( !bIsGraphicValid )
894 bIsGraphicValid = LoadLinkedGraphic_Impl();
896 if ( bIsGraphicValid )
897 pTmpBrush.reset(new SvxBrushItem( aBgdGraphic,
898 GetGraphicPosition_Impl(),
899 nWhich ));
901 if(pTmpBrush)
903 lcl_SetTransparency(*pTmpBrush, static_cast<long>(m_pGraphTransMF->GetValue()));
904 rCoreSet->Put(*pTmpBrush);
907 bModified = ( bIsBrush || m_pBtnLink->IsChecked() || bIsGraphicValid );
910 else if ( SID_ATTR_BRUSH_CHAR == nSlot && aBgdColor != Color( COL_WHITE ) )
912 rCoreSet->Put( SvxBrushItem( aBgdColor, nWhich ) );
913 bModified = true;
916 if( m_pTblLBox->IsVisible() )
918 // the current condition has already been put
919 if( nSlot != SID_ATTR_BRUSH && pTableBck_Impl->pCellBrush)
921 const SfxPoolItem* pOldCell =
922 GetOldItem( *rCoreSet, SID_ATTR_BRUSH );
924 if ( *pTableBck_Impl->pCellBrush != *pOldCell )
926 rCoreSet->Put( *pTableBck_Impl->pCellBrush );
927 bModified |= true;
931 if( nSlot != SID_ATTR_BRUSH_ROW && pTableBck_Impl->pRowBrush)
933 const SfxPoolItem* pOldRow =
934 GetOldItem( *rCoreSet, SID_ATTR_BRUSH_ROW );
936 if ( *pTableBck_Impl->pRowBrush != *pOldRow )
938 rCoreSet->Put( *pTableBck_Impl->pRowBrush );
939 bModified |= true;
943 if( nSlot != SID_ATTR_BRUSH_TABLE && pTableBck_Impl->pTableBrush)
945 const SfxPoolItem* pOldTable =
946 GetOldItem( *rCoreSet, SID_ATTR_BRUSH_TABLE );
948 if ( *pTableBck_Impl->pTableBrush != *pOldTable )
950 rCoreSet->Put( *pTableBck_Impl->pTableBrush );
951 bModified |= true;
955 if( m_pTblLBox->IsValueChangedFromSaved() )
957 rCoreSet->Put( SfxUInt16Item( SID_BACKGRND_DESTINATION,
958 m_pTblLBox->GetSelectEntryPos() ) );
959 bModified |= true;
962 else if (m_pParaLBox->GetData() == m_pParaLBox)
964 // the current condition has already been put
965 if( nSlot != SID_ATTR_BRUSH && m_pParaLBox->IsVisible()) // not in search format dialog
967 const SfxPoolItem* pOldPara =
968 GetOldItem( *rCoreSet, SID_ATTR_BRUSH );
970 if ( *pParaBck_Impl->pParaBrush != *pOldPara )
972 rCoreSet->Put( *pParaBck_Impl->pParaBrush );
973 bModified |= true;
977 if( nSlot != SID_ATTR_BRUSH_CHAR )
979 const SfxPoolItem* pOldChar =
980 GetOldItem( *rCoreSet, SID_ATTR_BRUSH_CHAR );
981 DBG_ASSERT(pParaBck_Impl, "pParaBck_Impl == NULL ?");
982 if ( pOldChar &&
983 //#111173# crash report shows that pParaBck_Impl can be NULL, the cause is unknown
984 pParaBck_Impl &&
985 (*pParaBck_Impl->pCharBrush != *pOldChar ||
986 *pParaBck_Impl->pCharBrush != SvxBrushItem(SID_ATTR_BRUSH_CHAR)))
988 rCoreSet->Put( *pParaBck_Impl->pCharBrush );
989 bModified |= true;
993 if( m_pParaLBox->IsValueChangedFromSaved() )
995 rCoreSet->Put( SfxUInt16Item( SID_BACKGRND_DESTINATION,
996 m_pParaLBox->GetSelectEntryPos() ) );
997 bModified |= true;
1000 else if( bHighlighting )
1002 if( nSlot != SID_ATTR_BRUSH_CHAR )
1004 const SfxPoolItem* pOldChar =
1005 GetOldItem( *rCoreSet, SID_ATTR_BRUSH_CHAR );
1006 if ( pOldChar && pHighlighting &&
1007 (*pHighlighting != *pOldChar || *pHighlighting != SvxBrushItem(SID_ATTR_BRUSH_CHAR)))
1009 rCoreSet->Put( *pHighlighting );
1010 bModified |= true;
1014 return bModified;
1017 bool SvxBackgroundTabPage::FillItemSetWithWallpaperItem( SfxItemSet& rCoreSet, sal_uInt16 nSlot)
1019 sal_uInt16 nWhich = GetWhich( nSlot );
1020 const SfxPoolItem* pOld = GetOldItem( rCoreSet, nSlot );
1021 DBG_ASSERT(pOld,"FillItemSetWithWallpaperItem: Item not found");
1022 if (!pOld)
1023 return false;
1024 const SfxItemSet& rOldSet = GetItemSet();
1026 SvxBrushItem rOldItem( static_cast<const CntWallpaperItem&>(*pOld), nWhich );
1027 SvxGraphicPosition eOldPos = rOldItem.GetGraphicPos();
1028 const bool bIsBrush = ( drawing::FillStyle_SOLID == lcl_getFillStyle(m_pLbSelect) );
1029 bool bModified = false;
1031 if ( ( (GPOS_NONE == eOldPos) && bIsBrush )
1032 || ( (GPOS_NONE != eOldPos) && !bIsBrush ) ) // Brush <-> Bitmap changed?
1034 // background art hasn't been changed
1036 if ( (GPOS_NONE == eOldPos) || !m_pLbSelect->IsVisible() )
1038 // Brush-treatment:
1039 if ( rOldItem.GetColor() != aBgdColor )
1041 bModified = true;
1042 CntWallpaperItem aItem( nWhich );
1043 aItem.SetColor( aBgdColor );
1044 rCoreSet.Put( aItem );
1046 else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) )
1047 rCoreSet.ClearItem( nWhich );
1049 else
1051 // Bitmap-treatment:
1052 SvxGraphicPosition eNewPos = GetGraphicPosition_Impl();
1054 bool bBitmapChanged = ( ( eNewPos != eOldPos ) ||
1055 ( rOldItem.GetGraphicLink() != aBgdGraphicPath ) );
1056 bool bBrushChanged = ( rOldItem.GetColor() != aBgdColor );
1057 if( bBitmapChanged || bBrushChanged )
1059 bModified = true;
1061 CntWallpaperItem aItem( nWhich );
1062 WallpaperStyle eWallStyle = SvxBrushItem::GraphicPos2WallpaperStyle(eNewPos);
1063 aItem.SetStyle( sal::static_int_cast< sal_uInt16 >( eWallStyle ) );
1064 aItem.SetColor( aBgdColor );
1065 aItem.SetBitmapURL( aBgdGraphicPath );
1066 rCoreSet.Put( aItem );
1068 else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) )
1069 rCoreSet.ClearItem( nWhich );
1072 else // Brush <-> Bitmap changed!
1074 CntWallpaperItem aItem( nWhich );
1075 if ( bIsBrush )
1077 aItem.SetColor( aBgdColor );
1078 rCoreSet.Put( aItem );
1080 else
1082 WallpaperStyle eWallStyle =
1083 SvxBrushItem::GraphicPos2WallpaperStyle( GetGraphicPosition_Impl() );
1084 aItem.SetStyle( sal::static_int_cast< sal_uInt16 >( eWallStyle ) );
1085 aItem.SetColor( aBgdColor );
1086 aItem.SetBitmapURL( aBgdGraphicPath );
1087 rCoreSet.Put( aItem );
1090 bModified = true;
1092 return bModified;
1095 /** virtual method; is called on deactivation */
1096 SfxTabPage::sfxpg SvxBackgroundTabPage::DeactivatePage( SfxItemSet* _pSet )
1098 if ( pPageImpl->bIsImportDlgInExecute )
1099 return KEEP_PAGE;
1101 if ( _pSet )
1102 FillItemSet( _pSet );
1104 return LEAVE_PAGE;
1107 void SvxBackgroundTabPage::PointChanged( vcl::Window* , RECT_POINT )
1109 // has to be implemented so that position control can work
1112 void SvxBackgroundTabPage::ShowSelector()
1114 if( bAllowShowSelector)
1116 m_pAsGrid->Show();
1117 m_pSelectTxt->Show();
1118 m_pLbSelect->Show();
1119 m_pLbSelect->SetSelectHdl( HDL(SelectHdl_Impl) );
1120 m_pBtnLink->SetClickHdl( HDL(FileClickHdl_Impl) );
1121 m_pBtnPreview->SetClickHdl( HDL(FileClickHdl_Impl) );
1122 m_pBtnBrowse->SetClickHdl( HDL(BrowseHdl_Impl) );
1123 m_pBtnArea->SetClickHdl( HDL(RadioClickHdl_Impl) );
1124 m_pBtnTile->SetClickHdl( HDL(RadioClickHdl_Impl) );
1125 m_pBtnPosition->SetClickHdl( HDL(RadioClickHdl_Impl) );
1127 // delayed loading via timer (because of UI-Update)
1128 pPageImpl->pLoadIdle = new Idle;
1129 pPageImpl->pLoadIdle->SetPriority( SchedulerPriority::LOWEST );
1130 pPageImpl->pLoadIdle->SetIdleHdl(
1131 LINK( this, SvxBackgroundTabPage, LoadIdleHdl_Impl ) );
1133 bAllowShowSelector = false;
1135 if(nHtmlMode & HTMLMODE_ON)
1137 m_pBtnArea->Enable(false);
1142 void SvxBackgroundTabPage::RaiseLoadError_Impl()
1144 SfxErrorContext aContext( ERRCTX_SVX_BACKGROUND,
1145 OUString(),
1146 this,
1147 RID_SVXERRCTX,
1148 &CUI_MGR() );
1150 ErrorHandler::HandleError(
1151 *new StringErrorInfo( ERRCODE_SVX_GRAPHIC_NOTREADABLE,
1152 aBgdGraphicPath ) );
1155 bool SvxBackgroundTabPage::LoadLinkedGraphic_Impl()
1157 bool bResult = ( !aBgdGraphicPath.isEmpty() ) &&
1158 ( GRFILTER_OK == GraphicFilter::LoadGraphic( aBgdGraphicPath,
1159 aBgdGraphicFilter,
1160 aBgdGraphic ) );
1161 return bResult;
1164 void SvxBackgroundTabPage::FillColorValueSets_Impl()
1166 SfxObjectShell* pDocSh = SfxObjectShell::Current();
1167 const SfxPoolItem* pItem = NULL;
1168 XColorListRef pColorTable = NULL;
1169 if ( pDocSh && ( 0 != ( pItem = pDocSh->GetItem( SID_COLOR_TABLE ) ) ) )
1171 pColorTable = static_cast<const SvxColorListItem*>(pItem)->GetColorList();
1174 if ( !pColorTable.is() )
1175 pColorTable = XColorList::CreateStdColorList();
1177 if ( pColorTable.is() )
1179 m_pBackgroundColorSet->Clear();
1180 m_pBackgroundColorSet->addEntriesForXColorList(*pColorTable);
1183 const WinBits nBits(m_pBackgroundColorSet->GetStyle() | WB_ITEMBORDER | WB_NAMEFIELD | WB_NONEFIELD);
1184 m_pBackgroundColorSet->SetStyle(nBits);
1185 m_pBackgroundColorSet->SetColCount(SvxColorValueSet::getColumnCount());
1188 /** Hide the controls for editing the bitmap
1189 and show the controls for color settings instead.
1191 void SvxBackgroundTabPage::ShowColorUI_Impl()
1193 if (!m_pBackGroundColorFrame->IsVisible())
1195 HideBitmapUI_Impl();
1196 m_pBackGroundColorFrame->Show();
1198 if(bColTransparency)
1200 m_pColTransFT->Show();
1201 m_pColTransMF->Show();
1206 void SvxBackgroundTabPage::HideColorUI_Impl()
1208 m_pBackGroundColorFrame->Hide();
1211 /** Hide the controls for color settings
1212 and show controls for editing the bitmap instead.
1214 void SvxBackgroundTabPage::ShowBitmapUI_Impl()
1216 if (m_pLbSelect->IsVisible() &&
1217 (m_pBackGroundColorFrame->IsVisible() || !m_pFileFrame->IsVisible()))
1219 HideColorUI_Impl();
1222 m_pBitmapContainer->Show();
1224 m_pFileFrame->Show();
1225 m_pBtnLink->Show(!bLinkOnly && !(nHtmlMode & HTMLMODE_ON));
1227 m_pTypeFrame->Show();
1229 m_pPreviewWin2->Show();
1230 m_pBtnPreview->Show();
1232 m_pGraphTransFrame->Show(bGraphTransparency);
1233 m_pColTransFT->Show(false);
1234 m_pColTransMF->Show(false);
1238 void SvxBackgroundTabPage::HideBitmapUI_Impl()
1240 m_pBitmapContainer->Hide();
1241 m_pFileFrame->Hide();
1242 m_pTypeFrame->Hide();
1243 m_pPreviewWin2->Hide();
1244 m_pBtnPreview->Hide();
1245 m_pGraphTransFrame->Hide();
1248 void SvxBackgroundTabPage::SetGraphicPosition_Impl( SvxGraphicPosition ePos )
1250 switch ( ePos )
1252 case GPOS_AREA:
1254 m_pBtnArea->Check();
1255 m_pWndPosition->Disable();
1257 break;
1259 case GPOS_TILED:
1261 m_pBtnTile->Check();
1262 m_pWndPosition->Disable();
1264 break;
1266 default:
1268 m_pBtnPosition->Check();
1269 m_pWndPosition->Enable();
1270 RECT_POINT eNewPos = RP_MM;
1272 switch ( ePos )
1274 case GPOS_MM: break;
1275 case GPOS_LT: eNewPos = RP_LT; break;
1276 case GPOS_MT: eNewPos = RP_MT; break;
1277 case GPOS_RT: eNewPos = RP_RT; break;
1278 case GPOS_LM: eNewPos = RP_LM; break;
1279 case GPOS_RM: eNewPos = RP_RM; break;
1280 case GPOS_LB: eNewPos = RP_LB; break;
1281 case GPOS_MB: eNewPos = RP_MB; break;
1282 case GPOS_RB: eNewPos = RP_RB; break;
1283 default: ;//prevent warning
1285 m_pWndPosition->SetActualRP( eNewPos );
1287 break;
1289 m_pWndPosition->Invalidate();
1292 SvxGraphicPosition SvxBackgroundTabPage::GetGraphicPosition_Impl()
1294 if ( m_pBtnTile->IsChecked() )
1295 return GPOS_TILED;
1296 else if ( m_pBtnArea->IsChecked() )
1297 return GPOS_AREA;
1298 else
1300 switch ( m_pWndPosition->GetActualRP() )
1302 case RP_LT: return GPOS_LT;
1303 case RP_MT: return GPOS_MT;
1304 case RP_RT: return GPOS_RT;
1305 case RP_LM: return GPOS_LM;
1306 case RP_MM: return GPOS_MM;
1307 case RP_RM: return GPOS_RM;
1308 case RP_LB: return GPOS_LB;
1309 case RP_MB: return GPOS_MB;
1310 case RP_RB: return GPOS_RB;
1313 return GPOS_MM;
1317 // Handler
1319 /** Handler, called when color selection is changed */
1320 IMPL_LINK_NOARG(SvxBackgroundTabPage, BackgroundColorHdl_Impl)
1322 sal_uInt16 nItemId = m_pBackgroundColorSet->GetSelectItemId();
1323 Color aColor = nItemId ? ( m_pBackgroundColorSet->GetItemColor( nItemId ) ) : Color( COL_TRANSPARENT );
1324 aBgdColor = aColor;
1325 m_pPreviewWin1->NotifyChange( aBgdColor );
1326 bool bEnableTransp = aBgdColor.GetTransparency() < 0xff;
1327 m_pColTransFT->Enable(bEnableTransp);
1328 m_pColTransMF->Enable(bEnableTransp);
1329 return 0;
1332 IMPL_LINK_NOARG(SvxBackgroundTabPage, SelectHdl_Impl)
1334 if ( drawing::FillStyle_SOLID == lcl_getFillStyle(m_pLbSelect) )
1336 ShowColorUI_Impl();
1337 m_pParaLBox->Enable(); // drawing background can't be a bitmap
1339 else
1341 ShowBitmapUI_Impl();
1342 m_pParaLBox->Enable(false); // drawing background can't be a bitmap
1344 return 0;
1347 IMPL_LINK( SvxBackgroundTabPage, FileClickHdl_Impl, CheckBox*, pBox )
1349 if (m_pBtnLink == pBox)
1351 if ( m_pBtnLink->IsChecked() )
1353 m_pFtUnlinked->Hide();
1354 INetURLObject aObj( aBgdGraphicPath );
1355 OUString aFilePath;
1356 if ( aObj.GetProtocol() == INetProtocol::File )
1357 aFilePath = aObj.getFSysPath( INetURLObject::FSYS_DETECT );
1358 else
1359 aFilePath = aBgdGraphicPath;
1360 m_pFtFile->SetText( aFilePath );
1361 m_pFtFile->Show();
1363 else
1365 m_pFtUnlinked->Show();
1366 m_pFtFile->Hide();
1369 else if (m_pBtnPreview == pBox)
1371 if ( m_pBtnPreview->IsChecked() )
1373 if ( !bIsGraphicValid )
1374 bIsGraphicValid = LoadLinkedGraphic_Impl();
1376 if ( bIsGraphicValid )
1378 Bitmap aBmp = aBgdGraphic.GetBitmap();
1379 m_pPreviewWin2->NotifyChange( &aBmp );
1381 else
1383 if ( !aBgdGraphicPath.isEmpty() ) // only for linked bitmap
1384 RaiseLoadError_Impl();
1385 m_pPreviewWin2->NotifyChange( NULL );
1388 else
1389 m_pPreviewWin2->NotifyChange( NULL );
1391 return 0;
1394 IMPL_LINK( SvxBackgroundTabPage, RadioClickHdl_Impl, RadioButton*, pBtn )
1396 if (pBtn == m_pBtnPosition)
1398 if ( !m_pWndPosition->IsEnabled() )
1400 m_pWndPosition->Enable();
1401 m_pWndPosition->Invalidate();
1404 else if ( m_pWndPosition->IsEnabled() )
1406 m_pWndPosition->Disable();
1407 m_pWndPosition->Invalidate();
1409 return 0;
1412 /** Handler, called by pressing the browse button.
1413 Create graphic/insert dialog, set path and start.
1415 IMPL_LINK_NOARG(SvxBackgroundTabPage, BrowseHdl_Impl)
1417 if ( pPageImpl->pLoadIdle->IsActive() )
1418 return 0;
1419 bool bHtml = 0 != ( nHtmlMode & HTMLMODE_ON );
1421 OUString aStrBrowse(get<vcl::Window>("findgraphicsft")->GetText());
1422 pImportDlg = new SvxOpenGraphicDialog( aStrBrowse );
1423 if ( bHtml || bLinkOnly )
1424 pImportDlg->EnableLink(false);
1425 pImportDlg->SetPath( aBgdGraphicPath, m_pBtnLink->IsChecked() );
1427 pPageImpl->bIsImportDlgInExecute = true;
1428 short nErr = pImportDlg->Execute();
1429 pPageImpl->bIsImportDlgInExecute = false;
1431 if( !nErr )
1433 if ( bHtml )
1434 m_pBtnLink->Check();
1435 // if link isn't checked and preview isn't, either,
1436 // activate preview, so that the user sees which
1437 // graphic he has chosen
1438 if ( !m_pBtnLink->IsChecked() && !m_pBtnPreview->IsChecked() )
1439 m_pBtnPreview->Check( true );
1440 // timer-delayed loading of the graphic
1441 pPageImpl->pLoadIdle->Start();
1443 else
1444 DELETEZ( pImportDlg );
1445 return 0;
1448 /** Delayed loading of the graphic.
1449 Graphic is only loaded, if it's
1450 different to the current graphic.
1452 IMPL_LINK_TYPED( SvxBackgroundTabPage, LoadIdleHdl_Impl, Idle* , pIdle, void )
1454 if ( pIdle == pPageImpl->pLoadIdle )
1456 pPageImpl->pLoadIdle->Stop();
1458 if ( pImportDlg )
1460 INetURLObject aOld( aBgdGraphicPath );
1461 INetURLObject aNew( pImportDlg->GetPath() );
1462 if ( aBgdGraphicPath.isEmpty() || aNew != aOld )
1464 // new file chosen
1465 aBgdGraphicPath = pImportDlg->GetPath();
1466 aBgdGraphicFilter = pImportDlg->GetCurrentFilter();
1467 bool bLink = ( nHtmlMode & HTMLMODE_ON ) || bLinkOnly || pImportDlg->IsAsLink();
1468 m_pBtnLink->Check( bLink );
1469 m_pBtnLink->Enable();
1471 if ( m_pBtnPreview->IsChecked() )
1473 if( !pImportDlg->GetGraphic(aBgdGraphic) )
1475 bIsGraphicValid = true;
1477 else
1479 aBgdGraphicFilter.clear();
1480 aBgdGraphicPath.clear();
1481 bIsGraphicValid = false;
1484 else
1485 bIsGraphicValid = false; // load graphic not until preview click
1487 if ( m_pBtnPreview->IsChecked() && bIsGraphicValid )
1489 Bitmap aBmp = aBgdGraphic.GetBitmap();
1490 m_pPreviewWin2->NotifyChange( &aBmp );
1492 else
1493 m_pPreviewWin2->NotifyChange( NULL );
1496 FileClickHdl_Impl(m_pBtnLink);
1497 DELETEZ( pImportDlg );
1502 void SvxBackgroundTabPage::ShowTblControl()
1504 m_pTblLBox->SetSelectHdl( HDL(TblDestinationHdl_Impl) );
1505 m_pTblLBox->SelectEntryPos(0);
1506 m_pTblDesc->Show();
1507 m_pTblLBox->Show();
1508 m_pAsGrid->Show();
1511 void SvxBackgroundTabPage::ShowParaControl(bool bCharOnly)
1513 m_pParaLBox->SetSelectHdl(HDL(ParaDestinationHdl_Impl));
1514 m_pParaLBox->SelectEntryPos(0);
1515 if (!bCharOnly)
1517 m_pTblDesc->Show();
1518 m_pParaLBox->Show();
1519 m_pAsGrid->Show();
1521 m_pParaLBox->SetData(m_pParaLBox); // here it can be recognized that this mode is turned on
1524 IMPL_LINK( SvxBackgroundTabPage, TblDestinationHdl_Impl, ListBox*, pBox )
1526 sal_Int32 nSelPos = pBox->GetSelectEntryPos();
1527 if( pTableBck_Impl && pTableBck_Impl->nActPos != nSelPos)
1529 boost::scoped_ptr<SvxBrushItem> xItemHolder;
1530 SvxBrushItem* pActItem = NULL;
1531 sal_uInt16 nWhich = 0;
1532 switch(pTableBck_Impl->nActPos)
1534 case TBL_DEST_CELL:
1535 pActItem = pTableBck_Impl->pCellBrush;
1536 nWhich = pTableBck_Impl->nCellWhich;
1537 break;
1538 case TBL_DEST_ROW:
1539 pActItem = pTableBck_Impl->pRowBrush;
1540 nWhich = pTableBck_Impl->nRowWhich;
1541 break;
1542 case TBL_DEST_TBL:
1543 pActItem = pTableBck_Impl->pTableBrush;
1544 nWhich = pTableBck_Impl->nTableWhich;
1545 break;
1546 default:
1547 pActItem = NULL;
1548 break;
1550 pTableBck_Impl->nActPos = nSelPos;
1551 if(!pActItem)
1553 xItemHolder.reset(new SvxBrushItem(nWhich));
1554 pActItem = xItemHolder.get();
1556 if(drawing::FillStyle_SOLID == lcl_getFillStyle(m_pLbSelect)) // brush selected
1558 *pActItem = SvxBrushItem( aBgdColor, nWhich );
1560 else
1562 SvxGraphicPosition eNewPos = GetGraphicPosition_Impl();
1563 const bool bIsLink = m_pBtnLink->IsChecked();
1565 if ( !bIsLink && !bIsGraphicValid )
1566 bIsGraphicValid = LoadLinkedGraphic_Impl();
1568 if ( bIsLink )
1569 *pActItem = SvxBrushItem( aBgdGraphicPath,
1570 aBgdGraphicFilter,
1571 eNewPos,
1572 pActItem->Which() );
1573 else
1574 *pActItem = SvxBrushItem( aBgdGraphic,
1575 eNewPos,
1576 pActItem->Which() );
1578 switch(nSelPos)
1580 case TBL_DEST_CELL:
1581 pActItem = pTableBck_Impl->pCellBrush;
1582 m_pLbSelect->Enable();
1583 nWhich = pTableBck_Impl->nCellWhich;
1584 break;
1585 case TBL_DEST_ROW:
1586 pActItem = pTableBck_Impl->pRowBrush;
1587 nWhich = pTableBck_Impl->nRowWhich;
1588 break;
1589 case TBL_DEST_TBL:
1590 pActItem = pTableBck_Impl->pTableBrush;
1591 m_pLbSelect->Enable();
1592 nWhich = pTableBck_Impl->nTableWhich;
1593 break;
1594 default:
1595 // The item will be new'ed again below, but that will be the
1596 // default item then, not an existing modified one.
1597 xItemHolder.reset();
1598 pActItem = NULL;
1599 break;
1601 OUString aUserData = GetUserData();
1602 if (!pActItem)
1604 xItemHolder.reset(new SvxBrushItem(nWhich));
1605 pActItem = xItemHolder.get();
1607 FillControls_Impl(*pActItem, aUserData);
1609 return 0;
1612 IMPL_LINK( SvxBackgroundTabPage, ParaDestinationHdl_Impl, ListBox*, pBox )
1614 sal_Int32 nSelPos = pBox->GetSelectEntryPos();
1615 if( pParaBck_Impl && pParaBck_Impl->nActPos != nSelPos)
1617 SvxBrushItem* pActItem = NULL;
1618 switch(pParaBck_Impl->nActPos)
1620 case PARA_DEST_PARA:
1621 pActItem = pParaBck_Impl->pParaBrush;
1622 break;
1623 case PARA_DEST_CHAR:
1624 pActItem = pParaBck_Impl->pCharBrush;
1625 break;
1626 default:
1627 /* we assert here because the rest of the code expect pActItem to be non NULL */
1628 assert(false);
1629 return 0;
1631 pParaBck_Impl->nActPos = nSelPos;
1632 if(drawing::FillStyle_SOLID == lcl_getFillStyle(m_pLbSelect)) // brush selected
1634 sal_uInt16 nWhich = pActItem->Which();
1635 *pActItem = SvxBrushItem( aBgdColor, nWhich );
1637 else
1639 SvxGraphicPosition eNewPos = GetGraphicPosition_Impl();
1640 const bool bIsLink = m_pBtnLink->IsChecked();
1642 if ( !bIsLink && !bIsGraphicValid )
1643 bIsGraphicValid = LoadLinkedGraphic_Impl();
1645 if ( bIsLink )
1646 *pActItem = SvxBrushItem( aBgdGraphicPath,
1647 aBgdGraphicFilter,
1648 eNewPos,
1649 pActItem->Which() );
1650 else
1651 *pActItem = SvxBrushItem( aBgdGraphic,
1652 eNewPos,
1653 pActItem->Which() );
1655 switch(nSelPos)
1657 case PARA_DEST_PARA:
1658 pActItem = pParaBck_Impl->pParaBrush;
1659 m_pLbSelect->Enable();
1660 break;
1661 case PARA_DEST_CHAR:
1663 pActItem = pParaBck_Impl->pCharBrush;
1664 m_pLbSelect->Enable(false);
1666 break;
1668 OUString aUserData = GetUserData();
1669 FillControls_Impl(*pActItem, aUserData);
1671 return 0;
1674 void SvxBackgroundTabPage::FillControls_Impl( const SvxBrushItem& rBgdAttr,
1675 const OUString& rUserData )
1677 SvxGraphicPosition ePos = rBgdAttr.GetGraphicPos();
1678 const Color& rColor = rBgdAttr.GetColor();
1679 if(bColTransparency)
1681 m_pColTransMF->SetValue(lcl_TransparencyToPercent(rColor.GetTransparency()));
1682 m_pColTransMF->SaveValue();
1683 bool bEnableTransp = rColor.GetTransparency() < 0xff;
1684 m_pColTransFT->Enable(bEnableTransp);
1685 m_pColTransMF->Enable(bEnableTransp);
1686 //the default setting should be "no transparency"
1687 if(!bEnableTransp)
1688 m_pColTransMF->SetValue(0);
1691 if ( GPOS_NONE == ePos || !m_pLbSelect->IsVisible() )
1693 lcl_setFillStyle(m_pLbSelect, drawing::FillStyle_SOLID);
1694 ShowColorUI_Impl();
1695 Color aTrColor( COL_TRANSPARENT );
1696 aBgdColor = rColor;
1698 sal_uInt16 nCol = ( aTrColor != aBgdColor ) ?
1699 GetItemId_Impl(*m_pBackgroundColorSet, aBgdColor) : 0;
1701 if( aTrColor != aBgdColor && nCol == 0)
1703 m_pBackgroundColorSet->SetNoSelection();
1705 else
1707 m_pBackgroundColorSet->SelectItem( nCol );
1710 m_pPreviewWin1->NotifyChange( aBgdColor );
1712 if ( m_pLbSelect->IsVisible() ) // initialize graphic part
1714 aBgdGraphicFilter.clear();
1715 aBgdGraphicPath.clear();
1717 if ( rUserData.isEmpty() )
1718 m_pBtnPreview->Check( false );
1719 m_pBtnLink->Check( false );
1720 m_pBtnLink->Disable();
1721 m_pPreviewWin2->NotifyChange( NULL );
1722 SetGraphicPosition_Impl( GPOS_TILED ); // tiles as default
1725 else
1727 const OUString aStrLink = rBgdAttr.GetGraphicLink();
1728 const OUString aStrFilter = rBgdAttr.GetGraphicFilter();
1730 lcl_setFillStyle(m_pLbSelect, drawing::FillStyle_BITMAP);
1731 ShowBitmapUI_Impl();
1733 if ( !aStrLink.isEmpty() )
1735 #ifdef DBG_UTIL
1736 INetURLObject aObj( aStrLink );
1737 DBG_ASSERT( aObj.GetProtocol() != INetProtocol::NotValid, "Invalid URL!" );
1738 #endif
1739 aBgdGraphicPath = aStrLink;
1740 m_pBtnLink->Check( true );
1741 m_pBtnLink->Enable();
1743 else
1745 aBgdGraphicPath.clear();
1746 m_pBtnLink->Check( false );
1747 m_pBtnLink->Disable();
1750 if (bGraphTransparency)
1752 const GraphicObject* pObject = rBgdAttr.GetGraphicObject();
1753 if(pObject)
1754 m_pGraphTransMF->SetValue(lcl_TransparencyToPercent(pObject->GetAttr().GetTransparency()));
1755 else
1756 m_pGraphTransMF->SetValue(0);
1757 m_pGraphTransMF->SaveValue();
1760 FileClickHdl_Impl(m_pBtnLink);
1762 aBgdGraphicFilter = aStrFilter;
1764 if ( aStrLink.isEmpty() || m_pBtnPreview->IsChecked() )
1766 // Graphic exists in the item and doesn't have
1767 // to be loaded:
1769 const Graphic* pGraphic = rBgdAttr.GetGraphic();
1771 if ( !pGraphic && m_pBtnPreview->IsChecked() )
1772 bIsGraphicValid = LoadLinkedGraphic_Impl();
1773 else if ( pGraphic )
1775 aBgdGraphic = *pGraphic;
1776 bIsGraphicValid = true;
1778 if ( rUserData.isEmpty() )
1779 m_pBtnPreview->Check();
1781 else
1783 RaiseLoadError_Impl();
1784 bIsGraphicValid = false;
1786 if ( rUserData.isEmpty() )
1787 m_pBtnPreview->Check( false );
1791 if ( m_pBtnPreview->IsChecked() && bIsGraphicValid )
1793 Bitmap aBmp = aBgdGraphic.GetBitmap();
1794 m_pPreviewWin2->NotifyChange( &aBmp );
1796 else
1797 m_pPreviewWin2->NotifyChange( NULL );
1799 SetGraphicPosition_Impl( ePos );
1803 void SvxBackgroundTabPage::EnableTransparency(bool bColor, bool bGraphic)
1805 bColTransparency = bColor;
1806 bGraphTransparency = bGraphic;
1807 m_pColTransFT->Show(bColor);
1808 m_pColTransMF->Show(bColor);
1811 void SvxBackgroundTabPage::PageCreated(const SfxAllItemSet& aSet)
1813 SFX_ITEMSET_ARG (&aSet,pFlagItem,SfxUInt32Item,SID_FLAG_TYPE,false);
1815 if (pFlagItem)
1817 SvxBackgroundTabFlags nFlags = static_cast<SvxBackgroundTabFlags>(pFlagItem->GetValue());
1818 if (nFlags & SvxBackgroundTabFlags::SHOW_TBLCTL )
1819 ShowTblControl();
1820 if ( nFlags & SvxBackgroundTabFlags::SHOW_PARACTL )
1821 ShowParaControl();
1822 if ( nFlags & SvxBackgroundTabFlags::SHOW_SELECTOR )
1823 ShowSelector();
1824 if ( nFlags & SvxBackgroundTabFlags::ENABLE_TRANSPARENCY )
1825 EnableTransparency(true, true);
1826 if ( nFlags & SvxBackgroundTabFlags::SHOW_HIGHLIGHTING )
1828 m_pBackGroundColorLabelFT->SetText(CUI_RES(RID_SVXSTR_CHARNAME_HIGHLIGHTING));
1829 bHighlighting = true;
1834 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */