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