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