xref: /aoo42x/main/cui/source/tabpages/backgrnd.cxx (revision c7be74b1)
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 
SvxBackgroundTable_ImplSvxBackgroundTable_Impl89 	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 
SvxBackgroundPara_ImplSvxBackgroundPara_Impl101 	SvxBackgroundPara_Impl() :
102 		pParaBrush(NULL), pCharBrush(NULL) {}
103 };
104 
105 struct SvxBackgroundPage_Impl
106 {
107 	Timer*          pLoadTimer;
108 	sal_Bool            bIsImportDlgInExecute;
109 
SvxBackgroundPage_ImplSvxBackgroundPage_Impl110 	SvxBackgroundPage_Impl() :
111 		pLoadTimer(NULL), bIsImportDlgInExecute(sal_False) {}
112 };
113 /* -----------------------------15.08.2002 12:21------------------------------
114 
115  ---------------------------------------------------------------------------*/
lcl_PercentToTransparency(long nPercent)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 }
lcl_TransparencyToPercent(sal_uInt8 nTrans)121 inline sal_uInt8 lcl_TransparencyToPercent(sal_uInt8 nTrans)
122 {
123     return (nTrans * 100 + 127) / 254;
124 }
lcl_SetTransparency(SvxBrushItem & rBrush,long nTransparency)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 
GetItemId_Impl(ValueSet & rValueSet,const Color & rCol)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 
BackgroundPreviewImpl(Window * pParent,const ResId & rResId,sal_Bool bIsBmpPreview)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 
~BackgroundPreviewImpl()214 BackgroundPreviewImpl::~BackgroundPreviewImpl()
215 
216 /*	[Beschreibung]
217 
218 */
219 
220 {
221 	delete pBitmap;
222 }
223 
224 //-----------------------------------------------------------------------
NotifyChange(const Color & rColor)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 
NotifyChange(const Bitmap * pNewBitmap)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 
Paint(const Rectangle &)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  ---------------------------------------------------------------------------*/
DataChanged(const DataChangedEvent & rDCEvt)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 
SvxBackgroundTabPage(Window * pParent,const SfxItemSet & rCoreSet)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 
~SvxBackgroundTabPage()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 
GetRanges()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 
Create(Window * pParent,const SfxItemSet & rAttrSet)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 
Reset(const SfxItemSet & rSet)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 
ResetFromWallpaperItem(const SfxItemSet & rSet)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 
FillUserData()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 
FillItemSet(SfxItemSet & rCoreSet)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 
FillItemSetWithWallpaperItem(SfxItemSet & rCoreSet,sal_uInt16 nSlot)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 
DeactivatePage(SfxItemSet * _pSet)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 
PointChanged(Window *,RECT_POINT)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 
ShowSelector()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 
RaiseLoadError_Impl()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 
LoadLinkedGraphic_Impl()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 
FillColorValueSets_Impl()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 	XColorListSharedPtr aColorTable;
1201     long nColorCount(0);
1202 
1203 	if ( pDocSh && ( 0 != ( pItem = pDocSh->GetItem( SID_COLOR_TABLE ) ) ) )
1204     {
1205 		aColorTable = dynamic_cast< const SvxColorTableItem* >(pItem)->GetColorTable();
1206     }
1207 
1208 	if ( !aColorTable.get() )
1209 	{
1210 		aColorTable = XPropertyListFactory::CreateSharedXColorList(SvtPathOptions().GetPalettePath());
1211 	}
1212 
1213 	if ( aColorTable.get() )
1214 	{
1215         nColorCount = aColorTable->Count();
1216         aBackgroundColorSet.Clear();
1217         aBackgroundColorSet.addEntriesForXColorList(aColorTable);
1218     }
1219 
1220 	const WinBits nBits(aBackgroundColorSet.GetStyle() | WB_ITEMBORDER | WB_NAMEFIELD | WB_NONEFIELD);
1221 	aBackgroundColorSet.SetStyle(nBits);
1222     aBackgroundColorSet.SetColCount(aBackgroundColorSet.getColumnCount());
1223 
1224     // here we have enough space to the left, so layout with fixed column size
1225     // and fixed height, adapt width. Apply the adapted width by moving the left
1226     // edge of the control to the left, keeping the right edge aligned
1227     // with the original position
1228     const Point aCurrentPosContainer(aBorderWin.GetPosPixel());
1229     const Size aCurrentSizeContainer(aBorderWin.GetOutputSizePixel());
1230     const Size aCurrentSizeContent(aBackgroundColorSet.GetOutputSizePixel());
1231     const Size aNewSizeContent(aBackgroundColorSet.layoutToGivenHeight(aCurrentSizeContent.Height() - 4, nColorCount));
1232     static sal_Int32 nAdd = 4;
1233     const Size aNewSizeContainer(aNewSizeContent.Width() + nAdd, aNewSizeContent.Height() + nAdd);
1234     const Point aNewPos((aCurrentPosContainer.X() + aCurrentSizeContainer.Width()) - aNewSizeContainer.Width(), aCurrentPosContainer.Y());
1235 
1236     aBorderWin.SetOutputSizePixel(aNewSizeContainer);
1237     aBackgroundColorSet.SetOutputSizePixel(aNewSizeContent);
1238     aBackgroundColorSet.SetPosSizePixel(Point(nAdd/2, nAdd/2), aNewSizeContent);
1239     aBorderWin.SetPosSizePixel(aNewPos, aNewSizeContainer);
1240 }
1241 
1242 //------------------------------------------------------------------------
1243 
1244 
1245 
1246 //------------------------------------------------------------------------
1247 
ShowColorUI_Impl()1248 void SvxBackgroundTabPage::ShowColorUI_Impl()
1249 
1250 /*	[Beschreibung]
1251 
1252 	Die Controls f"ur das Einstellen der Grafik ausblenden und die
1253 	Controls f"ur die Farbeinstellung einblenden.
1254 */
1255 
1256 {
1257 	if( !aBackgroundColorSet.IsVisible() )
1258 	{
1259 		aBackgroundColorSet.Show();
1260 		aBackgroundColorBox.Show();
1261 		aBorderWin.Show();
1262 		pPreviewWin1->Show();
1263 		aBtnBrowse.Hide();
1264 		aFtFile.Hide();
1265 		aBtnLink.Hide();
1266 		aBtnPreview.Hide();
1267 		aGbFile.Hide();
1268 		aBtnPosition.Hide();
1269 		aBtnArea.Hide();
1270 		aBtnTile.Hide();
1271 		aWndPosition.Hide();
1272 		aGbPosition.Hide();
1273 		pPreviewWin2->Hide();
1274         aGraphTransFL.Show(sal_False);
1275         aGraphTransMF.Show(sal_False);
1276         if(bColTransparency)
1277 		{
1278 			aColTransFT.Show();
1279 			aColTransMF.Show();
1280 		}
1281     }
1282 }
1283 
1284 //------------------------------------------------------------------------
1285 
ShowBitmapUI_Impl()1286 void SvxBackgroundTabPage::ShowBitmapUI_Impl()
1287 
1288 /*	[Beschreibung]
1289 
1290 	Die Controls f"ur die Farbeinstellung ausblenden und die
1291 	Controls f"ur das Einstellen der Grafik einblenden.
1292 */
1293 
1294 {
1295 	if ( aLbSelect.IsVisible() &&
1296 		 (
1297 		aBackgroundColorSet.IsVisible()
1298 		 || !aBtnBrowse.IsVisible() ) )
1299 	{
1300 		aBackgroundColorSet.Hide();
1301 		aBackgroundColorBox.Hide();
1302 		aBorderWin.Hide();
1303 		pPreviewWin1->Hide();
1304 		aBtnBrowse.Show();
1305 		aFtFile.Show();
1306 
1307 		if ( !bLinkOnly && ! nHtmlMode & HTMLMODE_ON )
1308 			aBtnLink.Show();
1309 		aBtnPreview.Show();
1310 		aGbFile.Show();
1311 		aBtnPosition.Show();
1312 		aBtnArea.Show();
1313 		aBtnTile.Show();
1314 		aWndPosition.Show();
1315 		aGbPosition.Show();
1316 		pPreviewWin2->Show();
1317         if(bGraphTransparency)
1318 		{
1319 			aGraphTransFL.Show();
1320 			aGraphTransMF.Show();
1321 		}
1322         aColTransFT.Show(sal_False);
1323         aColTransMF.Show(sal_False);
1324     }
1325 }
1326 
1327 //------------------------------------------------------------------------
1328 
SetGraphicPosition_Impl(SvxGraphicPosition ePos)1329 void SvxBackgroundTabPage::SetGraphicPosition_Impl( SvxGraphicPosition ePos )
1330 
1331 /*	[Beschreibung]
1332 
1333 	Die Controls f"ur die Grafikposition einstellen.
1334 */
1335 
1336 {
1337 	switch ( ePos )
1338 	{
1339 		case GPOS_AREA:
1340 		{
1341 			aBtnArea.Check();
1342 			aWndPosition.Disable();
1343 		}
1344 		break;
1345 
1346 		case GPOS_TILED:
1347 		{
1348 			aBtnTile.Check();
1349 			aWndPosition.Disable();
1350 		}
1351 		break;
1352 
1353 		default:
1354 		{
1355 			aBtnPosition.Check();
1356 			aWndPosition.Enable();
1357 			RECT_POINT eNewPos = RP_MM;
1358 
1359 			switch ( ePos )
1360 			{
1361 				case GPOS_MM:	break;
1362 				case GPOS_LT:	eNewPos = RP_LT; break;
1363 				case GPOS_MT:	eNewPos = RP_MT; break;
1364 				case GPOS_RT:	eNewPos = RP_RT; break;
1365 				case GPOS_LM:	eNewPos = RP_LM; break;
1366 				case GPOS_RM:	eNewPos = RP_RM; break;
1367 				case GPOS_LB:	eNewPos = RP_LB; break;
1368 				case GPOS_MB:	eNewPos = RP_MB; break;
1369 				case GPOS_RB:	eNewPos = RP_RB; break;
1370                 default: ;//prevent warning
1371 			}
1372 			aWndPosition.SetActualRP( eNewPos );
1373 		}
1374 		break;
1375 	}
1376 	aWndPosition.Invalidate();
1377 }
1378 
1379 //------------------------------------------------------------------------
1380 
GetGraphicPosition_Impl()1381 SvxGraphicPosition SvxBackgroundTabPage::GetGraphicPosition_Impl()
1382 
1383 /*	[Beschreibung]
1384 
1385 	Die Position der Grafik zur"uckgeben.
1386 */
1387 
1388 {
1389 	if ( aBtnTile.IsChecked() )
1390 		return GPOS_TILED;
1391 	else if ( aBtnArea.IsChecked() )
1392 		return GPOS_AREA;
1393 	else
1394 	{
1395 		switch ( aWndPosition.GetActualRP() )
1396 		{
1397 			case RP_LT:	return GPOS_LT;
1398 			case RP_MT:	return GPOS_MT;
1399 			case RP_RT:	return GPOS_RT;
1400 			case RP_LM:	return GPOS_LM;
1401 			case RP_MM:	return GPOS_MM;
1402 			case RP_RM:	return GPOS_RM;
1403 			case RP_LB:	return GPOS_LB;
1404 			case RP_MB:	return GPOS_MB;
1405 			case RP_RB:	return GPOS_RB;
1406 		}
1407 	}
1408 	return GPOS_MM;
1409 }
1410 
1411 //-----------------------------------------------------------------------
1412 // Handler
1413 //-----------------------------------------------------------------------
1414 
IMPL_LINK(SvxBackgroundTabPage,BackgroundColorHdl_Impl,ValueSet *,EMPTYARG)1415 IMPL_LINK( SvxBackgroundTabPage, BackgroundColorHdl_Impl, ValueSet*, EMPTYARG )
1416 /*
1417     Handler, called when color selection is changed
1418 */
1419 {
1420 	sal_uInt16 nItemId = aBackgroundColorSet.GetSelectItemId();
1421 	Color aColor = nItemId ? ( aBackgroundColorSet.GetItemColor( nItemId ) ) : Color( COL_TRANSPARENT );
1422 	aBgdColor = aColor;
1423 	pPreviewWin1->NotifyChange( aBgdColor );
1424     sal_Bool bEnableTransp = aBgdColor.GetTransparency() < 0xff;
1425     aColTransFT.Enable(bEnableTransp);
1426     aColTransMF.Enable(bEnableTransp);
1427     return 0;
1428 }
1429 
1430 //------------------------------------------------------------------------
1431 
IMPL_LINK(SvxBackgroundTabPage,SelectHdl_Impl,ListBox *,EMPTYARG)1432 IMPL_LINK( SvxBackgroundTabPage, SelectHdl_Impl, ListBox*, EMPTYARG )
1433 
1434 /*	[Beschreibung]
1435 
1436 */
1437 
1438 {
1439 	if ( 0 == aLbSelect.GetSelectEntryPos() )
1440 	{
1441 		ShowColorUI_Impl();
1442 		aParaLBox.Enable(); // Zeichenhintergrund kann keine Bitmap sein
1443 	}
1444 	else
1445 	{
1446 		ShowBitmapUI_Impl();
1447 		aParaLBox.Enable(sal_False);// Zeichenhintergrund kann keine Bitmap sein
1448 	}
1449 	return 0;
1450 }
1451 
1452 //------------------------------------------------------------------------
1453 
IMPL_LINK(SvxBackgroundTabPage,FileClickHdl_Impl,CheckBox *,pBox)1454 IMPL_LINK( SvxBackgroundTabPage, FileClickHdl_Impl, CheckBox*, pBox )
1455 
1456 /*	[Beschreibung]
1457 
1458 */
1459 
1460 {
1461 	if ( &aBtnLink == pBox )
1462 	{
1463 		if ( aBtnLink.IsChecked() )
1464 		{
1465             INetURLObject aObj( aBgdGraphicPath );
1466 			String aFilePath;
1467 			if ( aObj.GetProtocol() == INET_PROT_FILE )
1468 				aFilePath = aObj.getFSysPath( INetURLObject::FSYS_DETECT );
1469 			else
1470 				aFilePath = aBgdGraphicPath;
1471 			aFtFile.SetText( aFilePath );
1472 		}
1473 		else
1474 			aFtFile.SetText( aStrUnlinked );
1475 	}
1476 	else if ( &aBtnPreview == pBox )
1477 	{
1478 		if ( aBtnPreview.IsChecked() )
1479 		{
1480 			if ( !bIsGraphicValid )
1481 				bIsGraphicValid = LoadLinkedGraphic_Impl();
1482 
1483 			if ( bIsGraphicValid )
1484 			{
1485 				Bitmap aBmp = aBgdGraphic.GetBitmap();
1486 				pPreviewWin2->NotifyChange( &aBmp );
1487 			}
1488 			else
1489 			{
1490 				if ( aBgdGraphicPath.Len() > 0 ) // nur bei gelinkter Grafik
1491 					RaiseLoadError_Impl();		 // ein Fehler
1492 				pPreviewWin2->NotifyChange( NULL );
1493 			}
1494 		}
1495 		else
1496 			pPreviewWin2->NotifyChange( NULL );
1497 	}
1498 	return 0;
1499 }
1500 
1501 //------------------------------------------------------------------------
1502 
IMPL_LINK(SvxBackgroundTabPage,RadioClickHdl_Impl,RadioButton *,pBtn)1503 IMPL_LINK( SvxBackgroundTabPage, RadioClickHdl_Impl, RadioButton*, pBtn )
1504 
1505 /*	[Beschreibung]
1506 
1507 */
1508 
1509 {
1510 	if ( pBtn == &aBtnPosition )
1511 	{
1512 		if ( !aWndPosition.IsEnabled() )
1513 		{
1514 			aWndPosition.Enable();
1515 			aWndPosition.Invalidate();
1516 		}
1517 	}
1518 	else if ( aWndPosition.IsEnabled() )
1519 	{
1520 		aWndPosition.Disable();
1521 		aWndPosition.Invalidate();
1522 	}
1523 	return 0;
1524 }
1525 
1526 //------------------------------------------------------------------------
1527 
IMPL_LINK(SvxBackgroundTabPage,BrowseHdl_Impl,PushButton *,EMPTYARG)1528 IMPL_LINK( SvxBackgroundTabPage, BrowseHdl_Impl, PushButton* , EMPTYARG )
1529 
1530 /*	[Beschreibung]
1531 
1532 	Handler, gerufen durch das Dr"ucken des Durchsuchen-Buttons.
1533 	Grafik/Einf"ugen-Dialog erzeugen, Pfad setzen und starten.
1534 */
1535 
1536 {
1537 	if ( pPageImpl->pLoadTimer->IsActive() )
1538 		return 0;
1539 	sal_Bool bHtml = 0 != ( nHtmlMode & HTMLMODE_ON );
1540 
1541 	pImportDlg = new SvxOpenGraphicDialog( aStrBrowse );
1542 	if ( bHtml || bLinkOnly )
1543 		pImportDlg->EnableLink(sal_False);
1544 	pImportDlg->SetPath( aBgdGraphicPath, aBtnLink.IsChecked() );
1545 
1546 	pPageImpl->bIsImportDlgInExecute = sal_True;
1547 	short nErr = pImportDlg->Execute();
1548 	pPageImpl->bIsImportDlgInExecute = sal_False;
1549 
1550 	if( !nErr )
1551 	{
1552 		if ( bHtml )
1553 			aBtnLink.Check();
1554 		// wenn Verkn"upfen nicht gecheckt ist und die Vorschau auch nicht,
1555 		// dann die Vorschau aktivieren, damit der Anwender sieht,
1556 		// welche Grafik er ausgew"ahlt hat
1557 		if ( !aBtnLink.IsChecked() && !aBtnPreview.IsChecked() )
1558 			aBtnPreview.Check( sal_True );
1559 		// timer-verz"ogertes Laden der Grafik
1560 		pPageImpl->pLoadTimer->Start();
1561 	}
1562 	else
1563 		DELETEZ( pImportDlg );
1564 	return 0;
1565 }
1566 
1567 //-----------------------------------------------------------------------
1568 
IMPL_LINK(SvxBackgroundTabPage,LoadTimerHdl_Impl,Timer *,pTimer)1569 IMPL_LINK( SvxBackgroundTabPage, LoadTimerHdl_Impl, Timer* , pTimer )
1570 
1571 /*	[Beschreibung]
1572 
1573 	Verz"ogertes Laden der Grafik.
1574 	Grafik wird nur dann geladen, wenn sie unterschiedlich zur
1575 	aktuellen Grafik ist.
1576 */
1577 
1578 {
1579 	if ( pTimer == pPageImpl->pLoadTimer )
1580 	{
1581 		pPageImpl->pLoadTimer->Stop();
1582 
1583 		if ( pImportDlg )
1584 		{
1585             INetURLObject aOld( aBgdGraphicPath );
1586 			INetURLObject aNew( pImportDlg->GetPath() );
1587 			if ( !aBgdGraphicPath.Len() || aNew != aOld )
1588 			{
1589 				// neue Datei gew"ahlt
1590 				aBgdGraphicPath   = pImportDlg->GetPath();
1591 				aBgdGraphicFilter =	pImportDlg->GetCurrentFilter();
1592 				sal_Bool bLink = ( nHtmlMode & HTMLMODE_ON ) || bLinkOnly ? sal_True : pImportDlg->IsAsLink();
1593 				aBtnLink.Check( bLink );
1594 				aBtnLink.Enable();
1595 
1596 				if ( aBtnPreview.IsChecked() )
1597 				{
1598 					if( !pImportDlg->GetGraphic(aBgdGraphic) )
1599 					{
1600 						bIsGraphicValid = sal_True;
1601 					}
1602 					else
1603 					{
1604 						aBgdGraphicFilter.Erase();
1605 						aBgdGraphicPath.Erase();
1606 						bIsGraphicValid = sal_False;
1607 					}
1608 				}
1609 				else
1610 					bIsGraphicValid = sal_False; // Grafik erst beim Preview-Click laden
1611 
1612 				if ( aBtnPreview.IsChecked() && bIsGraphicValid )
1613 				{
1614 					Bitmap aBmp = aBgdGraphic.GetBitmap();
1615 					pPreviewWin2->NotifyChange( &aBmp );
1616 				}
1617 				else
1618 					pPreviewWin2->NotifyChange( NULL );
1619 			}
1620 
1621 			FileClickHdl_Impl( &aBtnLink );
1622 			DELETEZ( pImportDlg );
1623 		}
1624 	}
1625 	return 0;
1626 }
1627 
1628 //-----------------------------------------------------------------------
1629 
ShowTblControl()1630 void SvxBackgroundTabPage::ShowTblControl()
1631 
1632 /*	[Beschreibung]
1633 
1634 */
1635 
1636 {
1637 	aTblLBox			.SetSelectHdl( HDL(TblDestinationHdl_Impl) );
1638 	aTblLBox			.SelectEntryPos(0);
1639 	aTblDesc.Show();
1640 	aTblLBox.Show();
1641 }
1642 
1643 //-----------------------------------------------------------------------
1644 
ShowParaControl(sal_Bool bCharOnly)1645 void SvxBackgroundTabPage::ShowParaControl(sal_Bool bCharOnly)
1646 {
1647 	aParaLBox.SetSelectHdl(HDL(ParaDestinationHdl_Impl));
1648 	aParaLBox.SelectEntryPos(0);
1649 	if(!bCharOnly)
1650 	{
1651 		aTblDesc.Show();
1652 		aParaLBox.Show();
1653 	}
1654 	aParaLBox.SetData(&aParaLBox); // hier erkennt man, dass dieser Mode eingeschaltet ist
1655 }
1656 //-----------------------------------------------------------------------
1657 
IMPL_LINK(SvxBackgroundTabPage,TblDestinationHdl_Impl,ListBox *,pBox)1658 IMPL_LINK( SvxBackgroundTabPage, TblDestinationHdl_Impl, ListBox*, pBox )
1659 
1660 /*	[Beschreibung]
1661 
1662 */
1663 
1664 {
1665 	sal_uInt16 nSelPos = pBox->GetSelectEntryPos();
1666 	if( pTableBck_Impl && pTableBck_Impl->nActPos != nSelPos)
1667 	{
1668 		SvxBrushItem** pActItem = new (SvxBrushItem*);
1669         sal_uInt16 nWhich = 0;
1670         switch(pTableBck_Impl->nActPos)
1671 		{
1672 			case TBL_DEST_CELL:
1673                 *pActItem = pTableBck_Impl->pCellBrush;
1674                 nWhich = pTableBck_Impl->nCellWhich;
1675 			break;
1676 			case TBL_DEST_ROW:
1677                 *pActItem = pTableBck_Impl->pRowBrush;
1678                 nWhich = pTableBck_Impl->nRowWhich;
1679 			break;
1680 			case TBL_DEST_TBL:
1681                 *pActItem = pTableBck_Impl->pTableBrush;
1682                 nWhich = pTableBck_Impl->nTableWhich;
1683 			break;
1684 		}
1685 		pTableBck_Impl->nActPos = nSelPos;
1686         if(!*pActItem)
1687             *pActItem = new SvxBrushItem(nWhich);
1688         if(0 == aLbSelect.GetSelectEntryPos())  // Brush ausgewaehlt
1689 		{
1690             **pActItem = SvxBrushItem( aBgdColor, nWhich );
1691 		}
1692 		else
1693 		{
1694 				SvxGraphicPosition	eNewPos  = GetGraphicPosition_Impl();
1695 				const sal_Bool			bIsLink  = aBtnLink.IsChecked();
1696 
1697 				if ( !bIsLink && !bIsGraphicValid )
1698 					bIsGraphicValid = LoadLinkedGraphic_Impl();
1699 
1700 				if ( bIsLink )
1701 					**pActItem = SvxBrushItem( aBgdGraphicPath,
1702 												aBgdGraphicFilter,
1703 												eNewPos,
1704 												(*pActItem)->Which() );
1705 				else
1706 					**pActItem = SvxBrushItem( aBgdGraphic,
1707 												eNewPos,
1708 												(*pActItem)->Which() );
1709 		}
1710 		switch(nSelPos)
1711 		{
1712 			case TBL_DEST_CELL:
1713 				*pActItem = pTableBck_Impl->pCellBrush;
1714 				aLbSelect.Enable();
1715                 nWhich = pTableBck_Impl->nCellWhich;
1716             break;
1717 			case TBL_DEST_ROW:
1718 			{
1719 				if((nHtmlMode & HTMLMODE_ON) && !(nHtmlMode & HTMLMODE_SOME_STYLES))
1720 					aLbSelect.Disable();
1721 				*pActItem = pTableBck_Impl->pRowBrush;
1722                 nWhich = pTableBck_Impl->nRowWhich;
1723             }
1724 			break;
1725 			case TBL_DEST_TBL:
1726 				*pActItem = pTableBck_Impl->pTableBrush;
1727 				aLbSelect.Enable();
1728                 nWhich = pTableBck_Impl->nTableWhich;
1729             break;
1730 		}
1731 		String aUserData = GetUserData();
1732         if(!*pActItem)
1733             *pActItem = new SvxBrushItem(nWhich);
1734         FillControls_Impl(**pActItem, aUserData);
1735 		delete pActItem;
1736 	}
1737 	return 0;
1738 }
1739 
1740 //-----------------------------------------------------------------------
1741 
IMPL_LINK(SvxBackgroundTabPage,ParaDestinationHdl_Impl,ListBox *,pBox)1742 IMPL_LINK( SvxBackgroundTabPage, ParaDestinationHdl_Impl, ListBox*, pBox )
1743 {
1744 	sal_uInt16 nSelPos = pBox->GetSelectEntryPos();
1745 	if( pParaBck_Impl && pParaBck_Impl->nActPos != nSelPos)
1746 	{
1747 		SvxBrushItem** pActItem = new (SvxBrushItem*);
1748 		switch(pParaBck_Impl->nActPos)
1749 		{
1750 			case PARA_DEST_PARA:
1751 				*pActItem = pParaBck_Impl->pParaBrush;
1752 			break;
1753 			case PARA_DEST_CHAR:
1754 				*pActItem = pParaBck_Impl->pCharBrush;
1755 			break;
1756 		}
1757 		pParaBck_Impl->nActPos = nSelPos;
1758 		if(0 == aLbSelect.GetSelectEntryPos())  // Brush ausgewaehlt
1759 		{
1760 			sal_uInt16 nWhich = (*pActItem)->Which();
1761             **pActItem = SvxBrushItem( aBgdColor, nWhich );
1762 		}
1763 		else
1764 		{
1765 				SvxGraphicPosition	eNewPos  = GetGraphicPosition_Impl();
1766 				const sal_Bool			bIsLink  = aBtnLink.IsChecked();
1767 
1768 				if ( !bIsLink && !bIsGraphicValid )
1769 					bIsGraphicValid = LoadLinkedGraphic_Impl();
1770 
1771 				if ( bIsLink )
1772 					**pActItem = SvxBrushItem( aBgdGraphicPath,
1773 												aBgdGraphicFilter,
1774 												eNewPos,
1775 												(*pActItem)->Which() );
1776 				else
1777 					**pActItem = SvxBrushItem( aBgdGraphic,
1778 												eNewPos,
1779 												(*pActItem)->Which() );
1780 		}
1781 		switch(nSelPos)
1782 		{
1783 			case PARA_DEST_PARA:
1784 				*pActItem = pParaBck_Impl->pParaBrush;
1785 				aLbSelect.Enable();
1786 			break;
1787 			case PARA_DEST_CHAR:
1788 			{
1789 				*pActItem = pParaBck_Impl->pCharBrush;
1790 				aLbSelect.Enable(sal_False);
1791 			}
1792 			break;
1793 		}
1794 		String aUserData = GetUserData();
1795 		FillControls_Impl(**pActItem, aUserData);
1796 		delete pActItem;
1797 	}
1798 	return 0;
1799 }
1800 
1801 //-----------------------------------------------------------------------
1802 
FillControls_Impl(const SvxBrushItem & rBgdAttr,const String & rUserData)1803 void SvxBackgroundTabPage::FillControls_Impl( const SvxBrushItem& rBgdAttr,
1804 											  const String& rUserData )
1805 
1806 /*	[Beschreibung]
1807 
1808 */
1809 
1810 {
1811 	SvxGraphicPosition	ePos = rBgdAttr.GetGraphicPos();
1812 	const Color& rColor = rBgdAttr.GetColor();
1813     if(bColTransparency)
1814     {
1815         aColTransMF.SetValue(lcl_TransparencyToPercent(rColor.GetTransparency()));
1816         aColTransMF.SaveValue();
1817 		sal_Bool bEnableTransp = rColor.GetTransparency() < 0xff;
1818 		aColTransFT.Enable(bEnableTransp);
1819 		aColTransMF.Enable(bEnableTransp);
1820 		//the default setting should be "no transparency"
1821 		if(!bEnableTransp)
1822 			aColTransMF.SetValue(0);
1823     }
1824 
1825     if ( GPOS_NONE == ePos || !aLbSelect.IsVisible() )
1826 	{
1827 		aLbSelect.SelectEntryPos( 0 );
1828 		ShowColorUI_Impl();
1829 		Color aTrColor( COL_TRANSPARENT );
1830 		aBgdColor = rColor;
1831 
1832 		sal_uInt16 nCol = ( aTrColor != aBgdColor ) ?
1833 			GetItemId_Impl( aBackgroundColorSet, aBgdColor ) : 0;
1834 
1835 		if( aTrColor != aBgdColor && nCol == 0)
1836 		{
1837 			aBackgroundColorSet.SetNoSelection();
1838 		}
1839 		else
1840 		{
1841 			aBackgroundColorSet.SelectItem( nCol );
1842 		}
1843 
1844 		pPreviewWin1->NotifyChange( aBgdColor );
1845 		if ( aLbSelect.IsVisible() ) // Grafikteil initialisieren
1846 		{
1847 			aBgdGraphicFilter.Erase();
1848 			aBgdGraphicPath.Erase();
1849 
1850 			if ( !rUserData.Len() )
1851 				aBtnPreview.Check( sal_False );
1852 			aBtnLink.Check( sal_False );
1853 			aBtnLink.Disable();
1854 			pPreviewWin2->NotifyChange( NULL );
1855 			SetGraphicPosition_Impl( GPOS_TILED );	// Kacheln als Default
1856 		}
1857 	}
1858 	else
1859 	{
1860 		const String*	pStrLink   = rBgdAttr.GetGraphicLink();
1861 		const String*	pStrFilter = rBgdAttr.GetGraphicFilter();
1862 
1863 		aLbSelect.SelectEntryPos( 1 );
1864 		ShowBitmapUI_Impl();
1865 
1866 		if ( pStrLink )
1867 		{
1868 #ifdef DBG_UTIL
1869             INetURLObject aObj( *pStrLink );
1870             DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
1871 #endif
1872 			aBgdGraphicPath = *pStrLink;
1873 			aBtnLink.Check( sal_True );
1874 			aBtnLink.Enable();
1875 		}
1876 		else
1877 		{
1878 			aBgdGraphicPath.Erase();
1879 			aBtnLink.Check( sal_False );
1880 			aBtnLink.Disable();
1881 		}
1882 
1883         if(bGraphTransparency)
1884         {
1885             const GraphicObject* pObject = rBgdAttr.GetGraphicObject();
1886             if(pObject)
1887                 aGraphTransMF.SetValue(lcl_TransparencyToPercent(pObject->GetAttr().GetTransparency()));
1888             else
1889                 aGraphTransMF.SetValue(0);
1890             aGraphTransMF.SaveValue();
1891         }
1892 
1893         FileClickHdl_Impl( &aBtnLink );
1894 
1895 		if ( pStrFilter )
1896 			aBgdGraphicFilter = *pStrFilter;
1897 		else
1898 			aBgdGraphicFilter.Erase();
1899 
1900 		if ( !pStrLink || aBtnPreview.IsChecked() )
1901 		{
1902 			// Grafik ist im Item vorhanden und muss nicht
1903 			// geladen werden:
1904 
1905 			const Graphic* pGraphic = rBgdAttr.GetGraphic();
1906 
1907 			if ( !pGraphic && aBtnPreview.IsChecked() )
1908 				bIsGraphicValid = LoadLinkedGraphic_Impl();
1909 			else if ( pGraphic )
1910 			{
1911 				aBgdGraphic = *pGraphic;
1912 				bIsGraphicValid = sal_True;
1913 
1914 				if ( !rUserData.Len() )
1915 					aBtnPreview.Check();
1916 			}
1917 			else
1918 			{
1919 				RaiseLoadError_Impl();
1920 				bIsGraphicValid = sal_False;
1921 
1922 				if ( !rUserData.Len() )
1923 					aBtnPreview.Check( sal_False );
1924 			}
1925 		}
1926 
1927 		if ( aBtnPreview.IsChecked() && bIsGraphicValid )
1928 		{
1929 			Bitmap aBmp = aBgdGraphic.GetBitmap();
1930 			pPreviewWin2->NotifyChange( &aBmp );
1931 		}
1932 		else
1933 			pPreviewWin2->NotifyChange( NULL );
1934 
1935 		SetGraphicPosition_Impl( ePos );
1936 	}
1937 }
1938 /* -----------------------------09.08.2002 14:04------------------------------
1939 
1940  ---------------------------------------------------------------------------*/
EnableTransparency(sal_Bool bColor,sal_Bool bGraphic)1941 void SvxBackgroundTabPage::EnableTransparency(sal_Bool bColor, sal_Bool bGraphic)
1942 {
1943     bColTransparency  = bColor;
1944     bGraphTransparency = bGraphic;
1945     if(bColor)
1946     {
1947         aColTransFT.Show();
1948         aColTransMF.Show();
1949     }
1950     if(bGraphic)
1951     {
1952         Size aRectSize(aWndPosition.GetSizePixel());
1953         Point aRectPos(aWndPosition.GetPosPixel());
1954         Point aFLPos(aGraphTransFL.GetPosPixel());
1955         Size aTmp(LogicToPixel(Size(RSC_SP_FLGR_SPACE_Y, RSC_SP_FLGR_SPACE_Y), MAP_APPFONT));
1956         long nRectHeight = aFLPos.Y() - aRectPos.Y() - aTmp.Height();
1957         aRectSize.Height() = nRectHeight;
1958         aWndPosition.SetSizePixel(aRectSize);
1959         aWndPosition.Invalidate();
1960     }
1961 }
1962 
PageCreated(SfxAllItemSet aSet)1963 void SvxBackgroundTabPage::PageCreated (SfxAllItemSet aSet) //add CHINA001
1964 {
1965 	SFX_ITEMSET_ARG (&aSet,pFlagItem,SfxUInt32Item,SID_FLAG_TYPE,sal_False);
1966 	if (pFlagItem)
1967 	{
1968 		sal_uInt32 nFlags=pFlagItem->GetValue();
1969 		if ( ( nFlags & SVX_SHOW_TBLCTL ) == SVX_SHOW_TBLCTL )
1970 			ShowTblControl();
1971 		if ( ( nFlags & SVX_SHOW_PARACTL ) == SVX_SHOW_PARACTL )
1972 			ShowParaControl();
1973 		if ( ( nFlags & SVX_SHOW_SELECTOR ) == SVX_SHOW_SELECTOR )
1974 			ShowSelector();
1975 		if ( ( nFlags & SVX_ENABLE_TRANSPARENCY ) == SVX_ENABLE_TRANSPARENCY )
1976 			EnableTransparency(sal_True, sal_True);
1977 	}
1978 }
1979