LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/cui/source/tabpages - tpbitmap.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 488 0.0 %
Date: 2013-07-09 Functions: 0 30 0.0 %
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 <vcl/wrkwin.hxx>
      21             : #include <tools/shl.hxx>
      22             : #include <vcl/msgbox.hxx>
      23             : #include <tools/urlobj.hxx>
      24             : #include <unotools/ucbstreamhelper.hxx>
      25             : #include <unotools/pathoptions.hxx>
      26             : #include <sfx2/app.hxx>
      27             : #include <sfx2/filedlghelper.hxx>
      28             : #include <unotools/localfilehelper.hxx>
      29             : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
      30             : #include <svx/dialmgr.hxx>
      31             : #include <vcl/bmpacc.hxx>
      32             : #include <svx/dialogs.hrc>
      33             : 
      34             : #include <cuires.hrc>
      35             : #include "helpid.hrc"
      36             : #include "svx/xattr.hxx"
      37             : #include <svx/xpool.hxx>
      38             : #include <svx/xtable.hxx>
      39             : #include "svx/xoutbmp.hxx"
      40             : #include "svx/drawitem.hxx"
      41             : #include "cuitabarea.hxx"
      42             : #include "tabarea.hrc"
      43             : #include "defdlgname.hxx"
      44             : #include "dlgname.hxx"
      45             : #include <svx/svxdlg.hxx>
      46             : #include <dialmgr.hxx>
      47             : #include "sfx2/opengrf.hxx"
      48             : #include "paragrph.hrc"
      49             : 
      50           0 : SvxBitmapTabPage::SvxBitmapTabPage
      51             : (
      52             :     Window* pParent,
      53             :     const SfxItemSet& rInAttrs
      54             : ) :
      55             : 
      56           0 :     SvxTabPage          ( pParent, CUI_RES( RID_SVXPAGE_BITMAP ), rInAttrs ),
      57             : 
      58           0 :     aCtlPixel           ( this, CUI_RES( CTL_PIXEL ) ),
      59           0 :     aFtPixelEdit        ( this, CUI_RES( FT_PIXEL_EDIT ) ),
      60           0 :     aFtColor            ( this, CUI_RES( FT_COLOR ) ),
      61           0 :     aLbColor            ( this, CUI_RES( LB_COLOR ) ),
      62           0 :     aFtBackgroundColor  ( this, CUI_RES( FT_BACKGROUND_COLOR ) ),
      63           0 :     aLbBackgroundColor  ( this, CUI_RES( LB_BACKGROUND_COLOR ) ),
      64             :     // This fix text is used only to provide the name for the following
      65             :     // bitmap list box.  The fixed text is not displayed.
      66           0 :     aLbBitmapsHidden    ( this, CUI_RES( FT_BITMAPS_HIDDEN ) ),
      67           0 :     aLbBitmaps          ( this, CUI_RES( LB_BITMAPS ) ),
      68           0 :     aFlProp             ( this, CUI_RES( FL_PROP ) ),
      69           0 :     aCtlPreview         ( this, CUI_RES( CTL_PREVIEW ) ),
      70           0 :     aBtnAdd             ( this, CUI_RES( BTN_ADD ) ),
      71           0 :     aBtnModify          ( this, CUI_RES( BTN_MODIFY ) ),
      72           0 :     aBtnImport          ( this, CUI_RES( BTN_IMPORT ) ),
      73           0 :     aBtnDelete          ( this, CUI_RES( BTN_DELETE ) ),
      74           0 :     aBtnLoad            ( this, CUI_RES( BTN_LOAD ) ),
      75           0 :     aBtnSave            ( this, CUI_RES( BTN_SAVE ) ),
      76             : 
      77           0 :     aBitmapCtl          ( this, aCtlPreview.GetSizePixel() ),
      78             :     rOutAttrs           ( rInAttrs ),
      79             : 
      80             :     pnBitmapListState   ( 0 ),
      81             :     pnColorListState    ( 0 ),
      82             :     pPageType           ( 0 ),
      83             :     pDlgType            ( 0 ),
      84             :     pbAreaTP            ( 0 ),
      85             : 
      86             :     bBmpChanged         ( false ),
      87             : 
      88           0 :     pXPool              ( (XOutdevItemPool*) rInAttrs.GetPool() ),
      89             :     aXFStyleItem        ( XFILL_BITMAP ),
      90             :     aXBitmapItem        ( String(), Graphic() ),
      91             :     aXFillAttr          ( pXPool ),
      92           0 :     rXFSet              ( aXFillAttr.GetItemSet() )
      93             : {
      94           0 :     FreeResource();
      95             : 
      96             :     // this page needs ExchangeSupport
      97           0 :     SetExchangeSupport();
      98             : 
      99             :     // setting the output device
     100           0 :     rXFSet.Put( aXFStyleItem );
     101           0 :     rXFSet.Put( aXBitmapItem );
     102             : 
     103           0 :     aBtnAdd.SetClickHdl( LINK( this, SvxBitmapTabPage, ClickAddHdl_Impl ) );
     104             :     aBtnImport.SetClickHdl(
     105           0 :         LINK( this, SvxBitmapTabPage, ClickImportHdl_Impl ) );
     106             :     aBtnModify.SetClickHdl(
     107           0 :         LINK( this, SvxBitmapTabPage, ClickModifyHdl_Impl ) );
     108             :     aBtnDelete.SetClickHdl(
     109           0 :         LINK( this, SvxBitmapTabPage, ClickDeleteHdl_Impl ) );
     110           0 :     aBtnLoad.SetClickHdl( LINK( this, SvxBitmapTabPage, ClickLoadHdl_Impl ) );
     111           0 :     aBtnSave.SetClickHdl( LINK( this, SvxBitmapTabPage, ClickSaveHdl_Impl ) );
     112             : 
     113             :     aLbBitmaps.SetSelectHdl(
     114           0 :         LINK( this, SvxBitmapTabPage, ChangeBitmapHdl_Impl ) );
     115             :     aLbColor.SetSelectHdl(
     116           0 :         LINK( this, SvxBitmapTabPage, ChangePixelColorHdl_Impl ) );
     117             :     aLbBackgroundColor.SetSelectHdl(
     118           0 :         LINK( this, SvxBitmapTabPage, ChangeBackgrndColorHdl_Impl ) );
     119             : 
     120           0 :     String accName = String(CUI_RES(STR_EXAMPLE));
     121           0 :     aCtlPreview.SetAccessibleName(accName);
     122           0 :     aCtlPixel.SetAccessibleRelationMemberOf( &aFlProp );
     123           0 :     aCtlPixel.SetAccessibleRelationLabeledBy( &aFtPixelEdit );
     124           0 :     aLbBitmaps.SetAccessibleRelationLabeledBy(&aLbBitmaps);
     125           0 :     aBtnAdd.SetAccessibleRelationMemberOf( &aFlProp );
     126           0 :     aBtnModify.SetAccessibleRelationMemberOf( &aFlProp );
     127           0 :     aBtnImport.SetAccessibleRelationMemberOf( &aFlProp );
     128           0 :     aBtnDelete.SetAccessibleRelationMemberOf( &aFlProp );
     129             : 
     130           0 : }
     131             : 
     132             : // -----------------------------------------------------------------------
     133             : 
     134           0 : void SvxBitmapTabPage::Construct()
     135             : {
     136           0 :     aLbColor.Fill( pColorList );
     137           0 :     aLbBackgroundColor.CopyEntries( aLbColor );
     138             : 
     139           0 :     aLbBitmaps.Fill( pBitmapList );
     140           0 : }
     141             : 
     142             : // -----------------------------------------------------------------------
     143             : 
     144           0 : void SvxBitmapTabPage::ActivatePage( const SfxItemSet&  )
     145             : {
     146             :     sal_uInt16 nPos;
     147             :     sal_uInt16 nCount;
     148             : 
     149           0 :     if( *pDlgType == 0 ) // area dialog
     150             :     {
     151           0 :         *pbAreaTP = sal_False;
     152             : 
     153           0 :         if( pColorList.is() )
     154             :         {
     155             :             // ColorList
     156           0 :             if( *pnColorListState & CT_CHANGED ||
     157           0 :                 *pnColorListState & CT_MODIFIED )
     158             :             {
     159           0 :                 if( *pnColorListState & CT_CHANGED )
     160           0 :                     pColorList = ( (SvxAreaTabDialog*) GetParentDialog() )->GetNewColorList();
     161             : 
     162             :                 // LbColor
     163           0 :                 nPos = aLbColor.GetSelectEntryPos();
     164           0 :                 aLbColor.Clear();
     165           0 :                 aLbColor.Fill( pColorList );
     166           0 :                 nCount = aLbColor.GetEntryCount();
     167           0 :                 if( nCount == 0 )
     168             :                     ; // this case should not occur
     169           0 :                 else if( nCount <= nPos )
     170           0 :                     aLbColor.SelectEntryPos( 0 );
     171             :                 else
     172           0 :                     aLbColor.SelectEntryPos( nPos );
     173             : 
     174             :                 // LbColorBackground
     175           0 :                 nPos = aLbBackgroundColor.GetSelectEntryPos();
     176           0 :                 aLbBackgroundColor.Clear();
     177           0 :                 aLbBackgroundColor.CopyEntries( aLbColor );
     178           0 :                 nCount = aLbBackgroundColor.GetEntryCount();
     179           0 :                 if( nCount == 0 )
     180             :                     ; // this case should not occur
     181           0 :                 else if( nCount <= nPos )
     182           0 :                     aLbBackgroundColor.SelectEntryPos( 0 );
     183             :                 else
     184           0 :                     aLbBackgroundColor.SelectEntryPos( nPos );
     185             : 
     186           0 :                 ChangePixelColorHdl_Impl( this );
     187           0 :                 ChangeBackgrndColorHdl_Impl( this );
     188             :             }
     189             : 
     190             :             // determining (possibly cutting) the name and
     191             :             // displaying it in the GroupBox
     192           0 :             OUString        aString( CUI_RES( RID_SVXSTR_TABLE ) );
     193           0 :             aString         += ": ";
     194           0 :             INetURLObject   aURL( pBitmapList->GetPath() );
     195             : 
     196           0 :             aURL.Append( pBitmapList->GetName() );
     197             :             DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
     198             : 
     199           0 :             if( aURL.getBase().getLength() > 18 )
     200             :             {
     201           0 :                 aString += aURL.getBase().copy( 0, 15 );
     202           0 :                 aString += "...";
     203             :             }
     204             :             else
     205           0 :                 aString += aURL.getBase();
     206             : 
     207           0 :             if( *pPageType == PT_BITMAP && *pPos != LISTBOX_ENTRY_NOTFOUND )
     208             :             {
     209           0 :                 aLbBitmaps.SelectEntryPos( *pPos );
     210             :             }
     211             :             // colors could have been deleted
     212           0 :             ChangeBitmapHdl_Impl( this );
     213             : 
     214           0 :             *pPageType = PT_BITMAP;
     215           0 :             *pPos = LISTBOX_ENTRY_NOTFOUND;
     216             :         }
     217             :     }
     218           0 : }
     219             : 
     220             : // -----------------------------------------------------------------------
     221             : 
     222           0 : int SvxBitmapTabPage::DeactivatePage( SfxItemSet* _pSet)
     223             : {
     224           0 :     if ( CheckChanges_Impl() == -1L )
     225           0 :         return KEEP_PAGE;
     226             : 
     227           0 :     if( _pSet )
     228           0 :         FillItemSet( *_pSet );
     229             : 
     230           0 :     return LEAVE_PAGE;
     231             : }
     232             : 
     233             : // -----------------------------------------------------------------------
     234             : 
     235           0 : sal_Bool SvxBitmapTabPage::FillItemSet( SfxItemSet& _rOutAttrs )
     236             : {
     237           0 :     if( *pDlgType == 0 && *pbAreaTP == sal_False ) // area dialog
     238             :     {
     239           0 :         if(PT_BITMAP == *pPageType)
     240             :         {
     241           0 :             _rOutAttrs.Put(XFillStyleItem(XFILL_BITMAP));
     242           0 :             sal_uInt16 nPos = aLbBitmaps.GetSelectEntryPos();
     243           0 :             if(LISTBOX_ENTRY_NOTFOUND != nPos)
     244             :             {
     245           0 :                 const XBitmapEntry* pXBitmapEntry = pBitmapList->GetBitmap(nPos);
     246           0 :                 const String aString(aLbBitmaps.GetSelectEntry());
     247             : 
     248           0 :                 _rOutAttrs.Put(XFillBitmapItem(aString, pXBitmapEntry->GetGraphicObject()));
     249             :             }
     250             :             else
     251             :             {
     252           0 :                 const BitmapEx aBitmapEx(aBitmapCtl.GetBitmapEx());
     253             : 
     254           0 :                 _rOutAttrs.Put(XFillBitmapItem(String(), Graphic(aBitmapEx)));
     255             :             }
     256             :         }
     257             :     }
     258             : 
     259           0 :     return sal_True;
     260             : }
     261             : 
     262             : // -----------------------------------------------------------------------
     263             : 
     264           0 : void SvxBitmapTabPage::Reset( const SfxItemSet&  )
     265             : {
     266             :     // aLbBitmaps.SelectEntryPos( 0 );
     267             : 
     268           0 :     aBitmapCtl.SetLines( aCtlPixel.GetLineCount() );
     269           0 :     aBitmapCtl.SetPixelColor( aLbColor.GetSelectEntryColor() );
     270           0 :     aBitmapCtl.SetBackgroundColor( aLbBackgroundColor.GetSelectEntryColor() );
     271           0 :     aBitmapCtl.SetBmpArray( aCtlPixel.GetBitmapPixelPtr() );
     272             : 
     273             :     // get bitmap and display it
     274           0 :     const XFillBitmapItem aBmpItem(OUString(), Graphic(aBitmapCtl.GetBitmapEx()));
     275           0 :     rXFSet.Put( aBmpItem );
     276           0 :     aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
     277           0 :     aCtlPreview.Invalidate();
     278             : 
     279           0 :     ChangeBitmapHdl_Impl( this );
     280             : 
     281             :     // determine button state
     282           0 :     if( pBitmapList->Count() )
     283             :     {
     284           0 :         aBtnAdd.Enable();
     285           0 :         aBtnModify.Enable();
     286           0 :         aBtnDelete.Enable();
     287           0 :         aBtnSave.Enable();
     288             :     }
     289             :     else
     290             :     {
     291           0 :         aBtnModify.Disable();
     292           0 :         aBtnDelete.Disable();
     293           0 :         aBtnSave.Disable();
     294           0 :     }
     295           0 : }
     296             : 
     297             : // -----------------------------------------------------------------------
     298             : 
     299           0 : SfxTabPage* SvxBitmapTabPage::Create( Window* pWindow,
     300             :                 const SfxItemSet& rSet )
     301             : {
     302           0 :     return new SvxBitmapTabPage( pWindow, rSet );
     303             : }
     304             : 
     305             : //------------------------------------------------------------------------
     306             : 
     307           0 : IMPL_LINK_NOARG(SvxBitmapTabPage, ChangeBitmapHdl_Impl)
     308             : {
     309           0 :     GraphicObject* pGraphicObject = 0;
     310           0 :     int nPos(aLbBitmaps.GetSelectEntryPos());
     311             : 
     312           0 :     if(LISTBOX_ENTRY_NOTFOUND != nPos)
     313             :     {
     314           0 :         pGraphicObject = new GraphicObject(pBitmapList->GetBitmap(nPos)->GetGraphicObject());
     315             :     }
     316             :     else
     317             :     {
     318           0 :         const SfxPoolItem* pPoolItem = 0;
     319             : 
     320           0 :         if(SFX_ITEM_SET == rOutAttrs.GetItemState(GetWhich(XATTR_FILLSTYLE), true, &pPoolItem))
     321             :         {
     322           0 :             const XFillStyle eXFS((XFillStyle)((const XFillStyleItem*)pPoolItem)->GetValue());
     323             : 
     324           0 :             if((XFILL_BITMAP == eXFS) && (SFX_ITEM_SET == rOutAttrs.GetItemState(GetWhich(XATTR_FILLBITMAP), true, &pPoolItem)))
     325             :             {
     326           0 :                 pGraphicObject = new GraphicObject(((const XFillBitmapItem*)pPoolItem)->GetGraphicObject());
     327             :             }
     328             :         }
     329             : 
     330           0 :         if(!pGraphicObject)
     331             :         {
     332           0 :             aLbBitmaps.SelectEntryPos(0);
     333           0 :             nPos = aLbBitmaps.GetSelectEntryPos();
     334             : 
     335           0 :             if(LISTBOX_ENTRY_NOTFOUND != nPos)
     336             :             {
     337           0 :                 pGraphicObject = new GraphicObject(pBitmapList->GetBitmap(nPos)->GetGraphicObject());
     338             :             }
     339             :         }
     340             :     }
     341             : 
     342           0 :     if(pGraphicObject)
     343             :     {
     344           0 :         BitmapColor aBack;
     345           0 :         BitmapColor aFront;
     346           0 :         bool bIs8x8(isHistorical8x8(pGraphicObject->GetGraphic().GetBitmap(), aBack, aFront));
     347             : 
     348           0 :         aLbColor.SetNoSelection();
     349           0 :         aLbBackgroundColor.SetNoSelection();
     350             : 
     351           0 :         if(bIs8x8)
     352             :         {
     353           0 :             aCtlPixel.SetPaintable( sal_True );
     354           0 :             aCtlPixel.Enable();
     355           0 :             aFtPixelEdit.Enable();
     356           0 :             aFtColor.Enable();
     357           0 :             aLbColor.Enable();
     358           0 :             aFtBackgroundColor.Enable();
     359           0 :             aLbBackgroundColor.Enable();
     360           0 :             aBtnModify.Enable();
     361           0 :             aBtnAdd.Enable();
     362             : 
     363             :             // setting the pixel control
     364           0 :             aCtlPixel.SetXBitmap(pGraphicObject->GetGraphic().GetBitmapEx());
     365             : 
     366           0 :             Color aPixelColor = aFront;
     367           0 :             Color aBackColor = aBack;
     368             : 
     369           0 :             aBitmapCtl.SetPixelColor( aPixelColor );
     370           0 :             aBitmapCtl.SetBackgroundColor( aBackColor );
     371             : 
     372             :             // if the entry is not in the listbox,
     373             :             // the color is added temporarily
     374           0 :             if( 0 == aLbBitmaps.GetSelectEntryPos() )
     375             :             {
     376           0 :                 aLbColor.SelectEntry( Color( COL_BLACK ) );
     377           0 :                 ChangePixelColorHdl_Impl( this );
     378             :             }
     379             :             else
     380           0 :                 aLbColor.SelectEntry( aPixelColor );
     381           0 :             if( aLbColor.GetSelectEntryCount() == 0 )
     382             :             {
     383           0 :                 aLbColor.InsertEntry( aPixelColor, String() );
     384           0 :                 aLbColor.SelectEntry( aPixelColor );
     385             :             }
     386           0 :             aLbBackgroundColor.SelectEntry( aBackColor );
     387           0 :             if( aLbBackgroundColor.GetSelectEntryCount() == 0 )
     388             :             {
     389           0 :                 aLbBackgroundColor.InsertEntry( aBackColor, String() );
     390           0 :                 aLbBackgroundColor.SelectEntry( aBackColor );
     391             :             }
     392             :         }
     393             :         else
     394             :         {
     395           0 :             aCtlPixel.Reset();
     396           0 :             aCtlPixel.SetPaintable( sal_False );
     397           0 :             aCtlPixel.Disable();
     398           0 :             aFtPixelEdit.Disable();
     399           0 :             aFtColor.Disable();
     400           0 :             aLbColor.Disable();
     401           0 :             aFtBackgroundColor.Disable();
     402           0 :             aLbBackgroundColor.Disable();
     403           0 :             aBtnModify.Disable();
     404           0 :             aBtnAdd.Disable();
     405             :         }
     406             : 
     407           0 :         aCtlPixel.Invalidate();
     408             : 
     409             :         // display bitmap
     410           0 :         const XFillBitmapItem aXBmpItem(String(), *pGraphicObject);
     411           0 :         rXFSet.Put( aXBmpItem );
     412             : 
     413           0 :         aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
     414           0 :         aCtlPreview.Invalidate();
     415             : 
     416           0 :         bBmpChanged = sal_False;
     417           0 :         delete pGraphicObject;
     418             :     }
     419             : 
     420           0 :     return 0;
     421             : }
     422             : 
     423             : // -----------------------------------------------------------------------
     424             : 
     425           0 : long SvxBitmapTabPage::CheckChanges_Impl()
     426             : {
     427           0 :     sal_uInt16 nPos = aLbBitmaps.GetSelectEntryPos();
     428           0 :     if( nPos != LISTBOX_ENTRY_NOTFOUND )
     429             :     {
     430           0 :         if( bBmpChanged )
     431             :         {
     432           0 :             ResMgr& rMgr = CUI_MGR();
     433           0 :             Image aWarningBoxImage = WarningBox::GetStandardImage();
     434           0 :             SvxMessDialog* aMessDlg = new SvxMessDialog(GetParentDialog(),
     435           0 :                                                         String( SVX_RES( RID_SVXSTR_BITMAP ) ),
     436           0 :                                                         String( CUI_RES( RID_SVXSTR_ASK_CHANGE_BITMAP ) ),
     437           0 :                                                         &aWarningBoxImage  );
     438             :             DBG_ASSERT(aMessDlg, "Dialogdiet fail!");
     439             :             aMessDlg->SetButtonText( MESS_BTN_1,
     440           0 :                                     String( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
     441             :             aMessDlg->SetButtonText( MESS_BTN_2,
     442           0 :                                     String( ResId( RID_SVXSTR_ADD, rMgr ) ) );
     443             : 
     444           0 :             short nRet = aMessDlg->Execute();
     445             : 
     446           0 :             switch( nRet )
     447             :             {
     448             :                 case RET_BTN_1:
     449             :                 {
     450           0 :                     ClickModifyHdl_Impl( this );
     451             :                 }
     452           0 :                 break;
     453             : 
     454             :                 case RET_BTN_2:
     455             :                 {
     456           0 :                     ClickAddHdl_Impl( this );
     457           0 :                     nPos = aLbBitmaps.GetSelectEntryPos();
     458             :                 }
     459           0 :                 break;
     460             : 
     461             :                 case RET_CANCEL:
     462           0 :                 break;
     463             :             }
     464           0 :             delete aMessDlg;
     465             :         }
     466             :     }
     467           0 :     nPos = aLbBitmaps.GetSelectEntryPos();
     468           0 :     if( nPos != LISTBOX_ENTRY_NOTFOUND )
     469           0 :         *pPos = nPos;
     470           0 :     return 0L;
     471             : }
     472             : 
     473             : //------------------------------------------------------------------------
     474             : 
     475           0 : IMPL_LINK_NOARG(SvxBitmapTabPage, ClickAddHdl_Impl)
     476             : {
     477           0 :     ResMgr& rMgr = CUI_MGR();
     478           0 :     String aNewName( SVX_RES( RID_SVXSTR_BITMAP ) );
     479           0 :     String aDesc( CUI_RES( RID_SVXSTR_DESC_NEW_BITMAP ) );
     480           0 :     String aName;
     481             : 
     482           0 :     long nCount = pBitmapList->Count();
     483           0 :     long j = 1;
     484           0 :     sal_Bool bDifferent = sal_False;
     485             : 
     486           0 :     while( !bDifferent )
     487             :     {
     488           0 :         aName  = aNewName;
     489           0 :         aName += sal_Unicode(' ');
     490           0 :         aName += OUString::valueOf( j++ );
     491           0 :         bDifferent = sal_True;
     492             : 
     493           0 :         for( long i = 0; i < nCount && bDifferent; i++ )
     494           0 :             if( aName == pBitmapList->GetBitmap( i )->GetName() )
     495           0 :                 bDifferent = sal_False;
     496             :     }
     497             : 
     498           0 :     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     499             :     DBG_ASSERT(pFact, "Dialogdiet fail!");
     500           0 :     AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
     501             :     DBG_ASSERT(pDlg, "Dialogdiet fail!");
     502           0 :     WarningBox*    pWarnBox = NULL;
     503           0 :     sal_uInt16         nError   = RID_SVXSTR_WARN_NAME_DUPLICATE;
     504             : 
     505           0 :     while( pDlg->Execute() == RET_OK )
     506             :     {
     507           0 :         pDlg->GetName( aName );
     508             : 
     509           0 :         bDifferent = sal_True;
     510             : 
     511           0 :         for( long i = 0; i < nCount && bDifferent; i++ )
     512           0 :             if( aName == pBitmapList->GetBitmap( i )->GetName() )
     513           0 :                 bDifferent = sal_False;
     514             : 
     515           0 :         if( bDifferent ) {
     516           0 :             nError = 0;
     517           0 :             break;
     518             :         }
     519             : 
     520           0 :         if( !pWarnBox )
     521             :         {
     522           0 :             pWarnBox = new WarningBox( GetParentDialog(),
     523             :                                        WinBits( WB_OK_CANCEL ),
     524           0 :                                        String( ResId( nError, rMgr ) ) );
     525           0 :             pWarnBox->SetHelpId( HID_WARN_NAME_DUPLICATE );
     526             :         }
     527             : 
     528           0 :         if( pWarnBox->Execute() != RET_OK )
     529           0 :             break;
     530             :     }
     531             : 
     532           0 :     delete pDlg;
     533           0 :     delete pWarnBox;
     534             : 
     535           0 :     if( !nError )
     536             :     {
     537           0 :         XBitmapEntry* pEntry = 0;
     538           0 :         if( aCtlPixel.IsEnabled() )
     539             :         {
     540           0 :             const BitmapEx aBitmapEx(aBitmapCtl.GetBitmapEx());
     541             : 
     542           0 :             pEntry = new XBitmapEntry(Graphic(aBitmapEx), aName);
     543             :         }
     544             :         else // it must be a not existing imported bitmap
     545             :         {
     546           0 :             const SfxPoolItem* pPoolItem = 0;
     547             : 
     548           0 :             if(SFX_ITEM_SET == rOutAttrs.GetItemState(XATTR_FILLBITMAP, true, &pPoolItem))
     549             :             {
     550           0 :                 pEntry = new XBitmapEntry(dynamic_cast< const XFillBitmapItem* >(pPoolItem)->GetGraphicObject(), aName);
     551             :             }
     552             :         }
     553             : 
     554             :         DBG_ASSERT( pEntry, "SvxBitmapTabPage::ClickAddHdl_Impl(), pEntry == 0 ?" );
     555             : 
     556           0 :         if( pEntry )
     557             :         {
     558           0 :             pBitmapList->Insert( pEntry );
     559           0 :             const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
     560           0 :             aLbBitmaps.Append(rStyleSettings.GetListBoxPreviewDefaultPixelSize(), *pEntry );
     561           0 :             aLbBitmaps.SelectEntryPos( aLbBitmaps.GetEntryCount() - 1 );
     562             : 
     563           0 :             *pnBitmapListState |= CT_MODIFIED;
     564             : 
     565           0 :             ChangeBitmapHdl_Impl( this );
     566             :         }
     567             :     }
     568             : 
     569             :     // determine button state
     570           0 :     if( pBitmapList->Count() )
     571             :     {
     572           0 :         aBtnModify.Enable();
     573           0 :         aBtnDelete.Enable();
     574           0 :         aBtnSave.Enable();
     575             :     }
     576           0 :     return 0L;
     577             : }
     578             : 
     579             : 
     580             : /******************************************************************************/
     581             : /******************************************************************************/
     582             : 
     583             : 
     584             : //------------------------------------------------------------------------
     585             : 
     586           0 : IMPL_LINK_NOARG(SvxBitmapTabPage, ClickImportHdl_Impl)
     587             : {
     588           0 :     ResMgr& rMgr = CUI_MGR();
     589           0 :     SvxOpenGraphicDialog aDlg( OUString("Import") );
     590           0 :     aDlg.EnableLink(sal_False);
     591             : 
     592           0 :     if( !aDlg.Execute() )
     593             :     {
     594           0 :         Graphic         aGraphic;
     595           0 :         int             nError = 1;
     596             : 
     597           0 :         EnterWait();
     598           0 :         nError = aDlg.GetGraphic( aGraphic );
     599           0 :         LeaveWait();
     600             : 
     601           0 :         if( !nError )
     602             :         {
     603           0 :             String aDesc( ResId(RID_SVXSTR_DESC_EXT_BITMAP, rMgr) );
     604           0 :             WarningBox*    pWarnBox = NULL;
     605             : 
     606             :             // convert file URL to UI name
     607           0 :             String          aName;
     608           0 :             INetURLObject   aURL( aDlg.GetPath() );
     609           0 :             SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     610             :             DBG_ASSERT(pFact, "Dialogdiet fail!");
     611           0 :             AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), String(aURL.GetName()).GetToken( 0, '.' ), aDesc );
     612             :             DBG_ASSERT(pDlg, "Dialogdiet fail!");
     613           0 :             nError = RID_SVXSTR_WARN_NAME_DUPLICATE;
     614             : 
     615           0 :             while( pDlg->Execute() == RET_OK )
     616             :             {
     617           0 :                 pDlg->GetName( aName );
     618             : 
     619           0 :                 sal_Bool bDifferent = sal_True;
     620           0 :                 long nCount     = pBitmapList->Count();
     621             : 
     622           0 :                 for( long i = 0; i < nCount && bDifferent; i++ )
     623           0 :                     if( aName == pBitmapList->GetBitmap( i )->GetName() )
     624           0 :                         bDifferent = sal_False;
     625             : 
     626           0 :                 if( bDifferent ) {
     627           0 :                     nError = 0;
     628           0 :                     break;
     629             :                 }
     630             : 
     631           0 :                 if( !pWarnBox )
     632             :                 {
     633           0 :                     pWarnBox = new WarningBox( GetParentDialog(),
     634             :                                                WinBits( WB_OK_CANCEL ),
     635           0 :                                                String( ResId( nError, rMgr ) ) );
     636           0 :                     pWarnBox->SetHelpId( HID_WARN_NAME_DUPLICATE );
     637             :                 }
     638             : 
     639             : 
     640           0 :                 if( pWarnBox->Execute() != RET_OK )
     641           0 :                     break;
     642             :             }
     643             : 
     644           0 :             delete pDlg;
     645           0 :             delete pWarnBox;
     646             : 
     647           0 :             if( !nError )
     648             :             {
     649           0 :                 XBitmapEntry* pEntry = new XBitmapEntry( aGraphic, aName );
     650           0 :                 pBitmapList->Insert( pEntry );
     651             : 
     652           0 :                 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
     653           0 :                 aLbBitmaps.Append(rStyleSettings.GetListBoxPreviewDefaultPixelSize(), *pEntry );
     654           0 :                 aLbBitmaps.SelectEntryPos( aLbBitmaps.GetEntryCount() - 1 );
     655             : 
     656           0 :                 *pnBitmapListState |= CT_MODIFIED;
     657             : 
     658           0 :                 ChangeBitmapHdl_Impl( this );
     659           0 :             }
     660             :         }
     661             :         else
     662             :             // graphic couldn't be loaded
     663           0 :             ErrorBox( GetParentDialog(),
     664             :                       WinBits( WB_OK ),
     665           0 :                       String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
     666             :     }
     667             : 
     668           0 :     return 0L;
     669             : }
     670             : 
     671             : //------------------------------------------------------------------------
     672             : 
     673           0 : IMPL_LINK_NOARG(SvxBitmapTabPage, ClickModifyHdl_Impl)
     674             : {
     675           0 :     sal_uInt16 nPos = aLbBitmaps.GetSelectEntryPos();
     676             : 
     677           0 :     if ( nPos != LISTBOX_ENTRY_NOTFOUND )
     678             :     {
     679           0 :         ResMgr& rMgr = CUI_MGR();
     680           0 :         String aDesc( ResId( RID_SVXSTR_DESC_NEW_BITMAP, rMgr ) );
     681           0 :         String aName( pBitmapList->GetBitmap( nPos )->GetName() );
     682           0 :         String aOldName = aName;
     683             : 
     684           0 :         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     685             :         DBG_ASSERT(pFact, "Dialogdiet fail!");
     686           0 :         AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
     687             :         DBG_ASSERT(pDlg, "Dialogdiet fail!");
     688             : 
     689           0 :         long nCount = pBitmapList->Count();
     690           0 :         sal_Bool bDifferent = sal_False;
     691           0 :         sal_Bool bLoop = sal_True;
     692           0 :         const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
     693             : 
     694           0 :         while( bLoop && pDlg->Execute() == RET_OK )
     695             :         {
     696           0 :             pDlg->GetName( aName );
     697           0 :             bDifferent = sal_True;
     698             : 
     699           0 :             for( long i = 0; i < nCount && bDifferent; i++ )
     700             :             {
     701           0 :                 if( aName == pBitmapList->GetBitmap( i )->GetName() &&
     702           0 :                     aName != aOldName )
     703           0 :                     bDifferent = sal_False;
     704             :             }
     705             : 
     706           0 :             if( bDifferent )
     707             :             {
     708           0 :                 bLoop = sal_False;
     709             : 
     710           0 :                 const BitmapEx aBitmapEx(aBitmapCtl.GetBitmapEx());
     711           0 :                 const XBitmapEntry aEntry(Graphic(aBitmapEx), aName);
     712             : 
     713           0 :                 aLbBitmaps.Modify( rStyleSettings.GetListBoxPreviewDefaultPixelSize(), aEntry, nPos );
     714           0 :                 aLbBitmaps.SelectEntryPos( nPos );
     715             : 
     716           0 :                 *pnBitmapListState |= CT_MODIFIED;
     717             : 
     718           0 :                 bBmpChanged = sal_False;
     719             :             }
     720             :             else
     721             :             {
     722           0 :                 WarningBox aBox( GetParentDialog(), WinBits( WB_OK ), String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
     723           0 :                 aBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
     724           0 :                 aBox.Execute();
     725             :             }
     726             :         }
     727           0 :         delete pDlg;
     728             :     }
     729           0 :     return 0L;
     730             : }
     731             : 
     732             : //------------------------------------------------------------------------
     733             : 
     734           0 : IMPL_LINK_NOARG(SvxBitmapTabPage, ClickDeleteHdl_Impl)
     735             : {
     736           0 :     sal_uInt16 nPos = aLbBitmaps.GetSelectEntryPos();
     737             : 
     738           0 :     if( nPos != LISTBOX_ENTRY_NOTFOUND )
     739             :     {
     740           0 :         QueryBox aQueryBox( GetParentDialog(), WinBits( WB_YES_NO | WB_DEF_NO ),
     741           0 :             String( CUI_RES( RID_SVXSTR_ASK_DEL_BITMAP ) ) );
     742             : 
     743           0 :         if( aQueryBox.Execute() == RET_YES )
     744             :         {
     745           0 :             delete pBitmapList->Remove( nPos );
     746           0 :             aLbBitmaps.RemoveEntry( nPos );
     747           0 :             aLbBitmaps.SelectEntryPos( 0 );
     748             : 
     749           0 :             aCtlPreview.Invalidate();
     750           0 :             aCtlPixel.Invalidate();
     751             : 
     752           0 :             ChangeBitmapHdl_Impl( this );
     753             : 
     754           0 :             *pnBitmapListState |= CT_MODIFIED;
     755           0 :         }
     756             :     }
     757             :     // determine button state
     758           0 :     if( !pBitmapList->Count() )
     759             :     {
     760           0 :         aBtnModify.Disable();
     761           0 :         aBtnDelete.Disable();
     762           0 :         aBtnSave.Disable();
     763             :     }
     764           0 :     return 0L;
     765             : }
     766             : 
     767             : // -----------------------------------------------------------------------
     768             : 
     769           0 : IMPL_LINK_NOARG(SvxBitmapTabPage, ClickLoadHdl_Impl)
     770             : {
     771           0 :     sal_uInt16 nReturn = RET_YES;
     772           0 :     ResMgr& rMgr = CUI_MGR();
     773             : 
     774           0 :     if ( *pnBitmapListState & CT_MODIFIED )
     775             :     {
     776           0 :         nReturn = WarningBox( GetParentDialog(), WinBits( WB_YES_NO_CANCEL ),
     777           0 :             String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
     778             : 
     779           0 :         if ( nReturn == RET_YES )
     780           0 :             pBitmapList->Save();
     781             :     }
     782             : 
     783           0 :     if ( nReturn != RET_CANCEL )
     784             :     {
     785             :         ::sfx2::FileDialogHelper aDlg(
     786             :             com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
     787           0 :             0 );
     788           0 :         String aStrFilterType( "*.sob" );
     789           0 :         aDlg.AddFilter( aStrFilterType, aStrFilterType );
     790           0 :         INetURLObject aFile( SvtPathOptions().GetPalettePath() );
     791           0 :         aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
     792             : 
     793           0 :         if ( aDlg.Execute() == ERRCODE_NONE )
     794             :         {
     795           0 :             EnterWait();
     796           0 :             INetURLObject aURL( aDlg.GetPath() );
     797           0 :             INetURLObject aPathURL( aURL );
     798             : 
     799           0 :             aPathURL.removeSegment();
     800           0 :             aPathURL.removeFinalSlash();
     801             : 
     802             :             // save table
     803             :             XBitmapListRef pBmpList = XPropertyList::CreatePropertyList(
     804           0 :                 XBITMAP_LIST, aPathURL.GetMainURL( INetURLObject::NO_DECODE ) )->AsBitmapList();
     805           0 :             pBmpList->SetName( aURL.getName() );
     806           0 :             if( pBmpList->Load() )
     807             :             {
     808           0 :                 pBitmapList = pBmpList;
     809           0 :                 ( (SvxAreaTabDialog*) GetParentDialog() )->SetNewBitmapList( pBitmapList );
     810             : 
     811           0 :                 aLbBitmaps.Clear();
     812           0 :                 aLbBitmaps.Fill( pBitmapList );
     813           0 :                 Reset( rOutAttrs );
     814             : 
     815           0 :                 pBitmapList->SetName( aURL.getName() );
     816             : 
     817             :                 // determining (possibly cutting) the name
     818             :                 // displaying it in the GroupBox
     819           0 :                 OUString aString( ResId( RID_SVXSTR_TABLE, rMgr ) );
     820           0 :                 aString += ": ";
     821             : 
     822           0 :                 if ( aURL.getBase().getLength() > 18 )
     823             :                 {
     824           0 :                     aString += aURL.getBase().copy( 0, 15 );
     825           0 :                     aString += "...";
     826             :                 }
     827             :                 else
     828           0 :                     aString += aURL.getBase();
     829             : 
     830           0 :                 *pnBitmapListState |= CT_CHANGED;
     831           0 :                 *pnBitmapListState &= ~CT_MODIFIED;
     832           0 :                 LeaveWait();
     833             :             }
     834             :             else
     835             :             {
     836           0 :                 LeaveWait();
     837           0 :                 ErrorBox( GetParentDialog(), WinBits( WB_OK ),
     838           0 :                     String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) ).Execute();
     839           0 :             }
     840           0 :         }
     841             :     }
     842             : 
     843             :     // determine button state
     844           0 :     if( pBitmapList->Count() )
     845             :     {
     846           0 :         aBtnModify.Enable();
     847           0 :         aBtnDelete.Enable();
     848           0 :         aBtnSave.Enable();
     849             :     }
     850             :     else
     851             :     {
     852           0 :         aBtnModify.Disable();
     853           0 :         aBtnDelete.Disable();
     854           0 :         aBtnSave.Disable();
     855             :     }
     856           0 :     return 0L;
     857             : }
     858             : 
     859             : // -----------------------------------------------------------------------
     860             : 
     861           0 : IMPL_LINK_NOARG(SvxBitmapTabPage, ClickSaveHdl_Impl)
     862             : {
     863             :        ::sfx2::FileDialogHelper aDlg(
     864           0 :         com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
     865           0 :     String aStrFilterType( "*.sob" );
     866           0 :     aDlg.AddFilter( aStrFilterType, aStrFilterType );
     867             : 
     868           0 :     INetURLObject aFile( SvtPathOptions().GetPalettePath() );
     869             :     DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
     870             : 
     871           0 :     if( pBitmapList->GetName().Len() )
     872             :     {
     873           0 :         aFile.Append( pBitmapList->GetName() );
     874             : 
     875           0 :         if( aFile.getExtension().isEmpty() )
     876           0 :             aFile.SetExtension( OUString("sob") );
     877             :     }
     878             : 
     879           0 :     aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
     880           0 :     if ( aDlg.Execute() == ERRCODE_NONE )
     881             :     {
     882           0 :         INetURLObject   aURL( aDlg.GetPath() );
     883           0 :         INetURLObject   aPathURL( aURL );
     884             : 
     885           0 :         aPathURL.removeSegment();
     886           0 :         aPathURL.removeFinalSlash();
     887             : 
     888           0 :         pBitmapList->SetName( aURL.getName() );
     889           0 :         pBitmapList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
     890             : 
     891           0 :         if( pBitmapList->Save() )
     892             :         {
     893             :             // determining (possibly cutting) the name
     894             :             // displaying it in the GroupBox
     895           0 :             OUString aString( CUI_RES( RID_SVXSTR_TABLE ) );
     896           0 :             aString += ": ";
     897             : 
     898           0 :             if ( aURL.getBase().getLength() > 18 )
     899             :             {
     900           0 :                 aString += aURL.getBase().copy( 0, 15 );
     901           0 :                 aString += "...";
     902             :             }
     903             :             else
     904           0 :                 aString += aURL.getBase();
     905             : 
     906           0 :             *pnBitmapListState |= CT_SAVED;
     907           0 :             *pnBitmapListState &= ~CT_MODIFIED;
     908             :         }
     909             :         else
     910             :         {
     911           0 :             ErrorBox( GetParentDialog(), WinBits( WB_OK ),
     912           0 :                 String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) ).Execute();
     913           0 :         }
     914             :     }
     915             : 
     916           0 :     return 0L;
     917             : }
     918             : 
     919             : //------------------------------------------------------------------------
     920             : 
     921           0 : IMPL_LINK_NOARG(SvxBitmapTabPage, ChangePixelColorHdl_Impl)
     922             : {
     923           0 :     aCtlPixel.SetPixelColor( aLbColor.GetSelectEntryColor() );
     924           0 :     aCtlPixel.Invalidate();
     925             : 
     926           0 :     aBitmapCtl.SetPixelColor( aLbColor.GetSelectEntryColor() );
     927             : 
     928             :     // get bitmap and display it
     929           0 :     rXFSet.Put(XFillBitmapItem(String(), Graphic(aBitmapCtl.GetBitmapEx())));
     930           0 :     aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
     931           0 :     aCtlPreview.Invalidate();
     932             : 
     933           0 :     bBmpChanged = sal_True;
     934             : 
     935           0 :     return 0L;
     936             : }
     937             : 
     938             : //------------------------------------------------------------------------
     939             : 
     940           0 : IMPL_LINK_NOARG(SvxBitmapTabPage, ChangeBackgrndColorHdl_Impl)
     941             : {
     942           0 :     aCtlPixel.SetBackgroundColor( aLbBackgroundColor.GetSelectEntryColor() );
     943           0 :     aCtlPixel.Invalidate();
     944             : 
     945           0 :     aBitmapCtl.SetBackgroundColor( aLbBackgroundColor.GetSelectEntryColor() );
     946             : 
     947             :     // get bitmap and display it
     948           0 :     rXFSet.Put(XFillBitmapItem(String(), Graphic(aBitmapCtl.GetBitmapEx())));
     949           0 :     aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
     950           0 :     aCtlPreview.Invalidate();
     951             : 
     952           0 :     bBmpChanged = sal_True;
     953             : 
     954           0 :     return 0L;
     955             : }
     956             : 
     957             : //------------------------------------------------------------------------
     958             : 
     959           0 : void SvxBitmapTabPage::PointChanged( Window* pWindow, RECT_POINT )
     960             : {
     961           0 :     if( pWindow == &aCtlPixel )
     962             :     {
     963           0 :         aBitmapCtl.SetBmpArray( aCtlPixel.GetBitmapPixelPtr() );
     964             : 
     965             :         // get bitmap and display it
     966           0 :         rXFSet.Put(XFillBitmapItem(String(), Graphic(aBitmapCtl.GetBitmapEx())));
     967           0 :         aCtlPreview.SetAttributes( aXFillAttr.GetItemSet() );
     968           0 :         aCtlPreview.Invalidate();
     969             : 
     970           0 :         bBmpChanged = sal_True;
     971             :     }
     972           0 : }
     973             : 
     974             : 
     975             : 
     976             : 
     977           0 : Window* SvxBitmapTabPage::GetParentLabeledBy( const Window* pLabeled ) const
     978             : {
     979           0 :     if (pLabeled == &aLbBitmaps)
     980           0 :         return const_cast<FixedText*>(&aLbBitmapsHidden);
     981             :     else
     982           0 :         return SvxTabPage::GetParentLabeledBy (pLabeled);
     983           0 : }
     984             : 
     985             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10