Update ooo320-m1
[ooovba.git] / svx / source / cui / backgrnd.cxx
blobf297f052e864ba632ed45d97fee5252958c703df
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: backgrnd.cxx,v $
10 * $Revision: 1.39 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
36 #endif
38 // include ---------------------------------------------------------------
39 #include <svtools/pathoptions.hxx>
40 #include <svtools/intitem.hxx>
41 #include <vcl/msgbox.hxx>
42 #include <tools/urlobj.hxx>
43 #include <sfx2/objsh.hxx>
44 #include <sfx2/docfile.hxx>
45 #include <svtools/wallitem.hxx>
46 #include <svtools/cntwall.hxx>
47 #ifndef _CNTIDS_HRC
48 #include <sfx2/cntids.hrc>
49 #endif
51 #define _SVX_BACKGRND_CXX
53 #include <svx/dialogs.hrc>
54 #include "backgrnd.hrc"
55 #include <svx/svxitems.hrc>
60 // Tabellenhintergrund
61 #define TBL_DEST_CELL 0
62 #define TBL_DEST_ROW 1
63 #define TBL_DEST_TBL 2
65 #include <svx/brshitem.hxx>
66 #include "backgrnd.hxx"
68 #include <svx/xtable.hxx>
69 #include "opengrf.hxx"
70 #include "impgrf.hxx"
71 #include "svxerr.hxx"
72 #include "drawitem.hxx"
73 #include <svx/dialmgr.hxx>
74 #include "htmlmode.hxx"
75 #ifndef _SVT_CONTROLDIMS_HRC_
76 #include <svtools/controldims.hrc>
77 #endif
78 #include <svx/svxids.hrc> //CHINA001
79 #include "flagsdef.hxx" //CHINA001
80 #include <svtools/intitem.hxx> //CHINA001
81 #include <sfx2/request.hxx> //CHINA001
82 using namespace ::com::sun::star;
83 // static ----------------------------------------------------------------
85 static USHORT pRanges[] =
87 SID_VIEW_FLD_PIC, SID_VIEW_FLD_PIC,
88 SID_ATTR_BRUSH, SID_ATTR_BRUSH,
89 SID_ATTR_BRUSH_CHAR, SID_ATTR_BRUSH_CHAR,
93 struct SvxBackgroundTable_Impl
95 SvxBrushItem* pCellBrush;
96 SvxBrushItem* pRowBrush;
97 SvxBrushItem* pTableBrush;
98 USHORT nCellWhich;
99 USHORT nRowWhich;
100 USHORT nTableWhich;
101 USHORT nActPos;
103 SvxBackgroundTable_Impl() :
104 pCellBrush(NULL), pRowBrush(NULL), pTableBrush(NULL),
105 nCellWhich(0), nRowWhich(0), nTableWhich(0) {}
108 struct SvxBackgroundPara_Impl
110 SvxBrushItem* pParaBrush;
111 SvxBrushItem* pCharBrush;
113 USHORT nActPos;
115 SvxBackgroundPara_Impl() :
116 pParaBrush(NULL), pCharBrush(NULL) {}
119 struct SvxBackgroundPage_Impl
121 Timer* pLoadTimer;
122 BOOL bIsImportDlgInExecute;
124 SvxBackgroundPage_Impl() :
125 pLoadTimer(NULL), bIsImportDlgInExecute(FALSE) {}
127 /* -----------------------------15.08.2002 12:21------------------------------
129 ---------------------------------------------------------------------------*/
130 inline BYTE lcl_PercentToTransparency(long nPercent)
132 //0xff must not be returned!
133 return BYTE(nPercent ? (50 + 0xfe * nPercent) / 100 : 0);
135 inline BYTE lcl_TransparencyToPercent(BYTE nTrans)
137 return (nTrans * 100 + 127) / 254;
139 void lcl_SetTransparency(SvxBrushItem& rBrush, long nTransparency)
141 uno::Any aTransparency;
142 aTransparency <<= (sal_Int8)nTransparency;
143 rBrush.PutValue(aTransparency, MID_GRAPHIC_TRANSPARENCY);
145 //-------------------------------------------------------------------------
147 /* [Beschreibung]
151 USHORT GetItemId_Impl( ValueSet& rValueSet, const Color& rCol )
153 BOOL bFound = FALSE;
154 USHORT nCount = rValueSet.GetItemCount();
155 USHORT n = 1;
157 while ( !bFound && n <= nCount )
159 Color aValCol = rValueSet.GetItemColor(n);
161 bFound = ( aValCol.GetRed() == rCol.GetRed()
162 && aValCol.GetGreen() == rCol.GetGreen()
163 && aValCol.GetBlue() == rCol.GetBlue() );
165 if ( !bFound )
166 n++;
168 return bFound ? n : 0;
171 // class BackgroundPreview -----------------------------------------------
173 /* [Beschreibung]
175 Vorschaufenster f"ur Brush oder Bitmap
178 class BackgroundPreviewImpl : public Window
180 public:
181 BackgroundPreviewImpl( Window* pParent,
182 const ResId& rResId, BOOL bIsBmpPreview );
183 ~BackgroundPreviewImpl();
185 void NotifyChange( const Color& rColor );
186 void NotifyChange( const Bitmap* pBitmap );
188 protected:
189 virtual void Paint( const Rectangle& rRect );
190 virtual void DataChanged( const DataChangedEvent& rDCEvt );
192 private:
193 const BOOL bIsBmp;
194 Bitmap* pBitmap;
195 Point aDrawPos;
196 Size aDrawSize;
197 Rectangle aDrawRect;
198 BYTE nTransparency;
201 //-----------------------------------------------------------------------
203 BackgroundPreviewImpl::BackgroundPreviewImpl
205 Window* pParent,
206 const ResId& rResId,
207 BOOL bIsBmpPreview
210 /* [Beschreibung]
214 Window( pParent, rResId ),
216 bIsBmp ( bIsBmpPreview ),
217 pBitmap ( NULL ),
218 aDrawRect( Point(0,0), GetOutputSizePixel() ),
219 nTransparency(0)
222 SetBorderStyle(WINDOW_BORDER_MONO);
223 Paint( aDrawRect );
226 //-----------------------------------------------------------------------
228 BackgroundPreviewImpl::~BackgroundPreviewImpl()
230 /* [Beschreibung]
235 delete pBitmap;
238 //-----------------------------------------------------------------------
239 void BackgroundPreviewImpl::NotifyChange( const Color& rColor )
241 if ( !bIsBmp )
243 const static Color aTranspCol( COL_TRANSPARENT );
245 nTransparency = lcl_TransparencyToPercent( rColor.GetTransparency() );
247 SetFillColor( rColor == aTranspCol ? GetSettings().GetStyleSettings().GetFieldColor() : (Color) rColor.GetRGBColor() );
248 Paint( aDrawRect );
252 //-----------------------------------------------------------------------
254 void BackgroundPreviewImpl::NotifyChange( const Bitmap* pNewBitmap )
255 /* [Beschreibung]
260 if ( bIsBmp && (pNewBitmap || pBitmap) )
262 if ( pNewBitmap && pBitmap )
263 *pBitmap = *pNewBitmap;
264 else if ( pNewBitmap && !pBitmap )
265 pBitmap = new Bitmap( *pNewBitmap );
266 else if ( !pNewBitmap )
267 DELETEZ( pBitmap );
269 if ( pBitmap )
271 Size aSize = GetOutputSizePixel();
272 // InnerSize == Size without one pixel border
273 Size aInnerSize = aSize;
274 aInnerSize.Width() -= 2;
275 aInnerSize.Height() -= 2;
276 aDrawSize = pBitmap->GetSizePixel();
278 // bitmap bigger than preview window?
279 if ( aDrawSize.Width() > aInnerSize.Width() )
281 aDrawSize.Height() = aDrawSize.Height() * aInnerSize.Width() / aDrawSize.Width();
282 if ( aDrawSize.Height() > aInnerSize.Height() )
284 aDrawSize.Width() = aDrawSize.Height();
285 aDrawSize.Height() = aInnerSize.Height();
287 else
288 aDrawSize.Width() = aInnerSize.Width();
290 else if ( aDrawSize.Height() > aInnerSize.Height() )
292 aDrawSize.Width() = aDrawSize.Width() * aInnerSize.Height() / aDrawSize.Height();
293 if ( aDrawSize.Width() > aInnerSize.Width() )
295 aDrawSize.Height() = aDrawSize.Width();
296 aDrawSize.Width() = aInnerSize.Width();
298 else
299 aDrawSize.Height() = aInnerSize.Height();
302 aDrawPos.X() = (aSize.Width() - aDrawSize.Width()) / 2;
303 aDrawPos.Y() = (aSize.Height() - aDrawSize.Height()) / 2;
305 Invalidate( aDrawRect );
306 Update();
310 //-----------------------------------------------------------------------
312 void BackgroundPreviewImpl::Paint( const Rectangle& )
314 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
315 SetBackground(Wallpaper(rStyleSettings.GetWindowColor()));
316 SetLineColor();
317 if(bIsBmp)
318 SetFillColor( Color(COL_TRANSPARENT) );
319 DrawRect( aDrawRect );
320 if ( bIsBmp )
322 if ( pBitmap )
323 DrawBitmap( aDrawPos, aDrawSize, *pBitmap );
324 else
326 Size aSize = GetOutputSizePixel();
327 DrawLine( Point(0,0), Point(aSize.Width(),aSize.Height()) );
328 DrawLine( Point(0,aSize.Height()), Point(aSize.Width(),0) );
332 /* -----------------------------27.02.2002 11:07------------------------------
334 ---------------------------------------------------------------------------*/
335 void BackgroundPreviewImpl::DataChanged( const DataChangedEvent& rDCEvt )
337 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
338 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
340 Invalidate();
342 Window::DataChanged( rDCEvt );
345 // class SvxBackgroundTabPage --------------------------------------------
347 #define HDL(hdl) LINK(this,SvxBackgroundTabPage,hdl)
349 SvxBackgroundTabPage::SvxBackgroundTabPage( Window* pParent,
350 const SfxItemSet& rCoreSet ) :
352 /* [Beschreibung]
356 SvxTabPage( pParent, SVX_RES( RID_SVXPAGE_BACKGROUND ), rCoreSet ),
358 aBorderWin ( this, SVX_RES(CT_BORDER) ),
359 aBackgroundColorSet ( &aBorderWin, SVX_RES( SET_BGDCOLOR ) ),
360 aBackgroundColorBox ( this, SVX_RES( GB_BGDCOLOR ) ),
361 pPreviewWin1 ( new BackgroundPreviewImpl(
362 this, SVX_RES( WIN_PREVIEW1 ), FALSE ) ),
363 aColTransFT ( this, SVX_RES( FT_COL_TRANS ) ),
364 aColTransMF ( this, SVX_RES( MF_COL_TRANS ) ),
365 aBtnBrowse ( this, SVX_RES( BTN_BROWSE ) ),
366 aBtnLink ( this, SVX_RES( BTN_LINK ) ),
367 aBtnPreview ( this, SVX_RES( BTN_PREVIEW ) ),
368 aFtFile ( this, SVX_RES( FT_FILE ) ),
369 aGbFile ( this, SVX_RES( GB_FILE ) ),
370 aBtnPosition ( this, SVX_RES( BTN_POSITION ) ),
371 aBtnArea ( this, SVX_RES( BTN_AREA ) ),
372 aBtnTile ( this, SVX_RES( BTN_TILE ) ),
373 aWndPosition ( this, SVX_RES( WND_POSITION ), RP_MM ),
374 aGbPosition ( this, SVX_RES( GB_POSITION ) ),
375 aGraphTransFL ( this, SVX_RES( FL_GRAPH_TRANS ) ),
376 aGraphTransMF ( this, SVX_RES( MF_GRAPH_TRANS ) ),
377 pPreviewWin2 ( new BackgroundPreviewImpl(
378 this, SVX_RES( WIN_PREVIEW2 ), TRUE ) ),
379 aSelectTxt ( this, SVX_RES( FT_SELECTOR ) ),
380 aLbSelect ( this, SVX_RES( LB_SELECTOR ) ),
381 aStrBrowse ( SVX_RES( STR_BROWSE ) ),
382 aStrUnlinked ( SVX_RES( STR_UNLINKED ) ),
383 aTblDesc ( this, SVX_RES( FT_TBL_DESC ) ),
384 aTblLBox ( this, SVX_RES( LB_TBL_BOX ) ),
385 aParaLBox ( this, SVX_RES( LB_PARA_BOX ) ),
386 nHtmlMode ( 0 ),
387 bAllowShowSelector ( TRUE ),
388 bIsGraphicValid ( FALSE ),
389 bLinkOnly ( FALSE ),
390 bResized ( FALSE ),
391 bColTransparency ( FALSE ),
392 bGraphTransparency ( FALSE ),
394 pPageImpl ( new SvxBackgroundPage_Impl ),
395 pImportDlg ( NULL ),
396 pTableBck_Impl ( NULL ),
397 pParaBck_Impl ( NULL )
400 // diese Page braucht ExchangeSupport
401 SetExchangeSupport();
403 const SfxPoolItem* pItem;
404 SfxObjectShell* pShell;
406 if ( SFX_ITEM_SET == rCoreSet.GetItemState( SID_HTML_MODE, FALSE, &pItem )
407 || ( 0 != ( pShell = SfxObjectShell::Current()) &&
408 0 != ( pItem = pShell->GetItem( SID_HTML_MODE ) ) ) )
410 nHtmlMode = ((SfxUInt16Item*)pItem)->GetValue();
413 FillColorValueSets_Impl();
415 aBackgroundColorSet.SetSelectHdl( HDL(BackgroundColorHdl_Impl) );
416 FreeResource();
419 //------------------------------------------------------------------------
421 SvxBackgroundTabPage::~SvxBackgroundTabPage()
423 /* [Beschreibung]
428 delete pPreviewWin1;
429 delete pPreviewWin2;
430 delete pPageImpl->pLoadTimer;
431 delete pPageImpl;
432 delete pImportDlg;
434 if( pTableBck_Impl)
436 delete pTableBck_Impl->pCellBrush;
437 delete pTableBck_Impl->pRowBrush;
438 delete pTableBck_Impl->pTableBrush;
439 delete pTableBck_Impl;
442 if(pParaBck_Impl)
444 delete pParaBck_Impl->pParaBrush;
445 delete pParaBck_Impl->pCharBrush;
446 delete pParaBck_Impl;
450 //------------------------------------------------------------------------
452 USHORT* SvxBackgroundTabPage::GetRanges()
454 /* [Beschreibung]
456 gibt den Bereich der Which-Werte zur"uck
460 return pRanges;
463 //------------------------------------------------------------------------
465 SfxTabPage* SvxBackgroundTabPage::Create( Window* pParent,
466 const SfxItemSet& rAttrSet )
468 /* [Beschreibung]
470 Create-Methode f"ur den TabDialog
474 return ( new SvxBackgroundTabPage( pParent, rAttrSet ) );
477 //------------------------------------------------------------------------
479 void SvxBackgroundTabPage::Reset( const SfxItemSet& rSet )
481 /* [Beschreibung]
486 // os: So ein Unsinn! Irgendwo laesst sich so ein Item immer finden,
487 // es muss aber im rSet vorhanden sein!
488 // const SfxPoolItem* pX = GetOldItem( rSet, SID_VIEW_FLD_PIC );
489 // if( pX && pX->ISA(SfxWallpaperItem))
490 if(SFX_ITEM_AVAILABLE <= rSet.GetItemState(GetWhich(SID_VIEW_FLD_PIC), FALSE))
492 ResetFromWallpaperItem( rSet );
493 return;
496 // Zustand des Vorschau-Buttons durch UserData persistent
497 String aUserData = GetUserData();
498 aBtnPreview.Check( aUserData.Len() && sal_Unicode('1') == aUserData.GetChar( 0 ) );
500 // nach Reset kein ShowSelector() mehr aufrufen d"urfen
501 bAllowShowSelector = FALSE;
504 // Input-BrushItem besorgen und auswerten
505 const SvxBrushItem* pBgdAttr = NULL;
506 USHORT nSlot = SID_ATTR_BRUSH;
507 const SfxPoolItem* pItem;
508 USHORT nDestValue = USHRT_MAX;
510 if ( SFX_ITEM_SET == rSet.GetItemState( SID_BACKGRND_DESTINATION,
511 FALSE, &pItem ) )
513 nDestValue = ((const SfxUInt16Item*)pItem)->GetValue();
514 aTblLBox.SelectEntryPos(nDestValue);
516 switch ( nDestValue )
518 case TBL_DEST_CELL:
519 nSlot = SID_ATTR_BRUSH;
520 break;
521 case TBL_DEST_ROW:
522 nSlot = SID_ATTR_BRUSH_ROW;
523 break;
524 case TBL_DEST_TBL:
525 nSlot = SID_ATTR_BRUSH_TABLE;
526 break;
529 else if( SFX_ITEM_SET == rSet.GetItemState(
530 SID_PARA_BACKGRND_DESTINATION, FALSE, &pItem ) )
532 nDestValue = ((const SfxUInt16Item*)pItem)->GetValue();
533 // ist gerade Zeichen aktiviert?
534 USHORT nParaSel = aParaLBox.GetSelectEntryPos();
535 if(1 == nParaSel)
537 // dann war das ein "Standard" - Aufruf
538 nDestValue = nParaSel;
540 aParaLBox.SelectEntryPos(nDestValue);
542 switch ( nDestValue )
544 case PARA_DEST_PARA:
545 nSlot = SID_ATTR_BRUSH;
546 break;
547 case PARA_DEST_CHAR:
548 nSlot = SID_ATTR_BRUSH_CHAR;
549 break;
552 //#111173# the destination item is missing when the parent style has been changed
553 if(USHRT_MAX == nDestValue && (aParaLBox.IsVisible()||aTblLBox.IsVisible()))
554 nDestValue = 0;
555 USHORT nWhich = GetWhich( nSlot );
557 if ( rSet.GetItemState( nWhich, FALSE ) >= SFX_ITEM_AVAILABLE )
558 pBgdAttr = (const SvxBrushItem*)&( rSet.Get( nWhich ) );
560 aBtnTile.Check();
562 if ( pBgdAttr )
564 FillControls_Impl(*pBgdAttr, aUserData);
565 aBgdColor = ( (SvxBrushItem*)pBgdAttr )->GetColor();
567 else
569 aSelectTxt.Hide();
570 aLbSelect.Hide();
571 aLbSelect.SelectEntryPos( 0 );
572 ShowColorUI_Impl();
574 const SfxPoolItem* pOld = GetOldItem( rSet, SID_ATTR_BRUSH );
576 if ( pOld )
577 aBgdColor = ( (SvxBrushItem*)pOld )->GetColor();
580 if ( nDestValue != USHRT_MAX )
582 if(aTblLBox.IsVisible())
584 USHORT nValue = aTblLBox.GetSelectEntryPos();
586 if ( pTableBck_Impl )
588 DELETEZ( pTableBck_Impl->pCellBrush);
589 DELETEZ( pTableBck_Impl->pRowBrush);
590 DELETEZ( pTableBck_Impl->pTableBrush);
592 else
593 pTableBck_Impl = new SvxBackgroundTable_Impl();
595 pTableBck_Impl->nActPos = nValue;
597 nWhich = GetWhich( SID_ATTR_BRUSH );
598 if ( rSet.GetItemState( nWhich, FALSE ) >= SFX_ITEM_AVAILABLE )
600 pBgdAttr = (const SvxBrushItem*)&( rSet.Get( nWhich ) );
601 pTableBck_Impl->pCellBrush = new SvxBrushItem(*pBgdAttr);
603 pTableBck_Impl->nCellWhich = nWhich;
605 if ( rSet.GetItemState( SID_ATTR_BRUSH_ROW, FALSE ) >= SFX_ITEM_AVAILABLE )
607 pBgdAttr = (const SvxBrushItem*)&( rSet.Get( SID_ATTR_BRUSH_ROW ) );
608 pTableBck_Impl->pRowBrush = new SvxBrushItem(*pBgdAttr);
610 pTableBck_Impl->nRowWhich = SID_ATTR_BRUSH_ROW;
612 if ( rSet.GetItemState( SID_ATTR_BRUSH_TABLE, FALSE ) >= SFX_ITEM_AVAILABLE )
614 pBgdAttr = (const SvxBrushItem*)&( rSet.Get( SID_ATTR_BRUSH_TABLE ) );
615 pTableBck_Impl->pTableBrush = new SvxBrushItem(*pBgdAttr);
617 pTableBck_Impl->nTableWhich = SID_ATTR_BRUSH_TABLE;
619 TblDestinationHdl_Impl(&aTblLBox);
620 aTblLBox.SaveValue();
622 else
624 USHORT nValue = aParaLBox.GetSelectEntryPos();
626 if ( pParaBck_Impl )
628 delete pParaBck_Impl->pParaBrush;
629 delete pParaBck_Impl->pCharBrush;
631 else
632 pParaBck_Impl = new SvxBackgroundPara_Impl();
634 pParaBck_Impl->nActPos = nValue;
636 nWhich = GetWhich( SID_ATTR_BRUSH );
637 if ( rSet.GetItemState( nWhich, FALSE ) >= SFX_ITEM_AVAILABLE )
639 pBgdAttr = (const SvxBrushItem*)&( rSet.Get( nWhich ) );
640 pParaBck_Impl->pParaBrush = new SvxBrushItem(*pBgdAttr);
643 nWhich = GetWhich( SID_ATTR_BRUSH_CHAR );
644 SfxItemState eState = rSet.GetItemState( nWhich, TRUE );
645 eState = rSet.GetItemState( nWhich, FALSE );
646 if ( rSet.GetItemState( nWhich, TRUE ) > SFX_ITEM_AVAILABLE )
648 pBgdAttr = (const SvxBrushItem*)&( rSet.Get( nWhich ) );
649 pParaBck_Impl->pCharBrush = new SvxBrushItem(*pBgdAttr);
651 else
652 pParaBck_Impl->pCharBrush = new SvxBrushItem(SID_ATTR_BRUSH_CHAR);
654 ParaDestinationHdl_Impl(&aParaLBox);
655 aParaLBox.SaveValue();
658 if(!bResized)
660 if(!aLbSelect.IsVisible() && !aTblLBox.IsVisible() && !aParaLBox.IsVisible())
662 long nY(LogicToPixel(Point(11,14), MAP_APPFONT).X());
663 long nX(LogicToPixel(Point(11,14), MAP_APPFONT).Y());
664 Point aPos(aBorderWin.GetPosPixel());
665 aPos.X() = nX;
666 aPos.Y() = nY;
667 aBorderWin.SetPosPixel(aPos);
668 aPos = pPreviewWin1->GetPosPixel();
669 aPos.Y() = nY;
670 pPreviewWin1->SetPosPixel(aPos);
671 aBackgroundColorBox.Hide();
676 void SvxBackgroundTabPage::ResetFromWallpaperItem( const SfxItemSet& rSet )
678 ShowSelector();
680 // Zustand des Vorschau-Buttons durch UserData persistent
681 String aUserData = GetUserData();
682 aBtnPreview.Check( aUserData.Len() && sal_Unicode('1') == aUserData.GetChar( 0 ) );
684 // Input-BrushItem besorgen und auswerten
685 const SvxBrushItem* pBgdAttr = NULL;
686 USHORT nSlot = SID_VIEW_FLD_PIC;
687 USHORT nWhich = GetWhich( nSlot );
688 SvxBrushItem* pTemp = 0;
689 const CntWallpaperItem* pItem = 0;
691 if ( rSet.GetItemState( nWhich, FALSE ) >= SFX_ITEM_AVAILABLE )
693 pItem = (const CntWallpaperItem*)&rSet.Get( nWhich );
694 pTemp = new SvxBrushItem( *pItem, nWhich );
695 pBgdAttr = pTemp;
698 aBtnTile.Check();
700 if ( pBgdAttr )
702 FillControls_Impl(*pBgdAttr, aUserData);
703 // Auch bei Anzeige der Grafik, soll die Brush erhalten bleiben
704 if( aBgdColor != pBgdAttr->GetColor() )
706 aBgdColor = pBgdAttr->GetColor();
707 USHORT nCol = GetItemId_Impl( aBackgroundColorSet, aBgdColor );
708 aBackgroundColorSet.SelectItem( nCol );
709 pPreviewWin1->NotifyChange( aBgdColor );
712 else
714 aLbSelect.SelectEntryPos( 0 );
715 ShowColorUI_Impl();
717 const SfxPoolItem* pOld = GetOldItem( rSet, SID_VIEW_FLD_PIC );
718 if ( pOld )
719 aBgdColor = Color( ((CntWallpaperItem*)pOld)->GetColor() );
722 // We now have always a link to the background
723 bLinkOnly = TRUE;
724 aBtnLink.Check( TRUE );
725 aBtnLink.Show( FALSE );
726 // if( !pItem || !pItem->GetWallpaper(FALSE).IsBitmap() )
727 // aBtnLink.Check();
729 delete pTemp;
734 //------------------------------------------------------------------------
736 void SvxBackgroundTabPage::FillUserData()
738 /* [Beschreibung]
740 Beim Destruieren einer SfxTabPage wird diese virtuelle Methode gerufen,
741 damit die TabPage interne Informationen sichern kann.
743 In diesem Fall wird der Zustand des Vorschau-Buttons gesichert.
747 SetUserData( String( aBtnPreview.IsChecked() ? sal_Unicode('1') : sal_Unicode('0') ) );
750 //------------------------------------------------------------------------
752 BOOL SvxBackgroundTabPage::FillItemSet( SfxItemSet& rCoreSet )
754 /* [Beschreibung]
759 if ( pPageImpl->pLoadTimer && pPageImpl->pLoadTimer->IsActive() )
761 pPageImpl->pLoadTimer->Stop();
762 LoadTimerHdl_Impl( pPageImpl->pLoadTimer );
764 // os: So ein Unsinn! Irgendwo laesst sich so ein Item immer finden,
765 // es muss aber im rSet vorhanden sein!
767 // const SfxPoolItem* pX = GetOldItem( rCoreSet, SID_VIEW_FLD_PIC );
768 // if( pX && pX->ISA(SfxWallpaperItem))
769 if(SFX_ITEM_AVAILABLE <= rCoreSet.GetItemState(GetWhich(SID_VIEW_FLD_PIC), FALSE))
770 return FillItemSetWithWallpaperItem( rCoreSet, SID_VIEW_FLD_PIC );
772 BOOL bModified = FALSE;
773 USHORT nSlot = SID_ATTR_BRUSH;
775 if ( aTblLBox.IsVisible() )
777 switch( aTblLBox.GetSelectEntryPos() )
779 case TBL_DEST_CELL:
780 nSlot = SID_ATTR_BRUSH;
781 break;
782 case TBL_DEST_ROW:
783 nSlot = SID_ATTR_BRUSH_ROW;
784 break;
785 case TBL_DEST_TBL:
786 nSlot = SID_ATTR_BRUSH_TABLE;
787 break;
790 else if(aParaLBox.GetData() == &aParaLBox)
792 switch(aParaLBox.GetSelectEntryPos())
794 case PARA_DEST_PARA:
795 nSlot = SID_ATTR_BRUSH;
796 break;
797 case PARA_DEST_CHAR:
798 nSlot = SID_ATTR_BRUSH_CHAR;
799 break;
802 USHORT nWhich = GetWhich( nSlot );
804 const SfxPoolItem* pOld = GetOldItem( rCoreSet, nSlot );
805 SfxItemState eOldItemState = rCoreSet.GetItemState(nSlot, FALSE);
806 const SfxItemSet& rOldSet = GetItemSet();
808 BOOL bGraphTransparencyChanged = bGraphTransparency && (aGraphTransMF.GetText() != aGraphTransMF.GetSavedValue());
809 if ( pOld )
811 const SvxBrushItem& rOldItem = (const SvxBrushItem&)*pOld;
812 SvxGraphicPosition eOldPos = rOldItem.GetGraphicPos();
813 const BOOL bIsBrush = ( 0 == aLbSelect.GetSelectEntryPos() );
815 // transparency has to be set if enabled, the color not already set to "No fill" and
816 if( bColTransparency &&
817 aBgdColor.GetTransparency() < 0xff)
819 aBgdColor.SetTransparency(lcl_PercentToTransparency(static_cast<long>(aColTransMF.GetValue())));
821 if ( ( (GPOS_NONE == eOldPos) && bIsBrush )
822 || ( (GPOS_NONE != eOldPos) && !bIsBrush ) ) // Brush <-> Bitmap gewechselt?
824 // Hintergrund-Art wurde nicht gewechselt:
826 if ( (GPOS_NONE == eOldPos) || !aLbSelect.IsVisible() )
828 // Brush-Behandlung:
829 if ( rOldItem.GetColor() != aBgdColor ||
830 (SFX_ITEM_AVAILABLE >= eOldItemState && !aBackgroundColorSet.IsNoSelection()))
832 bModified = TRUE;
833 rCoreSet.Put( SvxBrushItem( aBgdColor, nWhich ) );
835 else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich, FALSE ) )
836 rCoreSet.ClearItem( nWhich );
838 else
840 // Bitmap-Behandlung:
842 SvxGraphicPosition eNewPos = GetGraphicPosition_Impl();
843 const BOOL bIsLink = aBtnLink.IsChecked();
844 const BOOL bWasLink = (NULL != rOldItem.GetGraphicLink() );
847 if ( !bIsLink && !bIsGraphicValid )
848 bIsGraphicValid = LoadLinkedGraphic_Impl();
850 if ( bGraphTransparencyChanged ||
851 eNewPos != eOldPos
852 || bIsLink != bWasLink
853 || ( bWasLink && *rOldItem.GetGraphicLink()
854 != aBgdGraphicPath )
855 || ( !bWasLink && rOldItem.GetGraphic()->GetBitmap()
856 != aBgdGraphic.GetBitmap() )
859 bModified = TRUE;
861 SvxBrushItem aTmpBrush(nWhich);
862 if ( bIsLink )
864 aTmpBrush = SvxBrushItem( aBgdGraphicPath,
865 aBgdGraphicFilter,
866 eNewPos,
867 nWhich );
869 else
870 aTmpBrush = SvxBrushItem( aBgdGraphic,
871 eNewPos,
872 nWhich );
873 lcl_SetTransparency(aTmpBrush, static_cast<long>(aGraphTransMF.GetValue()));
875 rCoreSet.Put(aTmpBrush);
877 else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich, FALSE ) )
878 rCoreSet.ClearItem( nWhich );
881 else // Brush <-> Bitmap gewechselt!
883 if ( bIsBrush )
884 rCoreSet.Put( SvxBrushItem( aBgdColor, nWhich ) );
885 else
887 SvxBrushItem* pTmpBrush = 0;
888 if ( aBtnLink.IsChecked() )
890 pTmpBrush = new SvxBrushItem( aBgdGraphicPath,
891 aBgdGraphicFilter,
892 GetGraphicPosition_Impl(),
893 nWhich );
895 else
897 if ( !bIsGraphicValid )
898 bIsGraphicValid = LoadLinkedGraphic_Impl();
900 if ( bIsGraphicValid )
901 pTmpBrush = new SvxBrushItem( aBgdGraphic,
902 GetGraphicPosition_Impl(),
903 nWhich );
905 if(pTmpBrush)
907 lcl_SetTransparency(*pTmpBrush, static_cast<long>(aGraphTransMF.GetValue()));
908 rCoreSet.Put(*pTmpBrush);
909 delete pTmpBrush;
912 bModified = ( bIsBrush || aBtnLink.IsChecked() || bIsGraphicValid );
915 else if ( SID_ATTR_BRUSH_CHAR == nSlot && aBgdColor != Color( COL_WHITE ) )
917 rCoreSet.Put( SvxBrushItem( aBgdColor, nWhich ) );
918 bModified = TRUE;
921 if( aTblLBox.IsVisible() )
923 // Der aktuelle Zustand wurde bereits geputtet
924 if( nSlot != SID_ATTR_BRUSH && pTableBck_Impl->pCellBrush)
926 const SfxPoolItem* pOldCell =
927 GetOldItem( rCoreSet, SID_ATTR_BRUSH );
929 if ( *pTableBck_Impl->pCellBrush != *pOldCell )
931 rCoreSet.Put( *pTableBck_Impl->pCellBrush );
932 bModified |= TRUE;
936 if( nSlot != SID_ATTR_BRUSH_ROW && pTableBck_Impl->pRowBrush)
938 const SfxPoolItem* pOldRow =
939 GetOldItem( rCoreSet, SID_ATTR_BRUSH_ROW );
941 if ( *pTableBck_Impl->pRowBrush != *pOldRow )
943 rCoreSet.Put( *pTableBck_Impl->pRowBrush );
944 bModified |= TRUE;
948 if( nSlot != SID_ATTR_BRUSH_TABLE && pTableBck_Impl->pTableBrush)
950 const SfxPoolItem* pOldTable =
951 GetOldItem( rCoreSet, SID_ATTR_BRUSH_TABLE );
953 if ( *pTableBck_Impl->pTableBrush != *pOldTable )
955 rCoreSet.Put( *pTableBck_Impl->pTableBrush );
956 bModified |= TRUE;
960 if( aTblLBox.GetSavedValue() != aTblLBox.GetSelectEntryPos() )
962 rCoreSet.Put( SfxUInt16Item( SID_BACKGRND_DESTINATION,
963 aTblLBox.GetSelectEntryPos() ) );
964 bModified |= TRUE;
967 else if(aParaLBox.GetData() == &aParaLBox)
969 // Der aktuelle Zustand wurde bereits geputtet
970 if( nSlot != SID_ATTR_BRUSH && aParaLBox.IsVisible()) // nicht im Suchen-Format-Dialog
972 const SfxPoolItem* pOldPara =
973 GetOldItem( rCoreSet, SID_ATTR_BRUSH );
975 if ( *pParaBck_Impl->pParaBrush != *pOldPara )
977 rCoreSet.Put( *pParaBck_Impl->pParaBrush );
978 bModified |= TRUE;
982 if( nSlot != SID_ATTR_BRUSH_CHAR )
984 const SfxPoolItem* pOldChar =
985 GetOldItem( rCoreSet, SID_ATTR_BRUSH_CHAR );
986 DBG_ASSERT(pParaBck_Impl, "pParaBck_Impl == NULL ?");
987 if ( pOldChar &&
988 //#111173# crash report shows that pParaBck_Impl can be NULL, the cause is unknown
989 pParaBck_Impl &&
990 (*pParaBck_Impl->pCharBrush != *pOldChar ||
991 *pParaBck_Impl->pCharBrush != SvxBrushItem(SID_ATTR_BRUSH_CHAR)))
993 rCoreSet.Put( *pParaBck_Impl->pCharBrush );
994 bModified |= TRUE;
998 if( aParaLBox.GetSavedValue() != aParaLBox.GetSelectEntryPos() )
1000 rCoreSet.Put( SfxUInt16Item( SID_BACKGRND_DESTINATION,
1001 aParaLBox.GetSelectEntryPos() ) );
1002 bModified |= TRUE;
1005 return bModified;
1008 BOOL SvxBackgroundTabPage::FillItemSetWithWallpaperItem( SfxItemSet& rCoreSet, USHORT nSlot)
1010 USHORT nWhich = GetWhich( nSlot );
1011 const SfxPoolItem* pOld = GetOldItem( rCoreSet, nSlot );
1012 const SfxItemSet& rOldSet = GetItemSet();
1013 DBG_ASSERT(pOld,"FillItemSetWithWallpaperItem: Item not found");
1015 SvxBrushItem rOldItem( (const CntWallpaperItem&)*pOld, nWhich );
1016 SvxGraphicPosition eOldPos = rOldItem.GetGraphicPos();
1017 const BOOL bIsBrush = ( 0 == aLbSelect.GetSelectEntryPos() );
1018 BOOL bModified = FALSE;
1020 if ( ( (GPOS_NONE == eOldPos) && bIsBrush )
1021 || ( (GPOS_NONE != eOldPos) && !bIsBrush ) ) // Brush <-> Bitmap gewechselt?
1023 // Hintergrund-Art wurde nicht gewechselt:
1025 if ( (GPOS_NONE == eOldPos) || !aLbSelect.IsVisible() )
1027 // Brush-Behandlung:
1028 if ( rOldItem.GetColor() != aBgdColor )
1030 bModified = TRUE;
1031 CntWallpaperItem aItem( nWhich );
1032 aItem.SetColor( aBgdColor );
1033 rCoreSet.Put( aItem );
1035 else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich, FALSE ) )
1036 rCoreSet.ClearItem( nWhich );
1038 else
1040 // Bitmap-Behandlung:
1041 SvxGraphicPosition eNewPos = GetGraphicPosition_Impl();
1043 int bBitmapChanged = ( ( eNewPos != eOldPos ) ||
1044 ( *rOldItem.GetGraphicLink() != aBgdGraphicPath ) );
1045 int bBrushChanged = ( rOldItem.GetColor() != aBgdColor );
1046 if( bBitmapChanged || bBrushChanged )
1048 bModified = TRUE;
1050 CntWallpaperItem aItem( nWhich );
1051 WallpaperStyle eWallStyle = SvxBrushItem::GraphicPos2WallpaperStyle(eNewPos);
1052 aItem.SetStyle( sal::static_int_cast< USHORT >( eWallStyle ) );
1053 aItem.SetColor( aBgdColor );
1054 aItem.SetBitmapURL( aBgdGraphicPath );
1055 rCoreSet.Put( aItem );
1057 else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich, FALSE ) )
1058 rCoreSet.ClearItem( nWhich );
1061 else // Brush <-> Bitmap gewechselt!
1063 CntWallpaperItem aItem( nWhich );
1064 if ( bIsBrush )
1066 aItem.SetColor( aBgdColor );
1067 rCoreSet.Put( aItem );
1069 else
1071 WallpaperStyle eWallStyle =
1072 SvxBrushItem::GraphicPos2WallpaperStyle( GetGraphicPosition_Impl() );
1073 aItem.SetStyle( sal::static_int_cast< USHORT >( eWallStyle ) );
1074 aItem.SetColor( aBgdColor );
1075 aItem.SetBitmapURL( aBgdGraphicPath );
1076 rCoreSet.Put( aItem );
1079 bModified = TRUE;
1081 return bModified;
1084 //-----------------------------------------------------------------------
1086 int SvxBackgroundTabPage::DeactivatePage( SfxItemSet* _pSet )
1088 /* [Beschreibung]
1090 virtuelle Methode, wird beim Deaktivieren gerufen
1094 if ( pPageImpl->bIsImportDlgInExecute )
1095 return KEEP_PAGE;
1097 if ( _pSet )
1098 FillItemSet( *_pSet );
1100 return LEAVE_PAGE;
1103 //-----------------------------------------------------------------------
1105 void SvxBackgroundTabPage::PointChanged( Window* , RECT_POINT )
1107 /* [Beschreibung]
1112 // muss implementiert werden, damit Position-Control funktioniert
1115 //-----------------------------------------------------------------------
1117 void SvxBackgroundTabPage::ShowSelector()
1119 /* [Beschreibung]
1124 if( bAllowShowSelector)
1126 aSelectTxt.Show();
1127 aLbSelect.Show();
1128 aLbSelect.SetSelectHdl( HDL(SelectHdl_Impl) );
1129 aBtnLink.SetClickHdl( HDL(FileClickHdl_Impl) );
1130 aBtnPreview.SetClickHdl( HDL(FileClickHdl_Impl) );
1131 aBtnBrowse.SetClickHdl( HDL(BrowseHdl_Impl) );
1132 aBtnArea.SetClickHdl( HDL(RadioClickHdl_Impl) );
1133 aBtnTile.SetClickHdl( HDL(RadioClickHdl_Impl) );
1134 aBtnPosition.SetClickHdl( HDL(RadioClickHdl_Impl) );
1136 // Verz"ogertes Laden "uber Timer (wg. UI-Update)
1137 pPageImpl->pLoadTimer = new Timer;
1138 pPageImpl->pLoadTimer->SetTimeout( 500 ); // 500ms verz"ogern
1139 pPageImpl->pLoadTimer->SetTimeoutHdl(
1140 LINK( this, SvxBackgroundTabPage, LoadTimerHdl_Impl ) );
1142 bAllowShowSelector = FALSE;
1144 if(nHtmlMode & HTMLMODE_ON)
1146 if(!(nHtmlMode & HTMLMODE_GRAPH_POS))
1147 aBtnPosition.Enable(FALSE);
1148 aBtnArea.Enable(FALSE);
1153 //------------------------------------------------------------------------
1156 void SvxBackgroundTabPage::RaiseLoadError_Impl()
1158 /* [Beschreibung]
1163 SfxErrorContext aContext( ERRCTX_SVX_BACKGROUND,
1164 String(),
1165 this,
1166 RID_SVXERRCTX,
1167 &DIALOG_MGR() );
1169 ErrorHandler::HandleError(
1170 *new StringErrorInfo( ERRCODE_SVX_GRAPHIC_NOTREADABLE,
1171 aBgdGraphicPath ) );
1174 //------------------------------------------------------------------------
1176 BOOL SvxBackgroundTabPage::LoadLinkedGraphic_Impl()
1178 /* [Beschreibung]
1183 BOOL bResult = ( aBgdGraphicPath.Len() > 0 ) &&
1184 ( GRFILTER_OK == LoadGraphic( aBgdGraphicPath,
1185 aBgdGraphicFilter,
1186 aBgdGraphic ) );
1187 return bResult;
1190 //------------------------------------------------------------------------
1193 void SvxBackgroundTabPage::FillColorValueSets_Impl()
1195 /* [Beschreibung]
1197 F"ullen des Farb-Sets
1201 SfxObjectShell* pDocSh = SfxObjectShell::Current();
1202 const SfxPoolItem* pItem = NULL;
1203 XColorTable* pColorTable = NULL;
1204 const Size aSize15x15 = Size( 15, 15 );
1205 FASTBOOL bOwn = FALSE;
1207 if ( pDocSh && ( 0 != ( pItem = pDocSh->GetItem( SID_COLOR_TABLE ) ) ) )
1208 pColorTable = ( (SvxColorTableItem*)pItem )->GetColorTable();
1210 if ( !pColorTable )
1212 bOwn = TRUE;
1213 pColorTable = new XColorTable( SvtPathOptions().GetPalettePath() );
1216 if ( pColorTable )
1218 short i = 0;
1219 long nCount = pColorTable->Count();
1220 XColorEntry* pEntry = NULL;
1221 Color aColWhite( COL_WHITE );
1222 String aStrWhite( SVX_RES( RID_SVXITEMS_COLOR_WHITE ) );
1223 WinBits nBits = ( aBackgroundColorSet.GetStyle() | WB_ITEMBORDER | WB_NAMEFIELD | WB_NONEFIELD );
1224 aBackgroundColorSet.SetText( String( SVX_RES( RID_SVXSTR_TRANSPARENT ) ) );
1225 aBackgroundColorSet.SetStyle( nBits );
1226 for ( i = 0; i < nCount; i++ )
1228 pEntry = pColorTable->GetColor(i);
1229 aBackgroundColorSet.InsertItem( i + 1, pEntry->GetColor(), pEntry->GetName() );
1232 while ( i < 80 )
1234 aBackgroundColorSet.InsertItem( i + 1, aColWhite, aStrWhite );
1235 i++;
1238 if ( nCount > 80 )
1240 aBackgroundColorSet.SetStyle( nBits | WB_VSCROLL );
1244 if ( bOwn )
1245 delete pColorTable;
1247 aBackgroundColorSet.SetColCount( 10 );
1248 aBackgroundColorSet.SetLineCount( 10 );
1249 aBackgroundColorSet.CalcWindowSizePixel( aSize15x15 );
1253 //------------------------------------------------------------------------
1257 //------------------------------------------------------------------------
1259 void SvxBackgroundTabPage::ShowColorUI_Impl()
1261 /* [Beschreibung]
1263 Die Controls f"ur das Einstellen der Grafik ausblenden und die
1264 Controls f"ur die Farbeinstellung einblenden.
1268 if( !aBackgroundColorSet.IsVisible() )
1270 aBackgroundColorSet.Show();
1271 aBackgroundColorBox.Show();
1272 aBorderWin.Show();
1273 pPreviewWin1->Show();
1274 aBtnBrowse.Hide();
1275 aFtFile.Hide();
1276 aBtnLink.Hide();
1277 aBtnPreview.Hide();
1278 aGbFile.Hide();
1279 aBtnPosition.Hide();
1280 aBtnArea.Hide();
1281 aBtnTile.Hide();
1282 aWndPosition.Hide();
1283 aGbPosition.Hide();
1284 pPreviewWin2->Hide();
1285 aGraphTransFL.Show(FALSE);
1286 aGraphTransMF.Show(FALSE);
1287 if(bColTransparency)
1289 aColTransFT.Show();
1290 aColTransMF.Show();
1295 //------------------------------------------------------------------------
1297 void SvxBackgroundTabPage::ShowBitmapUI_Impl()
1299 /* [Beschreibung]
1301 Die Controls f"ur die Farbeinstellung ausblenden und die
1302 Controls f"ur das Einstellen der Grafik einblenden.
1306 if ( aLbSelect.IsVisible() &&
1308 aBackgroundColorSet.IsVisible()
1309 || !aBtnBrowse.IsVisible() ) )
1311 aBackgroundColorSet.Hide();
1312 aBackgroundColorBox.Hide();
1313 aBorderWin.Hide();
1314 pPreviewWin1->Hide();
1315 aBtnBrowse.Show();
1316 aFtFile.Show();
1318 if ( !bLinkOnly && ! nHtmlMode & HTMLMODE_ON )
1319 aBtnLink.Show();
1320 aBtnPreview.Show();
1321 aGbFile.Show();
1322 aBtnPosition.Show();
1323 aBtnArea.Show();
1324 aBtnTile.Show();
1325 aWndPosition.Show();
1326 aGbPosition.Show();
1327 pPreviewWin2->Show();
1328 if(bGraphTransparency)
1330 aGraphTransFL.Show();
1331 aGraphTransMF.Show();
1333 aColTransFT.Show(FALSE);
1334 aColTransMF.Show(FALSE);
1338 //------------------------------------------------------------------------
1340 void SvxBackgroundTabPage::SetGraphicPosition_Impl( SvxGraphicPosition ePos )
1342 /* [Beschreibung]
1344 Die Controls f"ur die Grafikposition einstellen.
1348 switch ( ePos )
1350 case GPOS_AREA:
1352 aBtnArea.Check();
1353 aWndPosition.Disable();
1355 break;
1357 case GPOS_TILED:
1359 aBtnTile.Check();
1360 aWndPosition.Disable();
1362 break;
1364 default:
1366 aBtnPosition.Check();
1367 aWndPosition.Enable();
1368 RECT_POINT eNewPos = RP_MM;
1370 switch ( ePos )
1372 case GPOS_MM: break;
1373 case GPOS_LT: eNewPos = RP_LT; break;
1374 case GPOS_MT: eNewPos = RP_MT; break;
1375 case GPOS_RT: eNewPos = RP_RT; break;
1376 case GPOS_LM: eNewPos = RP_LM; break;
1377 case GPOS_RM: eNewPos = RP_RM; break;
1378 case GPOS_LB: eNewPos = RP_LB; break;
1379 case GPOS_MB: eNewPos = RP_MB; break;
1380 case GPOS_RB: eNewPos = RP_RB; break;
1381 default: ;//prevent warning
1383 aWndPosition.SetActualRP( eNewPos );
1385 break;
1387 aWndPosition.Invalidate();
1390 //------------------------------------------------------------------------
1392 SvxGraphicPosition SvxBackgroundTabPage::GetGraphicPosition_Impl()
1394 /* [Beschreibung]
1396 Die Position der Grafik zur"uckgeben.
1400 if ( aBtnTile.IsChecked() )
1401 return GPOS_TILED;
1402 else if ( aBtnArea.IsChecked() )
1403 return GPOS_AREA;
1404 else
1406 switch ( aWndPosition.GetActualRP() )
1408 case RP_LT: return GPOS_LT;
1409 case RP_MT: return GPOS_MT;
1410 case RP_RT: return GPOS_RT;
1411 case RP_LM: return GPOS_LM;
1412 case RP_MM: return GPOS_MM;
1413 case RP_RM: return GPOS_RM;
1414 case RP_LB: return GPOS_LB;
1415 case RP_MB: return GPOS_MB;
1416 case RP_RB: return GPOS_RB;
1419 return GPOS_MM;
1422 //-----------------------------------------------------------------------
1423 // Handler
1424 //-----------------------------------------------------------------------
1426 IMPL_LINK( SvxBackgroundTabPage, BackgroundColorHdl_Impl, ValueSet*, EMPTYARG )
1428 Handler, called when color selection is changed
1431 USHORT nItemId = aBackgroundColorSet.GetSelectItemId();
1432 Color aColor = nItemId ? ( aBackgroundColorSet.GetItemColor( nItemId ) ) : Color( COL_TRANSPARENT );
1433 aBgdColor = aColor;
1434 pPreviewWin1->NotifyChange( aBgdColor );
1435 BOOL bEnableTransp = aBgdColor.GetTransparency() < 0xff;
1436 aColTransFT.Enable(bEnableTransp);
1437 aColTransMF.Enable(bEnableTransp);
1438 return 0;
1441 //------------------------------------------------------------------------
1443 IMPL_LINK( SvxBackgroundTabPage, SelectHdl_Impl, ListBox*, EMPTYARG )
1445 /* [Beschreibung]
1450 if ( 0 == aLbSelect.GetSelectEntryPos() )
1452 ShowColorUI_Impl();
1453 aParaLBox.Enable(); // Zeichenhintergrund kann keine Bitmap sein
1455 else
1457 ShowBitmapUI_Impl();
1458 aParaLBox.Enable(FALSE);// Zeichenhintergrund kann keine Bitmap sein
1460 return 0;
1463 //------------------------------------------------------------------------
1465 IMPL_LINK( SvxBackgroundTabPage, FileClickHdl_Impl, CheckBox*, pBox )
1467 /* [Beschreibung]
1472 if ( &aBtnLink == pBox )
1474 if ( aBtnLink.IsChecked() )
1476 INetURLObject aObj( aBgdGraphicPath );
1477 String aFilePath;
1478 if ( aObj.GetProtocol() == INET_PROT_FILE )
1479 aFilePath = aObj.getFSysPath( INetURLObject::FSYS_DETECT );
1480 else
1481 aFilePath = aBgdGraphicPath;
1482 aFtFile.SetText( aFilePath );
1484 else
1485 aFtFile.SetText( aStrUnlinked );
1487 else if ( &aBtnPreview == pBox )
1489 if ( aBtnPreview.IsChecked() )
1491 if ( !bIsGraphicValid )
1492 bIsGraphicValid = LoadLinkedGraphic_Impl();
1494 if ( bIsGraphicValid )
1496 Bitmap aBmp = aBgdGraphic.GetBitmap();
1497 pPreviewWin2->NotifyChange( &aBmp );
1499 else
1501 if ( aBgdGraphicPath.Len() > 0 ) // nur bei gelinkter Grafik
1502 RaiseLoadError_Impl(); // ein Fehler
1503 pPreviewWin2->NotifyChange( NULL );
1506 else
1507 pPreviewWin2->NotifyChange( NULL );
1509 return 0;
1512 //------------------------------------------------------------------------
1514 IMPL_LINK( SvxBackgroundTabPage, RadioClickHdl_Impl, RadioButton*, pBtn )
1516 /* [Beschreibung]
1521 if ( pBtn == &aBtnPosition )
1523 if ( !aWndPosition.IsEnabled() )
1525 aWndPosition.Enable();
1526 aWndPosition.Invalidate();
1529 else if ( aWndPosition.IsEnabled() )
1531 aWndPosition.Disable();
1532 aWndPosition.Invalidate();
1534 return 0;
1537 //------------------------------------------------------------------------
1539 IMPL_LINK( SvxBackgroundTabPage, BrowseHdl_Impl, PushButton* , EMPTYARG )
1541 /* [Beschreibung]
1543 Handler, gerufen durch das Dr"ucken des Durchsuchen-Buttons.
1544 Grafik/Einf"ugen-Dialog erzeugen, Pfad setzen und starten.
1548 if ( pPageImpl->pLoadTimer->IsActive() )
1549 return 0;
1550 BOOL bHtml = 0 != ( nHtmlMode & HTMLMODE_ON );
1552 pImportDlg = new SvxOpenGraphicDialog( aStrBrowse );
1553 if ( bHtml || bLinkOnly )
1554 pImportDlg->EnableLink(sal_False);
1555 pImportDlg->SetPath( aBgdGraphicPath, aBtnLink.IsChecked() );
1557 pPageImpl->bIsImportDlgInExecute = TRUE;
1558 short nErr = pImportDlg->Execute();
1559 pPageImpl->bIsImportDlgInExecute = FALSE;
1561 if( !nErr )
1563 if ( bHtml )
1564 aBtnLink.Check();
1565 // wenn Verkn"upfen nicht gecheckt ist und die Vorschau auch nicht,
1566 // dann die Vorschau aktivieren, damit der Anwender sieht,
1567 // welche Grafik er ausgew"ahlt hat
1568 if ( !aBtnLink.IsChecked() && !aBtnPreview.IsChecked() )
1569 aBtnPreview.Check( TRUE );
1570 // timer-verz"ogertes Laden der Grafik
1571 pPageImpl->pLoadTimer->Start();
1573 else
1574 DELETEZ( pImportDlg );
1575 return 0;
1578 //-----------------------------------------------------------------------
1580 IMPL_LINK( SvxBackgroundTabPage, LoadTimerHdl_Impl, Timer* , pTimer )
1582 /* [Beschreibung]
1584 Verz"ogertes Laden der Grafik.
1585 Grafik wird nur dann geladen, wenn sie unterschiedlich zur
1586 aktuellen Grafik ist.
1590 if ( pTimer == pPageImpl->pLoadTimer )
1592 pPageImpl->pLoadTimer->Stop();
1594 if ( pImportDlg )
1596 INetURLObject aOld( aBgdGraphicPath );
1597 INetURLObject aNew( pImportDlg->GetPath() );
1598 if ( !aBgdGraphicPath.Len() || aNew != aOld )
1600 // neue Datei gew"ahlt
1601 aBgdGraphicPath = pImportDlg->GetPath();
1602 aBgdGraphicFilter = pImportDlg->GetCurrentFilter();
1603 BOOL bLink = ( nHtmlMode & HTMLMODE_ON ) || bLinkOnly ? TRUE : pImportDlg->IsAsLink();
1604 aBtnLink.Check( bLink );
1605 aBtnLink.Enable();
1607 if ( aBtnPreview.IsChecked() )
1609 if( !pImportDlg->GetGraphic(aBgdGraphic) )
1611 bIsGraphicValid = TRUE;
1613 else
1615 aBgdGraphicFilter.Erase();
1616 aBgdGraphicPath.Erase();
1617 bIsGraphicValid = FALSE;
1620 else
1621 bIsGraphicValid = FALSE; // Grafik erst beim Preview-Click laden
1623 if ( aBtnPreview.IsChecked() && bIsGraphicValid )
1625 Bitmap aBmp = aBgdGraphic.GetBitmap();
1626 pPreviewWin2->NotifyChange( &aBmp );
1628 else
1629 pPreviewWin2->NotifyChange( NULL );
1632 FileClickHdl_Impl( &aBtnLink );
1633 DELETEZ( pImportDlg );
1636 return 0;
1639 //-----------------------------------------------------------------------
1641 void SvxBackgroundTabPage::ShowTblControl()
1643 /* [Beschreibung]
1648 aTblLBox .SetSelectHdl( HDL(TblDestinationHdl_Impl) );
1649 aTblLBox .SelectEntryPos(0);
1650 aTblDesc.Show();
1651 aTblLBox.Show();
1654 //-----------------------------------------------------------------------
1656 void SvxBackgroundTabPage::ShowParaControl(BOOL bCharOnly)
1658 aParaLBox.SetSelectHdl(HDL(ParaDestinationHdl_Impl));
1659 aParaLBox.SelectEntryPos(0);
1660 if(!bCharOnly)
1662 aTblDesc.Show();
1663 aParaLBox.Show();
1665 aParaLBox.SetData(&aParaLBox); // hier erkennt man, dass dieser Mode eingeschaltet ist
1667 //-----------------------------------------------------------------------
1669 IMPL_LINK( SvxBackgroundTabPage, TblDestinationHdl_Impl, ListBox*, pBox )
1671 /* [Beschreibung]
1676 USHORT nSelPos = pBox->GetSelectEntryPos();
1677 if( pTableBck_Impl && pTableBck_Impl->nActPos != nSelPos)
1679 SvxBrushItem** pActItem = new (SvxBrushItem*);
1680 USHORT nWhich = 0;
1681 switch(pTableBck_Impl->nActPos)
1683 case TBL_DEST_CELL:
1684 *pActItem = pTableBck_Impl->pCellBrush;
1685 nWhich = pTableBck_Impl->nCellWhich;
1686 break;
1687 case TBL_DEST_ROW:
1688 *pActItem = pTableBck_Impl->pRowBrush;
1689 nWhich = pTableBck_Impl->nRowWhich;
1690 break;
1691 case TBL_DEST_TBL:
1692 *pActItem = pTableBck_Impl->pTableBrush;
1693 nWhich = pTableBck_Impl->nTableWhich;
1694 break;
1696 pTableBck_Impl->nActPos = nSelPos;
1697 if(!*pActItem)
1698 *pActItem = new SvxBrushItem(nWhich);
1699 if(0 == aLbSelect.GetSelectEntryPos()) // Brush ausgewaehlt
1701 **pActItem = SvxBrushItem( aBgdColor, nWhich );
1703 else
1705 SvxGraphicPosition eNewPos = GetGraphicPosition_Impl();
1706 const BOOL bIsLink = aBtnLink.IsChecked();
1708 if ( !bIsLink && !bIsGraphicValid )
1709 bIsGraphicValid = LoadLinkedGraphic_Impl();
1711 if ( bIsLink )
1712 **pActItem = SvxBrushItem( aBgdGraphicPath,
1713 aBgdGraphicFilter,
1714 eNewPos,
1715 (*pActItem)->Which() );
1716 else
1717 **pActItem = SvxBrushItem( aBgdGraphic,
1718 eNewPos,
1719 (*pActItem)->Which() );
1721 switch(nSelPos)
1723 case TBL_DEST_CELL:
1724 *pActItem = pTableBck_Impl->pCellBrush;
1725 aLbSelect.Enable();
1726 nWhich = pTableBck_Impl->nCellWhich;
1727 break;
1728 case TBL_DEST_ROW:
1730 if((nHtmlMode & HTMLMODE_ON) && !(nHtmlMode & HTMLMODE_SOME_STYLES))
1731 aLbSelect.Disable();
1732 *pActItem = pTableBck_Impl->pRowBrush;
1733 nWhich = pTableBck_Impl->nRowWhich;
1735 break;
1736 case TBL_DEST_TBL:
1737 *pActItem = pTableBck_Impl->pTableBrush;
1738 aLbSelect.Enable();
1739 nWhich = pTableBck_Impl->nTableWhich;
1740 break;
1742 String aUserData = GetUserData();
1743 if(!*pActItem)
1744 *pActItem = new SvxBrushItem(nWhich);
1745 FillControls_Impl(**pActItem, aUserData);
1746 delete pActItem;
1748 return 0;
1751 //-----------------------------------------------------------------------
1753 IMPL_LINK( SvxBackgroundTabPage, ParaDestinationHdl_Impl, ListBox*, pBox )
1755 USHORT nSelPos = pBox->GetSelectEntryPos();
1756 if( pParaBck_Impl && pParaBck_Impl->nActPos != nSelPos)
1758 SvxBrushItem** pActItem = new (SvxBrushItem*);
1759 switch(pParaBck_Impl->nActPos)
1761 case PARA_DEST_PARA:
1762 *pActItem = pParaBck_Impl->pParaBrush;
1763 break;
1764 case PARA_DEST_CHAR:
1765 *pActItem = pParaBck_Impl->pCharBrush;
1766 break;
1768 pParaBck_Impl->nActPos = nSelPos;
1769 if(0 == aLbSelect.GetSelectEntryPos()) // Brush ausgewaehlt
1771 USHORT nWhich = (*pActItem)->Which();
1772 **pActItem = SvxBrushItem( aBgdColor, nWhich );
1774 else
1776 SvxGraphicPosition eNewPos = GetGraphicPosition_Impl();
1777 const BOOL bIsLink = aBtnLink.IsChecked();
1779 if ( !bIsLink && !bIsGraphicValid )
1780 bIsGraphicValid = LoadLinkedGraphic_Impl();
1782 if ( bIsLink )
1783 **pActItem = SvxBrushItem( aBgdGraphicPath,
1784 aBgdGraphicFilter,
1785 eNewPos,
1786 (*pActItem)->Which() );
1787 else
1788 **pActItem = SvxBrushItem( aBgdGraphic,
1789 eNewPos,
1790 (*pActItem)->Which() );
1792 switch(nSelPos)
1794 case PARA_DEST_PARA:
1795 *pActItem = pParaBck_Impl->pParaBrush;
1796 aLbSelect.Enable();
1797 break;
1798 case PARA_DEST_CHAR:
1800 *pActItem = pParaBck_Impl->pCharBrush;
1801 aLbSelect.Enable(FALSE);
1803 break;
1805 String aUserData = GetUserData();
1806 FillControls_Impl(**pActItem, aUserData);
1807 delete pActItem;
1809 return 0;
1812 //-----------------------------------------------------------------------
1814 void SvxBackgroundTabPage::FillControls_Impl( const SvxBrushItem& rBgdAttr,
1815 const String& rUserData )
1817 /* [Beschreibung]
1822 SvxGraphicPosition ePos = rBgdAttr.GetGraphicPos();
1823 const Color& rColor = rBgdAttr.GetColor();
1824 if(bColTransparency)
1826 aColTransMF.SetValue(lcl_TransparencyToPercent(rColor.GetTransparency()));
1827 aColTransMF.SaveValue();
1828 BOOL bEnableTransp = rColor.GetTransparency() < 0xff;
1829 aColTransFT.Enable(bEnableTransp);
1830 aColTransMF.Enable(bEnableTransp);
1831 //the default setting should be "no transparency"
1832 if(!bEnableTransp)
1833 aColTransMF.SetValue(0);
1836 if ( GPOS_NONE == ePos || !aLbSelect.IsVisible() )
1838 aLbSelect.SelectEntryPos( 0 );
1839 ShowColorUI_Impl();
1840 Color aTrColor( COL_TRANSPARENT );
1841 aBgdColor = rColor;
1843 USHORT nCol = ( aTrColor != aBgdColor ) ?
1844 GetItemId_Impl( aBackgroundColorSet, aBgdColor ) : 0;
1846 if( aTrColor != aBgdColor && nCol == 0)
1848 aBackgroundColorSet.SetNoSelection();
1850 else
1852 aBackgroundColorSet.SelectItem( nCol );
1855 pPreviewWin1->NotifyChange( aBgdColor );
1856 if ( aLbSelect.IsVisible() ) // Grafikteil initialisieren
1858 aBgdGraphicFilter.Erase();
1859 aBgdGraphicPath.Erase();
1861 if ( !rUserData.Len() )
1862 aBtnPreview.Check( FALSE );
1863 aBtnLink.Check( FALSE );
1864 aBtnLink.Disable();
1865 pPreviewWin2->NotifyChange( NULL );
1866 SetGraphicPosition_Impl( GPOS_TILED ); // Kacheln als Default
1869 else
1871 const String* pStrLink = rBgdAttr.GetGraphicLink();
1872 const String* pStrFilter = rBgdAttr.GetGraphicFilter();
1874 aLbSelect.SelectEntryPos( 1 );
1875 ShowBitmapUI_Impl();
1877 if ( pStrLink )
1879 #ifdef DBG_UTIL
1880 INetURLObject aObj( *pStrLink );
1881 DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
1882 #endif
1883 aBgdGraphicPath = *pStrLink;
1884 aBtnLink.Check( TRUE );
1885 aBtnLink.Enable();
1887 else
1889 aBgdGraphicPath.Erase();
1890 aBtnLink.Check( FALSE );
1891 aBtnLink.Disable();
1894 if(bGraphTransparency)
1896 const GraphicObject* pObject = rBgdAttr.GetGraphicObject(SfxObjectShell::Current());
1897 if(pObject)
1898 aGraphTransMF.SetValue(lcl_TransparencyToPercent(pObject->GetAttr().GetTransparency()));
1899 else
1900 aGraphTransMF.SetValue(0);
1901 aGraphTransMF.SaveValue();
1904 FileClickHdl_Impl( &aBtnLink );
1906 if ( pStrFilter )
1907 aBgdGraphicFilter = *pStrFilter;
1908 else
1909 aBgdGraphicFilter.Erase();
1911 if ( !pStrLink || aBtnPreview.IsChecked() )
1913 // Grafik ist im Item vorhanden und muss nicht
1914 // geladen werden:
1916 const Graphic* pGraphic =
1917 rBgdAttr.GetGraphic( SfxObjectShell::Current() );
1919 if ( !pGraphic && aBtnPreview.IsChecked() )
1920 bIsGraphicValid = LoadLinkedGraphic_Impl();
1921 else if ( pGraphic )
1923 aBgdGraphic = *pGraphic;
1924 bIsGraphicValid = TRUE;
1926 if ( !rUserData.Len() )
1927 aBtnPreview.Check();
1929 else
1931 RaiseLoadError_Impl();
1932 bIsGraphicValid = FALSE;
1934 if ( !rUserData.Len() )
1935 aBtnPreview.Check( FALSE );
1939 if ( aBtnPreview.IsChecked() && bIsGraphicValid )
1941 Bitmap aBmp = aBgdGraphic.GetBitmap();
1942 pPreviewWin2->NotifyChange( &aBmp );
1944 else
1945 pPreviewWin2->NotifyChange( NULL );
1947 SetGraphicPosition_Impl( ePos );
1950 /* -----------------------------09.08.2002 14:04------------------------------
1952 ---------------------------------------------------------------------------*/
1953 void SvxBackgroundTabPage::EnableTransparency(BOOL bColor, BOOL bGraphic)
1955 bColTransparency = bColor;
1956 bGraphTransparency = bGraphic;
1957 if(bColor)
1959 aColTransFT.Show();
1960 aColTransMF.Show();
1962 if(bGraphic)
1964 Size aRectSize(aWndPosition.GetSizePixel());
1965 Point aRectPos(aWndPosition.GetPosPixel());
1966 Point aFLPos(aGraphTransFL.GetPosPixel());
1967 Size aTmp(LogicToPixel(Size(RSC_SP_FLGR_SPACE_Y, RSC_SP_FLGR_SPACE_Y), MAP_APPFONT));
1968 long nRectHeight = aFLPos.Y() - aRectPos.Y() - aTmp.Height();
1969 aRectSize.Height() = nRectHeight;
1970 aWndPosition.SetSizePixel(aRectSize);
1971 aWndPosition.Invalidate();
1975 void SvxBackgroundTabPage::PageCreated (SfxAllItemSet aSet) //add CHINA001
1977 SFX_ITEMSET_ARG (&aSet,pFlagItem,SfxUInt32Item,SID_FLAG_TYPE,sal_False);
1978 if (pFlagItem)
1980 UINT32 nFlags=pFlagItem->GetValue();
1981 if ( ( nFlags & SVX_SHOW_TBLCTL ) == SVX_SHOW_TBLCTL )
1982 ShowTblControl();
1983 if ( ( nFlags & SVX_SHOW_PARACTL ) == SVX_SHOW_PARACTL )
1984 ShowParaControl();
1985 if ( ( nFlags & SVX_SHOW_SELECTOR ) == SVX_SHOW_SELECTOR )
1986 ShowSelector();
1987 if ( ( nFlags & SVX_ENABLE_TRANSPARENCY ) == SVX_ENABLE_TRANSPARENCY )
1988 EnableTransparency(TRUE, TRUE);