xref: /trunk/main/cui/source/tabpages/backgrnd.cxx (revision 28bcfa49)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cui.hxx"
26 
27 // include ---------------------------------------------------------------
28 #include <unotools/pathoptions.hxx>
29 #include <svl/intitem.hxx>
30 #include <vcl/msgbox.hxx>
31 #include <tools/urlobj.hxx>
32 #include <sfx2/objsh.hxx>
33 #include <sfx2/docfile.hxx>
34 #include <svtools/wallitem.hxx>
35 #include <svl/cntwall.hxx>
36 #include <sfx2/cntids.hrc>
37 #include <svx/dialogs.hrc>
38 
39 #define _SVX_BACKGRND_CXX
40 
41 #include <cuires.hrc>
42 #include "backgrnd.hrc"
43 #include <svx/dialmgr.hxx>
44 #include <editeng/memberids.hrc>
45 #include <editeng/editrids.hrc>
46 #include <editeng/eerdll.hxx>
47 
48 // Tabellenhintergrund
49 #define TBL_DEST_CELL 	0
50 #define TBL_DEST_ROW 	1
51 #define TBL_DEST_TBL	2
52 
53 #include <editeng/brshitem.hxx>
54 #include "backgrnd.hxx"
55 
56 #include <svx/xtable.hxx>
57 #include <sfx2/opengrf.hxx>
58 #include <svx/svxerr.hxx>
59 #include <svx/drawitem.hxx>
60 #include <dialmgr.hxx>
61 #include <svx/htmlmode.hxx>
62 #include <svtools/controldims.hrc>
63 #include <svx/flagsdef.hxx>	//CHINA001
64 #include <svl/intitem.hxx> //CHINA001
65 #include <sfx2/request.hxx> //CHINA001
66 #include <svtools/grfmgr.hxx>
67 
68 using namespace ::com::sun::star;
69 // static ----------------------------------------------------------------
70 
71 static sal_uInt16 pRanges[] =
72 {
73 	SID_VIEW_FLD_PIC, SID_VIEW_FLD_PIC,
74 	SID_ATTR_BRUSH, SID_ATTR_BRUSH,
75 	SID_ATTR_BRUSH_CHAR, SID_ATTR_BRUSH_CHAR,
76 	0
77 };
78 
79 struct SvxBackgroundTable_Impl
80 {
81 	SvxBrushItem*	pCellBrush;
82 	SvxBrushItem*	pRowBrush;
83 	SvxBrushItem*	pTableBrush;
84     sal_uInt16          nCellWhich;
85     sal_uInt16          nRowWhich;
86     sal_uInt16          nTableWhich;
87     sal_uInt16          nActPos;
88 
89 	SvxBackgroundTable_Impl() :
90         pCellBrush(NULL), pRowBrush(NULL), pTableBrush(NULL),
91         nCellWhich(0), nRowWhich(0), nTableWhich(0) {}
92 };
93 
94 struct SvxBackgroundPara_Impl
95 {
96 	SvxBrushItem*	pParaBrush;
97 	SvxBrushItem*	pCharBrush;
98 
99 	sal_uInt16 			nActPos;
100 
101 	SvxBackgroundPara_Impl() :
102 		pParaBrush(NULL), pCharBrush(NULL) {}
103 };
104 
105 struct SvxBackgroundPage_Impl
106 {
107 	Timer*          pLoadTimer;
108 	sal_Bool            bIsImportDlgInExecute;
109 
110 	SvxBackgroundPage_Impl() :
111 		pLoadTimer(NULL), bIsImportDlgInExecute(sal_False) {}
112 };
113 /* -----------------------------15.08.2002 12:21------------------------------
114 
115  ---------------------------------------------------------------------------*/
116 inline sal_uInt8 lcl_PercentToTransparency(long nPercent)
117 {
118     //0xff must not be returned!
119     return sal_uInt8(nPercent ? (50 + 0xfe * nPercent) / 100 : 0);
120 }
121 inline sal_uInt8 lcl_TransparencyToPercent(sal_uInt8 nTrans)
122 {
123     return (nTrans * 100 + 127) / 254;
124 }
125 void lcl_SetTransparency(SvxBrushItem& rBrush, long nTransparency)
126 {
127     uno::Any aTransparency;
128     aTransparency <<= (sal_Int8)nTransparency;
129     rBrush.PutValue(aTransparency, MID_GRAPHIC_TRANSPARENCY);
130 }
131 //-------------------------------------------------------------------------
132 
133 /*	[Beschreibung]
134 
135 */
136 
137 sal_uInt16 GetItemId_Impl( ValueSet& rValueSet, const Color& rCol )
138 {
139 	sal_Bool	bFound = sal_False;
140 	sal_uInt16	nCount = rValueSet.GetItemCount();
141 	sal_uInt16	n	   = 1;
142 
143 	while ( !bFound && n <= nCount )
144 	{
145 		Color aValCol = rValueSet.GetItemColor(n);
146 
147 		bFound = (   aValCol.GetRed()   == rCol.GetRed()
148 				  && aValCol.GetGreen() == rCol.GetGreen()
149 				  && aValCol.GetBlue()  == rCol.GetBlue() );
150 
151 		if ( !bFound )
152 			n++;
153 	}
154 	return bFound ? n : 0;
155 }
156 
157 // class BackgroundPreview -----------------------------------------------
158 
159 /*	[Beschreibung]
160 
161 	Vorschaufenster f"ur Brush oder Bitmap
162 */
163 
164 class BackgroundPreviewImpl : public Window
165 {
166 public:
167 	BackgroundPreviewImpl( Window* pParent,
168 						   const ResId& rResId, sal_Bool bIsBmpPreview );
169 	~BackgroundPreviewImpl();
170 
171 	void			NotifyChange( const Color&  rColor );
172 	void			NotifyChange( const Bitmap* pBitmap );
173 
174 protected:
175 	virtual void	Paint( const Rectangle& rRect );
176     virtual void    DataChanged( const DataChangedEvent& rDCEvt );
177 
178 private:
179 	const sal_Bool		bIsBmp;
180 	Bitmap*			pBitmap;
181 	Point			aDrawPos;
182 	Size			aDrawSize;
183 	Rectangle		aDrawRect;
184     sal_uInt8            nTransparency;
185 };
186 
187 //-----------------------------------------------------------------------
188 
189 BackgroundPreviewImpl::BackgroundPreviewImpl
190 (
191 	Window* pParent,
192 	const ResId& rResId,
193 	sal_Bool bIsBmpPreview
194 ) :
195 
196 /*	[Beschreibung]
197 
198 */
199 
200 	Window( pParent, rResId ),
201 
202 	bIsBmp	 ( bIsBmpPreview ),
203 	pBitmap	 ( NULL ),
204     aDrawRect( Point(0,0), GetOutputSizePixel() ),
205     nTransparency(0)
206 
207 {
208     SetBorderStyle(WINDOW_BORDER_MONO);
209     Paint( aDrawRect );
210 }
211 
212 //-----------------------------------------------------------------------
213 
214 BackgroundPreviewImpl::~BackgroundPreviewImpl()
215 
216 /*	[Beschreibung]
217 
218 */
219 
220 {
221 	delete pBitmap;
222 }
223 
224 //-----------------------------------------------------------------------
225 void BackgroundPreviewImpl::NotifyChange( const Color& rColor )
226 {
227 	if ( !bIsBmp )
228 	{
229 		const static Color aTranspCol( COL_TRANSPARENT );
230 
231         nTransparency = lcl_TransparencyToPercent( rColor.GetTransparency() );
232 
233 		SetFillColor( rColor == aTranspCol ? GetSettings().GetStyleSettings().GetFieldColor() : (Color) rColor.GetRGBColor() );
234         Paint( aDrawRect );
235 	}
236 }
237 
238 //-----------------------------------------------------------------------
239 
240 void BackgroundPreviewImpl::NotifyChange( const Bitmap* pNewBitmap )
241 /*	[Beschreibung]
242 
243 */
244 
245 {
246     if ( bIsBmp && (pNewBitmap || pBitmap) )
247 	{
248         if ( pNewBitmap && pBitmap )
249 			*pBitmap = *pNewBitmap;
250 		else if ( pNewBitmap && !pBitmap )
251 			pBitmap = new Bitmap( *pNewBitmap );
252 		else if ( !pNewBitmap )
253 			DELETEZ( pBitmap );
254 
255 		if ( pBitmap )
256 		{
257 			Size aSize = GetOutputSizePixel();
258 			// InnerSize == Size without one pixel border
259 			Size aInnerSize = aSize;
260 			aInnerSize.Width() -= 2;
261 			aInnerSize.Height() -= 2;
262 			aDrawSize = pBitmap->GetSizePixel();
263 
264 			// bitmap bigger than preview window?
265 			if ( aDrawSize.Width() > aInnerSize.Width() )
266 			{
267 				aDrawSize.Height() = aDrawSize.Height() * aInnerSize.Width() / aDrawSize.Width();
268 				if ( aDrawSize.Height() > aInnerSize.Height() )
269 				{
270 					aDrawSize.Width() = aDrawSize.Height();
271 					aDrawSize.Height() = aInnerSize.Height();
272 				}
273 				else
274 					aDrawSize.Width() = aInnerSize.Width();
275 			}
276 			else if ( aDrawSize.Height() > aInnerSize.Height() )
277 			{
278 				aDrawSize.Width() = aDrawSize.Width() * aInnerSize.Height() / aDrawSize.Height();
279 				if ( aDrawSize.Width() > aInnerSize.Width() )
280 				{
281 					aDrawSize.Height() = aDrawSize.Width();
282 					aDrawSize.Width() = aInnerSize.Width();
283 				}
284 				else
285 					aDrawSize.Height() = aInnerSize.Height();
286 			}
287 
288 			aDrawPos.X() = (aSize.Width()  - aDrawSize.Width())  / 2;
289 			aDrawPos.Y() = (aSize.Height() - aDrawSize.Height()) / 2;
290 		}
291 		Invalidate( aDrawRect );
292 		Update();
293 	}
294 }
295 
296 //-----------------------------------------------------------------------
297 
298 void BackgroundPreviewImpl::Paint( const Rectangle& )
299 {
300     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
301     SetBackground(Wallpaper(rStyleSettings.GetWindowColor()));
302     SetLineColor();
303     if(bIsBmp)
304         SetFillColor( Color(COL_TRANSPARENT) );
305     DrawRect( aDrawRect );
306 	if ( bIsBmp )
307 	{
308 		if ( pBitmap )
309 			DrawBitmap( aDrawPos, aDrawSize, *pBitmap );
310 		else
311 		{
312 			Size aSize = GetOutputSizePixel();
313             DrawLine( Point(0,0),               Point(aSize.Width(),aSize.Height()) );
314 			DrawLine( Point(0,aSize.Height()),	Point(aSize.Width(),0) );
315 		}
316 	}
317 }
318 /* -----------------------------27.02.2002 11:07------------------------------
319 
320  ---------------------------------------------------------------------------*/
321 void BackgroundPreviewImpl::DataChanged( const DataChangedEvent& rDCEvt )
322 {
323 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
324          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
325     {
326         Invalidate();
327     }
328     Window::DataChanged( rDCEvt );
329 }
330 
331 // class SvxBackgroundTabPage --------------------------------------------
332 
333 #define HDL(hdl) LINK(this,SvxBackgroundTabPage,hdl)
334 
335 SvxBackgroundTabPage::SvxBackgroundTabPage( Window* pParent,
336 											const SfxItemSet& rCoreSet ) :
337 
338 /*	[Beschreibung]
339 
340 */
341 
342 	SvxTabPage( pParent, CUI_RES( RID_SVXPAGE_BACKGROUND ), rCoreSet ),
343 
344 	aSelectTxt			( this, CUI_RES( FT_SELECTOR ) ),
345 	aLbSelect			( this, CUI_RES( LB_SELECTOR ) ),
346     aStrBrowse          ( CUI_RES( STR_BROWSE ) ),
347     aStrUnlinked        ( CUI_RES( STR_UNLINKED ) ),
348     aTblDesc            ( this, CUI_RES( FT_TBL_DESC ) ),
349 	aTblLBox            ( this, CUI_RES( LB_TBL_BOX ) ),
350 	aParaLBox           ( this, CUI_RES( LB_PARA_BOX ) ),
351 
352 	aBorderWin			( this, CUI_RES(CT_BORDER) ),
353 	aBackgroundColorSet ( &aBorderWin, CUI_RES( SET_BGDCOLOR ) ),
354 	aBackgroundColorBox ( this, CUI_RES( GB_BGDCOLOR ) ),
355 	pPreviewWin1        ( new BackgroundPreviewImpl( this, CUI_RES( WIN_PREVIEW1 ), sal_False ) ),
356 
357     aColTransFT         ( this, CUI_RES( FT_COL_TRANS ) ),
358     aColTransMF         ( this, CUI_RES( MF_COL_TRANS ) ),
359 	aBtnPreview	        ( this, CUI_RES( BTN_PREVIEW ) ),
360 	aGbFile		        ( this, CUI_RES( GB_FILE ) ),
361 	aBtnBrowse	        ( this, CUI_RES( BTN_BROWSE ) ),
362 	aBtnLink	        ( this, CUI_RES( BTN_LINK ) ),
363 	aGbPosition			( this, CUI_RES( GB_POSITION ) ),
364 	aBtnPosition        ( this, CUI_RES( BTN_POSITION ) ),
365 	aBtnArea	        ( this, CUI_RES( BTN_AREA ) ),
366 	aBtnTile	        ( this, CUI_RES( BTN_TILE ) ),
367 	aWndPosition		( this, CUI_RES( WND_POSITION ), RP_MM ),
368 	aFtFile		        ( this, CUI_RES( FT_FILE ) ),
369     aGraphTransFL       ( this, CUI_RES( FL_GRAPH_TRANS ) ),
370     aGraphTransMF       ( this, CUI_RES( MF_GRAPH_TRANS ) ),
371     pPreviewWin2        ( new BackgroundPreviewImpl(
372 							this, CUI_RES( WIN_PREVIEW2 ), sal_True ) ),
373 
374     nHtmlMode           ( 0 ),
375 	bAllowShowSelector	( sal_True ),
376 	bIsGraphicValid		( sal_False ),
377 	bLinkOnly			( sal_False ),
378     bResized            ( sal_False ),
379     bColTransparency    ( sal_False ),
380     bGraphTransparency  ( sal_False ),
381 
382 	pPageImpl           ( new SvxBackgroundPage_Impl ),
383 	pImportDlg			( NULL ),
384 	pTableBck_Impl		( NULL ),
385 	pParaBck_Impl       ( NULL )
386 
387 {
388 	// diese Page braucht ExchangeSupport
389 	SetExchangeSupport();
390 
391 	const SfxPoolItem* pItem;
392 	SfxObjectShell* pShell;
393 
394 	if ( SFX_ITEM_SET == rCoreSet.GetItemState( SID_HTML_MODE, sal_False, &pItem )
395 		 || ( 0 != ( pShell = SfxObjectShell::Current()) &&
396 			  0 != ( pItem = pShell->GetItem( SID_HTML_MODE ) ) ) )
397 	{
398 		nHtmlMode = ((SfxUInt16Item*)pItem)->GetValue();
399 	}
400 
401 	FillColorValueSets_Impl();
402 
403 	aBackgroundColorSet.SetSelectHdl( HDL(BackgroundColorHdl_Impl) );
404     aBackgroundColorSet.SetStyle(aBackgroundColorSet.GetStyle() | WB_ITEMBORDER | WB_NAMEFIELD | WB_NONEFIELD);
405 	aBackgroundColorSet.SetText(SVX_RESSTR(RID_SVXSTR_TRANSPARENT));
406 	aBackgroundColorSet.SetAccessibleName(aBackgroundColorBox.GetText());
407 	FreeResource();
408 
409 	aBtnBrowse.SetAccessibleRelationMemberOf(&aGbFile);
410 	aWndPosition.SetAccessibleRelationMemberOf(&aGbPosition);
411 	aWndPosition.SetAccessibleRelationLabeledBy(&aBtnPosition);
412     aBackgroundColorSet.SetAccessibleRelationLabeledBy(&aBackgroundColorBox);
413 }
414 
415 //------------------------------------------------------------------------
416 
417 SvxBackgroundTabPage::~SvxBackgroundTabPage()
418 
419 /*	[Beschreibung]
420 
421 */
422 
423 {
424 	delete pPreviewWin1;
425 	delete pPreviewWin2;
426 	delete pPageImpl->pLoadTimer;
427 	delete pPageImpl;
428 	delete pImportDlg;
429 
430 	if( pTableBck_Impl)
431 	{
432 		delete pTableBck_Impl->pCellBrush;
433 		delete pTableBck_Impl->pRowBrush;
434 		delete pTableBck_Impl->pTableBrush;
435 		delete pTableBck_Impl;
436 	}
437 
438 	if(pParaBck_Impl)
439 	{
440 		delete pParaBck_Impl->pParaBrush;
441 		delete pParaBck_Impl->pCharBrush;
442 		delete pParaBck_Impl;
443 	}
444 }
445 
446 //------------------------------------------------------------------------
447 
448 sal_uInt16* SvxBackgroundTabPage::GetRanges()
449 
450 /*	[Beschreibung]
451 
452 	gibt den Bereich der Which-Werte zur"uck
453 */
454 
455 {
456 	return pRanges;
457 }
458 
459 //------------------------------------------------------------------------
460 
461 SfxTabPage* SvxBackgroundTabPage::Create( Window* pParent,
462 										  const SfxItemSet& rAttrSet )
463 
464 /*	[Beschreibung]
465 
466 	Create-Methode f"ur den TabDialog
467 */
468 
469 {
470 	return ( new SvxBackgroundTabPage( pParent, rAttrSet ) );
471 }
472 
473 //------------------------------------------------------------------------
474 
475 void SvxBackgroundTabPage::Reset( const SfxItemSet& rSet )
476 
477 /*	[Beschreibung]
478 
479 */
480 
481 {
482 // os: So ein Unsinn! Irgendwo laesst sich so ein Item immer finden,
483 //		es muss aber im rSet vorhanden sein!
484 //	const SfxPoolItem* pX = GetOldItem( rSet, SID_VIEW_FLD_PIC );
485 // 	if( pX && pX->ISA(SfxWallpaperItem))
486 	if(SFX_ITEM_AVAILABLE <= rSet.GetItemState(GetWhich(SID_VIEW_FLD_PIC), sal_False))
487 	{
488 		ResetFromWallpaperItem( rSet );
489 		return;
490 	}
491 
492 	// Zustand des Vorschau-Buttons durch UserData persistent
493 	String aUserData = GetUserData();
494 	aBtnPreview.Check( aUserData.Len() && sal_Unicode('1') == aUserData.GetChar( 0 ) );
495 
496 	// nach Reset kein ShowSelector() mehr aufrufen d"urfen
497 	bAllowShowSelector = sal_False;
498 
499 
500 	// Input-BrushItem besorgen und auswerten
501 	const SvxBrushItem* pBgdAttr = NULL;
502 	sal_uInt16 nSlot = SID_ATTR_BRUSH;
503 	const SfxPoolItem* pItem;
504 	sal_uInt16 nDestValue = USHRT_MAX;
505 
506 	if ( SFX_ITEM_SET == rSet.GetItemState(	SID_BACKGRND_DESTINATION,
507 											sal_False, &pItem ) )
508 	{
509 		nDestValue = ((const SfxUInt16Item*)pItem)->GetValue();
510 		aTblLBox.SelectEntryPos(nDestValue);
511 
512 		switch ( nDestValue )
513 		{
514 			case TBL_DEST_CELL:
515 				nSlot = SID_ATTR_BRUSH;
516 			break;
517 			case TBL_DEST_ROW:
518 				nSlot = SID_ATTR_BRUSH_ROW;
519 			break;
520 			case TBL_DEST_TBL:
521 				nSlot = SID_ATTR_BRUSH_TABLE;
522 			break;
523 		}
524 	}
525 	else if( SFX_ITEM_SET == rSet.GetItemState(
526 				SID_PARA_BACKGRND_DESTINATION, sal_False, &pItem ) )
527 	{
528 		nDestValue = ((const SfxUInt16Item*)pItem)->GetValue();
529 		// ist gerade Zeichen aktiviert?
530 		sal_uInt16 nParaSel  = aParaLBox.GetSelectEntryPos();
531 		if(1 == nParaSel)
532 		{
533 			// dann war das ein "Standard" - Aufruf
534 			nDestValue = nParaSel;
535 		}
536 		aParaLBox.SelectEntryPos(nDestValue);
537 
538 		switch ( nDestValue )
539 		{
540 			case PARA_DEST_PARA:
541 				nSlot = SID_ATTR_BRUSH;
542 			break;
543 			case PARA_DEST_CHAR:
544 				nSlot = SID_ATTR_BRUSH_CHAR;
545 			break;
546 		}
547 	}
548     //#111173# the destination item is missing when the parent style has been changed
549     if(USHRT_MAX == nDestValue && (aParaLBox.IsVisible()||aTblLBox.IsVisible()))
550         nDestValue = 0;
551 	sal_uInt16 nWhich = GetWhich( nSlot );
552 
553 	if ( rSet.GetItemState( nWhich, sal_False ) >= SFX_ITEM_AVAILABLE )
554 		pBgdAttr = (const SvxBrushItem*)&( rSet.Get( nWhich ) );
555 
556 	aBtnTile.Check();
557 
558 	if ( pBgdAttr )
559 	{
560 		FillControls_Impl(*pBgdAttr, aUserData);
561 		aBgdColor = ( (SvxBrushItem*)pBgdAttr )->GetColor();
562 	}
563 	else
564 	{
565 		aSelectTxt.Hide();
566 		aLbSelect.Hide();
567 		aLbSelect.SelectEntryPos( 0 );
568 		ShowColorUI_Impl();
569 
570 		const SfxPoolItem* pOld = GetOldItem( rSet, SID_ATTR_BRUSH );
571 
572 		if ( pOld )
573 			aBgdColor = ( (SvxBrushItem*)pOld )->GetColor();
574 	}
575 
576 	if ( nDestValue != USHRT_MAX )
577 	{
578 		if(aTblLBox.IsVisible())
579 		{
580 			sal_uInt16 nValue = aTblLBox.GetSelectEntryPos();
581 
582 			if ( pTableBck_Impl )
583 			{
584                 DELETEZ( pTableBck_Impl->pCellBrush);
585                 DELETEZ( pTableBck_Impl->pRowBrush);
586                 DELETEZ( pTableBck_Impl->pTableBrush);
587 			}
588 			else
589 				pTableBck_Impl = new SvxBackgroundTable_Impl();
590 
591 			pTableBck_Impl->nActPos = nValue;
592 
593 			nWhich = GetWhich( SID_ATTR_BRUSH );
594 			if ( rSet.GetItemState( nWhich, sal_False ) >= SFX_ITEM_AVAILABLE )
595             {
596 				pBgdAttr = (const SvxBrushItem*)&( rSet.Get( nWhich ) );
597                 pTableBck_Impl->pCellBrush = new SvxBrushItem(*pBgdAttr);
598             }
599             pTableBck_Impl->nCellWhich = nWhich;
600 
601 			if ( rSet.GetItemState( SID_ATTR_BRUSH_ROW, sal_False ) >= SFX_ITEM_AVAILABLE )
602             {
603 				pBgdAttr = (const SvxBrushItem*)&( rSet.Get( SID_ATTR_BRUSH_ROW ) );
604                 pTableBck_Impl->pRowBrush = new SvxBrushItem(*pBgdAttr);
605             }
606             pTableBck_Impl->nRowWhich = SID_ATTR_BRUSH_ROW;
607 
608 			if ( rSet.GetItemState( SID_ATTR_BRUSH_TABLE, sal_False ) >= SFX_ITEM_AVAILABLE )
609             {
610 				pBgdAttr = (const SvxBrushItem*)&( rSet.Get( SID_ATTR_BRUSH_TABLE ) );
611                 pTableBck_Impl->pTableBrush = new SvxBrushItem(*pBgdAttr);
612             }
613             pTableBck_Impl->nTableWhich = SID_ATTR_BRUSH_TABLE;
614 
615 			TblDestinationHdl_Impl(&aTblLBox);
616 			aTblLBox.SaveValue();
617 		}
618 		else
619 		{
620 			sal_uInt16 nValue = aParaLBox.GetSelectEntryPos();
621 
622 			if ( pParaBck_Impl )
623 			{
624 				delete pParaBck_Impl->pParaBrush;
625 				delete pParaBck_Impl->pCharBrush;
626 			}
627 			else
628 				pParaBck_Impl = new SvxBackgroundPara_Impl();
629 
630 			pParaBck_Impl->nActPos = nValue;
631 
632 			nWhich = GetWhich( SID_ATTR_BRUSH );
633 			if ( rSet.GetItemState( nWhich, sal_False ) >= SFX_ITEM_AVAILABLE )
634             {
635 				pBgdAttr = (const SvxBrushItem*)&( rSet.Get( nWhich ) );
636 			    pParaBck_Impl->pParaBrush = new SvxBrushItem(*pBgdAttr);
637             }
638 
639 			nWhich = GetWhich( SID_ATTR_BRUSH_CHAR );
640 			SfxItemState eState = rSet.GetItemState( nWhich, sal_True );
641 			eState = rSet.GetItemState( nWhich, sal_False );
642 			if ( rSet.GetItemState( nWhich, sal_True ) > SFX_ITEM_AVAILABLE )
643 			{
644 				pBgdAttr = (const SvxBrushItem*)&( rSet.Get( nWhich ) );
645 				pParaBck_Impl->pCharBrush = new SvxBrushItem(*pBgdAttr);
646 			}
647 			else
648 				pParaBck_Impl->pCharBrush = new SvxBrushItem(SID_ATTR_BRUSH_CHAR);
649 
650 			ParaDestinationHdl_Impl(&aParaLBox);
651 			aParaLBox.SaveValue();
652 		}
653 	}
654     if(!bResized)
655     {
656         if(!aLbSelect.IsVisible() && !aTblLBox.IsVisible() && !aParaLBox.IsVisible())
657         {
658 			long nY(LogicToPixel(Point(11,14), MAP_APPFONT).X());
659 			long nX(LogicToPixel(Point(11,14), MAP_APPFONT).Y());
660             Point aPos(aBorderWin.GetPosPixel());
661 			aPos.X() = nX;
662             aPos.Y() = nY;
663             aBorderWin.SetPosPixel(aPos);
664             aPos = pPreviewWin1->GetPosPixel();
665             aPos.Y()  = nY;
666             pPreviewWin1->SetPosPixel(aPos);
667             aBackgroundColorBox.Hide();
668             aBackgroundColorSet.SetAccessibleRelationLabeledBy(&aBackgroundColorSet);
669         }
670     }
671 }
672 
673 void SvxBackgroundTabPage::ResetFromWallpaperItem( const SfxItemSet& rSet )
674 {
675 	ShowSelector();
676 
677 	// Zustand des Vorschau-Buttons durch UserData persistent
678 	String aUserData = GetUserData();
679 	aBtnPreview.Check( aUserData.Len() && sal_Unicode('1') == aUserData.GetChar( 0 ) );
680 
681 	// Input-BrushItem besorgen und auswerten
682 	const SvxBrushItem* pBgdAttr = NULL;
683 	sal_uInt16 nSlot = SID_VIEW_FLD_PIC;
684 	sal_uInt16 nWhich = GetWhich( nSlot );
685 	SvxBrushItem* pTemp = 0;
686 	const CntWallpaperItem* pItem = 0;
687 
688 	if ( rSet.GetItemState( nWhich, sal_False ) >= SFX_ITEM_AVAILABLE )
689 	{
690 		pItem = (const CntWallpaperItem*)&rSet.Get( nWhich );
691 		pTemp = new SvxBrushItem( *pItem, nWhich );
692 		pBgdAttr = pTemp;
693 	}
694 
695 	aBtnTile.Check();
696 
697 	if ( pBgdAttr )
698 	{
699 		FillControls_Impl(*pBgdAttr, aUserData);
700 		// Auch bei Anzeige der Grafik, soll die Brush erhalten bleiben
701 		if( aBgdColor != pBgdAttr->GetColor() )
702 		{
703 			aBgdColor = pBgdAttr->GetColor();
704 			sal_uInt16 nCol = GetItemId_Impl( aBackgroundColorSet, aBgdColor );
705 			aBackgroundColorSet.SelectItem( nCol );
706 			pPreviewWin1->NotifyChange( aBgdColor );
707 		}
708 	}
709 	else
710 	{
711 		aLbSelect.SelectEntryPos( 0 );
712 		ShowColorUI_Impl();
713 
714 		const SfxPoolItem* pOld = GetOldItem( rSet, SID_VIEW_FLD_PIC );
715 		if ( pOld )
716 			aBgdColor = Color( ((CntWallpaperItem*)pOld)->GetColor() );
717 	}
718 
719 	// We now have always a link to the background
720 	bLinkOnly = sal_True;
721 	aBtnLink.Check( sal_True );
722 	aBtnLink.Show( sal_False );
723 //	if( !pItem || !pItem->GetWallpaper(sal_False).IsBitmap() )
724 //		aBtnLink.Check();
725 
726 	delete pTemp;
727 }
728 
729 
730 
731 //------------------------------------------------------------------------
732 
733 void SvxBackgroundTabPage::FillUserData()
734 
735 /*	[Beschreibung]
736 
737 	Beim Destruieren einer SfxTabPage wird diese virtuelle Methode gerufen,
738 	damit die TabPage interne Informationen sichern kann.
739 
740 	In diesem Fall wird der Zustand des Vorschau-Buttons gesichert.
741 */
742 
743 {
744 	SetUserData( String( aBtnPreview.IsChecked() ? sal_Unicode('1') : sal_Unicode('0') ) );
745 }
746 
747 //------------------------------------------------------------------------
748 
749 sal_Bool SvxBackgroundTabPage::FillItemSet( SfxItemSet& rCoreSet )
750 
751 /*	[Beschreibung]
752 
753 */
754 
755 {
756 	if ( pPageImpl->pLoadTimer && pPageImpl->pLoadTimer->IsActive() )
757 	{
758 		pPageImpl->pLoadTimer->Stop();
759 		LoadTimerHdl_Impl( pPageImpl->pLoadTimer );
760 	}
761 // os: So ein Unsinn! Irgendwo laesst sich so ein Item immer finden,
762 //		es muss aber im rSet vorhanden sein!
763 
764 //	const SfxPoolItem* pX = GetOldItem( rCoreSet, SID_VIEW_FLD_PIC );
765 //	if( pX && pX->ISA(SfxWallpaperItem))
766 	if(SFX_ITEM_AVAILABLE <= rCoreSet.GetItemState(GetWhich(SID_VIEW_FLD_PIC), sal_False))
767 		return FillItemSetWithWallpaperItem( rCoreSet, SID_VIEW_FLD_PIC );
768 
769 	sal_Bool bModified = sal_False;
770 	sal_uInt16 nSlot = SID_ATTR_BRUSH;
771 
772 	if ( aTblLBox.IsVisible() )
773 	{
774 		switch( aTblLBox.GetSelectEntryPos() )
775 		{
776 			case TBL_DEST_CELL:
777 				nSlot = SID_ATTR_BRUSH;
778 			break;
779 			case TBL_DEST_ROW:
780 				nSlot = SID_ATTR_BRUSH_ROW;
781 			break;
782 			case TBL_DEST_TBL:
783 				nSlot = SID_ATTR_BRUSH_TABLE;
784 			break;
785 		}
786 	}
787 	else if(aParaLBox.GetData() == &aParaLBox)
788 	{
789 		switch(aParaLBox.GetSelectEntryPos())
790 		{
791 			case PARA_DEST_PARA:
792 				nSlot = SID_ATTR_BRUSH;
793 			break;
794 			case PARA_DEST_CHAR:
795 				nSlot = SID_ATTR_BRUSH_CHAR;
796 			break;
797 		}
798 	}
799 	sal_uInt16 nWhich = GetWhich( nSlot );
800 
801 	const SfxPoolItem* pOld = GetOldItem( rCoreSet, nSlot );
802 	SfxItemState eOldItemState = rCoreSet.GetItemState(nSlot, sal_False);
803 	const SfxItemSet& rOldSet = GetItemSet();
804 
805     sal_Bool bGraphTransparencyChanged = bGraphTransparency && (aGraphTransMF.GetText() != aGraphTransMF.GetSavedValue());
806     if ( pOld )
807 	{
808 		const SvxBrushItem& rOldItem	= (const SvxBrushItem&)*pOld;
809 		SvxGraphicPosition	eOldPos		= rOldItem.GetGraphicPos();
810 		const sal_Bool 			bIsBrush	= ( 0 == aLbSelect.GetSelectEntryPos() );
811 
812         // transparency has to be set if enabled, the color not already set to "No fill" and
813         if( bColTransparency &&
814             aBgdColor.GetTransparency() < 0xff)
815         {
816             aBgdColor.SetTransparency(lcl_PercentToTransparency(static_cast<long>(aColTransMF.GetValue())));
817         }
818         if (   ( (GPOS_NONE == eOldPos) && bIsBrush  )
819 			|| ( (GPOS_NONE != eOldPos) && !bIsBrush ) ) // Brush <-> Bitmap gewechselt?
820 		{
821 			// Hintergrund-Art wurde nicht gewechselt:
822 
823 			if ( (GPOS_NONE == eOldPos) || !aLbSelect.IsVisible() )
824 			{
825 				// Brush-Behandlung:
826 				if ( rOldItem.GetColor() != aBgdColor ||
827 						(SFX_ITEM_AVAILABLE >= eOldItemState && !aBackgroundColorSet.IsNoSelection()))
828 				{
829 					bModified = sal_True;
830 					rCoreSet.Put( SvxBrushItem( aBgdColor, nWhich ) );
831 				}
832 				else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich, sal_False ) )
833 					rCoreSet.ClearItem( nWhich );
834 			}
835 			else
836 			{
837 				// Bitmap-Behandlung:
838 
839 				SvxGraphicPosition	eNewPos  = GetGraphicPosition_Impl();
840 				const sal_Bool			bIsLink  = aBtnLink.IsChecked();
841 				const sal_Bool			bWasLink = (NULL != rOldItem.GetGraphicLink() );
842 
843 
844 				if ( !bIsLink && !bIsGraphicValid )
845 					bIsGraphicValid = LoadLinkedGraphic_Impl();
846 
847                 if (    bGraphTransparencyChanged ||
848                         eNewPos != eOldPos
849 					|| bIsLink != bWasLink
850 					|| ( bWasLink  &&    *rOldItem.GetGraphicLink()
851 									  != aBgdGraphicPath )
852 					|| ( !bWasLink &&    rOldItem.GetGraphic()->GetBitmap()
853 									  != aBgdGraphic.GetBitmap() )
854 				   )
855 				{
856 					bModified = sal_True;
857 
858                     SvxBrushItem aTmpBrush(nWhich);
859                     if ( bIsLink )
860 					{
861                         aTmpBrush = SvxBrushItem( aBgdGraphicPath,
862                                                 aBgdGraphicFilter,
863                                                 eNewPos,
864                                                 nWhich );
865 					}
866 					else
867                         aTmpBrush = SvxBrushItem( aBgdGraphic,
868                                         eNewPos,
869                                         nWhich );
870                     lcl_SetTransparency(aTmpBrush, static_cast<long>(aGraphTransMF.GetValue()));
871 
872                     rCoreSet.Put(aTmpBrush);
873 				}
874 				else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich, sal_False ) )
875 					rCoreSet.ClearItem( nWhich );
876 			}
877 		}
878 		else // Brush <-> Bitmap gewechselt!
879 		{
880 			if ( bIsBrush )
881 				rCoreSet.Put( SvxBrushItem( aBgdColor, nWhich ) );
882 			else
883 			{
884                 SvxBrushItem* pTmpBrush = 0;
885                 if ( aBtnLink.IsChecked() )
886 				{
887                     pTmpBrush = new SvxBrushItem( aBgdGraphicPath,
888 												aBgdGraphicFilter,
889 												GetGraphicPosition_Impl(),
890                                                 nWhich );
891 				}
892 				else
893 				{
894 					if ( !bIsGraphicValid )
895 						bIsGraphicValid = LoadLinkedGraphic_Impl();
896 
897 					if ( bIsGraphicValid )
898                         pTmpBrush = new SvxBrushItem( aBgdGraphic,
899 													GetGraphicPosition_Impl(),
900                                                     nWhich );
901 				}
902                 if(pTmpBrush)
903                 {
904                     lcl_SetTransparency(*pTmpBrush, static_cast<long>(aGraphTransMF.GetValue()));
905                     rCoreSet.Put(*pTmpBrush);
906                     delete pTmpBrush;
907                 }
908 			}
909 			bModified = ( bIsBrush || aBtnLink.IsChecked() || bIsGraphicValid );
910 		}
911 	}
912 	else if ( SID_ATTR_BRUSH_CHAR == nSlot && aBgdColor != Color( COL_WHITE ) )
913 	{
914 		rCoreSet.Put( SvxBrushItem( aBgdColor, nWhich ) );
915 		bModified = sal_True;
916 	}
917 
918 	if( aTblLBox.IsVisible() )
919 	{
920 		// Der aktuelle Zustand wurde bereits geputtet
921         if( nSlot != SID_ATTR_BRUSH && pTableBck_Impl->pCellBrush)
922 		{
923 			const SfxPoolItem* pOldCell =
924 				GetOldItem( rCoreSet, SID_ATTR_BRUSH );
925 
926             if ( *pTableBck_Impl->pCellBrush != *pOldCell )
927 			{
928 				rCoreSet.Put( *pTableBck_Impl->pCellBrush );
929 				bModified |= sal_True;
930 			}
931 		}
932 
933         if( nSlot != SID_ATTR_BRUSH_ROW && pTableBck_Impl->pRowBrush)
934 		{
935 			const SfxPoolItem* pOldRow =
936 				GetOldItem( rCoreSet, SID_ATTR_BRUSH_ROW );
937 
938             if ( *pTableBck_Impl->pRowBrush != *pOldRow )
939 			{
940 				rCoreSet.Put( *pTableBck_Impl->pRowBrush );
941 				bModified |= sal_True;
942 			}
943 		}
944 
945         if( nSlot != SID_ATTR_BRUSH_TABLE && pTableBck_Impl->pTableBrush)
946 		{
947 			const SfxPoolItem* pOldTable =
948 				GetOldItem( rCoreSet, SID_ATTR_BRUSH_TABLE );
949 
950 			if ( *pTableBck_Impl->pTableBrush != *pOldTable )
951 			{
952 				rCoreSet.Put( *pTableBck_Impl->pTableBrush );
953 				bModified |= sal_True;
954 			}
955 		}
956 
957 		if( aTblLBox.GetSavedValue() != aTblLBox.GetSelectEntryPos() )
958 		{
959 			rCoreSet.Put( SfxUInt16Item( SID_BACKGRND_DESTINATION,
960 										 aTblLBox.GetSelectEntryPos() ) );
961 			bModified |= sal_True;
962 		}
963 	}
964 	else if(aParaLBox.GetData() == &aParaLBox)
965 	{
966 		// Der aktuelle Zustand wurde bereits geputtet
967 		if( nSlot != SID_ATTR_BRUSH && aParaLBox.IsVisible()) // nicht im Suchen-Format-Dialog
968 		{
969 			const SfxPoolItem* pOldPara =
970 				GetOldItem( rCoreSet, SID_ATTR_BRUSH );
971 
972 			if ( *pParaBck_Impl->pParaBrush != *pOldPara )
973 			{
974 				rCoreSet.Put( *pParaBck_Impl->pParaBrush );
975 				bModified |= sal_True;
976 			}
977 		}
978 
979 		if( nSlot != SID_ATTR_BRUSH_CHAR )
980 		{
981 			const SfxPoolItem* pOldChar =
982 				GetOldItem( rCoreSet, SID_ATTR_BRUSH_CHAR );
983             DBG_ASSERT(pParaBck_Impl, "pParaBck_Impl == NULL ?");
984             if ( pOldChar &&
985                     //#111173#  crash report shows that pParaBck_Impl can be NULL, the cause is unknown
986                     pParaBck_Impl &&
987                         (*pParaBck_Impl->pCharBrush != *pOldChar ||
988                 *pParaBck_Impl->pCharBrush != SvxBrushItem(SID_ATTR_BRUSH_CHAR)))
989 			{
990 				rCoreSet.Put( *pParaBck_Impl->pCharBrush );
991 				bModified |= sal_True;
992 			}
993 		}
994 
995 		if( aParaLBox.GetSavedValue() != aParaLBox.GetSelectEntryPos() )
996 		{
997 			rCoreSet.Put( SfxUInt16Item( SID_BACKGRND_DESTINATION,
998 										 aParaLBox.GetSelectEntryPos() ) );
999 			bModified |= sal_True;
1000 		}
1001 	}
1002 	return bModified;
1003 }
1004 
1005 sal_Bool SvxBackgroundTabPage::FillItemSetWithWallpaperItem( SfxItemSet& rCoreSet, sal_uInt16 nSlot)
1006 {
1007 	sal_uInt16 nWhich = GetWhich( nSlot );
1008 	const SfxPoolItem* pOld = GetOldItem( rCoreSet, nSlot );
1009 	const SfxItemSet& rOldSet = GetItemSet();
1010 	DBG_ASSERT(pOld,"FillItemSetWithWallpaperItem: Item not found");
1011 
1012 	SvxBrushItem 		rOldItem( (const CntWallpaperItem&)*pOld, nWhich );
1013 	SvxGraphicPosition	eOldPos		= rOldItem.GetGraphicPos();
1014 	const sal_Bool 			bIsBrush	= ( 0 == aLbSelect.GetSelectEntryPos() );
1015 	sal_Bool				bModified = sal_False;
1016 
1017 	if (   ( (GPOS_NONE == eOldPos) && bIsBrush  )
1018 		|| ( (GPOS_NONE != eOldPos) && !bIsBrush ) ) // Brush <-> Bitmap gewechselt?
1019 	{
1020 		// Hintergrund-Art wurde nicht gewechselt:
1021 
1022 		if ( (GPOS_NONE == eOldPos) || !aLbSelect.IsVisible() )
1023 		{
1024 			// Brush-Behandlung:
1025 			if ( rOldItem.GetColor() != aBgdColor )
1026 			{
1027 				bModified = sal_True;
1028 				CntWallpaperItem aItem( nWhich );
1029 				aItem.SetColor( aBgdColor );
1030 				rCoreSet.Put( aItem );
1031 			}
1032 			else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich, sal_False ) )
1033 				rCoreSet.ClearItem( nWhich );
1034 		}
1035 		else
1036 		{
1037 			// Bitmap-Behandlung:
1038 			SvxGraphicPosition	eNewPos  = GetGraphicPosition_Impl();
1039 
1040 			int bBitmapChanged = ( ( eNewPos != eOldPos ) ||
1041 								   ( *rOldItem.GetGraphicLink() != aBgdGraphicPath ) );
1042 			int bBrushChanged = ( rOldItem.GetColor() != aBgdColor );
1043 			if( bBitmapChanged || bBrushChanged )
1044 			{
1045 				bModified = sal_True;
1046 
1047 				CntWallpaperItem aItem( nWhich );
1048 				WallpaperStyle eWallStyle = SvxBrushItem::GraphicPos2WallpaperStyle(eNewPos);
1049 				aItem.SetStyle( sal::static_int_cast< sal_uInt16 >( eWallStyle ) );
1050 				aItem.SetColor( aBgdColor );
1051                 aItem.SetBitmapURL( aBgdGraphicPath );
1052 				rCoreSet.Put( aItem );
1053 			}
1054 			else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich, sal_False ) )
1055 				rCoreSet.ClearItem( nWhich );
1056 		}
1057 	}
1058 	else // Brush <-> Bitmap gewechselt!
1059 	{
1060 		CntWallpaperItem aItem( nWhich );
1061 		if ( bIsBrush )
1062 		{
1063 			aItem.SetColor( aBgdColor );
1064 			rCoreSet.Put( aItem );
1065 		}
1066 		else
1067 		{
1068 			WallpaperStyle eWallStyle =
1069 				SvxBrushItem::GraphicPos2WallpaperStyle( GetGraphicPosition_Impl() );
1070 			aItem.SetStyle( sal::static_int_cast< sal_uInt16 >( eWallStyle ) );
1071 			aItem.SetColor( aBgdColor );
1072             aItem.SetBitmapURL( aBgdGraphicPath );
1073 			rCoreSet.Put( aItem );
1074 		}
1075 
1076 		bModified = sal_True;
1077 	}
1078 	return bModified;
1079 }
1080 
1081 //-----------------------------------------------------------------------
1082 
1083 int SvxBackgroundTabPage::DeactivatePage( SfxItemSet* _pSet )
1084 
1085 /*	[Beschreibung]
1086 
1087 	virtuelle Methode, wird beim Deaktivieren gerufen
1088 */
1089 
1090 {
1091 	if ( pPageImpl->bIsImportDlgInExecute )
1092 		return KEEP_PAGE;
1093 
1094     if ( _pSet )
1095         FillItemSet( *_pSet );
1096 
1097     return LEAVE_PAGE;
1098 }
1099 
1100 //-----------------------------------------------------------------------
1101 
1102 void SvxBackgroundTabPage::PointChanged( Window* , RECT_POINT  )
1103 
1104 /*	[Beschreibung]
1105 
1106 */
1107 
1108 {
1109 	// muss implementiert werden, damit Position-Control funktioniert
1110 }
1111 
1112 //-----------------------------------------------------------------------
1113 
1114 void SvxBackgroundTabPage::ShowSelector()
1115 
1116 /*	[Beschreibung]
1117 
1118 */
1119 
1120 {
1121 	if( bAllowShowSelector)
1122 	{
1123 		aSelectTxt.Show();
1124 		aLbSelect.Show();
1125 		aLbSelect.SetSelectHdl( HDL(SelectHdl_Impl) );
1126 		aBtnLink.SetClickHdl( HDL(FileClickHdl_Impl) );
1127 		aBtnPreview.SetClickHdl( HDL(FileClickHdl_Impl) );
1128 		aBtnBrowse.SetClickHdl( HDL(BrowseHdl_Impl) );
1129 		aBtnArea.SetClickHdl( HDL(RadioClickHdl_Impl) );
1130 		aBtnTile.SetClickHdl( HDL(RadioClickHdl_Impl) );
1131 		aBtnPosition.SetClickHdl( HDL(RadioClickHdl_Impl) );
1132 
1133 		// Verz"ogertes Laden "uber Timer (wg. UI-Update)
1134 		pPageImpl->pLoadTimer = new Timer;
1135 		pPageImpl->pLoadTimer->SetTimeout( 500 ); // 500ms verz"ogern
1136 		pPageImpl->pLoadTimer->SetTimeoutHdl(
1137 			LINK( this, SvxBackgroundTabPage, LoadTimerHdl_Impl ) );
1138 
1139 		bAllowShowSelector = sal_False;
1140 
1141 		if(nHtmlMode & HTMLMODE_ON)
1142 		{
1143 			if(!(nHtmlMode & HTMLMODE_GRAPH_POS))
1144 				aBtnPosition.Enable(sal_False);
1145 			aBtnArea.Enable(sal_False);
1146 		}
1147 	}
1148 }
1149 
1150 //------------------------------------------------------------------------
1151 
1152 
1153 void SvxBackgroundTabPage::RaiseLoadError_Impl()
1154 
1155 /*	[Beschreibung]
1156 
1157 */
1158 
1159 {
1160 	SfxErrorContext aContext( ERRCTX_SVX_BACKGROUND,
1161 							  String(),
1162 							  this,
1163 							  RID_SVXERRCTX,
1164 							  &CUI_MGR() );
1165 
1166 	ErrorHandler::HandleError(
1167 		*new StringErrorInfo( ERRCODE_SVX_GRAPHIC_NOTREADABLE,
1168 							  aBgdGraphicPath ) );
1169 }
1170 
1171 //------------------------------------------------------------------------
1172 
1173 sal_Bool SvxBackgroundTabPage::LoadLinkedGraphic_Impl()
1174 
1175 /*	[Beschreibung]
1176 
1177 */
1178 
1179 {
1180 	sal_Bool bResult = ( aBgdGraphicPath.Len() > 0 ) &&
1181 				   ( GRFILTER_OK == GraphicFilter::LoadGraphic( aBgdGraphicPath,
1182 												 aBgdGraphicFilter,
1183 												 aBgdGraphic ) );
1184 	return bResult;
1185 }
1186 
1187 //------------------------------------------------------------------------
1188 
1189 
1190 void SvxBackgroundTabPage::FillColorValueSets_Impl()
1191 
1192 /*	[Beschreibung]
1193 
1194 	F"ullen des Farb-Sets
1195 */
1196 
1197 {
1198 	SfxObjectShell* pDocSh = SfxObjectShell::Current();
1199 	const SfxPoolItem* pItem = NULL;
1200 	XColorList* pColorTable = NULL;
1201 	bool bOwn(false);
1202     long nColorCount(0);
1203 
1204 	if ( pDocSh && ( 0 != ( pItem = pDocSh->GetItem( SID_COLOR_TABLE ) ) ) )
1205     {
1206 		pColorTable = ( (SvxColorTableItem*)pItem )->GetColorTable();
1207     }
1208 
1209 	if ( !pColorTable )
1210 	{
1211 		bOwn = true;
1212 		pColorTable = new XColorList( SvtPathOptions().GetPalettePath() );
1213 	}
1214 
1215 	if ( pColorTable )
1216 	{
1217         nColorCount = pColorTable->Count();
1218         aBackgroundColorSet.Clear();
1219         aBackgroundColorSet.addEntriesForXColorList(*pColorTable);
1220 
1221         if(bOwn)
1222         {
1223 		    delete pColorTable;
1224         }
1225     }
1226 
1227 	const WinBits nBits(aBackgroundColorSet.GetStyle() | WB_ITEMBORDER | WB_NAMEFIELD | WB_NONEFIELD);
1228 	aBackgroundColorSet.SetStyle(nBits);
1229     aBackgroundColorSet.SetColCount(aBackgroundColorSet.getColumnCount());
1230 
1231     // here we have enough space to the left, so layout with fixed column size
1232     // and fixed height, adapt width. Apply the adapted width by moving the left
1233     // edge of the control to the left, keeping the right edge aligned
1234     // with the original position
1235     const Point aCurrentPosContainer(aBorderWin.GetPosPixel());
1236     const Size aCurrentSizeContainer(aBorderWin.GetOutputSizePixel());
1237     const Size aCurrentSizeContent(aBackgroundColorSet.GetOutputSizePixel());
1238     const Size aNewSizeContent(aBackgroundColorSet.layoutToGivenHeight(aCurrentSizeContent.Height() - 4, nColorCount));
1239     const Size aNewSizeContainer(aNewSizeContent.Width() + 4, aNewSizeContent.Height() + 4);
1240     const Point aNewPos((aCurrentPosContainer.X() + aCurrentSizeContainer.Width()) - aNewSizeContainer.Width(), aCurrentPosContainer.Y());
1241 
1242     aBorderWin.SetOutputSizePixel(aNewSizeContainer);
1243     aBackgroundColorSet.SetOutputSizePixel(aNewSizeContent);
1244     aBorderWin.SetPosSizePixel(aNewPos, aNewSizeContainer);
1245 }
1246 
1247 //------------------------------------------------------------------------
1248 
1249 
1250 
1251 //------------------------------------------------------------------------
1252 
1253 void SvxBackgroundTabPage::ShowColorUI_Impl()
1254 
1255 /*	[Beschreibung]
1256 
1257 	Die Controls f"ur das Einstellen der Grafik ausblenden und die
1258 	Controls f"ur die Farbeinstellung einblenden.
1259 */
1260 
1261 {
1262 	if( !aBackgroundColorSet.IsVisible() )
1263 	{
1264 		aBackgroundColorSet.Show();
1265 		aBackgroundColorBox.Show();
1266 		aBorderWin.Show();
1267 		pPreviewWin1->Show();
1268 		aBtnBrowse.Hide();
1269 		aFtFile.Hide();
1270 		aBtnLink.Hide();
1271 		aBtnPreview.Hide();
1272 		aGbFile.Hide();
1273 		aBtnPosition.Hide();
1274 		aBtnArea.Hide();
1275 		aBtnTile.Hide();
1276 		aWndPosition.Hide();
1277 		aGbPosition.Hide();
1278 		pPreviewWin2->Hide();
1279         aGraphTransFL.Show(sal_False);
1280         aGraphTransMF.Show(sal_False);
1281         if(bColTransparency)
1282 		{
1283 			aColTransFT.Show();
1284 			aColTransMF.Show();
1285 		}
1286     }
1287 }
1288 
1289 //------------------------------------------------------------------------
1290 
1291 void SvxBackgroundTabPage::ShowBitmapUI_Impl()
1292 
1293 /*	[Beschreibung]
1294 
1295 	Die Controls f"ur die Farbeinstellung ausblenden und die
1296 	Controls f"ur das Einstellen der Grafik einblenden.
1297 */
1298 
1299 {
1300 	if ( aLbSelect.IsVisible() &&
1301 		 (
1302 		aBackgroundColorSet.IsVisible()
1303 		 || !aBtnBrowse.IsVisible() ) )
1304 	{
1305 		aBackgroundColorSet.Hide();
1306 		aBackgroundColorBox.Hide();
1307 		aBorderWin.Hide();
1308 		pPreviewWin1->Hide();
1309 		aBtnBrowse.Show();
1310 		aFtFile.Show();
1311 
1312 		if ( !bLinkOnly && ! nHtmlMode & HTMLMODE_ON )
1313 			aBtnLink.Show();
1314 		aBtnPreview.Show();
1315 		aGbFile.Show();
1316 		aBtnPosition.Show();
1317 		aBtnArea.Show();
1318 		aBtnTile.Show();
1319 		aWndPosition.Show();
1320 		aGbPosition.Show();
1321 		pPreviewWin2->Show();
1322         if(bGraphTransparency)
1323 		{
1324 			aGraphTransFL.Show();
1325 			aGraphTransMF.Show();
1326 		}
1327         aColTransFT.Show(sal_False);
1328         aColTransMF.Show(sal_False);
1329     }
1330 }
1331 
1332 //------------------------------------------------------------------------
1333 
1334 void SvxBackgroundTabPage::SetGraphicPosition_Impl( SvxGraphicPosition ePos )
1335 
1336 /*	[Beschreibung]
1337 
1338 	Die Controls f"ur die Grafikposition einstellen.
1339 */
1340 
1341 {
1342 	switch ( ePos )
1343 	{
1344 		case GPOS_AREA:
1345 		{
1346 			aBtnArea.Check();
1347 			aWndPosition.Disable();
1348 		}
1349 		break;
1350 
1351 		case GPOS_TILED:
1352 		{
1353 			aBtnTile.Check();
1354 			aWndPosition.Disable();
1355 		}
1356 		break;
1357 
1358 		default:
1359 		{
1360 			aBtnPosition.Check();
1361 			aWndPosition.Enable();
1362 			RECT_POINT eNewPos = RP_MM;
1363 
1364 			switch ( ePos )
1365 			{
1366 				case GPOS_MM:	break;
1367 				case GPOS_LT:	eNewPos = RP_LT; break;
1368 				case GPOS_MT:	eNewPos = RP_MT; break;
1369 				case GPOS_RT:	eNewPos = RP_RT; break;
1370 				case GPOS_LM:	eNewPos = RP_LM; break;
1371 				case GPOS_RM:	eNewPos = RP_RM; break;
1372 				case GPOS_LB:	eNewPos = RP_LB; break;
1373 				case GPOS_MB:	eNewPos = RP_MB; break;
1374 				case GPOS_RB:	eNewPos = RP_RB; break;
1375                 default: ;//prevent warning
1376 			}
1377 			aWndPosition.SetActualRP( eNewPos );
1378 		}
1379 		break;
1380 	}
1381 	aWndPosition.Invalidate();
1382 }
1383 
1384 //------------------------------------------------------------------------
1385 
1386 SvxGraphicPosition SvxBackgroundTabPage::GetGraphicPosition_Impl()
1387 
1388 /*	[Beschreibung]
1389 
1390 	Die Position der Grafik zur"uckgeben.
1391 */
1392 
1393 {
1394 	if ( aBtnTile.IsChecked() )
1395 		return GPOS_TILED;
1396 	else if ( aBtnArea.IsChecked() )
1397 		return GPOS_AREA;
1398 	else
1399 	{
1400 		switch ( aWndPosition.GetActualRP() )
1401 		{
1402 			case RP_LT:	return GPOS_LT;
1403 			case RP_MT:	return GPOS_MT;
1404 			case RP_RT:	return GPOS_RT;
1405 			case RP_LM:	return GPOS_LM;
1406 			case RP_MM:	return GPOS_MM;
1407 			case RP_RM:	return GPOS_RM;
1408 			case RP_LB:	return GPOS_LB;
1409 			case RP_MB:	return GPOS_MB;
1410 			case RP_RB:	return GPOS_RB;
1411 		}
1412 	}
1413 	return GPOS_MM;
1414 }
1415 
1416 //-----------------------------------------------------------------------
1417 // Handler
1418 //-----------------------------------------------------------------------
1419 
1420 IMPL_LINK( SvxBackgroundTabPage, BackgroundColorHdl_Impl, ValueSet*, EMPTYARG )
1421 /*
1422     Handler, called when color selection is changed
1423 */
1424 {
1425 	sal_uInt16 nItemId = aBackgroundColorSet.GetSelectItemId();
1426 	Color aColor = nItemId ? ( aBackgroundColorSet.GetItemColor( nItemId ) ) : Color( COL_TRANSPARENT );
1427 	aBgdColor = aColor;
1428 	pPreviewWin1->NotifyChange( aBgdColor );
1429     sal_Bool bEnableTransp = aBgdColor.GetTransparency() < 0xff;
1430     aColTransFT.Enable(bEnableTransp);
1431     aColTransMF.Enable(bEnableTransp);
1432     return 0;
1433 }
1434 
1435 //------------------------------------------------------------------------
1436 
1437 IMPL_LINK( SvxBackgroundTabPage, SelectHdl_Impl, ListBox*, EMPTYARG )
1438 
1439 /*	[Beschreibung]
1440 
1441 */
1442 
1443 {
1444 	if ( 0 == aLbSelect.GetSelectEntryPos() )
1445 	{
1446 		ShowColorUI_Impl();
1447 		aParaLBox.Enable(); // Zeichenhintergrund kann keine Bitmap sein
1448 	}
1449 	else
1450 	{
1451 		ShowBitmapUI_Impl();
1452 		aParaLBox.Enable(sal_False);// Zeichenhintergrund kann keine Bitmap sein
1453 	}
1454 	return 0;
1455 }
1456 
1457 //------------------------------------------------------------------------
1458 
1459 IMPL_LINK( SvxBackgroundTabPage, FileClickHdl_Impl, CheckBox*, pBox )
1460 
1461 /*	[Beschreibung]
1462 
1463 */
1464 
1465 {
1466 	if ( &aBtnLink == pBox )
1467 	{
1468 		if ( aBtnLink.IsChecked() )
1469 		{
1470             INetURLObject aObj( aBgdGraphicPath );
1471 			String aFilePath;
1472 			if ( aObj.GetProtocol() == INET_PROT_FILE )
1473 				aFilePath = aObj.getFSysPath( INetURLObject::FSYS_DETECT );
1474 			else
1475 				aFilePath = aBgdGraphicPath;
1476 			aFtFile.SetText( aFilePath );
1477 		}
1478 		else
1479 			aFtFile.SetText( aStrUnlinked );
1480 	}
1481 	else if ( &aBtnPreview == pBox )
1482 	{
1483 		if ( aBtnPreview.IsChecked() )
1484 		{
1485 			if ( !bIsGraphicValid )
1486 				bIsGraphicValid = LoadLinkedGraphic_Impl();
1487 
1488 			if ( bIsGraphicValid )
1489 			{
1490 				Bitmap aBmp = aBgdGraphic.GetBitmap();
1491 				pPreviewWin2->NotifyChange( &aBmp );
1492 			}
1493 			else
1494 			{
1495 				if ( aBgdGraphicPath.Len() > 0 ) // nur bei gelinkter Grafik
1496 					RaiseLoadError_Impl();		 // ein Fehler
1497 				pPreviewWin2->NotifyChange( NULL );
1498 			}
1499 		}
1500 		else
1501 			pPreviewWin2->NotifyChange( NULL );
1502 	}
1503 	return 0;
1504 }
1505 
1506 //------------------------------------------------------------------------
1507 
1508 IMPL_LINK( SvxBackgroundTabPage, RadioClickHdl_Impl, RadioButton*, pBtn )
1509 
1510 /*	[Beschreibung]
1511 
1512 */
1513 
1514 {
1515 	if ( pBtn == &aBtnPosition )
1516 	{
1517 		if ( !aWndPosition.IsEnabled() )
1518 		{
1519 			aWndPosition.Enable();
1520 			aWndPosition.Invalidate();
1521 		}
1522 	}
1523 	else if ( aWndPosition.IsEnabled() )
1524 	{
1525 		aWndPosition.Disable();
1526 		aWndPosition.Invalidate();
1527 	}
1528 	return 0;
1529 }
1530 
1531 //------------------------------------------------------------------------
1532 
1533 IMPL_LINK( SvxBackgroundTabPage, BrowseHdl_Impl, PushButton* , EMPTYARG )
1534 
1535 /*	[Beschreibung]
1536 
1537 	Handler, gerufen durch das Dr"ucken des Durchsuchen-Buttons.
1538 	Grafik/Einf"ugen-Dialog erzeugen, Pfad setzen und starten.
1539 */
1540 
1541 {
1542 	if ( pPageImpl->pLoadTimer->IsActive() )
1543 		return 0;
1544 	sal_Bool bHtml = 0 != ( nHtmlMode & HTMLMODE_ON );
1545 
1546 	pImportDlg = new SvxOpenGraphicDialog( aStrBrowse );
1547 	if ( bHtml || bLinkOnly )
1548 		pImportDlg->EnableLink(sal_False);
1549 	pImportDlg->SetPath( aBgdGraphicPath, aBtnLink.IsChecked() );
1550 
1551 	pPageImpl->bIsImportDlgInExecute = sal_True;
1552 	short nErr = pImportDlg->Execute();
1553 	pPageImpl->bIsImportDlgInExecute = sal_False;
1554 
1555 	if( !nErr )
1556 	{
1557 		if ( bHtml )
1558 			aBtnLink.Check();
1559 		// wenn Verkn"upfen nicht gecheckt ist und die Vorschau auch nicht,
1560 		// dann die Vorschau aktivieren, damit der Anwender sieht,
1561 		// welche Grafik er ausgew"ahlt hat
1562 		if ( !aBtnLink.IsChecked() && !aBtnPreview.IsChecked() )
1563 			aBtnPreview.Check( sal_True );
1564 		// timer-verz"ogertes Laden der Grafik
1565 		pPageImpl->pLoadTimer->Start();
1566 	}
1567 	else
1568 		DELETEZ( pImportDlg );
1569 	return 0;
1570 }
1571 
1572 //-----------------------------------------------------------------------
1573 
1574 IMPL_LINK( SvxBackgroundTabPage, LoadTimerHdl_Impl, Timer* , pTimer )
1575 
1576 /*	[Beschreibung]
1577 
1578 	Verz"ogertes Laden der Grafik.
1579 	Grafik wird nur dann geladen, wenn sie unterschiedlich zur
1580 	aktuellen Grafik ist.
1581 */
1582 
1583 {
1584 	if ( pTimer == pPageImpl->pLoadTimer )
1585 	{
1586 		pPageImpl->pLoadTimer->Stop();
1587 
1588 		if ( pImportDlg )
1589 		{
1590             INetURLObject aOld( aBgdGraphicPath );
1591 			INetURLObject aNew( pImportDlg->GetPath() );
1592 			if ( !aBgdGraphicPath.Len() || aNew != aOld )
1593 			{
1594 				// neue Datei gew"ahlt
1595 				aBgdGraphicPath   = pImportDlg->GetPath();
1596 				aBgdGraphicFilter =	pImportDlg->GetCurrentFilter();
1597 				sal_Bool bLink = ( nHtmlMode & HTMLMODE_ON ) || bLinkOnly ? sal_True : pImportDlg->IsAsLink();
1598 				aBtnLink.Check( bLink );
1599 				aBtnLink.Enable();
1600 
1601 				if ( aBtnPreview.IsChecked() )
1602 				{
1603 					if( !pImportDlg->GetGraphic(aBgdGraphic) )
1604 					{
1605 						bIsGraphicValid = sal_True;
1606 					}
1607 					else
1608 					{
1609 						aBgdGraphicFilter.Erase();
1610 						aBgdGraphicPath.Erase();
1611 						bIsGraphicValid = sal_False;
1612 					}
1613 				}
1614 				else
1615 					bIsGraphicValid = sal_False; // Grafik erst beim Preview-Click laden
1616 
1617 				if ( aBtnPreview.IsChecked() && bIsGraphicValid )
1618 				{
1619 					Bitmap aBmp = aBgdGraphic.GetBitmap();
1620 					pPreviewWin2->NotifyChange( &aBmp );
1621 				}
1622 				else
1623 					pPreviewWin2->NotifyChange( NULL );
1624 			}
1625 
1626 			FileClickHdl_Impl( &aBtnLink );
1627 			DELETEZ( pImportDlg );
1628 		}
1629 	}
1630 	return 0;
1631 }
1632 
1633 //-----------------------------------------------------------------------
1634 
1635 void SvxBackgroundTabPage::ShowTblControl()
1636 
1637 /*	[Beschreibung]
1638 
1639 */
1640 
1641 {
1642 	aTblLBox			.SetSelectHdl( HDL(TblDestinationHdl_Impl) );
1643 	aTblLBox			.SelectEntryPos(0);
1644 	aTblDesc.Show();
1645 	aTblLBox.Show();
1646 }
1647 
1648 //-----------------------------------------------------------------------
1649 
1650 void SvxBackgroundTabPage::ShowParaControl(sal_Bool bCharOnly)
1651 {
1652 	aParaLBox.SetSelectHdl(HDL(ParaDestinationHdl_Impl));
1653 	aParaLBox.SelectEntryPos(0);
1654 	if(!bCharOnly)
1655 	{
1656 		aTblDesc.Show();
1657 		aParaLBox.Show();
1658 	}
1659 	aParaLBox.SetData(&aParaLBox); // hier erkennt man, dass dieser Mode eingeschaltet ist
1660 }
1661 //-----------------------------------------------------------------------
1662 
1663 IMPL_LINK( SvxBackgroundTabPage, TblDestinationHdl_Impl, ListBox*, pBox )
1664 
1665 /*	[Beschreibung]
1666 
1667 */
1668 
1669 {
1670 	sal_uInt16 nSelPos = pBox->GetSelectEntryPos();
1671 	if( pTableBck_Impl && pTableBck_Impl->nActPos != nSelPos)
1672 	{
1673 		SvxBrushItem** pActItem = new (SvxBrushItem*);
1674         sal_uInt16 nWhich = 0;
1675         switch(pTableBck_Impl->nActPos)
1676 		{
1677 			case TBL_DEST_CELL:
1678                 *pActItem = pTableBck_Impl->pCellBrush;
1679                 nWhich = pTableBck_Impl->nCellWhich;
1680 			break;
1681 			case TBL_DEST_ROW:
1682                 *pActItem = pTableBck_Impl->pRowBrush;
1683                 nWhich = pTableBck_Impl->nRowWhich;
1684 			break;
1685 			case TBL_DEST_TBL:
1686                 *pActItem = pTableBck_Impl->pTableBrush;
1687                 nWhich = pTableBck_Impl->nTableWhich;
1688 			break;
1689 		}
1690 		pTableBck_Impl->nActPos = nSelPos;
1691         if(!*pActItem)
1692             *pActItem = new SvxBrushItem(nWhich);
1693         if(0 == aLbSelect.GetSelectEntryPos())  // Brush ausgewaehlt
1694 		{
1695             **pActItem = SvxBrushItem( aBgdColor, nWhich );
1696 		}
1697 		else
1698 		{
1699 				SvxGraphicPosition	eNewPos  = GetGraphicPosition_Impl();
1700 				const sal_Bool			bIsLink  = aBtnLink.IsChecked();
1701 
1702 				if ( !bIsLink && !bIsGraphicValid )
1703 					bIsGraphicValid = LoadLinkedGraphic_Impl();
1704 
1705 				if ( bIsLink )
1706 					**pActItem = SvxBrushItem( aBgdGraphicPath,
1707 												aBgdGraphicFilter,
1708 												eNewPos,
1709 												(*pActItem)->Which() );
1710 				else
1711 					**pActItem = SvxBrushItem( aBgdGraphic,
1712 												eNewPos,
1713 												(*pActItem)->Which() );
1714 		}
1715 		switch(nSelPos)
1716 		{
1717 			case TBL_DEST_CELL:
1718 				*pActItem = pTableBck_Impl->pCellBrush;
1719 				aLbSelect.Enable();
1720                 nWhich = pTableBck_Impl->nCellWhich;
1721             break;
1722 			case TBL_DEST_ROW:
1723 			{
1724 				if((nHtmlMode & HTMLMODE_ON) && !(nHtmlMode & HTMLMODE_SOME_STYLES))
1725 					aLbSelect.Disable();
1726 				*pActItem = pTableBck_Impl->pRowBrush;
1727                 nWhich = pTableBck_Impl->nRowWhich;
1728             }
1729 			break;
1730 			case TBL_DEST_TBL:
1731 				*pActItem = pTableBck_Impl->pTableBrush;
1732 				aLbSelect.Enable();
1733                 nWhich = pTableBck_Impl->nTableWhich;
1734             break;
1735 		}
1736 		String aUserData = GetUserData();
1737         if(!*pActItem)
1738             *pActItem = new SvxBrushItem(nWhich);
1739         FillControls_Impl(**pActItem, aUserData);
1740 		delete pActItem;
1741 	}
1742 	return 0;
1743 }
1744 
1745 //-----------------------------------------------------------------------
1746 
1747 IMPL_LINK( SvxBackgroundTabPage, ParaDestinationHdl_Impl, ListBox*, pBox )
1748 {
1749 	sal_uInt16 nSelPos = pBox->GetSelectEntryPos();
1750 	if( pParaBck_Impl && pParaBck_Impl->nActPos != nSelPos)
1751 	{
1752 		SvxBrushItem** pActItem = new (SvxBrushItem*);
1753 		switch(pParaBck_Impl->nActPos)
1754 		{
1755 			case PARA_DEST_PARA:
1756 				*pActItem = pParaBck_Impl->pParaBrush;
1757 			break;
1758 			case PARA_DEST_CHAR:
1759 				*pActItem = pParaBck_Impl->pCharBrush;
1760 			break;
1761 		}
1762 		pParaBck_Impl->nActPos = nSelPos;
1763 		if(0 == aLbSelect.GetSelectEntryPos())  // Brush ausgewaehlt
1764 		{
1765 			sal_uInt16 nWhich = (*pActItem)->Which();
1766             **pActItem = SvxBrushItem( aBgdColor, nWhich );
1767 		}
1768 		else
1769 		{
1770 				SvxGraphicPosition	eNewPos  = GetGraphicPosition_Impl();
1771 				const sal_Bool			bIsLink  = aBtnLink.IsChecked();
1772 
1773 				if ( !bIsLink && !bIsGraphicValid )
1774 					bIsGraphicValid = LoadLinkedGraphic_Impl();
1775 
1776 				if ( bIsLink )
1777 					**pActItem = SvxBrushItem( aBgdGraphicPath,
1778 												aBgdGraphicFilter,
1779 												eNewPos,
1780 												(*pActItem)->Which() );
1781 				else
1782 					**pActItem = SvxBrushItem( aBgdGraphic,
1783 												eNewPos,
1784 												(*pActItem)->Which() );
1785 		}
1786 		switch(nSelPos)
1787 		{
1788 			case PARA_DEST_PARA:
1789 				*pActItem = pParaBck_Impl->pParaBrush;
1790 				aLbSelect.Enable();
1791 			break;
1792 			case PARA_DEST_CHAR:
1793 			{
1794 				*pActItem = pParaBck_Impl->pCharBrush;
1795 				aLbSelect.Enable(sal_False);
1796 			}
1797 			break;
1798 		}
1799 		String aUserData = GetUserData();
1800 		FillControls_Impl(**pActItem, aUserData);
1801 		delete pActItem;
1802 	}
1803 	return 0;
1804 }
1805 
1806 //-----------------------------------------------------------------------
1807 
1808 void SvxBackgroundTabPage::FillControls_Impl( const SvxBrushItem& rBgdAttr,
1809 											  const String& rUserData )
1810 
1811 /*	[Beschreibung]
1812 
1813 */
1814 
1815 {
1816 	SvxGraphicPosition	ePos = rBgdAttr.GetGraphicPos();
1817 	const Color& rColor = rBgdAttr.GetColor();
1818     if(bColTransparency)
1819     {
1820         aColTransMF.SetValue(lcl_TransparencyToPercent(rColor.GetTransparency()));
1821         aColTransMF.SaveValue();
1822 		sal_Bool bEnableTransp = rColor.GetTransparency() < 0xff;
1823 		aColTransFT.Enable(bEnableTransp);
1824 		aColTransMF.Enable(bEnableTransp);
1825 		//the default setting should be "no transparency"
1826 		if(!bEnableTransp)
1827 			aColTransMF.SetValue(0);
1828     }
1829 
1830     if ( GPOS_NONE == ePos || !aLbSelect.IsVisible() )
1831 	{
1832 		aLbSelect.SelectEntryPos( 0 );
1833 		ShowColorUI_Impl();
1834 		Color aTrColor( COL_TRANSPARENT );
1835 		aBgdColor = rColor;
1836 
1837 		sal_uInt16 nCol = ( aTrColor != aBgdColor ) ?
1838 			GetItemId_Impl( aBackgroundColorSet, aBgdColor ) : 0;
1839 
1840 		if( aTrColor != aBgdColor && nCol == 0)
1841 		{
1842 			aBackgroundColorSet.SetNoSelection();
1843 		}
1844 		else
1845 		{
1846 			aBackgroundColorSet.SelectItem( nCol );
1847 		}
1848 
1849 		pPreviewWin1->NotifyChange( aBgdColor );
1850 		if ( aLbSelect.IsVisible() ) // Grafikteil initialisieren
1851 		{
1852 			aBgdGraphicFilter.Erase();
1853 			aBgdGraphicPath.Erase();
1854 
1855 			if ( !rUserData.Len() )
1856 				aBtnPreview.Check( sal_False );
1857 			aBtnLink.Check( sal_False );
1858 			aBtnLink.Disable();
1859 			pPreviewWin2->NotifyChange( NULL );
1860 			SetGraphicPosition_Impl( GPOS_TILED );	// Kacheln als Default
1861 		}
1862 	}
1863 	else
1864 	{
1865 		const String*	pStrLink   = rBgdAttr.GetGraphicLink();
1866 		const String*	pStrFilter = rBgdAttr.GetGraphicFilter();
1867 
1868 		aLbSelect.SelectEntryPos( 1 );
1869 		ShowBitmapUI_Impl();
1870 
1871 		if ( pStrLink )
1872 		{
1873 #ifdef DBG_UTIL
1874             INetURLObject aObj( *pStrLink );
1875             DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
1876 #endif
1877 			aBgdGraphicPath = *pStrLink;
1878 			aBtnLink.Check( sal_True );
1879 			aBtnLink.Enable();
1880 		}
1881 		else
1882 		{
1883 			aBgdGraphicPath.Erase();
1884 			aBtnLink.Check( sal_False );
1885 			aBtnLink.Disable();
1886 		}
1887 
1888         if(bGraphTransparency)
1889         {
1890             const GraphicObject* pObject = rBgdAttr.GetGraphicObject();
1891             if(pObject)
1892                 aGraphTransMF.SetValue(lcl_TransparencyToPercent(pObject->GetAttr().GetTransparency()));
1893             else
1894                 aGraphTransMF.SetValue(0);
1895             aGraphTransMF.SaveValue();
1896         }
1897 
1898         FileClickHdl_Impl( &aBtnLink );
1899 
1900 		if ( pStrFilter )
1901 			aBgdGraphicFilter = *pStrFilter;
1902 		else
1903 			aBgdGraphicFilter.Erase();
1904 
1905 		if ( !pStrLink || aBtnPreview.IsChecked() )
1906 		{
1907 			// Grafik ist im Item vorhanden und muss nicht
1908 			// geladen werden:
1909 
1910 			const Graphic* pGraphic = rBgdAttr.GetGraphic();
1911 
1912 			if ( !pGraphic && aBtnPreview.IsChecked() )
1913 				bIsGraphicValid = LoadLinkedGraphic_Impl();
1914 			else if ( pGraphic )
1915 			{
1916 				aBgdGraphic = *pGraphic;
1917 				bIsGraphicValid = sal_True;
1918 
1919 				if ( !rUserData.Len() )
1920 					aBtnPreview.Check();
1921 			}
1922 			else
1923 			{
1924 				RaiseLoadError_Impl();
1925 				bIsGraphicValid = sal_False;
1926 
1927 				if ( !rUserData.Len() )
1928 					aBtnPreview.Check( sal_False );
1929 			}
1930 		}
1931 
1932 		if ( aBtnPreview.IsChecked() && bIsGraphicValid )
1933 		{
1934 			Bitmap aBmp = aBgdGraphic.GetBitmap();
1935 			pPreviewWin2->NotifyChange( &aBmp );
1936 		}
1937 		else
1938 			pPreviewWin2->NotifyChange( NULL );
1939 
1940 		SetGraphicPosition_Impl( ePos );
1941 	}
1942 }
1943 /* -----------------------------09.08.2002 14:04------------------------------
1944 
1945  ---------------------------------------------------------------------------*/
1946 void SvxBackgroundTabPage::EnableTransparency(sal_Bool bColor, sal_Bool bGraphic)
1947 {
1948     bColTransparency  = bColor;
1949     bGraphTransparency = bGraphic;
1950     if(bColor)
1951     {
1952         aColTransFT.Show();
1953         aColTransMF.Show();
1954     }
1955     if(bGraphic)
1956     {
1957         Size aRectSize(aWndPosition.GetSizePixel());
1958         Point aRectPos(aWndPosition.GetPosPixel());
1959         Point aFLPos(aGraphTransFL.GetPosPixel());
1960         Size aTmp(LogicToPixel(Size(RSC_SP_FLGR_SPACE_Y, RSC_SP_FLGR_SPACE_Y), MAP_APPFONT));
1961         long nRectHeight = aFLPos.Y() - aRectPos.Y() - aTmp.Height();
1962         aRectSize.Height() = nRectHeight;
1963         aWndPosition.SetSizePixel(aRectSize);
1964         aWndPosition.Invalidate();
1965     }
1966 }
1967 
1968 void SvxBackgroundTabPage::PageCreated (SfxAllItemSet aSet) //add CHINA001
1969 {
1970 	SFX_ITEMSET_ARG (&aSet,pFlagItem,SfxUInt32Item,SID_FLAG_TYPE,sal_False);
1971 	if (pFlagItem)
1972 	{
1973 		sal_uInt32 nFlags=pFlagItem->GetValue();
1974 		if ( ( nFlags & SVX_SHOW_TBLCTL ) == SVX_SHOW_TBLCTL )
1975 			ShowTblControl();
1976 		if ( ( nFlags & SVX_SHOW_PARACTL ) == SVX_SHOW_PARACTL )
1977 			ShowParaControl();
1978 		if ( ( nFlags & SVX_SHOW_SELECTOR ) == SVX_SHOW_SELECTOR )
1979 			ShowSelector();
1980 		if ( ( nFlags & SVX_ENABLE_TRANSPARENCY ) == SVX_ENABLE_TRANSPARENCY )
1981 			EnableTransparency(sal_True, sal_True);
1982 	}
1983 }
1984