LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/tbxctrls - fillctrl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 157 395 39.7 %
Date: 2013-07-09 Functions: 17 22 77.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10