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

Generated by: LCOV version 1.10