xref: /aoo42x/main/svx/source/tbxctrls/fillctrl.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_svx.hxx"
26 
27 // include ---------------------------------------------------------------
28 
29 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
30 #include <sfx2/app.hxx>
31 #include <sfx2/dispatch.hxx>
32 #include <sfx2/objsh.hxx>
33 #include <sfx2/viewsh.hxx>
34 #include <rtl/ustring.hxx>
35 
36 #include <svx/dialogs.hrc>
37 
38 #define DELAY_TIMEOUT			300
39 
40 #define TMP_STR_BEGIN	'['
41 #define TMP_STR_END		']'
42 
43 #include "svx/drawitem.hxx"
44 #include "svx/xattr.hxx"
45 #include <svx/xtable.hxx>
46 #include <svx/fillctrl.hxx>
47 #include <svx/itemwin.hxx>
48 #include <svx/dialmgr.hxx>
49 #include "helpid.hrc"
50 
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::util;
53 using namespace ::com::sun::star::beans;
54 using namespace ::com::sun::star::frame;
55 using namespace ::com::sun::star::lang;
56 
57 SFX_IMPL_TOOLBOX_CONTROL( SvxFillToolBoxControl, XFillStyleItem );
58 
59 /*************************************************************************
60 |*
61 |* SvxFillToolBoxControl
62 |*
63 \************************************************************************/
64 
65 SvxFillToolBoxControl::SvxFillToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
66 	SfxToolBoxControl( nSlotId, nId, rTbx ),
67 
68 	pStyleItem		( NULL ),
69 	pColorItem		( NULL ),
70 	pGradientItem	( NULL ),
71 	pHatchItem		( NULL ),
72 	pBitmapItem		( NULL ),
73 	pFillControl	( NULL ),
74 	pFillTypeLB		( NULL ),
75 	pFillAttrLB		( NULL ),
76 	bUpdate			( sal_False ),
77     bIgnoreStatusUpdate( sal_False ),
78     eLastXFS        ( XFILL_NONE )
79 {
80     addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FillColor" )));
81     addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FillGradient" )));
82     addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FillHatch" )));
83     addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FillBitmap" )));
84     addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ColorTableState" )));
85     addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GradientListState" )));
86     addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:HatchListState" )));
87     addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:BitmapListState" )));
88 }
89 
90 //========================================================================
91 
92 SvxFillToolBoxControl::~SvxFillToolBoxControl()
93 {
94 	delete pStyleItem;
95 	delete pColorItem;
96 	delete pGradientItem;
97 	delete pHatchItem;
98 	delete pBitmapItem;
99 }
100 
101 //========================================================================
102 
103 void SvxFillToolBoxControl::StateChanged(
104 
105 	sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
106 
107 {
108 	bool bEnableControls = sal_False;
109 
110     if ( bIgnoreStatusUpdate )
111         return;
112 
113 	if( eState == SFX_ITEM_DISABLED )
114 	{
115 		if( nSID == SID_ATTR_FILL_STYLE )
116 		{
117 			pFillTypeLB->Disable();
118 			pFillTypeLB->SetNoSelection();
119 		}
120 		pFillAttrLB->Disable();
121 		pFillAttrLB->SetNoSelection();
122 	}
123 	else
124 	{
125 		if ( SFX_ITEM_AVAILABLE == eState )
126 		{
127 			if( nSID == SID_ATTR_FILL_STYLE )
128 			{
129 				delete pStyleItem;
130 				pStyleItem = (XFillStyleItem*) pState->Clone();
131 				pFillTypeLB->Enable();
132 			}
133 			else if( pStyleItem )
134 			{
135 				XFillStyle eXFS = (XFillStyle)pStyleItem->GetValue();
136 
137 				if( nSID == SID_ATTR_FILL_COLOR )
138 				{
139 					delete pColorItem;
140 					pColorItem = (XFillColorItem*) pState->Clone();
141 
142 					if( eXFS == XFILL_SOLID )
143 						bEnableControls = sal_True;
144 				}
145 				else if( nSID == SID_ATTR_FILL_GRADIENT )
146 				{
147 					delete pGradientItem;
148 					pGradientItem = (XFillGradientItem*) pState->Clone();
149 
150 					if( eXFS == XFILL_GRADIENT )
151 						bEnableControls = sal_True;
152 				}
153 				else if( nSID == SID_ATTR_FILL_HATCH )
154 				{
155 					delete pHatchItem;
156 					pHatchItem = (XFillHatchItem*) pState->Clone();
157 
158 					if( eXFS == XFILL_HATCH )
159 						bEnableControls = sal_True;
160 				}
161 				else if( nSID == SID_ATTR_FILL_BITMAP )
162 				{
163 					delete pBitmapItem;
164 					pBitmapItem = (XFillBitmapItem*) pState->Clone();
165 
166 					if( eXFS == XFILL_BITMAP )
167 						bEnableControls = sal_True;
168 				}
169 			}
170 
171             if( pStyleItem )
172             {
173                 // ensure that the correct entry is selected in pFillTypeLB. It
174                 // might have been changed by nSID == SID_ATTR_FILL_STYLE, but
175                 // it might also be in an in-between state when user had started to
176                 // change fillstyle, but not yet changed fillvalue for new style
177                 // and when nSID == SID_ATTR_FILL_COLOR/SID_ATTR_FILL_GRADIENT/
178                 // SID_ATTR_FILL_HATCH/SID_ATTR_FILL_BITMAP value change is triggered
179                 eLastXFS = pFillTypeLB->GetSelectEntryPos();
180                 XFillStyle eXFS = (XFillStyle)pStyleItem->GetValue();
181 
182                 if(eLastXFS != eXFS)
183                 {
184                     bUpdate = sal_True;
185                     pFillTypeLB->SelectEntryPos( sal::static_int_cast< sal_uInt16 >( eXFS ) );
186                 }
187 
188                 pFillAttrLB->Enable();
189             }
190 
191             if( bEnableControls )
192 			{
193 				//pFillTypeLB->Enable();
194 				pFillAttrLB->Enable();
195 
196 				bUpdate = sal_True;
197 			}
198 
199             Update( pState );
200         }
201 		else
202 		{
203 			// leerer oder uneindeutiger Status
204 			if( nSID == SID_ATTR_FILL_STYLE )
205 			{
206 				pFillTypeLB->SetNoSelection();
207 				pFillAttrLB->Disable();
208 				pFillAttrLB->SetNoSelection();
209 				bUpdate = sal_False;
210 			}
211 			else
212 			{
213 				XFillStyle eXFS = XFILL_NONE;
214 				if( pStyleItem )
215 					eXFS = (XFillStyle)pStyleItem->GetValue();
216 				if( !pStyleItem ||
217 					( nSID == SID_ATTR_FILL_COLOR	 && eXFS == XFILL_SOLID ) ||
218 					( nSID == SID_ATTR_FILL_GRADIENT && eXFS == XFILL_GRADIENT ) ||
219 					( nSID == SID_ATTR_FILL_HATCH 	 && eXFS == XFILL_HATCH ) ||
220 					( nSID == SID_ATTR_FILL_BITMAP 	 && eXFS == XFILL_BITMAP ) )
221 				{
222 					pFillAttrLB->SetNoSelection();
223 					//bUpdate = sal_False;
224 				}
225 			}
226 		}
227 	}
228 }
229 
230 //========================================================================
231 
232 void SvxFillToolBoxControl::IgnoreStatusUpdate( sal_Bool bSet )
233 {
234     bIgnoreStatusUpdate = bSet;
235 }
236 
237 //========================================================================
238 
239 void SvxFillToolBoxControl::Update( const SfxPoolItem* pState )
240 {
241 	if ( pStyleItem && pState && bUpdate )
242 	{
243 		bUpdate = sal_False;
244 
245 		XFillStyle eXFS = (XFillStyle)pStyleItem->GetValue();
246 
247 		// Pruefen, ob Fuellstil schon vorher aktiv war
248 		//if( eTmpXFS != eXFS )
249 		if( (XFillStyle) eLastXFS != eXFS )
250 			pFillControl->SelectFillTypeHdl( NULL );
251 			//eLastXFS = eXFS;
252 
253 		switch( eXFS )
254 		{
255 			case XFILL_NONE:
256 			break;
257 
258 			case XFILL_SOLID:
259 			{
260 				if ( pColorItem )
261 				{
262 					String aString( pColorItem->GetName() );
263                     ::Color aColor = pColorItem->GetColorValue();
264 
265 					pFillAttrLB->SelectEntry( aString );
266 
267 					if ( pFillAttrLB->GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND ||
268 						 pFillAttrLB->GetSelectEntryColor() != aColor )
269 						pFillAttrLB->SelectEntry( aColor );
270 
271 					// NEU
272 					// Pruefen, ob Eintrag nicht in der Liste ist
273 					if( pFillAttrLB->GetSelectEntryPos() ==
274 						LISTBOX_ENTRY_NOTFOUND ||
275 						pFillAttrLB->GetSelectEntryColor() != aColor )
276 					{
277 						sal_uInt16 nCount = pFillAttrLB->GetEntryCount();
278 						String aTmpStr;
279 						if( nCount > 0 )
280 						{
281 							//Letzter Eintrag wird auf temporaere Farbe geprueft
282 							aTmpStr = pFillAttrLB->GetEntry( nCount - 1 );
283 							if(  aTmpStr.GetChar(0) == TMP_STR_BEGIN &&
284 								 aTmpStr.GetChar(aTmpStr.Len()-1) == TMP_STR_END )
285 							{
286 								pFillAttrLB->RemoveEntry( nCount - 1 );
287 							}
288 						}
289 						aTmpStr = TMP_STR_BEGIN;
290 						aTmpStr += aString;
291 						aTmpStr += TMP_STR_END;
292 
293 						//pFillAttrLB->SetUpdateMode( sal_False );
294 						sal_uInt16 nPos = pFillAttrLB->InsertEntry( aColor, aTmpStr );
295 						//pFillAttrLB->SetUpdateMode( sal_True );
296 						pFillAttrLB->SelectEntryPos( nPos );
297 					}
298 					// NEU
299 				}
300 				else
301 					pFillAttrLB->SetNoSelection();
302 			}
303 			break;
304 
305 			case XFILL_GRADIENT:
306 			{
307 				if ( pGradientItem )
308 				{
309 					String aString( pGradientItem->GetName() );
310 					pFillAttrLB->SelectEntry( aString );
311 					// NEU
312 					// Pruefen, ob Eintrag nicht in der Liste ist
313 					if( pFillAttrLB->GetSelectEntry() != aString )
314 					{
315 						sal_uInt16 nCount = pFillAttrLB->GetEntryCount();
316 						String aTmpStr;
317 						if( nCount > 0 )
318 						{
319 							//Letzter Eintrag wird auf temporaeren Eintrag geprueft
320 							aTmpStr = pFillAttrLB->GetEntry( nCount - 1 );
321 							if(  aTmpStr.GetChar(0) == TMP_STR_BEGIN &&
322 								 aTmpStr.GetChar(aTmpStr.Len()-1) == TMP_STR_END )
323 							{
324 								pFillAttrLB->RemoveEntry( nCount - 1 );
325 							}
326 						}
327 						aTmpStr = TMP_STR_BEGIN;
328 						aTmpStr += aString;
329 						aTmpStr += TMP_STR_END;
330 
331 						XGradientEntry* pEntry = new XGradientEntry( pGradientItem->GetGradientValue(), aTmpStr );
332                         XGradientListSharedPtr aGradientList(XPropertyListFactory::CreateSharedXGradientList(String::CreateFromAscii("TmpList")));
333 
334                         aGradientList->Insert(pEntry);
335 						aGradientList->SetDirty(false);
336 						const Bitmap aBmp = aGradientList->GetUiBitmap( 0 );
337 
338 						if( !aBmp.IsEmpty() )
339 						{
340 							( (ListBox*)pFillAttrLB )->InsertEntry( pEntry->GetName(), aBmp );
341 							pFillAttrLB->SelectEntryPos( pFillAttrLB->GetEntryCount() - 1 );
342 						}
343 					}
344 					// NEU
345 				}
346 				else
347 					pFillAttrLB->SetNoSelection();
348 			}
349 			break;
350 
351 			case XFILL_HATCH:
352 			{
353 				if ( pHatchItem )
354 				{
355 					String aString( pHatchItem->GetName() );
356 					pFillAttrLB->SelectEntry( aString );
357 					// NEU
358 					// Pruefen, ob Eintrag nicht in der Liste ist
359 					if( pFillAttrLB->GetSelectEntry() != aString )
360 					{
361 						sal_uInt16 nCount = pFillAttrLB->GetEntryCount();
362 						String aTmpStr;
363 						if( nCount > 0 )
364 						{
365 							//Letzter Eintrag wird auf temporaeren Eintrag geprueft
366 							aTmpStr = pFillAttrLB->GetEntry( nCount - 1 );
367 							if(  aTmpStr.GetChar(0) == TMP_STR_BEGIN &&
368 								 aTmpStr.GetChar(aTmpStr.Len()-1) == TMP_STR_END )
369 							{
370 								pFillAttrLB->RemoveEntry( nCount - 1 );
371 							}
372 						}
373 						aTmpStr = TMP_STR_BEGIN;
374 						aTmpStr += aString;
375 						aTmpStr += TMP_STR_END;
376 
377 						XHatchEntry* pEntry = new XHatchEntry( pHatchItem->GetHatchValue(), aTmpStr );
378 						XHatchListSharedPtr aHatchList(XPropertyListFactory::CreateSharedXHatchList(String::CreateFromAscii("TmpList")));
379 
380 						aHatchList->Insert( pEntry );
381 						aHatchList->SetDirty( sal_False );
382 						const Bitmap aBmp = aHatchList->GetUiBitmap( 0 );
383 
384 						if( !aBmp.IsEmpty() )
385 						{
386 							( (ListBox*)pFillAttrLB )->InsertEntry( pEntry->GetName(), aBmp );
387 							pFillAttrLB->SelectEntryPos( pFillAttrLB->GetEntryCount() - 1 );
388 						}
389 					}
390 					// NEU
391 				}
392 				else
393 					pFillAttrLB->SetNoSelection();
394 			}
395 			break;
396 
397 			case XFILL_BITMAP:
398 			{
399 				if ( pBitmapItem )
400 					// &&
401 					// SfxObjectShell::Current() 	&&
402 					// SfxObjectShell::Current()->GetItem( SID_BITMAP_LIST ) )
403 				{
404 					String aString( pBitmapItem->GetName() );
405 					// Bitmap aBitmap( pBitmapItem->GetValue() );
406 
407 					// SvxBitmapListItem aItem( *(const SvxBitmapListItem*)(
408 					// 	SfxObjectShell::Current()->GetItem( SID_BITMAP_LIST ) ) );
409 					pFillAttrLB->SelectEntry( aString );
410 					// NEU
411 					// Pruefen, ob Eintrag nicht in der Liste ist
412 					if( pFillAttrLB->GetSelectEntry() != aString )
413 					{
414 						sal_uInt16 nCount = pFillAttrLB->GetEntryCount();
415 						String aTmpStr;
416 						if( nCount > 0 )
417 						{
418 							//Letzter Eintrag wird auf temporaeren Eintrag geprueft
419 							aTmpStr = pFillAttrLB->GetEntry( nCount - 1 );
420 							if(  aTmpStr.GetChar(0) == TMP_STR_BEGIN &&
421 								 aTmpStr.GetChar(aTmpStr.Len()-1) == TMP_STR_END )
422 							{
423 								pFillAttrLB->RemoveEntry( nCount - 1 );
424 							}
425 						}
426 						aTmpStr = TMP_STR_BEGIN;
427 						aTmpStr += aString;
428 						aTmpStr += TMP_STR_END;
429 
430                         XBitmapListSharedPtr aNew(XPropertyListFactory::CreateSharedXBitmapList(String::CreateFromAscii("TmpList")));
431                         aNew->Insert(new XBitmapEntry(pBitmapItem->GetGraphicObject(), aTmpStr));
432                         aNew->SetDirty(false);
433 
434                         pFillAttrLB->Fill( aNew );
435                         pFillAttrLB->SelectEntryPos( pFillAttrLB->GetEntryCount() - 1 );
436 					}
437 					// NEU
438 				}
439 				else
440 					pFillAttrLB->SetNoSelection();
441 			}
442 			break;
443 
444 			default:
445 				DBG_ERROR( "Nicht unterstuetzter Flaechentyp" );
446 			break;
447 		}
448 	}
449 
450 	if( pState && pStyleItem )
451 	{
452 		XFillStyle eXFS = (XFillStyle) pStyleItem->GetValue();
453 
454 		// Die Listen haben sich geaendert ?
455 		if( pState->ISA( SvxColorTableItem ) &&
456 			eXFS == XFILL_SOLID )
457 		{
458 			::Color aTmpColor( pFillAttrLB->GetSelectEntryColor() );
459 			pFillAttrLB->Clear();
460 			pFillAttrLB->Fill( ( (SvxColorTableItem*)pState )->GetColorTable() );
461 			pFillAttrLB->SelectEntry( aTmpColor );
462 		}
463 		if( pState->ISA( SvxGradientListItem ) &&
464 			eXFS == XFILL_GRADIENT )
465 		{
466 			String aString( pFillAttrLB->GetSelectEntry() );
467 			pFillAttrLB->Clear();
468 			pFillAttrLB->Fill( ( (SvxGradientListItem*)pState )->GetGradientList() );
469 			pFillAttrLB->SelectEntry( aString );
470 		}
471 		if( pState->ISA( SvxHatchListItem ) &&
472 			eXFS == XFILL_HATCH )
473 		{
474 			String aString( pFillAttrLB->GetSelectEntry() );
475 			pFillAttrLB->Clear();
476 			pFillAttrLB->Fill( ( (SvxHatchListItem*)pState )->GetHatchList() );
477 			pFillAttrLB->SelectEntry( aString );
478 		}
479 		if( pState->ISA( SvxBitmapListItem ) &&
480 			eXFS == XFILL_BITMAP )
481 		{
482 			String aString( pFillAttrLB->GetSelectEntry() );
483 			pFillAttrLB->Clear();
484 			pFillAttrLB->Fill( ( (SvxBitmapListItem*)pState )->GetBitmapList() );
485 			pFillAttrLB->SelectEntry( aString );
486 		}
487 	}
488 }
489 
490 //========================================================================
491 
492 Window* SvxFillToolBoxControl::CreateItemWindow( Window *pParent )
493 {
494 	if ( GetSlotId() == SID_ATTR_FILL_STYLE )
495 	{
496 		pFillControl = new FillControl( pParent );
497 		// Damit dem FillControl das SvxFillToolBoxControl bekannt ist
498 		// (und um kompatibel zu bleiben)
499 		pFillControl->SetData( this );
500 
501 		pFillAttrLB = (SvxFillAttrBox*)pFillControl->pLbFillAttr;
502 		pFillTypeLB = (SvxFillTypeBox*)pFillControl->pLbFillType;
503 
504 		pFillAttrLB->SetUniqueId( HID_FILL_ATTR_LISTBOX );
505 		pFillTypeLB->SetUniqueId( HID_FILL_TYPE_LISTBOX );
506 
507 		return pFillControl;
508 	}
509 	return NULL;
510 }
511 
512 /*************************************************************************
513 |*
514 |* FillControl
515 |*
516 \************************************************************************/
517 
518 FillControl::FillControl( Window* pParent, WinBits nStyle ) :
519     Window( pParent, nStyle | WB_DIALOGCONTROL ),
520     pLbFillType(new SvxFillTypeBox( this )),
521     aLogicalFillSize(40,80),
522     aLogicalAttrSize(50,80)
523 {
524     pLbFillAttr = new SvxFillAttrBox( this );
525     Size aTypeSize(LogicToPixel(aLogicalFillSize, MAP_APPFONT));
526     Size aAttrSize(LogicToPixel(aLogicalAttrSize, MAP_APPFONT));
527     pLbFillType->SetSizePixel(aTypeSize);
528     pLbFillAttr->SetSizePixel(aAttrSize);
529     //to get the base height
530     aTypeSize = pLbFillType->GetSizePixel();
531     aAttrSize = pLbFillAttr->GetSizePixel();
532     Point aAttrPnt = pLbFillAttr->GetPosPixel();
533 	SetSizePixel(
534 		Size( aAttrPnt.X() + aAttrSize.Width(),
535 			  Max( aAttrSize.Height(), aTypeSize.Height() ) ) );
536 
537 	pLbFillType->SetSelectHdl( LINK( this, FillControl, SelectFillTypeHdl ) );
538 	pLbFillAttr->SetSelectHdl( LINK( this, FillControl, SelectFillAttrHdl ) );
539 
540 	aDelayTimer.SetTimeout( DELAY_TIMEOUT );
541 	aDelayTimer.SetTimeoutHdl( LINK( this, FillControl, DelayHdl ) );
542 	aDelayTimer.Start();
543 }
544 
545 //------------------------------------------------------------------------
546 
547 FillControl::~FillControl()
548 {
549 	delete pLbFillType;
550 	delete pLbFillAttr;
551 }
552 
553 //------------------------------------------------------------------------
554 
555 IMPL_LINK_INLINE_START( FillControl, DelayHdl, Timer *, EMPTYARG )
556 {
557 	SelectFillTypeHdl( NULL );
558     ( (SvxFillToolBoxControl*)GetData() )->updateStatus( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FillStyle" )));
559 //	( (SvxFillToolBoxControl*)GetData() )->GetBindings().Invalidate( SID_ATTR_FILL_STYLE );
560 	return 0;
561 }
562 IMPL_LINK_INLINE_END( FillControl, DelayHdl, Timer *, pTimer )
563 
564 //------------------------------------------------------------------------
565 
566 IMPL_LINK( FillControl, SelectFillTypeHdl, ListBox *, pBox )
567 {
568 	XFillStyle  eXFS = (XFillStyle)pLbFillType->GetSelectEntryPos();
569 
570 	// Spaeter sollte eine Optimierung derart erfolgen, dass die
571 	// Listen, bzw. Tables nur dann geloescht und wieder aufgebaut
572 	// werden, wenn sich die Listen, bzw. Tables tatsaechlich geaendert
573 	// haben (in den LBs natuerlich).
574 
575 	if ( ( pBox && !pBox->IsTravelSelect() ) || !pBox )
576 	{
577 		// Damit wir in folgendem Fall einen Status anzeigen koennen:
578 		// Ein Typ wurde ausgewaehlt aber kein Attribut.
579 		// Die Selektion hat genau die gleichen Attribute wie die vorherige.
580 //		SvxFillToolBoxControl* pControlerItem = (SvxFillToolBoxControl*)GetData();
581 //		if( pControlerItem )
582 //			pControlerItem->ClearCache();
583 
584 		pLbFillAttr->Clear();
585 		SfxObjectShell* pSh = SfxObjectShell::Current();
586 
587 		switch( eXFS )
588 		{
589 			case XFILL_NONE:
590 			{
591 				pLbFillType->Selected();
592 				SelectFillAttrHdl( pBox );
593 				pLbFillAttr->Disable();
594 			}
595 			break;
596 
597 			case XFILL_SOLID:
598 			{
599 				if ( pSh && pSh->GetItem( SID_COLOR_TABLE ) )
600 				{
601 					SvxColorTableItem aItem( *(const SvxColorTableItem*)(
602 						pSh->GetItem( SID_COLOR_TABLE ) ) );
603 					pLbFillAttr->Enable();
604 					pLbFillAttr->Fill( aItem.GetColorTable() );
605 				}
606 				else
607 					pLbFillAttr->Disable();
608 			}
609 			break;
610 
611 			case XFILL_GRADIENT:
612 			{
613 				if ( pSh && pSh->GetItem( SID_GRADIENT_LIST ) )
614 				{
615 					SvxGradientListItem aItem( *(const SvxGradientListItem*)(
616 						pSh->GetItem( SID_GRADIENT_LIST ) ) );
617 					pLbFillAttr->Enable();
618 					pLbFillAttr->Fill( aItem.GetGradientList() );
619 				}
620 				else
621 					pLbFillAttr->Disable();
622 			}
623 			break;
624 
625 			case XFILL_HATCH:
626 			{
627 				if ( pSh && pSh->GetItem( SID_HATCH_LIST ) )
628 				{
629 					SvxHatchListItem aItem( *(const SvxHatchListItem*)(
630 						pSh->GetItem( SID_HATCH_LIST ) ) );
631 					pLbFillAttr->Enable();
632 					pLbFillAttr->Fill( aItem.GetHatchList() );
633 				}
634 				else
635 					pLbFillAttr->Disable();
636 			}
637 			break;
638 
639 			case XFILL_BITMAP:
640 			{
641 				if ( pSh && pSh->GetItem( SID_BITMAP_LIST ) )
642 				{
643 					SvxBitmapListItem aItem( *(const SvxBitmapListItem*)(
644 						pSh->GetItem( SID_BITMAP_LIST ) ) );
645 					pLbFillAttr->Enable();
646 					pLbFillAttr->Fill( aItem.GetBitmapList() );
647 				}
648 				else
649 					pLbFillAttr->Disable();
650 			}
651 			break;
652 		}
653 
654 		if( eXFS != XFILL_NONE ) // Wurde schon erledigt
655 		{
656 			if ( pBox )
657 				pLbFillType->Selected();
658 
659 			// release focus
660             if ( pBox && pLbFillType->IsRelease() )
661 			{
662 				SfxViewShell* pViewShell = SfxViewShell::Current();
663 				if( pViewShell && pViewShell->GetWindow() )
664 					pViewShell->GetWindow()->GrabFocus();
665 			}
666 		}
667     }
668 	return 0;
669 }
670 
671 //------------------------------------------------------------------------
672 
673 IMPL_LINK( FillControl, SelectFillAttrHdl, ListBox *, pBox )
674 {
675 	XFillStyle eXFS = (XFillStyle)pLbFillType->GetSelectEntryPos();
676 	XFillStyleItem aXFillStyleItem( eXFS );
677 	sal_Bool bAction = pBox && !pLbFillAttr->IsTravelSelect();
678 
679 	SfxObjectShell* pSh = SfxObjectShell::Current();
680     if ( bAction )
681     {
682         Any a;
683         Sequence< PropertyValue > aArgs( 1 );
684 
685         // First set the style
686         aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FillStyle" ));
687         aXFillStyleItem.QueryValue(  a );
688         aArgs[0].Value = a;
689         ( (SvxFillToolBoxControl*)GetData() )->IgnoreStatusUpdate( sal_True );
690         ((SvxFillToolBoxControl*)GetData())->Dispatch(
691             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FillStyle" )), aArgs );
692         ( (SvxFillToolBoxControl*)GetData() )->IgnoreStatusUpdate( sal_False );
693 
694         switch( eXFS )
695         {
696             case XFILL_NONE:
697             {
698             }
699             break;
700 
701             case XFILL_SOLID:
702             {
703                 // NEU
704                 //Eintrag wird auf temporaere Farbe geprueft
705                 String aTmpStr = pLbFillAttr->GetSelectEntry();
706                 if( aTmpStr.GetChar(0) == TMP_STR_BEGIN && aTmpStr.GetChar(aTmpStr.Len()-1) == TMP_STR_END )
707                 {
708                     aTmpStr.Erase( aTmpStr.Len()-1, 1 );
709                     aTmpStr.Erase( 0, 1 );
710                 }
711 
712                 XFillColorItem aXFillColorItem( aTmpStr, pLbFillAttr->GetSelectEntryColor() );
713 
714                 aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FillColor" ));
715                 aXFillColorItem.QueryValue( a );
716                 aArgs[0].Value = a;
717                 ((SvxFillToolBoxControl*)GetData())->Dispatch( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FillColor" )),
718                                                                aArgs );
719             }
720             break;
721             case XFILL_GRADIENT:
722             {
723                 sal_uInt16 nPos = pLbFillAttr->GetSelectEntryPos();
724 
725                 if ( nPos != LISTBOX_ENTRY_NOTFOUND && pSh && pSh->GetItem( SID_GRADIENT_LIST ) )
726                 {
727                     SvxGradientListItem aItem(
728                         *(const SvxGradientListItem*)( pSh->GetItem( SID_GRADIENT_LIST ) ) );
729 
730                     if ( nPos < aItem.GetGradientList()->Count() )  // kein temp. Eintrag ?
731                     {
732                         XGradient aGradient = aItem.GetGradientList()->GetGradient( nPos )->GetGradient();
733                         XFillGradientItem aXFillGradientItem( pLbFillAttr->GetSelectEntry(), aGradient );
734 
735                         aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FillGradient" ));
736                         aXFillGradientItem.QueryValue( a );
737                         aArgs[0].Value = a;
738                         ((SvxFillToolBoxControl*)GetData())->Dispatch( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FillGradient" )),
739                                                                        aArgs );
740                     }
741                 }
742             }
743             break;
744 
745             case XFILL_HATCH:
746             {
747                 sal_uInt16 nPos = pLbFillAttr->GetSelectEntryPos();
748 
749                 if ( nPos != LISTBOX_ENTRY_NOTFOUND && pSh && pSh->GetItem( SID_HATCH_LIST ) )
750                 {
751                     SvxHatchListItem aItem( *(const SvxHatchListItem*)( pSh->GetItem( SID_HATCH_LIST ) ) );
752 
753                     if ( nPos < aItem.GetHatchList()->Count() )  // kein temp. Eintrag ?
754                     {
755                         XHatch aHatch = aItem.GetHatchList()->GetHatch( nPos )->GetHatch();
756                         XFillHatchItem aXFillHatchItem( pLbFillAttr->GetSelectEntry(), aHatch );
757 
758                         aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FillHatch" ));
759                         aXFillHatchItem.QueryValue( a );
760                         aArgs[0].Value = a;
761                         ((SvxFillToolBoxControl*)GetData())->Dispatch( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FillHatch" )),
762                                                                        aArgs );
763                     }
764                 }
765             }
766             break;
767 
768             case XFILL_BITMAP:
769             {
770                 sal_uInt16 nPos = pLbFillAttr->GetSelectEntryPos();
771 
772                 if ( nPos != LISTBOX_ENTRY_NOTFOUND && pSh && pSh->GetItem( SID_BITMAP_LIST ) )
773                 {
774                     SvxBitmapListItem aItem(
775                         *(const SvxBitmapListItem*)( pSh->GetItem( SID_BITMAP_LIST ) ) );
776 
777                     if ( nPos < aItem.GetBitmapList()->Count() )  // kein temp. Eintrag ?
778                     {
779                         const XBitmapEntry* pXBitmapEntry = aItem.GetBitmapList()->GetBitmap(nPos);
780                         const XFillBitmapItem aXFillBitmapItem(pLbFillAttr->GetSelectEntry(), pXBitmapEntry->GetGraphicObject());
781 
782                         aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FillBitmap" ));
783                         aXFillBitmapItem.QueryValue( a );
784                         aArgs[0].Value = a;
785                         ((SvxFillToolBoxControl*)GetData())->Dispatch(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:FillBitmap")), aArgs);
786                     }
787                 }
788             }
789             break;
790         }
791 
792         // release focus
793         if ( pLbFillAttr->IsRelease()  && pBox )
794 		{
795 			SfxViewShell* pViewShell = SfxViewShell::Current();
796 			if( pViewShell && pViewShell->GetWindow() )
797 			{
798 	            pViewShell->GetWindow()->GrabFocus();
799 			}
800 		}
801     }
802 
803     return 0;
804 }
805 
806 //------------------------------------------------------------------------
807 
808 void FillControl::Resize()
809 {
810 	// Breite der beiden ListBoxen nicht 1/2 : 1/2, sondern 2/5 : 3/5
811 	long nW = GetOutputSizePixel().Width() / 5;
812 	long nH = 180;
813 	long nSep = 0; // war vorher 4
814 
815 	pLbFillType->SetSizePixel( Size( nW * 2 - nSep, nH ) );
816 	pLbFillAttr->SetPosSizePixel( Point( nW * 2 + nSep, 0 ), Size( nW * 3 - nSep, nH ) );
817 }
818 /* -----------------------------08.03.2002 15:04------------------------------
819 
820  ---------------------------------------------------------------------------*/
821 
822 void FillControl::DataChanged( const DataChangedEvent& rDCEvt )
823 {
824 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
825          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
826     {
827         Size aTypeSize(LogicToPixel(aLogicalFillSize, MAP_APPFONT));
828         Size aAttrSize(LogicToPixel(aLogicalAttrSize, MAP_APPFONT));
829         pLbFillType->SetSizePixel(aTypeSize);
830         pLbFillAttr->SetSizePixel(aAttrSize);
831         //to get the base height
832         aTypeSize = pLbFillType->GetSizePixel();
833         aAttrSize = pLbFillAttr->GetSizePixel();
834         Point aAttrPnt = pLbFillAttr->GetPosPixel();
835 
836         SetSizePixel(
837             Size( aAttrPnt.X() + aAttrSize.Width(),
838                 Max( aAttrSize.Height(), aTypeSize.Height() ) ) );
839     }
840     Window::DataChanged( rDCEvt );
841 }
842 
843