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